0000-raspberry-pi.patch 3.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651109652109653109654109655109656109657109658109659109660109661109662109663109664109665109666109667109668109669109670109671109672109673109674109675109676109677109678109679109680109681109682109683109684109685109686109687109688109689109690109691109692109693109694109695109696109697109698109699109700109701109702109703109704109705109706109707109708109709109710109711109712109713109714109715109716109717109718109719109720109721109722109723109724109725109726109727109728109729109730109731109732109733109734109735109736109737109738109739109740109741109742109743109744109745109746109747109748109749109750109751109752109753109754109755109756109757109758109759109760109761109762109763109764109765109766109767109768109769109770109771109772109773109774109775109776109777109778109779109780109781109782109783109784109785109786109787109788109789109790109791109792109793109794109795109796109797109798109799109800109801109802109803109804109805109806109807109808109809109810109811109812109813109814109815109816109817109818109819109820109821109822109823109824109825109826109827109828109829109830109831109832109833109834109835109836109837109838109839109840109841109842109843109844109845109846109847109848109849109850109851109852109853109854109855109856109857109858109859109860109861109862109863109864109865109866109867109868109869109870109871109872109873109874109875109876109877109878109879109880109881109882109883109884109885109886109887109888109889109890109891109892109893109894109895109896109897109898109899109900109901109902109903109904109905109906109907109908109909109910109911109912109913109914109915109916109917109918109919109920109921109922109923109924109925109926109927109928109929109930109931109932109933109934109935109936109937109938109939109940109941109942109943109944109945109946109947109948109949109950109951109952109953109954109955109956109957109958109959109960109961109962109963109964109965109966109967109968109969109970109971109972109973109974109975109976109977109978109979109980109981109982109983109984109985109986109987109988109989109990109991109992109993109994109995109996109997109998109999110000110001110002110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110074110075110076110077110078110079110080110081110082110083110084110085110086110087110088110089110090110091110092110093110094110095110096110097110098110099110100110101110102110103110104110105110106110107110108110109110110110111110112110113110114110115110116110117110118110119110120110121110122110123110124110125110126110127110128110129110130110131110132110133110134110135110136110137110138110139110140110141110142110143110144110145110146110147110148110149110150110151110152110153110154110155110156110157110158110159110160110161110162110163110164110165110166110167110168110169110170110171110172110173110174110175110176110177110178110179110180110181110182110183110184110185110186110187110188110189110190110191110192110193110194110195110196110197110198110199110200110201110202110203110204110205110206110207110208110209110210110211110212110213110214110215110216110217110218110219110220110221110222110223110224110225110226110227110228110229110230110231110232110233110234110235110236110237110238110239110240110241110242110243110244110245110246110247110248110249110250110251110252110253110254110255110256110257110258110259110260110261110262110263110264110265110266110267110268110269110270110271110272110273110274110275110276110277110278110279110280110281110282110283110284110285110286110287110288110289110290110291110292110293110294110295110296110297110298110299110300110301110302110303110304110305110306110307110308110309110310110311110312110313110314110315110316110317110318110319110320110321110322110323110324110325110326110327110328110329110330110331110332110333110334110335110336110337110338110339110340110341110342110343110344110345110346110347110348110349110350110351110352110353110354110355110356110357110358110359110360110361110362110363110364110365110366110367110368110369110370110371110372110373110374110375110376110377110378110379110380110381110382110383110384110385110386110387110388110389110390110391110392110393110394110395110396110397110398110399110400110401110402110403110404110405110406110407110408110409110410110411110412110413110414110415110416110417110418110419110420110421110422110423110424110425110426110427110428110429110430110431110432110433110434110435110436110437110438110439110440110441110442110443110444110445110446110447110448110449110450110451110452110453110454110455110456110457110458110459110460110461110462110463110464110465110466110467110468110469110470110471110472110473110474110475110476110477110478110479110480110481110482110483110484110485110486110487110488110489110490110491110492110493110494110495110496110497110498110499110500110501110502110503110504110505110506110507110508110509110510110511110512110513110514110515110516110517110518110519110520110521110522110523110524110525110526110527110528110529110530110531110532110533110534110535110536110537110538110539110540110541110542110543110544110545110546110547110548110549110550110551110552110553110554110555110556110557110558110559110560110561110562110563110564110565110566110567110568110569110570110571110572110573110574110575110576110577110578110579110580110581110582110583110584110585110586110587110588110589110590110591110592110593110594110595110596110597110598110599110600110601110602110603110604110605110606110607110608110609110610110611110612110613110614110615110616110617110618110619110620110621110622110623110624110625110626110627110628110629110630110631110632110633110634110635110636110637110638110639110640110641110642110643110644110645110646110647110648110649110650110651110652110653110654110655110656110657110658110659110660110661110662110663110664110665110666110667110668110669110670110671110672110673110674110675110676110677110678110679110680110681110682110683110684110685110686110687110688110689110690110691110692110693110694110695110696110697110698110699110700110701110702110703110704110705110706110707110708110709110710110711110712110713110714110715110716110717110718110719110720110721110722110723110724110725110726110727110728110729110730110731110732110733110734110735110736110737110738110739110740110741110742110743110744110745110746110747110748110749110750110751110752110753110754110755110756110757110758110759110760110761110762110763110764110765110766110767110768110769110770110771110772110773110774110775110776110777110778110779110780110781110782110783110784110785110786110787110788110789110790110791110792110793110794110795110796110797110798110799110800110801110802110803110804110805110806110807110808110809110810110811110812110813110814110815110816110817110818110819110820110821110822110823110824110825110826110827110828110829110830110831110832110833110834110835110836110837110838110839110840110841110842110843110844110845110846110847110848110849110850110851110852110853110854110855110856110857110858110859110860110861110862110863110864110865110866110867110868110869110870110871110872110873110874110875110876110877110878110879110880110881110882110883110884110885110886110887110888110889110890110891110892110893110894110895110896110897110898110899110900110901110902110903110904110905110906110907110908110909110910110911110912110913110914110915110916110917110918110919110920110921110922110923110924110925110926110927110928110929110930110931110932110933110934110935110936110937110938110939110940110941110942110943110944110945110946110947110948110949110950110951110952110953110954110955110956110957110958110959110960110961110962110963110964110965110966110967110968110969110970110971110972110973110974110975110976110977110978110979110980110981110982110983110984110985110986110987110988110989110990110991110992110993110994110995110996110997110998110999111000111001111002111003111004111005111006111007111008111009111010111011111012111013111014111015111016111017111018111019111020111021111022111023111024111025111026111027111028111029111030111031111032111033111034111035111036111037111038111039111040111041111042111043111044111045111046111047111048111049111050111051111052111053111054111055111056111057111058111059111060111061111062111063111064111065111066111067111068111069111070111071111072111073111074111075111076111077111078111079111080111081111082111083111084111085111086111087111088111089111090111091111092111093111094111095111096111097111098111099111100111101111102111103111104111105111106111107111108111109111110111111111112111113111114111115111116111117111118111119111120111121111122111123111124111125111126111127111128111129111130111131111132111133111134111135111136111137111138111139111140111141111142111143111144111145111146111147111148111149111150111151111152111153111154111155111156111157111158111159111160111161111162111163111164111165111166111167111168111169111170111171111172111173111174111175111176111177111178111179111180111181111182111183111184111185111186111187111188111189111190111191111192111193111194111195111196111197111198111199111200111201111202111203111204111205111206111207111208111209111210111211111212111213111214111215111216111217111218111219111220111221111222111223111224111225111226111227111228111229111230111231111232111233111234111235111236111237111238111239111240111241111242111243111244111245111246111247111248111249111250111251111252111253111254111255111256111257111258111259111260111261111262111263111264111265111266111267111268111269111270111271111272111273111274111275111276111277111278111279111280111281111282111283111284111285111286111287111288111289111290111291111292111293111294111295111296111297111298111299111300111301111302111303111304111305111306111307111308111309111310111311111312111313111314111315111316111317111318111319111320111321111322111323111324111325111326111327111328111329111330111331111332111333111334111335111336111337111338111339111340111341111342111343111344111345111346111347111348111349111350111351111352111353111354111355111356111357111358111359111360111361111362111363111364111365111366111367111368111369111370111371111372111373111374111375111376111377111378111379111380111381111382111383111384111385111386111387111388111389111390111391111392111393111394111395111396111397111398111399111400111401111402111403111404111405111406111407111408111409111410111411111412111413111414111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447111448111449111450111451111452111453111454111455111456111457111458111459111460111461111462111463111464111465111466111467111468111469111470111471111472111473111474111475111476111477111478111479111480111481111482111483111484111485111486111487111488111489111490111491111492111493111494111495111496111497111498111499111500111501111502111503111504111505111506111507111508111509111510111511111512111513111514111515111516111517111518111519111520111521111522111523111524111525111526111527111528111529111530111531111532111533111534111535111536111537111538111539111540111541111542111543111544111545111546111547111548111549111550111551111552111553111554111555111556111557111558111559111560111561111562111563111564111565111566111567111568111569111570111571111572111573111574111575111576111577111578111579111580111581111582111583111584111585111586111587111588111589111590111591111592111593111594111595111596111597111598111599111600111601111602111603111604111605111606111607111608111609111610111611111612111613111614111615111616111617111618111619111620111621111622111623111624111625111626111627111628111629111630111631111632111633111634111635111636111637111638111639111640111641111642111643111644111645111646111647111648111649111650111651111652111653111654111655111656111657111658111659111660111661111662111663111664111665111666111667111668111669111670111671111672111673111674111675111676111677111678111679111680111681111682111683111684111685111686111687111688111689111690111691111692111693111694111695111696111697111698111699111700111701111702111703111704111705111706111707111708111709111710111711111712111713111714111715111716111717111718111719111720111721111722111723111724111725111726111727111728111729111730111731111732111733111734111735111736111737111738111739111740111741111742111743111744111745111746111747111748111749111750111751111752111753111754111755111756111757111758111759111760111761111762111763111764111765111766111767111768111769111770111771111772111773111774111775111776111777111778111779111780111781111782111783111784111785111786111787111788111789111790111791111792111793111794111795111796111797111798111799111800111801111802111803111804111805111806111807111808111809111810111811111812111813111814111815111816111817111818111819111820111821111822111823111824111825111826111827111828111829111830111831111832111833111834111835111836111837111838111839111840111841111842111843111844111845111846111847111848111849111850111851111852111853111854111855111856111857111858111859111860111861111862111863111864111865111866111867111868111869111870111871111872111873111874111875111876111877111878111879111880111881111882111883111884111885111886111887111888111889111890111891111892111893111894111895111896111897111898111899111900111901111902111903111904111905111906111907111908111909111910111911111912111913111914111915111916111917111918111919111920111921111922111923111924111925111926111927111928111929111930111931111932111933111934111935111936111937111938111939111940111941111942111943111944111945111946111947111948111949111950111951111952111953111954111955111956111957111958111959111960111961111962111963111964111965111966111967111968111969111970111971111972111973111974111975111976111977111978111979111980111981111982111983111984111985111986111987111988111989111990111991111992111993111994111995111996111997111998111999112000112001112002112003112004112005112006112007112008112009112010112011112012112013112014112015112016112017112018112019112020112021112022112023112024112025112026112027112028112029112030112031112032112033112034112035112036112037112038112039112040112041112042112043112044112045112046112047112048112049112050112051112052112053112054112055112056112057112058112059112060112061112062112063112064112065112066112067112068112069112070112071112072112073112074112075112076112077112078112079112080112081112082112083112084112085112086112087112088112089112090112091112092112093112094112095112096112097112098112099112100112101112102112103112104112105112106112107112108112109112110112111112112112113112114112115112116112117112118112119112120112121112122112123112124112125112126112127112128112129112130112131112132112133112134112135112136112137112138112139112140112141112142112143112144112145112146112147112148112149112150112151112152112153112154112155112156112157112158112159112160112161112162112163112164112165112166112167112168112169112170112171112172112173112174112175112176112177112178112179112180112181112182112183112184112185112186112187112188112189112190112191112192112193112194112195112196112197112198112199112200112201112202112203112204112205112206112207112208112209112210112211112212112213112214112215112216112217112218112219112220112221112222112223112224112225112226112227112228112229112230112231112232112233112234112235112236112237112238112239112240112241112242112243112244112245112246112247112248112249112250112251112252112253112254112255112256112257112258112259112260112261112262112263112264112265112266112267112268112269112270112271112272112273112274112275112276112277112278112279112280112281112282112283112284112285112286112287112288112289112290112291112292112293112294112295112296112297112298112299112300112301112302112303112304112305112306112307112308112309112310112311112312112313112314112315112316112317112318112319112320112321112322112323112324112325112326112327112328112329112330112331112332112333112334112335112336112337112338112339112340112341112342112343112344112345112346112347112348112349112350112351112352112353112354112355112356112357112358112359112360112361112362112363112364112365112366112367112368112369112370112371112372112373112374112375112376112377112378112379112380112381112382112383112384112385112386112387112388112389112390112391112392112393112394112395112396112397112398112399112400112401112402112403112404112405112406112407112408112409112410112411112412112413112414112415112416112417112418112419112420112421112422112423112424112425112426112427112428112429112430112431112432112433112434112435112436112437112438112439112440112441112442112443112444112445112446112447112448112449112450112451112452112453112454112455112456112457112458112459112460112461112462112463112464112465112466112467112468112469112470112471112472112473112474112475112476112477112478112479112480112481112482112483112484112485112486112487112488112489112490112491112492112493112494112495112496112497112498112499112500112501112502112503112504112505112506112507112508112509112510112511112512112513112514112515112516112517112518112519112520112521112522112523112524112525112526112527112528112529112530112531112532112533112534112535112536112537112538112539112540112541112542112543112544112545112546112547112548112549112550112551112552112553112554112555112556112557112558112559112560112561112562112563112564112565112566112567112568112569112570112571112572112573112574112575112576112577112578112579112580112581112582112583112584112585112586112587112588112589112590112591112592112593112594112595112596112597112598112599112600112601112602112603112604112605112606112607112608112609112610112611112612112613112614112615112616112617112618112619112620112621112622112623112624112625112626112627112628112629112630112631112632112633112634112635112636112637112638112639112640112641112642112643112644112645112646112647112648112649112650112651112652112653112654112655112656112657112658112659112660112661112662112663112664112665112666112667112668112669112670112671112672112673112674112675112676112677112678112679112680112681112682112683112684112685112686112687112688112689112690112691112692112693112694112695112696112697112698112699112700112701112702112703112704112705112706112707112708112709112710112711112712112713112714112715112716112717112718112719112720112721112722112723112724112725112726112727112728112729112730112731112732112733112734112735112736112737112738112739112740112741112742112743112744112745112746112747112748112749112750112751112752112753112754112755112756112757112758112759112760112761112762112763112764112765112766112767112768112769112770112771112772112773112774112775112776112777112778112779112780112781112782112783112784112785112786112787112788112789112790112791112792112793112794112795112796112797112798112799112800112801112802112803112804112805112806112807112808112809112810112811112812112813112814112815112816112817112818112819112820112821112822112823112824112825112826112827112828112829112830112831112832112833112834112835112836112837112838112839112840112841112842112843112844112845112846112847112848112849112850112851112852112853112854112855112856112857112858112859112860112861112862112863112864112865112866112867112868112869112870112871112872112873112874112875112876112877112878112879112880112881112882112883112884112885112886112887112888112889112890112891112892112893112894112895112896112897112898112899112900112901112902112903112904112905112906112907112908112909112910112911112912112913112914112915112916112917112918112919112920112921112922112923112924112925112926112927112928112929112930112931112932112933112934112935112936112937112938112939112940112941112942112943112944112945112946112947112948112949112950112951112952112953112954112955112956112957112958112959112960112961112962112963112964112965112966112967112968112969112970112971112972112973112974112975112976112977112978112979112980112981112982112983112984112985112986112987112988112989112990112991112992112993112994112995112996112997112998112999113000113001113002113003113004113005113006113007113008113009113010113011113012113013113014113015113016113017113018113019113020113021113022113023113024113025113026113027113028113029113030113031113032113033113034113035113036113037113038113039113040113041113042113043113044113045113046113047113048113049113050113051113052113053113054113055113056113057113058113059113060113061113062113063113064113065113066113067113068113069113070113071113072113073113074113075113076113077113078113079113080113081113082113083113084113085113086113087113088113089113090113091113092113093113094113095113096113097113098113099113100113101113102113103113104113105113106113107113108113109113110113111113112113113113114113115113116113117113118113119113120113121113122113123113124113125113126113127113128113129113130113131113132113133113134113135113136113137113138113139113140113141113142113143113144113145113146113147113148113149113150113151113152113153113154113155113156113157113158113159113160113161113162113163113164113165113166113167113168113169113170113171113172113173113174113175113176113177113178113179113180113181113182113183113184113185113186113187113188113189113190113191113192113193113194113195113196113197113198113199113200113201113202113203113204113205113206113207113208113209113210113211113212113213113214113215113216113217113218113219113220113221113222113223113224113225113226113227113228113229113230113231113232113233113234113235113236113237113238113239113240113241113242113243113244113245113246113247113248113249113250113251113252113253113254113255113256113257113258113259113260113261113262113263113264113265113266113267113268113269113270113271113272113273113274113275113276113277113278113279113280113281113282113283113284113285113286113287113288113289113290113291113292113293113294113295113296113297113298113299113300113301113302113303113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324113325113326113327113328113329113330113331113332113333113334113335113336113337113338113339113340113341113342113343113344113345113346113347113348113349113350113351113352113353113354113355113356113357113358113359113360113361113362113363113364113365113366113367113368113369113370113371113372113373113374113375113376113377113378113379113380113381113382113383113384113385113386113387113388113389113390113391113392113393113394113395113396113397113398113399113400113401113402113403113404113405113406113407113408113409113410113411113412113413113414113415113416113417113418113419113420113421113422113423113424113425113426113427113428113429113430113431113432113433113434113435113436113437113438113439113440113441113442113443113444113445113446113447113448113449113450113451113452113453113454113455113456113457113458113459113460113461113462113463113464113465113466113467113468113469113470113471113472113473113474113475113476113477113478113479113480113481113482113483113484113485113486113487113488113489113490113491113492113493113494113495113496113497113498113499113500113501113502113503113504113505113506113507113508113509113510113511113512113513113514113515113516113517113518113519113520113521113522113523113524113525113526113527113528113529113530113531113532113533113534113535113536113537113538113539113540113541113542113543113544113545113546113547113548113549113550113551113552113553113554113555113556113557113558113559113560113561113562113563113564113565113566113567113568113569113570113571113572113573113574113575113576113577113578113579113580113581113582113583113584113585113586113587113588113589113590113591113592113593113594113595113596113597113598113599113600113601113602113603113604113605113606113607113608113609113610113611113612113613113614113615113616113617113618113619113620113621113622113623113624113625113626113627113628113629113630113631113632113633113634113635113636113637113638113639113640113641113642113643113644113645113646113647113648113649113650113651113652113653113654113655113656113657113658113659113660113661113662113663113664113665113666113667113668113669113670113671113672113673113674113675113676113677113678113679113680113681113682113683113684113685113686113687113688113689113690113691113692113693113694113695113696113697113698113699113700113701113702113703113704113705113706113707113708113709113710113711113712113713113714113715113716113717113718113719113720113721113722113723113724113725113726113727113728113729113730113731113732113733113734113735113736113737113738113739113740113741113742113743113744113745113746113747113748113749113750113751113752113753113754113755113756113757113758113759113760113761113762113763113764113765113766113767113768113769113770113771113772113773113774113775113776113777113778113779113780113781113782113783113784113785113786113787113788113789113790113791113792113793113794113795113796113797113798113799113800113801113802113803113804113805113806113807113808113809113810113811113812113813113814113815113816113817113818113819113820113821113822113823113824113825113826113827113828113829113830113831113832113833113834113835113836113837113838113839113840113841113842113843113844113845113846113847113848113849113850113851113852113853113854113855113856113857113858113859113860113861113862113863113864113865113866113867113868113869113870113871113872113873113874113875113876113877113878113879113880113881113882113883113884113885113886113887113888113889113890113891113892113893113894113895113896113897113898113899113900113901113902113903113904113905113906113907113908113909113910113911113912113913113914113915113916113917113918113919113920113921113922113923113924113925113926113927113928113929113930113931113932113933113934113935113936113937113938113939113940113941113942113943113944113945113946113947113948113949113950113951113952113953113954113955113956113957113958113959113960113961113962113963113964113965113966113967113968113969113970113971113972113973113974113975113976113977113978113979113980113981113982113983113984113985113986113987113988113989113990113991113992113993113994113995113996113997113998113999114000114001114002114003114004114005114006114007114008114009114010114011114012114013114014114015114016114017114018114019114020114021114022114023114024114025114026114027114028114029114030114031114032114033114034114035114036114037114038114039114040114041114042114043114044114045114046114047114048114049114050114051114052114053114054114055114056114057114058114059114060114061114062114063114064114065114066114067114068114069114070114071114072114073114074114075114076114077114078114079114080114081114082114083114084114085114086114087114088114089114090114091114092114093114094114095114096114097114098114099114100114101114102114103114104114105114106114107114108114109114110114111114112114113114114114115114116114117114118114119114120114121114122114123114124114125114126114127114128114129114130114131114132114133114134114135114136114137114138114139114140114141114142114143114144114145114146114147114148114149114150114151114152114153114154114155114156114157114158114159114160114161114162114163114164114165114166114167114168114169114170114171114172114173114174114175114176114177114178114179114180114181114182114183114184114185114186114187114188114189114190114191114192114193114194114195114196114197114198114199114200114201114202114203114204114205114206114207114208114209114210114211114212114213114214114215114216114217114218114219114220114221114222114223114224114225114226114227114228114229114230114231114232114233114234114235114236114237114238114239114240114241114242114243114244114245114246114247114248114249114250114251114252114253114254114255114256114257114258114259114260114261114262114263114264114265114266114267114268114269114270114271114272114273114274114275114276114277114278114279114280114281114282114283114284114285114286114287114288114289114290114291114292114293114294114295114296114297114298114299114300114301114302114303114304114305114306114307114308114309114310114311114312114313114314114315114316114317114318114319114320114321114322114323114324114325114326114327114328114329114330114331114332114333114334114335114336114337114338114339114340114341114342114343114344114345114346114347114348114349114350114351114352114353114354114355114356114357114358114359114360114361114362114363114364114365114366114367114368114369114370114371114372114373114374114375114376114377114378114379114380114381114382114383114384114385114386114387114388114389114390114391114392114393114394114395114396114397114398114399114400114401114402114403114404114405114406114407114408114409114410114411114412114413114414114415114416114417114418114419114420114421114422114423114424114425114426114427114428114429114430114431114432114433114434114435114436114437114438114439114440114441114442114443114444114445114446114447114448114449114450114451114452114453114454114455114456114457114458114459114460114461114462114463114464114465114466114467114468114469114470114471114472114473114474114475114476114477114478114479114480114481114482114483114484114485114486114487114488114489114490114491114492114493114494114495114496114497114498114499114500114501114502114503114504114505114506114507114508114509114510114511114512114513114514114515114516114517114518114519114520114521114522114523114524114525114526114527114528114529114530114531114532114533114534114535114536114537114538114539114540114541114542114543114544114545114546114547114548114549114550114551114552114553114554114555114556114557114558114559114560114561114562114563114564114565114566114567114568114569114570114571114572114573114574114575114576114577114578114579114580114581114582114583114584114585114586114587114588114589114590114591114592114593114594114595114596114597114598114599114600114601114602114603114604114605114606114607114608114609114610114611114612114613114614114615114616114617114618114619114620114621114622114623114624114625114626114627114628114629114630114631114632114633114634114635114636114637114638114639114640114641114642114643114644114645114646114647114648114649114650114651114652114653114654114655114656114657114658114659114660114661114662114663114664114665114666114667114668114669114670114671114672114673114674114675114676114677114678114679114680114681114682114683114684114685114686114687114688114689114690114691114692114693114694114695114696114697114698114699114700114701114702114703114704114705114706114707114708114709114710114711114712114713114714114715114716114717114718114719114720114721114722114723114724114725114726114727114728114729114730114731114732114733114734114735114736114737114738114739114740114741114742114743114744114745114746114747114748114749114750114751114752114753114754114755114756114757114758114759114760114761114762114763114764114765114766114767114768114769114770114771114772114773114774114775114776114777114778114779114780114781114782114783114784114785114786114787114788114789114790114791114792114793114794114795114796114797114798114799114800114801114802114803114804114805114806114807114808114809114810114811114812114813114814114815114816114817114818114819114820114821114822114823114824114825114826114827114828114829114830114831114832114833114834114835114836114837114838114839114840114841114842114843114844114845114846114847114848114849114850114851114852114853114854114855114856114857114858114859114860114861114862114863114864114865114866114867114868114869114870114871114872114873114874114875114876114877114878114879114880114881114882114883114884114885114886114887114888114889114890114891114892114893114894114895114896114897114898114899114900114901114902114903114904114905114906114907114908114909114910114911114912114913114914114915114916114917114918114919114920114921114922114923114924114925114926114927114928114929114930114931114932114933114934114935114936114937114938114939114940114941114942114943114944114945114946114947114948114949114950114951114952114953114954114955114956114957114958114959114960114961114962114963114964114965114966114967114968114969114970114971114972114973114974114975114976114977114978114979114980114981114982114983114984114985114986114987114988114989114990114991114992114993114994114995114996114997114998114999115000115001115002115003115004115005115006115007115008115009115010115011115012115013115014115015115016115017115018115019115020115021115022115023115024115025115026115027115028115029115030115031115032115033115034115035115036115037115038115039115040115041115042115043115044115045115046115047115048115049115050115051115052115053115054115055115056115057115058115059115060115061115062115063115064115065115066115067115068115069115070115071115072115073115074115075115076115077115078115079115080115081115082115083115084115085115086115087115088115089115090115091115092115093115094115095115096115097115098115099115100115101115102115103115104115105115106115107115108115109115110115111115112115113115114115115115116115117115118115119115120115121115122115123115124115125115126115127115128115129115130115131115132115133115134115135115136115137115138115139115140115141115142115143115144115145115146115147115148115149115150115151115152115153115154115155115156115157115158115159115160115161115162115163115164115165115166115167115168115169115170115171115172115173115174115175115176115177115178115179115180115181115182115183115184115185115186115187115188115189115190115191115192115193115194115195115196115197115198115199115200115201115202115203115204115205115206115207115208115209115210115211115212115213115214115215115216115217115218115219115220115221115222115223115224115225115226115227115228115229115230115231115232115233115234115235115236115237115238115239115240115241115242115243115244115245115246115247115248115249115250115251115252115253115254115255115256115257115258115259115260115261115262115263115264115265115266115267115268115269115270115271115272115273115274115275115276115277115278115279115280115281115282115283115284115285115286115287115288115289115290115291115292115293115294115295115296115297115298115299115300115301115302115303115304115305115306115307115308115309115310115311115312115313115314115315115316115317115318115319115320115321115322115323115324115325115326115327115328115329115330115331115332115333115334115335115336115337115338115339115340115341115342115343115344115345115346115347115348115349115350115351115352115353115354115355115356115357115358115359115360115361115362115363115364115365115366115367115368115369115370115371115372115373115374115375115376115377115378115379115380115381115382115383115384115385115386115387115388115389115390115391115392115393115394115395115396115397115398115399115400115401115402115403115404115405115406115407115408115409115410115411115412115413115414115415115416115417115418115419115420115421115422115423115424115425115426115427115428115429115430115431115432115433115434115435115436115437115438115439115440115441115442115443115444115445115446115447115448115449115450115451115452115453115454115455115456115457115458115459115460115461115462115463115464115465115466115467115468115469115470115471115472115473115474115475115476115477115478115479115480115481115482115483115484115485115486115487115488115489115490115491115492115493115494115495115496115497115498115499115500115501115502115503115504115505115506115507115508115509115510115511115512115513115514115515115516115517115518115519115520115521115522115523115524115525115526115527115528115529115530115531115532115533115534115535115536115537115538115539115540115541115542115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563115564115565115566115567115568115569115570115571115572115573115574115575115576115577115578115579115580115581115582115583115584115585115586115587115588115589115590115591115592115593115594115595115596115597115598115599115600115601115602115603115604115605115606115607115608115609115610115611115612115613115614115615115616115617115618115619115620115621115622115623115624115625115626115627115628115629115630115631115632115633115634115635115636115637115638115639115640115641115642115643115644115645115646115647115648115649115650115651115652115653115654115655115656115657115658115659115660115661115662115663115664115665115666115667115668115669115670115671115672115673115674115675115676115677115678115679115680115681115682115683115684115685115686115687115688115689115690115691115692115693115694115695115696115697115698115699115700115701115702115703115704115705115706115707115708115709115710115711115712115713115714115715115716115717115718115719115720115721115722115723115724115725115726115727115728115729115730115731115732115733115734115735115736115737115738115739115740115741115742115743115744115745115746115747115748115749115750115751115752115753115754115755115756115757115758115759115760115761115762115763115764115765115766115767115768115769115770115771115772115773115774115775115776115777115778115779115780115781115782115783115784115785115786115787115788115789115790115791115792115793115794115795115796115797115798115799115800115801115802115803115804115805115806115807115808115809115810115811115812115813115814115815115816115817115818115819115820115821115822115823115824115825115826115827115828115829115830115831115832115833115834115835115836115837115838115839115840115841115842115843115844115845115846115847115848115849115850115851115852115853115854115855115856115857115858115859115860115861115862115863115864115865115866115867115868115869115870115871115872115873115874115875115876115877115878115879115880115881115882115883115884115885115886115887115888115889115890115891115892115893115894115895115896115897115898115899115900115901115902115903115904115905115906115907115908115909115910115911115912115913115914115915115916115917115918115919115920115921115922115923115924115925115926115927115928115929115930115931115932115933115934115935115936115937115938115939115940115941115942115943115944115945115946115947115948115949115950115951115952115953115954115955115956115957115958115959115960115961115962115963115964115965115966115967115968115969115970115971115972115973115974115975115976115977115978115979115980115981115982115983115984115985115986115987115988115989115990115991115992115993115994115995115996115997115998115999116000116001116002116003116004116005116006116007116008116009116010116011116012116013116014116015116016116017116018116019116020116021116022116023116024116025116026116027116028116029116030116031116032116033116034116035116036116037116038116039116040116041116042116043116044116045116046116047116048116049116050116051116052116053116054116055116056116057116058116059116060116061116062116063116064116065116066116067116068116069116070116071116072116073116074116075116076116077116078116079116080116081116082116083116084116085116086116087116088116089116090116091116092116093116094116095116096116097116098116099116100116101116102116103116104116105116106116107116108116109116110116111116112116113116114116115116116116117116118116119116120116121116122116123116124116125116126116127116128116129116130116131116132116133116134116135116136116137116138116139116140116141116142116143116144116145116146116147116148116149116150116151116152116153116154116155116156116157116158116159116160116161116162116163116164116165116166116167116168116169116170116171116172116173116174116175116176116177116178116179116180116181116182116183116184116185116186116187116188116189116190116191116192116193116194116195116196116197116198116199116200116201116202116203116204116205116206116207116208116209116210116211116212116213116214116215116216116217116218116219116220116221116222116223116224116225116226116227116228116229116230116231116232116233116234116235116236116237116238116239116240116241116242116243116244116245116246116247116248116249116250116251116252116253116254116255116256116257116258116259116260116261116262116263116264116265116266116267116268116269116270116271116272116273116274116275116276116277116278116279116280116281116282116283116284116285116286116287116288116289116290116291116292116293116294116295116296116297116298116299116300116301116302116303116304116305116306116307116308116309116310116311116312116313116314116315116316116317116318116319116320116321116322116323116324116325116326116327116328116329116330116331116332116333116334116335116336116337116338116339116340116341116342116343116344116345116346116347116348116349116350116351116352116353116354116355116356116357116358116359116360116361116362116363116364116365116366116367116368116369116370116371116372116373116374116375116376116377116378116379116380116381116382116383116384116385116386116387116388116389116390116391116392116393116394116395116396116397116398116399116400116401116402116403116404116405116406116407116408116409116410116411116412116413116414116415116416116417116418116419116420116421116422116423116424116425116426116427116428116429116430116431116432116433116434116435116436116437116438116439116440116441116442116443116444116445116446116447116448116449116450116451116452116453116454116455116456116457116458116459116460116461116462116463116464116465116466116467116468116469116470116471116472116473116474116475116476116477116478116479116480116481116482116483116484116485116486116487116488116489116490116491116492116493116494116495116496116497116498116499116500116501116502116503116504116505116506116507116508116509116510116511116512116513116514116515116516116517116518116519116520116521116522116523116524116525116526116527116528116529116530116531116532116533116534116535116536116537116538116539116540116541116542116543116544116545116546116547116548116549116550116551116552116553116554116555116556116557116558116559116560116561116562116563116564116565116566116567116568116569116570116571116572116573116574116575116576116577116578116579116580116581116582116583116584116585116586116587116588116589116590116591116592116593116594116595116596116597116598116599116600116601116602116603116604116605116606116607116608116609116610116611116612116613116614116615116616116617116618116619116620116621116622116623116624116625116626116627116628116629116630116631116632116633116634116635116636116637116638116639116640116641116642116643116644116645116646116647116648116649116650116651116652116653116654116655116656116657116658116659116660116661116662116663116664116665116666116667116668116669116670116671116672116673116674116675116676116677116678116679116680116681116682116683116684116685116686116687116688116689116690116691116692116693116694116695116696116697116698116699116700116701116702116703116704116705116706116707116708116709116710116711116712116713116714116715116716116717116718116719116720116721116722116723116724116725116726116727116728116729116730116731116732116733116734116735116736116737116738116739116740116741116742116743116744116745116746116747116748116749116750116751116752116753116754116755116756116757116758116759116760116761116762116763116764116765116766116767116768116769116770116771116772116773116774116775116776116777116778116779116780116781116782116783116784116785116786116787116788116789116790116791116792116793116794116795116796116797116798116799116800116801116802116803116804116805116806116807116808116809116810116811116812116813116814116815116816116817116818116819116820116821116822116823116824116825116826116827116828116829116830116831116832116833116834116835116836116837116838116839116840116841116842116843116844116845116846116847116848116849116850116851116852116853116854116855116856116857116858116859116860116861116862116863116864116865116866116867116868116869116870116871116872116873116874116875116876116877116878116879116880116881116882116883116884116885116886116887116888116889116890116891116892116893116894116895116896116897116898116899116900116901116902116903116904116905116906116907116908116909116910116911116912116913116914116915116916116917116918116919116920116921116922116923116924116925116926116927116928116929116930116931116932116933116934116935116936116937116938116939116940116941116942116943116944116945116946116947116948116949116950116951116952116953116954116955116956116957116958116959116960116961116962116963116964116965116966116967116968116969116970116971116972116973116974116975116976116977116978116979116980116981116982116983116984116985116986116987116988116989116990116991116992116993116994116995116996116997116998116999117000117001117002117003117004117005117006117007117008117009117010117011117012117013117014117015117016117017117018117019117020117021117022117023117024117025117026117027117028117029117030117031117032117033117034117035117036117037117038117039117040117041117042117043117044117045117046117047117048117049117050117051117052117053117054117055117056117057117058117059117060117061117062117063117064117065117066117067117068117069117070117071117072117073117074117075117076117077117078117079117080117081117082117083117084117085117086117087117088117089117090117091117092117093117094117095117096117097117098117099117100117101117102117103117104117105117106117107117108117109117110117111117112117113117114117115117116117117117118117119117120117121117122117123117124117125117126117127117128117129117130117131117132117133117134117135117136117137117138117139117140117141117142117143117144117145117146117147117148117149117150117151117152117153117154117155117156117157117158117159117160117161117162117163117164117165117166117167117168117169117170117171117172117173117174117175117176117177117178117179117180117181117182117183117184117185117186117187117188117189117190117191117192117193117194117195117196117197117198117199117200117201117202117203117204117205117206117207117208117209117210117211117212117213117214117215117216117217117218117219117220117221117222117223117224117225117226117227117228117229117230117231117232117233117234117235117236117237117238117239117240117241117242117243117244117245117246117247117248117249117250117251117252117253117254117255117256117257117258117259117260117261117262117263117264117265117266117267117268117269117270117271117272117273117274117275117276117277117278117279117280117281117282117283117284117285117286117287117288117289117290117291117292117293117294117295117296117297117298117299117300117301117302117303117304117305117306117307117308117309117310117311117312117313117314117315117316117317117318117319117320117321117322117323117324117325117326117327117328117329117330117331117332117333117334117335117336117337117338117339117340117341117342117343117344117345117346117347117348117349117350117351117352117353117354117355117356117357117358117359117360117361117362117363117364117365117366117367117368117369117370117371117372117373117374117375117376117377117378117379117380117381117382117383117384117385117386117387117388117389117390117391117392117393117394117395117396117397117398117399117400117401117402117403117404117405117406117407117408117409117410117411117412117413117414117415117416117417117418117419117420117421117422117423117424117425117426117427117428117429117430117431117432117433117434117435117436117437117438117439117440117441117442117443117444117445117446117447117448117449117450117451117452117453117454117455117456117457117458117459117460117461117462117463117464117465117466117467117468117469117470117471117472117473117474117475117476117477117478117479117480117481117482117483117484117485117486117487117488117489117490117491117492117493117494117495117496117497117498117499117500117501117502117503117504117505117506117507117508117509117510117511117512117513117514117515117516117517117518117519117520117521117522117523117524117525117526117527117528117529117530117531117532117533117534117535117536117537117538117539117540117541117542117543117544117545117546117547117548117549117550117551117552117553117554117555117556117557117558117559117560117561117562117563117564117565117566117567117568117569117570117571117572117573117574117575117576117577117578117579117580117581117582117583117584117585117586117587117588117589117590117591117592117593117594117595117596117597117598117599117600117601117602117603117604117605117606117607117608117609117610117611117612117613117614117615117616117617117618117619117620117621117622117623117624117625117626117627117628117629117630117631117632117633117634117635117636117637117638117639117640117641117642117643117644117645117646117647117648117649117650117651117652117653117654117655117656117657117658117659117660117661117662117663117664117665117666117667117668117669117670117671117672117673117674117675117676117677117678117679117680117681117682117683117684117685117686117687117688117689117690117691117692117693117694117695117696117697117698117699117700117701117702117703117704117705117706117707117708117709117710117711117712117713117714117715117716117717117718117719117720117721117722117723117724117725117726117727117728117729117730117731117732117733117734117735117736117737117738117739117740117741117742117743117744117745117746117747117748117749117750117751117752117753117754117755117756117757117758117759117760117761117762117763117764117765117766117767117768117769117770117771117772117773117774117775117776117777117778117779117780117781117782117783117784117785117786117787117788117789117790117791117792117793117794117795117796117797117798117799117800117801117802117803117804117805117806117807117808117809117810117811117812117813117814117815117816117817117818117819117820117821117822117823117824117825117826117827117828117829117830117831117832117833117834117835117836117837117838117839117840117841117842117843117844117845117846117847117848117849117850117851117852117853117854117855117856117857117858117859117860117861117862117863117864117865117866117867117868117869117870117871117872117873117874117875117876117877117878117879117880117881117882117883117884117885117886117887117888117889117890117891117892117893117894117895117896117897117898117899117900117901117902117903117904117905117906117907117908117909117910117911117912117913117914117915117916117917117918117919117920117921117922117923117924117925117926117927117928117929117930117931117932117933117934117935117936117937117938117939117940117941117942117943117944117945117946117947117948117949117950117951117952117953117954117955117956117957117958117959117960117961117962117963117964117965117966117967117968117969117970117971117972117973117974117975117976117977117978117979117980117981117982117983117984117985117986117987117988117989117990117991117992117993117994117995117996117997117998117999118000118001118002118003118004118005118006118007118008118009118010118011118012118013118014118015118016118017118018118019118020118021118022118023118024118025118026118027118028118029118030118031118032118033118034118035118036118037118038118039118040118041118042118043118044118045118046118047118048118049118050118051118052118053118054118055118056118057118058118059118060118061118062118063118064118065118066118067118068118069118070118071118072118073118074118075118076118077118078118079118080118081118082118083118084118085118086118087118088118089118090118091118092118093118094118095118096118097118098118099118100118101118102118103118104118105118106118107118108118109118110118111118112118113118114118115118116118117118118118119118120118121118122118123118124118125118126118127118128118129118130118131118132118133118134118135118136118137118138118139118140118141118142118143118144118145118146118147118148118149118150118151118152118153118154118155118156118157118158118159118160118161118162118163118164118165118166118167118168118169118170118171118172118173118174118175118176118177118178118179118180118181118182118183118184118185118186118187118188118189118190118191118192118193118194118195118196118197118198118199118200118201118202118203118204118205118206118207118208118209118210118211118212118213118214118215118216118217118218118219118220118221118222118223118224118225118226118227118228118229118230118231118232118233118234118235118236118237118238118239118240118241118242118243118244118245118246118247118248118249118250118251118252118253118254118255118256118257118258118259118260118261118262118263118264118265118266118267118268118269118270118271118272118273118274118275118276118277118278118279118280118281118282118283118284118285118286118287118288118289118290118291118292118293118294118295118296118297118298118299118300118301118302118303118304118305118306118307118308118309118310118311118312118313118314118315118316118317118318118319118320118321118322118323118324118325118326118327118328118329118330118331118332118333118334118335118336118337118338118339118340118341118342118343118344118345118346118347118348118349118350118351118352118353118354118355118356118357118358118359118360118361118362118363118364118365118366118367118368118369118370118371118372118373118374118375118376118377118378118379118380118381118382118383118384118385118386118387118388118389118390118391118392118393118394118395118396118397118398118399118400118401118402118403118404118405118406118407118408118409118410118411118412118413118414118415118416118417118418118419118420118421118422118423118424118425118426118427118428118429118430118431118432118433118434118435118436118437118438118439118440118441118442118443118444118445118446118447118448118449118450118451118452118453118454118455118456118457118458118459118460118461118462118463118464118465118466118467118468118469118470118471118472118473118474118475118476118477118478118479118480118481118482118483118484118485118486118487118488118489118490118491118492118493118494118495118496118497118498118499118500118501118502118503118504118505118506118507118508118509118510118511118512118513118514118515118516118517118518118519118520118521118522118523118524118525118526118527118528118529118530118531118532118533118534118535118536118537118538118539118540118541118542118543118544118545118546118547118548118549118550118551118552118553118554118555118556118557118558118559118560118561118562118563118564118565118566118567118568118569118570118571118572118573118574118575118576118577118578118579118580118581118582118583118584118585118586118587118588118589118590118591118592118593118594118595118596118597118598118599118600118601118602118603118604118605118606118607118608118609118610118611118612118613118614118615118616118617118618118619118620118621118622118623118624118625118626118627118628118629118630118631118632118633118634118635118636118637118638118639118640118641118642118643118644118645118646118647118648118649118650118651118652118653118654118655118656118657118658118659118660118661118662118663118664118665118666118667118668118669118670118671118672118673118674118675118676118677118678118679118680118681118682118683118684118685118686118687118688118689118690118691118692118693118694118695118696118697118698118699118700118701118702118703118704118705118706118707118708118709118710118711118712118713118714118715118716118717118718118719118720118721118722118723118724118725118726118727118728118729118730118731118732118733118734118735118736118737118738118739118740118741118742118743118744118745118746118747118748118749118750118751118752118753118754118755118756118757118758118759118760118761118762118763118764118765118766118767118768118769118770118771118772118773118774118775118776118777118778118779118780118781118782118783118784118785118786118787118788118789118790118791118792118793118794118795118796118797118798118799118800118801118802118803118804118805118806118807118808118809118810118811118812118813118814118815118816118817118818118819118820118821118822118823118824118825118826118827118828118829118830118831118832118833118834118835118836118837118838118839118840118841118842118843118844118845118846118847118848118849118850118851118852118853118854118855118856118857118858118859118860118861118862118863118864118865118866118867118868118869118870118871118872118873118874118875118876118877118878118879118880118881118882118883118884118885118886118887118888118889118890118891118892118893118894118895118896118897118898118899118900118901118902118903118904118905118906118907118908118909118910118911118912118913118914118915118916118917118918118919118920118921118922118923118924118925118926118927118928118929118930118931118932118933118934118935118936118937118938118939118940118941118942118943118944118945118946118947118948118949118950118951118952118953118954118955118956118957118958118959118960118961118962118963118964118965118966118967118968118969118970118971118972118973118974118975118976118977118978118979118980118981118982118983118984118985118986118987118988118989118990118991118992118993118994118995118996118997118998118999119000119001119002119003119004119005119006119007119008119009119010119011119012119013119014119015119016119017119018119019119020119021119022119023119024119025119026119027119028119029119030119031119032119033119034119035119036119037119038119039119040119041119042119043119044119045119046119047119048119049119050119051119052119053119054119055119056119057119058119059119060119061119062119063119064119065119066119067119068119069119070119071119072119073119074119075119076119077119078119079119080119081119082119083119084119085119086119087119088119089119090119091119092119093119094119095119096119097119098119099119100119101119102119103119104119105119106119107119108119109119110119111119112119113119114119115119116119117119118119119119120119121119122119123119124119125119126119127119128119129119130119131119132119133119134119135119136119137119138119139119140119141119142119143119144119145119146119147119148119149119150119151119152119153119154119155119156119157119158119159119160119161119162119163119164119165119166119167119168119169119170119171119172119173119174119175119176119177119178119179119180119181119182119183119184119185119186119187119188119189119190119191119192119193119194119195119196119197119198119199119200119201119202119203119204119205119206119207119208119209119210119211119212119213119214119215119216119217119218119219119220119221119222119223119224119225119226119227119228119229119230119231119232119233119234119235119236119237119238119239119240119241119242119243119244119245119246119247119248119249119250119251119252119253119254119255119256119257119258119259119260119261119262119263119264119265119266119267119268119269119270119271119272119273119274119275119276119277119278119279119280119281119282119283119284119285119286119287119288119289119290119291119292119293119294119295119296119297119298119299119300119301119302119303119304119305119306119307119308119309119310119311119312119313119314119315119316119317119318119319119320119321119322119323119324119325119326119327119328119329119330119331119332119333119334119335119336119337119338119339119340119341119342119343119344119345119346119347119348119349119350119351119352119353119354119355119356119357119358119359119360119361119362119363119364119365119366119367119368119369119370119371119372119373119374119375119376119377119378119379119380119381119382119383119384119385119386119387119388119389119390119391119392119393119394119395119396119397119398119399119400119401119402119403119404119405119406119407119408119409119410119411119412119413119414119415119416119417119418119419119420119421119422119423119424119425119426119427119428119429119430119431119432119433119434119435119436119437119438119439119440119441119442119443119444119445119446119447119448119449119450119451119452119453119454119455119456119457119458119459119460119461119462119463119464119465119466119467119468119469119470119471119472119473119474119475119476119477119478119479119480119481119482119483119484119485119486119487119488119489119490119491119492119493119494119495119496119497119498119499119500119501119502119503119504119505119506119507119508119509119510119511119512119513119514119515119516119517119518119519119520119521119522119523119524119525119526119527119528119529119530119531119532119533119534119535119536119537119538119539119540119541119542119543119544119545119546119547119548119549119550119551119552119553119554119555119556119557119558119559119560119561119562119563119564119565119566119567119568119569119570119571119572119573119574119575119576119577119578119579119580119581119582119583119584119585119586119587119588119589119590119591119592119593119594119595119596119597119598119599119600119601119602119603119604119605119606119607119608119609119610119611119612119613119614119615119616119617119618119619119620119621119622119623119624119625119626119627119628119629119630119631119632119633119634119635119636119637119638119639119640119641119642119643119644119645119646119647119648119649119650119651119652119653119654119655119656119657119658119659119660119661119662119663119664119665119666119667119668119669119670119671119672119673119674119675119676119677119678119679119680119681119682119683119684119685119686119687119688119689119690119691119692119693119694119695119696119697119698119699119700119701119702119703119704119705119706119707119708119709119710119711119712119713119714119715119716119717119718119719119720119721119722119723119724119725119726119727119728119729119730119731119732119733119734119735119736119737119738119739119740119741119742119743119744119745119746119747119748119749119750119751119752119753119754119755119756119757119758119759119760119761119762119763119764119765119766119767119768119769119770119771119772119773119774119775119776119777119778119779119780119781119782119783119784119785119786119787119788119789119790119791119792119793119794119795119796119797119798119799119800119801119802119803119804119805119806119807119808119809119810119811119812119813119814119815119816119817119818119819119820119821119822119823119824119825119826119827119828119829119830119831119832119833119834119835119836119837119838119839119840119841119842119843119844119845119846119847119848119849119850119851119852119853119854119855119856119857119858119859119860119861119862119863119864119865119866119867119868119869119870119871119872119873119874119875119876119877119878119879119880119881119882119883119884119885119886119887119888119889119890119891119892119893119894119895119896119897119898119899119900119901119902119903119904119905119906119907119908119909119910119911119912119913119914119915119916119917119918119919119920119921119922119923119924119925119926119927119928119929119930119931119932119933119934119935119936119937119938119939119940119941119942119943119944119945119946119947119948119949119950119951119952119953119954119955119956119957119958119959119960119961119962119963119964119965119966119967119968119969119970119971119972119973119974119975119976119977119978119979119980119981119982119983119984119985119986119987119988119989119990119991119992119993119994119995119996119997119998119999120000120001120002120003120004120005120006120007120008120009120010120011120012120013120014120015120016120017120018120019120020120021120022120023120024120025120026120027120028120029120030120031120032120033120034120035120036120037120038120039120040120041120042120043120044120045120046120047120048120049120050120051120052120053120054120055120056120057120058120059120060120061120062120063120064120065120066120067120068120069120070120071120072120073120074120075120076120077120078120079120080120081120082120083120084120085120086120087120088120089120090120091120092120093120094120095120096120097120098120099120100120101120102120103120104120105120106120107120108120109120110120111120112120113120114120115120116120117120118120119120120120121120122120123120124120125120126120127120128120129120130120131120132120133120134120135120136120137120138120139120140120141120142120143120144120145120146120147120148120149120150120151120152120153120154120155120156120157120158120159120160120161120162120163120164120165120166120167120168120169120170120171120172120173120174120175120176120177120178120179120180120181120182120183120184120185120186120187120188120189120190120191120192120193120194120195120196120197120198120199120200120201120202120203120204120205120206120207120208120209120210120211120212120213120214120215120216120217120218120219120220120221120222120223120224120225120226120227120228120229120230120231120232120233120234120235120236120237120238120239120240120241120242120243120244120245120246120247120248120249120250120251120252120253120254120255120256120257120258120259120260120261120262120263120264120265120266120267120268120269120270120271120272120273120274120275120276120277120278120279120280120281120282120283120284120285120286120287120288120289120290120291120292120293120294120295120296120297120298120299120300120301120302120303120304120305120306120307120308120309120310120311120312120313120314120315120316120317120318120319120320120321120322120323120324120325120326120327120328120329120330120331120332120333120334120335120336120337120338120339120340120341120342120343120344120345120346120347120348120349120350120351120352120353120354120355120356120357120358120359120360120361120362120363120364120365120366120367120368120369120370120371120372120373120374120375120376120377120378120379120380120381120382120383120384120385120386120387120388120389120390120391120392120393120394120395120396120397120398120399120400120401120402120403120404120405120406120407120408120409120410120411120412120413120414120415120416120417120418120419120420120421120422120423120424120425120426120427120428120429120430120431120432120433120434120435120436120437120438120439120440120441120442120443120444120445120446120447120448120449120450120451120452120453120454120455120456120457120458120459120460120461120462120463120464120465120466120467120468120469120470120471120472120473120474120475120476120477120478120479120480120481120482120483120484120485120486120487120488120489120490120491120492120493120494120495120496120497120498120499120500120501120502120503120504120505120506120507120508120509120510120511120512120513120514120515120516120517120518120519120520120521120522120523120524120525120526120527120528120529120530120531120532120533120534120535120536120537120538120539120540120541120542120543120544120545120546120547120548120549120550120551120552120553120554120555120556120557120558120559120560120561120562120563120564120565120566120567120568120569120570120571120572120573120574120575120576120577120578120579120580120581120582120583120584120585120586120587120588120589120590120591120592120593120594120595120596120597120598120599120600120601120602120603120604120605120606120607120608120609120610120611120612120613120614120615120616120617120618120619120620120621120622120623120624120625120626120627120628120629120630120631120632120633120634120635120636120637120638120639120640120641120642120643120644120645120646120647120648120649120650120651120652120653120654120655120656120657120658120659120660120661120662120663120664120665120666120667120668120669120670120671120672120673120674120675120676120677120678120679120680120681120682120683120684120685120686120687120688120689120690120691120692120693120694120695120696120697120698120699120700120701120702120703120704120705120706120707120708120709120710120711120712120713120714120715120716120717120718120719120720120721120722120723120724120725120726120727120728120729120730120731120732120733120734120735120736120737120738120739120740120741120742120743120744120745120746120747120748120749120750120751120752120753120754120755120756120757120758120759120760120761120762120763120764120765120766120767120768120769120770120771120772120773120774120775120776120777120778120779120780120781120782120783120784120785120786120787120788120789120790120791120792120793120794120795120796120797120798120799120800120801120802120803120804120805120806120807120808120809120810120811120812120813120814120815120816120817120818120819120820120821120822120823120824120825120826120827120828120829120830120831120832120833120834120835120836120837120838120839120840120841120842120843120844120845120846120847120848120849120850120851120852120853120854120855120856120857120858120859120860120861120862120863120864120865120866120867120868120869120870120871120872120873120874120875120876120877120878120879120880120881120882120883120884120885120886120887120888120889120890120891120892120893120894120895120896120897120898120899120900120901120902120903120904120905120906120907120908120909120910120911120912120913120914120915120916120917120918120919120920120921120922120923120924120925120926120927120928120929120930120931120932120933120934120935120936120937120938120939120940120941120942120943120944120945120946120947120948120949120950120951120952120953120954120955120956120957120958120959120960120961120962120963120964120965120966120967120968120969120970120971120972120973120974120975120976120977120978120979120980120981120982120983120984120985120986120987120988120989120990120991120992120993120994120995120996120997120998120999121000121001121002121003121004121005121006121007121008121009121010121011121012121013121014121015121016121017121018121019121020121021121022121023121024121025121026121027121028121029121030121031121032121033121034121035121036121037121038121039121040121041121042121043121044121045121046121047121048121049121050121051121052121053121054121055121056121057121058121059121060121061121062121063121064121065121066121067121068121069121070121071121072121073121074121075121076121077121078121079121080121081121082121083121084121085121086121087121088121089121090121091121092121093121094121095121096121097121098121099121100121101121102121103121104121105121106121107121108121109121110121111121112121113121114121115121116121117121118121119121120121121121122121123121124121125121126121127121128121129121130121131121132121133121134121135121136121137121138121139121140121141121142121143121144121145121146121147121148121149121150121151121152121153121154121155121156121157121158121159121160121161121162121163121164121165121166121167121168121169121170121171121172121173121174121175121176121177121178121179121180121181121182121183121184121185121186121187121188121189121190121191121192121193121194121195121196121197121198121199121200121201121202121203121204121205121206121207121208121209121210121211121212121213121214121215121216121217121218121219121220121221121222121223121224121225121226121227121228121229121230121231121232121233121234121235121236121237121238121239121240121241121242121243121244121245121246121247121248121249121250121251121252121253121254121255121256121257121258121259121260121261121262121263121264121265121266121267121268121269121270121271121272121273121274121275121276121277121278121279121280121281121282121283121284121285121286121287121288121289121290121291121292121293121294121295121296121297121298121299121300121301121302121303121304121305121306121307121308121309121310121311121312121313121314121315121316121317121318121319121320121321121322121323121324121325121326121327121328121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349121350121351121352121353121354121355121356121357121358121359121360121361121362121363121364121365121366121367121368121369121370121371121372121373121374121375121376121377121378121379121380121381121382121383121384121385121386121387121388121389121390121391121392121393121394121395121396121397121398121399121400121401121402121403121404121405121406121407121408121409121410121411121412121413121414121415121416121417121418121419121420121421121422121423121424121425121426121427121428121429121430121431121432121433121434121435121436121437121438121439121440121441121442121443121444121445121446121447121448121449121450121451121452121453121454121455121456121457121458121459121460121461121462121463121464121465121466121467121468121469121470121471121472121473121474121475121476121477121478121479121480121481121482121483121484121485121486121487121488121489121490121491121492121493121494121495121496121497121498121499121500121501121502121503121504121505121506121507121508121509121510121511121512121513121514121515121516121517121518121519121520121521121522121523121524121525121526121527121528121529121530121531121532121533121534121535121536121537121538121539121540121541121542121543121544121545121546121547121548121549121550121551121552121553121554121555121556121557121558121559121560121561121562121563121564121565121566121567121568121569121570121571121572121573121574121575121576121577121578121579121580121581121582121583121584121585121586121587121588121589121590121591121592121593121594121595121596121597121598121599121600121601121602121603121604121605121606121607121608121609121610121611121612121613121614121615121616121617121618121619121620121621121622121623121624121625121626121627121628121629121630121631121632121633121634121635121636121637121638121639121640121641121642121643121644121645121646121647121648121649121650121651121652121653121654121655121656121657121658121659121660121661121662121663121664121665121666121667121668121669121670121671121672121673121674121675121676121677121678121679121680121681121682121683121684121685121686121687121688121689121690121691121692121693121694121695121696121697121698121699121700121701121702121703121704121705121706121707121708121709121710121711121712121713121714121715121716121717121718121719121720121721121722121723121724121725121726121727121728121729121730121731121732121733121734121735121736121737121738121739121740121741121742121743121744121745121746121747121748121749121750121751121752121753121754121755121756121757121758121759121760121761121762121763121764121765121766121767121768121769121770121771121772121773121774121775121776121777121778121779121780121781121782121783121784121785121786121787121788121789121790121791121792121793121794121795121796121797121798121799121800121801121802121803121804121805121806121807121808121809121810121811121812121813121814121815121816121817121818121819121820121821121822121823121824121825121826121827121828121829121830121831121832121833121834121835121836121837121838121839121840121841121842121843121844121845121846121847121848121849121850121851121852121853121854121855121856121857121858121859121860121861121862121863121864121865121866121867121868121869121870121871121872121873121874121875121876121877121878121879121880121881121882121883121884121885121886121887121888121889121890121891121892121893121894121895121896121897121898121899121900121901121902121903121904121905121906121907121908121909121910121911121912121913121914121915121916121917121918121919121920121921121922121923121924121925121926121927121928121929121930121931121932121933121934121935121936121937121938121939121940121941121942121943121944121945121946121947121948121949121950121951121952121953121954121955121956121957121958121959121960121961121962121963121964121965121966121967121968121969121970121971121972121973121974121975121976121977121978121979121980121981121982121983121984121985121986121987121988121989121990121991121992121993121994121995121996121997121998121999122000122001122002122003122004122005122006122007122008122009122010122011122012122013122014122015122016122017122018122019122020122021122022122023122024122025122026122027122028122029122030122031122032122033122034122035122036122037122038122039122040122041122042122043122044122045122046122047122048122049122050122051122052122053122054122055122056122057122058122059122060122061122062122063122064122065122066122067122068122069122070122071122072122073122074122075122076122077122078122079122080122081122082122083122084122085122086122087122088122089122090122091122092122093122094122095122096122097122098122099122100122101122102122103122104122105122106122107122108122109122110122111122112122113122114122115122116122117122118122119122120122121122122122123122124122125122126122127122128122129122130122131122132122133122134122135122136122137122138122139122140122141122142122143122144122145122146122147122148122149122150122151122152122153122154122155122156122157122158122159122160122161122162122163122164122165122166122167122168122169122170122171122172122173122174122175122176122177122178122179122180122181122182122183122184122185122186122187122188122189122190122191122192122193122194122195122196122197122198122199122200122201122202122203122204122205122206122207122208122209122210122211122212122213122214122215122216122217122218122219122220122221122222122223122224122225122226122227122228122229122230122231122232122233122234122235122236122237122238122239122240122241122242122243122244122245122246122247122248122249122250122251122252122253122254122255122256122257122258122259122260122261122262122263122264122265122266122267122268122269122270122271122272122273122274122275122276122277122278122279122280122281122282122283122284122285122286122287122288122289122290122291122292122293122294122295122296122297122298122299122300122301122302122303122304122305122306122307122308122309122310122311122312122313122314122315122316122317122318122319122320122321122322122323122324122325122326122327122328122329122330122331122332122333122334122335122336122337122338122339122340122341122342122343122344122345122346122347122348122349122350122351122352122353122354122355122356122357122358122359122360122361122362122363122364122365122366122367122368122369122370122371122372122373122374122375122376122377122378122379122380122381122382122383122384122385122386122387122388122389122390122391122392122393122394122395122396122397122398122399122400122401122402122403122404122405122406122407122408122409122410122411122412122413122414122415122416122417122418122419122420122421122422122423122424122425122426122427122428122429122430122431122432122433122434122435122436122437122438122439122440122441122442122443122444122445122446122447122448122449122450122451122452122453122454122455122456122457122458122459122460122461122462122463122464122465122466122467122468122469122470122471122472122473122474122475122476122477122478122479122480122481122482122483122484122485122486122487122488122489122490122491122492122493122494122495122496122497122498122499122500122501122502122503122504122505122506122507122508122509122510122511122512122513122514122515122516122517122518122519122520122521122522122523122524122525122526122527122528122529122530122531122532122533122534122535122536122537122538122539122540122541122542122543122544122545122546122547122548122549122550122551122552122553122554122555122556122557122558122559122560122561122562122563122564122565122566122567122568122569122570122571122572122573122574122575122576122577122578122579122580122581122582122583122584122585122586122587122588122589122590122591122592122593122594122595122596122597122598122599122600122601122602122603122604122605122606122607122608122609122610122611122612122613122614122615122616122617122618122619122620122621122622122623122624122625122626122627122628122629122630122631122632122633122634122635122636122637122638122639122640122641122642122643122644122645122646122647122648122649122650122651122652122653122654122655122656122657122658122659122660122661122662122663122664122665122666122667122668122669122670122671122672122673122674122675122676122677122678122679122680122681122682122683122684122685122686122687122688122689122690122691122692122693122694122695122696122697122698122699122700122701122702122703122704122705122706122707122708122709122710122711122712122713122714122715122716122717122718122719122720122721122722122723122724122725122726122727122728122729122730122731122732122733122734122735122736122737122738122739122740122741122742122743122744122745122746122747122748122749122750122751122752122753122754122755122756122757122758122759122760122761122762122763122764122765122766122767122768122769122770122771122772122773122774122775122776122777122778122779122780122781122782122783122784122785122786122787122788122789122790122791122792122793122794122795122796122797122798122799122800122801122802122803122804122805122806122807122808122809122810122811122812122813122814122815122816122817122818122819122820122821122822122823122824122825122826122827122828122829122830122831122832122833122834122835122836122837122838122839122840122841122842122843122844122845122846122847122848122849122850122851122852122853122854122855122856122857122858122859122860122861122862122863122864122865122866122867122868122869122870122871122872122873122874122875122876122877122878122879122880122881122882122883122884122885122886122887122888122889122890122891122892122893122894122895122896122897122898122899122900122901122902122903122904122905122906122907122908122909122910122911122912122913122914122915122916122917122918122919122920122921122922122923122924122925122926122927122928122929122930122931122932122933122934122935122936122937122938122939122940122941122942122943122944122945122946122947122948122949122950122951122952122953122954122955122956122957122958122959122960122961122962122963122964122965122966122967122968122969122970122971122972122973122974122975122976122977122978122979122980122981122982122983122984122985122986122987122988122989122990122991122992122993122994122995122996122997122998122999123000123001123002123003123004123005123006123007123008123009123010123011123012123013123014123015123016123017123018123019123020123021123022123023123024123025123026123027123028123029123030123031123032123033123034123035123036123037123038123039123040123041123042123043123044123045123046123047123048123049123050123051123052123053123054123055123056123057123058123059123060123061123062123063123064123065123066123067123068123069123070123071123072123073123074123075123076123077123078123079123080123081123082123083123084123085123086123087123088123089123090123091123092123093123094123095123096123097123098123099123100123101123102123103123104123105123106123107123108123109123110123111123112123113123114123115123116123117123118123119123120123121123122123123123124123125123126123127123128123129123130123131123132123133123134123135123136123137123138123139123140123141123142123143123144123145123146123147123148123149123150123151123152123153123154123155123156123157123158123159123160123161123162123163123164123165123166123167123168123169123170123171123172123173123174123175123176123177123178123179123180123181123182123183123184123185123186123187123188123189123190123191123192123193123194123195123196123197123198123199123200123201123202123203123204123205123206123207123208123209123210123211123212123213123214123215123216123217123218123219123220123221123222123223123224123225123226123227123228123229123230123231123232123233123234123235123236123237123238123239123240123241123242123243123244123245123246123247123248123249123250123251123252123253123254123255123256123257123258123259123260123261123262123263123264123265123266123267123268123269123270123271123272123273123274123275123276123277123278123279123280123281123282123283123284123285123286123287123288123289123290123291123292123293123294123295123296123297123298123299123300123301123302123303123304123305123306123307123308123309123310123311123312123313123314123315123316123317123318123319123320123321123322123323123324123325123326123327123328123329123330123331123332123333123334123335123336123337123338123339123340123341123342123343123344123345123346123347123348123349123350123351123352123353123354123355123356123357123358123359123360123361123362123363123364123365123366123367123368123369123370123371123372123373123374123375123376123377123378123379123380123381123382123383123384123385123386123387123388123389123390123391123392123393123394123395123396123397123398123399123400123401123402123403123404123405123406123407123408123409123410123411123412123413123414123415123416123417123418123419123420123421123422123423123424123425123426123427123428123429123430123431123432123433123434123435123436123437123438123439123440123441123442123443123444123445123446123447123448123449123450123451123452123453123454123455123456123457123458123459123460123461123462123463123464123465123466123467123468123469123470123471123472123473123474123475123476123477123478123479123480123481123482123483123484123485123486123487123488123489123490123491123492123493123494123495123496123497123498123499123500123501123502123503123504123505123506123507123508123509123510123511123512123513123514123515123516123517123518123519123520123521123522123523123524123525123526123527123528123529123530123531123532123533123534123535123536123537123538123539123540123541123542123543123544123545123546123547123548123549123550123551123552123553123554123555123556123557123558123559123560123561123562123563123564123565123566123567123568123569123570123571123572123573123574123575123576123577123578123579123580123581123582123583123584123585123586123587123588123589123590123591123592123593123594123595123596123597123598123599123600123601123602123603123604123605123606123607123608123609123610123611123612123613123614123615123616123617123618123619123620123621123622123623123624123625123626123627123628123629123630123631123632123633123634123635123636123637123638123639123640123641123642123643123644123645123646123647123648123649123650123651123652123653123654123655123656123657123658123659123660123661123662123663123664123665123666123667123668123669123670123671123672123673123674123675123676123677123678123679123680123681123682123683123684123685123686123687123688123689123690123691123692123693123694123695123696123697123698123699123700123701123702123703123704123705123706123707123708123709123710123711123712123713123714123715123716123717123718123719123720123721123722123723123724123725123726123727123728123729123730123731123732123733123734123735123736123737123738123739123740123741123742123743123744123745123746123747123748123749123750123751123752123753123754123755123756123757123758123759123760123761123762123763123764123765123766123767123768123769123770123771123772123773123774123775123776123777123778123779123780123781123782123783123784123785123786123787123788123789123790123791123792123793123794123795123796123797123798123799123800123801123802123803123804123805123806123807123808123809123810123811123812123813123814123815123816123817123818123819123820123821123822123823123824123825123826123827123828123829123830123831123832123833123834123835123836123837123838123839123840123841123842123843123844123845123846123847123848123849123850123851123852123853123854123855123856123857123858123859123860123861123862123863123864123865123866123867123868123869123870123871123872123873123874123875123876123877123878123879123880123881123882123883123884123885123886123887123888123889123890123891123892123893123894123895123896123897123898123899123900123901123902123903123904123905123906123907123908123909123910123911123912123913123914123915123916123917123918123919123920123921123922123923123924123925123926123927123928123929123930123931123932123933123934123935123936123937123938123939123940123941123942123943123944123945123946123947123948123949123950123951123952123953123954123955123956123957123958123959123960123961123962123963123964123965123966123967123968123969123970123971123972123973123974123975123976123977123978123979123980123981123982123983123984123985123986123987123988123989123990123991123992123993123994123995123996123997123998123999124000124001124002124003124004124005124006124007124008124009124010124011124012124013124014124015124016124017124018124019124020124021124022124023124024124025124026124027124028124029124030124031124032124033124034124035124036124037124038124039124040124041124042124043124044124045124046124047124048124049124050124051124052124053124054124055124056124057124058124059124060124061124062124063124064124065124066124067124068124069124070124071124072124073124074124075124076124077124078124079124080124081124082124083124084124085124086124087124088124089124090124091124092124093124094124095124096124097124098124099124100124101124102124103124104124105124106124107124108124109124110124111124112124113124114124115124116124117124118124119124120124121124122124123124124124125124126124127124128124129124130124131124132124133124134124135124136124137124138124139124140124141124142124143124144124145124146124147124148124149124150124151124152124153124154124155124156124157124158124159124160124161124162124163124164124165124166124167124168124169124170124171124172124173124174124175124176124177124178124179124180124181124182124183124184124185124186124187124188124189124190124191124192124193124194124195124196124197124198124199124200124201124202124203124204124205124206124207124208124209124210124211124212124213124214124215124216124217124218124219124220124221124222124223124224124225124226124227124228124229124230124231124232124233124234124235124236124237124238124239124240124241124242124243124244124245124246124247124248124249124250124251124252124253124254124255124256124257124258124259124260124261124262124263124264124265124266124267124268124269124270124271124272124273124274124275124276124277124278124279124280124281124282124283124284124285124286124287124288124289124290124291124292124293124294124295124296124297124298124299124300124301124302124303124304124305124306124307124308124309124310124311124312124313124314124315124316124317124318124319124320124321124322124323124324124325124326124327124328124329124330124331124332124333124334124335124336124337124338124339124340124341124342124343124344124345124346124347124348124349124350124351124352124353124354124355124356124357124358124359124360124361124362124363124364124365124366124367124368124369124370124371124372124373124374124375124376124377124378124379124380124381124382124383124384124385124386124387124388124389124390124391124392124393124394124395124396124397124398124399124400124401124402124403124404124405124406124407124408124409124410124411124412124413124414124415124416124417124418124419124420124421124422124423124424124425124426124427124428124429124430124431124432124433124434124435124436124437124438124439124440124441124442124443124444124445124446124447124448124449124450124451124452124453124454124455124456124457124458124459124460124461124462124463124464124465124466124467124468124469124470124471124472124473124474124475124476124477124478124479124480124481124482124483124484124485124486124487124488124489124490124491124492124493124494124495124496124497124498124499124500124501124502124503124504124505124506124507124508124509124510124511124512124513124514124515124516124517124518124519124520124521124522124523124524124525124526124527124528124529124530124531124532124533124534124535124536124537124538124539124540124541124542124543124544124545124546124547124548124549124550124551124552124553124554124555124556124557124558124559124560124561124562124563124564124565124566124567124568124569124570124571124572124573124574124575124576124577124578124579124580124581124582124583124584124585124586124587124588124589124590124591124592124593124594124595124596124597124598124599124600124601124602124603124604124605124606124607124608124609124610124611124612124613124614124615124616124617124618124619124620124621124622124623124624124625124626124627124628124629124630124631124632124633124634124635124636124637124638124639124640124641124642124643124644124645124646124647124648124649124650124651124652124653124654124655124656124657124658124659124660124661124662124663124664124665124666124667124668124669124670124671124672124673124674124675124676124677124678124679124680124681124682124683124684124685124686124687124688124689124690124691124692124693124694124695124696124697124698124699124700124701124702124703124704124705124706124707124708124709124710124711124712124713124714124715124716124717124718124719124720124721124722124723124724124725124726124727124728124729124730124731124732124733124734124735124736124737124738124739124740124741124742124743124744124745124746124747124748124749124750124751124752124753124754124755124756124757124758124759124760124761124762124763124764124765124766124767124768124769124770124771124772124773124774124775124776124777124778124779124780124781124782124783124784124785124786124787124788124789124790124791124792124793124794124795124796124797124798124799124800124801124802124803124804124805124806124807124808124809124810124811124812124813124814124815124816124817124818124819124820124821124822124823124824124825124826124827124828124829124830124831124832124833124834124835124836124837124838124839124840124841124842124843124844124845124846124847124848124849124850124851124852124853124854124855124856124857124858124859124860124861124862124863124864124865124866124867124868124869124870124871124872124873124874124875124876124877124878124879124880124881124882124883124884124885124886124887124888124889124890124891124892124893124894124895124896124897124898124899124900124901124902124903124904124905124906124907124908124909124910124911124912124913124914124915124916124917124918124919124920124921124922124923124924124925124926124927124928124929124930124931124932124933124934124935124936124937124938124939124940124941124942124943124944124945124946124947124948124949124950124951124952124953124954124955124956124957124958124959124960124961124962124963124964124965124966124967124968124969124970124971124972124973124974124975124976124977124978124979124980124981124982124983124984124985124986124987124988124989124990124991124992124993124994124995124996124997124998124999125000125001125002125003125004125005125006125007125008125009125010125011125012125013125014125015125016125017125018125019125020125021125022125023125024125025125026125027125028125029125030125031125032125033125034125035125036125037125038125039125040125041125042125043125044125045125046125047125048125049125050125051125052125053125054125055125056125057125058125059125060125061125062125063125064125065125066125067125068125069125070125071125072125073125074125075125076125077125078125079125080125081125082125083125084125085125086125087125088125089125090125091125092125093125094125095125096125097125098125099125100125101125102125103125104125105125106125107125108125109125110125111125112125113125114125115125116125117125118125119125120125121125122125123125124125125125126125127125128125129125130125131125132125133125134125135125136125137125138125139125140125141125142125143125144125145125146125147125148125149125150125151125152125153125154125155125156125157125158125159125160125161125162125163125164125165125166125167125168125169125170125171125172125173125174125175125176125177125178125179125180125181125182125183125184125185125186125187125188125189125190125191125192125193125194125195125196125197125198125199125200125201125202125203125204125205125206125207125208125209125210125211125212125213125214125215125216125217125218125219125220125221125222125223125224125225125226125227125228125229125230125231125232125233125234125235125236125237125238125239125240125241125242125243125244125245125246125247125248125249125250125251125252125253125254125255125256125257125258125259125260125261125262125263125264125265125266125267125268125269125270125271125272125273125274125275125276125277125278125279125280125281125282125283125284125285125286125287125288125289125290125291125292125293125294125295125296125297125298125299125300125301125302125303125304125305125306125307125308125309125310125311125312125313125314125315125316125317125318125319125320125321125322125323125324125325125326125327125328125329125330125331125332125333125334125335125336125337125338125339125340125341125342125343125344125345125346125347125348125349125350125351125352125353125354125355125356125357125358125359125360125361125362125363125364125365125366125367125368125369125370125371125372125373125374125375125376125377125378125379125380125381125382125383125384125385125386125387125388125389125390125391125392125393125394125395125396125397125398125399125400125401125402125403125404125405125406125407125408125409125410125411125412125413125414125415125416125417125418125419125420125421125422125423125424125425125426125427125428125429125430125431125432125433125434125435125436125437125438125439125440125441125442125443125444125445125446125447125448125449125450125451125452125453125454125455125456125457125458125459125460125461125462125463125464125465125466125467125468125469125470125471125472125473125474125475125476125477125478125479125480125481125482125483125484125485125486125487125488125489125490125491125492125493125494125495125496125497125498125499125500125501125502125503125504125505125506125507125508125509125510125511125512125513125514125515125516125517125518125519125520125521125522125523125524125525125526125527125528125529125530125531125532125533125534125535125536125537125538125539125540125541125542125543125544125545125546125547125548125549125550125551125552125553125554125555125556125557125558125559125560125561125562125563125564125565125566125567125568125569125570125571125572125573125574125575125576125577125578125579125580125581125582125583125584125585125586125587125588125589125590125591125592125593125594125595125596125597125598125599125600125601125602125603125604125605125606125607125608125609125610125611125612125613125614125615125616125617125618125619125620125621125622125623125624125625125626125627125628125629125630125631125632125633125634125635125636125637125638125639125640125641125642125643125644125645125646125647125648125649125650125651125652125653125654125655125656125657125658125659125660125661125662125663125664125665125666125667125668125669125670125671125672125673125674125675125676125677125678125679125680125681125682125683125684125685125686125687125688125689125690125691125692125693125694125695125696125697125698125699125700125701125702125703125704125705125706125707125708125709125710125711125712125713125714125715125716125717125718125719125720125721125722125723125724125725125726125727125728125729125730125731125732125733125734125735125736125737125738125739125740125741125742125743125744125745125746125747125748125749125750125751125752125753125754125755125756125757125758125759125760125761125762125763125764125765125766125767125768125769125770125771125772125773125774125775125776125777125778125779125780125781125782125783125784125785125786125787125788125789125790125791125792125793125794125795125796125797125798125799125800125801125802125803125804125805125806125807125808125809125810125811125812125813125814125815125816125817125818125819125820125821125822125823125824125825125826125827125828125829125830125831125832125833125834125835125836125837125838125839125840125841125842125843125844125845125846125847125848125849125850125851125852125853125854125855125856125857125858125859125860125861125862125863125864125865125866125867125868125869125870125871125872125873125874125875125876125877125878125879125880125881125882125883125884125885125886125887125888125889125890125891125892125893125894125895125896125897125898125899125900125901125902125903125904125905125906125907125908125909125910125911125912125913125914125915125916125917125918125919125920125921125922125923125924125925125926125927125928125929125930125931125932125933125934125935125936125937125938125939125940125941125942125943125944125945125946125947125948125949125950125951125952125953125954125955125956125957125958125959125960125961125962125963125964125965125966125967125968125969125970125971125972125973125974125975125976125977125978125979125980125981125982125983125984125985125986125987125988125989125990125991125992125993125994125995125996125997125998125999126000126001126002126003126004126005126006126007126008126009126010126011126012126013126014126015126016126017126018126019126020126021126022126023126024126025126026126027126028126029126030126031126032126033126034126035126036126037126038126039126040126041126042126043126044126045126046126047126048126049126050126051126052126053126054126055126056126057126058126059126060126061126062126063126064126065126066126067126068126069126070126071126072126073126074126075126076126077126078126079126080126081126082126083126084126085126086126087126088126089126090126091126092126093126094126095126096126097126098126099126100126101126102126103126104126105126106126107126108126109126110126111126112126113126114126115126116126117126118126119126120126121126122126123126124126125126126126127126128126129126130126131126132126133126134126135126136126137126138126139126140126141126142126143126144126145126146126147126148126149126150126151126152126153126154126155126156126157126158126159126160126161126162126163126164126165126166126167126168126169126170126171126172126173126174126175126176126177126178126179126180126181126182126183126184126185126186126187126188126189126190126191126192126193126194126195126196126197126198126199126200126201126202126203126204126205126206126207126208126209126210126211126212126213126214126215126216126217126218126219126220126221126222126223126224126225126226126227126228126229126230126231126232126233126234126235126236126237126238126239126240126241126242126243126244126245126246126247126248126249126250126251126252126253126254126255126256126257126258126259126260126261126262126263126264126265126266126267126268126269126270126271126272126273126274126275126276126277126278126279126280126281126282126283126284126285126286126287126288126289126290126291126292126293126294126295126296126297126298126299126300126301126302126303126304126305126306126307126308126309126310126311126312126313126314126315126316126317126318126319126320126321126322126323126324126325126326126327126328126329126330126331126332126333126334126335126336126337126338126339126340126341126342126343126344126345126346126347126348126349126350126351126352126353126354126355126356126357126358126359126360126361126362126363126364126365126366126367126368126369126370126371126372126373126374126375126376126377126378126379126380126381126382126383126384126385126386126387126388126389126390126391126392126393126394126395126396126397126398126399126400126401126402126403126404126405126406126407126408126409126410126411126412126413126414126415126416126417126418126419126420126421126422126423126424126425126426126427126428126429126430126431126432126433126434126435126436126437126438126439126440126441126442126443126444126445126446126447126448126449126450126451126452126453126454126455126456126457126458126459126460126461126462126463126464126465126466126467126468126469126470126471126472126473126474126475126476126477126478126479126480126481126482126483126484126485126486126487126488126489126490126491126492126493126494126495126496126497126498126499126500126501126502126503126504126505126506126507126508126509126510126511126512126513126514126515126516126517126518126519126520126521126522126523126524126525126526126527126528126529126530126531126532126533126534126535126536126537126538126539126540126541126542126543126544126545126546126547126548126549126550126551126552126553126554126555126556126557126558126559126560126561126562126563126564126565126566126567126568126569126570126571126572126573126574126575126576126577126578126579126580126581126582126583126584126585126586126587126588126589126590126591126592126593126594126595126596126597126598126599126600126601126602126603126604126605126606126607126608126609126610126611126612126613126614126615126616126617126618126619126620126621126622126623126624126625126626126627126628126629126630126631126632126633126634126635126636126637126638126639126640126641126642126643126644126645126646126647126648126649126650126651126652126653126654126655126656126657126658126659126660126661126662126663126664126665126666126667126668126669126670126671126672126673126674126675126676126677126678126679126680126681126682126683126684126685126686126687126688126689126690126691126692126693126694126695126696126697126698126699126700126701126702126703126704126705126706126707126708126709126710126711126712126713126714126715126716126717126718126719126720126721126722126723126724126725126726126727126728126729126730126731126732126733126734126735126736126737126738126739126740126741126742126743126744126745126746126747126748126749126750126751126752126753126754126755126756126757126758126759126760126761126762126763126764126765126766126767126768126769126770126771126772126773126774126775126776126777126778126779126780126781126782126783126784126785126786126787126788126789126790126791126792126793126794126795126796126797126798126799126800126801126802126803126804126805126806126807126808126809126810126811126812126813126814126815126816126817126818126819126820126821126822126823126824126825126826126827126828126829126830126831126832126833126834126835126836126837126838126839126840126841126842126843126844126845126846126847126848126849126850126851126852126853126854126855126856126857126858126859126860126861126862126863126864
  1. diff -Nur linux-3.12.38/arch/arm/boot/dts/imx25.dtsi linux-rpi/arch/arm/boot/dts/imx25.dtsi
  2. --- linux-3.12.38/arch/arm/boot/dts/imx25.dtsi 2015-02-16 16:15:42.000000000 +0100
  3. +++ linux-rpi/arch/arm/boot/dts/imx25.dtsi 2015-03-10 17:26:49.674216697 +0100
  4. @@ -158,7 +158,7 @@
  5. #size-cells = <0>;
  6. compatible = "fsl,imx25-cspi", "fsl,imx35-cspi";
  7. reg = <0x43fa4000 0x4000>;
  8. - clocks = <&clks 78>, <&clks 78>;
  9. + clocks = <&clks 62>, <&clks 62>;
  10. clock-names = "ipg", "per";
  11. interrupts = <14>;
  12. status = "disabled";
  13. @@ -352,7 +352,7 @@
  14. compatible = "fsl,imx25-pwm", "fsl,imx27-pwm";
  15. #pwm-cells = <2>;
  16. reg = <0x53fa0000 0x4000>;
  17. - clocks = <&clks 106>, <&clks 52>;
  18. + clocks = <&clks 106>, <&clks 36>;
  19. clock-names = "ipg", "per";
  20. interrupts = <36>;
  21. };
  22. @@ -371,7 +371,7 @@
  23. compatible = "fsl,imx25-pwm", "fsl,imx27-pwm";
  24. #pwm-cells = <2>;
  25. reg = <0x53fa8000 0x4000>;
  26. - clocks = <&clks 107>, <&clks 52>;
  27. + clocks = <&clks 107>, <&clks 36>;
  28. clock-names = "ipg", "per";
  29. interrupts = <41>;
  30. };
  31. @@ -412,7 +412,7 @@
  32. pwm4: pwm@53fc8000 {
  33. compatible = "fsl,imx25-pwm", "fsl,imx27-pwm";
  34. reg = <0x53fc8000 0x4000>;
  35. - clocks = <&clks 108>, <&clks 52>;
  36. + clocks = <&clks 108>, <&clks 36>;
  37. clock-names = "ipg", "per";
  38. interrupts = <42>;
  39. };
  40. @@ -458,7 +458,7 @@
  41. compatible = "fsl,imx25-pwm", "fsl,imx27-pwm";
  42. #pwm-cells = <2>;
  43. reg = <0x53fe0000 0x4000>;
  44. - clocks = <&clks 105>, <&clks 52>;
  45. + clocks = <&clks 105>, <&clks 36>;
  46. clock-names = "ipg", "per";
  47. interrupts = <26>;
  48. };
  49. diff -Nur linux-3.12.38/arch/arm/boot/dts/Makefile.orig linux-rpi/arch/arm/boot/dts/Makefile.orig
  50. --- linux-3.12.38/arch/arm/boot/dts/Makefile.orig 1970-01-01 01:00:00.000000000 +0100
  51. +++ linux-rpi/arch/arm/boot/dts/Makefile.orig 2015-03-09 10:39:28.450893747 +0100
  52. @@ -0,0 +1,573 @@
  53. +ifeq ($(CONFIG_OF),y)
  54. +
  55. +# Keep at91 dtb files sorted alphabetically for each SoC
  56. +# rm9200
  57. +dtb-$(CONFIG_ARCH_AT91) += at91rm9200ek.dtb
  58. +dtb-$(CONFIG_ARCH_AT91) += mpa1600.dtb
  59. +# sam9260
  60. +dtb-$(CONFIG_ARCH_AT91) += animeo_ip.dtb
  61. +dtb-$(CONFIG_ARCH_AT91) += at91-qil_a9260.dtb
  62. +dtb-$(CONFIG_ARCH_AT91) += aks-cdu.dtb
  63. +dtb-$(CONFIG_ARCH_AT91) += ethernut5.dtb
  64. +dtb-$(CONFIG_ARCH_AT91) += evk-pro3.dtb
  65. +dtb-$(CONFIG_ARCH_AT91) += tny_a9260.dtb
  66. +dtb-$(CONFIG_ARCH_AT91) += usb_a9260.dtb
  67. +# sam9261
  68. +dtb-$(CONFIG_ARCH_AT91) += at91sam9261ek.dtb
  69. +# sam9263
  70. +dtb-$(CONFIG_ARCH_AT91) += at91sam9263ek.dtb
  71. +dtb-$(CONFIG_ARCH_AT91) += tny_a9263.dtb
  72. +dtb-$(CONFIG_ARCH_AT91) += usb_a9263.dtb
  73. +# sam9g20
  74. +dtb-$(CONFIG_ARCH_AT91) += at91-foxg20.dtb
  75. +dtb-$(CONFIG_ARCH_AT91) += at91sam9g20ek.dtb
  76. +dtb-$(CONFIG_ARCH_AT91) += at91sam9g20ek_2mmc.dtb
  77. +dtb-$(CONFIG_ARCH_AT91) += kizbox.dtb
  78. +dtb-$(CONFIG_ARCH_AT91) += tny_a9g20.dtb
  79. +dtb-$(CONFIG_ARCH_AT91) += usb_a9g20.dtb
  80. +dtb-$(CONFIG_ARCH_AT91) += usb_a9g20_lpw.dtb
  81. +# sam9g45
  82. +dtb-$(CONFIG_ARCH_AT91) += at91sam9m10g45ek.dtb
  83. +dtb-$(CONFIG_ARCH_AT91) += pm9g45.dtb
  84. +# sam9n12
  85. +dtb-$(CONFIG_ARCH_AT91) += at91sam9n12ek.dtb
  86. +# sam9rl
  87. +dtb-$(CONFIG_ARCH_AT91) += at91sam9rlek.dtb
  88. +# sam9x5
  89. +dtb-$(CONFIG_ARCH_AT91) += at91-ariag25.dtb
  90. +dtb-$(CONFIG_ARCH_AT91) += at91-cosino_mega2560.dtb
  91. +dtb-$(CONFIG_ARCH_AT91) += at91sam9g15ek.dtb
  92. +dtb-$(CONFIG_ARCH_AT91) += at91sam9g25ek.dtb
  93. +dtb-$(CONFIG_ARCH_AT91) += at91sam9g35ek.dtb
  94. +dtb-$(CONFIG_ARCH_AT91) += at91sam9x25ek.dtb
  95. +dtb-$(CONFIG_ARCH_AT91) += at91sam9x35ek.dtb
  96. +# sama5d3
  97. +dtb-$(CONFIG_ARCH_AT91) += at91-sama5d3_xplained.dtb
  98. +dtb-$(CONFIG_ARCH_AT91) += sama5d31ek.dtb
  99. +dtb-$(CONFIG_ARCH_AT91) += sama5d33ek.dtb
  100. +dtb-$(CONFIG_ARCH_AT91) += sama5d34ek.dtb
  101. +dtb-$(CONFIG_ARCH_AT91) += sama5d35ek.dtb
  102. +dtb-$(CONFIG_ARCH_AT91) += sama5d36ek.dtb
  103. +# sama5d4
  104. +dtb-$(CONFIG_ARCH_AT91) += at91-sama5d4ek.dtb
  105. +
  106. +dtb-$(CONFIG_ARCH_ATLAS6) += atlas6-evb.dtb
  107. +dtb-$(CONFIG_ARCH_AXXIA) += axm5516-amarillo.dtb
  108. +
  109. +# Raspberry Pi
  110. +ifeq ($(CONFIG_BCM2708_DT),y)
  111. + RPI_DT_OVERLAYS=y
  112. +endif
  113. +ifeq ($(CONFIG_BCM2709_DT),y)
  114. + RPI_DT_OVERLAYS=y
  115. +endif
  116. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b.dtb
  117. +dtb-$(CONFIG_BCM2708_DT) += bcm2708-rpi-b-plus.dtb
  118. +dtb-$(CONFIG_BCM2709_DT) += bcm2709-rpi-2-b.dtb
  119. +dtb-$(RPI_DT_OVERLAYS) += bmp085_i2c-sensor-overlay.dtb
  120. +dtb-$(RPI_DT_OVERLAYS) += ds1307-rtc-overlay.dtb
  121. +dtb-$(RPI_DT_OVERLAYS) += enc28j60-overlay.dtb
  122. +dtb-$(RPI_DT_OVERLAYS) += i2c-rtc-overlay.dtb
  123. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dac-overlay.dtb
  124. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-dacplus-overlay.dtb
  125. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-digi-overlay.dtb
  126. +dtb-$(RPI_DT_OVERLAYS) += hifiberry-amp-overlay.dtb
  127. +dtb-$(RPI_DT_OVERLAYS) += hy28a-overlay.dtb
  128. +dtb-$(RPI_DT_OVERLAYS) += hy28b-overlay.dtb
  129. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dac-overlay.dtb
  130. +dtb-$(RPI_DT_OVERLAYS) += iqaudio-dacplus-overlay.dtb
  131. +dtb-$(RPI_DT_OVERLAYS) += lirc-rpi-overlay.dtb
  132. +dtb-$(RPI_DT_OVERLAYS) += mz61581-overlay.dtb
  133. +dtb-$(RPI_DT_OVERLAYS) += pcf2127-rtc-overlay.dtb
  134. +dtb-$(RPI_DT_OVERLAYS) += pcf8523-rtc-overlay.dtb
  135. +dtb-$(RPI_DT_OVERLAYS) += piscreen-overlay.dtb
  136. +dtb-$(RPI_DT_OVERLAYS) += pitft28-resistive-overlay.dtb
  137. +dtb-$(RPI_DT_OVERLAYS) += pps-gpio-overlay.dtb
  138. +dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
  139. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-overlay.dtb
  140. +dtb-$(RPI_DT_OVERLAYS) += w1-gpio-pullup-overlay.dtb
  141. +dtb-$(RPI_DT_OVERLAYS) += spi-bcm2835-overlay.dtb
  142. +dtb-$(RPI_DT_OVERLAYS) += mcp2515-can0-overlay.dtb
  143. +dtb-$(CONFIG_ARCH_BCM2835) += bcm2835-rpi-b.dtb
  144. +
  145. +dtb-$(CONFIG_ARCH_BCM_5301X) += bcm4708-netgear-r6250.dtb
  146. +dtb-$(CONFIG_ARCH_BCM_63XX) += bcm963138dvt.dtb
  147. +dtb-$(CONFIG_ARCH_BCM_MOBILE) += bcm28155-ap.dtb \
  148. + bcm21664-garnet.dtb
  149. +dtb-$(CONFIG_ARCH_BERLIN) += \
  150. + berlin2-sony-nsz-gs7.dtb \
  151. + berlin2cd-google-chromecast.dtb \
  152. + berlin2q-marvell-dmp.dtb
  153. +dtb-$(CONFIG_ARCH_BRCMSTB) += \
  154. + bcm7445-bcm97445svmb.dtb
  155. +dtb-$(CONFIG_ARCH_DAVINCI) += da850-enbw-cmc.dtb \
  156. + da850-evm.dtb
  157. +dtb-$(CONFIG_ARCH_EFM32) += efm32gg-dk3750.dtb
  158. +dtb-$(CONFIG_ARCH_EXYNOS) += exynos4210-origen.dtb \
  159. + exynos4210-smdkv310.dtb \
  160. + exynos4210-trats.dtb \
  161. + exynos4210-universal_c210.dtb \
  162. + exynos4412-odroidu3.dtb \
  163. + exynos4412-odroidx.dtb \
  164. + exynos4412-odroidx2.dtb \
  165. + exynos4412-origen.dtb \
  166. + exynos4412-smdk4412.dtb \
  167. + exynos4412-tiny4412.dtb \
  168. + exynos4412-trats2.dtb \
  169. + exynos5250-arndale.dtb \
  170. + exynos5250-smdk5250.dtb \
  171. + exynos5250-snow.dtb \
  172. + exynos5260-xyref5260.dtb \
  173. + exynos5410-smdk5410.dtb \
  174. + exynos5420-arndale-octa.dtb \
  175. + exynos5420-peach-pit.dtb \
  176. + exynos5420-smdk5420.dtb \
  177. + exynos5440-sd5v1.dtb \
  178. + exynos5440-ssdk5440.dtb \
  179. + exynos5800-peach-pi.dtb
  180. +dtb-$(CONFIG_ARCH_HI3xxx) += hi3620-hi4511.dtb
  181. +dtb-$(CONFIG_ARCH_HIX5HD2) += hisi-x5hd2-dkb.dtb
  182. +dtb-$(CONFIG_ARCH_HIGHBANK) += highbank.dtb \
  183. + ecx-2000.dtb
  184. +dtb-$(CONFIG_ARCH_HIP04) += hip04-d01.dtb
  185. +dtb-$(CONFIG_ARCH_INTEGRATOR) += integratorap.dtb \
  186. + integratorcp.dtb
  187. +dtb-$(CONFIG_ARCH_KEYSTONE) += k2hk-evm.dtb \
  188. + k2l-evm.dtb \
  189. + k2e-evm.dtb
  190. +dtb-$(CONFIG_MACH_KIRKWOOD) += kirkwood-b3.dtb \
  191. + kirkwood-cloudbox.dtb \
  192. + kirkwood-d2net.dtb \
  193. + kirkwood-db-88f6281.dtb \
  194. + kirkwood-db-88f6282.dtb \
  195. + kirkwood-dns320.dtb \
  196. + kirkwood-dns325.dtb \
  197. + kirkwood-dockstar.dtb \
  198. + kirkwood-dreamplug.dtb \
  199. + kirkwood-ds109.dtb \
  200. + kirkwood-ds110jv10.dtb \
  201. + kirkwood-ds111.dtb \
  202. + kirkwood-ds209.dtb \
  203. + kirkwood-ds210.dtb \
  204. + kirkwood-ds212.dtb \
  205. + kirkwood-ds212j.dtb \
  206. + kirkwood-ds409.dtb \
  207. + kirkwood-ds409slim.dtb \
  208. + kirkwood-ds411.dtb \
  209. + kirkwood-ds411j.dtb \
  210. + kirkwood-ds411slim.dtb \
  211. + kirkwood-goflexnet.dtb \
  212. + kirkwood-guruplug-server-plus.dtb \
  213. + kirkwood-ib62x0.dtb \
  214. + kirkwood-iconnect.dtb \
  215. + kirkwood-iomega_ix2_200.dtb \
  216. + kirkwood-is2.dtb \
  217. + kirkwood-km_kirkwood.dtb \
  218. + kirkwood-laplug.dtb \
  219. + kirkwood-lschlv2.dtb \
  220. + kirkwood-lsxhl.dtb \
  221. + kirkwood-mplcec4.dtb \
  222. + kirkwood-mv88f6281gtw-ge.dtb \
  223. + kirkwood-net2big.dtb \
  224. + kirkwood-net5big.dtb \
  225. + kirkwood-netgear_readynas_duo_v2.dtb \
  226. + kirkwood-netgear_readynas_nv+_v2.dtb \
  227. + kirkwood-ns2.dtb \
  228. + kirkwood-ns2lite.dtb \
  229. + kirkwood-ns2max.dtb \
  230. + kirkwood-ns2mini.dtb \
  231. + kirkwood-nsa310.dtb \
  232. + kirkwood-nsa310a.dtb \
  233. + kirkwood-openblocks_a6.dtb \
  234. + kirkwood-openblocks_a7.dtb \
  235. + kirkwood-openrd-base.dtb \
  236. + kirkwood-openrd-client.dtb \
  237. + kirkwood-openrd-ultimate.dtb \
  238. + kirkwood-rd88f6192.dtb \
  239. + kirkwood-rd88f6281-z0.dtb \
  240. + kirkwood-rd88f6281-a.dtb \
  241. + kirkwood-rs212.dtb \
  242. + kirkwood-rs409.dtb \
  243. + kirkwood-rs411.dtb \
  244. + kirkwood-sheevaplug.dtb \
  245. + kirkwood-sheevaplug-esata.dtb \
  246. + kirkwood-t5325.dtb \
  247. + kirkwood-topkick.dtb \
  248. + kirkwood-ts219-6281.dtb \
  249. + kirkwood-ts219-6282.dtb \
  250. + kirkwood-ts419-6281.dtb \
  251. + kirkwood-ts419-6282.dtb
  252. +dtb-$(CONFIG_ARCH_LPC32XX) += ea3250.dtb phy3250.dtb
  253. +dtb-$(CONFIG_ARCH_MARCO) += marco-evb.dtb
  254. +dtb-$(CONFIG_MACH_MESON6) += meson6-atv1200.dtb
  255. +dtb-$(CONFIG_ARCH_MOXART) += moxart-uc7112lx.dtb
  256. +dtb-$(CONFIG_ARCH_MXC) += \
  257. + imx1-ads.dtb \
  258. + imx1-apf9328.dtb \
  259. + imx25-eukrea-mbimxsd25-baseboard.dtb \
  260. + imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dtb \
  261. + imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dtb \
  262. + imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dtb \
  263. + imx25-karo-tx25.dtb \
  264. + imx25-pdk.dtb \
  265. + imx27-apf27.dtb \
  266. + imx27-apf27dev.dtb \
  267. + imx27-eukrea-mbimxsd27-baseboard.dtb \
  268. + imx27-pdk.dtb \
  269. + imx27-phytec-phycore-rdk.dtb \
  270. + imx27-phytec-phycard-s-rdk.dtb \
  271. + imx31-bug.dtb \
  272. + imx35-eukrea-mbimxsd35-baseboard.dtb \
  273. + imx35-pdk.dtb \
  274. + imx50-evk.dtb \
  275. + imx51-apf51.dtb \
  276. + imx51-apf51dev.dtb \
  277. + imx51-babbage.dtb \
  278. + imx51-digi-connectcore-jsk.dtb \
  279. + imx51-eukrea-mbimxsd51-baseboard.dtb \
  280. + imx53-ard.dtb \
  281. + imx53-m53evk.dtb \
  282. + imx53-mba53.dtb \
  283. + imx53-qsb.dtb \
  284. + imx53-qsrb.dtb \
  285. + imx53-smd.dtb \
  286. + imx53-tx53-x03x.dtb \
  287. + imx53-tx53-x13x.dtb \
  288. + imx53-voipac-bsb.dtb \
  289. + imx6dl-aristainetos_4.dtb \
  290. + imx6dl-aristainetos_7.dtb \
  291. + imx6dl-cubox-i.dtb \
  292. + imx6dl-dfi-fs700-m60.dtb \
  293. + imx6dl-gw51xx.dtb \
  294. + imx6dl-gw52xx.dtb \
  295. + imx6dl-gw53xx.dtb \
  296. + imx6dl-gw54xx.dtb \
  297. + imx6dl-gw552x.dtb \
  298. + imx6dl-hummingboard.dtb \
  299. + imx6dl-nitrogen6x.dtb \
  300. + imx6dl-phytec-pbab01.dtb \
  301. + imx6dl-rex-basic.dtb \
  302. + imx6dl-riotboard.dtb \
  303. + imx6dl-sabreauto.dtb \
  304. + imx6dl-sabrelite.dtb \
  305. + imx6dl-sabresd.dtb \
  306. + imx6dl-tx6dl-comtft.dtb \
  307. + imx6dl-tx6u-801x.dtb \
  308. + imx6dl-tx6u-811x.dtb \
  309. + imx6dl-wandboard.dtb \
  310. + imx6dl-wandboard-revb1.dtb \
  311. + imx6q-arm2.dtb \
  312. + imx6q-cm-fx6.dtb \
  313. + imx6q-cubox-i.dtb \
  314. + imx6q-dfi-fs700-m60.dtb \
  315. + imx6q-dmo-edmqmx6.dtb \
  316. + imx6q-gk802.dtb \
  317. + imx6q-gw51xx.dtb \
  318. + imx6q-gw52xx.dtb \
  319. + imx6q-gw53xx.dtb \
  320. + imx6q-gw5400-a.dtb \
  321. + imx6q-gw54xx.dtb \
  322. + imx6q-gw552x.dtb \
  323. + imx6q-hummingboard.dtb \
  324. + imx6q-nitrogen6x.dtb \
  325. + imx6q-phytec-pbab01.dtb \
  326. + imx6q-rex-pro.dtb \
  327. + imx6q-sabreauto.dtb \
  328. + imx6q-sabrelite.dtb \
  329. + imx6q-sabresd.dtb \
  330. + imx6q-sbc6x.dtb \
  331. + imx6q-udoo.dtb \
  332. + imx6q-wandboard.dtb \
  333. + imx6q-wandboard-revb1.dtb \
  334. + imx6q-tx6q-1010.dtb \
  335. + imx6q-tx6q-1010-comtft.dtb \
  336. + imx6q-tx6q-1020.dtb \
  337. + imx6q-tx6q-1020-comtft.dtb \
  338. + imx6q-tx6q-1110.dtb \
  339. + imx6sl-evk.dtb \
  340. + imx6sx-sdb.dtb \
  341. + vf610-colibri-eval-v3.dtb \
  342. + vf610-cosmic.dtb \
  343. + vf610-twr.dtb
  344. +dtb-$(CONFIG_ARCH_MXS) += imx23-evk.dtb \
  345. + imx23-olinuxino.dtb \
  346. + imx23-stmp378x_devb.dtb \
  347. + imx28-apf28.dtb \
  348. + imx28-apf28dev.dtb \
  349. + imx28-apx4devkit.dtb \
  350. + imx28-cfa10036.dtb \
  351. + imx28-cfa10037.dtb \
  352. + imx28-cfa10049.dtb \
  353. + imx28-cfa10055.dtb \
  354. + imx28-cfa10056.dtb \
  355. + imx28-cfa10057.dtb \
  356. + imx28-cfa10058.dtb \
  357. + imx28-duckbill.dtb \
  358. + imx28-eukrea-mbmx283lc.dtb \
  359. + imx28-eukrea-mbmx287lc.dtb \
  360. + imx28-evk.dtb \
  361. + imx28-m28cu3.dtb \
  362. + imx28-m28evk.dtb \
  363. + imx28-sps1.dtb \
  364. + imx28-tx28.dtb
  365. +dtb-$(CONFIG_ARCH_NOMADIK) += ste-nomadik-s8815.dtb
  366. +dtb-$(CONFIG_ARCH_NSPIRE) += nspire-cx.dtb \
  367. + nspire-tp.dtb \
  368. + nspire-clp.dtb
  369. +dtb-$(CONFIG_ARCH_OMAP2) += omap2420-h4.dtb \
  370. + omap2420-n800.dtb \
  371. + omap2420-n810.dtb \
  372. + omap2420-n810-wimax.dtb \
  373. + omap2430-sdp.dtb
  374. +dtb-$(CONFIG_ARCH_OMAP3) += am3517-craneboard.dtb \
  375. + am3517-evm.dtb \
  376. + am3517_mt_ventoux.dtb \
  377. + omap3430-sdp.dtb \
  378. + omap3-beagle.dtb \
  379. + omap3-beagle-xm.dtb \
  380. + omap3-beagle-xm-ab.dtb \
  381. + omap3-cm-t3517.dtb \
  382. + omap3-cm-t3530.dtb \
  383. + omap3-cm-t3730.dtb \
  384. + omap3-devkit8000.dtb \
  385. + omap3-evm.dtb \
  386. + omap3-evm-37xx.dtb \
  387. + omap3-gta04a3.dtb \
  388. + omap3-gta04a4.dtb \
  389. + omap3-gta04a5.dtb \
  390. + omap3-ha.dtb \
  391. + omap3-ha-lcd.dtb \
  392. + omap3-igep0020.dtb \
  393. + omap3-igep0030.dtb \
  394. + omap3-ldp.dtb \
  395. + omap3-lilly-dbb056.dtb \
  396. + omap3-n900.dtb \
  397. + omap3-n9.dtb \
  398. + omap3-n950.dtb \
  399. + omap3-overo-alto35.dtb \
  400. + omap3-overo-chestnut43.dtb \
  401. + omap3-overo-gallop43.dtb \
  402. + omap3-overo-palo43.dtb \
  403. + omap3-overo-storm-alto35.dtb \
  404. + omap3-overo-storm-chestnut43.dtb \
  405. + omap3-overo-storm-gallop43.dtb \
  406. + omap3-overo-storm-palo43.dtb \
  407. + omap3-overo-storm-summit.dtb \
  408. + omap3-overo-storm-tobi.dtb \
  409. + omap3-overo-summit.dtb \
  410. + omap3-overo-tobi.dtb \
  411. + omap3-sbc-t3517.dtb \
  412. + omap3-sbc-t3530.dtb \
  413. + omap3-sbc-t3730.dtb \
  414. + omap3-thunder.dtb \
  415. + omap3-zoom3.dtb
  416. +dtb-$(CONFIG_SOC_AM33XX) += am335x-base0033.dtb \
  417. + am335x-bone.dtb \
  418. + am335x-boneblack.dtb \
  419. + am335x-evm.dtb \
  420. + am335x-evmsk.dtb \
  421. + am335x-nano.dtb \
  422. + am335x-pepper.dtb
  423. +dtb-$(CONFIG_ARCH_OMAP4) += omap4-duovero-parlor.dtb \
  424. + omap4-panda.dtb \
  425. + omap4-panda-a4.dtb \
  426. + omap4-panda-es.dtb \
  427. + omap4-sdp.dtb \
  428. + omap4-sdp-es23plus.dtb \
  429. + omap4-var-dvk-om44.dtb \
  430. + omap4-var-stk-om44.dtb
  431. +dtb-$(CONFIG_SOC_AM43XX) += am43x-epos-evm.dtb \
  432. + am437x-sk-evm.dtb \
  433. + am437x-gp-evm.dtb
  434. +dtb-$(CONFIG_SOC_OMAP5) += omap5-cm-t54.dtb \
  435. + omap5-sbc-t54.dtb \
  436. + omap5-uevm.dtb
  437. +dtb-$(CONFIG_SOC_DRA7XX) += dra7-evm.dtb \
  438. + dra72-evm.dtb
  439. +dtb-$(CONFIG_ARCH_ORION5X) += orion5x-lacie-d2-network.dtb \
  440. + orion5x-lacie-ethernet-disk-mini-v2.dtb \
  441. + orion5x-maxtor-shared-storage-2.dtb \
  442. + orion5x-rd88f5182-nas.dtb
  443. +dtb-$(CONFIG_ARCH_PRIMA2) += prima2-evb.dtb
  444. +dtb-$(CONFIG_ARCH_QCOM) += \
  445. + qcom-apq8064-cm-qs600.dtb \
  446. + qcom-apq8064-ifc6410.dtb \
  447. + qcom-apq8074-dragonboard.dtb \
  448. + qcom-apq8084-ifc6540.dtb \
  449. + qcom-apq8084-mtp.dtb \
  450. + qcom-ipq8064-ap148.dtb \
  451. + qcom-msm8660-surf.dtb \
  452. + qcom-msm8960-cdp.dtb \
  453. + qcom-msm8974-sony-xperia-honami.dtb
  454. +dtb-$(CONFIG_ARCH_ROCKCHIP) += \
  455. + rk3066a-bqcurie2.dtb \
  456. + rk3188-radxarock.dtb \
  457. + rk3288-evb-act8846.dtb \
  458. + rk3288-evb-rk808.dtb
  459. +dtb-$(CONFIG_ARCH_S3C24XX) += s3c2416-smdk2416.dtb
  460. +dtb-$(CONFIG_ARCH_S3C64XX) += s3c6410-mini6410.dtb \
  461. + s3c6410-smdk6410.dtb
  462. +dtb-$(CONFIG_ARCH_S5PV210) += s5pv210-aquila.dtb \
  463. + s5pv210-goni.dtb \
  464. + s5pv210-smdkc110.dtb \
  465. + s5pv210-smdkv210.dtb \
  466. + s5pv210-torbreck.dtb
  467. +dtb-$(CONFIG_ARCH_SHMOBILE_LEGACY) += r7s72100-genmai.dtb \
  468. + r8a7740-armadillo800eva.dtb \
  469. + r8a7778-bockw.dtb \
  470. + r8a7778-bockw-reference.dtb \
  471. + r8a7779-marzen.dtb \
  472. + r8a7791-koelsch.dtb \
  473. + r8a7790-lager.dtb \
  474. + sh73a0-kzm9g.dtb \
  475. + sh73a0-kzm9g-reference.dtb \
  476. + r8a73a4-ape6evm.dtb \
  477. + r8a73a4-ape6evm-reference.dtb \
  478. + sh7372-mackerel.dtb
  479. +dtb-$(CONFIG_ARCH_SHMOBILE_MULTI) += emev2-kzm9d.dtb \
  480. + r7s72100-genmai.dtb \
  481. + r8a7740-armadillo800eva.dtb \
  482. + r8a7791-henninger.dtb \
  483. + r8a7791-koelsch.dtb \
  484. + r8a7790-lager.dtb \
  485. + r8a7779-marzen.dtb \
  486. + r8a7794-alt.dtb
  487. +dtb-$(CONFIG_ARCH_SOCFPGA) += socfpga_arria5_socdk.dtb \
  488. + socfpga_cyclone5_socdk.dtb \
  489. + socfpga_cyclone5_sockit.dtb \
  490. + socfpga_cyclone5_socrates.dtb \
  491. + socfpga_vt.dtb
  492. +dtb-$(CONFIG_ARCH_SPEAR13XX) += spear1310-evb.dtb \
  493. + spear1340-evb.dtb
  494. +dtb-$(CONFIG_ARCH_SPEAR3XX)+= spear300-evb.dtb \
  495. + spear310-evb.dtb \
  496. + spear320-evb.dtb \
  497. + spear320-hmi.dtb
  498. +dtb-$(CONFIG_ARCH_SPEAR6XX)+= spear600-evb.dtb
  499. +dtb-$(CONFIG_ARCH_STI)+= stih407-b2120.dtb \
  500. + stih415-b2000.dtb \
  501. + stih415-b2020.dtb \
  502. + stih416-b2000.dtb \
  503. + stih416-b2020.dtb \
  504. + stih416-b2020e.dtb
  505. +dtb-$(CONFIG_MACH_SUN4I) += \
  506. + sun4i-a10-a1000.dtb \
  507. + sun4i-a10-ba10-tvbox.dtb \
  508. + sun4i-a10-cubieboard.dtb \
  509. + sun4i-a10-mini-xplus.dtb \
  510. + sun4i-a10-hackberry.dtb \
  511. + sun4i-a10-inet97fv2.dtb \
  512. + sun4i-a10-olinuxino-lime.dtb \
  513. + sun4i-a10-pcduino.dtb
  514. +dtb-$(CONFIG_MACH_SUN5I) += \
  515. + sun5i-a10s-olinuxino-micro.dtb \
  516. + sun5i-a10s-r7-tv-dongle.dtb \
  517. + sun5i-a13-hsg-h702.dtb \
  518. + sun5i-a13-olinuxino.dtb \
  519. + sun5i-a13-olinuxino-micro.dtb
  520. +dtb-$(CONFIG_MACH_SUN6I) += \
  521. + sun6i-a31-app4-evb1.dtb \
  522. + sun6i-a31-colombus.dtb \
  523. + sun6i-a31-hummingbird.dtb \
  524. + sun6i-a31-m9.dtb
  525. +dtb-$(CONFIG_MACH_SUN7I) += \
  526. + sun7i-a20-cubieboard2.dtb \
  527. + sun7i-a20-cubietruck.dtb \
  528. + sun7i-a20-hummingbird.dtb \
  529. + sun7i-a20-i12-tvbox.dtb \
  530. + sun7i-a20-olinuxino-lime.dtb \
  531. + sun7i-a20-olinuxino-micro.dtb \
  532. + sun7i-a20-pcduino3.dtb
  533. +dtb-$(CONFIG_MACH_SUN8I) += \
  534. + sun8i-a23-ippo-q8h-v5.dtb
  535. +dtb-$(CONFIG_ARCH_TEGRA) += tegra20-harmony.dtb \
  536. + tegra20-iris-512.dtb \
  537. + tegra20-medcom-wide.dtb \
  538. + tegra20-paz00.dtb \
  539. + tegra20-plutux.dtb \
  540. + tegra20-seaboard.dtb \
  541. + tegra20-tec.dtb \
  542. + tegra20-trimslice.dtb \
  543. + tegra20-ventana.dtb \
  544. + tegra20-whistler.dtb \
  545. + tegra30-apalis-eval.dtb \
  546. + tegra30-beaver.dtb \
  547. + tegra30-cardhu-a02.dtb \
  548. + tegra30-cardhu-a04.dtb \
  549. + tegra30-colibri-eval-v3.dtb \
  550. + tegra114-dalmore.dtb \
  551. + tegra114-roth.dtb \
  552. + tegra114-tn7.dtb \
  553. + tegra124-jetson-tk1.dtb \
  554. + tegra124-nyan-big.dtb \
  555. + tegra124-venice2.dtb
  556. +dtb-$(CONFIG_ARCH_U300) += ste-u300.dtb
  557. +dtb-$(CONFIG_ARCH_U8500) += ste-snowball.dtb \
  558. + ste-hrefprev60-stuib.dtb \
  559. + ste-hrefprev60-tvk.dtb \
  560. + ste-hrefv60plus-stuib.dtb \
  561. + ste-hrefv60plus-tvk.dtb \
  562. + ste-ccu8540.dtb \
  563. + ste-ccu9540.dtb
  564. +dtb-$(CONFIG_ARCH_VERSATILE) += versatile-ab.dtb \
  565. + versatile-pb.dtb
  566. +dtb-$(CONFIG_ARCH_VEXPRESS) += vexpress-v2p-ca5s.dtb \
  567. + vexpress-v2p-ca9.dtb \
  568. + vexpress-v2p-ca15-tc1.dtb \
  569. + vexpress-v2p-ca15_a7.dtb
  570. +dtb-$(CONFIG_ARCH_VIRT) += xenvm-4.2.dtb
  571. +dtb-$(CONFIG_ARCH_VT8500) += vt8500-bv07.dtb \
  572. + wm8505-ref.dtb \
  573. + wm8650-mid.dtb \
  574. + wm8750-apc8750.dtb \
  575. + wm8850-w70v2.dtb
  576. +dtb-$(CONFIG_ARCH_ZYNQ) += \
  577. + zynq-parallella.dtb \
  578. + zynq-zc702.dtb \
  579. + zynq-zc706.dtb \
  580. + zynq-zed.dtb
  581. +dtb-$(CONFIG_MACH_ARMADA_370) += \
  582. + armada-370-db.dtb \
  583. + armada-370-mirabox.dtb \
  584. + armada-370-netgear-rn102.dtb \
  585. + armada-370-netgear-rn104.dtb \
  586. + armada-370-rd.dtb
  587. +dtb-$(CONFIG_MACH_ARMADA_375) += \
  588. + armada-375-db.dtb
  589. +dtb-$(CONFIG_MACH_ARMADA_38X) += \
  590. + armada-385-db.dtb \
  591. + armada-385-rd.dtb
  592. +dtb-$(CONFIG_MACH_ARMADA_XP) += \
  593. + armada-xp-axpwifiap.dtb \
  594. + armada-xp-db.dtb \
  595. + armada-xp-gp.dtb \
  596. + armada-xp-lenovo-ix4-300d.dtb \
  597. + armada-xp-matrix.dtb \
  598. + armada-xp-netgear-rn2120.dtb \
  599. + armada-xp-openblocks-ax3-4.dtb
  600. +dtb-$(CONFIG_MACH_DOVE) += dove-cm-a510.dtb \
  601. + dove-cubox.dtb \
  602. + dove-cubox-es.dtb \
  603. + dove-d2plug.dtb \
  604. + dove-d3plug.dtb \
  605. + dove-dove-db.dtb
  606. +dtb-$(CONFIG_ARCH_MEDIATEK) += mt6589-aquaris5.dtb
  607. +
  608. +targets += dtbs dtbs_install
  609. +targets += $(dtb-y)
  610. +
  611. +endif
  612. +
  613. +# Enable fixups to support overlays on BCM2708 platforms
  614. +ifeq ($(RPI_DT_OVERLAYS),y)
  615. + DTC_FLAGS ?= -@
  616. +endif
  617. +
  618. +# *.dtb used to be generated in the directory above. Clean out the
  619. +# old build results so people don't accidentally use them.
  620. +dtbs: $(addprefix $(obj)/, $(dtb-y))
  621. + $(Q)rm -f $(obj)/../*.dtb
  622. +
  623. +clean-files := *.dtb
  624. +
  625. +dtbs_install: $(addsuffix _dtbinst_, $(dtb-y))
  626. diff -Nur linux-3.12.38/arch/arm/configs/bcmrpi_cutdown_defconfig linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig
  627. --- linux-3.12.38/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  628. +++ linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig 2015-03-10 17:26:49.690216697 +0100
  629. @@ -0,0 +1,463 @@
  630. +# CONFIG_LOCALVERSION_AUTO is not set
  631. +CONFIG_SYSVIPC=y
  632. +CONFIG_POSIX_MQUEUE=y
  633. +CONFIG_NO_HZ=y
  634. +CONFIG_HIGH_RES_TIMERS=y
  635. +CONFIG_IKCONFIG=y
  636. +CONFIG_IKCONFIG_PROC=y
  637. +# CONFIG_UID16 is not set
  638. +# CONFIG_KALLSYMS is not set
  639. +CONFIG_EMBEDDED=y
  640. +# CONFIG_VM_EVENT_COUNTERS is not set
  641. +# CONFIG_COMPAT_BRK is not set
  642. +CONFIG_SLAB=y
  643. +CONFIG_MODULES=y
  644. +CONFIG_MODULE_UNLOAD=y
  645. +CONFIG_MODVERSIONS=y
  646. +CONFIG_MODULE_SRCVERSION_ALL=y
  647. +# CONFIG_BLK_DEV_BSG is not set
  648. +CONFIG_PARTITION_ADVANCED=y
  649. +CONFIG_MAC_PARTITION=y
  650. +CONFIG_ARCH_BCM2708=y
  651. +CONFIG_AEABI=y
  652. +CONFIG_ZBOOT_ROM_TEXT=0x0
  653. +CONFIG_ZBOOT_ROM_BSS=0x0
  654. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  655. +CONFIG_CPU_IDLE=y
  656. +CONFIG_VFP=y
  657. +CONFIG_BINFMT_MISC=m
  658. +CONFIG_NET=y
  659. +CONFIG_PACKET=y
  660. +CONFIG_UNIX=y
  661. +CONFIG_XFRM_USER=y
  662. +CONFIG_NET_KEY=m
  663. +CONFIG_INET=y
  664. +CONFIG_IP_MULTICAST=y
  665. +CONFIG_IP_PNP=y
  666. +CONFIG_IP_PNP_DHCP=y
  667. +CONFIG_IP_PNP_RARP=y
  668. +CONFIG_SYN_COOKIES=y
  669. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  670. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  671. +# CONFIG_INET_XFRM_MODE_BEET is not set
  672. +# CONFIG_INET_LRO is not set
  673. +# CONFIG_INET_DIAG is not set
  674. +# CONFIG_IPV6 is not set
  675. +CONFIG_NET_PKTGEN=m
  676. +CONFIG_IRDA=m
  677. +CONFIG_IRLAN=m
  678. +CONFIG_IRCOMM=m
  679. +CONFIG_IRDA_ULTRA=y
  680. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  681. +CONFIG_IRDA_FAST_RR=y
  682. +CONFIG_IRTTY_SIR=m
  683. +CONFIG_KINGSUN_DONGLE=m
  684. +CONFIG_KSDAZZLE_DONGLE=m
  685. +CONFIG_KS959_DONGLE=m
  686. +CONFIG_USB_IRDA=m
  687. +CONFIG_SIGMATEL_FIR=m
  688. +CONFIG_MCS_FIR=m
  689. +CONFIG_BT=m
  690. +CONFIG_BT_RFCOMM=m
  691. +CONFIG_BT_RFCOMM_TTY=y
  692. +CONFIG_BT_BNEP=m
  693. +CONFIG_BT_BNEP_MC_FILTER=y
  694. +CONFIG_BT_BNEP_PROTO_FILTER=y
  695. +CONFIG_BT_HIDP=m
  696. +CONFIG_BT_HCIBTUSB=m
  697. +CONFIG_BT_HCIBCM203X=m
  698. +CONFIG_BT_HCIBPA10X=m
  699. +CONFIG_BT_HCIBFUSB=m
  700. +CONFIG_BT_HCIVHCI=m
  701. +CONFIG_BT_MRVL=m
  702. +CONFIG_BT_MRVL_SDIO=m
  703. +CONFIG_BT_ATH3K=m
  704. +CONFIG_CFG80211=m
  705. +CONFIG_MAC80211=m
  706. +CONFIG_MAC80211_RC_PID=y
  707. +CONFIG_MAC80211_MESH=y
  708. +CONFIG_WIMAX=m
  709. +CONFIG_NET_9P=m
  710. +CONFIG_NFC=m
  711. +CONFIG_NFC_PN533=m
  712. +CONFIG_DEVTMPFS=y
  713. +CONFIG_BLK_DEV_LOOP=y
  714. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  715. +CONFIG_BLK_DEV_NBD=m
  716. +CONFIG_BLK_DEV_RAM=y
  717. +CONFIG_CDROM_PKTCDVD=m
  718. +CONFIG_SCSI=y
  719. +# CONFIG_SCSI_PROC_FS is not set
  720. +CONFIG_BLK_DEV_SD=m
  721. +CONFIG_BLK_DEV_SR=m
  722. +CONFIG_SCSI_MULTI_LUN=y
  723. +# CONFIG_SCSI_LOWLEVEL is not set
  724. +CONFIG_NETDEVICES=y
  725. +CONFIG_NETCONSOLE=m
  726. +CONFIG_TUN=m
  727. +CONFIG_MDIO_BITBANG=m
  728. +CONFIG_PPP=m
  729. +CONFIG_PPP_BSDCOMP=m
  730. +CONFIG_PPP_DEFLATE=m
  731. +CONFIG_PPP_ASYNC=m
  732. +CONFIG_PPP_SYNC_TTY=m
  733. +CONFIG_SLIP=m
  734. +CONFIG_SLIP_COMPRESSED=y
  735. +CONFIG_USB_CATC=m
  736. +CONFIG_USB_KAWETH=m
  737. +CONFIG_USB_PEGASUS=m
  738. +CONFIG_USB_RTL8150=m
  739. +CONFIG_USB_USBNET=y
  740. +CONFIG_USB_NET_AX8817X=m
  741. +CONFIG_USB_NET_CDCETHER=m
  742. +CONFIG_USB_NET_CDC_EEM=m
  743. +CONFIG_USB_NET_DM9601=m
  744. +CONFIG_USB_NET_SMSC75XX=m
  745. +CONFIG_USB_NET_SMSC95XX=y
  746. +CONFIG_USB_NET_GL620A=m
  747. +CONFIG_USB_NET_NET1080=m
  748. +CONFIG_USB_NET_PLUSB=m
  749. +CONFIG_USB_NET_MCS7830=m
  750. +CONFIG_USB_NET_CDC_SUBSET=m
  751. +CONFIG_USB_ALI_M5632=y
  752. +CONFIG_USB_AN2720=y
  753. +CONFIG_USB_KC2190=y
  754. +# CONFIG_USB_NET_ZAURUS is not set
  755. +CONFIG_USB_NET_CX82310_ETH=m
  756. +CONFIG_USB_NET_KALMIA=m
  757. +CONFIG_USB_NET_INT51X1=m
  758. +CONFIG_USB_IPHETH=m
  759. +CONFIG_USB_SIERRA_NET=m
  760. +CONFIG_USB_VL600=m
  761. +CONFIG_LIBERTAS_THINFIRM=m
  762. +CONFIG_LIBERTAS_THINFIRM_USB=m
  763. +CONFIG_AT76C50X_USB=m
  764. +CONFIG_USB_ZD1201=m
  765. +CONFIG_USB_NET_RNDIS_WLAN=m
  766. +CONFIG_RTL8187=m
  767. +CONFIG_MAC80211_HWSIM=m
  768. +CONFIG_B43=m
  769. +CONFIG_B43LEGACY=m
  770. +CONFIG_HOSTAP=m
  771. +CONFIG_LIBERTAS=m
  772. +CONFIG_LIBERTAS_USB=m
  773. +CONFIG_LIBERTAS_SDIO=m
  774. +CONFIG_P54_COMMON=m
  775. +CONFIG_P54_USB=m
  776. +CONFIG_RT2X00=m
  777. +CONFIG_RT2500USB=m
  778. +CONFIG_RT73USB=m
  779. +CONFIG_RT2800USB=m
  780. +CONFIG_RT2800USB_RT53XX=y
  781. +CONFIG_RTL8192CU=m
  782. +CONFIG_ZD1211RW=m
  783. +CONFIG_MWIFIEX=m
  784. +CONFIG_MWIFIEX_SDIO=m
  785. +CONFIG_WIMAX_I2400M_USB=m
  786. +CONFIG_INPUT_POLLDEV=m
  787. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  788. +CONFIG_INPUT_JOYDEV=m
  789. +CONFIG_INPUT_EVDEV=m
  790. +# CONFIG_INPUT_KEYBOARD is not set
  791. +# CONFIG_INPUT_MOUSE is not set
  792. +CONFIG_INPUT_MISC=y
  793. +CONFIG_INPUT_AD714X=m
  794. +CONFIG_INPUT_ATI_REMOTE2=m
  795. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  796. +CONFIG_INPUT_POWERMATE=m
  797. +CONFIG_INPUT_YEALINK=m
  798. +CONFIG_INPUT_CM109=m
  799. +CONFIG_INPUT_UINPUT=m
  800. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  801. +CONFIG_INPUT_ADXL34X=m
  802. +CONFIG_INPUT_CMA3000=m
  803. +CONFIG_SERIO=m
  804. +CONFIG_SERIO_RAW=m
  805. +CONFIG_GAMEPORT=m
  806. +CONFIG_GAMEPORT_NS558=m
  807. +CONFIG_GAMEPORT_L4=m
  808. +# CONFIG_LEGACY_PTYS is not set
  809. +# CONFIG_DEVKMEM is not set
  810. +CONFIG_SERIAL_AMBA_PL011=y
  811. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  812. +# CONFIG_HW_RANDOM is not set
  813. +CONFIG_RAW_DRIVER=y
  814. +CONFIG_I2C=y
  815. +CONFIG_I2C_CHARDEV=m
  816. +CONFIG_I2C_BCM2708=m
  817. +CONFIG_SPI=y
  818. +CONFIG_SPI_BCM2708=m
  819. +CONFIG_GPIO_SYSFS=y
  820. +# CONFIG_HWMON is not set
  821. +CONFIG_WATCHDOG=y
  822. +CONFIG_BCM2708_WDT=m
  823. +CONFIG_FB=y
  824. +CONFIG_FB_BCM2708=y
  825. +CONFIG_FRAMEBUFFER_CONSOLE=y
  826. +CONFIG_LOGO=y
  827. +# CONFIG_LOGO_LINUX_MONO is not set
  828. +# CONFIG_LOGO_LINUX_VGA16 is not set
  829. +CONFIG_SOUND=y
  830. +CONFIG_SND=m
  831. +CONFIG_SND_SEQUENCER=m
  832. +CONFIG_SND_SEQ_DUMMY=m
  833. +CONFIG_SND_MIXER_OSS=m
  834. +CONFIG_SND_PCM_OSS=m
  835. +CONFIG_SND_SEQUENCER_OSS=y
  836. +CONFIG_SND_HRTIMER=m
  837. +CONFIG_SND_DUMMY=m
  838. +CONFIG_SND_ALOOP=m
  839. +CONFIG_SND_VIRMIDI=m
  840. +CONFIG_SND_MTPAV=m
  841. +CONFIG_SND_SERIAL_U16550=m
  842. +CONFIG_SND_MPU401=m
  843. +CONFIG_SND_BCM2835=m
  844. +CONFIG_SND_USB_AUDIO=m
  845. +CONFIG_SND_USB_UA101=m
  846. +CONFIG_SND_USB_CAIAQ=m
  847. +CONFIG_SND_USB_6FIRE=m
  848. +CONFIG_SOUND_PRIME=m
  849. +CONFIG_HID_A4TECH=m
  850. +CONFIG_HID_ACRUX=m
  851. +CONFIG_HID_APPLE=m
  852. +CONFIG_HID_BELKIN=m
  853. +CONFIG_HID_CHERRY=m
  854. +CONFIG_HID_CHICONY=m
  855. +CONFIG_HID_CYPRESS=m
  856. +CONFIG_HID_DRAGONRISE=m
  857. +CONFIG_HID_EMS_FF=m
  858. +CONFIG_HID_ELECOM=m
  859. +CONFIG_HID_EZKEY=m
  860. +CONFIG_HID_HOLTEK=m
  861. +CONFIG_HID_KEYTOUCH=m
  862. +CONFIG_HID_KYE=m
  863. +CONFIG_HID_UCLOGIC=m
  864. +CONFIG_HID_WALTOP=m
  865. +CONFIG_HID_GYRATION=m
  866. +CONFIG_HID_TWINHAN=m
  867. +CONFIG_HID_KENSINGTON=m
  868. +CONFIG_HID_LCPOWER=m
  869. +CONFIG_HID_LOGITECH=m
  870. +CONFIG_HID_MAGICMOUSE=m
  871. +CONFIG_HID_MICROSOFT=m
  872. +CONFIG_HID_MONTEREY=m
  873. +CONFIG_HID_MULTITOUCH=m
  874. +CONFIG_HID_NTRIG=m
  875. +CONFIG_HID_ORTEK=m
  876. +CONFIG_HID_PANTHERLORD=m
  877. +CONFIG_HID_PETALYNX=m
  878. +CONFIG_HID_PICOLCD=m
  879. +CONFIG_HID_ROCCAT=m
  880. +CONFIG_HID_SAMSUNG=m
  881. +CONFIG_HID_SPEEDLINK=m
  882. +CONFIG_HID_SUNPLUS=m
  883. +CONFIG_HID_GREENASIA=m
  884. +CONFIG_HID_SMARTJOYPLUS=m
  885. +CONFIG_HID_TOPSEED=m
  886. +CONFIG_HID_THRUSTMASTER=m
  887. +CONFIG_HID_ZEROPLUS=m
  888. +CONFIG_HID_ZYDACRON=m
  889. +CONFIG_HID_PID=y
  890. +CONFIG_USB_HIDDEV=y
  891. +CONFIG_USB=y
  892. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  893. +CONFIG_USB_MON=m
  894. +CONFIG_USB_DWCOTG=y
  895. +CONFIG_USB_STORAGE=y
  896. +CONFIG_USB_STORAGE_REALTEK=m
  897. +CONFIG_USB_STORAGE_DATAFAB=m
  898. +CONFIG_USB_STORAGE_FREECOM=m
  899. +CONFIG_USB_STORAGE_ISD200=m
  900. +CONFIG_USB_STORAGE_USBAT=m
  901. +CONFIG_USB_STORAGE_SDDR09=m
  902. +CONFIG_USB_STORAGE_SDDR55=m
  903. +CONFIG_USB_STORAGE_JUMPSHOT=m
  904. +CONFIG_USB_STORAGE_ALAUDA=m
  905. +CONFIG_USB_STORAGE_ONETOUCH=m
  906. +CONFIG_USB_STORAGE_KARMA=m
  907. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  908. +CONFIG_USB_STORAGE_ENE_UB6250=m
  909. +CONFIG_USB_MDC800=m
  910. +CONFIG_USB_MICROTEK=m
  911. +CONFIG_USB_SERIAL=m
  912. +CONFIG_USB_SERIAL_GENERIC=y
  913. +CONFIG_USB_SERIAL_AIRCABLE=m
  914. +CONFIG_USB_SERIAL_ARK3116=m
  915. +CONFIG_USB_SERIAL_BELKIN=m
  916. +CONFIG_USB_SERIAL_CH341=m
  917. +CONFIG_USB_SERIAL_WHITEHEAT=m
  918. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  919. +CONFIG_USB_SERIAL_CP210X=m
  920. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  921. +CONFIG_USB_SERIAL_EMPEG=m
  922. +CONFIG_USB_SERIAL_FTDI_SIO=m
  923. +CONFIG_USB_SERIAL_VISOR=m
  924. +CONFIG_USB_SERIAL_IPAQ=m
  925. +CONFIG_USB_SERIAL_IR=m
  926. +CONFIG_USB_SERIAL_EDGEPORT=m
  927. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  928. +CONFIG_USB_SERIAL_GARMIN=m
  929. +CONFIG_USB_SERIAL_IPW=m
  930. +CONFIG_USB_SERIAL_IUU=m
  931. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  932. +CONFIG_USB_SERIAL_KEYSPAN=m
  933. +CONFIG_USB_SERIAL_KLSI=m
  934. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  935. +CONFIG_USB_SERIAL_MCT_U232=m
  936. +CONFIG_USB_SERIAL_MOS7720=m
  937. +CONFIG_USB_SERIAL_MOS7840=m
  938. +CONFIG_USB_SERIAL_NAVMAN=m
  939. +CONFIG_USB_SERIAL_PL2303=m
  940. +CONFIG_USB_SERIAL_OTI6858=m
  941. +CONFIG_USB_SERIAL_QCAUX=m
  942. +CONFIG_USB_SERIAL_QUALCOMM=m
  943. +CONFIG_USB_SERIAL_SPCP8X5=m
  944. +CONFIG_USB_SERIAL_SAFE=m
  945. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  946. +CONFIG_USB_SERIAL_SYMBOL=m
  947. +CONFIG_USB_SERIAL_TI=m
  948. +CONFIG_USB_SERIAL_CYBERJACK=m
  949. +CONFIG_USB_SERIAL_XIRCOM=m
  950. +CONFIG_USB_SERIAL_OPTION=m
  951. +CONFIG_USB_SERIAL_OMNINET=m
  952. +CONFIG_USB_SERIAL_OPTICON=m
  953. +CONFIG_USB_SERIAL_SSU100=m
  954. +CONFIG_USB_SERIAL_DEBUG=m
  955. +CONFIG_USB_EMI62=m
  956. +CONFIG_USB_EMI26=m
  957. +CONFIG_USB_ADUTUX=m
  958. +CONFIG_USB_SEVSEG=m
  959. +CONFIG_USB_RIO500=m
  960. +CONFIG_USB_LEGOTOWER=m
  961. +CONFIG_USB_LCD=m
  962. +CONFIG_USB_LED=m
  963. +CONFIG_USB_CYPRESS_CY7C63=m
  964. +CONFIG_USB_CYTHERM=m
  965. +CONFIG_USB_IDMOUSE=m
  966. +CONFIG_USB_FTDI_ELAN=m
  967. +CONFIG_USB_APPLEDISPLAY=m
  968. +CONFIG_USB_LD=m
  969. +CONFIG_USB_TRANCEVIBRATOR=m
  970. +CONFIG_USB_IOWARRIOR=m
  971. +CONFIG_USB_TEST=m
  972. +CONFIG_USB_ISIGHTFW=m
  973. +CONFIG_USB_YUREX=m
  974. +CONFIG_MMC=y
  975. +CONFIG_MMC_SDHCI=y
  976. +CONFIG_MMC_SDHCI_PLTFM=y
  977. +CONFIG_MMC_SDHCI_BCM2708=y
  978. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  979. +CONFIG_MMC_BCM2835=y
  980. +CONFIG_MMC_BCM2835_DMA=y
  981. +CONFIG_UIO=m
  982. +CONFIG_UIO_PDRV_GENIRQ=m
  983. +# CONFIG_IOMMU_SUPPORT is not set
  984. +CONFIG_EXT4_FS=y
  985. +CONFIG_EXT4_FS_POSIX_ACL=y
  986. +CONFIG_EXT4_FS_SECURITY=y
  987. +CONFIG_REISERFS_FS=m
  988. +CONFIG_REISERFS_FS_XATTR=y
  989. +CONFIG_REISERFS_FS_POSIX_ACL=y
  990. +CONFIG_REISERFS_FS_SECURITY=y
  991. +CONFIG_JFS_FS=m
  992. +CONFIG_JFS_POSIX_ACL=y
  993. +CONFIG_JFS_SECURITY=y
  994. +CONFIG_XFS_FS=m
  995. +CONFIG_XFS_QUOTA=y
  996. +CONFIG_XFS_POSIX_ACL=y
  997. +CONFIG_XFS_RT=y
  998. +CONFIG_GFS2_FS=m
  999. +CONFIG_OCFS2_FS=m
  1000. +CONFIG_BTRFS_FS=m
  1001. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1002. +CONFIG_NILFS2_FS=m
  1003. +CONFIG_AUTOFS4_FS=y
  1004. +CONFIG_FUSE_FS=m
  1005. +CONFIG_CUSE=m
  1006. +CONFIG_FSCACHE=y
  1007. +CONFIG_CACHEFILES=y
  1008. +CONFIG_ISO9660_FS=m
  1009. +CONFIG_JOLIET=y
  1010. +CONFIG_ZISOFS=y
  1011. +CONFIG_UDF_FS=m
  1012. +CONFIG_MSDOS_FS=y
  1013. +CONFIG_VFAT_FS=y
  1014. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1015. +CONFIG_NTFS_FS=m
  1016. +CONFIG_TMPFS=y
  1017. +CONFIG_TMPFS_POSIX_ACL=y
  1018. +CONFIG_CONFIGFS_FS=y
  1019. +CONFIG_SQUASHFS=m
  1020. +CONFIG_SQUASHFS_XATTR=y
  1021. +CONFIG_SQUASHFS_LZO=y
  1022. +CONFIG_SQUASHFS_XZ=y
  1023. +CONFIG_NFS_FS=y
  1024. +CONFIG_NFS_V3_ACL=y
  1025. +CONFIG_NFS_V4=y
  1026. +CONFIG_ROOT_NFS=y
  1027. +CONFIG_NFS_FSCACHE=y
  1028. +CONFIG_CIFS=m
  1029. +CONFIG_CIFS_WEAK_PW_HASH=y
  1030. +CONFIG_CIFS_XATTR=y
  1031. +CONFIG_CIFS_POSIX=y
  1032. +CONFIG_9P_FS=m
  1033. +CONFIG_NLS_DEFAULT="utf8"
  1034. +CONFIG_NLS_CODEPAGE_437=y
  1035. +CONFIG_NLS_CODEPAGE_737=m
  1036. +CONFIG_NLS_CODEPAGE_775=m
  1037. +CONFIG_NLS_CODEPAGE_850=m
  1038. +CONFIG_NLS_CODEPAGE_852=m
  1039. +CONFIG_NLS_CODEPAGE_855=m
  1040. +CONFIG_NLS_CODEPAGE_857=m
  1041. +CONFIG_NLS_CODEPAGE_860=m
  1042. +CONFIG_NLS_CODEPAGE_861=m
  1043. +CONFIG_NLS_CODEPAGE_862=m
  1044. +CONFIG_NLS_CODEPAGE_863=m
  1045. +CONFIG_NLS_CODEPAGE_864=m
  1046. +CONFIG_NLS_CODEPAGE_865=m
  1047. +CONFIG_NLS_CODEPAGE_866=m
  1048. +CONFIG_NLS_CODEPAGE_869=m
  1049. +CONFIG_NLS_CODEPAGE_936=m
  1050. +CONFIG_NLS_CODEPAGE_950=m
  1051. +CONFIG_NLS_CODEPAGE_932=m
  1052. +CONFIG_NLS_CODEPAGE_949=m
  1053. +CONFIG_NLS_CODEPAGE_874=m
  1054. +CONFIG_NLS_ISO8859_8=m
  1055. +CONFIG_NLS_CODEPAGE_1250=m
  1056. +CONFIG_NLS_CODEPAGE_1251=m
  1057. +CONFIG_NLS_ASCII=y
  1058. +CONFIG_NLS_ISO8859_1=m
  1059. +CONFIG_NLS_ISO8859_2=m
  1060. +CONFIG_NLS_ISO8859_3=m
  1061. +CONFIG_NLS_ISO8859_4=m
  1062. +CONFIG_NLS_ISO8859_5=m
  1063. +CONFIG_NLS_ISO8859_6=m
  1064. +CONFIG_NLS_ISO8859_7=m
  1065. +CONFIG_NLS_ISO8859_9=m
  1066. +CONFIG_NLS_ISO8859_13=m
  1067. +CONFIG_NLS_ISO8859_14=m
  1068. +CONFIG_NLS_ISO8859_15=m
  1069. +CONFIG_NLS_KOI8_R=m
  1070. +CONFIG_NLS_KOI8_U=m
  1071. +CONFIG_NLS_UTF8=m
  1072. +# CONFIG_SCHED_DEBUG is not set
  1073. +# CONFIG_DEBUG_BUGVERBOSE is not set
  1074. +# CONFIG_FTRACE is not set
  1075. +# CONFIG_ARM_UNWIND is not set
  1076. +CONFIG_CRYPTO_AUTHENC=m
  1077. +CONFIG_CRYPTO_SEQIV=m
  1078. +CONFIG_CRYPTO_CBC=y
  1079. +CONFIG_CRYPTO_HMAC=y
  1080. +CONFIG_CRYPTO_XCBC=m
  1081. +CONFIG_CRYPTO_MD5=y
  1082. +CONFIG_CRYPTO_SHA1=y
  1083. +CONFIG_CRYPTO_SHA512=m
  1084. +CONFIG_CRYPTO_TGR192=m
  1085. +CONFIG_CRYPTO_WP512=m
  1086. +CONFIG_CRYPTO_CAST5=m
  1087. +CONFIG_CRYPTO_DES=y
  1088. +CONFIG_CRYPTO_DEFLATE=m
  1089. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1090. +# CONFIG_CRYPTO_HW is not set
  1091. +CONFIG_CRC_ITU_T=y
  1092. +CONFIG_LIBCRC32C=y
  1093. diff -Nur linux-3.12.38/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  1094. --- linux-3.12.38/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  1095. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2015-03-10 17:26:49.690216697 +0100
  1096. @@ -0,0 +1,1119 @@
  1097. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  1098. +# CONFIG_LOCALVERSION_AUTO is not set
  1099. +CONFIG_SYSVIPC=y
  1100. +CONFIG_POSIX_MQUEUE=y
  1101. +CONFIG_FHANDLE=y
  1102. +CONFIG_AUDIT=y
  1103. +CONFIG_NO_HZ=y
  1104. +CONFIG_HIGH_RES_TIMERS=y
  1105. +CONFIG_BSD_PROCESS_ACCT=y
  1106. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1107. +CONFIG_TASKSTATS=y
  1108. +CONFIG_TASK_DELAY_ACCT=y
  1109. +CONFIG_TASK_XACCT=y
  1110. +CONFIG_TASK_IO_ACCOUNTING=y
  1111. +CONFIG_IKCONFIG=y
  1112. +CONFIG_IKCONFIG_PROC=y
  1113. +CONFIG_CGROUP_FREEZER=y
  1114. +CONFIG_CGROUP_DEVICE=y
  1115. +CONFIG_CGROUP_CPUACCT=y
  1116. +CONFIG_RESOURCE_COUNTERS=y
  1117. +CONFIG_MEMCG=y
  1118. +CONFIG_BLK_CGROUP=y
  1119. +CONFIG_NAMESPACES=y
  1120. +CONFIG_SCHED_AUTOGROUP=y
  1121. +CONFIG_RELAY=y
  1122. +CONFIG_BLK_DEV_INITRD=y
  1123. +CONFIG_EMBEDDED=y
  1124. +# CONFIG_COMPAT_BRK is not set
  1125. +CONFIG_PROFILING=y
  1126. +CONFIG_OPROFILE=m
  1127. +CONFIG_KPROBES=y
  1128. +CONFIG_JUMP_LABEL=y
  1129. +CONFIG_MODULES=y
  1130. +CONFIG_MODULE_UNLOAD=y
  1131. +CONFIG_MODVERSIONS=y
  1132. +CONFIG_MODULE_SRCVERSION_ALL=y
  1133. +CONFIG_BLK_DEV_THROTTLING=y
  1134. +CONFIG_PARTITION_ADVANCED=y
  1135. +CONFIG_MAC_PARTITION=y
  1136. +CONFIG_CFQ_GROUP_IOSCHED=y
  1137. +CONFIG_ARCH_BCM2708=y
  1138. +CONFIG_PREEMPT=y
  1139. +CONFIG_AEABI=y
  1140. +CONFIG_CLEANCACHE=y
  1141. +CONFIG_FRONTSWAP=y
  1142. +CONFIG_CMA=y
  1143. +CONFIG_UACCESS_WITH_MEMCPY=y
  1144. +CONFIG_SECCOMP=y
  1145. +CONFIG_CC_STACKPROTECTOR=y
  1146. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1147. +CONFIG_ZBOOT_ROM_BSS=0x0
  1148. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  1149. +CONFIG_KEXEC=y
  1150. +CONFIG_CPU_FREQ=y
  1151. +CONFIG_CPU_FREQ_STAT=m
  1152. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  1153. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  1154. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  1155. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  1156. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  1157. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  1158. +CONFIG_CPU_IDLE=y
  1159. +CONFIG_VFP=y
  1160. +CONFIG_BINFMT_MISC=m
  1161. +CONFIG_NET=y
  1162. +CONFIG_PACKET=y
  1163. +CONFIG_UNIX=y
  1164. +CONFIG_XFRM_USER=y
  1165. +CONFIG_NET_KEY=m
  1166. +CONFIG_INET=y
  1167. +CONFIG_IP_MULTICAST=y
  1168. +CONFIG_IP_ADVANCED_ROUTER=y
  1169. +CONFIG_IP_MULTIPLE_TABLES=y
  1170. +CONFIG_IP_ROUTE_MULTIPATH=y
  1171. +CONFIG_IP_ROUTE_VERBOSE=y
  1172. +CONFIG_IP_PNP=y
  1173. +CONFIG_IP_PNP_DHCP=y
  1174. +CONFIG_IP_PNP_RARP=y
  1175. +CONFIG_NET_IPIP=m
  1176. +CONFIG_NET_IPGRE_DEMUX=m
  1177. +CONFIG_NET_IPGRE=m
  1178. +CONFIG_IP_MROUTE=y
  1179. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  1180. +CONFIG_IP_PIMSM_V1=y
  1181. +CONFIG_IP_PIMSM_V2=y
  1182. +CONFIG_SYN_COOKIES=y
  1183. +CONFIG_INET_AH=m
  1184. +CONFIG_INET_ESP=m
  1185. +CONFIG_INET_IPCOMP=m
  1186. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  1187. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  1188. +CONFIG_INET_XFRM_MODE_BEET=m
  1189. +CONFIG_INET_LRO=m
  1190. +CONFIG_INET_DIAG=m
  1191. +CONFIG_IPV6_PRIVACY=y
  1192. +CONFIG_INET6_AH=m
  1193. +CONFIG_INET6_ESP=m
  1194. +CONFIG_INET6_IPCOMP=m
  1195. +CONFIG_IPV6_TUNNEL=m
  1196. +CONFIG_IPV6_MULTIPLE_TABLES=y
  1197. +CONFIG_IPV6_MROUTE=y
  1198. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  1199. +CONFIG_IPV6_PIMSM_V2=y
  1200. +CONFIG_NETFILTER=y
  1201. +CONFIG_NF_CONNTRACK=m
  1202. +CONFIG_NF_CONNTRACK_ZONES=y
  1203. +CONFIG_NF_CONNTRACK_EVENTS=y
  1204. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  1205. +CONFIG_NF_CT_PROTO_DCCP=m
  1206. +CONFIG_NF_CT_PROTO_UDPLITE=m
  1207. +CONFIG_NF_CONNTRACK_AMANDA=m
  1208. +CONFIG_NF_CONNTRACK_FTP=m
  1209. +CONFIG_NF_CONNTRACK_H323=m
  1210. +CONFIG_NF_CONNTRACK_IRC=m
  1211. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  1212. +CONFIG_NF_CONNTRACK_SNMP=m
  1213. +CONFIG_NF_CONNTRACK_PPTP=m
  1214. +CONFIG_NF_CONNTRACK_SANE=m
  1215. +CONFIG_NF_CONNTRACK_SIP=m
  1216. +CONFIG_NF_CONNTRACK_TFTP=m
  1217. +CONFIG_NF_CT_NETLINK=m
  1218. +CONFIG_NETFILTER_XT_SET=m
  1219. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  1220. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  1221. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  1222. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  1223. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  1224. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  1225. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  1226. +CONFIG_NETFILTER_XT_TARGET_LED=m
  1227. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  1228. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  1229. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  1230. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  1231. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  1232. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  1233. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  1234. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  1235. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  1236. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  1237. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  1238. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  1239. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  1240. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  1241. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  1242. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  1243. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  1244. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  1245. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  1246. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  1247. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  1248. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  1249. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  1250. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  1251. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  1252. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  1253. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  1254. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  1255. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  1256. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  1257. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  1258. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  1259. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  1260. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  1261. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  1262. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  1263. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  1264. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  1265. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  1266. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  1267. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  1268. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  1269. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  1270. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  1271. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  1272. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  1273. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  1274. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  1275. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  1276. +CONFIG_NETFILTER_XT_MATCH_U32=m
  1277. +CONFIG_IP_SET=m
  1278. +CONFIG_IP_SET_BITMAP_IP=m
  1279. +CONFIG_IP_SET_BITMAP_IPMAC=m
  1280. +CONFIG_IP_SET_BITMAP_PORT=m
  1281. +CONFIG_IP_SET_HASH_IP=m
  1282. +CONFIG_IP_SET_HASH_IPPORT=m
  1283. +CONFIG_IP_SET_HASH_IPPORTIP=m
  1284. +CONFIG_IP_SET_HASH_IPPORTNET=m
  1285. +CONFIG_IP_SET_HASH_NET=m
  1286. +CONFIG_IP_SET_HASH_NETPORT=m
  1287. +CONFIG_IP_SET_HASH_NETIFACE=m
  1288. +CONFIG_IP_SET_LIST_SET=m
  1289. +CONFIG_IP_VS=m
  1290. +CONFIG_IP_VS_PROTO_TCP=y
  1291. +CONFIG_IP_VS_PROTO_UDP=y
  1292. +CONFIG_IP_VS_PROTO_ESP=y
  1293. +CONFIG_IP_VS_PROTO_AH=y
  1294. +CONFIG_IP_VS_PROTO_SCTP=y
  1295. +CONFIG_IP_VS_RR=m
  1296. +CONFIG_IP_VS_WRR=m
  1297. +CONFIG_IP_VS_LC=m
  1298. +CONFIG_IP_VS_WLC=m
  1299. +CONFIG_IP_VS_LBLC=m
  1300. +CONFIG_IP_VS_LBLCR=m
  1301. +CONFIG_IP_VS_DH=m
  1302. +CONFIG_IP_VS_SH=m
  1303. +CONFIG_IP_VS_SED=m
  1304. +CONFIG_IP_VS_NQ=m
  1305. +CONFIG_IP_VS_FTP=m
  1306. +CONFIG_IP_VS_PE_SIP=m
  1307. +CONFIG_NF_CONNTRACK_IPV4=m
  1308. +CONFIG_IP_NF_IPTABLES=m
  1309. +CONFIG_IP_NF_MATCH_AH=m
  1310. +CONFIG_IP_NF_MATCH_ECN=m
  1311. +CONFIG_IP_NF_MATCH_TTL=m
  1312. +CONFIG_IP_NF_FILTER=m
  1313. +CONFIG_IP_NF_TARGET_REJECT=m
  1314. +CONFIG_IP_NF_TARGET_ULOG=m
  1315. +CONFIG_NF_NAT_IPV4=m
  1316. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  1317. +CONFIG_IP_NF_TARGET_NETMAP=m
  1318. +CONFIG_IP_NF_TARGET_REDIRECT=m
  1319. +CONFIG_IP_NF_MANGLE=m
  1320. +CONFIG_IP_NF_TARGET_ECN=m
  1321. +CONFIG_IP_NF_TARGET_TTL=m
  1322. +CONFIG_IP_NF_RAW=m
  1323. +CONFIG_IP_NF_ARPTABLES=m
  1324. +CONFIG_IP_NF_ARPFILTER=m
  1325. +CONFIG_IP_NF_ARP_MANGLE=m
  1326. +CONFIG_NF_CONNTRACK_IPV6=m
  1327. +CONFIG_IP6_NF_IPTABLES=m
  1328. +CONFIG_IP6_NF_MATCH_AH=m
  1329. +CONFIG_IP6_NF_MATCH_EUI64=m
  1330. +CONFIG_IP6_NF_MATCH_FRAG=m
  1331. +CONFIG_IP6_NF_MATCH_OPTS=m
  1332. +CONFIG_IP6_NF_MATCH_HL=m
  1333. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  1334. +CONFIG_IP6_NF_MATCH_MH=m
  1335. +CONFIG_IP6_NF_MATCH_RT=m
  1336. +CONFIG_IP6_NF_TARGET_HL=m
  1337. +CONFIG_IP6_NF_FILTER=m
  1338. +CONFIG_IP6_NF_TARGET_REJECT=m
  1339. +CONFIG_IP6_NF_MANGLE=m
  1340. +CONFIG_IP6_NF_RAW=m
  1341. +CONFIG_NF_NAT_IPV6=m
  1342. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  1343. +CONFIG_IP6_NF_TARGET_NPT=m
  1344. +CONFIG_BRIDGE_NF_EBTABLES=m
  1345. +CONFIG_BRIDGE_EBT_BROUTE=m
  1346. +CONFIG_BRIDGE_EBT_T_FILTER=m
  1347. +CONFIG_BRIDGE_EBT_T_NAT=m
  1348. +CONFIG_BRIDGE_EBT_802_3=m
  1349. +CONFIG_BRIDGE_EBT_AMONG=m
  1350. +CONFIG_BRIDGE_EBT_ARP=m
  1351. +CONFIG_BRIDGE_EBT_IP=m
  1352. +CONFIG_BRIDGE_EBT_IP6=m
  1353. +CONFIG_BRIDGE_EBT_LIMIT=m
  1354. +CONFIG_BRIDGE_EBT_MARK=m
  1355. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  1356. +CONFIG_BRIDGE_EBT_STP=m
  1357. +CONFIG_BRIDGE_EBT_VLAN=m
  1358. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  1359. +CONFIG_BRIDGE_EBT_DNAT=m
  1360. +CONFIG_BRIDGE_EBT_MARK_T=m
  1361. +CONFIG_BRIDGE_EBT_REDIRECT=m
  1362. +CONFIG_BRIDGE_EBT_SNAT=m
  1363. +CONFIG_BRIDGE_EBT_LOG=m
  1364. +CONFIG_BRIDGE_EBT_ULOG=m
  1365. +CONFIG_BRIDGE_EBT_NFLOG=m
  1366. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  1367. +CONFIG_ATM=m
  1368. +CONFIG_L2TP=m
  1369. +CONFIG_L2TP_V3=y
  1370. +CONFIG_L2TP_IP=m
  1371. +CONFIG_L2TP_ETH=m
  1372. +CONFIG_BRIDGE=m
  1373. +CONFIG_VLAN_8021Q=m
  1374. +CONFIG_VLAN_8021Q_GVRP=y
  1375. +CONFIG_ATALK=m
  1376. +CONFIG_NET_SCHED=y
  1377. +CONFIG_NET_SCH_CBQ=m
  1378. +CONFIG_NET_SCH_HTB=m
  1379. +CONFIG_NET_SCH_HFSC=m
  1380. +CONFIG_NET_SCH_PRIO=m
  1381. +CONFIG_NET_SCH_MULTIQ=m
  1382. +CONFIG_NET_SCH_RED=m
  1383. +CONFIG_NET_SCH_SFB=m
  1384. +CONFIG_NET_SCH_SFQ=m
  1385. +CONFIG_NET_SCH_TEQL=m
  1386. +CONFIG_NET_SCH_TBF=m
  1387. +CONFIG_NET_SCH_GRED=m
  1388. +CONFIG_NET_SCH_DSMARK=m
  1389. +CONFIG_NET_SCH_NETEM=m
  1390. +CONFIG_NET_SCH_DRR=m
  1391. +CONFIG_NET_SCH_MQPRIO=m
  1392. +CONFIG_NET_SCH_CHOKE=m
  1393. +CONFIG_NET_SCH_QFQ=m
  1394. +CONFIG_NET_SCH_CODEL=m
  1395. +CONFIG_NET_SCH_FQ_CODEL=m
  1396. +CONFIG_NET_SCH_INGRESS=m
  1397. +CONFIG_NET_SCH_PLUG=m
  1398. +CONFIG_NET_CLS_BASIC=m
  1399. +CONFIG_NET_CLS_TCINDEX=m
  1400. +CONFIG_NET_CLS_ROUTE4=m
  1401. +CONFIG_NET_CLS_FW=m
  1402. +CONFIG_NET_CLS_U32=m
  1403. +CONFIG_CLS_U32_MARK=y
  1404. +CONFIG_NET_CLS_RSVP=m
  1405. +CONFIG_NET_CLS_RSVP6=m
  1406. +CONFIG_NET_CLS_FLOW=m
  1407. +CONFIG_NET_CLS_CGROUP=m
  1408. +CONFIG_NET_EMATCH=y
  1409. +CONFIG_NET_EMATCH_CMP=m
  1410. +CONFIG_NET_EMATCH_NBYTE=m
  1411. +CONFIG_NET_EMATCH_U32=m
  1412. +CONFIG_NET_EMATCH_META=m
  1413. +CONFIG_NET_EMATCH_TEXT=m
  1414. +CONFIG_NET_EMATCH_IPSET=m
  1415. +CONFIG_NET_CLS_ACT=y
  1416. +CONFIG_NET_ACT_POLICE=m
  1417. +CONFIG_NET_ACT_GACT=m
  1418. +CONFIG_GACT_PROB=y
  1419. +CONFIG_NET_ACT_MIRRED=m
  1420. +CONFIG_NET_ACT_IPT=m
  1421. +CONFIG_NET_ACT_NAT=m
  1422. +CONFIG_NET_ACT_PEDIT=m
  1423. +CONFIG_NET_ACT_SIMP=m
  1424. +CONFIG_NET_ACT_SKBEDIT=m
  1425. +CONFIG_NET_ACT_CSUM=m
  1426. +CONFIG_BATMAN_ADV=m
  1427. +CONFIG_OPENVSWITCH=m
  1428. +CONFIG_NET_PKTGEN=m
  1429. +CONFIG_HAMRADIO=y
  1430. +CONFIG_AX25=m
  1431. +CONFIG_NETROM=m
  1432. +CONFIG_ROSE=m
  1433. +CONFIG_MKISS=m
  1434. +CONFIG_6PACK=m
  1435. +CONFIG_BPQETHER=m
  1436. +CONFIG_BAYCOM_SER_FDX=m
  1437. +CONFIG_BAYCOM_SER_HDX=m
  1438. +CONFIG_YAM=m
  1439. +CONFIG_IRDA=m
  1440. +CONFIG_IRLAN=m
  1441. +CONFIG_IRNET=m
  1442. +CONFIG_IRCOMM=m
  1443. +CONFIG_IRDA_ULTRA=y
  1444. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1445. +CONFIG_IRDA_FAST_RR=y
  1446. +CONFIG_IRTTY_SIR=m
  1447. +CONFIG_KINGSUN_DONGLE=m
  1448. +CONFIG_KSDAZZLE_DONGLE=m
  1449. +CONFIG_KS959_DONGLE=m
  1450. +CONFIG_USB_IRDA=m
  1451. +CONFIG_SIGMATEL_FIR=m
  1452. +CONFIG_MCS_FIR=m
  1453. +CONFIG_BT=m
  1454. +CONFIG_BT_RFCOMM=m
  1455. +CONFIG_BT_RFCOMM_TTY=y
  1456. +CONFIG_BT_BNEP=m
  1457. +CONFIG_BT_BNEP_MC_FILTER=y
  1458. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1459. +CONFIG_BT_HIDP=m
  1460. +CONFIG_BT_HCIBTUSB=m
  1461. +CONFIG_BT_HCIBCM203X=m
  1462. +CONFIG_BT_HCIBPA10X=m
  1463. +CONFIG_BT_HCIBFUSB=m
  1464. +CONFIG_BT_HCIVHCI=m
  1465. +CONFIG_BT_MRVL=m
  1466. +CONFIG_BT_MRVL_SDIO=m
  1467. +CONFIG_BT_ATH3K=m
  1468. +CONFIG_BT_WILINK=m
  1469. +CONFIG_CFG80211=m
  1470. +CONFIG_CFG80211_WEXT=y
  1471. +CONFIG_MAC80211=m
  1472. +CONFIG_MAC80211_RC_PID=y
  1473. +CONFIG_MAC80211_MESH=y
  1474. +CONFIG_WIMAX=m
  1475. +CONFIG_RFKILL=m
  1476. +CONFIG_RFKILL_INPUT=y
  1477. +CONFIG_NET_9P=m
  1478. +CONFIG_NFC=m
  1479. +CONFIG_NFC_PN533=m
  1480. +CONFIG_DEVTMPFS=y
  1481. +CONFIG_DEVTMPFS_MOUNT=y
  1482. +CONFIG_DMA_CMA=y
  1483. +CONFIG_CMA_SIZE_MBYTES=5
  1484. +CONFIG_BLK_DEV_LOOP=y
  1485. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1486. +CONFIG_BLK_DEV_DRBD=m
  1487. +CONFIG_BLK_DEV_NBD=m
  1488. +CONFIG_BLK_DEV_RAM=y
  1489. +CONFIG_CDROM_PKTCDVD=m
  1490. +CONFIG_EEPROM_AT24=m
  1491. +CONFIG_SCSI=y
  1492. +# CONFIG_SCSI_PROC_FS is not set
  1493. +CONFIG_BLK_DEV_SD=y
  1494. +CONFIG_CHR_DEV_ST=m
  1495. +CONFIG_CHR_DEV_OSST=m
  1496. +CONFIG_BLK_DEV_SR=m
  1497. +CONFIG_CHR_DEV_SG=m
  1498. +CONFIG_SCSI_MULTI_LUN=y
  1499. +CONFIG_SCSI_ISCSI_ATTRS=y
  1500. +CONFIG_ISCSI_TCP=m
  1501. +CONFIG_ISCSI_BOOT_SYSFS=m
  1502. +CONFIG_MD=y
  1503. +CONFIG_MD_LINEAR=m
  1504. +CONFIG_MD_RAID0=m
  1505. +CONFIG_BLK_DEV_DM=m
  1506. +CONFIG_DM_CRYPT=m
  1507. +CONFIG_DM_SNAPSHOT=m
  1508. +CONFIG_DM_MIRROR=m
  1509. +CONFIG_DM_RAID=m
  1510. +CONFIG_DM_LOG_USERSPACE=m
  1511. +CONFIG_DM_ZERO=m
  1512. +CONFIG_DM_DELAY=m
  1513. +CONFIG_NETDEVICES=y
  1514. +CONFIG_BONDING=m
  1515. +CONFIG_DUMMY=m
  1516. +CONFIG_IFB=m
  1517. +CONFIG_MACVLAN=m
  1518. +CONFIG_NETCONSOLE=m
  1519. +CONFIG_TUN=m
  1520. +CONFIG_VETH=m
  1521. +CONFIG_MDIO_BITBANG=m
  1522. +CONFIG_PPP=m
  1523. +CONFIG_PPP_BSDCOMP=m
  1524. +CONFIG_PPP_DEFLATE=m
  1525. +CONFIG_PPP_FILTER=y
  1526. +CONFIG_PPP_MPPE=m
  1527. +CONFIG_PPP_MULTILINK=y
  1528. +CONFIG_PPPOATM=m
  1529. +CONFIG_PPPOE=m
  1530. +CONFIG_PPPOL2TP=m
  1531. +CONFIG_PPP_ASYNC=m
  1532. +CONFIG_PPP_SYNC_TTY=m
  1533. +CONFIG_SLIP=m
  1534. +CONFIG_SLIP_COMPRESSED=y
  1535. +CONFIG_SLIP_SMART=y
  1536. +CONFIG_USB_CATC=m
  1537. +CONFIG_USB_KAWETH=m
  1538. +CONFIG_USB_PEGASUS=m
  1539. +CONFIG_USB_RTL8150=m
  1540. +CONFIG_USB_RTL8152=m
  1541. +CONFIG_USB_USBNET=y
  1542. +CONFIG_USB_NET_AX8817X=m
  1543. +CONFIG_USB_NET_AX88179_178A=m
  1544. +CONFIG_USB_NET_CDCETHER=m
  1545. +CONFIG_USB_NET_CDC_EEM=m
  1546. +CONFIG_USB_NET_CDC_NCM=m
  1547. +CONFIG_USB_NET_CDC_MBIM=m
  1548. +CONFIG_USB_NET_DM9601=m
  1549. +CONFIG_USB_NET_SMSC75XX=m
  1550. +CONFIG_USB_NET_SMSC95XX=y
  1551. +CONFIG_USB_NET_GL620A=m
  1552. +CONFIG_USB_NET_NET1080=m
  1553. +CONFIG_USB_NET_PLUSB=m
  1554. +CONFIG_USB_NET_MCS7830=m
  1555. +CONFIG_USB_NET_CDC_SUBSET=m
  1556. +CONFIG_USB_ALI_M5632=y
  1557. +CONFIG_USB_AN2720=y
  1558. +CONFIG_USB_EPSON2888=y
  1559. +CONFIG_USB_KC2190=y
  1560. +CONFIG_USB_NET_ZAURUS=m
  1561. +CONFIG_USB_NET_CX82310_ETH=m
  1562. +CONFIG_USB_NET_KALMIA=m
  1563. +CONFIG_USB_NET_QMI_WWAN=m
  1564. +CONFIG_USB_HSO=m
  1565. +CONFIG_USB_NET_INT51X1=m
  1566. +CONFIG_USB_IPHETH=m
  1567. +CONFIG_USB_SIERRA_NET=m
  1568. +CONFIG_USB_VL600=m
  1569. +CONFIG_LIBERTAS_THINFIRM=m
  1570. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1571. +CONFIG_AT76C50X_USB=m
  1572. +CONFIG_USB_ZD1201=m
  1573. +CONFIG_USB_NET_RNDIS_WLAN=m
  1574. +CONFIG_RTL8187=m
  1575. +CONFIG_MAC80211_HWSIM=m
  1576. +CONFIG_ATH_CARDS=m
  1577. +CONFIG_ATH9K=m
  1578. +CONFIG_ATH9K_HTC=m
  1579. +CONFIG_CARL9170=m
  1580. +CONFIG_ATH6KL=m
  1581. +CONFIG_ATH6KL_USB=m
  1582. +CONFIG_AR5523=m
  1583. +CONFIG_B43=m
  1584. +# CONFIG_B43_PHY_N is not set
  1585. +CONFIG_B43LEGACY=m
  1586. +CONFIG_BRCMFMAC=m
  1587. +# CONFIG_BRCMFMAC_SDIO is not set
  1588. +CONFIG_BRCMFMAC_USB=y
  1589. +CONFIG_HOSTAP=m
  1590. +CONFIG_LIBERTAS=m
  1591. +CONFIG_LIBERTAS_USB=m
  1592. +CONFIG_LIBERTAS_SDIO=m
  1593. +CONFIG_P54_COMMON=m
  1594. +CONFIG_P54_USB=m
  1595. +CONFIG_RT2X00=m
  1596. +CONFIG_RT2500USB=m
  1597. +CONFIG_RT73USB=m
  1598. +CONFIG_RT2800USB=m
  1599. +CONFIG_RT2800USB_RT3573=y
  1600. +CONFIG_RT2800USB_RT53XX=y
  1601. +CONFIG_RT2800USB_RT55XX=y
  1602. +CONFIG_RT2800USB_UNKNOWN=y
  1603. +CONFIG_RTL8192CU=m
  1604. +CONFIG_ZD1211RW=m
  1605. +CONFIG_MWIFIEX=m
  1606. +CONFIG_MWIFIEX_SDIO=m
  1607. +CONFIG_WIMAX_I2400M_USB=m
  1608. +CONFIG_INPUT_POLLDEV=m
  1609. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1610. +CONFIG_INPUT_JOYDEV=m
  1611. +CONFIG_INPUT_EVDEV=m
  1612. +# CONFIG_INPUT_KEYBOARD is not set
  1613. +# CONFIG_INPUT_MOUSE is not set
  1614. +CONFIG_INPUT_JOYSTICK=y
  1615. +CONFIG_JOYSTICK_IFORCE=m
  1616. +CONFIG_JOYSTICK_IFORCE_USB=y
  1617. +CONFIG_JOYSTICK_XPAD=m
  1618. +CONFIG_JOYSTICK_XPAD_FF=y
  1619. +CONFIG_INPUT_MISC=y
  1620. +CONFIG_INPUT_AD714X=m
  1621. +CONFIG_INPUT_ATI_REMOTE2=m
  1622. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1623. +CONFIG_INPUT_POWERMATE=m
  1624. +CONFIG_INPUT_YEALINK=m
  1625. +CONFIG_INPUT_CM109=m
  1626. +CONFIG_INPUT_UINPUT=m
  1627. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1628. +CONFIG_INPUT_ADXL34X=m
  1629. +CONFIG_INPUT_CMA3000=m
  1630. +CONFIG_SERIO=m
  1631. +CONFIG_SERIO_RAW=m
  1632. +CONFIG_GAMEPORT=m
  1633. +CONFIG_GAMEPORT_NS558=m
  1634. +CONFIG_GAMEPORT_L4=m
  1635. +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
  1636. +# CONFIG_LEGACY_PTYS is not set
  1637. +# CONFIG_DEVKMEM is not set
  1638. +CONFIG_SERIAL_AMBA_PL011=y
  1639. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1640. +CONFIG_TTY_PRINTK=y
  1641. +CONFIG_HW_RANDOM=y
  1642. +CONFIG_HW_RANDOM_BCM2708=m
  1643. +CONFIG_RAW_DRIVER=y
  1644. +CONFIG_BRCM_CHAR_DRIVERS=y
  1645. +CONFIG_BCM_VC_CMA=y
  1646. +CONFIG_BCM_VC_SM=y
  1647. +CONFIG_I2C=y
  1648. +CONFIG_I2C_CHARDEV=m
  1649. +CONFIG_I2C_BCM2708=m
  1650. +CONFIG_SPI=y
  1651. +CONFIG_SPI_BCM2708=m
  1652. +CONFIG_SPI_SPIDEV=y
  1653. +CONFIG_PPS=m
  1654. +CONFIG_PPS_CLIENT_LDISC=m
  1655. +CONFIG_PPS_CLIENT_GPIO=m
  1656. +CONFIG_GPIO_SYSFS=y
  1657. +CONFIG_W1=m
  1658. +CONFIG_W1_MASTER_DS2490=m
  1659. +CONFIG_W1_MASTER_DS2482=m
  1660. +CONFIG_W1_MASTER_DS1WM=m
  1661. +CONFIG_W1_MASTER_GPIO=m
  1662. +CONFIG_W1_SLAVE_THERM=m
  1663. +CONFIG_W1_SLAVE_SMEM=m
  1664. +CONFIG_W1_SLAVE_DS2408=m
  1665. +CONFIG_W1_SLAVE_DS2413=m
  1666. +CONFIG_W1_SLAVE_DS2423=m
  1667. +CONFIG_W1_SLAVE_DS2431=m
  1668. +CONFIG_W1_SLAVE_DS2433=m
  1669. +CONFIG_W1_SLAVE_DS2760=m
  1670. +CONFIG_W1_SLAVE_DS2780=m
  1671. +CONFIG_W1_SLAVE_DS2781=m
  1672. +CONFIG_W1_SLAVE_DS28E04=m
  1673. +CONFIG_W1_SLAVE_BQ27000=m
  1674. +CONFIG_BATTERY_DS2760=m
  1675. +# CONFIG_HWMON is not set
  1676. +CONFIG_THERMAL=y
  1677. +CONFIG_THERMAL_BCM2835=y
  1678. +CONFIG_WATCHDOG=y
  1679. +CONFIG_BCM2708_WDT=m
  1680. +CONFIG_MEDIA_SUPPORT=m
  1681. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1682. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1683. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1684. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1685. +CONFIG_MEDIA_RC_SUPPORT=y
  1686. +CONFIG_MEDIA_CONTROLLER=y
  1687. +CONFIG_LIRC=m
  1688. +CONFIG_RC_DEVICES=y
  1689. +CONFIG_RC_ATI_REMOTE=m
  1690. +CONFIG_IR_IMON=m
  1691. +CONFIG_IR_MCEUSB=m
  1692. +CONFIG_IR_REDRAT3=m
  1693. +CONFIG_IR_STREAMZAP=m
  1694. +CONFIG_IR_IGUANA=m
  1695. +CONFIG_IR_TTUSBIR=m
  1696. +CONFIG_RC_LOOPBACK=m
  1697. +CONFIG_IR_GPIO_CIR=m
  1698. +CONFIG_MEDIA_USB_SUPPORT=y
  1699. +CONFIG_USB_VIDEO_CLASS=m
  1700. +CONFIG_USB_M5602=m
  1701. +CONFIG_USB_STV06XX=m
  1702. +CONFIG_USB_GL860=m
  1703. +CONFIG_USB_GSPCA_BENQ=m
  1704. +CONFIG_USB_GSPCA_CONEX=m
  1705. +CONFIG_USB_GSPCA_CPIA1=m
  1706. +CONFIG_USB_GSPCA_ETOMS=m
  1707. +CONFIG_USB_GSPCA_FINEPIX=m
  1708. +CONFIG_USB_GSPCA_JEILINJ=m
  1709. +CONFIG_USB_GSPCA_JL2005BCD=m
  1710. +CONFIG_USB_GSPCA_KINECT=m
  1711. +CONFIG_USB_GSPCA_KONICA=m
  1712. +CONFIG_USB_GSPCA_MARS=m
  1713. +CONFIG_USB_GSPCA_MR97310A=m
  1714. +CONFIG_USB_GSPCA_NW80X=m
  1715. +CONFIG_USB_GSPCA_OV519=m
  1716. +CONFIG_USB_GSPCA_OV534=m
  1717. +CONFIG_USB_GSPCA_OV534_9=m
  1718. +CONFIG_USB_GSPCA_PAC207=m
  1719. +CONFIG_USB_GSPCA_PAC7302=m
  1720. +CONFIG_USB_GSPCA_PAC7311=m
  1721. +CONFIG_USB_GSPCA_SE401=m
  1722. +CONFIG_USB_GSPCA_SN9C2028=m
  1723. +CONFIG_USB_GSPCA_SN9C20X=m
  1724. +CONFIG_USB_GSPCA_SONIXB=m
  1725. +CONFIG_USB_GSPCA_SONIXJ=m
  1726. +CONFIG_USB_GSPCA_SPCA500=m
  1727. +CONFIG_USB_GSPCA_SPCA501=m
  1728. +CONFIG_USB_GSPCA_SPCA505=m
  1729. +CONFIG_USB_GSPCA_SPCA506=m
  1730. +CONFIG_USB_GSPCA_SPCA508=m
  1731. +CONFIG_USB_GSPCA_SPCA561=m
  1732. +CONFIG_USB_GSPCA_SPCA1528=m
  1733. +CONFIG_USB_GSPCA_SQ905=m
  1734. +CONFIG_USB_GSPCA_SQ905C=m
  1735. +CONFIG_USB_GSPCA_SQ930X=m
  1736. +CONFIG_USB_GSPCA_STK014=m
  1737. +CONFIG_USB_GSPCA_STK1135=m
  1738. +CONFIG_USB_GSPCA_STV0680=m
  1739. +CONFIG_USB_GSPCA_SUNPLUS=m
  1740. +CONFIG_USB_GSPCA_T613=m
  1741. +CONFIG_USB_GSPCA_TOPRO=m
  1742. +CONFIG_USB_GSPCA_TV8532=m
  1743. +CONFIG_USB_GSPCA_VC032X=m
  1744. +CONFIG_USB_GSPCA_VICAM=m
  1745. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1746. +CONFIG_USB_GSPCA_ZC3XX=m
  1747. +CONFIG_USB_PWC=m
  1748. +CONFIG_VIDEO_CPIA2=m
  1749. +CONFIG_USB_ZR364XX=m
  1750. +CONFIG_USB_STKWEBCAM=m
  1751. +CONFIG_USB_S2255=m
  1752. +CONFIG_USB_SN9C102=m
  1753. +CONFIG_VIDEO_USBTV=m
  1754. +CONFIG_VIDEO_PVRUSB2=m
  1755. +CONFIG_VIDEO_HDPVR=m
  1756. +CONFIG_VIDEO_TLG2300=m
  1757. +CONFIG_VIDEO_USBVISION=m
  1758. +CONFIG_VIDEO_STK1160_COMMON=m
  1759. +CONFIG_VIDEO_AU0828=m
  1760. +CONFIG_VIDEO_CX231XX=m
  1761. +CONFIG_VIDEO_CX231XX_ALSA=m
  1762. +CONFIG_VIDEO_CX231XX_DVB=m
  1763. +CONFIG_VIDEO_TM6000=m
  1764. +CONFIG_VIDEO_TM6000_ALSA=m
  1765. +CONFIG_VIDEO_TM6000_DVB=m
  1766. +CONFIG_DVB_USB=m
  1767. +CONFIG_DVB_USB_A800=m
  1768. +CONFIG_DVB_USB_DIBUSB_MB=m
  1769. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1770. +CONFIG_DVB_USB_DIBUSB_MC=m
  1771. +CONFIG_DVB_USB_DIB0700=m
  1772. +CONFIG_DVB_USB_UMT_010=m
  1773. +CONFIG_DVB_USB_CXUSB=m
  1774. +CONFIG_DVB_USB_M920X=m
  1775. +CONFIG_DVB_USB_DIGITV=m
  1776. +CONFIG_DVB_USB_VP7045=m
  1777. +CONFIG_DVB_USB_VP702X=m
  1778. +CONFIG_DVB_USB_GP8PSK=m
  1779. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1780. +CONFIG_DVB_USB_TTUSB2=m
  1781. +CONFIG_DVB_USB_DTT200U=m
  1782. +CONFIG_DVB_USB_OPERA1=m
  1783. +CONFIG_DVB_USB_AF9005=m
  1784. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1785. +CONFIG_DVB_USB_PCTV452E=m
  1786. +CONFIG_DVB_USB_DW2102=m
  1787. +CONFIG_DVB_USB_CINERGY_T2=m
  1788. +CONFIG_DVB_USB_DTV5100=m
  1789. +CONFIG_DVB_USB_FRIIO=m
  1790. +CONFIG_DVB_USB_AZ6027=m
  1791. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1792. +CONFIG_DVB_USB_V2=m
  1793. +CONFIG_DVB_USB_AF9015=m
  1794. +CONFIG_DVB_USB_AF9035=m
  1795. +CONFIG_DVB_USB_ANYSEE=m
  1796. +CONFIG_DVB_USB_AU6610=m
  1797. +CONFIG_DVB_USB_AZ6007=m
  1798. +CONFIG_DVB_USB_CE6230=m
  1799. +CONFIG_DVB_USB_EC168=m
  1800. +CONFIG_DVB_USB_GL861=m
  1801. +CONFIG_DVB_USB_IT913X=m
  1802. +CONFIG_DVB_USB_LME2510=m
  1803. +CONFIG_DVB_USB_MXL111SF=m
  1804. +CONFIG_DVB_USB_RTL28XXU=m
  1805. +CONFIG_SMS_USB_DRV=m
  1806. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1807. +CONFIG_VIDEO_EM28XX=m
  1808. +CONFIG_VIDEO_EM28XX_ALSA=m
  1809. +CONFIG_VIDEO_EM28XX_DVB=m
  1810. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1811. +CONFIG_VIDEO_BCM2835=y
  1812. +CONFIG_VIDEO_BCM2835_MMAL=m
  1813. +CONFIG_RADIO_SI470X=y
  1814. +CONFIG_USB_SI470X=m
  1815. +CONFIG_I2C_SI470X=m
  1816. +CONFIG_USB_MR800=m
  1817. +CONFIG_USB_DSBR=m
  1818. +CONFIG_RADIO_SHARK=m
  1819. +CONFIG_RADIO_SHARK2=m
  1820. +CONFIG_RADIO_SI4713=m
  1821. +CONFIG_USB_KEENE=m
  1822. +CONFIG_USB_MA901=m
  1823. +CONFIG_RADIO_TEA5764=m
  1824. +CONFIG_RADIO_SAA7706H=m
  1825. +CONFIG_RADIO_TEF6862=m
  1826. +CONFIG_RADIO_WL1273=m
  1827. +CONFIG_RADIO_WL128X=m
  1828. +CONFIG_FB=y
  1829. +CONFIG_FB_BCM2708=y
  1830. +# CONFIG_BACKLIGHT_GENERIC is not set
  1831. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1832. +CONFIG_LOGO=y
  1833. +# CONFIG_LOGO_LINUX_MONO is not set
  1834. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1835. +CONFIG_SOUND=y
  1836. +CONFIG_SND=m
  1837. +CONFIG_SND_SEQUENCER=m
  1838. +CONFIG_SND_SEQ_DUMMY=m
  1839. +CONFIG_SND_MIXER_OSS=m
  1840. +CONFIG_SND_PCM_OSS=m
  1841. +CONFIG_SND_SEQUENCER_OSS=y
  1842. +CONFIG_SND_HRTIMER=m
  1843. +CONFIG_SND_DUMMY=m
  1844. +CONFIG_SND_ALOOP=m
  1845. +CONFIG_SND_VIRMIDI=m
  1846. +CONFIG_SND_MTPAV=m
  1847. +CONFIG_SND_SERIAL_U16550=m
  1848. +CONFIG_SND_MPU401=m
  1849. +CONFIG_SND_BCM2835=m
  1850. +CONFIG_SND_USB_AUDIO=m
  1851. +CONFIG_SND_USB_UA101=m
  1852. +CONFIG_SND_USB_CAIAQ=m
  1853. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1854. +CONFIG_SND_USB_6FIRE=m
  1855. +CONFIG_SND_SOC=m
  1856. +CONFIG_SND_BCM2708_SOC_I2S=m
  1857. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1858. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS=m
  1859. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1860. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP=m
  1861. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1862. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1863. +CONFIG_SND_SIMPLE_CARD=m
  1864. +CONFIG_SOUND_PRIME=m
  1865. +CONFIG_HIDRAW=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_ELO=m
  1877. +CONFIG_HID_EZKEY=m
  1878. +CONFIG_HID_HOLTEK=m
  1879. +CONFIG_HID_KEYTOUCH=m
  1880. +CONFIG_HID_KYE=m
  1881. +CONFIG_HID_UCLOGIC=m
  1882. +CONFIG_HID_WALTOP=m
  1883. +CONFIG_HID_GYRATION=m
  1884. +CONFIG_HID_TWINHAN=m
  1885. +CONFIG_HID_KENSINGTON=m
  1886. +CONFIG_HID_LCPOWER=m
  1887. +CONFIG_HID_LOGITECH=m
  1888. +CONFIG_HID_MAGICMOUSE=m
  1889. +CONFIG_HID_MICROSOFT=m
  1890. +CONFIG_HID_MONTEREY=m
  1891. +CONFIG_HID_MULTITOUCH=m
  1892. +CONFIG_HID_NTRIG=m
  1893. +CONFIG_HID_ORTEK=m
  1894. +CONFIG_HID_PANTHERLORD=m
  1895. +CONFIG_HID_PETALYNX=m
  1896. +CONFIG_HID_PICOLCD=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_THINGM=m
  1906. +CONFIG_HID_THRUSTMASTER=m
  1907. +CONFIG_HID_WACOM=m
  1908. +CONFIG_HID_WIIMOTE=m
  1909. +CONFIG_HID_XINMO=m
  1910. +CONFIG_HID_ZEROPLUS=m
  1911. +CONFIG_HID_ZYDACRON=m
  1912. +CONFIG_HID_PID=y
  1913. +CONFIG_USB_HIDDEV=y
  1914. +CONFIG_USB=y
  1915. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1916. +CONFIG_USB_MON=m
  1917. +CONFIG_USB_DWCOTG=y
  1918. +CONFIG_USB_PRINTER=m
  1919. +CONFIG_USB_STORAGE=y
  1920. +CONFIG_USB_STORAGE_REALTEK=m
  1921. +CONFIG_USB_STORAGE_DATAFAB=m
  1922. +CONFIG_USB_STORAGE_FREECOM=m
  1923. +CONFIG_USB_STORAGE_ISD200=m
  1924. +CONFIG_USB_STORAGE_USBAT=m
  1925. +CONFIG_USB_STORAGE_SDDR09=m
  1926. +CONFIG_USB_STORAGE_SDDR55=m
  1927. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1928. +CONFIG_USB_STORAGE_ALAUDA=m
  1929. +CONFIG_USB_STORAGE_ONETOUCH=m
  1930. +CONFIG_USB_STORAGE_KARMA=m
  1931. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1932. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1933. +CONFIG_USB_MDC800=m
  1934. +CONFIG_USB_MICROTEK=m
  1935. +CONFIG_USB_SERIAL=m
  1936. +CONFIG_USB_SERIAL_GENERIC=y
  1937. +CONFIG_USB_SERIAL_AIRCABLE=m
  1938. +CONFIG_USB_SERIAL_ARK3116=m
  1939. +CONFIG_USB_SERIAL_BELKIN=m
  1940. +CONFIG_USB_SERIAL_CH341=m
  1941. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1942. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1943. +CONFIG_USB_SERIAL_CP210X=m
  1944. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1945. +CONFIG_USB_SERIAL_EMPEG=m
  1946. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1947. +CONFIG_USB_SERIAL_VISOR=m
  1948. +CONFIG_USB_SERIAL_IPAQ=m
  1949. +CONFIG_USB_SERIAL_IR=m
  1950. +CONFIG_USB_SERIAL_EDGEPORT=m
  1951. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1952. +CONFIG_USB_SERIAL_F81232=m
  1953. +CONFIG_USB_SERIAL_GARMIN=m
  1954. +CONFIG_USB_SERIAL_IPW=m
  1955. +CONFIG_USB_SERIAL_IUU=m
  1956. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1957. +CONFIG_USB_SERIAL_KEYSPAN=m
  1958. +CONFIG_USB_SERIAL_KLSI=m
  1959. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1960. +CONFIG_USB_SERIAL_MCT_U232=m
  1961. +CONFIG_USB_SERIAL_METRO=m
  1962. +CONFIG_USB_SERIAL_MOS7720=m
  1963. +CONFIG_USB_SERIAL_MOS7840=m
  1964. +CONFIG_USB_SERIAL_NAVMAN=m
  1965. +CONFIG_USB_SERIAL_PL2303=m
  1966. +CONFIG_USB_SERIAL_OTI6858=m
  1967. +CONFIG_USB_SERIAL_QCAUX=m
  1968. +CONFIG_USB_SERIAL_QUALCOMM=m
  1969. +CONFIG_USB_SERIAL_SPCP8X5=m
  1970. +CONFIG_USB_SERIAL_SAFE=m
  1971. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1972. +CONFIG_USB_SERIAL_SYMBOL=m
  1973. +CONFIG_USB_SERIAL_TI=m
  1974. +CONFIG_USB_SERIAL_CYBERJACK=m
  1975. +CONFIG_USB_SERIAL_XIRCOM=m
  1976. +CONFIG_USB_SERIAL_OPTION=m
  1977. +CONFIG_USB_SERIAL_OMNINET=m
  1978. +CONFIG_USB_SERIAL_OPTICON=m
  1979. +CONFIG_USB_SERIAL_XSENS_MT=m
  1980. +CONFIG_USB_SERIAL_WISHBONE=m
  1981. +CONFIG_USB_SERIAL_ZTE=m
  1982. +CONFIG_USB_SERIAL_SSU100=m
  1983. +CONFIG_USB_SERIAL_QT2=m
  1984. +CONFIG_USB_SERIAL_DEBUG=m
  1985. +CONFIG_USB_EMI62=m
  1986. +CONFIG_USB_EMI26=m
  1987. +CONFIG_USB_ADUTUX=m
  1988. +CONFIG_USB_SEVSEG=m
  1989. +CONFIG_USB_RIO500=m
  1990. +CONFIG_USB_LEGOTOWER=m
  1991. +CONFIG_USB_LCD=m
  1992. +CONFIG_USB_LED=m
  1993. +CONFIG_USB_CYPRESS_CY7C63=m
  1994. +CONFIG_USB_CYTHERM=m
  1995. +CONFIG_USB_IDMOUSE=m
  1996. +CONFIG_USB_FTDI_ELAN=m
  1997. +CONFIG_USB_APPLEDISPLAY=m
  1998. +CONFIG_USB_LD=m
  1999. +CONFIG_USB_TRANCEVIBRATOR=m
  2000. +CONFIG_USB_IOWARRIOR=m
  2001. +CONFIG_USB_TEST=m
  2002. +CONFIG_USB_ISIGHTFW=m
  2003. +CONFIG_USB_YUREX=m
  2004. +CONFIG_USB_ATM=m
  2005. +CONFIG_USB_SPEEDTOUCH=m
  2006. +CONFIG_USB_CXACRU=m
  2007. +CONFIG_USB_UEAGLEATM=m
  2008. +CONFIG_USB_XUSBATM=m
  2009. +CONFIG_MMC=y
  2010. +CONFIG_MMC_BLOCK_MINORS=32
  2011. +CONFIG_MMC_SDHCI=y
  2012. +CONFIG_MMC_SDHCI_PLTFM=y
  2013. +CONFIG_MMC_SDHCI_BCM2708=y
  2014. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2015. +CONFIG_MMC_BCM2835=y
  2016. +CONFIG_MMC_BCM2835_DMA=y
  2017. +CONFIG_MMC_SPI=m
  2018. +CONFIG_LEDS_GPIO=m
  2019. +CONFIG_LEDS_TRIGGER_TIMER=y
  2020. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  2021. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  2022. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  2023. +CONFIG_LEDS_TRIGGER_CPU=y
  2024. +CONFIG_LEDS_TRIGGER_GPIO=y
  2025. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  2026. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  2027. +CONFIG_LEDS_TRIGGER_CAMERA=m
  2028. +CONFIG_RTC_CLASS=y
  2029. +# CONFIG_RTC_HCTOSYS is not set
  2030. +CONFIG_RTC_DRV_DS1307=m
  2031. +CONFIG_RTC_DRV_DS1374=m
  2032. +CONFIG_RTC_DRV_DS1672=m
  2033. +CONFIG_RTC_DRV_DS3232=m
  2034. +CONFIG_RTC_DRV_MAX6900=m
  2035. +CONFIG_RTC_DRV_RS5C372=m
  2036. +CONFIG_RTC_DRV_ISL1208=m
  2037. +CONFIG_RTC_DRV_ISL12022=m
  2038. +CONFIG_RTC_DRV_X1205=m
  2039. +CONFIG_RTC_DRV_PCF2127=m
  2040. +CONFIG_RTC_DRV_PCF8523=m
  2041. +CONFIG_RTC_DRV_PCF8563=m
  2042. +CONFIG_RTC_DRV_PCF8583=m
  2043. +CONFIG_RTC_DRV_M41T80=m
  2044. +CONFIG_RTC_DRV_BQ32K=m
  2045. +CONFIG_RTC_DRV_S35390A=m
  2046. +CONFIG_RTC_DRV_FM3130=m
  2047. +CONFIG_RTC_DRV_RX8581=m
  2048. +CONFIG_RTC_DRV_RX8025=m
  2049. +CONFIG_RTC_DRV_EM3027=m
  2050. +CONFIG_RTC_DRV_RV3029C2=m
  2051. +CONFIG_RTC_DRV_M41T93=m
  2052. +CONFIG_RTC_DRV_M41T94=m
  2053. +CONFIG_RTC_DRV_DS1305=m
  2054. +CONFIG_RTC_DRV_DS1390=m
  2055. +CONFIG_RTC_DRV_MAX6902=m
  2056. +CONFIG_RTC_DRV_R9701=m
  2057. +CONFIG_RTC_DRV_RS5C348=m
  2058. +CONFIG_RTC_DRV_DS3234=m
  2059. +CONFIG_RTC_DRV_PCF2123=m
  2060. +CONFIG_RTC_DRV_RX4581=m
  2061. +CONFIG_DMADEVICES=y
  2062. +CONFIG_DMA_BCM2708=y
  2063. +CONFIG_UIO=m
  2064. +CONFIG_UIO_PDRV_GENIRQ=m
  2065. +CONFIG_STAGING=y
  2066. +CONFIG_W35UND=m
  2067. +CONFIG_PRISM2_USB=m
  2068. +CONFIG_R8712U=m
  2069. +CONFIG_VT6656=m
  2070. +CONFIG_SPEAKUP=m
  2071. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  2072. +CONFIG_STAGING_MEDIA=y
  2073. +CONFIG_DVB_AS102=m
  2074. +CONFIG_LIRC_STAGING=y
  2075. +CONFIG_LIRC_IGORPLUGUSB=m
  2076. +CONFIG_LIRC_IMON=m
  2077. +CONFIG_LIRC_RPI=m
  2078. +CONFIG_LIRC_SASEM=m
  2079. +CONFIG_LIRC_SERIAL=m
  2080. +# CONFIG_IOMMU_SUPPORT is not set
  2081. +CONFIG_EXT4_FS=y
  2082. +CONFIG_EXT4_FS_POSIX_ACL=y
  2083. +CONFIG_EXT4_FS_SECURITY=y
  2084. +CONFIG_REISERFS_FS=m
  2085. +CONFIG_REISERFS_FS_XATTR=y
  2086. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2087. +CONFIG_REISERFS_FS_SECURITY=y
  2088. +CONFIG_JFS_FS=m
  2089. +CONFIG_JFS_POSIX_ACL=y
  2090. +CONFIG_JFS_SECURITY=y
  2091. +CONFIG_JFS_STATISTICS=y
  2092. +CONFIG_XFS_FS=m
  2093. +CONFIG_XFS_QUOTA=y
  2094. +CONFIG_XFS_POSIX_ACL=y
  2095. +CONFIG_XFS_RT=y
  2096. +CONFIG_GFS2_FS=m
  2097. +CONFIG_OCFS2_FS=m
  2098. +CONFIG_BTRFS_FS=m
  2099. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2100. +CONFIG_NILFS2_FS=m
  2101. +CONFIG_FANOTIFY=y
  2102. +CONFIG_QFMT_V1=m
  2103. +CONFIG_QFMT_V2=m
  2104. +CONFIG_AUTOFS4_FS=y
  2105. +CONFIG_FUSE_FS=m
  2106. +CONFIG_CUSE=m
  2107. +CONFIG_FSCACHE=y
  2108. +CONFIG_FSCACHE_STATS=y
  2109. +CONFIG_FSCACHE_HISTOGRAM=y
  2110. +CONFIG_CACHEFILES=y
  2111. +CONFIG_ISO9660_FS=m
  2112. +CONFIG_JOLIET=y
  2113. +CONFIG_ZISOFS=y
  2114. +CONFIG_UDF_FS=m
  2115. +CONFIG_MSDOS_FS=y
  2116. +CONFIG_VFAT_FS=y
  2117. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2118. +CONFIG_NTFS_FS=m
  2119. +CONFIG_NTFS_RW=y
  2120. +CONFIG_TMPFS=y
  2121. +CONFIG_TMPFS_POSIX_ACL=y
  2122. +CONFIG_CONFIGFS_FS=y
  2123. +CONFIG_ECRYPT_FS=m
  2124. +CONFIG_HFS_FS=m
  2125. +CONFIG_HFSPLUS_FS=m
  2126. +CONFIG_SQUASHFS=m
  2127. +CONFIG_SQUASHFS_XATTR=y
  2128. +CONFIG_SQUASHFS_LZO=y
  2129. +CONFIG_SQUASHFS_XZ=y
  2130. +CONFIG_F2FS_FS=y
  2131. +CONFIG_NFS_FS=y
  2132. +CONFIG_NFS_V3_ACL=y
  2133. +CONFIG_NFS_V4=y
  2134. +CONFIG_NFS_SWAP=y
  2135. +CONFIG_ROOT_NFS=y
  2136. +CONFIG_NFS_FSCACHE=y
  2137. +CONFIG_NFSD=m
  2138. +CONFIG_NFSD_V3_ACL=y
  2139. +CONFIG_NFSD_V4=y
  2140. +CONFIG_CIFS=m
  2141. +CONFIG_CIFS_WEAK_PW_HASH=y
  2142. +CONFIG_CIFS_XATTR=y
  2143. +CONFIG_CIFS_POSIX=y
  2144. +CONFIG_9P_FS=m
  2145. +CONFIG_9P_FS_POSIX_ACL=y
  2146. +CONFIG_NLS_DEFAULT="utf8"
  2147. +CONFIG_NLS_CODEPAGE_437=y
  2148. +CONFIG_NLS_CODEPAGE_737=m
  2149. +CONFIG_NLS_CODEPAGE_775=m
  2150. +CONFIG_NLS_CODEPAGE_850=m
  2151. +CONFIG_NLS_CODEPAGE_852=m
  2152. +CONFIG_NLS_CODEPAGE_855=m
  2153. +CONFIG_NLS_CODEPAGE_857=m
  2154. +CONFIG_NLS_CODEPAGE_860=m
  2155. +CONFIG_NLS_CODEPAGE_861=m
  2156. +CONFIG_NLS_CODEPAGE_862=m
  2157. +CONFIG_NLS_CODEPAGE_863=m
  2158. +CONFIG_NLS_CODEPAGE_864=m
  2159. +CONFIG_NLS_CODEPAGE_865=m
  2160. +CONFIG_NLS_CODEPAGE_866=m
  2161. +CONFIG_NLS_CODEPAGE_869=m
  2162. +CONFIG_NLS_CODEPAGE_936=m
  2163. +CONFIG_NLS_CODEPAGE_950=m
  2164. +CONFIG_NLS_CODEPAGE_932=m
  2165. +CONFIG_NLS_CODEPAGE_949=m
  2166. +CONFIG_NLS_CODEPAGE_874=m
  2167. +CONFIG_NLS_ISO8859_8=m
  2168. +CONFIG_NLS_CODEPAGE_1250=m
  2169. +CONFIG_NLS_CODEPAGE_1251=m
  2170. +CONFIG_NLS_ASCII=y
  2171. +CONFIG_NLS_ISO8859_1=m
  2172. +CONFIG_NLS_ISO8859_2=m
  2173. +CONFIG_NLS_ISO8859_3=m
  2174. +CONFIG_NLS_ISO8859_4=m
  2175. +CONFIG_NLS_ISO8859_5=m
  2176. +CONFIG_NLS_ISO8859_6=m
  2177. +CONFIG_NLS_ISO8859_7=m
  2178. +CONFIG_NLS_ISO8859_9=m
  2179. +CONFIG_NLS_ISO8859_13=m
  2180. +CONFIG_NLS_ISO8859_14=m
  2181. +CONFIG_NLS_ISO8859_15=m
  2182. +CONFIG_NLS_KOI8_R=m
  2183. +CONFIG_NLS_KOI8_U=m
  2184. +CONFIG_DLM=m
  2185. +CONFIG_PRINTK_TIME=y
  2186. +CONFIG_BOOT_PRINTK_DELAY=y
  2187. +CONFIG_DEBUG_FS=y
  2188. +CONFIG_DEBUG_MEMORY_INIT=y
  2189. +CONFIG_DETECT_HUNG_TASK=y
  2190. +CONFIG_TIMER_STATS=y
  2191. +# CONFIG_DEBUG_PREEMPT is not set
  2192. +CONFIG_LATENCYTOP=y
  2193. +# CONFIG_KPROBE_EVENT is not set
  2194. +CONFIG_KGDB=y
  2195. +CONFIG_KGDB_KDB=y
  2196. +CONFIG_KDB_KEYBOARD=y
  2197. +CONFIG_STRICT_DEVMEM=y
  2198. +CONFIG_CRYPTO_USER=m
  2199. +CONFIG_CRYPTO_NULL=m
  2200. +CONFIG_CRYPTO_CRYPTD=m
  2201. +CONFIG_CRYPTO_CBC=y
  2202. +CONFIG_CRYPTO_CTS=m
  2203. +CONFIG_CRYPTO_XTS=m
  2204. +CONFIG_CRYPTO_XCBC=m
  2205. +CONFIG_CRYPTO_SHA1_ARM=m
  2206. +CONFIG_CRYPTO_SHA512=m
  2207. +CONFIG_CRYPTO_TGR192=m
  2208. +CONFIG_CRYPTO_WP512=m
  2209. +CONFIG_CRYPTO_AES_ARM=m
  2210. +CONFIG_CRYPTO_CAST5=m
  2211. +CONFIG_CRYPTO_DES=y
  2212. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2213. +# CONFIG_CRYPTO_HW is not set
  2214. +CONFIG_CRC_ITU_T=y
  2215. +CONFIG_LIBCRC32C=y
  2216. diff -Nur linux-3.12.38/arch/arm/configs/bcmrpi_emergency_defconfig linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig
  2217. --- linux-3.12.38/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  2218. +++ linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig 2015-03-10 17:26:49.690216697 +0100
  2219. @@ -0,0 +1,495 @@
  2220. +# CONFIG_LOCALVERSION_AUTO is not set
  2221. +CONFIG_SYSVIPC=y
  2222. +CONFIG_POSIX_MQUEUE=y
  2223. +CONFIG_FHANDLE=y
  2224. +CONFIG_AUDIT=y
  2225. +CONFIG_NO_HZ=y
  2226. +CONFIG_HIGH_RES_TIMERS=y
  2227. +CONFIG_BSD_PROCESS_ACCT=y
  2228. +CONFIG_BSD_PROCESS_ACCT_V3=y
  2229. +CONFIG_IKCONFIG=y
  2230. +CONFIG_IKCONFIG_PROC=y
  2231. +CONFIG_CGROUP_FREEZER=y
  2232. +CONFIG_CGROUP_DEVICE=y
  2233. +CONFIG_CGROUP_CPUACCT=y
  2234. +CONFIG_RESOURCE_COUNTERS=y
  2235. +CONFIG_BLK_CGROUP=y
  2236. +CONFIG_NAMESPACES=y
  2237. +CONFIG_SCHED_AUTOGROUP=y
  2238. +CONFIG_BLK_DEV_INITRD=y
  2239. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  2240. +CONFIG_EMBEDDED=y
  2241. +# CONFIG_COMPAT_BRK is not set
  2242. +CONFIG_SLAB=y
  2243. +CONFIG_PROFILING=y
  2244. +CONFIG_OPROFILE=m
  2245. +CONFIG_KPROBES=y
  2246. +CONFIG_MODULES=y
  2247. +CONFIG_MODULE_UNLOAD=y
  2248. +CONFIG_MODVERSIONS=y
  2249. +CONFIG_MODULE_SRCVERSION_ALL=y
  2250. +# CONFIG_BLK_DEV_BSG is not set
  2251. +CONFIG_BLK_DEV_THROTTLING=y
  2252. +CONFIG_PARTITION_ADVANCED=y
  2253. +CONFIG_MAC_PARTITION=y
  2254. +CONFIG_CFQ_GROUP_IOSCHED=y
  2255. +CONFIG_ARCH_BCM2708=y
  2256. +CONFIG_AEABI=y
  2257. +CONFIG_SECCOMP=y
  2258. +CONFIG_CC_STACKPROTECTOR=y
  2259. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2260. +CONFIG_ZBOOT_ROM_BSS=0x0
  2261. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  2262. +CONFIG_KEXEC=y
  2263. +CONFIG_CPU_IDLE=y
  2264. +CONFIG_VFP=y
  2265. +CONFIG_BINFMT_MISC=m
  2266. +CONFIG_NET=y
  2267. +CONFIG_PACKET=y
  2268. +CONFIG_UNIX=y
  2269. +CONFIG_XFRM_USER=y
  2270. +CONFIG_NET_KEY=m
  2271. +CONFIG_INET=y
  2272. +CONFIG_IP_MULTICAST=y
  2273. +CONFIG_IP_PNP=y
  2274. +CONFIG_IP_PNP_DHCP=y
  2275. +CONFIG_IP_PNP_RARP=y
  2276. +CONFIG_SYN_COOKIES=y
  2277. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2278. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2279. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2280. +# CONFIG_INET_LRO is not set
  2281. +# CONFIG_INET_DIAG is not set
  2282. +# CONFIG_IPV6 is not set
  2283. +CONFIG_NET_PKTGEN=m
  2284. +CONFIG_IRDA=m
  2285. +CONFIG_IRLAN=m
  2286. +CONFIG_IRCOMM=m
  2287. +CONFIG_IRDA_ULTRA=y
  2288. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  2289. +CONFIG_IRDA_FAST_RR=y
  2290. +CONFIG_IRTTY_SIR=m
  2291. +CONFIG_KINGSUN_DONGLE=m
  2292. +CONFIG_KSDAZZLE_DONGLE=m
  2293. +CONFIG_KS959_DONGLE=m
  2294. +CONFIG_USB_IRDA=m
  2295. +CONFIG_SIGMATEL_FIR=m
  2296. +CONFIG_MCS_FIR=m
  2297. +CONFIG_BT=m
  2298. +CONFIG_BT_RFCOMM=m
  2299. +CONFIG_BT_RFCOMM_TTY=y
  2300. +CONFIG_BT_BNEP=m
  2301. +CONFIG_BT_BNEP_MC_FILTER=y
  2302. +CONFIG_BT_BNEP_PROTO_FILTER=y
  2303. +CONFIG_BT_HIDP=m
  2304. +CONFIG_BT_HCIBTUSB=m
  2305. +CONFIG_BT_HCIBCM203X=m
  2306. +CONFIG_BT_HCIBPA10X=m
  2307. +CONFIG_BT_HCIBFUSB=m
  2308. +CONFIG_BT_HCIVHCI=m
  2309. +CONFIG_BT_MRVL=m
  2310. +CONFIG_BT_MRVL_SDIO=m
  2311. +CONFIG_BT_ATH3K=m
  2312. +CONFIG_CFG80211=m
  2313. +CONFIG_MAC80211=m
  2314. +CONFIG_MAC80211_RC_PID=y
  2315. +CONFIG_MAC80211_MESH=y
  2316. +CONFIG_WIMAX=m
  2317. +CONFIG_NET_9P=m
  2318. +CONFIG_NFC=m
  2319. +CONFIG_NFC_PN533=m
  2320. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  2321. +CONFIG_BLK_DEV_LOOP=y
  2322. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  2323. +CONFIG_BLK_DEV_NBD=m
  2324. +CONFIG_BLK_DEV_RAM=y
  2325. +CONFIG_CDROM_PKTCDVD=m
  2326. +CONFIG_SCSI=y
  2327. +# CONFIG_SCSI_PROC_FS is not set
  2328. +CONFIG_BLK_DEV_SD=y
  2329. +CONFIG_BLK_DEV_SR=m
  2330. +CONFIG_SCSI_MULTI_LUN=y
  2331. +# CONFIG_SCSI_LOWLEVEL is not set
  2332. +CONFIG_MD=y
  2333. +CONFIG_NETDEVICES=y
  2334. +CONFIG_NETCONSOLE=m
  2335. +CONFIG_TUN=m
  2336. +CONFIG_MDIO_BITBANG=m
  2337. +CONFIG_PPP=m
  2338. +CONFIG_PPP_BSDCOMP=m
  2339. +CONFIG_PPP_DEFLATE=m
  2340. +CONFIG_PPP_ASYNC=m
  2341. +CONFIG_PPP_SYNC_TTY=m
  2342. +CONFIG_SLIP=m
  2343. +CONFIG_SLIP_COMPRESSED=y
  2344. +CONFIG_USB_CATC=m
  2345. +CONFIG_USB_KAWETH=m
  2346. +CONFIG_USB_PEGASUS=m
  2347. +CONFIG_USB_RTL8150=m
  2348. +CONFIG_USB_USBNET=y
  2349. +CONFIG_USB_NET_AX8817X=m
  2350. +CONFIG_USB_NET_CDCETHER=m
  2351. +CONFIG_USB_NET_CDC_EEM=m
  2352. +CONFIG_USB_NET_DM9601=m
  2353. +CONFIG_USB_NET_SMSC75XX=m
  2354. +CONFIG_USB_NET_SMSC95XX=y
  2355. +CONFIG_USB_NET_GL620A=m
  2356. +CONFIG_USB_NET_NET1080=m
  2357. +CONFIG_USB_NET_PLUSB=m
  2358. +CONFIG_USB_NET_MCS7830=m
  2359. +CONFIG_USB_NET_CDC_SUBSET=m
  2360. +CONFIG_USB_ALI_M5632=y
  2361. +CONFIG_USB_AN2720=y
  2362. +CONFIG_USB_KC2190=y
  2363. +# CONFIG_USB_NET_ZAURUS is not set
  2364. +CONFIG_USB_NET_CX82310_ETH=m
  2365. +CONFIG_USB_NET_KALMIA=m
  2366. +CONFIG_USB_NET_INT51X1=m
  2367. +CONFIG_USB_IPHETH=m
  2368. +CONFIG_USB_SIERRA_NET=m
  2369. +CONFIG_USB_VL600=m
  2370. +CONFIG_LIBERTAS_THINFIRM=m
  2371. +CONFIG_LIBERTAS_THINFIRM_USB=m
  2372. +CONFIG_AT76C50X_USB=m
  2373. +CONFIG_USB_ZD1201=m
  2374. +CONFIG_USB_NET_RNDIS_WLAN=m
  2375. +CONFIG_RTL8187=m
  2376. +CONFIG_MAC80211_HWSIM=m
  2377. +CONFIG_B43=m
  2378. +CONFIG_B43LEGACY=m
  2379. +CONFIG_HOSTAP=m
  2380. +CONFIG_LIBERTAS=m
  2381. +CONFIG_LIBERTAS_USB=m
  2382. +CONFIG_LIBERTAS_SDIO=m
  2383. +CONFIG_P54_COMMON=m
  2384. +CONFIG_P54_USB=m
  2385. +CONFIG_RT2X00=m
  2386. +CONFIG_RT2500USB=m
  2387. +CONFIG_RT73USB=m
  2388. +CONFIG_RT2800USB=m
  2389. +CONFIG_RT2800USB_RT53XX=y
  2390. +CONFIG_RTL8192CU=m
  2391. +CONFIG_ZD1211RW=m
  2392. +CONFIG_MWIFIEX=m
  2393. +CONFIG_MWIFIEX_SDIO=m
  2394. +CONFIG_WIMAX_I2400M_USB=m
  2395. +CONFIG_INPUT_POLLDEV=m
  2396. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  2397. +CONFIG_INPUT_JOYDEV=m
  2398. +CONFIG_INPUT_EVDEV=m
  2399. +# CONFIG_INPUT_KEYBOARD is not set
  2400. +# CONFIG_INPUT_MOUSE is not set
  2401. +CONFIG_INPUT_MISC=y
  2402. +CONFIG_INPUT_AD714X=m
  2403. +CONFIG_INPUT_ATI_REMOTE2=m
  2404. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  2405. +CONFIG_INPUT_POWERMATE=m
  2406. +CONFIG_INPUT_YEALINK=m
  2407. +CONFIG_INPUT_CM109=m
  2408. +CONFIG_INPUT_UINPUT=m
  2409. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  2410. +CONFIG_INPUT_ADXL34X=m
  2411. +CONFIG_INPUT_CMA3000=m
  2412. +CONFIG_SERIO=m
  2413. +CONFIG_SERIO_RAW=m
  2414. +CONFIG_GAMEPORT=m
  2415. +CONFIG_GAMEPORT_NS558=m
  2416. +CONFIG_GAMEPORT_L4=m
  2417. +# CONFIG_LEGACY_PTYS is not set
  2418. +# CONFIG_DEVKMEM is not set
  2419. +CONFIG_SERIAL_AMBA_PL011=y
  2420. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2421. +# CONFIG_HW_RANDOM is not set
  2422. +CONFIG_RAW_DRIVER=y
  2423. +CONFIG_GPIO_SYSFS=y
  2424. +# CONFIG_HWMON is not set
  2425. +CONFIG_WATCHDOG=y
  2426. +CONFIG_BCM2708_WDT=m
  2427. +CONFIG_FB=y
  2428. +CONFIG_FB_BCM2708=y
  2429. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2430. +CONFIG_LOGO=y
  2431. +# CONFIG_LOGO_LINUX_MONO is not set
  2432. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2433. +CONFIG_SOUND=y
  2434. +CONFIG_SND=m
  2435. +CONFIG_SND_SEQUENCER=m
  2436. +CONFIG_SND_SEQ_DUMMY=m
  2437. +CONFIG_SND_MIXER_OSS=m
  2438. +CONFIG_SND_PCM_OSS=m
  2439. +CONFIG_SND_SEQUENCER_OSS=y
  2440. +CONFIG_SND_HRTIMER=m
  2441. +CONFIG_SND_DUMMY=m
  2442. +CONFIG_SND_ALOOP=m
  2443. +CONFIG_SND_VIRMIDI=m
  2444. +CONFIG_SND_MTPAV=m
  2445. +CONFIG_SND_SERIAL_U16550=m
  2446. +CONFIG_SND_MPU401=m
  2447. +CONFIG_SND_BCM2835=m
  2448. +CONFIG_SND_USB_AUDIO=m
  2449. +CONFIG_SND_USB_UA101=m
  2450. +CONFIG_SND_USB_CAIAQ=m
  2451. +CONFIG_SND_USB_6FIRE=m
  2452. +CONFIG_SOUND_PRIME=m
  2453. +CONFIG_HID_A4TECH=m
  2454. +CONFIG_HID_ACRUX=m
  2455. +CONFIG_HID_APPLE=m
  2456. +CONFIG_HID_BELKIN=m
  2457. +CONFIG_HID_CHERRY=m
  2458. +CONFIG_HID_CHICONY=m
  2459. +CONFIG_HID_CYPRESS=m
  2460. +CONFIG_HID_DRAGONRISE=m
  2461. +CONFIG_HID_EMS_FF=m
  2462. +CONFIG_HID_ELECOM=m
  2463. +CONFIG_HID_EZKEY=m
  2464. +CONFIG_HID_HOLTEK=m
  2465. +CONFIG_HID_KEYTOUCH=m
  2466. +CONFIG_HID_KYE=m
  2467. +CONFIG_HID_UCLOGIC=m
  2468. +CONFIG_HID_WALTOP=m
  2469. +CONFIG_HID_GYRATION=m
  2470. +CONFIG_HID_TWINHAN=m
  2471. +CONFIG_HID_KENSINGTON=m
  2472. +CONFIG_HID_LCPOWER=m
  2473. +CONFIG_HID_LOGITECH=m
  2474. +CONFIG_HID_MAGICMOUSE=m
  2475. +CONFIG_HID_MICROSOFT=m
  2476. +CONFIG_HID_MONTEREY=m
  2477. +CONFIG_HID_MULTITOUCH=m
  2478. +CONFIG_HID_NTRIG=m
  2479. +CONFIG_HID_ORTEK=m
  2480. +CONFIG_HID_PANTHERLORD=m
  2481. +CONFIG_HID_PETALYNX=m
  2482. +CONFIG_HID_PICOLCD=m
  2483. +CONFIG_HID_ROCCAT=m
  2484. +CONFIG_HID_SAMSUNG=m
  2485. +CONFIG_HID_SPEEDLINK=m
  2486. +CONFIG_HID_SUNPLUS=m
  2487. +CONFIG_HID_GREENASIA=m
  2488. +CONFIG_HID_SMARTJOYPLUS=m
  2489. +CONFIG_HID_TOPSEED=m
  2490. +CONFIG_HID_THRUSTMASTER=m
  2491. +CONFIG_HID_ZEROPLUS=m
  2492. +CONFIG_HID_ZYDACRON=m
  2493. +CONFIG_HID_PID=y
  2494. +CONFIG_USB_HIDDEV=y
  2495. +CONFIG_USB=y
  2496. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2497. +CONFIG_USB_MON=m
  2498. +CONFIG_USB_DWCOTG=y
  2499. +CONFIG_USB_STORAGE=y
  2500. +CONFIG_USB_STORAGE_REALTEK=m
  2501. +CONFIG_USB_STORAGE_DATAFAB=m
  2502. +CONFIG_USB_STORAGE_FREECOM=m
  2503. +CONFIG_USB_STORAGE_ISD200=m
  2504. +CONFIG_USB_STORAGE_USBAT=m
  2505. +CONFIG_USB_STORAGE_SDDR09=m
  2506. +CONFIG_USB_STORAGE_SDDR55=m
  2507. +CONFIG_USB_STORAGE_JUMPSHOT=m
  2508. +CONFIG_USB_STORAGE_ALAUDA=m
  2509. +CONFIG_USB_STORAGE_ONETOUCH=m
  2510. +CONFIG_USB_STORAGE_KARMA=m
  2511. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  2512. +CONFIG_USB_STORAGE_ENE_UB6250=m
  2513. +CONFIG_USB_MDC800=m
  2514. +CONFIG_USB_MICROTEK=m
  2515. +CONFIG_USB_SERIAL=m
  2516. +CONFIG_USB_SERIAL_GENERIC=y
  2517. +CONFIG_USB_SERIAL_AIRCABLE=m
  2518. +CONFIG_USB_SERIAL_ARK3116=m
  2519. +CONFIG_USB_SERIAL_BELKIN=m
  2520. +CONFIG_USB_SERIAL_CH341=m
  2521. +CONFIG_USB_SERIAL_WHITEHEAT=m
  2522. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  2523. +CONFIG_USB_SERIAL_CP210X=m
  2524. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  2525. +CONFIG_USB_SERIAL_EMPEG=m
  2526. +CONFIG_USB_SERIAL_FTDI_SIO=m
  2527. +CONFIG_USB_SERIAL_VISOR=m
  2528. +CONFIG_USB_SERIAL_IPAQ=m
  2529. +CONFIG_USB_SERIAL_IR=m
  2530. +CONFIG_USB_SERIAL_EDGEPORT=m
  2531. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  2532. +CONFIG_USB_SERIAL_GARMIN=m
  2533. +CONFIG_USB_SERIAL_IPW=m
  2534. +CONFIG_USB_SERIAL_IUU=m
  2535. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  2536. +CONFIG_USB_SERIAL_KEYSPAN=m
  2537. +CONFIG_USB_SERIAL_KLSI=m
  2538. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  2539. +CONFIG_USB_SERIAL_MCT_U232=m
  2540. +CONFIG_USB_SERIAL_MOS7720=m
  2541. +CONFIG_USB_SERIAL_MOS7840=m
  2542. +CONFIG_USB_SERIAL_NAVMAN=m
  2543. +CONFIG_USB_SERIAL_PL2303=m
  2544. +CONFIG_USB_SERIAL_OTI6858=m
  2545. +CONFIG_USB_SERIAL_QCAUX=m
  2546. +CONFIG_USB_SERIAL_QUALCOMM=m
  2547. +CONFIG_USB_SERIAL_SPCP8X5=m
  2548. +CONFIG_USB_SERIAL_SAFE=m
  2549. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  2550. +CONFIG_USB_SERIAL_SYMBOL=m
  2551. +CONFIG_USB_SERIAL_TI=m
  2552. +CONFIG_USB_SERIAL_CYBERJACK=m
  2553. +CONFIG_USB_SERIAL_XIRCOM=m
  2554. +CONFIG_USB_SERIAL_OPTION=m
  2555. +CONFIG_USB_SERIAL_OMNINET=m
  2556. +CONFIG_USB_SERIAL_OPTICON=m
  2557. +CONFIG_USB_SERIAL_SSU100=m
  2558. +CONFIG_USB_SERIAL_DEBUG=m
  2559. +CONFIG_USB_EMI62=m
  2560. +CONFIG_USB_EMI26=m
  2561. +CONFIG_USB_ADUTUX=m
  2562. +CONFIG_USB_SEVSEG=m
  2563. +CONFIG_USB_RIO500=m
  2564. +CONFIG_USB_LEGOTOWER=m
  2565. +CONFIG_USB_LCD=m
  2566. +CONFIG_USB_LED=m
  2567. +CONFIG_USB_CYPRESS_CY7C63=m
  2568. +CONFIG_USB_CYTHERM=m
  2569. +CONFIG_USB_IDMOUSE=m
  2570. +CONFIG_USB_FTDI_ELAN=m
  2571. +CONFIG_USB_APPLEDISPLAY=m
  2572. +CONFIG_USB_LD=m
  2573. +CONFIG_USB_TRANCEVIBRATOR=m
  2574. +CONFIG_USB_IOWARRIOR=m
  2575. +CONFIG_USB_TEST=m
  2576. +CONFIG_USB_ISIGHTFW=m
  2577. +CONFIG_USB_YUREX=m
  2578. +CONFIG_MMC=y
  2579. +CONFIG_MMC_SDHCI=y
  2580. +CONFIG_MMC_SDHCI_PLTFM=y
  2581. +CONFIG_MMC_SDHCI_BCM2708=y
  2582. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2583. +CONFIG_MMC_BCM2835=y
  2584. +CONFIG_MMC_BCM2835_DMA=y
  2585. +CONFIG_UIO=m
  2586. +CONFIG_UIO_PDRV_GENIRQ=m
  2587. +# CONFIG_IOMMU_SUPPORT is not set
  2588. +CONFIG_EXT4_FS=y
  2589. +CONFIG_EXT4_FS_POSIX_ACL=y
  2590. +CONFIG_EXT4_FS_SECURITY=y
  2591. +CONFIG_REISERFS_FS=m
  2592. +CONFIG_REISERFS_FS_XATTR=y
  2593. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2594. +CONFIG_REISERFS_FS_SECURITY=y
  2595. +CONFIG_JFS_FS=m
  2596. +CONFIG_JFS_POSIX_ACL=y
  2597. +CONFIG_JFS_SECURITY=y
  2598. +CONFIG_JFS_STATISTICS=y
  2599. +CONFIG_XFS_FS=m
  2600. +CONFIG_XFS_QUOTA=y
  2601. +CONFIG_XFS_POSIX_ACL=y
  2602. +CONFIG_XFS_RT=y
  2603. +CONFIG_GFS2_FS=m
  2604. +CONFIG_OCFS2_FS=m
  2605. +CONFIG_BTRFS_FS=m
  2606. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2607. +CONFIG_NILFS2_FS=m
  2608. +CONFIG_FANOTIFY=y
  2609. +CONFIG_AUTOFS4_FS=y
  2610. +CONFIG_FUSE_FS=m
  2611. +CONFIG_CUSE=m
  2612. +CONFIG_FSCACHE=y
  2613. +CONFIG_FSCACHE_STATS=y
  2614. +CONFIG_FSCACHE_HISTOGRAM=y
  2615. +CONFIG_CACHEFILES=y
  2616. +CONFIG_ISO9660_FS=m
  2617. +CONFIG_JOLIET=y
  2618. +CONFIG_ZISOFS=y
  2619. +CONFIG_UDF_FS=m
  2620. +CONFIG_MSDOS_FS=y
  2621. +CONFIG_VFAT_FS=y
  2622. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2623. +CONFIG_NTFS_FS=m
  2624. +CONFIG_TMPFS=y
  2625. +CONFIG_TMPFS_POSIX_ACL=y
  2626. +CONFIG_CONFIGFS_FS=y
  2627. +CONFIG_SQUASHFS=m
  2628. +CONFIG_SQUASHFS_XATTR=y
  2629. +CONFIG_SQUASHFS_LZO=y
  2630. +CONFIG_SQUASHFS_XZ=y
  2631. +CONFIG_NFS_FS=y
  2632. +CONFIG_NFS_V3_ACL=y
  2633. +CONFIG_NFS_V4=y
  2634. +CONFIG_ROOT_NFS=y
  2635. +CONFIG_NFS_FSCACHE=y
  2636. +CONFIG_CIFS=m
  2637. +CONFIG_CIFS_WEAK_PW_HASH=y
  2638. +CONFIG_CIFS_XATTR=y
  2639. +CONFIG_CIFS_POSIX=y
  2640. +CONFIG_9P_FS=m
  2641. +CONFIG_9P_FS_POSIX_ACL=y
  2642. +CONFIG_NLS_DEFAULT="utf8"
  2643. +CONFIG_NLS_CODEPAGE_437=y
  2644. +CONFIG_NLS_CODEPAGE_737=m
  2645. +CONFIG_NLS_CODEPAGE_775=m
  2646. +CONFIG_NLS_CODEPAGE_850=m
  2647. +CONFIG_NLS_CODEPAGE_852=m
  2648. +CONFIG_NLS_CODEPAGE_855=m
  2649. +CONFIG_NLS_CODEPAGE_857=m
  2650. +CONFIG_NLS_CODEPAGE_860=m
  2651. +CONFIG_NLS_CODEPAGE_861=m
  2652. +CONFIG_NLS_CODEPAGE_862=m
  2653. +CONFIG_NLS_CODEPAGE_863=m
  2654. +CONFIG_NLS_CODEPAGE_864=m
  2655. +CONFIG_NLS_CODEPAGE_865=m
  2656. +CONFIG_NLS_CODEPAGE_866=m
  2657. +CONFIG_NLS_CODEPAGE_869=m
  2658. +CONFIG_NLS_CODEPAGE_936=m
  2659. +CONFIG_NLS_CODEPAGE_950=m
  2660. +CONFIG_NLS_CODEPAGE_932=m
  2661. +CONFIG_NLS_CODEPAGE_949=m
  2662. +CONFIG_NLS_CODEPAGE_874=m
  2663. +CONFIG_NLS_ISO8859_8=m
  2664. +CONFIG_NLS_CODEPAGE_1250=m
  2665. +CONFIG_NLS_CODEPAGE_1251=m
  2666. +CONFIG_NLS_ASCII=y
  2667. +CONFIG_NLS_ISO8859_1=m
  2668. +CONFIG_NLS_ISO8859_2=m
  2669. +CONFIG_NLS_ISO8859_3=m
  2670. +CONFIG_NLS_ISO8859_4=m
  2671. +CONFIG_NLS_ISO8859_5=m
  2672. +CONFIG_NLS_ISO8859_6=m
  2673. +CONFIG_NLS_ISO8859_7=m
  2674. +CONFIG_NLS_ISO8859_9=m
  2675. +CONFIG_NLS_ISO8859_13=m
  2676. +CONFIG_NLS_ISO8859_14=m
  2677. +CONFIG_NLS_ISO8859_15=m
  2678. +CONFIG_NLS_KOI8_R=m
  2679. +CONFIG_NLS_KOI8_U=m
  2680. +CONFIG_NLS_UTF8=m
  2681. +CONFIG_PRINTK_TIME=y
  2682. +CONFIG_BOOT_PRINTK_DELAY=y
  2683. +CONFIG_DEBUG_INFO=y
  2684. +CONFIG_DEBUG_STACK_USAGE=y
  2685. +CONFIG_DEBUG_MEMORY_INIT=y
  2686. +CONFIG_DETECT_HUNG_TASK=y
  2687. +CONFIG_TIMER_STATS=y
  2688. +CONFIG_LATENCYTOP=y
  2689. +CONFIG_IRQSOFF_TRACER=y
  2690. +CONFIG_SCHED_TRACER=y
  2691. +CONFIG_STACK_TRACER=y
  2692. +CONFIG_BLK_DEV_IO_TRACE=y
  2693. +CONFIG_FUNCTION_PROFILER=y
  2694. +CONFIG_KGDB=y
  2695. +CONFIG_KGDB_KDB=y
  2696. +CONFIG_KDB_KEYBOARD=y
  2697. +CONFIG_STRICT_DEVMEM=y
  2698. +CONFIG_CRYPTO_AUTHENC=m
  2699. +CONFIG_CRYPTO_SEQIV=m
  2700. +CONFIG_CRYPTO_CBC=y
  2701. +CONFIG_CRYPTO_HMAC=y
  2702. +CONFIG_CRYPTO_XCBC=m
  2703. +CONFIG_CRYPTO_MD5=y
  2704. +CONFIG_CRYPTO_SHA1=y
  2705. +CONFIG_CRYPTO_SHA512=m
  2706. +CONFIG_CRYPTO_TGR192=m
  2707. +CONFIG_CRYPTO_WP512=m
  2708. +CONFIG_CRYPTO_CAST5=m
  2709. +CONFIG_CRYPTO_DES=y
  2710. +CONFIG_CRYPTO_DEFLATE=m
  2711. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2712. +# CONFIG_CRYPTO_HW is not set
  2713. +CONFIG_CRC_ITU_T=y
  2714. +CONFIG_LIBCRC32C=y
  2715. diff -Nur linux-3.12.38/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  2716. --- linux-3.12.38/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2717. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2015-03-10 17:26:49.690216697 +0100
  2718. @@ -0,0 +1,201 @@
  2719. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2720. +CONFIG_LOCALVERSION="-quick"
  2721. +# CONFIG_LOCALVERSION_AUTO is not set
  2722. +# CONFIG_SWAP is not set
  2723. +CONFIG_SYSVIPC=y
  2724. +CONFIG_POSIX_MQUEUE=y
  2725. +CONFIG_NO_HZ=y
  2726. +CONFIG_HIGH_RES_TIMERS=y
  2727. +CONFIG_IKCONFIG=y
  2728. +CONFIG_IKCONFIG_PROC=y
  2729. +CONFIG_KALLSYMS_ALL=y
  2730. +CONFIG_EMBEDDED=y
  2731. +CONFIG_PERF_EVENTS=y
  2732. +# CONFIG_COMPAT_BRK is not set
  2733. +CONFIG_SLAB=y
  2734. +CONFIG_MODULES=y
  2735. +CONFIG_MODULE_UNLOAD=y
  2736. +CONFIG_MODVERSIONS=y
  2737. +CONFIG_MODULE_SRCVERSION_ALL=y
  2738. +# CONFIG_BLK_DEV_BSG is not set
  2739. +CONFIG_ARCH_BCM2708=y
  2740. +CONFIG_PREEMPT=y
  2741. +CONFIG_AEABI=y
  2742. +CONFIG_CMA=y
  2743. +CONFIG_UACCESS_WITH_MEMCPY=y
  2744. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2745. +CONFIG_ZBOOT_ROM_BSS=0x0
  2746. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2747. +CONFIG_CPU_FREQ=y
  2748. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2749. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2750. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2751. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2752. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2753. +CONFIG_CPU_IDLE=y
  2754. +CONFIG_VFP=y
  2755. +CONFIG_BINFMT_MISC=y
  2756. +CONFIG_NET=y
  2757. +CONFIG_PACKET=y
  2758. +CONFIG_UNIX=y
  2759. +CONFIG_INET=y
  2760. +CONFIG_IP_MULTICAST=y
  2761. +CONFIG_IP_PNP=y
  2762. +CONFIG_IP_PNP_DHCP=y
  2763. +CONFIG_IP_PNP_RARP=y
  2764. +CONFIG_SYN_COOKIES=y
  2765. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2766. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2767. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2768. +# CONFIG_INET_LRO is not set
  2769. +# CONFIG_INET_DIAG is not set
  2770. +# CONFIG_IPV6 is not set
  2771. +# CONFIG_WIRELESS is not set
  2772. +CONFIG_DEVTMPFS=y
  2773. +CONFIG_DEVTMPFS_MOUNT=y
  2774. +CONFIG_DMA_CMA=y
  2775. +CONFIG_CMA_SIZE_MBYTES=5
  2776. +CONFIG_BLK_DEV_LOOP=y
  2777. +CONFIG_BLK_DEV_RAM=y
  2778. +CONFIG_SCSI=y
  2779. +# CONFIG_SCSI_PROC_FS is not set
  2780. +# CONFIG_SCSI_LOWLEVEL is not set
  2781. +CONFIG_NETDEVICES=y
  2782. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2783. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2784. +# CONFIG_NET_VENDOR_FARADAY is not set
  2785. +# CONFIG_NET_VENDOR_INTEL is not set
  2786. +# CONFIG_NET_VENDOR_MARVELL is not set
  2787. +# CONFIG_NET_VENDOR_MICREL is not set
  2788. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2789. +# CONFIG_NET_VENDOR_SEEQ is not set
  2790. +# CONFIG_NET_VENDOR_STMICRO is not set
  2791. +# CONFIG_NET_VENDOR_WIZNET is not set
  2792. +CONFIG_USB_USBNET=y
  2793. +# CONFIG_USB_NET_AX8817X is not set
  2794. +# CONFIG_USB_NET_CDCETHER is not set
  2795. +# CONFIG_USB_NET_CDC_NCM is not set
  2796. +CONFIG_USB_NET_SMSC95XX=y
  2797. +# CONFIG_USB_NET_NET1080 is not set
  2798. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2799. +# CONFIG_USB_NET_ZAURUS is not set
  2800. +# CONFIG_WLAN is not set
  2801. +# CONFIG_INPUT_MOUSEDEV is not set
  2802. +CONFIG_INPUT_EVDEV=y
  2803. +# CONFIG_INPUT_KEYBOARD is not set
  2804. +# CONFIG_INPUT_MOUSE is not set
  2805. +# CONFIG_SERIO is not set
  2806. +# CONFIG_LEGACY_PTYS is not set
  2807. +# CONFIG_DEVKMEM is not set
  2808. +CONFIG_SERIAL_AMBA_PL011=y
  2809. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2810. +CONFIG_TTY_PRINTK=y
  2811. +CONFIG_HW_RANDOM=y
  2812. +CONFIG_HW_RANDOM_BCM2708=y
  2813. +CONFIG_RAW_DRIVER=y
  2814. +CONFIG_THERMAL=y
  2815. +CONFIG_THERMAL_BCM2835=y
  2816. +CONFIG_WATCHDOG=y
  2817. +CONFIG_BCM2708_WDT=y
  2818. +CONFIG_REGULATOR=y
  2819. +CONFIG_REGULATOR_DEBUG=y
  2820. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2821. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2822. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2823. +CONFIG_FB=y
  2824. +CONFIG_FB_BCM2708=y
  2825. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2826. +CONFIG_LOGO=y
  2827. +# CONFIG_LOGO_LINUX_MONO is not set
  2828. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2829. +CONFIG_SOUND=y
  2830. +CONFIG_SND=y
  2831. +CONFIG_SND_BCM2835=y
  2832. +# CONFIG_SND_USB is not set
  2833. +CONFIG_USB=y
  2834. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2835. +CONFIG_USB_DWCOTG=y
  2836. +CONFIG_MMC=y
  2837. +CONFIG_MMC_SDHCI=y
  2838. +CONFIG_MMC_SDHCI_PLTFM=y
  2839. +CONFIG_MMC_SDHCI_BCM2708=y
  2840. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2841. +CONFIG_MMC_BCM2835=y
  2842. +CONFIG_MMC_BCM2835_DMA=y
  2843. +CONFIG_NEW_LEDS=y
  2844. +CONFIG_LEDS_CLASS=y
  2845. +CONFIG_LEDS_TRIGGERS=y
  2846. +# CONFIG_IOMMU_SUPPORT is not set
  2847. +CONFIG_EXT4_FS=y
  2848. +CONFIG_EXT4_FS_POSIX_ACL=y
  2849. +CONFIG_EXT4_FS_SECURITY=y
  2850. +CONFIG_AUTOFS4_FS=y
  2851. +CONFIG_FSCACHE=y
  2852. +CONFIG_CACHEFILES=y
  2853. +CONFIG_MSDOS_FS=y
  2854. +CONFIG_VFAT_FS=y
  2855. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2856. +CONFIG_TMPFS=y
  2857. +CONFIG_TMPFS_POSIX_ACL=y
  2858. +CONFIG_CONFIGFS_FS=y
  2859. +# CONFIG_MISC_FILESYSTEMS is not set
  2860. +CONFIG_NFS_FS=y
  2861. +CONFIG_NFS_V3_ACL=y
  2862. +CONFIG_NFS_V4=y
  2863. +CONFIG_ROOT_NFS=y
  2864. +CONFIG_NFS_FSCACHE=y
  2865. +CONFIG_NLS_DEFAULT="utf8"
  2866. +CONFIG_NLS_CODEPAGE_437=y
  2867. +CONFIG_NLS_CODEPAGE_737=y
  2868. +CONFIG_NLS_CODEPAGE_775=y
  2869. +CONFIG_NLS_CODEPAGE_850=y
  2870. +CONFIG_NLS_CODEPAGE_852=y
  2871. +CONFIG_NLS_CODEPAGE_855=y
  2872. +CONFIG_NLS_CODEPAGE_857=y
  2873. +CONFIG_NLS_CODEPAGE_860=y
  2874. +CONFIG_NLS_CODEPAGE_861=y
  2875. +CONFIG_NLS_CODEPAGE_862=y
  2876. +CONFIG_NLS_CODEPAGE_863=y
  2877. +CONFIG_NLS_CODEPAGE_864=y
  2878. +CONFIG_NLS_CODEPAGE_865=y
  2879. +CONFIG_NLS_CODEPAGE_866=y
  2880. +CONFIG_NLS_CODEPAGE_869=y
  2881. +CONFIG_NLS_CODEPAGE_936=y
  2882. +CONFIG_NLS_CODEPAGE_950=y
  2883. +CONFIG_NLS_CODEPAGE_932=y
  2884. +CONFIG_NLS_CODEPAGE_949=y
  2885. +CONFIG_NLS_CODEPAGE_874=y
  2886. +CONFIG_NLS_ISO8859_8=y
  2887. +CONFIG_NLS_CODEPAGE_1250=y
  2888. +CONFIG_NLS_CODEPAGE_1251=y
  2889. +CONFIG_NLS_ASCII=y
  2890. +CONFIG_NLS_ISO8859_1=y
  2891. +CONFIG_NLS_ISO8859_2=y
  2892. +CONFIG_NLS_ISO8859_3=y
  2893. +CONFIG_NLS_ISO8859_4=y
  2894. +CONFIG_NLS_ISO8859_5=y
  2895. +CONFIG_NLS_ISO8859_6=y
  2896. +CONFIG_NLS_ISO8859_7=y
  2897. +CONFIG_NLS_ISO8859_9=y
  2898. +CONFIG_NLS_ISO8859_13=y
  2899. +CONFIG_NLS_ISO8859_14=y
  2900. +CONFIG_NLS_ISO8859_15=y
  2901. +CONFIG_NLS_UTF8=y
  2902. +CONFIG_PRINTK_TIME=y
  2903. +CONFIG_DEBUG_FS=y
  2904. +CONFIG_DETECT_HUNG_TASK=y
  2905. +# CONFIG_DEBUG_PREEMPT is not set
  2906. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2907. +# CONFIG_FTRACE is not set
  2908. +CONFIG_KGDB=y
  2909. +CONFIG_KGDB_KDB=y
  2910. +# CONFIG_ARM_UNWIND is not set
  2911. +CONFIG_CRYPTO_CBC=y
  2912. +CONFIG_CRYPTO_HMAC=y
  2913. +CONFIG_CRYPTO_MD5=y
  2914. +CONFIG_CRYPTO_SHA1=y
  2915. +CONFIG_CRYPTO_DES=y
  2916. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2917. +# CONFIG_CRYPTO_HW is not set
  2918. +CONFIG_CRC_ITU_T=y
  2919. +CONFIG_LIBCRC32C=y
  2920. diff -Nur linux-3.12.38/arch/arm/configs/multi_v7_defconfig linux-rpi/arch/arm/configs/multi_v7_defconfig
  2921. --- linux-3.12.38/arch/arm/configs/multi_v7_defconfig 2015-02-16 16:15:42.000000000 +0100
  2922. +++ linux-rpi/arch/arm/configs/multi_v7_defconfig 2015-03-10 17:26:49.694216697 +0100
  2923. @@ -116,7 +116,6 @@
  2924. CONFIG_USB=y
  2925. CONFIG_USB_XHCI_HCD=y
  2926. CONFIG_USB_EHCI_HCD=y
  2927. -CONFIG_USB_EHCI_EXYNOS=y
  2928. CONFIG_USB_EHCI_TEGRA=y
  2929. CONFIG_USB_EHCI_HCD_PLATFORM=y
  2930. CONFIG_USB_ISP1760_HCD=y
  2931. diff -Nur linux-3.12.38/arch/arm/crypto/aes_glue.c linux-rpi/arch/arm/crypto/aes_glue.c
  2932. --- linux-3.12.38/arch/arm/crypto/aes_glue.c 2015-02-16 16:15:42.000000000 +0100
  2933. +++ linux-rpi/arch/arm/crypto/aes_glue.c 2015-03-10 17:26:49.698216697 +0100
  2934. @@ -103,6 +103,6 @@
  2935. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm (ASM)");
  2936. MODULE_LICENSE("GPL");
  2937. -MODULE_ALIAS_CRYPTO("aes");
  2938. -MODULE_ALIAS_CRYPTO("aes-asm");
  2939. +MODULE_ALIAS("aes");
  2940. +MODULE_ALIAS("aes-asm");
  2941. MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");
  2942. diff -Nur linux-3.12.38/arch/arm/crypto/sha1_glue.c linux-rpi/arch/arm/crypto/sha1_glue.c
  2943. --- linux-3.12.38/arch/arm/crypto/sha1_glue.c 2015-02-16 16:15:42.000000000 +0100
  2944. +++ linux-rpi/arch/arm/crypto/sha1_glue.c 2015-03-10 17:26:49.698216697 +0100
  2945. @@ -175,5 +175,5 @@
  2946. MODULE_LICENSE("GPL");
  2947. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)");
  2948. -MODULE_ALIAS_CRYPTO("sha1");
  2949. +MODULE_ALIAS("sha1");
  2950. MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>");
  2951. diff -Nur linux-3.12.38/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  2952. --- linux-3.12.38/arch/arm/include/asm/irqflags.h 2015-02-16 16:15:42.000000000 +0100
  2953. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2015-03-09 10:39:28.526893747 +0100
  2954. @@ -145,12 +145,22 @@
  2955. }
  2956. /*
  2957. - * restore saved IRQ & FIQ state
  2958. + * restore saved IRQ state
  2959. */
  2960. static inline void arch_local_irq_restore(unsigned long flags)
  2961. {
  2962. - asm volatile(
  2963. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2964. + unsigned long temp = 0;
  2965. + flags &= ~(1 << 6);
  2966. + asm volatile (
  2967. + " mrs %0, cpsr"
  2968. + : "=r" (temp)
  2969. + :
  2970. + : "memory", "cc");
  2971. + /* Preserve FIQ bit */
  2972. + temp &= (1 << 6);
  2973. + flags = flags | temp;
  2974. + asm volatile (
  2975. + " msr cpsr_c, %0 @ local_irq_restore"
  2976. :
  2977. : "r" (flags)
  2978. : "memory", "cc");
  2979. diff -Nur linux-3.12.38/arch/arm/include/asm/string.h linux-rpi/arch/arm/include/asm/string.h
  2980. --- linux-3.12.38/arch/arm/include/asm/string.h 2015-02-16 16:15:42.000000000 +0100
  2981. +++ linux-rpi/arch/arm/include/asm/string.h 2015-03-09 10:39:28.530893747 +0100
  2982. @@ -24,6 +24,11 @@
  2983. #define __HAVE_ARCH_MEMSET
  2984. extern void * memset(void *, int, __kernel_size_t);
  2985. +#ifdef CONFIG_MACH_BCM2708
  2986. +#define __HAVE_ARCH_MEMCMP
  2987. +extern int memcmp(const void *, const void *, size_t);
  2988. +#endif
  2989. +
  2990. extern void __memzero(void *ptr, __kernel_size_t n);
  2991. #define memset(p,v,n) \
  2992. diff -Nur linux-3.12.38/arch/arm/include/asm/uaccess.h linux-rpi/arch/arm/include/asm/uaccess.h
  2993. --- linux-3.12.38/arch/arm/include/asm/uaccess.h 2015-02-16 16:15:42.000000000 +0100
  2994. +++ linux-rpi/arch/arm/include/asm/uaccess.h 2015-03-10 17:26:49.702216697 +0100
  2995. @@ -427,6 +427,7 @@
  2996. #ifdef CONFIG_MMU
  2997. extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
  2998. +extern unsigned long __must_check __copy_from_user_std(void *to, const void __user *from, unsigned long n);
  2999. extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
  3000. extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
  3001. extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
  3002. diff -Nur linux-3.12.38/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  3003. --- linux-3.12.38/arch/arm/Kconfig 2015-02-16 16:15:42.000000000 +0100
  3004. +++ linux-rpi/arch/arm/Kconfig 2015-03-10 17:26:49.670216697 +0100
  3005. @@ -369,6 +369,24 @@
  3006. This enables support for systems based on Atmel
  3007. AT91RM9200 and AT91SAM9* processors.
  3008. +config ARCH_BCM2708
  3009. + bool "Broadcom BCM2708 family"
  3010. + select CPU_V6
  3011. + select ARM_AMBA
  3012. + select HAVE_CLK
  3013. + select HAVE_SCHED_CLOCK
  3014. + select NEED_MACH_GPIO_H
  3015. + select NEED_MACH_MEMORY_H
  3016. + select CLKDEV_LOOKUP
  3017. + select ARCH_HAS_CPUFREQ
  3018. + select GENERIC_CLOCKEVENTS
  3019. + select ARM_ERRATA_411920
  3020. + select MACH_BCM2708
  3021. + select VC4
  3022. + select FIQ
  3023. + help
  3024. + This enables support for Broadcom BCM2708 boards.
  3025. +
  3026. config ARCH_CLPS711X
  3027. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  3028. select ARCH_REQUIRE_GPIOLIB
  3029. @@ -1044,6 +1062,7 @@
  3030. source "arch/arm/mach-vt8500/Kconfig"
  3031. source "arch/arm/mach-w90x900/Kconfig"
  3032. +source "arch/arm/mach-bcm2708/Kconfig"
  3033. source "arch/arm/mach-zynq/Kconfig"
  3034. diff -Nur linux-3.12.38/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  3035. --- linux-3.12.38/arch/arm/Kconfig.debug 2015-02-16 16:15:42.000000000 +0100
  3036. +++ linux-rpi/arch/arm/Kconfig.debug 2015-03-10 17:26:49.670216697 +0100
  3037. @@ -847,6 +847,14 @@
  3038. options; the platform specific options are deprecated
  3039. and will be soon removed.
  3040. + config DEBUG_BCM2708_UART0
  3041. + bool "Broadcom BCM2708 UART0 (PL011)"
  3042. + depends on MACH_BCM2708
  3043. + help
  3044. + Say Y here if you want the debug print routines to direct
  3045. + their output to UART 0. The port must have been initialised
  3046. + by the boot-loader before use.
  3047. +
  3048. endchoice
  3049. config DEBUG_EXYNOS_UART
  3050. diff -Nur linux-3.12.38/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  3051. --- linux-3.12.38/arch/arm/kernel/fiqasm.S 2015-02-16 16:15:42.000000000 +0100
  3052. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2015-03-10 17:26:49.702216697 +0100
  3053. @@ -47,3 +47,7 @@
  3054. mov r0, r0 @ avoid hazard prior to ARMv4
  3055. mov pc, lr
  3056. ENDPROC(__get_fiq_regs)
  3057. +
  3058. +ENTRY(__FIQ_Branch)
  3059. + mov pc, r8
  3060. +ENDPROC(__FIQ_Branch)
  3061. diff -Nur linux-3.12.38/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  3062. --- linux-3.12.38/arch/arm/kernel/process.c 2015-02-16 16:15:42.000000000 +0100
  3063. +++ linux-rpi/arch/arm/kernel/process.c 2015-03-10 17:26:49.706216697 +0100
  3064. @@ -176,6 +176,16 @@
  3065. default_idle();
  3066. }
  3067. +char bcm2708_reboot_mode = 'h';
  3068. +
  3069. +int __init reboot_setup(char *str)
  3070. +{
  3071. + bcm2708_reboot_mode = str[0];
  3072. + return 1;
  3073. +}
  3074. +
  3075. +__setup("reboot=", reboot_setup);
  3076. +
  3077. /*
  3078. * Called by kexec, immediately prior to machine_kexec().
  3079. *
  3080. diff -Nur linux-3.12.38/arch/arm/kernel/setup.c linux-rpi/arch/arm/kernel/setup.c
  3081. --- linux-3.12.38/arch/arm/kernel/setup.c 2015-02-16 16:15:42.000000000 +0100
  3082. +++ linux-rpi/arch/arm/kernel/setup.c 2015-03-10 17:26:49.706216697 +0100
  3083. @@ -1016,15 +1016,6 @@
  3084. seq_printf(m, "model name\t: %s rev %d (%s)\n",
  3085. cpu_name, cpuid & 15, elf_platform);
  3086. -#if defined(CONFIG_SMP)
  3087. - seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  3088. - per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  3089. - (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  3090. -#else
  3091. - seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  3092. - loops_per_jiffy / (500000/HZ),
  3093. - (loops_per_jiffy / (5000/HZ)) % 100);
  3094. -#endif
  3095. /* dump out the processor features */
  3096. seq_puts(m, "Features\t: ");
  3097. diff -Nur linux-3.12.38/arch/arm/kernel/smp.c linux-rpi/arch/arm/kernel/smp.c
  3098. --- linux-3.12.38/arch/arm/kernel/smp.c 2015-02-16 16:15:42.000000000 +0100
  3099. +++ linux-rpi/arch/arm/kernel/smp.c 2015-03-10 17:26:49.706216697 +0100
  3100. @@ -383,17 +383,8 @@
  3101. void __init smp_cpus_done(unsigned int max_cpus)
  3102. {
  3103. - int cpu;
  3104. - unsigned long bogosum = 0;
  3105. -
  3106. - for_each_online_cpu(cpu)
  3107. - bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
  3108. -
  3109. - printk(KERN_INFO "SMP: Total of %d processors activated "
  3110. - "(%lu.%02lu BogoMIPS).\n",
  3111. - num_online_cpus(),
  3112. - bogosum / (500000/HZ),
  3113. - (bogosum / (5000/HZ)) % 100);
  3114. + printk(KERN_INFO "SMP: Total of %d processors activated.\n",
  3115. + num_online_cpus());
  3116. hyp_mode_check();
  3117. }
  3118. diff -Nur linux-3.12.38/arch/arm/lib/arm-mem.h linux-rpi/arch/arm/lib/arm-mem.h
  3119. --- linux-3.12.38/arch/arm/lib/arm-mem.h 1970-01-01 01:00:00.000000000 +0100
  3120. +++ linux-rpi/arch/arm/lib/arm-mem.h 2015-03-09 10:39:28.574893746 +0100
  3121. @@ -0,0 +1,159 @@
  3122. +/*
  3123. +Copyright (c) 2013, Raspberry Pi Foundation
  3124. +Copyright (c) 2013, RISC OS Open Ltd
  3125. +All rights reserved.
  3126. +
  3127. +Redistribution and use in source and binary forms, with or without
  3128. +modification, are permitted provided that the following conditions are met:
  3129. + * Redistributions of source code must retain the above copyright
  3130. + notice, this list of conditions and the following disclaimer.
  3131. + * Redistributions in binary form must reproduce the above copyright
  3132. + notice, this list of conditions and the following disclaimer in the
  3133. + documentation and/or other materials provided with the distribution.
  3134. + * Neither the name of the copyright holder nor the
  3135. + names of its contributors may be used to endorse or promote products
  3136. + derived from this software without specific prior written permission.
  3137. +
  3138. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  3139. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  3140. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  3141. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  3142. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3143. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3144. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3145. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3146. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  3147. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3148. +*/
  3149. +
  3150. +.macro myfunc fname
  3151. + .func fname
  3152. + .global fname
  3153. +fname:
  3154. +.endm
  3155. +
  3156. +.macro preload_leading_step1 backwards, ptr, base
  3157. +/* If the destination is already 16-byte aligned, then we need to preload
  3158. + * between 0 and prefetch_distance (inclusive) cache lines ahead so there
  3159. + * are no gaps when the inner loop starts.
  3160. + */
  3161. + .if backwards
  3162. + sub ptr, base, #1
  3163. + bic ptr, ptr, #31
  3164. + .else
  3165. + bic ptr, base, #31
  3166. + .endif
  3167. + .set OFFSET, 0
  3168. + .rept prefetch_distance+1
  3169. + pld [ptr, #OFFSET]
  3170. + .if backwards
  3171. + .set OFFSET, OFFSET-32
  3172. + .else
  3173. + .set OFFSET, OFFSET+32
  3174. + .endif
  3175. + .endr
  3176. +.endm
  3177. +
  3178. +.macro preload_leading_step2 backwards, ptr, base, leading_bytes, tmp
  3179. +/* However, if the destination is not 16-byte aligned, we may need to
  3180. + * preload one more cache line than that. The question we need to ask is:
  3181. + * are the leading bytes more than the amount by which the source
  3182. + * pointer will be rounded down for preloading, and if so, by how many
  3183. + * cache lines?
  3184. + */
  3185. + .if backwards
  3186. +/* Here we compare against how many bytes we are into the
  3187. + * cache line, counting down from the highest such address.
  3188. + * Effectively, we want to calculate
  3189. + * leading_bytes = dst&15
  3190. + * cacheline_offset = 31-((src-leading_bytes-1)&31)
  3191. + * extra_needed = leading_bytes - cacheline_offset
  3192. + * and test if extra_needed is <= 0, or rearranging:
  3193. + * leading_bytes + (src-leading_bytes-1)&31 <= 31
  3194. + */
  3195. + mov tmp, base, lsl #32-5
  3196. + sbc tmp, tmp, leading_bytes, lsl #32-5
  3197. + adds tmp, tmp, leading_bytes, lsl #32-5
  3198. + bcc 61f
  3199. + pld [ptr, #-32*(prefetch_distance+1)]
  3200. + .else
  3201. +/* Effectively, we want to calculate
  3202. + * leading_bytes = (-dst)&15
  3203. + * cacheline_offset = (src+leading_bytes)&31
  3204. + * extra_needed = leading_bytes - cacheline_offset
  3205. + * and test if extra_needed is <= 0.
  3206. + */
  3207. + mov tmp, base, lsl #32-5
  3208. + add tmp, tmp, leading_bytes, lsl #32-5
  3209. + rsbs tmp, tmp, leading_bytes, lsl #32-5
  3210. + bls 61f
  3211. + pld [ptr, #32*(prefetch_distance+1)]
  3212. + .endif
  3213. +61:
  3214. +.endm
  3215. +
  3216. +.macro preload_trailing backwards, base, remain, tmp
  3217. + /* We need either 0, 1 or 2 extra preloads */
  3218. + .if backwards
  3219. + rsb tmp, base, #0
  3220. + mov tmp, tmp, lsl #32-5
  3221. + .else
  3222. + mov tmp, base, lsl #32-5
  3223. + .endif
  3224. + adds tmp, tmp, remain, lsl #32-5
  3225. + adceqs tmp, tmp, #0
  3226. + /* The instruction above has two effects: ensures Z is only
  3227. + * set if C was clear (so Z indicates that both shifted quantities
  3228. + * were 0), and clears C if Z was set (so C indicates that the sum
  3229. + * of the shifted quantities was greater and not equal to 32) */
  3230. + beq 82f
  3231. + .if backwards
  3232. + sub tmp, base, #1
  3233. + bic tmp, tmp, #31
  3234. + .else
  3235. + bic tmp, base, #31
  3236. + .endif
  3237. + bcc 81f
  3238. + .if backwards
  3239. + pld [tmp, #-32*(prefetch_distance+1)]
  3240. +81:
  3241. + pld [tmp, #-32*prefetch_distance]
  3242. + .else
  3243. + pld [tmp, #32*(prefetch_distance+2)]
  3244. +81:
  3245. + pld [tmp, #32*(prefetch_distance+1)]
  3246. + .endif
  3247. +82:
  3248. +.endm
  3249. +
  3250. +.macro preload_all backwards, narrow_case, shift, base, remain, tmp0, tmp1
  3251. + .if backwards
  3252. + sub tmp0, base, #1
  3253. + bic tmp0, tmp0, #31
  3254. + pld [tmp0]
  3255. + sub tmp1, base, remain, lsl #shift
  3256. + .else
  3257. + bic tmp0, base, #31
  3258. + pld [tmp0]
  3259. + add tmp1, base, remain, lsl #shift
  3260. + sub tmp1, tmp1, #1
  3261. + .endif
  3262. + bic tmp1, tmp1, #31
  3263. + cmp tmp1, tmp0
  3264. + beq 92f
  3265. + .if narrow_case
  3266. + /* In this case, all the data fits in either 1 or 2 cache lines */
  3267. + pld [tmp1]
  3268. + .else
  3269. +91:
  3270. + .if backwards
  3271. + sub tmp0, tmp0, #32
  3272. + .else
  3273. + add tmp0, tmp0, #32
  3274. + .endif
  3275. + cmp tmp0, tmp1
  3276. + pld [tmp0]
  3277. + bne 91b
  3278. + .endif
  3279. +92:
  3280. +.endm
  3281. diff -Nur linux-3.12.38/arch/arm/lib/copy_from_user.S linux-rpi/arch/arm/lib/copy_from_user.S
  3282. --- linux-3.12.38/arch/arm/lib/copy_from_user.S 2015-02-16 16:15:42.000000000 +0100
  3283. +++ linux-rpi/arch/arm/lib/copy_from_user.S 2015-03-09 10:39:28.574893746 +0100
  3284. @@ -84,11 +84,13 @@
  3285. .text
  3286. -ENTRY(__copy_from_user)
  3287. +ENTRY(__copy_from_user_std)
  3288. +WEAK(__copy_from_user)
  3289. #include "copy_template.S"
  3290. ENDPROC(__copy_from_user)
  3291. +ENDPROC(__copy_from_user_std)
  3292. .pushsection .fixup,"ax"
  3293. .align 0
  3294. diff -Nur linux-3.12.38/arch/arm/lib/exports_rpi.c linux-rpi/arch/arm/lib/exports_rpi.c
  3295. --- linux-3.12.38/arch/arm/lib/exports_rpi.c 1970-01-01 01:00:00.000000000 +0100
  3296. +++ linux-rpi/arch/arm/lib/exports_rpi.c 2015-03-09 10:39:28.574893746 +0100
  3297. @@ -0,0 +1,37 @@
  3298. +/**
  3299. + * Copyright (c) 2014, Raspberry Pi (Trading) Ltd.
  3300. + *
  3301. + * Redistribution and use in source and binary forms, with or without
  3302. + * modification, are permitted provided that the following conditions
  3303. + * are met:
  3304. + * 1. Redistributions of source code must retain the above copyright
  3305. + * notice, this list of conditions, and the following disclaimer,
  3306. + * without modification.
  3307. + * 2. Redistributions in binary form must reproduce the above copyright
  3308. + * notice, this list of conditions and the following disclaimer in the
  3309. + * documentation and/or other materials provided with the distribution.
  3310. + * 3. The names of the above-listed copyright holders may not be used
  3311. + * to endorse or promote products derived from this software without
  3312. + * specific prior written permission.
  3313. + *
  3314. + * ALTERNATIVELY, this software may be distributed under the terms of the
  3315. + * GNU General Public License ("GPL") version 2, as published by the Free
  3316. + * Software Foundation.
  3317. + *
  3318. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  3319. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  3320. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  3321. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  3322. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  3323. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  3324. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  3325. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3326. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3327. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  3328. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3329. + */
  3330. +
  3331. +#include <linux/kernel.h>
  3332. +#include <linux/module.h>
  3333. +
  3334. +EXPORT_SYMBOL(memcmp);
  3335. diff -Nur linux-3.12.38/arch/arm/lib/Makefile linux-rpi/arch/arm/lib/Makefile
  3336. --- linux-3.12.38/arch/arm/lib/Makefile 2015-02-16 16:15:42.000000000 +0100
  3337. +++ linux-rpi/arch/arm/lib/Makefile 2015-03-10 17:26:49.710216697 +0100
  3338. @@ -6,15 +6,24 @@
  3339. lib-y := backtrace.o changebit.o csumipv6.o csumpartial.o \
  3340. csumpartialcopy.o csumpartialcopyuser.o clearbit.o \
  3341. - delay.o delay-loop.o findbit.o memchr.o memcpy.o \
  3342. - memmove.o memset.o memzero.o setbit.o \
  3343. - strchr.o strrchr.o \
  3344. + delay.o delay-loop.o findbit.o memchr.o memzero.o \
  3345. + setbit.o strchr.o strrchr.o \
  3346. testchangebit.o testclearbit.o testsetbit.o \
  3347. ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \
  3348. ucmpdi2.o lib1funcs.o div64.o \
  3349. io-readsb.o io-writesb.o io-readsl.o io-writesl.o \
  3350. call_with_stack.o
  3351. +# Choose optimised implementations for Raspberry Pi
  3352. +ifeq ($(CONFIG_MACH_BCM2708),y)
  3353. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_FROM_USER_THRESHOLD=1600
  3354. + CFLAGS_uaccess_with_memcpy.o += -DCOPY_TO_USER_THRESHOLD=672
  3355. + obj-$(CONFIG_MODULES) += exports_rpi.o
  3356. + lib-y += memcpy_rpi.o memmove_rpi.o memset_rpi.o memcmp_rpi.o
  3357. +else
  3358. + lib-y += memcpy.o memmove.o memset.o
  3359. +endif
  3360. +
  3361. mmu-y := clear_user.o copy_page.o getuser.o putuser.o
  3362. # the code in uaccess.S is not preemption safe and
  3363. diff -Nur linux-3.12.38/arch/arm/lib/memcmp_rpi.S linux-rpi/arch/arm/lib/memcmp_rpi.S
  3364. --- linux-3.12.38/arch/arm/lib/memcmp_rpi.S 1970-01-01 01:00:00.000000000 +0100
  3365. +++ linux-rpi/arch/arm/lib/memcmp_rpi.S 2015-03-09 10:39:28.574893746 +0100
  3366. @@ -0,0 +1,285 @@
  3367. +/*
  3368. +Copyright (c) 2013, Raspberry Pi Foundation
  3369. +Copyright (c) 2013, RISC OS Open Ltd
  3370. +All rights reserved.
  3371. +
  3372. +Redistribution and use in source and binary forms, with or without
  3373. +modification, are permitted provided that the following conditions are met:
  3374. + * Redistributions of source code must retain the above copyright
  3375. + notice, this list of conditions and the following disclaimer.
  3376. + * Redistributions in binary form must reproduce the above copyright
  3377. + notice, this list of conditions and the following disclaimer in the
  3378. + documentation and/or other materials provided with the distribution.
  3379. + * Neither the name of the copyright holder nor the
  3380. + names of its contributors may be used to endorse or promote products
  3381. + derived from this software without specific prior written permission.
  3382. +
  3383. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  3384. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  3385. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  3386. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  3387. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3388. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3389. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3390. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3391. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  3392. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3393. +*/
  3394. +
  3395. +#include <linux/linkage.h>
  3396. +#include "arm-mem.h"
  3397. +
  3398. +/* Prevent the stack from becoming executable */
  3399. +#if defined(__linux__) && defined(__ELF__)
  3400. +.section .note.GNU-stack,"",%progbits
  3401. +#endif
  3402. +
  3403. + .text
  3404. + .arch armv6
  3405. + .object_arch armv4
  3406. + .arm
  3407. + .altmacro
  3408. + .p2align 2
  3409. +
  3410. +.macro memcmp_process_head unaligned
  3411. + .if unaligned
  3412. + ldr DAT0, [S_1], #4
  3413. + ldr DAT1, [S_1], #4
  3414. + ldr DAT2, [S_1], #4
  3415. + ldr DAT3, [S_1], #4
  3416. + .else
  3417. + ldmia S_1!, {DAT0, DAT1, DAT2, DAT3}
  3418. + .endif
  3419. + ldmia S_2!, {DAT4, DAT5, DAT6, DAT7}
  3420. +.endm
  3421. +
  3422. +.macro memcmp_process_tail
  3423. + cmp DAT0, DAT4
  3424. + cmpeq DAT1, DAT5
  3425. + cmpeq DAT2, DAT6
  3426. + cmpeq DAT3, DAT7
  3427. + bne 200f
  3428. +.endm
  3429. +
  3430. +.macro memcmp_leading_31bytes
  3431. + movs DAT0, OFF, lsl #31
  3432. + ldrmib DAT0, [S_1], #1
  3433. + ldrcsh DAT1, [S_1], #2
  3434. + ldrmib DAT4, [S_2], #1
  3435. + ldrcsh DAT5, [S_2], #2
  3436. + movpl DAT0, #0
  3437. + movcc DAT1, #0
  3438. + movpl DAT4, #0
  3439. + movcc DAT5, #0
  3440. + submi N, N, #1
  3441. + subcs N, N, #2
  3442. + cmp DAT0, DAT4
  3443. + cmpeq DAT1, DAT5
  3444. + bne 200f
  3445. + movs DAT0, OFF, lsl #29
  3446. + ldrmi DAT0, [S_1], #4
  3447. + ldrcs DAT1, [S_1], #4
  3448. + ldrcs DAT2, [S_1], #4
  3449. + ldrmi DAT4, [S_2], #4
  3450. + ldmcsia S_2!, {DAT5, DAT6}
  3451. + movpl DAT0, #0
  3452. + movcc DAT1, #0
  3453. + movcc DAT2, #0
  3454. + movpl DAT4, #0
  3455. + movcc DAT5, #0
  3456. + movcc DAT6, #0
  3457. + submi N, N, #4
  3458. + subcs N, N, #8
  3459. + cmp DAT0, DAT4
  3460. + cmpeq DAT1, DAT5
  3461. + cmpeq DAT2, DAT6
  3462. + bne 200f
  3463. + tst OFF, #16
  3464. + beq 105f
  3465. + memcmp_process_head 1
  3466. + sub N, N, #16
  3467. + memcmp_process_tail
  3468. +105:
  3469. +.endm
  3470. +
  3471. +.macro memcmp_trailing_15bytes unaligned
  3472. + movs N, N, lsl #29
  3473. + .if unaligned
  3474. + ldrcs DAT0, [S_1], #4
  3475. + ldrcs DAT1, [S_1], #4
  3476. + .else
  3477. + ldmcsia S_1!, {DAT0, DAT1}
  3478. + .endif
  3479. + ldrmi DAT2, [S_1], #4
  3480. + ldmcsia S_2!, {DAT4, DAT5}
  3481. + ldrmi DAT6, [S_2], #4
  3482. + movcc DAT0, #0
  3483. + movcc DAT1, #0
  3484. + movpl DAT2, #0
  3485. + movcc DAT4, #0
  3486. + movcc DAT5, #0
  3487. + movpl DAT6, #0
  3488. + cmp DAT0, DAT4
  3489. + cmpeq DAT1, DAT5
  3490. + cmpeq DAT2, DAT6
  3491. + bne 200f
  3492. + movs N, N, lsl #2
  3493. + ldrcsh DAT0, [S_1], #2
  3494. + ldrmib DAT1, [S_1]
  3495. + ldrcsh DAT4, [S_2], #2
  3496. + ldrmib DAT5, [S_2]
  3497. + movcc DAT0, #0
  3498. + movpl DAT1, #0
  3499. + movcc DAT4, #0
  3500. + movpl DAT5, #0
  3501. + cmp DAT0, DAT4
  3502. + cmpeq DAT1, DAT5
  3503. + bne 200f
  3504. +.endm
  3505. +
  3506. +.macro memcmp_long_inner_loop unaligned
  3507. +110:
  3508. + memcmp_process_head unaligned
  3509. + pld [S_2, #prefetch_distance*32 + 16]
  3510. + memcmp_process_tail
  3511. + memcmp_process_head unaligned
  3512. + pld [S_1, OFF]
  3513. + memcmp_process_tail
  3514. + subs N, N, #32
  3515. + bhs 110b
  3516. + /* Just before the final (prefetch_distance+1) 32-byte blocks,
  3517. + * deal with final preloads */
  3518. + preload_trailing 0, S_1, N, DAT0
  3519. + preload_trailing 0, S_2, N, DAT0
  3520. + add N, N, #(prefetch_distance+2)*32 - 16
  3521. +120:
  3522. + memcmp_process_head unaligned
  3523. + memcmp_process_tail
  3524. + subs N, N, #16
  3525. + bhs 120b
  3526. + /* Trailing words and bytes */
  3527. + tst N, #15
  3528. + beq 199f
  3529. + memcmp_trailing_15bytes unaligned
  3530. +199: /* Reached end without detecting a difference */
  3531. + mov a1, #0
  3532. + setend le
  3533. + pop {DAT1-DAT6, pc}
  3534. +.endm
  3535. +
  3536. +.macro memcmp_short_inner_loop unaligned
  3537. + subs N, N, #16 /* simplifies inner loop termination */
  3538. + blo 122f
  3539. +120:
  3540. + memcmp_process_head unaligned
  3541. + memcmp_process_tail
  3542. + subs N, N, #16
  3543. + bhs 120b
  3544. +122: /* Trailing words and bytes */
  3545. + tst N, #15
  3546. + beq 199f
  3547. + memcmp_trailing_15bytes unaligned
  3548. +199: /* Reached end without detecting a difference */
  3549. + mov a1, #0
  3550. + setend le
  3551. + pop {DAT1-DAT6, pc}
  3552. +.endm
  3553. +
  3554. +/*
  3555. + * int memcmp(const void *s1, const void *s2, size_t n);
  3556. + * On entry:
  3557. + * a1 = pointer to buffer 1
  3558. + * a2 = pointer to buffer 2
  3559. + * a3 = number of bytes to compare (as unsigned chars)
  3560. + * On exit:
  3561. + * a1 = >0/=0/<0 if s1 >/=/< s2
  3562. + */
  3563. +
  3564. +.set prefetch_distance, 2
  3565. +
  3566. +ENTRY(memcmp)
  3567. + S_1 .req a1
  3568. + S_2 .req a2
  3569. + N .req a3
  3570. + DAT0 .req a4
  3571. + DAT1 .req v1
  3572. + DAT2 .req v2
  3573. + DAT3 .req v3
  3574. + DAT4 .req v4
  3575. + DAT5 .req v5
  3576. + DAT6 .req v6
  3577. + DAT7 .req ip
  3578. + OFF .req lr
  3579. +
  3580. + push {DAT1-DAT6, lr}
  3581. + setend be /* lowest-addressed bytes are most significant */
  3582. +
  3583. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  3584. + cmp N, #(prefetch_distance+3)*32 - 1
  3585. + blo 170f
  3586. +
  3587. + /* Long case */
  3588. + /* Adjust N so that the decrement instruction can also test for
  3589. + * inner loop termination. We want it to stop when there are
  3590. + * (prefetch_distance+1) complete blocks to go. */
  3591. + sub N, N, #(prefetch_distance+2)*32
  3592. + preload_leading_step1 0, DAT0, S_1
  3593. + preload_leading_step1 0, DAT1, S_2
  3594. + tst S_2, #31
  3595. + beq 154f
  3596. + rsb OFF, S_2, #0 /* no need to AND with 15 here */
  3597. + preload_leading_step2 0, DAT0, S_1, OFF, DAT2
  3598. + preload_leading_step2 0, DAT1, S_2, OFF, DAT2
  3599. + memcmp_leading_31bytes
  3600. +154: /* Second source now cacheline (32-byte) aligned; we have at
  3601. + * least one prefetch to go. */
  3602. + /* Prefetch offset is best selected such that it lies in the
  3603. + * first 8 of each 32 bytes - but it's just as easy to aim for
  3604. + * the first one */
  3605. + and OFF, S_1, #31
  3606. + rsb OFF, OFF, #32*prefetch_distance
  3607. + tst S_1, #3
  3608. + bne 140f
  3609. + memcmp_long_inner_loop 0
  3610. +140: memcmp_long_inner_loop 1
  3611. +
  3612. +170: /* Short case */
  3613. + teq N, #0
  3614. + beq 199f
  3615. + preload_all 0, 0, 0, S_1, N, DAT0, DAT1
  3616. + preload_all 0, 0, 0, S_2, N, DAT0, DAT1
  3617. + tst S_2, #3
  3618. + beq 174f
  3619. +172: subs N, N, #1
  3620. + blo 199f
  3621. + ldrb DAT0, [S_1], #1
  3622. + ldrb DAT4, [S_2], #1
  3623. + cmp DAT0, DAT4
  3624. + bne 200f
  3625. + tst S_2, #3
  3626. + bne 172b
  3627. +174: /* Second source now 4-byte aligned; we have 0 or more bytes to go */
  3628. + tst S_1, #3
  3629. + bne 140f
  3630. + memcmp_short_inner_loop 0
  3631. +140: memcmp_short_inner_loop 1
  3632. +
  3633. +200: /* Difference found: determine sign. */
  3634. + movhi a1, #1
  3635. + movlo a1, #-1
  3636. + setend le
  3637. + pop {DAT1-DAT6, pc}
  3638. +
  3639. + .unreq S_1
  3640. + .unreq S_2
  3641. + .unreq N
  3642. + .unreq DAT0
  3643. + .unreq DAT1
  3644. + .unreq DAT2
  3645. + .unreq DAT3
  3646. + .unreq DAT4
  3647. + .unreq DAT5
  3648. + .unreq DAT6
  3649. + .unreq DAT7
  3650. + .unreq OFF
  3651. +ENDPROC(memcmp)
  3652. diff -Nur linux-3.12.38/arch/arm/lib/memcpymove.h linux-rpi/arch/arm/lib/memcpymove.h
  3653. --- linux-3.12.38/arch/arm/lib/memcpymove.h 1970-01-01 01:00:00.000000000 +0100
  3654. +++ linux-rpi/arch/arm/lib/memcpymove.h 2015-03-09 10:39:28.574893746 +0100
  3655. @@ -0,0 +1,506 @@
  3656. +/*
  3657. +Copyright (c) 2013, Raspberry Pi Foundation
  3658. +Copyright (c) 2013, RISC OS Open Ltd
  3659. +All rights reserved.
  3660. +
  3661. +Redistribution and use in source and binary forms, with or without
  3662. +modification, are permitted provided that the following conditions are met:
  3663. + * Redistributions of source code must retain the above copyright
  3664. + notice, this list of conditions and the following disclaimer.
  3665. + * Redistributions in binary form must reproduce the above copyright
  3666. + notice, this list of conditions and the following disclaimer in the
  3667. + documentation and/or other materials provided with the distribution.
  3668. + * Neither the name of the copyright holder nor the
  3669. + names of its contributors may be used to endorse or promote products
  3670. + derived from this software without specific prior written permission.
  3671. +
  3672. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  3673. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  3674. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  3675. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  3676. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3677. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3678. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3679. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3680. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  3681. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3682. +*/
  3683. +
  3684. +.macro unaligned_words backwards, align, use_pld, words, r0, r1, r2, r3, r4, r5, r6, r7, r8
  3685. + .if words == 1
  3686. + .if backwards
  3687. + mov r1, r0, lsl #32-align*8
  3688. + ldr r0, [S, #-4]!
  3689. + orr r1, r1, r0, lsr #align*8
  3690. + str r1, [D, #-4]!
  3691. + .else
  3692. + mov r0, r1, lsr #align*8
  3693. + ldr r1, [S, #4]!
  3694. + orr r0, r0, r1, lsl #32-align*8
  3695. + str r0, [D], #4
  3696. + .endif
  3697. + .elseif words == 2
  3698. + .if backwards
  3699. + ldr r1, [S, #-4]!
  3700. + mov r2, r0, lsl #32-align*8
  3701. + ldr r0, [S, #-4]!
  3702. + orr r2, r2, r1, lsr #align*8
  3703. + mov r1, r1, lsl #32-align*8
  3704. + orr r1, r1, r0, lsr #align*8
  3705. + stmdb D!, {r1, r2}
  3706. + .else
  3707. + ldr r1, [S, #4]!
  3708. + mov r0, r2, lsr #align*8
  3709. + ldr r2, [S, #4]!
  3710. + orr r0, r0, r1, lsl #32-align*8
  3711. + mov r1, r1, lsr #align*8
  3712. + orr r1, r1, r2, lsl #32-align*8
  3713. + stmia D!, {r0, r1}
  3714. + .endif
  3715. + .elseif words == 4
  3716. + .if backwards
  3717. + ldmdb S!, {r2, r3}
  3718. + mov r4, r0, lsl #32-align*8
  3719. + ldmdb S!, {r0, r1}
  3720. + orr r4, r4, r3, lsr #align*8
  3721. + mov r3, r3, lsl #32-align*8
  3722. + orr r3, r3, r2, lsr #align*8
  3723. + mov r2, r2, lsl #32-align*8
  3724. + orr r2, r2, r1, lsr #align*8
  3725. + mov r1, r1, lsl #32-align*8
  3726. + orr r1, r1, r0, lsr #align*8
  3727. + stmdb D!, {r1, r2, r3, r4}
  3728. + .else
  3729. + ldmib S!, {r1, r2}
  3730. + mov r0, r4, lsr #align*8
  3731. + ldmib S!, {r3, r4}
  3732. + orr r0, r0, r1, lsl #32-align*8
  3733. + mov r1, r1, lsr #align*8
  3734. + orr r1, r1, r2, lsl #32-align*8
  3735. + mov r2, r2, lsr #align*8
  3736. + orr r2, r2, r3, lsl #32-align*8
  3737. + mov r3, r3, lsr #align*8
  3738. + orr r3, r3, r4, lsl #32-align*8
  3739. + stmia D!, {r0, r1, r2, r3}
  3740. + .endif
  3741. + .elseif words == 8
  3742. + .if backwards
  3743. + ldmdb S!, {r4, r5, r6, r7}
  3744. + mov r8, r0, lsl #32-align*8
  3745. + ldmdb S!, {r0, r1, r2, r3}
  3746. + .if use_pld
  3747. + pld [S, OFF]
  3748. + .endif
  3749. + orr r8, r8, r7, lsr #align*8
  3750. + mov r7, r7, lsl #32-align*8
  3751. + orr r7, r7, r6, lsr #align*8
  3752. + mov r6, r6, lsl #32-align*8
  3753. + orr r6, r6, r5, lsr #align*8
  3754. + mov r5, r5, lsl #32-align*8
  3755. + orr r5, r5, r4, lsr #align*8
  3756. + mov r4, r4, lsl #32-align*8
  3757. + orr r4, r4, r3, lsr #align*8
  3758. + mov r3, r3, lsl #32-align*8
  3759. + orr r3, r3, r2, lsr #align*8
  3760. + mov r2, r2, lsl #32-align*8
  3761. + orr r2, r2, r1, lsr #align*8
  3762. + mov r1, r1, lsl #32-align*8
  3763. + orr r1, r1, r0, lsr #align*8
  3764. + stmdb D!, {r5, r6, r7, r8}
  3765. + stmdb D!, {r1, r2, r3, r4}
  3766. + .else
  3767. + ldmib S!, {r1, r2, r3, r4}
  3768. + mov r0, r8, lsr #align*8
  3769. + ldmib S!, {r5, r6, r7, r8}
  3770. + .if use_pld
  3771. + pld [S, OFF]
  3772. + .endif
  3773. + orr r0, r0, r1, lsl #32-align*8
  3774. + mov r1, r1, lsr #align*8
  3775. + orr r1, r1, r2, lsl #32-align*8
  3776. + mov r2, r2, lsr #align*8
  3777. + orr r2, r2, r3, lsl #32-align*8
  3778. + mov r3, r3, lsr #align*8
  3779. + orr r3, r3, r4, lsl #32-align*8
  3780. + mov r4, r4, lsr #align*8
  3781. + orr r4, r4, r5, lsl #32-align*8
  3782. + mov r5, r5, lsr #align*8
  3783. + orr r5, r5, r6, lsl #32-align*8
  3784. + mov r6, r6, lsr #align*8
  3785. + orr r6, r6, r7, lsl #32-align*8
  3786. + mov r7, r7, lsr #align*8
  3787. + orr r7, r7, r8, lsl #32-align*8
  3788. + stmia D!, {r0, r1, r2, r3}
  3789. + stmia D!, {r4, r5, r6, r7}
  3790. + .endif
  3791. + .endif
  3792. +.endm
  3793. +
  3794. +.macro memcpy_leading_15bytes backwards, align
  3795. + movs DAT1, DAT2, lsl #31
  3796. + sub N, N, DAT2
  3797. + .if backwards
  3798. + ldrmib DAT0, [S, #-1]!
  3799. + ldrcsh DAT1, [S, #-2]!
  3800. + strmib DAT0, [D, #-1]!
  3801. + strcsh DAT1, [D, #-2]!
  3802. + .else
  3803. + ldrmib DAT0, [S], #1
  3804. + ldrcsh DAT1, [S], #2
  3805. + strmib DAT0, [D], #1
  3806. + strcsh DAT1, [D], #2
  3807. + .endif
  3808. + movs DAT1, DAT2, lsl #29
  3809. + .if backwards
  3810. + ldrmi DAT0, [S, #-4]!
  3811. + .if align == 0
  3812. + ldmcsdb S!, {DAT1, DAT2}
  3813. + .else
  3814. + ldrcs DAT2, [S, #-4]!
  3815. + ldrcs DAT1, [S, #-4]!
  3816. + .endif
  3817. + strmi DAT0, [D, #-4]!
  3818. + stmcsdb D!, {DAT1, DAT2}
  3819. + .else
  3820. + ldrmi DAT0, [S], #4
  3821. + .if align == 0
  3822. + ldmcsia S!, {DAT1, DAT2}
  3823. + .else
  3824. + ldrcs DAT1, [S], #4
  3825. + ldrcs DAT2, [S], #4
  3826. + .endif
  3827. + strmi DAT0, [D], #4
  3828. + stmcsia D!, {DAT1, DAT2}
  3829. + .endif
  3830. +.endm
  3831. +
  3832. +.macro memcpy_trailing_15bytes backwards, align
  3833. + movs N, N, lsl #29
  3834. + .if backwards
  3835. + .if align == 0
  3836. + ldmcsdb S!, {DAT0, DAT1}
  3837. + .else
  3838. + ldrcs DAT1, [S, #-4]!
  3839. + ldrcs DAT0, [S, #-4]!
  3840. + .endif
  3841. + ldrmi DAT2, [S, #-4]!
  3842. + stmcsdb D!, {DAT0, DAT1}
  3843. + strmi DAT2, [D, #-4]!
  3844. + .else
  3845. + .if align == 0
  3846. + ldmcsia S!, {DAT0, DAT1}
  3847. + .else
  3848. + ldrcs DAT0, [S], #4
  3849. + ldrcs DAT1, [S], #4
  3850. + .endif
  3851. + ldrmi DAT2, [S], #4
  3852. + stmcsia D!, {DAT0, DAT1}
  3853. + strmi DAT2, [D], #4
  3854. + .endif
  3855. + movs N, N, lsl #2
  3856. + .if backwards
  3857. + ldrcsh DAT0, [S, #-2]!
  3858. + ldrmib DAT1, [S, #-1]
  3859. + strcsh DAT0, [D, #-2]!
  3860. + strmib DAT1, [D, #-1]
  3861. + .else
  3862. + ldrcsh DAT0, [S], #2
  3863. + ldrmib DAT1, [S]
  3864. + strcsh DAT0, [D], #2
  3865. + strmib DAT1, [D]
  3866. + .endif
  3867. +.endm
  3868. +
  3869. +.macro memcpy_long_inner_loop backwards, align
  3870. + .if align != 0
  3871. + .if backwards
  3872. + ldr DAT0, [S, #-align]!
  3873. + .else
  3874. + ldr LAST, [S, #-align]!
  3875. + .endif
  3876. + .endif
  3877. +110:
  3878. + .if align == 0
  3879. + .if backwards
  3880. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  3881. + pld [S, OFF]
  3882. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  3883. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  3884. + .else
  3885. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  3886. + pld [S, OFF]
  3887. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  3888. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  3889. + .endif
  3890. + .else
  3891. + unaligned_words backwards, align, 1, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  3892. + .endif
  3893. + subs N, N, #32
  3894. + bhs 110b
  3895. + /* Just before the final (prefetch_distance+1) 32-byte blocks, deal with final preloads */
  3896. + preload_trailing backwards, S, N, OFF
  3897. + add N, N, #(prefetch_distance+2)*32 - 32
  3898. +120:
  3899. + .if align == 0
  3900. + .if backwards
  3901. + ldmdb S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  3902. + stmdb D!, {DAT4, DAT5, DAT6, LAST}
  3903. + stmdb D!, {DAT0, DAT1, DAT2, DAT3}
  3904. + .else
  3905. + ldmia S!, {DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, LAST}
  3906. + stmia D!, {DAT0, DAT1, DAT2, DAT3}
  3907. + stmia D!, {DAT4, DAT5, DAT6, LAST}
  3908. + .endif
  3909. + .else
  3910. + unaligned_words backwards, align, 0, 8, DAT0, DAT1, DAT2, DAT3, DAT4, DAT5, DAT6, DAT7, LAST
  3911. + .endif
  3912. + subs N, N, #32
  3913. + bhs 120b
  3914. + tst N, #16
  3915. + .if align == 0
  3916. + .if backwards
  3917. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  3918. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  3919. + .else
  3920. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  3921. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  3922. + .endif
  3923. + .else
  3924. + beq 130f
  3925. + unaligned_words backwards, align, 0, 4, DAT0, DAT1, DAT2, DAT3, LAST
  3926. +130:
  3927. + .endif
  3928. + /* Trailing words and bytes */
  3929. + tst N, #15
  3930. + beq 199f
  3931. + .if align != 0
  3932. + add S, S, #align
  3933. + .endif
  3934. + memcpy_trailing_15bytes backwards, align
  3935. +199:
  3936. + pop {DAT3, DAT4, DAT5, DAT6, DAT7}
  3937. + pop {D, DAT1, DAT2, pc}
  3938. +.endm
  3939. +
  3940. +.macro memcpy_medium_inner_loop backwards, align
  3941. +120:
  3942. + .if backwards
  3943. + .if align == 0
  3944. + ldmdb S!, {DAT0, DAT1, DAT2, LAST}
  3945. + .else
  3946. + ldr LAST, [S, #-4]!
  3947. + ldr DAT2, [S, #-4]!
  3948. + ldr DAT1, [S, #-4]!
  3949. + ldr DAT0, [S, #-4]!
  3950. + .endif
  3951. + stmdb D!, {DAT0, DAT1, DAT2, LAST}
  3952. + .else
  3953. + .if align == 0
  3954. + ldmia S!, {DAT0, DAT1, DAT2, LAST}
  3955. + .else
  3956. + ldr DAT0, [S], #4
  3957. + ldr DAT1, [S], #4
  3958. + ldr DAT2, [S], #4
  3959. + ldr LAST, [S], #4
  3960. + .endif
  3961. + stmia D!, {DAT0, DAT1, DAT2, LAST}
  3962. + .endif
  3963. + subs N, N, #16
  3964. + bhs 120b
  3965. + /* Trailing words and bytes */
  3966. + tst N, #15
  3967. + beq 199f
  3968. + memcpy_trailing_15bytes backwards, align
  3969. +199:
  3970. + pop {D, DAT1, DAT2, pc}
  3971. +.endm
  3972. +
  3973. +.macro memcpy_short_inner_loop backwards, align
  3974. + tst N, #16
  3975. + .if backwards
  3976. + .if align == 0
  3977. + ldmnedb S!, {DAT0, DAT1, DAT2, LAST}
  3978. + .else
  3979. + ldrne LAST, [S, #-4]!
  3980. + ldrne DAT2, [S, #-4]!
  3981. + ldrne DAT1, [S, #-4]!
  3982. + ldrne DAT0, [S, #-4]!
  3983. + .endif
  3984. + stmnedb D!, {DAT0, DAT1, DAT2, LAST}
  3985. + .else
  3986. + .if align == 0
  3987. + ldmneia S!, {DAT0, DAT1, DAT2, LAST}
  3988. + .else
  3989. + ldrne DAT0, [S], #4
  3990. + ldrne DAT1, [S], #4
  3991. + ldrne DAT2, [S], #4
  3992. + ldrne LAST, [S], #4
  3993. + .endif
  3994. + stmneia D!, {DAT0, DAT1, DAT2, LAST}
  3995. + .endif
  3996. + memcpy_trailing_15bytes backwards, align
  3997. +199:
  3998. + pop {D, DAT1, DAT2, pc}
  3999. +.endm
  4000. +
  4001. +.macro memcpy backwards
  4002. + D .req a1
  4003. + S .req a2
  4004. + N .req a3
  4005. + DAT0 .req a4
  4006. + DAT1 .req v1
  4007. + DAT2 .req v2
  4008. + DAT3 .req v3
  4009. + DAT4 .req v4
  4010. + DAT5 .req v5
  4011. + DAT6 .req v6
  4012. + DAT7 .req sl
  4013. + LAST .req ip
  4014. + OFF .req lr
  4015. +
  4016. + .cfi_startproc
  4017. +
  4018. + push {D, DAT1, DAT2, lr}
  4019. +
  4020. + .cfi_def_cfa_offset 16
  4021. + .cfi_rel_offset D, 0
  4022. + .cfi_undefined S
  4023. + .cfi_undefined N
  4024. + .cfi_undefined DAT0
  4025. + .cfi_rel_offset DAT1, 4
  4026. + .cfi_rel_offset DAT2, 8
  4027. + .cfi_undefined LAST
  4028. + .cfi_rel_offset lr, 12
  4029. +
  4030. + .if backwards
  4031. + add D, D, N
  4032. + add S, S, N
  4033. + .endif
  4034. +
  4035. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  4036. + cmp N, #31
  4037. + blo 170f
  4038. + /* To preload ahead as we go, we need at least (prefetch_distance+2) 32-byte blocks */
  4039. + cmp N, #(prefetch_distance+3)*32 - 1
  4040. + blo 160f
  4041. +
  4042. + /* Long case */
  4043. + push {DAT3, DAT4, DAT5, DAT6, DAT7}
  4044. +
  4045. + .cfi_def_cfa_offset 36
  4046. + .cfi_rel_offset D, 20
  4047. + .cfi_rel_offset DAT1, 24
  4048. + .cfi_rel_offset DAT2, 28
  4049. + .cfi_rel_offset DAT3, 0
  4050. + .cfi_rel_offset DAT4, 4
  4051. + .cfi_rel_offset DAT5, 8
  4052. + .cfi_rel_offset DAT6, 12
  4053. + .cfi_rel_offset DAT7, 16
  4054. + .cfi_rel_offset lr, 32
  4055. +
  4056. + /* Adjust N so that the decrement instruction can also test for
  4057. + * inner loop termination. We want it to stop when there are
  4058. + * (prefetch_distance+1) complete blocks to go. */
  4059. + sub N, N, #(prefetch_distance+2)*32
  4060. + preload_leading_step1 backwards, DAT0, S
  4061. + .if backwards
  4062. + /* Bug in GAS: it accepts, but mis-assembles the instruction
  4063. + * ands DAT2, D, #60, 2
  4064. + * which sets DAT2 to the number of leading bytes until destination is aligned and also clears C (sets borrow)
  4065. + */
  4066. + .word 0xE210513C
  4067. + beq 154f
  4068. + .else
  4069. + ands DAT2, D, #15
  4070. + beq 154f
  4071. + rsb DAT2, DAT2, #16 /* number of leading bytes until destination aligned */
  4072. + .endif
  4073. + preload_leading_step2 backwards, DAT0, S, DAT2, OFF
  4074. + memcpy_leading_15bytes backwards, 1
  4075. +154: /* Destination now 16-byte aligned; we have at least one prefetch as well as at least one 16-byte output block */
  4076. + /* Prefetch offset is best selected such that it lies in the first 8 of each 32 bytes - but it's just as easy to aim for the first one */
  4077. + .if backwards
  4078. + rsb OFF, S, #3
  4079. + and OFF, OFF, #28
  4080. + sub OFF, OFF, #32*(prefetch_distance+1)
  4081. + .else
  4082. + and OFF, S, #28
  4083. + rsb OFF, OFF, #32*prefetch_distance
  4084. + .endif
  4085. + movs DAT0, S, lsl #31
  4086. + bhi 157f
  4087. + bcs 156f
  4088. + bmi 155f
  4089. + memcpy_long_inner_loop backwards, 0
  4090. +155: memcpy_long_inner_loop backwards, 1
  4091. +156: memcpy_long_inner_loop backwards, 2
  4092. +157: memcpy_long_inner_loop backwards, 3
  4093. +
  4094. + .cfi_def_cfa_offset 16
  4095. + .cfi_rel_offset D, 0
  4096. + .cfi_rel_offset DAT1, 4
  4097. + .cfi_rel_offset DAT2, 8
  4098. + .cfi_same_value DAT3
  4099. + .cfi_same_value DAT4
  4100. + .cfi_same_value DAT5
  4101. + .cfi_same_value DAT6
  4102. + .cfi_same_value DAT7
  4103. + .cfi_rel_offset lr, 12
  4104. +
  4105. +160: /* Medium case */
  4106. + preload_all backwards, 0, 0, S, N, DAT2, OFF
  4107. + sub N, N, #16 /* simplifies inner loop termination */
  4108. + .if backwards
  4109. + ands DAT2, D, #15
  4110. + beq 164f
  4111. + .else
  4112. + ands DAT2, D, #15
  4113. + beq 164f
  4114. + rsb DAT2, DAT2, #16
  4115. + .endif
  4116. + memcpy_leading_15bytes backwards, align
  4117. +164: /* Destination now 16-byte aligned; we have at least one 16-byte output block */
  4118. + tst S, #3
  4119. + bne 140f
  4120. + memcpy_medium_inner_loop backwards, 0
  4121. +140: memcpy_medium_inner_loop backwards, 1
  4122. +
  4123. +170: /* Short case, less than 31 bytes, so no guarantee of at least one 16-byte block */
  4124. + teq N, #0
  4125. + beq 199f
  4126. + preload_all backwards, 1, 0, S, N, DAT2, LAST
  4127. + tst D, #3
  4128. + beq 174f
  4129. +172: subs N, N, #1
  4130. + blo 199f
  4131. + .if backwards
  4132. + ldrb DAT0, [S, #-1]!
  4133. + strb DAT0, [D, #-1]!
  4134. + .else
  4135. + ldrb DAT0, [S], #1
  4136. + strb DAT0, [D], #1
  4137. + .endif
  4138. + tst D, #3
  4139. + bne 172b
  4140. +174: /* Destination now 4-byte aligned; we have 0 or more output bytes to go */
  4141. + tst S, #3
  4142. + bne 140f
  4143. + memcpy_short_inner_loop backwards, 0
  4144. +140: memcpy_short_inner_loop backwards, 1
  4145. +
  4146. + .cfi_endproc
  4147. +
  4148. + .unreq D
  4149. + .unreq S
  4150. + .unreq N
  4151. + .unreq DAT0
  4152. + .unreq DAT1
  4153. + .unreq DAT2
  4154. + .unreq DAT3
  4155. + .unreq DAT4
  4156. + .unreq DAT5
  4157. + .unreq DAT6
  4158. + .unreq DAT7
  4159. + .unreq LAST
  4160. + .unreq OFF
  4161. +.endm
  4162. diff -Nur linux-3.12.38/arch/arm/lib/memcpy_rpi.S linux-rpi/arch/arm/lib/memcpy_rpi.S
  4163. --- linux-3.12.38/arch/arm/lib/memcpy_rpi.S 1970-01-01 01:00:00.000000000 +0100
  4164. +++ linux-rpi/arch/arm/lib/memcpy_rpi.S 2015-03-09 10:39:28.574893746 +0100
  4165. @@ -0,0 +1,59 @@
  4166. +/*
  4167. +Copyright (c) 2013, Raspberry Pi Foundation
  4168. +Copyright (c) 2013, RISC OS Open Ltd
  4169. +All rights reserved.
  4170. +
  4171. +Redistribution and use in source and binary forms, with or without
  4172. +modification, are permitted provided that the following conditions are met:
  4173. + * Redistributions of source code must retain the above copyright
  4174. + notice, this list of conditions and the following disclaimer.
  4175. + * Redistributions in binary form must reproduce the above copyright
  4176. + notice, this list of conditions and the following disclaimer in the
  4177. + documentation and/or other materials provided with the distribution.
  4178. + * Neither the name of the copyright holder nor the
  4179. + names of its contributors may be used to endorse or promote products
  4180. + derived from this software without specific prior written permission.
  4181. +
  4182. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4183. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4184. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4185. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4186. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4187. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4188. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4189. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4190. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4191. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4192. +*/
  4193. +
  4194. +#include <linux/linkage.h>
  4195. +#include "arm-mem.h"
  4196. +#include "memcpymove.h"
  4197. +
  4198. +/* Prevent the stack from becoming executable */
  4199. +#if defined(__linux__) && defined(__ELF__)
  4200. +.section .note.GNU-stack,"",%progbits
  4201. +#endif
  4202. +
  4203. + .text
  4204. + .arch armv6
  4205. + .object_arch armv4
  4206. + .arm
  4207. + .altmacro
  4208. + .p2align 2
  4209. +
  4210. +/*
  4211. + * void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
  4212. + * On entry:
  4213. + * a1 = pointer to destination
  4214. + * a2 = pointer to source
  4215. + * a3 = number of bytes to copy
  4216. + * On exit:
  4217. + * a1 preserved
  4218. + */
  4219. +
  4220. +.set prefetch_distance, 3
  4221. +
  4222. +ENTRY(memcpy)
  4223. + memcpy 0
  4224. +ENDPROC(memcpy)
  4225. diff -Nur linux-3.12.38/arch/arm/lib/memmove_rpi.S linux-rpi/arch/arm/lib/memmove_rpi.S
  4226. --- linux-3.12.38/arch/arm/lib/memmove_rpi.S 1970-01-01 01:00:00.000000000 +0100
  4227. +++ linux-rpi/arch/arm/lib/memmove_rpi.S 2015-03-09 10:39:28.574893746 +0100
  4228. @@ -0,0 +1,61 @@
  4229. +/*
  4230. +Copyright (c) 2013, Raspberry Pi Foundation
  4231. +Copyright (c) 2013, RISC OS Open Ltd
  4232. +All rights reserved.
  4233. +
  4234. +Redistribution and use in source and binary forms, with or without
  4235. +modification, are permitted provided that the following conditions are met:
  4236. + * Redistributions of source code must retain the above copyright
  4237. + notice, this list of conditions and the following disclaimer.
  4238. + * Redistributions in binary form must reproduce the above copyright
  4239. + notice, this list of conditions and the following disclaimer in the
  4240. + documentation and/or other materials provided with the distribution.
  4241. + * Neither the name of the copyright holder nor the
  4242. + names of its contributors may be used to endorse or promote products
  4243. + derived from this software without specific prior written permission.
  4244. +
  4245. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4246. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4247. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4248. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4249. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4250. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4251. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4252. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4253. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4254. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4255. +*/
  4256. +
  4257. +#include <linux/linkage.h>
  4258. +#include "arm-mem.h"
  4259. +#include "memcpymove.h"
  4260. +
  4261. +/* Prevent the stack from becoming executable */
  4262. +#if defined(__linux__) && defined(__ELF__)
  4263. +.section .note.GNU-stack,"",%progbits
  4264. +#endif
  4265. +
  4266. + .text
  4267. + .arch armv6
  4268. + .object_arch armv4
  4269. + .arm
  4270. + .altmacro
  4271. + .p2align 2
  4272. +
  4273. +/*
  4274. + * void *memmove(void *s1, const void *s2, size_t n);
  4275. + * On entry:
  4276. + * a1 = pointer to destination
  4277. + * a2 = pointer to source
  4278. + * a3 = number of bytes to copy
  4279. + * On exit:
  4280. + * a1 preserved
  4281. + */
  4282. +
  4283. +.set prefetch_distance, 3
  4284. +
  4285. +ENTRY(memmove)
  4286. + cmp a2, a1
  4287. + bpl memcpy /* pl works even over -1 - 0 and 0x7fffffff - 0x80000000 boundaries */
  4288. + memcpy 1
  4289. +ENDPROC(memmove)
  4290. diff -Nur linux-3.12.38/arch/arm/lib/memset_rpi.S linux-rpi/arch/arm/lib/memset_rpi.S
  4291. --- linux-3.12.38/arch/arm/lib/memset_rpi.S 1970-01-01 01:00:00.000000000 +0100
  4292. +++ linux-rpi/arch/arm/lib/memset_rpi.S 2015-03-09 10:39:28.574893746 +0100
  4293. @@ -0,0 +1,121 @@
  4294. +/*
  4295. +Copyright (c) 2013, Raspberry Pi Foundation
  4296. +Copyright (c) 2013, RISC OS Open Ltd
  4297. +All rights reserved.
  4298. +
  4299. +Redistribution and use in source and binary forms, with or without
  4300. +modification, are permitted provided that the following conditions are met:
  4301. + * Redistributions of source code must retain the above copyright
  4302. + notice, this list of conditions and the following disclaimer.
  4303. + * Redistributions in binary form must reproduce the above copyright
  4304. + notice, this list of conditions and the following disclaimer in the
  4305. + documentation and/or other materials provided with the distribution.
  4306. + * Neither the name of the copyright holder nor the
  4307. + names of its contributors may be used to endorse or promote products
  4308. + derived from this software without specific prior written permission.
  4309. +
  4310. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  4311. +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4312. +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4313. +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  4314. +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4315. +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4316. +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4317. +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4318. +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4319. +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4320. +*/
  4321. +
  4322. +#include <linux/linkage.h>
  4323. +#include "arm-mem.h"
  4324. +
  4325. +/* Prevent the stack from becoming executable */
  4326. +#if defined(__linux__) && defined(__ELF__)
  4327. +.section .note.GNU-stack,"",%progbits
  4328. +#endif
  4329. +
  4330. + .text
  4331. + .arch armv6
  4332. + .object_arch armv4
  4333. + .arm
  4334. + .altmacro
  4335. + .p2align 2
  4336. +
  4337. +/*
  4338. + * void *memset(void *s, int c, size_t n);
  4339. + * On entry:
  4340. + * a1 = pointer to buffer to fill
  4341. + * a2 = byte pattern to fill with (caller-narrowed)
  4342. + * a3 = number of bytes to fill
  4343. + * On exit:
  4344. + * a1 preserved
  4345. + */
  4346. +ENTRY(memset)
  4347. + S .req a1
  4348. + DAT0 .req a2
  4349. + N .req a3
  4350. + DAT1 .req a4
  4351. + DAT2 .req ip
  4352. + DAT3 .req lr
  4353. +
  4354. + orr DAT0, DAT0, lsl #8
  4355. + push {S, lr}
  4356. + orr DAT0, DAT0, lsl #16
  4357. + mov DAT1, DAT0
  4358. +
  4359. + /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
  4360. + cmp N, #31
  4361. + blo 170f
  4362. +
  4363. +161: sub N, N, #16 /* simplifies inner loop termination */
  4364. + /* Leading words and bytes */
  4365. + tst S, #15
  4366. + beq 164f
  4367. + rsb DAT3, S, #0 /* bits 0-3 = number of leading bytes until aligned */
  4368. + movs DAT2, DAT3, lsl #31
  4369. + submi N, N, #1
  4370. + strmib DAT0, [S], #1
  4371. + subcs N, N, #2
  4372. + strcsh DAT0, [S], #2
  4373. + movs DAT2, DAT3, lsl #29
  4374. + submi N, N, #4
  4375. + strmi DAT0, [S], #4
  4376. + subcs N, N, #8
  4377. + stmcsia S!, {DAT0, DAT1}
  4378. +164: /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
  4379. + mov DAT2, DAT0
  4380. + mov DAT3, DAT0
  4381. + /* Now the inner loop of 16-byte stores */
  4382. +165: stmia S!, {DAT0, DAT1, DAT2, DAT3}
  4383. + subs N, N, #16
  4384. + bhs 165b
  4385. +166: /* Trailing words and bytes */
  4386. + movs N, N, lsl #29
  4387. + stmcsia S!, {DAT0, DAT1}
  4388. + strmi DAT0, [S], #4
  4389. + movs N, N, lsl #2
  4390. + strcsh DAT0, [S], #2
  4391. + strmib DAT0, [S]
  4392. +199: pop {S, pc}
  4393. +
  4394. +170: /* Short case */
  4395. + mov DAT2, DAT0
  4396. + mov DAT3, DAT0
  4397. + tst S, #3
  4398. + beq 174f
  4399. +172: subs N, N, #1
  4400. + blo 199b
  4401. + strb DAT0, [S], #1
  4402. + tst S, #3
  4403. + bne 172b
  4404. +174: tst N, #16
  4405. + stmneia S!, {DAT0, DAT1, DAT2, DAT3}
  4406. + b 166b
  4407. +
  4408. + .unreq S
  4409. + .unreq DAT0
  4410. + .unreq N
  4411. + .unreq DAT1
  4412. + .unreq DAT2
  4413. + .unreq DAT3
  4414. +ENDPROC(memset)
  4415. diff -Nur linux-3.12.38/arch/arm/lib/uaccess_with_memcpy.c linux-rpi/arch/arm/lib/uaccess_with_memcpy.c
  4416. --- linux-3.12.38/arch/arm/lib/uaccess_with_memcpy.c 2015-02-16 16:15:42.000000000 +0100
  4417. +++ linux-rpi/arch/arm/lib/uaccess_with_memcpy.c 2015-03-10 17:26:49.710216697 +0100
  4418. @@ -21,6 +21,14 @@
  4419. #include <asm/current.h>
  4420. #include <asm/page.h>
  4421. +#ifndef COPY_FROM_USER_THRESHOLD
  4422. +#define COPY_FROM_USER_THRESHOLD 64
  4423. +#endif
  4424. +
  4425. +#ifndef COPY_TO_USER_THRESHOLD
  4426. +#define COPY_TO_USER_THRESHOLD 64
  4427. +#endif
  4428. +
  4429. static int
  4430. pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  4431. {
  4432. @@ -56,7 +64,44 @@
  4433. return 1;
  4434. }
  4435. -static unsigned long noinline
  4436. +static int
  4437. +pin_page_for_read(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp)
  4438. +{
  4439. + unsigned long addr = (unsigned long)_addr;
  4440. + pgd_t *pgd;
  4441. + pmd_t *pmd;
  4442. + pte_t *pte;
  4443. + pud_t *pud;
  4444. + spinlock_t *ptl;
  4445. +
  4446. + pgd = pgd_offset(current->mm, addr);
  4447. + if (unlikely(pgd_none(*pgd) || pgd_bad(*pgd)))
  4448. + {
  4449. + return 0;
  4450. + }
  4451. + pud = pud_offset(pgd, addr);
  4452. + if (unlikely(pud_none(*pud) || pud_bad(*pud)))
  4453. + {
  4454. + return 0;
  4455. + }
  4456. +
  4457. + pmd = pmd_offset(pud, addr);
  4458. + if (unlikely(pmd_none(*pmd) || pmd_bad(*pmd)))
  4459. + return 0;
  4460. +
  4461. + pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl);
  4462. + if (unlikely(!pte_present(*pte) || !pte_young(*pte))) {
  4463. + pte_unmap_unlock(pte, ptl);
  4464. + return 0;
  4465. + }
  4466. +
  4467. + *ptep = pte;
  4468. + *ptlp = ptl;
  4469. +
  4470. + return 1;
  4471. +}
  4472. +
  4473. +unsigned long noinline
  4474. __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
  4475. {
  4476. int atomic;
  4477. @@ -103,6 +148,54 @@
  4478. return n;
  4479. }
  4480. +unsigned long noinline
  4481. +__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
  4482. +{
  4483. + int atomic;
  4484. +
  4485. + if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
  4486. + memcpy(to, (const void *)from, n);
  4487. + return 0;
  4488. + }
  4489. +
  4490. + /* the mmap semaphore is taken only if not in an atomic context */
  4491. + atomic = in_atomic();
  4492. +
  4493. + if (!atomic)
  4494. + down_read(&current->mm->mmap_sem);
  4495. + while (n) {
  4496. + pte_t *pte;
  4497. + spinlock_t *ptl;
  4498. + int tocopy;
  4499. +
  4500. + while (!pin_page_for_read(from, &pte, &ptl)) {
  4501. + char temp;
  4502. + if (!atomic)
  4503. + up_read(&current->mm->mmap_sem);
  4504. + if (__get_user(temp, (char __user *)from))
  4505. + goto out;
  4506. + if (!atomic)
  4507. + down_read(&current->mm->mmap_sem);
  4508. + }
  4509. +
  4510. + tocopy = (~(unsigned long)from & ~PAGE_MASK) + 1;
  4511. + if (tocopy > n)
  4512. + tocopy = n;
  4513. +
  4514. + memcpy(to, (const void *)from, tocopy);
  4515. + to += tocopy;
  4516. + from += tocopy;
  4517. + n -= tocopy;
  4518. +
  4519. + pte_unmap_unlock(pte, ptl);
  4520. + }
  4521. + if (!atomic)
  4522. + up_read(&current->mm->mmap_sem);
  4523. +
  4524. +out:
  4525. + return n;
  4526. +}
  4527. +
  4528. unsigned long
  4529. __copy_to_user(void __user *to, const void *from, unsigned long n)
  4530. {
  4531. @@ -113,10 +206,25 @@
  4532. * With frame pointer disabled, tail call optimization kicks in
  4533. * as well making this test almost invisible.
  4534. */
  4535. - if (n < 64)
  4536. + if (n < COPY_TO_USER_THRESHOLD)
  4537. return __copy_to_user_std(to, from, n);
  4538. return __copy_to_user_memcpy(to, from, n);
  4539. }
  4540. +
  4541. +unsigned long
  4542. +__copy_from_user(void *to, const void __user *from, unsigned long n)
  4543. +{
  4544. + /*
  4545. + * This test is stubbed out of the main function above to keep
  4546. + * the overhead for small copies low by avoiding a large
  4547. + * register dump on the stack just to reload them right away.
  4548. + * With frame pointer disabled, tail call optimization kicks in
  4549. + * as well making this test almost invisible.
  4550. + */
  4551. + if (n < COPY_FROM_USER_THRESHOLD)
  4552. + return __copy_from_user_std(to, from, n);
  4553. + return __copy_from_user_memcpy(to, from, n);
  4554. +}
  4555. static unsigned long noinline
  4556. __clear_user_memset(void __user *addr, unsigned long n)
  4557. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  4558. --- linux-3.12.38/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  4559. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2015-03-10 17:26:49.718216697 +0100
  4560. @@ -0,0 +1,219 @@
  4561. +/*
  4562. + * linux/arch/arm/mach-bcm2708/armctrl.c
  4563. + *
  4564. + * Copyright (C) 2010 Broadcom
  4565. + *
  4566. + * This program is free software; you can redistribute it and/or modify
  4567. + * it under the terms of the GNU General Public License as published by
  4568. + * the Free Software Foundation; either version 2 of the License, or
  4569. + * (at your option) any later version.
  4570. + *
  4571. + * This program is distributed in the hope that it will be useful,
  4572. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4573. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4574. + * GNU General Public License for more details.
  4575. + *
  4576. + * You should have received a copy of the GNU General Public License
  4577. + * along with this program; if not, write to the Free Software
  4578. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4579. + */
  4580. +#include <linux/init.h>
  4581. +#include <linux/list.h>
  4582. +#include <linux/io.h>
  4583. +#include <linux/version.h>
  4584. +#include <linux/syscore_ops.h>
  4585. +#include <linux/interrupt.h>
  4586. +
  4587. +#include <asm/mach/irq.h>
  4588. +#include <mach/hardware.h>
  4589. +#include "armctrl.h"
  4590. +
  4591. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  4592. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  4593. + INTERRUPT_VC_JPEG,
  4594. + INTERRUPT_VC_USB,
  4595. + INTERRUPT_VC_3D,
  4596. + INTERRUPT_VC_DMA2,
  4597. + INTERRUPT_VC_DMA3,
  4598. + INTERRUPT_VC_I2C,
  4599. + INTERRUPT_VC_SPI,
  4600. + INTERRUPT_VC_I2SPCM,
  4601. + INTERRUPT_VC_SDIO,
  4602. + INTERRUPT_VC_UART,
  4603. + INTERRUPT_VC_ARASANSDIO
  4604. +};
  4605. +
  4606. +static void armctrl_mask_irq(struct irq_data *d)
  4607. +{
  4608. + static const unsigned int disables[4] = {
  4609. + ARM_IRQ_DIBL1,
  4610. + ARM_IRQ_DIBL2,
  4611. + ARM_IRQ_DIBL3,
  4612. + 0
  4613. + };
  4614. +
  4615. + if (d->irq >= FIQ_START) {
  4616. + writel(0, __io_address(ARM_IRQ_FAST));
  4617. + } else {
  4618. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  4619. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  4620. + }
  4621. +}
  4622. +
  4623. +static void armctrl_unmask_irq(struct irq_data *d)
  4624. +{
  4625. + static const unsigned int enables[4] = {
  4626. + ARM_IRQ_ENBL1,
  4627. + ARM_IRQ_ENBL2,
  4628. + ARM_IRQ_ENBL3,
  4629. + 0
  4630. + };
  4631. +
  4632. + if (d->irq >= FIQ_START) {
  4633. + unsigned int data =
  4634. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  4635. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  4636. + } else {
  4637. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  4638. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  4639. + }
  4640. +}
  4641. +
  4642. +#if defined(CONFIG_PM)
  4643. +
  4644. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  4645. +
  4646. +/* Static defines
  4647. + * struct armctrl_device - VIC PM device (< 3.xx)
  4648. + * @sysdev: The system device which is registered. (< 3.xx)
  4649. + * @irq: The IRQ number for the base of the VIC.
  4650. + * @base: The register base for the VIC.
  4651. + * @resume_sources: A bitmask of interrupts for resume.
  4652. + * @resume_irqs: The IRQs enabled for resume.
  4653. + * @int_select: Save for VIC_INT_SELECT.
  4654. + * @int_enable: Save for VIC_INT_ENABLE.
  4655. + * @soft_int: Save for VIC_INT_SOFT.
  4656. + * @protect: Save for VIC_PROTECT.
  4657. + */
  4658. +struct armctrl_info {
  4659. + void __iomem *base;
  4660. + int irq;
  4661. + u32 resume_sources;
  4662. + u32 resume_irqs;
  4663. + u32 int_select;
  4664. + u32 int_enable;
  4665. + u32 soft_int;
  4666. + u32 protect;
  4667. +} armctrl;
  4668. +
  4669. +static int armctrl_suspend(void)
  4670. +{
  4671. + return 0;
  4672. +}
  4673. +
  4674. +static void armctrl_resume(void)
  4675. +{
  4676. + return;
  4677. +}
  4678. +
  4679. +/**
  4680. + * armctrl_pm_register - Register a VIC for later power management control
  4681. + * @base: The base address of the VIC.
  4682. + * @irq: The base IRQ for the VIC.
  4683. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  4684. + *
  4685. + * For older kernels (< 3.xx) do -
  4686. + * Register the VIC with the system device tree so that it can be notified
  4687. + * of suspend and resume requests and ensure that the correct actions are
  4688. + * taken to re-instate the settings on resume.
  4689. + */
  4690. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  4691. + u32 resume_sources)
  4692. +{
  4693. + armctrl.base = base;
  4694. + armctrl.resume_sources = resume_sources;
  4695. + armctrl.irq = irq;
  4696. +}
  4697. +
  4698. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  4699. +{
  4700. + unsigned int off = d->irq & 31;
  4701. + u32 bit = 1 << off;
  4702. +
  4703. + if (!(bit & armctrl.resume_sources))
  4704. + return -EINVAL;
  4705. +
  4706. + if (on)
  4707. + armctrl.resume_irqs |= bit;
  4708. + else
  4709. + armctrl.resume_irqs &= ~bit;
  4710. +
  4711. + return 0;
  4712. +}
  4713. +
  4714. +#else
  4715. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  4716. + u32 arg1)
  4717. +{
  4718. +}
  4719. +
  4720. +#define armctrl_suspend NULL
  4721. +#define armctrl_resume NULL
  4722. +#define armctrl_set_wake NULL
  4723. +#endif /* CONFIG_PM */
  4724. +
  4725. +static struct syscore_ops armctrl_syscore_ops = {
  4726. + .suspend = armctrl_suspend,
  4727. + .resume = armctrl_resume,
  4728. +};
  4729. +
  4730. +/**
  4731. + * armctrl_syscore_init - initicall to register VIC pm functions
  4732. + *
  4733. + * This is called via late_initcall() to register
  4734. + * the resources for the VICs due to the early
  4735. + * nature of the VIC's registration.
  4736. +*/
  4737. +static int __init armctrl_syscore_init(void)
  4738. +{
  4739. + register_syscore_ops(&armctrl_syscore_ops);
  4740. + return 0;
  4741. +}
  4742. +
  4743. +late_initcall(armctrl_syscore_init);
  4744. +
  4745. +static struct irq_chip armctrl_chip = {
  4746. + .name = "ARMCTRL",
  4747. + .irq_ack = NULL,
  4748. + .irq_mask = armctrl_mask_irq,
  4749. + .irq_unmask = armctrl_unmask_irq,
  4750. + .irq_set_wake = armctrl_set_wake,
  4751. +};
  4752. +
  4753. +/**
  4754. + * armctrl_init - initialise a vectored interrupt controller
  4755. + * @base: iomem base address
  4756. + * @irq_start: starting interrupt number, must be muliple of 32
  4757. + * @armctrl_sources: bitmask of interrupt sources to allow
  4758. + * @resume_sources: bitmask of interrupt sources to allow for resume
  4759. + */
  4760. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  4761. + u32 armctrl_sources, u32 resume_sources)
  4762. +{
  4763. + unsigned int irq;
  4764. +
  4765. + for (irq = 0; irq < BCM2708_ALLOC_IRQS; irq++) {
  4766. + unsigned int data = irq;
  4767. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  4768. + data = remap_irqs[irq - INTERRUPT_JPEG];
  4769. +
  4770. + irq_set_chip(irq, &armctrl_chip);
  4771. + irq_set_chip_data(irq, (void *)data);
  4772. + irq_set_handler(irq, handle_level_irq);
  4773. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  4774. + }
  4775. +
  4776. + armctrl_pm_register(base, irq_start, resume_sources);
  4777. + init_FIQ(FIQ_START);
  4778. + return 0;
  4779. +}
  4780. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  4781. --- linux-3.12.38/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  4782. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2015-03-09 10:39:28.582893746 +0100
  4783. @@ -0,0 +1,27 @@
  4784. +/*
  4785. + * linux/arch/arm/mach-bcm2708/armctrl.h
  4786. + *
  4787. + * Copyright (C) 2010 Broadcom
  4788. + *
  4789. + * This program is free software; you can redistribute it and/or modify
  4790. + * it under the terms of the GNU General Public License as published by
  4791. + * the Free Software Foundation; either version 2 of the License, or
  4792. + * (at your option) any later version.
  4793. + *
  4794. + * This program is distributed in the hope that it will be useful,
  4795. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4796. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4797. + * GNU General Public License for more details.
  4798. + *
  4799. + * You should have received a copy of the GNU General Public License
  4800. + * along with this program; if not, write to the Free Software
  4801. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4802. + */
  4803. +
  4804. +#ifndef __BCM2708_ARMCTRL_H
  4805. +#define __BCM2708_ARMCTRL_H
  4806. +
  4807. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  4808. + u32 armctrl_sources, u32 resume_sources);
  4809. +
  4810. +#endif
  4811. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  4812. --- linux-3.12.38/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  4813. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2015-03-10 17:26:49.718216697 +0100
  4814. @@ -0,0 +1,1139 @@
  4815. +/*
  4816. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  4817. + *
  4818. + * Copyright (C) 2010 Broadcom
  4819. + *
  4820. + * This program is free software; you can redistribute it and/or modify
  4821. + * it under the terms of the GNU General Public License as published by
  4822. + * the Free Software Foundation; either version 2 of the License, or
  4823. + * (at your option) any later version.
  4824. + *
  4825. + * This program is distributed in the hope that it will be useful,
  4826. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4827. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4828. + * GNU General Public License for more details.
  4829. + *
  4830. + * You should have received a copy of the GNU General Public License
  4831. + * along with this program; if not, write to the Free Software
  4832. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4833. + */
  4834. +
  4835. +#include <linux/init.h>
  4836. +#include <linux/device.h>
  4837. +#include <linux/dma-mapping.h>
  4838. +#include <linux/serial_8250.h>
  4839. +#include <linux/platform_device.h>
  4840. +#include <linux/syscore_ops.h>
  4841. +#include <linux/interrupt.h>
  4842. +#include <linux/amba/bus.h>
  4843. +#include <linux/amba/clcd.h>
  4844. +#include <linux/clockchips.h>
  4845. +#include <linux/cnt32_to_63.h>
  4846. +#include <linux/io.h>
  4847. +#include <linux/module.h>
  4848. +#include <linux/spi/spi.h>
  4849. +#include <linux/w1-gpio.h>
  4850. +#include <linux/pps-gpio.h>
  4851. +
  4852. +#include <linux/version.h>
  4853. +#include <linux/clkdev.h>
  4854. +#include <asm/system.h>
  4855. +#include <mach/hardware.h>
  4856. +#include <asm/irq.h>
  4857. +#include <linux/leds.h>
  4858. +#include <asm/mach-types.h>
  4859. +#include <linux/sched_clock.h>
  4860. +
  4861. +#include <asm/mach/arch.h>
  4862. +#include <asm/mach/flash.h>
  4863. +#include <asm/mach/irq.h>
  4864. +#include <asm/mach/time.h>
  4865. +#include <asm/mach/map.h>
  4866. +
  4867. +#include <mach/timex.h>
  4868. +#include <mach/dma.h>
  4869. +#include <mach/vcio.h>
  4870. +#include <mach/system.h>
  4871. +
  4872. +#include <linux/delay.h>
  4873. +
  4874. +#include "bcm2708.h"
  4875. +#include "armctrl.h"
  4876. +#include "clock.h"
  4877. +
  4878. +#ifdef CONFIG_BCM_VC_CMA
  4879. +#include <linux/broadcom/vc_cma.h>
  4880. +#endif
  4881. +
  4882. +
  4883. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  4884. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  4885. + * represent this window by setting our dmamasks to 26 bits but, in fact
  4886. + * we're not going to use addresses outside this range (they're not in real
  4887. + * memory) so we don't bother.
  4888. + *
  4889. + * In the future we might include code to use this IOMMU to remap other
  4890. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  4891. + * more legitimate.
  4892. + */
  4893. +#define DMA_MASK_BITS_COMMON 32
  4894. +
  4895. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  4896. +#define W1_GPIO 4
  4897. +// ensure one-wire GPIO pullup is disabled by default
  4898. +#define W1_PULLUP -1
  4899. +
  4900. +/* command line parameters */
  4901. +static unsigned boardrev, serial;
  4902. +static unsigned uart_clock;
  4903. +static unsigned disk_led_gpio = 16;
  4904. +static unsigned disk_led_active_low = 1;
  4905. +static unsigned reboot_part = 0;
  4906. +static unsigned w1_gpio_pin = W1_GPIO;
  4907. +static unsigned w1_gpio_pullup = W1_PULLUP;
  4908. +static int pps_gpio_pin = -1;
  4909. +static unsigned bcm2835_mmc = 1;
  4910. +static bool vc_i2c_override = false;
  4911. +
  4912. +static void __init bcm2708_init_led(void);
  4913. +
  4914. +void __init bcm2708_init_irq(void)
  4915. +{
  4916. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  4917. +}
  4918. +
  4919. +static struct map_desc bcm2708_io_desc[] __initdata = {
  4920. + {
  4921. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  4922. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  4923. + .length = SZ_4K,
  4924. + .type = MT_DEVICE},
  4925. + {
  4926. + .virtual = IO_ADDRESS(UART0_BASE),
  4927. + .pfn = __phys_to_pfn(UART0_BASE),
  4928. + .length = SZ_4K,
  4929. + .type = MT_DEVICE},
  4930. + {
  4931. + .virtual = IO_ADDRESS(UART1_BASE),
  4932. + .pfn = __phys_to_pfn(UART1_BASE),
  4933. + .length = SZ_4K,
  4934. + .type = MT_DEVICE},
  4935. + {
  4936. + .virtual = IO_ADDRESS(DMA_BASE),
  4937. + .pfn = __phys_to_pfn(DMA_BASE),
  4938. + .length = SZ_4K,
  4939. + .type = MT_DEVICE},
  4940. + {
  4941. + .virtual = IO_ADDRESS(MCORE_BASE),
  4942. + .pfn = __phys_to_pfn(MCORE_BASE),
  4943. + .length = SZ_4K,
  4944. + .type = MT_DEVICE},
  4945. + {
  4946. + .virtual = IO_ADDRESS(ST_BASE),
  4947. + .pfn = __phys_to_pfn(ST_BASE),
  4948. + .length = SZ_4K,
  4949. + .type = MT_DEVICE},
  4950. + {
  4951. + .virtual = IO_ADDRESS(USB_BASE),
  4952. + .pfn = __phys_to_pfn(USB_BASE),
  4953. + .length = SZ_128K,
  4954. + .type = MT_DEVICE},
  4955. + {
  4956. + .virtual = IO_ADDRESS(PM_BASE),
  4957. + .pfn = __phys_to_pfn(PM_BASE),
  4958. + .length = SZ_4K,
  4959. + .type = MT_DEVICE},
  4960. + {
  4961. + .virtual = IO_ADDRESS(GPIO_BASE),
  4962. + .pfn = __phys_to_pfn(GPIO_BASE),
  4963. + .length = SZ_4K,
  4964. + .type = MT_DEVICE}
  4965. +};
  4966. +
  4967. +void __init bcm2708_map_io(void)
  4968. +{
  4969. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  4970. +}
  4971. +
  4972. +/* The STC is a free running counter that increments at the rate of 1MHz */
  4973. +#define STC_FREQ_HZ 1000000
  4974. +
  4975. +static inline uint32_t timer_read(void)
  4976. +{
  4977. + /* STC: a free running counter that increments at the rate of 1MHz */
  4978. + return readl(__io_address(ST_BASE + 0x04));
  4979. +}
  4980. +
  4981. +static unsigned long bcm2708_read_current_timer(void)
  4982. +{
  4983. + return timer_read();
  4984. +}
  4985. +
  4986. +static u32 notrace bcm2708_read_sched_clock(void)
  4987. +{
  4988. + return timer_read();
  4989. +}
  4990. +
  4991. +static cycle_t clksrc_read(struct clocksource *cs)
  4992. +{
  4993. + return timer_read();
  4994. +}
  4995. +
  4996. +static struct clocksource clocksource_stc = {
  4997. + .name = "stc",
  4998. + .rating = 300,
  4999. + .read = clksrc_read,
  5000. + .mask = CLOCKSOURCE_MASK(32),
  5001. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  5002. +};
  5003. +
  5004. +unsigned long frc_clock_ticks32(void)
  5005. +{
  5006. + return timer_read();
  5007. +}
  5008. +
  5009. +static void __init bcm2708_clocksource_init(void)
  5010. +{
  5011. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  5012. + printk(KERN_ERR "timer: failed to initialize clock "
  5013. + "source %s\n", clocksource_stc.name);
  5014. + }
  5015. +}
  5016. +
  5017. +
  5018. +/*
  5019. + * These are fixed clocks.
  5020. + */
  5021. +static struct clk ref24_clk = {
  5022. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  5023. +};
  5024. +
  5025. +static struct clk osc_clk = {
  5026. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  5027. + .rate = 27000000,
  5028. +#else
  5029. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  5030. +#endif
  5031. +};
  5032. +
  5033. +/* warning - the USB needs a clock > 34MHz */
  5034. +
  5035. +static struct clk sdhost_clk = {
  5036. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  5037. + .rate = 4000000, /* 4MHz */
  5038. +#else
  5039. + .rate = 250000000, /* 250MHz */
  5040. +#endif
  5041. +};
  5042. +
  5043. +static struct clk_lookup lookups[] = {
  5044. + { /* UART0 */
  5045. + .dev_id = "dev:f1",
  5046. + .clk = &ref24_clk,
  5047. + },
  5048. + { /* USB */
  5049. + .dev_id = "bcm2708_usb",
  5050. + .clk = &osc_clk,
  5051. + }, { /* SPI */
  5052. + .dev_id = "bcm2708_spi.0",
  5053. + .clk = &sdhost_clk,
  5054. + }, { /* BSC0 */
  5055. + .dev_id = "bcm2708_i2c.0",
  5056. + .clk = &sdhost_clk,
  5057. + }, { /* BSC1 */
  5058. + .dev_id = "bcm2708_i2c.1",
  5059. + .clk = &sdhost_clk,
  5060. + }
  5061. +};
  5062. +
  5063. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  5064. +#define UART0_DMA { 15, 14 }
  5065. +
  5066. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  5067. +
  5068. +static struct amba_device *amba_devs[] __initdata = {
  5069. + &uart0_device,
  5070. +};
  5071. +
  5072. +static struct resource bcm2708_dmaman_resources[] = {
  5073. + {
  5074. + .start = DMA_BASE,
  5075. + .end = DMA_BASE + SZ_4K - 1,
  5076. + .flags = IORESOURCE_MEM,
  5077. + }
  5078. +};
  5079. +
  5080. +static struct platform_device bcm2708_dmaman_device = {
  5081. + .name = BCM_DMAMAN_DRIVER_NAME,
  5082. + .id = 0, /* first bcm2708_dma */
  5083. + .resource = bcm2708_dmaman_resources,
  5084. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  5085. +};
  5086. +
  5087. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  5088. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  5089. + .pin = W1_GPIO,
  5090. + .ext_pullup_enable_pin = W1_PULLUP,
  5091. + .is_open_drain = 0,
  5092. +};
  5093. +
  5094. +static struct platform_device w1_device = {
  5095. + .name = "w1-gpio",
  5096. + .id = -1,
  5097. + .dev.platform_data = &w1_gpio_pdata,
  5098. +};
  5099. +#endif
  5100. +
  5101. +static struct pps_gpio_platform_data pps_gpio_info = {
  5102. + .assert_falling_edge = false,
  5103. + .capture_clear = false,
  5104. + .gpio_pin = -1,
  5105. + .gpio_label = "PPS",
  5106. +};
  5107. +
  5108. +static struct platform_device pps_gpio_device = {
  5109. + .name = "pps-gpio",
  5110. + .id = PLATFORM_DEVID_NONE,
  5111. + .dev.platform_data = &pps_gpio_info,
  5112. +};
  5113. +
  5114. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5115. +
  5116. +static struct platform_device bcm2708_fb_device = {
  5117. + .name = "bcm2708_fb",
  5118. + .id = -1, /* only one bcm2708_fb */
  5119. + .resource = NULL,
  5120. + .num_resources = 0,
  5121. + .dev = {
  5122. + .dma_mask = &fb_dmamask,
  5123. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  5124. + },
  5125. +};
  5126. +
  5127. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  5128. + {
  5129. + .mapbase = UART1_BASE + 0x40,
  5130. + .irq = IRQ_AUX,
  5131. + .uartclk = 125000000,
  5132. + .regshift = 2,
  5133. + .iotype = UPIO_MEM,
  5134. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  5135. + .type = PORT_8250,
  5136. + },
  5137. + {},
  5138. +};
  5139. +
  5140. +static struct platform_device bcm2708_uart1_device = {
  5141. + .name = "serial8250",
  5142. + .id = PLAT8250_DEV_PLATFORM,
  5143. + .dev = {
  5144. + .platform_data = bcm2708_uart1_platform_data,
  5145. + },
  5146. +};
  5147. +
  5148. +static struct resource bcm2708_usb_resources[] = {
  5149. + [0] = {
  5150. + .start = USB_BASE,
  5151. + .end = USB_BASE + SZ_128K - 1,
  5152. + .flags = IORESOURCE_MEM,
  5153. + },
  5154. + [1] = {
  5155. + .start = MPHI_BASE,
  5156. + .end = MPHI_BASE + SZ_4K - 1,
  5157. + .flags = IORESOURCE_MEM,
  5158. + },
  5159. + [2] = {
  5160. + .start = IRQ_HOSTPORT,
  5161. + .end = IRQ_HOSTPORT,
  5162. + .flags = IORESOURCE_IRQ,
  5163. + },
  5164. + [3] = {
  5165. + .start = IRQ_USB,
  5166. + .end = IRQ_USB,
  5167. + .flags = IORESOURCE_IRQ,
  5168. + },
  5169. +};
  5170. +
  5171. +
  5172. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5173. +
  5174. +static struct platform_device bcm2708_usb_device = {
  5175. + .name = "bcm2708_usb",
  5176. + .id = -1, /* only one bcm2708_usb */
  5177. + .resource = bcm2708_usb_resources,
  5178. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  5179. + .dev = {
  5180. + .dma_mask = &usb_dmamask,
  5181. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  5182. + },
  5183. +};
  5184. +
  5185. +static struct resource bcm2708_vcio_resources[] = {
  5186. + [0] = { /* mailbox/semaphore/doorbell access */
  5187. + .start = MCORE_BASE,
  5188. + .end = MCORE_BASE + SZ_4K - 1,
  5189. + .flags = IORESOURCE_MEM,
  5190. + },
  5191. +};
  5192. +
  5193. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5194. +
  5195. +static struct platform_device bcm2708_vcio_device = {
  5196. + .name = BCM_VCIO_DRIVER_NAME,
  5197. + .id = -1, /* only one VideoCore I/O area */
  5198. + .resource = bcm2708_vcio_resources,
  5199. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  5200. + .dev = {
  5201. + .dma_mask = &vcio_dmamask,
  5202. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  5203. + },
  5204. +};
  5205. +
  5206. +#ifdef CONFIG_BCM2708_GPIO
  5207. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  5208. +
  5209. +static struct resource bcm2708_gpio_resources[] = {
  5210. + [0] = { /* general purpose I/O */
  5211. + .start = GPIO_BASE,
  5212. + .end = GPIO_BASE + SZ_4K - 1,
  5213. + .flags = IORESOURCE_MEM,
  5214. + },
  5215. +};
  5216. +
  5217. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5218. +
  5219. +static struct platform_device bcm2708_gpio_device = {
  5220. + .name = BCM_GPIO_DRIVER_NAME,
  5221. + .id = -1, /* only one VideoCore I/O area */
  5222. + .resource = bcm2708_gpio_resources,
  5223. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  5224. + .dev = {
  5225. + .dma_mask = &gpio_dmamask,
  5226. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  5227. + },
  5228. +};
  5229. +#endif
  5230. +
  5231. +static struct resource bcm2708_systemtimer_resources[] = {
  5232. + [0] = { /* system timer access */
  5233. + .start = ST_BASE,
  5234. + .end = ST_BASE + SZ_4K - 1,
  5235. + .flags = IORESOURCE_MEM,
  5236. + },
  5237. + {
  5238. + .start = IRQ_TIMER3,
  5239. + .end = IRQ_TIMER3,
  5240. + .flags = IORESOURCE_IRQ,
  5241. + }
  5242. +
  5243. +};
  5244. +
  5245. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5246. +
  5247. +static struct platform_device bcm2708_systemtimer_device = {
  5248. + .name = "bcm2708_systemtimer",
  5249. + .id = -1, /* only one VideoCore I/O area */
  5250. + .resource = bcm2708_systemtimer_resources,
  5251. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  5252. + .dev = {
  5253. + .dma_mask = &systemtimer_dmamask,
  5254. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  5255. + },
  5256. +};
  5257. +
  5258. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  5259. +static struct resource bcm2708_emmc_resources[] = {
  5260. + [0] = {
  5261. + .start = EMMC_BASE,
  5262. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  5263. + /* the memory map actually makes SZ_4K available */
  5264. + .flags = IORESOURCE_MEM,
  5265. + },
  5266. + [1] = {
  5267. + .start = IRQ_ARASANSDIO,
  5268. + .end = IRQ_ARASANSDIO,
  5269. + .flags = IORESOURCE_IRQ,
  5270. + },
  5271. +};
  5272. +
  5273. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  5274. +
  5275. +struct platform_device bcm2708_emmc_device = {
  5276. + .name = "bcm2708_sdhci",
  5277. + .id = 0,
  5278. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  5279. + .resource = bcm2708_emmc_resources,
  5280. + .dev = {
  5281. + .dma_mask = &bcm2708_emmc_dmamask,
  5282. + .coherent_dma_mask = 0xffffffffUL},
  5283. +};
  5284. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  5285. +
  5286. +#ifdef CONFIG_MMC_BCM2835 /* Arasan emmc SD (new) */
  5287. +static struct resource bcm2835_emmc_resources[] = {
  5288. + [0] = {
  5289. + .start = EMMC_BASE,
  5290. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  5291. + /* the memory map actually makes SZ_4K available */
  5292. + .flags = IORESOURCE_MEM,
  5293. + },
  5294. + [1] = {
  5295. + .start = IRQ_ARASANSDIO,
  5296. + .end = IRQ_ARASANSDIO,
  5297. + .flags = IORESOURCE_IRQ,
  5298. + },
  5299. +};
  5300. +
  5301. +static u64 bcm2835_emmc_dmamask = 0xffffffffUL;
  5302. +
  5303. +struct platform_device bcm2835_emmc_device = {
  5304. + .name = "mmc-bcm2835",
  5305. + .id = 0,
  5306. + .num_resources = ARRAY_SIZE(bcm2835_emmc_resources),
  5307. + .resource = bcm2835_emmc_resources,
  5308. + .dev = {
  5309. + .dma_mask = &bcm2835_emmc_dmamask,
  5310. + .coherent_dma_mask = 0xffffffffUL},
  5311. +};
  5312. +#endif /* CONFIG_MMC_BCM2835 */
  5313. +
  5314. +static struct resource bcm2708_powerman_resources[] = {
  5315. + [0] = {
  5316. + .start = PM_BASE,
  5317. + .end = PM_BASE + SZ_256 - 1,
  5318. + .flags = IORESOURCE_MEM,
  5319. + },
  5320. +};
  5321. +
  5322. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5323. +
  5324. +struct platform_device bcm2708_powerman_device = {
  5325. + .name = "bcm2708_powerman",
  5326. + .id = 0,
  5327. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  5328. + .resource = bcm2708_powerman_resources,
  5329. + .dev = {
  5330. + .dma_mask = &powerman_dmamask,
  5331. + .coherent_dma_mask = 0xffffffffUL},
  5332. +};
  5333. +
  5334. +
  5335. +static struct platform_device bcm2708_alsa_devices[] = {
  5336. + [0] = {
  5337. + .name = "bcm2835_AUD0",
  5338. + .id = 0, /* first audio device */
  5339. + .resource = 0,
  5340. + .num_resources = 0,
  5341. + },
  5342. + [1] = {
  5343. + .name = "bcm2835_AUD1",
  5344. + .id = 1, /* second audio device */
  5345. + .resource = 0,
  5346. + .num_resources = 0,
  5347. + },
  5348. + [2] = {
  5349. + .name = "bcm2835_AUD2",
  5350. + .id = 2, /* third audio device */
  5351. + .resource = 0,
  5352. + .num_resources = 0,
  5353. + },
  5354. + [3] = {
  5355. + .name = "bcm2835_AUD3",
  5356. + .id = 3, /* forth audio device */
  5357. + .resource = 0,
  5358. + .num_resources = 0,
  5359. + },
  5360. + [4] = {
  5361. + .name = "bcm2835_AUD4",
  5362. + .id = 4, /* fifth audio device */
  5363. + .resource = 0,
  5364. + .num_resources = 0,
  5365. + },
  5366. + [5] = {
  5367. + .name = "bcm2835_AUD5",
  5368. + .id = 5, /* sixth audio device */
  5369. + .resource = 0,
  5370. + .num_resources = 0,
  5371. + },
  5372. + [6] = {
  5373. + .name = "bcm2835_AUD6",
  5374. + .id = 6, /* seventh audio device */
  5375. + .resource = 0,
  5376. + .num_resources = 0,
  5377. + },
  5378. + [7] = {
  5379. + .name = "bcm2835_AUD7",
  5380. + .id = 7, /* eighth audio device */
  5381. + .resource = 0,
  5382. + .num_resources = 0,
  5383. + },
  5384. +};
  5385. +
  5386. +static struct resource bcm2708_spi_resources[] = {
  5387. + {
  5388. + .start = SPI0_BASE,
  5389. + .end = SPI0_BASE + SZ_256 - 1,
  5390. + .flags = IORESOURCE_MEM,
  5391. + }, {
  5392. + .start = IRQ_SPI,
  5393. + .end = IRQ_SPI,
  5394. + .flags = IORESOURCE_IRQ,
  5395. + }
  5396. +};
  5397. +
  5398. +
  5399. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  5400. +static struct platform_device bcm2708_spi_device = {
  5401. + .name = "bcm2708_spi",
  5402. + .id = 0,
  5403. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  5404. + .resource = bcm2708_spi_resources,
  5405. + .dev = {
  5406. + .dma_mask = &bcm2708_spi_dmamask,
  5407. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  5408. +};
  5409. +
  5410. +#ifdef CONFIG_BCM2708_SPIDEV
  5411. +static struct spi_board_info bcm2708_spi_devices[] = {
  5412. +#ifdef CONFIG_SPI_SPIDEV
  5413. + {
  5414. + .modalias = "spidev",
  5415. + .max_speed_hz = 500000,
  5416. + .bus_num = 0,
  5417. + .chip_select = 0,
  5418. + .mode = SPI_MODE_0,
  5419. + }, {
  5420. + .modalias = "spidev",
  5421. + .max_speed_hz = 500000,
  5422. + .bus_num = 0,
  5423. + .chip_select = 1,
  5424. + .mode = SPI_MODE_0,
  5425. + }
  5426. +#endif
  5427. +};
  5428. +#endif
  5429. +
  5430. +static struct resource bcm2708_bsc0_resources[] = {
  5431. + {
  5432. + .start = BSC0_BASE,
  5433. + .end = BSC0_BASE + SZ_256 - 1,
  5434. + .flags = IORESOURCE_MEM,
  5435. + }, {
  5436. + .start = INTERRUPT_I2C,
  5437. + .end = INTERRUPT_I2C,
  5438. + .flags = IORESOURCE_IRQ,
  5439. + }
  5440. +};
  5441. +
  5442. +static struct platform_device bcm2708_bsc0_device = {
  5443. + .name = "bcm2708_i2c",
  5444. + .id = 0,
  5445. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  5446. + .resource = bcm2708_bsc0_resources,
  5447. +};
  5448. +
  5449. +
  5450. +static struct resource bcm2708_bsc1_resources[] = {
  5451. + {
  5452. + .start = BSC1_BASE,
  5453. + .end = BSC1_BASE + SZ_256 - 1,
  5454. + .flags = IORESOURCE_MEM,
  5455. + }, {
  5456. + .start = INTERRUPT_I2C,
  5457. + .end = INTERRUPT_I2C,
  5458. + .flags = IORESOURCE_IRQ,
  5459. + }
  5460. +};
  5461. +
  5462. +static struct platform_device bcm2708_bsc1_device = {
  5463. + .name = "bcm2708_i2c",
  5464. + .id = 1,
  5465. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  5466. + .resource = bcm2708_bsc1_resources,
  5467. +};
  5468. +
  5469. +static struct platform_device bcm2835_hwmon_device = {
  5470. + .name = "bcm2835_hwmon",
  5471. +};
  5472. +
  5473. +static struct platform_device bcm2835_thermal_device = {
  5474. + .name = "bcm2835_thermal",
  5475. +};
  5476. +
  5477. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  5478. +static struct resource bcm2708_i2s_resources[] = {
  5479. + {
  5480. + .start = I2S_BASE,
  5481. + .end = I2S_BASE + 0x20,
  5482. + .flags = IORESOURCE_MEM,
  5483. + },
  5484. + {
  5485. + .start = PCM_CLOCK_BASE,
  5486. + .end = PCM_CLOCK_BASE + 0x02,
  5487. + .flags = IORESOURCE_MEM,
  5488. + }
  5489. +};
  5490. +
  5491. +static struct platform_device bcm2708_i2s_device = {
  5492. + .name = "bcm2708-i2s",
  5493. + .id = 0,
  5494. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  5495. + .resource = bcm2708_i2s_resources,
  5496. +};
  5497. +#endif
  5498. +
  5499. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  5500. +static struct platform_device snd_hifiberry_dac_device = {
  5501. + .name = "snd-hifiberry-dac",
  5502. + .id = 0,
  5503. + .num_resources = 0,
  5504. +};
  5505. +
  5506. +static struct platform_device snd_pcm5102a_codec_device = {
  5507. + .name = "pcm5102a-codec",
  5508. + .id = -1,
  5509. + .num_resources = 0,
  5510. +};
  5511. +#endif
  5512. +
  5513. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  5514. +static struct platform_device snd_rpi_hifiberry_dacplus_device = {
  5515. + .name = "snd-rpi-hifiberry-dacplus",
  5516. + .id = 0,
  5517. + .num_resources = 0,
  5518. +};
  5519. +
  5520. +static struct i2c_board_info __initdata snd_pcm512x_hbdacplus_i2c_devices[] = {
  5521. + {
  5522. + I2C_BOARD_INFO("pcm5122", 0x4d)
  5523. + },
  5524. +};
  5525. +#endif
  5526. +
  5527. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  5528. +static struct platform_device snd_hifiberry_digi_device = {
  5529. + .name = "snd-hifiberry-digi",
  5530. + .id = 0,
  5531. + .num_resources = 0,
  5532. +};
  5533. +
  5534. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  5535. + {
  5536. + I2C_BOARD_INFO("wm8804", 0x3b)
  5537. + },
  5538. +};
  5539. +
  5540. +#endif
  5541. +
  5542. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  5543. +static struct platform_device snd_hifiberry_amp_device = {
  5544. + .name = "snd-hifiberry-amp",
  5545. + .id = 0,
  5546. + .num_resources = 0,
  5547. +};
  5548. +
  5549. +static struct i2c_board_info __initdata snd_tas5713_i2c_devices[] = {
  5550. + {
  5551. + I2C_BOARD_INFO("tas5713", 0x1b)
  5552. + },
  5553. +};
  5554. +#endif
  5555. +
  5556. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  5557. +static struct platform_device snd_rpi_dac_device = {
  5558. + .name = "snd-rpi-dac",
  5559. + .id = 0,
  5560. + .num_resources = 0,
  5561. +};
  5562. +
  5563. +static struct platform_device snd_pcm1794a_codec_device = {
  5564. + .name = "pcm1794a-codec",
  5565. + .id = -1,
  5566. + .num_resources = 0,
  5567. +};
  5568. +#endif
  5569. +
  5570. +
  5571. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  5572. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  5573. + .name = "snd-rpi-iqaudio-dac",
  5574. + .id = 0,
  5575. + .num_resources = 0,
  5576. +};
  5577. +
  5578. +// Use the actual device name rather than generic driver name
  5579. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  5580. + {
  5581. + I2C_BOARD_INFO("pcm5122", 0x4c)
  5582. + },
  5583. +};
  5584. +#endif
  5585. +
  5586. +int __init bcm_register_device(struct platform_device *pdev)
  5587. +{
  5588. + int ret;
  5589. +
  5590. + ret = platform_device_register(pdev);
  5591. + if (ret)
  5592. + pr_debug("Unable to register platform device '%s': %d\n",
  5593. + pdev->name, ret);
  5594. +
  5595. + return ret;
  5596. +}
  5597. +
  5598. +int calc_rsts(int partition)
  5599. +{
  5600. + return PM_PASSWORD |
  5601. + ((partition & (1 << 0)) << 0) |
  5602. + ((partition & (1 << 1)) << 1) |
  5603. + ((partition & (1 << 2)) << 2) |
  5604. + ((partition & (1 << 3)) << 3) |
  5605. + ((partition & (1 << 4)) << 4) |
  5606. + ((partition & (1 << 5)) << 5);
  5607. +}
  5608. +
  5609. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  5610. +{
  5611. + extern char bcm2708_reboot_mode;
  5612. + uint32_t pm_rstc, pm_wdog;
  5613. + uint32_t timeout = 10;
  5614. + uint32_t pm_rsts = 0;
  5615. +
  5616. + if(bcm2708_reboot_mode == 'q')
  5617. + {
  5618. + // NOOBS < 1.3 booting with reboot=q
  5619. + pm_rsts = readl(__io_address(PM_RSTS));
  5620. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  5621. + }
  5622. + else if(bcm2708_reboot_mode == 'p')
  5623. + {
  5624. + // NOOBS < 1.3 halting
  5625. + pm_rsts = readl(__io_address(PM_RSTS));
  5626. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  5627. + }
  5628. + else
  5629. + {
  5630. + pm_rsts = calc_rsts(reboot_part);
  5631. + }
  5632. +
  5633. + writel(pm_rsts, __io_address(PM_RSTS));
  5634. +
  5635. + /* Setup watchdog for reset */
  5636. + pm_rstc = readl(__io_address(PM_RSTC));
  5637. +
  5638. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  5639. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  5640. +
  5641. + writel(pm_wdog, __io_address(PM_WDOG));
  5642. + writel(pm_rstc, __io_address(PM_RSTC));
  5643. +}
  5644. +
  5645. +/* 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 */
  5646. +static void bcm2708_power_off(void)
  5647. +{
  5648. + extern char bcm2708_reboot_mode;
  5649. + if(bcm2708_reboot_mode == 'q')
  5650. + {
  5651. + // NOOBS < v1.3
  5652. + bcm2708_restart('p', "");
  5653. + }
  5654. + else
  5655. + {
  5656. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  5657. + reboot_part = 63;
  5658. + /* continue with normal reset mechanism */
  5659. + bcm2708_restart(0, "");
  5660. + }
  5661. +}
  5662. +
  5663. +void __init bcm2708_init(void)
  5664. +{
  5665. + int i;
  5666. +
  5667. +#if defined(CONFIG_BCM_VC_CMA)
  5668. + vc_cma_early_init();
  5669. +#endif
  5670. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  5671. + pm_power_off = bcm2708_power_off;
  5672. +
  5673. + if (uart_clock)
  5674. + lookups[0].clk->rate = uart_clock;
  5675. +
  5676. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  5677. + clkdev_add(&lookups[i]);
  5678. +
  5679. + bcm_register_device(&bcm2708_dmaman_device);
  5680. + bcm_register_device(&bcm2708_vcio_device);
  5681. +#ifdef CONFIG_BCM2708_GPIO
  5682. + bcm_register_device(&bcm2708_gpio_device);
  5683. + if (pps_gpio_pin >= 0) {
  5684. + pr_info("bcm2708: GPIO %d setup as pps-gpio device\n", pps_gpio_pin);
  5685. + pps_gpio_info.gpio_pin = pps_gpio_pin;
  5686. + pps_gpio_device.id = pps_gpio_pin;
  5687. + bcm_register_device(&pps_gpio_device);
  5688. + }
  5689. +#endif
  5690. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  5691. + w1_gpio_pdata.pin = w1_gpio_pin;
  5692. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  5693. + platform_device_register(&w1_device);
  5694. +#endif
  5695. + bcm_register_device(&bcm2708_systemtimer_device);
  5696. + bcm_register_device(&bcm2708_fb_device);
  5697. + bcm_register_device(&bcm2708_usb_device);
  5698. + bcm_register_device(&bcm2708_uart1_device);
  5699. + bcm_register_device(&bcm2708_powerman_device);
  5700. +
  5701. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  5702. + if (!bcm2835_mmc)
  5703. + bcm_register_device(&bcm2708_emmc_device);
  5704. +#endif
  5705. +#ifdef CONFIG_MMC_BCM2835
  5706. + if (bcm2835_mmc)
  5707. + bcm_register_device(&bcm2835_emmc_device);
  5708. +#endif
  5709. + bcm2708_init_led();
  5710. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  5711. + bcm_register_device(&bcm2708_alsa_devices[i]);
  5712. +
  5713. + bcm_register_device(&bcm2708_spi_device);
  5714. +
  5715. + if (vc_i2c_override) {
  5716. + bcm_register_device(&bcm2708_bsc0_device);
  5717. + bcm_register_device(&bcm2708_bsc1_device);
  5718. + } else if ((boardrev & 0xffffff) == 0x2 || (boardrev & 0xffffff) == 0x3) {
  5719. + bcm_register_device(&bcm2708_bsc0_device);
  5720. + } else {
  5721. + bcm_register_device(&bcm2708_bsc1_device);
  5722. + }
  5723. +
  5724. + bcm_register_device(&bcm2835_hwmon_device);
  5725. + bcm_register_device(&bcm2835_thermal_device);
  5726. +
  5727. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  5728. + bcm_register_device(&bcm2708_i2s_device);
  5729. +#endif
  5730. +
  5731. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  5732. + bcm_register_device(&snd_hifiberry_dac_device);
  5733. + bcm_register_device(&snd_pcm5102a_codec_device);
  5734. +#endif
  5735. +
  5736. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
  5737. + bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
  5738. + i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
  5739. +#endif
  5740. +
  5741. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  5742. + bcm_register_device(&snd_hifiberry_digi_device);
  5743. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  5744. +#endif
  5745. +
  5746. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
  5747. + bcm_register_device(&snd_hifiberry_amp_device);
  5748. + i2c_register_board_info(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
  5749. +#endif
  5750. +
  5751. +
  5752. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  5753. + bcm_register_device(&snd_rpi_dac_device);
  5754. + bcm_register_device(&snd_pcm1794a_codec_device);
  5755. +#endif
  5756. +
  5757. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  5758. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  5759. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  5760. +#endif
  5761. +
  5762. +
  5763. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  5764. + struct amba_device *d = amba_devs[i];
  5765. + amba_device_register(d, &iomem_resource);
  5766. + }
  5767. + system_rev = boardrev;
  5768. + system_serial_low = serial;
  5769. +
  5770. +#ifdef CONFIG_BCM2708_SPIDEV
  5771. + spi_register_board_info(bcm2708_spi_devices,
  5772. + ARRAY_SIZE(bcm2708_spi_devices));
  5773. +#endif
  5774. +}
  5775. +
  5776. +static void timer_set_mode(enum clock_event_mode mode,
  5777. + struct clock_event_device *clk)
  5778. +{
  5779. + switch (mode) {
  5780. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  5781. + case CLOCK_EVT_MODE_SHUTDOWN:
  5782. + break;
  5783. + case CLOCK_EVT_MODE_PERIODIC:
  5784. +
  5785. + case CLOCK_EVT_MODE_UNUSED:
  5786. + case CLOCK_EVT_MODE_RESUME:
  5787. +
  5788. + default:
  5789. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  5790. + (int)mode);
  5791. + break;
  5792. + }
  5793. +
  5794. +}
  5795. +
  5796. +static int timer_set_next_event(unsigned long cycles,
  5797. + struct clock_event_device *unused)
  5798. +{
  5799. + unsigned long stc;
  5800. + do {
  5801. + stc = readl(__io_address(ST_BASE + 0x04));
  5802. + /* We could take a FIQ here, which may push ST above STC3 */
  5803. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  5804. + } while ((signed long) cycles >= 0 &&
  5805. + (signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  5806. + >= (signed long) cycles);
  5807. + return 0;
  5808. +}
  5809. +
  5810. +static struct clock_event_device timer0_clockevent = {
  5811. + .name = "timer0",
  5812. + .shift = 32,
  5813. + .features = CLOCK_EVT_FEAT_ONESHOT,
  5814. + .set_mode = timer_set_mode,
  5815. + .set_next_event = timer_set_next_event,
  5816. +};
  5817. +
  5818. +/*
  5819. + * IRQ handler for the timer
  5820. + */
  5821. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  5822. +{
  5823. + struct clock_event_device *evt = &timer0_clockevent;
  5824. +
  5825. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  5826. +
  5827. + evt->event_handler(evt);
  5828. +
  5829. + return IRQ_HANDLED;
  5830. +}
  5831. +
  5832. +static struct irqaction bcm2708_timer_irq = {
  5833. + .name = "BCM2708 Timer Tick",
  5834. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  5835. + .handler = bcm2708_timer_interrupt,
  5836. +};
  5837. +
  5838. +/*
  5839. + * Set up timer interrupt, and return the current time in seconds.
  5840. + */
  5841. +
  5842. +static struct delay_timer bcm2708_delay_timer = {
  5843. + .read_current_timer = bcm2708_read_current_timer,
  5844. + .freq = STC_FREQ_HZ,
  5845. +};
  5846. +
  5847. +static void __init bcm2708_timer_init(void)
  5848. +{
  5849. + /* init high res timer */
  5850. + bcm2708_clocksource_init();
  5851. +
  5852. + /*
  5853. + * Initialise to a known state (all timers off)
  5854. + */
  5855. + writel(0, __io_address(ARM_T_CONTROL));
  5856. + /*
  5857. + * Make irqs happen for the system timer
  5858. + */
  5859. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  5860. +
  5861. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  5862. +
  5863. + timer0_clockevent.mult =
  5864. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  5865. + timer0_clockevent.max_delta_ns =
  5866. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  5867. + timer0_clockevent.min_delta_ns =
  5868. + clockevent_delta2ns(0xf, &timer0_clockevent);
  5869. +
  5870. + timer0_clockevent.cpumask = cpumask_of(0);
  5871. + clockevents_register_device(&timer0_clockevent);
  5872. +
  5873. + register_current_timer_delay(&bcm2708_delay_timer);
  5874. +}
  5875. +
  5876. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  5877. +#include <linux/leds.h>
  5878. +
  5879. +static struct gpio_led bcm2708_leds[] = {
  5880. + [0] = {
  5881. + .gpio = 16,
  5882. + .name = "led0",
  5883. + .default_trigger = "mmc0",
  5884. + .active_low = 1,
  5885. + },
  5886. +};
  5887. +
  5888. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  5889. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  5890. + .leds = bcm2708_leds,
  5891. +};
  5892. +
  5893. +static struct platform_device bcm2708_led_device = {
  5894. + .name = "leds-gpio",
  5895. + .id = -1,
  5896. + .dev = {
  5897. + .platform_data = &bcm2708_led_pdata,
  5898. + },
  5899. +};
  5900. +
  5901. +static void __init bcm2708_init_led(void)
  5902. +{
  5903. + bcm2708_leds[0].gpio = disk_led_gpio;
  5904. + bcm2708_leds[0].active_low = disk_led_active_low;
  5905. + platform_device_register(&bcm2708_led_device);
  5906. +}
  5907. +#else
  5908. +static inline void bcm2708_init_led(void)
  5909. +{
  5910. +}
  5911. +#endif
  5912. +
  5913. +void __init bcm2708_init_early(void)
  5914. +{
  5915. + /*
  5916. + * Some devices allocate their coherent buffers from atomic
  5917. + * context. Increase size of atomic coherent pool to make sure such
  5918. + * the allocations won't fail.
  5919. + */
  5920. + init_dma_coherent_pool_size(SZ_4M);
  5921. +}
  5922. +
  5923. +static void __init board_reserve(void)
  5924. +{
  5925. +#if defined(CONFIG_BCM_VC_CMA)
  5926. + vc_cma_reserve();
  5927. +#endif
  5928. +}
  5929. +
  5930. +MACHINE_START(BCM2708, "BCM2708")
  5931. + /* Maintainer: Broadcom Europe Ltd. */
  5932. + .map_io = bcm2708_map_io,
  5933. + .init_irq = bcm2708_init_irq,
  5934. + .init_time = bcm2708_timer_init,
  5935. + .init_machine = bcm2708_init,
  5936. + .init_early = bcm2708_init_early,
  5937. + .reserve = board_reserve,
  5938. + .restart = bcm2708_restart,
  5939. +MACHINE_END
  5940. +
  5941. +module_param(boardrev, uint, 0644);
  5942. +module_param(serial, uint, 0644);
  5943. +module_param(uart_clock, uint, 0644);
  5944. +module_param(disk_led_gpio, uint, 0644);
  5945. +module_param(disk_led_active_low, uint, 0644);
  5946. +module_param(reboot_part, uint, 0644);
  5947. +module_param(w1_gpio_pin, uint, 0644);
  5948. +module_param(w1_gpio_pullup, uint, 0644);
  5949. +module_param(pps_gpio_pin, int, 0644);
  5950. +MODULE_PARM_DESC(pps_gpio_pin, "Set GPIO pin to reserve for PPS");
  5951. +module_param(bcm2835_mmc, uint, 0644);
  5952. +module_param(vc_i2c_override, bool, 0644);
  5953. +MODULE_PARM_DESC(vc_i2c_override, "Allow the use of VC's I2C peripheral.");
  5954. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  5955. --- linux-3.12.38/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  5956. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2015-03-10 17:26:49.718216697 +0100
  5957. @@ -0,0 +1,401 @@
  5958. +/*
  5959. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  5960. + *
  5961. + * Copyright (C) 2010 Broadcom
  5962. + *
  5963. + * This program is free software; you can redistribute it and/or modify
  5964. + * it under the terms of the GNU General Public License version 2 as
  5965. + * published by the Free Software Foundation.
  5966. + *
  5967. + */
  5968. +
  5969. +#include <linux/spinlock.h>
  5970. +#include <linux/module.h>
  5971. +#include <linux/delay.h>
  5972. +#include <linux/list.h>
  5973. +#include <linux/io.h>
  5974. +#include <linux/irq.h>
  5975. +#include <linux/interrupt.h>
  5976. +#include <linux/slab.h>
  5977. +#include <mach/gpio.h>
  5978. +#include <linux/gpio.h>
  5979. +#include <linux/platform_device.h>
  5980. +#include <mach/platform.h>
  5981. +
  5982. +#include <linux/platform_data/bcm2708.h>
  5983. +
  5984. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  5985. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  5986. +#define BCM_GPIO_USE_IRQ 1
  5987. +
  5988. +#define GPIOFSEL(x) (0x00+(x)*4)
  5989. +#define GPIOSET(x) (0x1c+(x)*4)
  5990. +#define GPIOCLR(x) (0x28+(x)*4)
  5991. +#define GPIOLEV(x) (0x34+(x)*4)
  5992. +#define GPIOEDS(x) (0x40+(x)*4)
  5993. +#define GPIOREN(x) (0x4c+(x)*4)
  5994. +#define GPIOFEN(x) (0x58+(x)*4)
  5995. +#define GPIOHEN(x) (0x64+(x)*4)
  5996. +#define GPIOLEN(x) (0x70+(x)*4)
  5997. +#define GPIOAREN(x) (0x7c+(x)*4)
  5998. +#define GPIOAFEN(x) (0x88+(x)*4)
  5999. +#define GPIOUD(x) (0x94+(x)*4)
  6000. +#define GPIOUDCLK(x) (0x98+(x)*4)
  6001. +
  6002. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  6003. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  6004. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  6005. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  6006. +};
  6007. +
  6008. + /* Each of the two spinlocks protects a different set of hardware
  6009. + * regiters and data structurs. This decouples the code of the IRQ from
  6010. + * the GPIO code. This also makes the case of a GPIO routine call from
  6011. + * the IRQ code simpler.
  6012. + */
  6013. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  6014. +
  6015. +struct bcm2708_gpio {
  6016. + struct list_head list;
  6017. + void __iomem *base;
  6018. + struct gpio_chip gc;
  6019. + unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
  6020. + unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
  6021. + unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
  6022. + unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
  6023. +};
  6024. +
  6025. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  6026. + int function)
  6027. +{
  6028. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  6029. + unsigned long flags;
  6030. + unsigned gpiodir;
  6031. + unsigned gpio_bank = offset / 10;
  6032. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  6033. +
  6034. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  6035. + if (offset >= BCM2708_NR_GPIOS)
  6036. + return -EINVAL;
  6037. +
  6038. + spin_lock_irqsave(&lock, flags);
  6039. +
  6040. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  6041. + gpiodir &= ~(7 << gpio_field_offset);
  6042. + gpiodir |= function << gpio_field_offset;
  6043. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  6044. + spin_unlock_irqrestore(&lock, flags);
  6045. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  6046. +
  6047. + return 0;
  6048. +}
  6049. +
  6050. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  6051. +{
  6052. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  6053. +}
  6054. +
  6055. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  6056. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  6057. + int value)
  6058. +{
  6059. + int ret;
  6060. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  6061. + if (ret >= 0)
  6062. + bcm2708_gpio_set(gc, offset, value);
  6063. + return ret;
  6064. +}
  6065. +
  6066. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  6067. +{
  6068. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  6069. + unsigned gpio_bank = offset / 32;
  6070. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  6071. + unsigned lev;
  6072. +
  6073. + if (offset >= BCM2708_NR_GPIOS)
  6074. + return 0;
  6075. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  6076. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  6077. + return 0x1 & (lev >> gpio_field_offset);
  6078. +}
  6079. +
  6080. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  6081. +{
  6082. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  6083. + unsigned gpio_bank = offset / 32;
  6084. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  6085. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  6086. + if (offset >= BCM2708_NR_GPIOS)
  6087. + return;
  6088. + if (value)
  6089. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  6090. + else
  6091. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  6092. +}
  6093. +
  6094. +/**********************
  6095. + * extension to configure pullups
  6096. + */
  6097. +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  6098. + bcm2708_gpio_pull_t value)
  6099. +{
  6100. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  6101. + unsigned gpio_bank = offset / 32;
  6102. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  6103. +
  6104. + if (offset >= BCM2708_NR_GPIOS)
  6105. + return -EINVAL;
  6106. +
  6107. + switch (value) {
  6108. + case BCM2708_PULL_UP:
  6109. + writel(2, gpio->base + GPIOUD(0));
  6110. + break;
  6111. + case BCM2708_PULL_DOWN:
  6112. + writel(1, gpio->base + GPIOUD(0));
  6113. + break;
  6114. + case BCM2708_PULL_OFF:
  6115. + writel(0, gpio->base + GPIOUD(0));
  6116. + break;
  6117. + }
  6118. +
  6119. + udelay(5);
  6120. + writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  6121. + udelay(5);
  6122. + writel(0, gpio->base + GPIOUD(0));
  6123. + writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
  6124. +
  6125. + return 0;
  6126. +}
  6127. +EXPORT_SYMBOL(bcm2708_gpio_setpull);
  6128. +
  6129. +/*************************************************************************************************************************
  6130. + * bcm2708 GPIO IRQ
  6131. + */
  6132. +
  6133. +#if BCM_GPIO_USE_IRQ
  6134. +
  6135. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  6136. +{
  6137. + return gpio_to_irq(gpio);
  6138. +}
  6139. +
  6140. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  6141. +{
  6142. + unsigned irq = d->irq;
  6143. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  6144. + unsigned gn = irq_to_gpio(irq);
  6145. + unsigned gb = gn / 32;
  6146. + unsigned go = gn % 32;
  6147. +
  6148. + gpio->rising[gb] &= ~(1 << go);
  6149. + gpio->falling[gb] &= ~(1 << go);
  6150. + gpio->high[gb] &= ~(1 << go);
  6151. + gpio->low[gb] &= ~(1 << go);
  6152. +
  6153. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  6154. + return -EINVAL;
  6155. +
  6156. + if (type & IRQ_TYPE_EDGE_RISING)
  6157. + gpio->rising[gb] |= (1 << go);
  6158. + if (type & IRQ_TYPE_EDGE_FALLING)
  6159. + gpio->falling[gb] |= (1 << go);
  6160. + if (type & IRQ_TYPE_LEVEL_HIGH)
  6161. + gpio->high[gb] |= (1 << go);
  6162. + if (type & IRQ_TYPE_LEVEL_LOW)
  6163. + gpio->low[gb] |= (1 << go);
  6164. + return 0;
  6165. +}
  6166. +
  6167. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  6168. +{
  6169. + unsigned irq = d->irq;
  6170. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  6171. + unsigned gn = irq_to_gpio(irq);
  6172. + unsigned gb = gn / 32;
  6173. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  6174. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  6175. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  6176. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  6177. +
  6178. + gn = gn % 32;
  6179. +
  6180. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  6181. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  6182. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  6183. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  6184. +}
  6185. +
  6186. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  6187. +{
  6188. + unsigned irq = d->irq;
  6189. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  6190. + unsigned gn = irq_to_gpio(irq);
  6191. + unsigned gb = gn / 32;
  6192. + unsigned go = gn % 32;
  6193. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  6194. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  6195. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  6196. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  6197. +
  6198. + writel(1 << go, gpio->base + GPIOEDS(gb));
  6199. +
  6200. + if (gpio->rising[gb] & (1 << go)) {
  6201. + writel(rising | (1 << go), gpio->base + GPIOREN(gb));
  6202. + } else {
  6203. + writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
  6204. + }
  6205. +
  6206. + if (gpio->falling[gb] & (1 << go)) {
  6207. + writel(falling | (1 << go), gpio->base + GPIOFEN(gb));
  6208. + } else {
  6209. + writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
  6210. + }
  6211. +
  6212. + if (gpio->high[gb] & (1 << go)) {
  6213. + writel(high | (1 << go), gpio->base + GPIOHEN(gb));
  6214. + } else {
  6215. + writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
  6216. + }
  6217. +
  6218. + if (gpio->low[gb] & (1 << go)) {
  6219. + writel(low | (1 << go), gpio->base + GPIOLEN(gb));
  6220. + } else {
  6221. + writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
  6222. + }
  6223. +}
  6224. +
  6225. +static struct irq_chip bcm2708_irqchip = {
  6226. + .name = "GPIO",
  6227. + .irq_enable = bcm2708_gpio_irq_unmask,
  6228. + .irq_disable = bcm2708_gpio_irq_mask,
  6229. + .irq_unmask = bcm2708_gpio_irq_unmask,
  6230. + .irq_mask = bcm2708_gpio_irq_mask,
  6231. + .irq_set_type = bcm2708_gpio_irq_set_type,
  6232. +};
  6233. +
  6234. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  6235. +{
  6236. + unsigned long edsr;
  6237. + unsigned bank;
  6238. + int i;
  6239. + unsigned gpio;
  6240. + for (bank = 0; bank <= 1; bank++) {
  6241. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  6242. + for_each_set_bit(i, &edsr, 32) {
  6243. + gpio = i + bank * 32;
  6244. + generic_handle_irq(gpio_to_irq(gpio));
  6245. + writel(1<<i,__io_address(GPIO_BASE) + GPIOEDS(bank));
  6246. + }
  6247. + }
  6248. + return IRQ_HANDLED;
  6249. +}
  6250. +
  6251. +static struct irqaction bcm2708_gpio_irq = {
  6252. + .name = "BCM2708 GPIO catchall handler",
  6253. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  6254. + .handler = bcm2708_gpio_interrupt,
  6255. +};
  6256. +
  6257. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  6258. +{
  6259. + unsigned irq;
  6260. +
  6261. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  6262. +
  6263. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  6264. + irq_set_chip_data(irq, ucb);
  6265. + irq_set_chip(irq, &bcm2708_irqchip);
  6266. + set_irq_flags(irq, IRQF_VALID);
  6267. + }
  6268. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  6269. +}
  6270. +
  6271. +#else
  6272. +
  6273. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  6274. +{
  6275. +}
  6276. +
  6277. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  6278. +
  6279. +static int bcm2708_gpio_probe(struct platform_device *dev)
  6280. +{
  6281. + struct bcm2708_gpio *ucb;
  6282. + struct resource *res;
  6283. + int err = 0;
  6284. +
  6285. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  6286. +
  6287. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  6288. + if (NULL == ucb) {
  6289. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  6290. + "mailbox memory\n");
  6291. + err = -ENOMEM;
  6292. + goto err;
  6293. + }
  6294. +
  6295. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  6296. +
  6297. + platform_set_drvdata(dev, ucb);
  6298. + ucb->base = __io_address(GPIO_BASE);
  6299. +
  6300. + ucb->gc.label = "bcm2708_gpio";
  6301. + ucb->gc.base = 0;
  6302. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  6303. + ucb->gc.owner = THIS_MODULE;
  6304. +
  6305. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  6306. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  6307. + ucb->gc.get = bcm2708_gpio_get;
  6308. + ucb->gc.set = bcm2708_gpio_set;
  6309. + ucb->gc.can_sleep = 0;
  6310. +
  6311. + bcm2708_gpio_irq_init(ucb);
  6312. +
  6313. + err = gpiochip_add(&ucb->gc);
  6314. + if (err)
  6315. + goto err;
  6316. +
  6317. +err:
  6318. + return err;
  6319. +
  6320. +}
  6321. +
  6322. +static int bcm2708_gpio_remove(struct platform_device *dev)
  6323. +{
  6324. + int err = 0;
  6325. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  6326. +
  6327. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  6328. +
  6329. + err = gpiochip_remove(&ucb->gc);
  6330. +
  6331. + platform_set_drvdata(dev, NULL);
  6332. + kfree(ucb);
  6333. +
  6334. + return err;
  6335. +}
  6336. +
  6337. +static struct platform_driver bcm2708_gpio_driver = {
  6338. + .probe = bcm2708_gpio_probe,
  6339. + .remove = bcm2708_gpio_remove,
  6340. + .driver = {
  6341. + .name = "bcm2708_gpio"},
  6342. +};
  6343. +
  6344. +static int __init bcm2708_gpio_init(void)
  6345. +{
  6346. + return platform_driver_register(&bcm2708_gpio_driver);
  6347. +}
  6348. +
  6349. +static void __exit bcm2708_gpio_exit(void)
  6350. +{
  6351. + platform_driver_unregister(&bcm2708_gpio_driver);
  6352. +}
  6353. +
  6354. +module_init(bcm2708_gpio_init);
  6355. +module_exit(bcm2708_gpio_exit);
  6356. +
  6357. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  6358. +MODULE_LICENSE("GPL");
  6359. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  6360. --- linux-3.12.38/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  6361. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2015-03-09 10:39:28.582893746 +0100
  6362. @@ -0,0 +1,49 @@
  6363. +/*
  6364. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  6365. + *
  6366. + * BCM2708 machine support header
  6367. + *
  6368. + * Copyright (C) 2010 Broadcom
  6369. + *
  6370. + * This program is free software; you can redistribute it and/or modify
  6371. + * it under the terms of the GNU General Public License as published by
  6372. + * the Free Software Foundation; either version 2 of the License, or
  6373. + * (at your option) any later version.
  6374. + *
  6375. + * This program is distributed in the hope that it will be useful,
  6376. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6377. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6378. + * GNU General Public License for more details.
  6379. + *
  6380. + * You should have received a copy of the GNU General Public License
  6381. + * along with this program; if not, write to the Free Software
  6382. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6383. + */
  6384. +
  6385. +#ifndef __BCM2708_BCM2708_H
  6386. +#define __BCM2708_BCM2708_H
  6387. +
  6388. +#include <linux/amba/bus.h>
  6389. +
  6390. +extern void __init bcm2708_init(void);
  6391. +extern void __init bcm2708_init_irq(void);
  6392. +extern void __init bcm2708_map_io(void);
  6393. +extern struct sys_timer bcm2708_timer;
  6394. +extern unsigned int mmc_status(struct device *dev);
  6395. +
  6396. +#define AMBA_DEVICE(name, busid, base, plat) \
  6397. +static struct amba_device name##_device = { \
  6398. + .dev = { \
  6399. + .coherent_dma_mask = ~0, \
  6400. + .init_name = busid, \
  6401. + .platform_data = plat, \
  6402. + }, \
  6403. + .res = { \
  6404. + .start = base##_BASE, \
  6405. + .end = (base##_BASE) + SZ_4K - 1,\
  6406. + .flags = IORESOURCE_MEM, \
  6407. + }, \
  6408. + .irq = base##_IRQ, \
  6409. +}
  6410. +
  6411. +#endif
  6412. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/clock.c linux-rpi/arch/arm/mach-bcm2708/clock.c
  6413. --- linux-3.12.38/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  6414. +++ linux-rpi/arch/arm/mach-bcm2708/clock.c 2015-03-10 17:26:49.718216697 +0100
  6415. @@ -0,0 +1,61 @@
  6416. +/*
  6417. + * linux/arch/arm/mach-bcm2708/clock.c
  6418. + *
  6419. + * Copyright (C) 2010 Broadcom
  6420. + *
  6421. + * This program is free software; you can redistribute it and/or modify
  6422. + * it under the terms of the GNU General Public License as published by
  6423. + * the Free Software Foundation; either version 2 of the License, or
  6424. + * (at your option) any later version.
  6425. + *
  6426. + * This program is distributed in the hope that it will be useful,
  6427. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6428. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6429. + * GNU General Public License for more details.
  6430. + *
  6431. + * You should have received a copy of the GNU General Public License
  6432. + * along with this program; if not, write to the Free Software
  6433. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6434. + */
  6435. +#include <linux/module.h>
  6436. +#include <linux/kernel.h>
  6437. +#include <linux/device.h>
  6438. +#include <linux/list.h>
  6439. +#include <linux/errno.h>
  6440. +#include <linux/err.h>
  6441. +#include <linux/string.h>
  6442. +#include <linux/clk.h>
  6443. +#include <linux/mutex.h>
  6444. +
  6445. +#include <asm/clkdev.h>
  6446. +
  6447. +#include "clock.h"
  6448. +
  6449. +int clk_enable(struct clk *clk)
  6450. +{
  6451. + return 0;
  6452. +}
  6453. +EXPORT_SYMBOL(clk_enable);
  6454. +
  6455. +void clk_disable(struct clk *clk)
  6456. +{
  6457. +}
  6458. +EXPORT_SYMBOL(clk_disable);
  6459. +
  6460. +unsigned long clk_get_rate(struct clk *clk)
  6461. +{
  6462. + return clk->rate;
  6463. +}
  6464. +EXPORT_SYMBOL(clk_get_rate);
  6465. +
  6466. +long clk_round_rate(struct clk *clk, unsigned long rate)
  6467. +{
  6468. + return clk->rate;
  6469. +}
  6470. +EXPORT_SYMBOL(clk_round_rate);
  6471. +
  6472. +int clk_set_rate(struct clk *clk, unsigned long rate)
  6473. +{
  6474. + return -EIO;
  6475. +}
  6476. +EXPORT_SYMBOL(clk_set_rate);
  6477. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/clock.h linux-rpi/arch/arm/mach-bcm2708/clock.h
  6478. --- linux-3.12.38/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  6479. +++ linux-rpi/arch/arm/mach-bcm2708/clock.h 2015-03-10 17:26:49.718216697 +0100
  6480. @@ -0,0 +1,24 @@
  6481. +/*
  6482. + * linux/arch/arm/mach-bcm2708/clock.h
  6483. + *
  6484. + * Copyright (C) 2010 Broadcom
  6485. + *
  6486. + * This program is free software; you can redistribute it and/or modify
  6487. + * it under the terms of the GNU General Public License as published by
  6488. + * the Free Software Foundation; either version 2 of the License, or
  6489. + * (at your option) any later version.
  6490. + *
  6491. + * This program is distributed in the hope that it will be useful,
  6492. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6493. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6494. + * GNU General Public License for more details.
  6495. + *
  6496. + * You should have received a copy of the GNU General Public License
  6497. + * along with this program; if not, write to the Free Software
  6498. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6499. + */
  6500. +struct module;
  6501. +
  6502. +struct clk {
  6503. + unsigned long rate;
  6504. +};
  6505. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  6506. --- linux-3.12.38/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  6507. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2015-03-09 10:39:28.582893746 +0100
  6508. @@ -0,0 +1,409 @@
  6509. +/*
  6510. + * linux/arch/arm/mach-bcm2708/dma.c
  6511. + *
  6512. + * Copyright (C) 2010 Broadcom
  6513. + *
  6514. + * This program is free software; you can redistribute it and/or modify
  6515. + * it under the terms of the GNU General Public License version 2 as
  6516. + * published by the Free Software Foundation.
  6517. + */
  6518. +
  6519. +#include <linux/slab.h>
  6520. +#include <linux/device.h>
  6521. +#include <linux/platform_device.h>
  6522. +#include <linux/module.h>
  6523. +#include <linux/scatterlist.h>
  6524. +
  6525. +#include <mach/dma.h>
  6526. +#include <mach/irqs.h>
  6527. +
  6528. +/*****************************************************************************\
  6529. + * *
  6530. + * Configuration *
  6531. + * *
  6532. +\*****************************************************************************/
  6533. +
  6534. +#define CACHE_LINE_MASK 31
  6535. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  6536. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  6537. +
  6538. +/* valid only for channels 0 - 14, 15 has its own base address */
  6539. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  6540. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  6541. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  6542. +
  6543. +
  6544. +/*****************************************************************************\
  6545. + * *
  6546. + * DMA Auxilliary Functions *
  6547. + * *
  6548. +\*****************************************************************************/
  6549. +
  6550. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  6551. + section inside the DMA buffer and another section outside it.
  6552. + Even if we flush DMA buffers from the cache there is always the chance that
  6553. + during a DMA someone will access the part of a cache line that is outside
  6554. + the DMA buffer - which will then bring in unwelcome data.
  6555. + Without being able to dictate our own buffer pools we must insist that
  6556. + DMA buffers consist of a whole number of cache lines.
  6557. +*/
  6558. +
  6559. +extern int
  6560. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  6561. +{
  6562. + int i;
  6563. +
  6564. + for (i = 0; i < sg_len; i++) {
  6565. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  6566. + sg_ptr[i].length & CACHE_LINE_MASK)
  6567. + return 0;
  6568. + }
  6569. +
  6570. + return 1;
  6571. +}
  6572. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  6573. +
  6574. +extern void
  6575. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  6576. +{
  6577. + dsb(); /* ARM data synchronization (push) operation */
  6578. +
  6579. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  6580. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  6581. +}
  6582. +
  6583. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  6584. +{
  6585. + dsb();
  6586. +
  6587. + /* ugly busy wait only option for now */
  6588. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  6589. + cpu_relax();
  6590. +}
  6591. +
  6592. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  6593. +
  6594. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  6595. +{
  6596. + dsb();
  6597. +
  6598. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  6599. +}
  6600. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  6601. +
  6602. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  6603. + Does nothing if there is no DMA in progress.
  6604. + This routine waits for the current AXI transfer to complete before
  6605. + terminating the current DMA. If the current transfer is hung on a DREQ used
  6606. + by an uncooperative peripheral the AXI transfer may never complete. In this
  6607. + case the routine times out and return a non-zero error code.
  6608. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  6609. + does not produce an interrupt.
  6610. +*/
  6611. +extern int
  6612. +bcm_dma_abort(void __iomem *dma_chan_base)
  6613. +{
  6614. + unsigned long int cs;
  6615. + int rc = 0;
  6616. +
  6617. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  6618. +
  6619. + if (BCM2708_DMA_ACTIVE & cs) {
  6620. + long int timeout = 10000;
  6621. +
  6622. + /* write 0 to the active bit - pause the DMA */
  6623. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  6624. +
  6625. + /* wait for any current AXI transfer to complete */
  6626. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  6627. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  6628. +
  6629. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  6630. + /* we'll un-pause when we set of our next DMA */
  6631. + rc = -ETIMEDOUT;
  6632. +
  6633. + } else if (BCM2708_DMA_ACTIVE & cs) {
  6634. + /* terminate the control block chain */
  6635. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  6636. +
  6637. + /* abort the whole DMA */
  6638. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  6639. + dma_chan_base + BCM2708_DMA_CS);
  6640. + }
  6641. + }
  6642. +
  6643. + return rc;
  6644. +}
  6645. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  6646. +
  6647. +
  6648. +/***************************************************************************** \
  6649. + * *
  6650. + * DMA Manager Device Methods *
  6651. + * *
  6652. +\*****************************************************************************/
  6653. +
  6654. +struct vc_dmaman {
  6655. + void __iomem *dma_base;
  6656. + u32 chan_available; /* bitmap of available channels */
  6657. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  6658. +};
  6659. +
  6660. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  6661. + u32 chans_available)
  6662. +{
  6663. + dmaman->dma_base = dma_base;
  6664. + dmaman->chan_available = chans_available;
  6665. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  6666. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  6667. + dmaman->has_feature[BCM_DMA_FEATURE_NORMAL_ORD] = 0xfe; /* chans 1 to 7 */
  6668. + dmaman->has_feature[BCM_DMA_FEATURE_LITE_ORD] = 0x7f00; /* chans 8 to 14 */
  6669. +}
  6670. +
  6671. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  6672. + unsigned preferred_feature_set)
  6673. +{
  6674. + u32 chans;
  6675. + int feature;
  6676. +
  6677. + chans = dmaman->chan_available;
  6678. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  6679. + /* select the subset of available channels with the desired
  6680. + feature so long as some of the candidate channels have that
  6681. + feature */
  6682. + if ((preferred_feature_set & (1 << feature)) &&
  6683. + (chans & dmaman->has_feature[feature]))
  6684. + chans &= dmaman->has_feature[feature];
  6685. +
  6686. + if (chans) {
  6687. + int chan = 0;
  6688. + /* return the ordinal of the first channel in the bitmap */
  6689. + while (chans != 0 && (chans & 1) == 0) {
  6690. + chans >>= 1;
  6691. + chan++;
  6692. + }
  6693. + /* claim the channel */
  6694. + dmaman->chan_available &= ~(1 << chan);
  6695. + return chan;
  6696. + } else
  6697. + return -ENOMEM;
  6698. +}
  6699. +
  6700. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  6701. +{
  6702. + if (chan < 0)
  6703. + return -EINVAL;
  6704. + else if ((1 << chan) & dmaman->chan_available)
  6705. + return -EIDRM;
  6706. + else {
  6707. + dmaman->chan_available |= (1 << chan);
  6708. + return 0;
  6709. + }
  6710. +}
  6711. +
  6712. +/*****************************************************************************\
  6713. + * *
  6714. + * DMA IRQs *
  6715. + * *
  6716. +\*****************************************************************************/
  6717. +
  6718. +static unsigned char bcm_dma_irqs[] = {
  6719. + IRQ_DMA0,
  6720. + IRQ_DMA1,
  6721. + IRQ_DMA2,
  6722. + IRQ_DMA3,
  6723. + IRQ_DMA4,
  6724. + IRQ_DMA5,
  6725. + IRQ_DMA6,
  6726. + IRQ_DMA7,
  6727. + IRQ_DMA8,
  6728. + IRQ_DMA9,
  6729. + IRQ_DMA10,
  6730. + IRQ_DMA11,
  6731. + IRQ_DMA12
  6732. +};
  6733. +
  6734. +
  6735. +/***************************************************************************** \
  6736. + * *
  6737. + * DMA Manager Monitor *
  6738. + * *
  6739. +\*****************************************************************************/
  6740. +
  6741. +static struct device *dmaman_dev; /* we assume there's only one! */
  6742. +
  6743. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  6744. + void __iomem **out_dma_base, int *out_dma_irq)
  6745. +{
  6746. + if (!dmaman_dev)
  6747. + return -ENODEV;
  6748. + else {
  6749. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  6750. + int rc;
  6751. +
  6752. + device_lock(dmaman_dev);
  6753. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  6754. + if (rc >= 0) {
  6755. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  6756. + rc);
  6757. + *out_dma_irq = bcm_dma_irqs[rc];
  6758. + }
  6759. + device_unlock(dmaman_dev);
  6760. +
  6761. + return rc;
  6762. + }
  6763. +}
  6764. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  6765. +
  6766. +extern int bcm_dma_chan_free(int channel)
  6767. +{
  6768. + if (dmaman_dev) {
  6769. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  6770. + int rc;
  6771. +
  6772. + device_lock(dmaman_dev);
  6773. + rc = vc_dmaman_chan_free(dmaman, channel);
  6774. + device_unlock(dmaman_dev);
  6775. +
  6776. + return rc;
  6777. + } else
  6778. + return -ENODEV;
  6779. +}
  6780. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  6781. +
  6782. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  6783. +{
  6784. + int rc = dmaman_dev ? -EINVAL : 0;
  6785. + dmaman_dev = dev;
  6786. + return rc;
  6787. +}
  6788. +
  6789. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  6790. +{
  6791. + dmaman_dev = NULL;
  6792. +}
  6793. +
  6794. +/*****************************************************************************\
  6795. + * *
  6796. + * DMA Device *
  6797. + * *
  6798. +\*****************************************************************************/
  6799. +
  6800. +static int dmachans = -1; /* module parameter */
  6801. +
  6802. +static int bcm_dmaman_probe(struct platform_device *pdev)
  6803. +{
  6804. + int ret = 0;
  6805. + struct vc_dmaman *dmaman;
  6806. + struct resource *dma_res = NULL;
  6807. + void __iomem *dma_base = NULL;
  6808. + int have_dma_region = 0;
  6809. +
  6810. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  6811. + if (NULL == dmaman) {
  6812. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  6813. + "DMA management memory\n");
  6814. + ret = -ENOMEM;
  6815. + } else {
  6816. +
  6817. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  6818. + if (dma_res == NULL) {
  6819. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  6820. + "resource\n");
  6821. + ret = -ENODEV;
  6822. + } else if (!request_mem_region(dma_res->start,
  6823. + resource_size(dma_res),
  6824. + DRIVER_NAME)) {
  6825. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  6826. + ret = -EBUSY;
  6827. + } else {
  6828. + have_dma_region = 1;
  6829. + dma_base = ioremap(dma_res->start,
  6830. + resource_size(dma_res));
  6831. + if (!dma_base) {
  6832. + dev_err(&pdev->dev, "cannot map DMA region\n");
  6833. + ret = -ENOMEM;
  6834. + } else {
  6835. + /* use module parameter if one was provided */
  6836. + if (dmachans > 0)
  6837. + vc_dmaman_init(dmaman, dma_base,
  6838. + dmachans);
  6839. + else
  6840. + vc_dmaman_init(dmaman, dma_base,
  6841. + DEFAULT_DMACHAN_BITMAP);
  6842. +
  6843. + platform_set_drvdata(pdev, dmaman);
  6844. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  6845. +
  6846. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  6847. + "at %p\n", dma_base);
  6848. + }
  6849. + }
  6850. + }
  6851. + if (ret != 0) {
  6852. + if (dma_base)
  6853. + iounmap(dma_base);
  6854. + if (dma_res && have_dma_region)
  6855. + release_mem_region(dma_res->start,
  6856. + resource_size(dma_res));
  6857. + if (dmaman)
  6858. + kfree(dmaman);
  6859. + }
  6860. + return ret;
  6861. +}
  6862. +
  6863. +static int bcm_dmaman_remove(struct platform_device *pdev)
  6864. +{
  6865. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  6866. +
  6867. + platform_set_drvdata(pdev, NULL);
  6868. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  6869. + kfree(dmaman);
  6870. +
  6871. + return 0;
  6872. +}
  6873. +
  6874. +static struct platform_driver bcm_dmaman_driver = {
  6875. + .probe = bcm_dmaman_probe,
  6876. + .remove = bcm_dmaman_remove,
  6877. +
  6878. + .driver = {
  6879. + .name = DRIVER_NAME,
  6880. + .owner = THIS_MODULE,
  6881. + },
  6882. +};
  6883. +
  6884. +/*****************************************************************************\
  6885. + * *
  6886. + * Driver init/exit *
  6887. + * *
  6888. +\*****************************************************************************/
  6889. +
  6890. +static int __init bcm_dmaman_drv_init(void)
  6891. +{
  6892. + int ret;
  6893. +
  6894. + ret = platform_driver_register(&bcm_dmaman_driver);
  6895. + if (ret != 0) {
  6896. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  6897. + "on platform\n");
  6898. + }
  6899. +
  6900. + return ret;
  6901. +}
  6902. +
  6903. +static void __exit bcm_dmaman_drv_exit(void)
  6904. +{
  6905. + platform_driver_unregister(&bcm_dmaman_driver);
  6906. +}
  6907. +
  6908. +module_init(bcm_dmaman_drv_init);
  6909. +module_exit(bcm_dmaman_drv_exit);
  6910. +
  6911. +module_param(dmachans, int, 0644);
  6912. +
  6913. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  6914. +MODULE_DESCRIPTION("DMA channel manager driver");
  6915. +MODULE_LICENSE("GPL");
  6916. +
  6917. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  6918. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  6919. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  6920. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2015-03-09 10:39:28.582893746 +0100
  6921. @@ -0,0 +1,419 @@
  6922. +/*
  6923. + * linux/arch/arm/mach-bcm2708/arm_control.h
  6924. + *
  6925. + * Copyright (C) 2010 Broadcom
  6926. + *
  6927. + * This program is free software; you can redistribute it and/or modify
  6928. + * it under the terms of the GNU General Public License as published by
  6929. + * the Free Software Foundation; either version 2 of the License, or
  6930. + * (at your option) any later version.
  6931. + *
  6932. + * This program is distributed in the hope that it will be useful,
  6933. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6934. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6935. + * GNU General Public License for more details.
  6936. + *
  6937. + * You should have received a copy of the GNU General Public License
  6938. + * along with this program; if not, write to the Free Software
  6939. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6940. + */
  6941. +
  6942. +#ifndef __BCM2708_ARM_CONTROL_H
  6943. +#define __BCM2708_ARM_CONTROL_H
  6944. +
  6945. +/*
  6946. + * Definitions and addresses for the ARM CONTROL logic
  6947. + * This file is manually generated.
  6948. + */
  6949. +
  6950. +#define ARM_BASE 0x7E00B000
  6951. +
  6952. +/* Basic configuration */
  6953. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  6954. +#define ARM_C0_SIZ128M 0x00000000
  6955. +#define ARM_C0_SIZ256M 0x00000001
  6956. +#define ARM_C0_SIZ512M 0x00000002
  6957. +#define ARM_C0_SIZ1G 0x00000003
  6958. +#define ARM_C0_BRESP0 0x00000000
  6959. +#define ARM_C0_BRESP1 0x00000004
  6960. +#define ARM_C0_BRESP2 0x00000008
  6961. +#define ARM_C0_BOOTHI 0x00000010
  6962. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  6963. +#define ARM_C0_FULLPERI 0x00000040
  6964. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  6965. +#define ARM_C0_JTAGMASK 0x00000E00
  6966. +#define ARM_C0_JTAGOFF 0x00000000
  6967. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  6968. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  6969. +#define ARM_C0_APROTMSK 0x0000F000
  6970. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  6971. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  6972. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  6973. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  6974. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  6975. +#define ARM_C0_PRIO_L2 0x0F000000
  6976. +#define ARM_C0_PRIO_UC 0xF0000000
  6977. +
  6978. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  6979. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  6980. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  6981. +
  6982. +
  6983. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  6984. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  6985. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  6986. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  6987. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  6988. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  6989. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  6990. +
  6991. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  6992. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  6993. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  6994. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  6995. +
  6996. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  6997. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  6998. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  6999. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  7000. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  7001. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  7002. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  7003. +
  7004. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  7005. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  7006. +#define ARM_IDVAL 0x364D5241
  7007. +
  7008. +/* Translation memory */
  7009. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  7010. +/* 32 locations: 0x100.. 0x17F */
  7011. +/* 32 spare means we CAN go to 64 pages.... */
  7012. +
  7013. +
  7014. +/* Interrupts */
  7015. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  7016. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  7017. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  7018. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  7019. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  7020. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  7021. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  7022. +
  7023. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  7024. +/* todo: all I1_interrupt sources */
  7025. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  7026. +/* todo: all I2_interrupt sources */
  7027. +
  7028. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  7029. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  7030. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  7031. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  7032. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  7033. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  7034. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  7035. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  7036. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  7037. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  7038. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  7039. +
  7040. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  7041. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  7042. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  7043. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  7044. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  7045. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  7046. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  7047. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  7048. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  7049. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  7050. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  7051. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  7052. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  7053. +
  7054. +/* Timer */
  7055. +/* For reg. fields see sp804 spec. */
  7056. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  7057. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  7058. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  7059. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  7060. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  7061. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  7062. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  7063. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  7064. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  7065. +
  7066. +#define TIMER_CTRL_ONESHOT (1 << 0)
  7067. +#define TIMER_CTRL_32BIT (1 << 1)
  7068. +#define TIMER_CTRL_DIV1 (0 << 2)
  7069. +#define TIMER_CTRL_DIV16 (1 << 2)
  7070. +#define TIMER_CTRL_DIV256 (2 << 2)
  7071. +#define TIMER_CTRL_IE (1 << 5)
  7072. +#define TIMER_CTRL_PERIODIC (1 << 6)
  7073. +#define TIMER_CTRL_ENABLE (1 << 7)
  7074. +#define TIMER_CTRL_DBGHALT (1 << 8)
  7075. +#define TIMER_CTRL_ENAFREE (1 << 9)
  7076. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  7077. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  7078. +
  7079. +/* Semaphores, Doorbells, Mailboxes */
  7080. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  7081. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  7082. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  7083. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  7084. +
  7085. +/* MAILBOXES
  7086. + * Register flags are common across all
  7087. + * owner registers. See end of this section
  7088. + *
  7089. + * Semaphores, Doorbells, Mailboxes Owner 0
  7090. + *
  7091. + */
  7092. +
  7093. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  7094. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  7095. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  7096. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  7097. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  7098. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  7099. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  7100. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  7101. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  7102. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  7103. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  7104. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  7105. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  7106. +/* MAILBOX 0 access in Owner 0 area */
  7107. +/* Some addresses should ONLY be used by owner 0 */
  7108. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  7109. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  7110. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  7111. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  7112. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  7113. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  7114. +/* MAILBOX 1 access in Owner 0 area */
  7115. +/* Owner 0 should only WRITE to this mailbox */
  7116. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  7117. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  7118. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  7119. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  7120. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  7121. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  7122. +/* General SEM, BELL, MAIL config/status */
  7123. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  7124. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  7125. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  7126. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  7127. +
  7128. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  7129. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  7130. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  7131. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  7132. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  7133. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  7134. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  7135. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  7136. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  7137. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  7138. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  7139. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  7140. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  7141. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  7142. +/* MAILBOX 0 access in Owner 0 area */
  7143. +/* Owner 1 should only WRITE to this mailbox */
  7144. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  7145. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  7146. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  7147. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  7148. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  7149. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  7150. +/* MAILBOX 1 access in Owner 0 area */
  7151. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  7152. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  7153. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  7154. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  7155. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  7156. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  7157. +/* General SEM, BELL, MAIL config/status */
  7158. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  7159. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  7160. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  7161. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  7162. +
  7163. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  7164. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  7165. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  7166. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  7167. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  7168. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  7169. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  7170. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  7171. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  7172. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  7173. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  7174. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  7175. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  7176. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  7177. +/* MAILBOX 0 access in Owner 2 area */
  7178. +/* Owner 2 should only WRITE to this mailbox */
  7179. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  7180. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  7181. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  7182. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  7183. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  7184. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  7185. +/* MAILBOX 1 access in Owner 2 area */
  7186. +/* Owner 2 should only WRITE to this mailbox */
  7187. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  7188. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  7189. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  7190. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  7191. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  7192. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  7193. +/* General SEM, BELL, MAIL config/status */
  7194. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  7195. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  7196. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  7197. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  7198. +
  7199. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  7200. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  7201. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  7202. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  7203. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  7204. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  7205. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  7206. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  7207. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  7208. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  7209. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  7210. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  7211. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  7212. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  7213. +/* MAILBOX 0 access in Owner 3 area */
  7214. +/* Owner 3 should only WRITE to this mailbox */
  7215. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  7216. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  7217. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  7218. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  7219. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  7220. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  7221. +/* MAILBOX 1 access in Owner 3 area */
  7222. +/* Owner 3 should only WRITE to this mailbox */
  7223. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  7224. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  7225. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  7226. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  7227. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  7228. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  7229. +/* General SEM, BELL, MAIL config/status */
  7230. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  7231. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  7232. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  7233. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  7234. +
  7235. +
  7236. +
  7237. +/* Mailbox flags. Valid for all owners */
  7238. +
  7239. +/* Mailbox status register (...0x98) */
  7240. +#define ARM_MS_FULL 0x80000000
  7241. +#define ARM_MS_EMPTY 0x40000000
  7242. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  7243. +
  7244. +/* MAILBOX config/status register (...0x9C) */
  7245. +/* ANY write to this register clears the error bits! */
  7246. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  7247. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  7248. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  7249. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  7250. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  7251. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  7252. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  7253. +/* Bit 7 is unused */
  7254. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  7255. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  7256. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  7257. +
  7258. +/* Semaphore clear/debug register (...0xE0) */
  7259. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  7260. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  7261. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  7262. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  7263. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  7264. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  7265. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  7266. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  7267. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  7268. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  7269. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  7270. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  7271. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  7272. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  7273. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  7274. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  7275. +
  7276. +/* Doorbells clear/debug register (...0xE4) */
  7277. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  7278. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  7279. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  7280. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  7281. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  7282. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  7283. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  7284. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  7285. +
  7286. +/* MY IRQS register (...0xF8) */
  7287. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  7288. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  7289. +
  7290. +/* ALL IRQS register (...0xF8) */
  7291. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  7292. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  7293. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  7294. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  7295. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  7296. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  7297. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  7298. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  7299. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  7300. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  7301. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  7302. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  7303. +/* */
  7304. +/* ARM JTAG BASH */
  7305. +/* */
  7306. +#define AJB_BASE 0x7e2000c0
  7307. +
  7308. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  7309. +#define AJB_BITS0 0x000000
  7310. +#define AJB_BITS4 0x000004
  7311. +#define AJB_BITS8 0x000008
  7312. +#define AJB_BITS12 0x00000C
  7313. +#define AJB_BITS16 0x000010
  7314. +#define AJB_BITS20 0x000014
  7315. +#define AJB_BITS24 0x000018
  7316. +#define AJB_BITS28 0x00001C
  7317. +#define AJB_BITS32 0x000020
  7318. +#define AJB_BITS34 0x000022
  7319. +#define AJB_OUT_MS 0x000040
  7320. +#define AJB_OUT_LS 0x000000
  7321. +#define AJB_INV_CLK 0x000080
  7322. +#define AJB_D0_RISE 0x000100
  7323. +#define AJB_D0_FALL 0x000000
  7324. +#define AJB_D1_RISE 0x000200
  7325. +#define AJB_D1_FALL 0x000000
  7326. +#define AJB_IN_RISE 0x000400
  7327. +#define AJB_IN_FALL 0x000000
  7328. +#define AJB_ENABLE 0x000800
  7329. +#define AJB_HOLD0 0x000000
  7330. +#define AJB_HOLD1 0x001000
  7331. +#define AJB_HOLD2 0x002000
  7332. +#define AJB_HOLD3 0x003000
  7333. +#define AJB_RESETN 0x004000
  7334. +#define AJB_CLKSHFT 16
  7335. +#define AJB_BUSY 0x80000000
  7336. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  7337. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  7338. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  7339. +
  7340. +#endif
  7341. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  7342. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  7343. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2015-03-09 10:39:28.582893746 +0100
  7344. @@ -0,0 +1,62 @@
  7345. +/*
  7346. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  7347. + *
  7348. + * Copyright (C) 2010 Broadcom
  7349. + *
  7350. + * This program is free software; you can redistribute it and/or modify
  7351. + * it under the terms of the GNU General Public License as published by
  7352. + * the Free Software Foundation; either version 2 of the License, or
  7353. + * (at your option) any later version.
  7354. + *
  7355. + * This program is distributed in the hope that it will be useful,
  7356. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7357. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7358. + * GNU General Public License for more details.
  7359. + *
  7360. + * You should have received a copy of the GNU General Public License
  7361. + * along with this program; if not, write to the Free Software
  7362. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7363. + */
  7364. +
  7365. +#ifndef _ARM_POWER_H
  7366. +#define _ARM_POWER_H
  7367. +
  7368. +/* Use meaningful names on each side */
  7369. +#ifdef __VIDEOCORE__
  7370. +#define PREFIX(x) ARM_##x
  7371. +#else
  7372. +#define PREFIX(x) BCM_##x
  7373. +#endif
  7374. +
  7375. +enum {
  7376. + PREFIX(POWER_SDCARD_BIT),
  7377. + PREFIX(POWER_UART_BIT),
  7378. + PREFIX(POWER_MINIUART_BIT),
  7379. + PREFIX(POWER_USB_BIT),
  7380. + PREFIX(POWER_I2C0_BIT),
  7381. + PREFIX(POWER_I2C1_BIT),
  7382. + PREFIX(POWER_I2C2_BIT),
  7383. + PREFIX(POWER_SPI_BIT),
  7384. + PREFIX(POWER_CCP2TX_BIT),
  7385. + PREFIX(POWER_DSI_BIT),
  7386. +
  7387. + PREFIX(POWER_MAX)
  7388. +};
  7389. +
  7390. +enum {
  7391. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  7392. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  7393. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  7394. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  7395. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  7396. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  7397. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  7398. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  7399. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  7400. + PREFIX(POWER_DSI) = (1 << PREFIX(POWER_DSI_BIT)),
  7401. +
  7402. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  7403. + PREFIX(POWER_NONE) = 0
  7404. +};
  7405. +
  7406. +#endif
  7407. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  7408. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  7409. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2015-03-09 10:39:28.582893746 +0100
  7410. @@ -0,0 +1,7 @@
  7411. +#ifndef __ASM_MACH_CLKDEV_H
  7412. +#define __ASM_MACH_CLKDEV_H
  7413. +
  7414. +#define __clk_get(clk) ({ 1; })
  7415. +#define __clk_put(clk) do { } while (0)
  7416. +
  7417. +#endif
  7418. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  7419. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  7420. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2015-03-09 10:39:28.582893746 +0100
  7421. @@ -0,0 +1,22 @@
  7422. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  7423. + *
  7424. + * Debugging macro include header
  7425. + *
  7426. + * Copyright (C) 2010 Broadcom
  7427. + * Copyright (C) 1994-1999 Russell King
  7428. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  7429. + *
  7430. + * This program is free software; you can redistribute it and/or modify
  7431. + * it under the terms of the GNU General Public License version 2 as
  7432. + * published by the Free Software Foundation.
  7433. + *
  7434. +*/
  7435. +
  7436. +#include <mach/platform.h>
  7437. +
  7438. + .macro addruart, rp, rv, tmp
  7439. + ldr \rp, =UART0_BASE
  7440. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  7441. + .endm
  7442. +
  7443. +#include <debug/pl01x.S>
  7444. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  7445. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  7446. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2015-03-09 10:39:28.582893746 +0100
  7447. @@ -0,0 +1,94 @@
  7448. +/*
  7449. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  7450. + *
  7451. + * Copyright (C) 2010 Broadcom
  7452. + *
  7453. + * This program is free software; you can redistribute it and/or modify
  7454. + * it under the terms of the GNU General Public License version 2 as
  7455. + * published by the Free Software Foundation.
  7456. + */
  7457. +
  7458. +
  7459. +#ifndef _MACH_BCM2708_DMA_H
  7460. +#define _MACH_BCM2708_DMA_H
  7461. +
  7462. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  7463. +
  7464. +/* DMA CS Control and Status bits */
  7465. +#define BCM2708_DMA_ACTIVE (1 << 0)
  7466. +#define BCM2708_DMA_INT (1 << 2)
  7467. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  7468. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  7469. +#define BCM2708_DMA_ERR (1 << 8)
  7470. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  7471. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  7472. +
  7473. +/* DMA control block "info" field bits */
  7474. +#define BCM2708_DMA_INT_EN (1 << 0)
  7475. +#define BCM2708_DMA_TDMODE (1 << 1)
  7476. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  7477. +#define BCM2708_DMA_D_INC (1 << 4)
  7478. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  7479. +#define BCM2708_DMA_D_DREQ (1 << 6)
  7480. +#define BCM2708_DMA_S_INC (1 << 8)
  7481. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  7482. +#define BCM2708_DMA_S_DREQ (1 << 10)
  7483. +
  7484. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  7485. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  7486. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  7487. +
  7488. +#define BCM2708_DMA_DREQ_EMMC 11
  7489. +#define BCM2708_DMA_DREQ_SDHOST 13
  7490. +
  7491. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  7492. +#define BCM2708_DMA_ADDR 0x04
  7493. +/* the current control block appears in the following registers - read only */
  7494. +#define BCM2708_DMA_INFO 0x08
  7495. +#define BCM2708_DMA_SOURCE_AD 0x0c
  7496. +#define BCM2708_DMA_DEST_AD 0x10
  7497. +#define BCM2708_DMA_NEXTCB 0x1C
  7498. +#define BCM2708_DMA_DEBUG 0x20
  7499. +
  7500. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  7501. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  7502. +
  7503. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  7504. +
  7505. +struct bcm2708_dma_cb {
  7506. + unsigned long info;
  7507. + unsigned long src;
  7508. + unsigned long dst;
  7509. + unsigned long length;
  7510. + unsigned long stride;
  7511. + unsigned long next;
  7512. + unsigned long pad[2];
  7513. +};
  7514. +struct scatterlist;
  7515. +
  7516. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  7517. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  7518. + dma_addr_t control_block);
  7519. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  7520. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  7521. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  7522. +
  7523. +/* When listing features we can ask for when allocating DMA channels give
  7524. + those with higher priority smaller ordinal numbers */
  7525. +#define BCM_DMA_FEATURE_FAST_ORD 0
  7526. +#define BCM_DMA_FEATURE_BULK_ORD 1
  7527. +#define BCM_DMA_FEATURE_NORMAL_ORD 2
  7528. +#define BCM_DMA_FEATURE_LITE_ORD 3
  7529. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  7530. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  7531. +#define BCM_DMA_FEATURE_NORMAL (1<<BCM_DMA_FEATURE_NORMAL_ORD)
  7532. +#define BCM_DMA_FEATURE_LITE (1<<BCM_DMA_FEATURE_LITE_ORD)
  7533. +#define BCM_DMA_FEATURE_COUNT 4
  7534. +
  7535. +/* return channel no or -ve error */
  7536. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  7537. + void __iomem **out_dma_base, int *out_dma_irq);
  7538. +extern int bcm_dma_chan_free(int channel);
  7539. +
  7540. +
  7541. +#endif /* _MACH_BCM2708_DMA_H */
  7542. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  7543. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  7544. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2015-03-09 10:39:28.582893746 +0100
  7545. @@ -0,0 +1,69 @@
  7546. +/*
  7547. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  7548. + *
  7549. + * Low-level IRQ helper macros for BCM2708 platforms
  7550. + *
  7551. + * Copyright (C) 2010 Broadcom
  7552. + *
  7553. + * This program is free software; you can redistribute it and/or modify
  7554. + * it under the terms of the GNU General Public License as published by
  7555. + * the Free Software Foundation; either version 2 of the License, or
  7556. + * (at your option) any later version.
  7557. + *
  7558. + * This program is distributed in the hope that it will be useful,
  7559. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7560. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7561. + * GNU General Public License for more details.
  7562. + *
  7563. + * You should have received a copy of the GNU General Public License
  7564. + * along with this program; if not, write to the Free Software
  7565. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7566. + */
  7567. +#include <mach/hardware.h>
  7568. +
  7569. + .macro disable_fiq
  7570. + .endm
  7571. +
  7572. + .macro get_irqnr_preamble, base, tmp
  7573. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  7574. + .endm
  7575. +
  7576. + .macro arch_ret_to_user, tmp1, tmp2
  7577. + .endm
  7578. +
  7579. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  7580. + /* get masked status */
  7581. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  7582. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  7583. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  7584. + /* clear bits 8 and 9, and test */
  7585. + bics \irqstat, \irqstat, #0x300
  7586. + bne 1010f
  7587. +
  7588. + tst \tmp, #0x100
  7589. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  7590. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  7591. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  7592. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  7593. + bicne \irqstat, #((1<<18) | (1<<19))
  7594. + bne 1010f
  7595. +
  7596. + tst \tmp, #0x200
  7597. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  7598. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  7599. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  7600. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  7601. + bicne \irqstat, #((1<<30))
  7602. + beq 1020f
  7603. +
  7604. +1010:
  7605. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  7606. + @ N.B. CLZ is an ARM5 instruction.
  7607. + sub \tmp, \irqstat, #1
  7608. + eor \irqstat, \irqstat, \tmp
  7609. + clz \tmp, \irqstat
  7610. + sub \irqnr, \tmp
  7611. +
  7612. +1020: @ EQ will be set if no irqs pending
  7613. +
  7614. + .endm
  7615. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  7616. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  7617. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2015-03-09 10:39:28.582893746 +0100
  7618. @@ -0,0 +1,38 @@
  7619. +/*
  7620. + * arch/arm/mach-bcm2708/include/mach/timex.h
  7621. + *
  7622. + * BCM2708 free running counter (timer)
  7623. + *
  7624. + * Copyright (C) 2010 Broadcom
  7625. + *
  7626. + * This program is free software; you can redistribute it and/or modify
  7627. + * it under the terms of the GNU General Public License as published by
  7628. + * the Free Software Foundation; either version 2 of the License, or
  7629. + * (at your option) any later version.
  7630. + *
  7631. + * This program is distributed in the hope that it will be useful,
  7632. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7633. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7634. + * GNU General Public License for more details.
  7635. + *
  7636. + * You should have received a copy of the GNU General Public License
  7637. + * along with this program; if not, write to the Free Software
  7638. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7639. + */
  7640. +
  7641. +#ifndef _MACH_FRC_H
  7642. +#define _MACH_FRC_H
  7643. +
  7644. +#define FRC_TICK_RATE (1000000)
  7645. +
  7646. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  7647. + (slightly faster than frc_clock_ticks63()
  7648. + */
  7649. +extern unsigned long frc_clock_ticks32(void);
  7650. +
  7651. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  7652. + * Note - top bit should be ignored (see cnt32_to_63)
  7653. + */
  7654. +extern unsigned long long frc_clock_ticks63(void);
  7655. +
  7656. +#endif
  7657. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  7658. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  7659. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2015-03-09 10:39:28.582893746 +0100
  7660. @@ -0,0 +1,17 @@
  7661. +/*
  7662. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  7663. + *
  7664. + * This file is licensed under the terms of the GNU General Public
  7665. + * License version 2. This program is licensed "as is" without any
  7666. + * warranty of any kind, whether express or implied.
  7667. + */
  7668. +
  7669. +#ifndef __ASM_ARCH_GPIO_H
  7670. +#define __ASM_ARCH_GPIO_H
  7671. +
  7672. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  7673. +
  7674. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  7675. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  7676. +
  7677. +#endif
  7678. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  7679. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  7680. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2015-03-09 10:39:28.582893746 +0100
  7681. @@ -0,0 +1,28 @@
  7682. +/*
  7683. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  7684. + *
  7685. + * This file contains the hardware definitions of the BCM2708 devices.
  7686. + *
  7687. + * Copyright (C) 2010 Broadcom
  7688. + *
  7689. + * This program is free software; you can redistribute it and/or modify
  7690. + * it under the terms of the GNU General Public License as published by
  7691. + * the Free Software Foundation; either version 2 of the License, or
  7692. + * (at your option) any later version.
  7693. + *
  7694. + * This program is distributed in the hope that it will be useful,
  7695. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7696. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7697. + * GNU General Public License for more details.
  7698. + *
  7699. + * You should have received a copy of the GNU General Public License
  7700. + * along with this program; if not, write to the Free Software
  7701. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7702. + */
  7703. +#ifndef __ASM_ARCH_HARDWARE_H
  7704. +#define __ASM_ARCH_HARDWARE_H
  7705. +
  7706. +#include <asm/sizes.h>
  7707. +#include <mach/platform.h>
  7708. +
  7709. +#endif
  7710. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  7711. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  7712. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2015-03-09 10:39:28.582893746 +0100
  7713. @@ -0,0 +1,27 @@
  7714. +/*
  7715. + * arch/arm/mach-bcm2708/include/mach/io.h
  7716. + *
  7717. + * Copyright (C) 2003 ARM Limited
  7718. + *
  7719. + * This program is free software; you can redistribute it and/or modify
  7720. + * it under the terms of the GNU General Public License as published by
  7721. + * the Free Software Foundation; either version 2 of the License, or
  7722. + * (at your option) any later version.
  7723. + *
  7724. + * This program is distributed in the hope that it will be useful,
  7725. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7726. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7727. + * GNU General Public License for more details.
  7728. + *
  7729. + * You should have received a copy of the GNU General Public License
  7730. + * along with this program; if not, write to the Free Software
  7731. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7732. + */
  7733. +#ifndef __ASM_ARM_ARCH_IO_H
  7734. +#define __ASM_ARM_ARCH_IO_H
  7735. +
  7736. +#define IO_SPACE_LIMIT 0xffffffff
  7737. +
  7738. +#define __io(a) __typesafe_io(a)
  7739. +
  7740. +#endif
  7741. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  7742. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  7743. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2015-03-09 10:39:28.582893746 +0100
  7744. @@ -0,0 +1,199 @@
  7745. +/*
  7746. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  7747. + *
  7748. + * Copyright (C) 2010 Broadcom
  7749. + * Copyright (C) 2003 ARM Limited
  7750. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  7751. + *
  7752. + * This program is free software; you can redistribute it and/or modify
  7753. + * it under the terms of the GNU General Public License as published by
  7754. + * the Free Software Foundation; either version 2 of the License, or
  7755. + * (at your option) any later version.
  7756. + *
  7757. + * This program is distributed in the hope that it will be useful,
  7758. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7759. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7760. + * GNU General Public License for more details.
  7761. + *
  7762. + * You should have received a copy of the GNU General Public License
  7763. + * along with this program; if not, write to the Free Software
  7764. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7765. + */
  7766. +
  7767. +#ifndef _BCM2708_IRQS_H_
  7768. +#define _BCM2708_IRQS_H_
  7769. +
  7770. +#include <mach/platform.h>
  7771. +
  7772. +/*
  7773. + * IRQ interrupts definitions are the same as the INT definitions
  7774. + * held within platform.h
  7775. + */
  7776. +#define IRQ_ARMCTRL_START 0
  7777. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  7778. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  7779. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  7780. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  7781. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  7782. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  7783. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  7784. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  7785. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  7786. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  7787. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  7788. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  7789. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  7790. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  7791. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  7792. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  7793. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  7794. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  7795. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  7796. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  7797. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  7798. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  7799. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  7800. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  7801. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  7802. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  7803. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  7804. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  7805. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  7806. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  7807. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  7808. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  7809. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  7810. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  7811. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  7812. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  7813. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  7814. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  7815. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  7816. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  7817. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  7818. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  7819. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  7820. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  7821. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  7822. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  7823. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  7824. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  7825. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  7826. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  7827. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  7828. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  7829. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  7830. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  7831. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  7832. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  7833. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  7834. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  7835. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  7836. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  7837. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  7838. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  7839. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  7840. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  7841. +
  7842. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  7843. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  7844. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  7845. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  7846. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  7847. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  7848. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  7849. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  7850. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  7851. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  7852. +
  7853. +#define FIQ_START HARD_IRQS
  7854. +
  7855. +/*
  7856. + * FIQ interrupts definitions are the same as the INT definitions.
  7857. + */
  7858. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  7859. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  7860. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  7861. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  7862. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  7863. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  7864. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  7865. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  7866. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  7867. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  7868. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  7869. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  7870. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  7871. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  7872. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  7873. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  7874. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  7875. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  7876. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  7877. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  7878. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  7879. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  7880. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  7881. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  7882. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  7883. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  7884. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  7885. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  7886. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  7887. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  7888. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  7889. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  7890. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  7891. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  7892. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  7893. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  7894. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  7895. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  7896. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  7897. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  7898. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  7899. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  7900. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  7901. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  7902. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  7903. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  7904. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  7905. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  7906. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  7907. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  7908. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  7909. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  7910. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  7911. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  7912. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  7913. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  7914. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  7915. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  7916. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  7917. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  7918. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  7919. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  7920. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  7921. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  7922. +
  7923. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  7924. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  7925. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  7926. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  7927. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  7928. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  7929. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  7930. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  7931. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  7932. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  7933. +
  7934. +#define HARD_IRQS (64 + 21)
  7935. +#define FIQ_IRQS (64 + 21)
  7936. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  7937. +#define GPIO_IRQS (32*5)
  7938. +#define SPARE_ALLOC_IRQS 64
  7939. +#define BCM2708_ALLOC_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_ALLOC_IRQS)
  7940. +#define FREE_IRQS 128
  7941. +#define NR_IRQS (BCM2708_ALLOC_IRQS+FREE_IRQS)
  7942. +
  7943. +#endif /* _BCM2708_IRQS_H_ */
  7944. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  7945. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  7946. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2015-03-10 17:26:49.718216697 +0100
  7947. @@ -0,0 +1,57 @@
  7948. +/*
  7949. + * arch/arm/mach-bcm2708/include/mach/memory.h
  7950. + *
  7951. + * Copyright (C) 2010 Broadcom
  7952. + *
  7953. + * This program is free software; you can redistribute it and/or modify
  7954. + * it under the terms of the GNU General Public License as published by
  7955. + * the Free Software Foundation; either version 2 of the License, or
  7956. + * (at your option) any later version.
  7957. + *
  7958. + * This program is distributed in the hope that it will be useful,
  7959. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7960. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7961. + * GNU General Public License for more details.
  7962. + *
  7963. + * You should have received a copy of the GNU General Public License
  7964. + * along with this program; if not, write to the Free Software
  7965. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7966. + */
  7967. +#ifndef __ASM_ARCH_MEMORY_H
  7968. +#define __ASM_ARCH_MEMORY_H
  7969. +
  7970. +/* Memory overview:
  7971. +
  7972. + [ARMcore] <--virtual addr-->
  7973. + [ARMmmu] <--physical addr-->
  7974. + [GERTmap] <--bus add-->
  7975. + [VCperiph]
  7976. +
  7977. +*/
  7978. +
  7979. +/*
  7980. + * Physical DRAM offset.
  7981. + */
  7982. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  7983. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  7984. +
  7985. +#ifdef CONFIG_BCM2708_NOL2CACHE
  7986. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  7987. +#else
  7988. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  7989. +#endif
  7990. +
  7991. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  7992. + * will provide the offset into this area as well as setting the bits that
  7993. + * stop the L1 and L2 cache from being used
  7994. + *
  7995. + * WARNING: this only works because the ARM is given memory at a fixed location
  7996. + * (ARMMEM_OFFSET)
  7997. + */
  7998. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  7999. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  8000. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  8001. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  8002. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  8003. +
  8004. +#endif
  8005. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  8006. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  8007. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2015-03-09 10:39:28.582893746 +0100
  8008. @@ -0,0 +1,228 @@
  8009. +/*
  8010. + * arch/arm/mach-bcm2708/include/mach/platform.h
  8011. + *
  8012. + * Copyright (C) 2010 Broadcom
  8013. + *
  8014. + * This program is free software; you can redistribute it and/or modify
  8015. + * it under the terms of the GNU General Public License as published by
  8016. + * the Free Software Foundation; either version 2 of the License, or
  8017. + * (at your option) any later version.
  8018. + *
  8019. + * This program is distributed in the hope that it will be useful,
  8020. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8021. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8022. + * GNU General Public License for more details.
  8023. + *
  8024. + * You should have received a copy of the GNU General Public License
  8025. + * along with this program; if not, write to the Free Software
  8026. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8027. + */
  8028. +
  8029. +#ifndef _BCM2708_PLATFORM_H
  8030. +#define _BCM2708_PLATFORM_H
  8031. +
  8032. +
  8033. +/* macros to get at IO space when running virtually */
  8034. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  8035. +
  8036. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  8037. +
  8038. +
  8039. +/*
  8040. + * SDRAM
  8041. + */
  8042. +#define BCM2708_SDRAM_BASE 0x00000000
  8043. +
  8044. +/*
  8045. + * Logic expansion modules
  8046. + *
  8047. + */
  8048. +
  8049. +
  8050. +/* ------------------------------------------------------------------------
  8051. + * BCM2708 ARMCTRL Registers
  8052. + * ------------------------------------------------------------------------
  8053. + */
  8054. +
  8055. +#define HW_REGISTER_RW(addr) (addr)
  8056. +#define HW_REGISTER_RO(addr) (addr)
  8057. +
  8058. +#include "arm_control.h"
  8059. +#undef ARM_BASE
  8060. +
  8061. +/*
  8062. + * Definitions and addresses for the ARM CONTROL logic
  8063. + * This file is manually generated.
  8064. + */
  8065. +
  8066. +#define BCM2708_PERI_BASE 0x20000000
  8067. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  8068. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  8069. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  8070. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  8071. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  8072. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  8073. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  8074. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  8075. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  8076. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  8077. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  8078. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  8079. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  8080. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  8081. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  8082. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  8083. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  8084. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  8085. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  8086. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  8087. +
  8088. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  8089. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  8090. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  8091. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  8092. +
  8093. +
  8094. +/*
  8095. + * Interrupt assignments
  8096. + */
  8097. +
  8098. +#define ARM_IRQ1_BASE 0
  8099. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  8100. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  8101. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  8102. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  8103. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  8104. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  8105. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  8106. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  8107. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  8108. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  8109. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  8110. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  8111. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  8112. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  8113. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  8114. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  8115. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  8116. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  8117. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  8118. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  8119. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  8120. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  8121. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  8122. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  8123. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  8124. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  8125. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  8126. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  8127. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  8128. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  8129. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  8130. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  8131. +
  8132. +#define ARM_IRQ2_BASE 32
  8133. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  8134. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  8135. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  8136. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  8137. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  8138. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  8139. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  8140. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  8141. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  8142. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  8143. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  8144. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  8145. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  8146. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  8147. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  8148. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  8149. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  8150. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  8151. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  8152. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  8153. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  8154. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  8155. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  8156. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  8157. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  8158. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  8159. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  8160. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  8161. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  8162. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  8163. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  8164. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  8165. +
  8166. +#define ARM_IRQ0_BASE 64
  8167. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  8168. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  8169. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  8170. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  8171. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  8172. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  8173. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  8174. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  8175. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  8176. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  8177. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  8178. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  8179. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  8180. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  8181. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  8182. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  8183. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  8184. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  8185. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  8186. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  8187. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  8188. +
  8189. +#define MAXIRQNUM (32 + 32 + 20)
  8190. +#define MAXFIQNUM (32 + 32 + 20)
  8191. +
  8192. +#define MAX_TIMER 2
  8193. +#define MAX_PERIOD 699050
  8194. +#define TICKS_PER_uSEC 1
  8195. +
  8196. +/*
  8197. + * These are useconds NOT ticks.
  8198. + *
  8199. + */
  8200. +#define mSEC_1 1000
  8201. +#define mSEC_5 (mSEC_1 * 5)
  8202. +#define mSEC_10 (mSEC_1 * 10)
  8203. +#define mSEC_25 (mSEC_1 * 25)
  8204. +#define SEC_1 (mSEC_1 * 1000)
  8205. +
  8206. +/*
  8207. + * Watchdog
  8208. + */
  8209. +#define PM_RSTC (PM_BASE+0x1c)
  8210. +#define PM_RSTS (PM_BASE+0x20)
  8211. +#define PM_WDOG (PM_BASE+0x24)
  8212. +
  8213. +#define PM_WDOG_RESET 0000000000
  8214. +#define PM_PASSWORD 0x5a000000
  8215. +#define PM_WDOG_TIME_SET 0x000fffff
  8216. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  8217. +#define PM_RSTC_WRCFG_SET 0x00000030
  8218. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  8219. +#define PM_RSTC_RESET 0x00000102
  8220. +
  8221. +#define PM_RSTS_HADPOR_SET 0x00001000
  8222. +#define PM_RSTS_HADSRH_SET 0x00000400
  8223. +#define PM_RSTS_HADSRF_SET 0x00000200
  8224. +#define PM_RSTS_HADSRQ_SET 0x00000100
  8225. +#define PM_RSTS_HADWRH_SET 0x00000040
  8226. +#define PM_RSTS_HADWRF_SET 0x00000020
  8227. +#define PM_RSTS_HADWRQ_SET 0x00000010
  8228. +#define PM_RSTS_HADDRH_SET 0x00000004
  8229. +#define PM_RSTS_HADDRF_SET 0x00000002
  8230. +#define PM_RSTS_HADDRQ_SET 0x00000001
  8231. +
  8232. +#define UART0_CLOCK 3000000
  8233. +
  8234. +#endif
  8235. +
  8236. +/* END */
  8237. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  8238. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  8239. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2015-03-09 10:39:28.582893746 +0100
  8240. @@ -0,0 +1,26 @@
  8241. +/*
  8242. + * linux/arch/arm/mach-bcm2708/power.h
  8243. + *
  8244. + * Copyright (C) 2010 Broadcom
  8245. + *
  8246. + * This program is free software; you can redistribute it and/or modify
  8247. + * it under the terms of the GNU General Public License version 2 as
  8248. + * published by the Free Software Foundation.
  8249. + *
  8250. + * This device provides a shared mechanism for controlling the power to
  8251. + * VideoCore subsystems.
  8252. + */
  8253. +
  8254. +#ifndef _MACH_BCM2708_POWER_H
  8255. +#define _MACH_BCM2708_POWER_H
  8256. +
  8257. +#include <linux/types.h>
  8258. +#include <mach/arm_power.h>
  8259. +
  8260. +typedef unsigned int BCM_POWER_HANDLE_T;
  8261. +
  8262. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  8263. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  8264. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  8265. +
  8266. +#endif
  8267. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  8268. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  8269. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2015-03-09 10:39:28.582893746 +0100
  8270. @@ -0,0 +1,38 @@
  8271. +/*
  8272. + * arch/arm/mach-bcm2708/include/mach/system.h
  8273. + *
  8274. + * Copyright (C) 2010 Broadcom
  8275. + * Copyright (C) 2003 ARM Limited
  8276. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  8277. + *
  8278. + * This program is free software; you can redistribute it and/or modify
  8279. + * it under the terms of the GNU General Public License as published by
  8280. + * the Free Software Foundation; either version 2 of the License, or
  8281. + * (at your option) any later version.
  8282. + *
  8283. + * This program is distributed in the hope that it will be useful,
  8284. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8285. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8286. + * GNU General Public License for more details.
  8287. + *
  8288. + * You should have received a copy of the GNU General Public License
  8289. + * along with this program; if not, write to the Free Software
  8290. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8291. + */
  8292. +#ifndef __ASM_ARCH_SYSTEM_H
  8293. +#define __ASM_ARCH_SYSTEM_H
  8294. +
  8295. +#include <linux/io.h>
  8296. +#include <mach/hardware.h>
  8297. +#include <mach/platform.h>
  8298. +
  8299. +static inline void arch_idle(void)
  8300. +{
  8301. + /*
  8302. + * This should do all the clock switching
  8303. + * and wait for interrupt tricks
  8304. + */
  8305. + cpu_do_idle();
  8306. +}
  8307. +
  8308. +#endif
  8309. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  8310. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  8311. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2015-03-09 10:39:28.582893746 +0100
  8312. @@ -0,0 +1,23 @@
  8313. +/*
  8314. + * arch/arm/mach-bcm2708/include/mach/timex.h
  8315. + *
  8316. + * BCM2708 sysem clock frequency
  8317. + *
  8318. + * Copyright (C) 2010 Broadcom
  8319. + *
  8320. + * This program is free software; you can redistribute it and/or modify
  8321. + * it under the terms of the GNU General Public License as published by
  8322. + * the Free Software Foundation; either version 2 of the License, or
  8323. + * (at your option) any later version.
  8324. + *
  8325. + * This program is distributed in the hope that it will be useful,
  8326. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8327. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8328. + * GNU General Public License for more details.
  8329. + *
  8330. + * You should have received a copy of the GNU General Public License
  8331. + * along with this program; if not, write to the Free Software
  8332. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8333. + */
  8334. +
  8335. +#define CLOCK_TICK_RATE (1000000)
  8336. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  8337. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  8338. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2015-03-09 10:39:28.582893746 +0100
  8339. @@ -0,0 +1,84 @@
  8340. +/*
  8341. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  8342. + *
  8343. + * Copyright (C) 2010 Broadcom
  8344. + * Copyright (C) 2003 ARM Limited
  8345. + *
  8346. + * This program is free software; you can redistribute it and/or modify
  8347. + * it under the terms of the GNU General Public License as published by
  8348. + * the Free Software Foundation; either version 2 of the License, or
  8349. + * (at your option) any later version.
  8350. + *
  8351. + * This program is distributed in the hope that it will be useful,
  8352. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8353. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8354. + * GNU General Public License for more details.
  8355. + *
  8356. + * You should have received a copy of the GNU General Public License
  8357. + * along with this program; if not, write to the Free Software
  8358. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8359. + */
  8360. +
  8361. +#include <linux/io.h>
  8362. +#include <linux/amba/serial.h>
  8363. +#include <mach/hardware.h>
  8364. +
  8365. +#define UART_BAUD 115200
  8366. +
  8367. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  8368. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  8369. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  8370. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  8371. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  8372. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  8373. +
  8374. +/*
  8375. + * This does not append a newline
  8376. + */
  8377. +static inline void putc(int c)
  8378. +{
  8379. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  8380. + barrier();
  8381. +
  8382. + __raw_writel(c, BCM2708_UART_DR);
  8383. +}
  8384. +
  8385. +static inline void flush(void)
  8386. +{
  8387. + int fr;
  8388. +
  8389. + do {
  8390. + fr = __raw_readl(BCM2708_UART_FR);
  8391. + barrier();
  8392. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  8393. +}
  8394. +
  8395. +static inline void arch_decomp_setup(void)
  8396. +{
  8397. + int temp, div, rem, frac;
  8398. +
  8399. + temp = 16 * UART_BAUD;
  8400. + div = UART0_CLOCK / temp;
  8401. + rem = UART0_CLOCK % temp;
  8402. + temp = (8 * rem) / UART_BAUD;
  8403. + frac = (temp >> 1) + (temp & 1);
  8404. +
  8405. + /* Make sure the UART is disabled before we start */
  8406. + __raw_writel(0, BCM2708_UART_CR);
  8407. +
  8408. + /* Set the baud rate */
  8409. + __raw_writel(div, BCM2708_UART_IBRD);
  8410. + __raw_writel(frac, BCM2708_UART_FBRD);
  8411. +
  8412. + /* Set the UART to 8n1, FIFO enabled */
  8413. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  8414. +
  8415. + /* Enable the UART */
  8416. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  8417. + BCM2708_UART_CR);
  8418. +}
  8419. +
  8420. +/*
  8421. + * nothing to do
  8422. + */
  8423. +#define arch_decomp_wdog()
  8424. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  8425. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  8426. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2015-03-09 10:39:28.582893746 +0100
  8427. @@ -0,0 +1,165 @@
  8428. +/*
  8429. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  8430. + *
  8431. + * Copyright (C) 2010 Broadcom
  8432. + *
  8433. + * This program is free software; you can redistribute it and/or modify
  8434. + * it under the terms of the GNU General Public License as published by
  8435. + * the Free Software Foundation; either version 2 of the License, or
  8436. + * (at your option) any later version.
  8437. + *
  8438. + * This program is distributed in the hope that it will be useful,
  8439. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8440. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8441. + * GNU General Public License for more details.
  8442. + *
  8443. + * You should have received a copy of the GNU General Public License
  8444. + * along with this program; if not, write to the Free Software
  8445. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8446. + */
  8447. +#ifndef _MACH_BCM2708_VCIO_H
  8448. +#define _MACH_BCM2708_VCIO_H
  8449. +
  8450. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  8451. + * (semaphores, doorbells, mailboxes)
  8452. + */
  8453. +
  8454. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  8455. +
  8456. +/* Constants shared with the ARM identifying separate mailbox channels */
  8457. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  8458. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  8459. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  8460. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  8461. +#define MBOX_CHAN_COUNT 9
  8462. +
  8463. +enum {
  8464. + VCMSG_PROCESS_REQUEST = 0x00000000
  8465. +};
  8466. +enum {
  8467. + VCMSG_REQUEST_SUCCESSFUL = 0x80000000,
  8468. + VCMSG_REQUEST_FAILED = 0x80000001
  8469. +};
  8470. +/* Mailbox property tags */
  8471. +enum {
  8472. + VCMSG_PROPERTY_END = 0x00000000,
  8473. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  8474. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  8475. + VCMSG_GET_BOARD_REVISION = 0x00010002,
  8476. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00010003,
  8477. + VCMSG_GET_BOARD_SERIAL = 0x00010004,
  8478. + VCMSG_GET_ARM_MEMORY = 0x00010005,
  8479. + VCMSG_GET_VC_MEMORY = 0x00010006,
  8480. + VCMSG_GET_CLOCKS = 0x00010007,
  8481. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  8482. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  8483. + VCMSG_GET_POWER_STATE = 0x00020001,
  8484. + VCMSG_GET_TIMING = 0x00020002,
  8485. + VCMSG_SET_POWER_STATE = 0x00028001,
  8486. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  8487. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  8488. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  8489. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  8490. + VCMSG_GET_VOLTAGE = 0x00030003,
  8491. + VCMSG_SET_VOLTAGE = 0x00038003,
  8492. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  8493. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  8494. + VCMSG_GET_TEMPERATURE = 0x00030006,
  8495. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  8496. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  8497. + VCMSG_GET_TURBO = 0x00030009,
  8498. + VCMSG_GET_MAX_TEMPERATURE = 0x0003000a,
  8499. + VCMSG_GET_STC = 0x0003000b,
  8500. + VCMSG_SET_TURBO = 0x00038009,
  8501. + VCMSG_SET_ALLOCATE_MEM = 0x0003000c,
  8502. + VCMSG_SET_LOCK_MEM = 0x0003000d,
  8503. + VCMSG_SET_UNLOCK_MEM = 0x0003000e,
  8504. + VCMSG_SET_RELEASE_MEM = 0x0003000f,
  8505. + VCMSG_SET_EXECUTE_CODE = 0x00030010,
  8506. + VCMSG_SET_EXECUTE_QPU = 0x00030011,
  8507. + VCMSG_SET_ENABLE_QPU = 0x00030012,
  8508. + VCMSG_GET_RESOURCE_HANDLE = 0x00030014,
  8509. + VCMSG_GET_EDID_BLOCK = 0x00030020,
  8510. + VCMSG_GET_CUSTOMER_OTP = 0x00030021,
  8511. + VCMSG_SET_CUSTOMER_OTP = 0x00038021,
  8512. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  8513. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  8514. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  8515. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  8516. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  8517. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  8518. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  8519. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  8520. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  8521. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  8522. + VCMSG_GET_DEPTH = 0x00040005,
  8523. + VCMSG_TST_DEPTH = 0x00044005,
  8524. + VCMSG_SET_DEPTH = 0x00048005,
  8525. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  8526. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  8527. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  8528. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  8529. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  8530. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  8531. + VCMSG_GET_PITCH = 0x00040008,
  8532. + VCMSG_TST_PITCH = 0x00044008,
  8533. + VCMSG_SET_PITCH = 0x00048008,
  8534. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  8535. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  8536. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  8537. + VCMSG_GET_OVERSCAN = 0x0004000a,
  8538. + VCMSG_TST_OVERSCAN = 0x0004400a,
  8539. + VCMSG_SET_OVERSCAN = 0x0004800a,
  8540. + VCMSG_GET_PALETTE = 0x0004000b,
  8541. + VCMSG_TST_PALETTE = 0x0004400b,
  8542. + VCMSG_SET_PALETTE = 0x0004800b,
  8543. + VCMSG_GET_LAYER = 0x0004000c,
  8544. + VCMSG_TST_LAYER = 0x0004400c,
  8545. + VCMSG_SET_LAYER = 0x0004800c,
  8546. + VCMSG_GET_TRANSFORM = 0x0004000d,
  8547. + VCMSG_TST_TRANSFORM = 0x0004400d,
  8548. + VCMSG_SET_TRANSFORM = 0x0004800d,
  8549. + VCMSG_TST_VSYNC = 0x0004400e,
  8550. + VCMSG_SET_VSYNC = 0x0004800e,
  8551. + VCMSG_SET_CURSOR_INFO = 0x00008010,
  8552. + VCMSG_SET_CURSOR_STATE = 0x00008011,
  8553. +};
  8554. +
  8555. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  8556. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  8557. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  8558. +
  8559. +#include <linux/ioctl.h>
  8560. +
  8561. +/*
  8562. + * The major device number. We can't rely on dynamic
  8563. + * registration any more, because ioctls need to know
  8564. + * it.
  8565. + */
  8566. +#define MAJOR_NUM 100
  8567. +
  8568. +/*
  8569. + * Set the message of the device driver
  8570. + */
  8571. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  8572. +/*
  8573. + * _IOWR means that we're creating an ioctl command
  8574. + * number for passing information from a user process
  8575. + * to the kernel module and from the kernel module to user process
  8576. + *
  8577. + * The first arguments, MAJOR_NUM, is the major device
  8578. + * number we're using.
  8579. + *
  8580. + * The second argument is the number of the command
  8581. + * (there could be several with different meanings).
  8582. + *
  8583. + * The third argument is the type we want to get from
  8584. + * the process to the kernel.
  8585. + */
  8586. +
  8587. +/*
  8588. + * The name of the device file
  8589. + */
  8590. +#define DEVICE_FILE_NAME "vcio"
  8591. +
  8592. +#endif
  8593. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  8594. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  8595. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2015-03-09 10:39:28.582893746 +0100
  8596. @@ -0,0 +1,35 @@
  8597. +/*****************************************************************************
  8598. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  8599. +*
  8600. +* Unless you and Broadcom execute a separate written software license
  8601. +* agreement governing use of this software, this software is licensed to you
  8602. +* under the terms of the GNU General Public License version 2, available at
  8603. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8604. +*
  8605. +* Notwithstanding the above, under no circumstances may you combine this
  8606. +* software in any way with any other Broadcom software provided under a
  8607. +* license other than the GPL, without Broadcom's express prior written
  8608. +* consent.
  8609. +*****************************************************************************/
  8610. +
  8611. +#if !defined( VC_MEM_H )
  8612. +#define VC_MEM_H
  8613. +
  8614. +#include <linux/ioctl.h>
  8615. +
  8616. +#define VC_MEM_IOC_MAGIC 'v'
  8617. +
  8618. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  8619. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  8620. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  8621. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  8622. +
  8623. +#if defined( __KERNEL__ )
  8624. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  8625. +
  8626. +extern unsigned long mm_vc_mem_phys_addr;
  8627. +extern unsigned int mm_vc_mem_size;
  8628. +extern int vc_mem_get_current_size( void );
  8629. +#endif
  8630. +
  8631. +#endif /* VC_MEM_H */
  8632. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h
  8633. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 1970-01-01 01:00:00.000000000 +0100
  8634. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_defs.h 2015-03-09 10:39:28.582893746 +0100
  8635. @@ -0,0 +1,181 @@
  8636. +/*****************************************************************************
  8637. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  8638. +*
  8639. +* Unless you and Broadcom execute a separate written software license
  8640. +* agreement governing use of this software, this software is licensed to you
  8641. +* under the terms of the GNU General Public License version 2, available at
  8642. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8643. +*
  8644. +* Notwithstanding the above, under no circumstances may you combine this
  8645. +* software in any way with any other Broadcom software provided under a
  8646. +* license other than the GPL, without Broadcom's express prior written
  8647. +* consent.
  8648. +*****************************************************************************/
  8649. +
  8650. +#ifndef __VC_SM_DEFS_H__INCLUDED__
  8651. +#define __VC_SM_DEFS_H__INCLUDED__
  8652. +
  8653. +/* FourCC code used for VCHI connection */
  8654. +#define VC_SM_SERVER_NAME MAKE_FOURCC("SMEM")
  8655. +
  8656. +/* Maximum message length */
  8657. +#define VC_SM_MAX_MSG_LEN (sizeof(VC_SM_MSG_UNION_T) + \
  8658. + sizeof(VC_SM_MSG_HDR_T))
  8659. +#define VC_SM_MAX_RSP_LEN (sizeof(VC_SM_MSG_UNION_T))
  8660. +
  8661. +/* Resource name maximum size */
  8662. +#define VC_SM_RESOURCE_NAME 32
  8663. +
  8664. +/* All message types supported for HOST->VC direction */
  8665. +typedef enum {
  8666. + /* Allocate shared memory block */
  8667. + VC_SM_MSG_TYPE_ALLOC,
  8668. + /* Lock allocated shared memory block */
  8669. + VC_SM_MSG_TYPE_LOCK,
  8670. + /* Unlock allocated shared memory block */
  8671. + VC_SM_MSG_TYPE_UNLOCK,
  8672. + /* Unlock allocated shared memory block, do not answer command */
  8673. + VC_SM_MSG_TYPE_UNLOCK_NOANS,
  8674. + /* Free shared memory block */
  8675. + VC_SM_MSG_TYPE_FREE,
  8676. + /* Resize a shared memory block */
  8677. + VC_SM_MSG_TYPE_RESIZE,
  8678. + /* Walk the allocated shared memory block(s) */
  8679. + VC_SM_MSG_TYPE_WALK_ALLOC,
  8680. +
  8681. + /* A previously applied action will need to be reverted */
  8682. + VC_SM_MSG_TYPE_ACTION_CLEAN,
  8683. + VC_SM_MSG_TYPE_MAX
  8684. +} VC_SM_MSG_TYPE;
  8685. +
  8686. +/* Type of memory to be allocated */
  8687. +typedef enum {
  8688. + VC_SM_ALLOC_CACHED,
  8689. + VC_SM_ALLOC_NON_CACHED,
  8690. +
  8691. +} VC_SM_ALLOC_TYPE_T;
  8692. +
  8693. +/* Message header for all messages in HOST->VC direction */
  8694. +typedef struct {
  8695. + int32_t type;
  8696. + uint32_t trans_id;
  8697. + uint8_t body[0];
  8698. +
  8699. +} VC_SM_MSG_HDR_T;
  8700. +
  8701. +/* Request to allocate memory (HOST->VC) */
  8702. +typedef struct {
  8703. + /* type of memory to allocate */
  8704. + VC_SM_ALLOC_TYPE_T type;
  8705. + /* byte amount of data to allocate per unit */
  8706. + uint32_t base_unit;
  8707. + /* number of unit to allocate */
  8708. + uint32_t num_unit;
  8709. + /* alignement to be applied on allocation */
  8710. + uint32_t alignement;
  8711. + /* identity of who allocated this block */
  8712. + uint32_t allocator;
  8713. + /* resource name (for easier tracking on vc side) */
  8714. + char name[VC_SM_RESOURCE_NAME];
  8715. +
  8716. +} VC_SM_ALLOC_T;
  8717. +
  8718. +/* Result of a requested memory allocation (VC->HOST) */
  8719. +typedef struct {
  8720. + /* Transaction identifier */
  8721. + uint32_t trans_id;
  8722. +
  8723. + /* Resource handle */
  8724. + uint32_t res_handle;
  8725. + /* Pointer to resource buffer */
  8726. + void *res_mem;
  8727. + /* Resource base size (bytes) */
  8728. + uint32_t res_base_size;
  8729. + /* Resource number */
  8730. + uint32_t res_num;
  8731. +
  8732. +} VC_SM_ALLOC_RESULT_T;
  8733. +
  8734. +/* Request to free a previously allocated memory (HOST->VC) */
  8735. +typedef struct {
  8736. + /* Resource handle (returned from alloc) */
  8737. + uint32_t res_handle;
  8738. + /* Resource buffer (returned from alloc) */
  8739. + void *res_mem;
  8740. +
  8741. +} VC_SM_FREE_T;
  8742. +
  8743. +/* Request to lock a previously allocated memory (HOST->VC) */
  8744. +typedef struct {
  8745. + /* Resource handle (returned from alloc) */
  8746. + uint32_t res_handle;
  8747. + /* Resource buffer (returned from alloc) */
  8748. + void *res_mem;
  8749. +
  8750. +} VC_SM_LOCK_UNLOCK_T;
  8751. +
  8752. +/* Request to resize a previously allocated memory (HOST->VC) */
  8753. +typedef struct {
  8754. + /* Resource handle (returned from alloc) */
  8755. + uint32_t res_handle;
  8756. + /* Resource buffer (returned from alloc) */
  8757. + void *res_mem;
  8758. + /* Resource *new* size requested (bytes) */
  8759. + uint32_t res_new_size;
  8760. +
  8761. +} VC_SM_RESIZE_T;
  8762. +
  8763. +/* Result of a requested memory lock (VC->HOST) */
  8764. +typedef struct {
  8765. + /* Transaction identifier */
  8766. + uint32_t trans_id;
  8767. +
  8768. + /* Resource handle */
  8769. + uint32_t res_handle;
  8770. + /* Pointer to resource buffer */
  8771. + void *res_mem;
  8772. + /* Pointer to former resource buffer if the memory
  8773. + * was reallocated */
  8774. + void *res_old_mem;
  8775. +
  8776. +} VC_SM_LOCK_RESULT_T;
  8777. +
  8778. +/* Generic result for a request (VC->HOST) */
  8779. +typedef struct {
  8780. + /* Transaction identifier */
  8781. + uint32_t trans_id;
  8782. +
  8783. + int32_t success;
  8784. +
  8785. +} VC_SM_RESULT_T;
  8786. +
  8787. +/* Request to revert a previously applied action (HOST->VC) */
  8788. +typedef struct {
  8789. + /* Action of interest */
  8790. + VC_SM_MSG_TYPE res_action;
  8791. + /* Transaction identifier for the action of interest */
  8792. + uint32_t action_trans_id;
  8793. +
  8794. +} VC_SM_ACTION_CLEAN_T;
  8795. +
  8796. +/* Request to remove all data associated with a given allocator (HOST->VC) */
  8797. +typedef struct {
  8798. + /* Allocator identifier */
  8799. + uint32_t allocator;
  8800. +
  8801. +} VC_SM_FREE_ALL_T;
  8802. +
  8803. +/* Union of ALL messages */
  8804. +typedef union {
  8805. + VC_SM_ALLOC_T alloc;
  8806. + VC_SM_ALLOC_RESULT_T alloc_result;
  8807. + VC_SM_FREE_T free;
  8808. + VC_SM_ACTION_CLEAN_T action_clean;
  8809. + VC_SM_RESIZE_T resize;
  8810. + VC_SM_LOCK_RESULT_T lock_result;
  8811. + VC_SM_RESULT_T result;
  8812. + VC_SM_FREE_ALL_T free_all;
  8813. +
  8814. +} VC_SM_MSG_UNION_T;
  8815. +
  8816. +#endif /* __VC_SM_DEFS_H__INCLUDED__ */
  8817. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h
  8818. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 1970-01-01 01:00:00.000000000 +0100
  8819. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_sm_knl.h 2015-03-09 10:39:28.582893746 +0100
  8820. @@ -0,0 +1,55 @@
  8821. +/*****************************************************************************
  8822. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  8823. +*
  8824. +* Unless you and Broadcom execute a separate written software license
  8825. +* agreement governing use of this software, this software is licensed to you
  8826. +* under the terms of the GNU General Public License version 2, available at
  8827. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8828. +*
  8829. +* Notwithstanding the above, under no circumstances may you combine this
  8830. +* software in any way with any other Broadcom software provided under a
  8831. +* license other than the GPL, without Broadcom's express prior written
  8832. +* consent.
  8833. +*****************************************************************************/
  8834. +
  8835. +#ifndef __VC_SM_KNL_H__INCLUDED__
  8836. +#define __VC_SM_KNL_H__INCLUDED__
  8837. +
  8838. +#if !defined(__KERNEL__)
  8839. +#error "This interface is for kernel use only..."
  8840. +#endif
  8841. +
  8842. +/* Type of memory to be locked (ie mapped) */
  8843. +typedef enum {
  8844. + VC_SM_LOCK_CACHED,
  8845. + VC_SM_LOCK_NON_CACHED,
  8846. +
  8847. +} VC_SM_LOCK_CACHE_MODE_T;
  8848. +
  8849. +/* Allocate a shared memory handle and block.
  8850. +*/
  8851. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle);
  8852. +
  8853. +/* Free a previously allocated shared memory handle and block.
  8854. +*/
  8855. +int vc_sm_free(int handle);
  8856. +
  8857. +/* Lock a memory handle for use by kernel.
  8858. +*/
  8859. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  8860. + long unsigned int *data);
  8861. +
  8862. +/* Unlock a memory handle in use by kernel.
  8863. +*/
  8864. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock);
  8865. +
  8866. +/* Get an internal resource handle mapped from the external one.
  8867. +*/
  8868. +int vc_sm_int_handle(int handle);
  8869. +
  8870. +/* Map a shared memory region for use by kernel.
  8871. +*/
  8872. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  8873. + long unsigned int *data);
  8874. +
  8875. +#endif /* __VC_SM_KNL_H__INCLUDED__ */
  8876. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h
  8877. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 1970-01-01 01:00:00.000000000 +0100
  8878. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_vchi_sm.h 2015-03-09 10:39:28.582893746 +0100
  8879. @@ -0,0 +1,82 @@
  8880. +/*****************************************************************************
  8881. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  8882. +*
  8883. +* Unless you and Broadcom execute a separate written software license
  8884. +* agreement governing use of this software, this software is licensed to you
  8885. +* under the terms of the GNU General Public License version 2, available at
  8886. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8887. +*
  8888. +* Notwithstanding the above, under no circumstances may you combine this
  8889. +* software in any way with any other Broadcom software provided under a
  8890. +* license other than the GPL, without Broadcom's express prior written
  8891. +* consent.
  8892. +*****************************************************************************/
  8893. +
  8894. +#ifndef __VC_VCHI_SM_H__INCLUDED__
  8895. +#define __VC_VCHI_SM_H__INCLUDED__
  8896. +
  8897. +#include "interface/vchi/vchi.h"
  8898. +
  8899. +#include "vc_sm_defs.h"
  8900. +
  8901. +/* Forward declare.
  8902. +*/
  8903. +typedef struct sm_instance *VC_VCHI_SM_HANDLE_T;
  8904. +
  8905. +/* Initialize the shared memory service, opens up vchi connection to talk to it.
  8906. +*/
  8907. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  8908. + VCHI_CONNECTION_T **vchi_connections,
  8909. + uint32_t num_connections);
  8910. +
  8911. +/* Terminates the shared memory service.
  8912. +*/
  8913. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle);
  8914. +
  8915. +/* Ask the shared memory service to allocate some memory on videocre and
  8916. +** return the result of this allocation (which upon success will be a pointer
  8917. +** to some memory in videocore space).
  8918. +*/
  8919. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle,
  8920. + VC_SM_ALLOC_T *alloc,
  8921. + VC_SM_ALLOC_RESULT_T *alloc_result, uint32_t *trans_id);
  8922. +
  8923. +/* Ask the shared memory service to free up some memory that was previously
  8924. +** allocated by the vc_vchi_sm_alloc function call.
  8925. +*/
  8926. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  8927. + VC_SM_FREE_T *free, uint32_t *trans_id);
  8928. +
  8929. +/* Ask the shared memory service to lock up some memory that was previously
  8930. +** allocated by the vc_vchi_sm_alloc function call.
  8931. +*/
  8932. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  8933. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  8934. + VC_SM_LOCK_RESULT_T *lock_result, uint32_t *trans_id);
  8935. +
  8936. +/* Ask the shared memory service to unlock some memory that was previously
  8937. +** allocated by the vc_vchi_sm_alloc function call.
  8938. +*/
  8939. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  8940. + VC_SM_LOCK_UNLOCK_T *lock_unlock,
  8941. + uint32_t *trans_id, uint8_t wait_reply);
  8942. +
  8943. +/* Ask the shared memory service to resize some memory that was previously
  8944. +** allocated by the vc_vchi_sm_alloc function call.
  8945. +*/
  8946. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle,
  8947. + VC_SM_RESIZE_T *resize, uint32_t *trans_id);
  8948. +
  8949. +/* Walk the allocated resources on the videocore side, the allocation will
  8950. +** show up in the log. This is purely for debug/information and takes no
  8951. +** specific actions.
  8952. +*/
  8953. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle);
  8954. +
  8955. +/* Clean up following a previously interrupted action which left the system
  8956. +** in a bad state of some sort.
  8957. +*/
  8958. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle,
  8959. + VC_SM_ACTION_CLEAN_T *action_clean);
  8960. +
  8961. +#endif /* __VC_VCHI_SM_H__INCLUDED__ */
  8962. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  8963. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  8964. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2015-03-09 10:39:28.582893746 +0100
  8965. @@ -0,0 +1,20 @@
  8966. +/*
  8967. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  8968. + *
  8969. + * Copyright (C) 2010 Broadcom
  8970. + *
  8971. + * This program is free software; you can redistribute it and/or modify
  8972. + * it under the terms of the GNU General Public License as published by
  8973. + * the Free Software Foundation; either version 2 of the License, or
  8974. + * (at your option) any later version.
  8975. + *
  8976. + * This program is distributed in the hope that it will be useful,
  8977. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8978. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8979. + * GNU General Public License for more details.
  8980. + *
  8981. + * You should have received a copy of the GNU General Public License
  8982. + * along with this program; if not, write to the Free Software
  8983. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  8984. + */
  8985. +#define VMALLOC_END (0xe8000000)
  8986. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h
  8987. --- linux-3.12.38/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  8988. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmcs_sm_ioctl.h 2015-03-09 10:39:28.582893746 +0100
  8989. @@ -0,0 +1,233 @@
  8990. +/*****************************************************************************
  8991. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  8992. +*
  8993. +* Unless you and Broadcom execute a separate written software license
  8994. +* agreement governing use of this software, this software is licensed to you
  8995. +* under the terms of the GNU General Public License version 2, available at
  8996. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8997. +*
  8998. +* Notwithstanding the above, under no circumstances may you combine this
  8999. +* software in any way with any other Broadcom software provided under a
  9000. +* license other than the GPL, without Broadcom's express prior written
  9001. +* consent.
  9002. +*
  9003. +*****************************************************************************/
  9004. +
  9005. +#if !defined(__VMCS_SM_IOCTL_H__INCLUDED__)
  9006. +#define __VMCS_SM_IOCTL_H__INCLUDED__
  9007. +
  9008. +/* ---- Include Files ---------------------------------------------------- */
  9009. +
  9010. +#if defined(__KERNEL__)
  9011. +#include <linux/types.h> /* Needed for standard types */
  9012. +#else
  9013. +#include <stdint.h>
  9014. +#endif
  9015. +
  9016. +#include <linux/ioctl.h>
  9017. +
  9018. +/* ---- Constants and Types ---------------------------------------------- */
  9019. +
  9020. +#define VMCS_SM_RESOURCE_NAME 32
  9021. +#define VMCS_SM_RESOURCE_NAME_DEFAULT "sm-host-resource"
  9022. +
  9023. +/* Type define used to create unique IOCTL number */
  9024. +#define VMCS_SM_MAGIC_TYPE 'I'
  9025. +
  9026. +/* IOCTL commands */
  9027. +enum vmcs_sm_cmd_e {
  9028. + VMCS_SM_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */
  9029. + VMCS_SM_CMD_ALLOC_SHARE,
  9030. + VMCS_SM_CMD_LOCK,
  9031. + VMCS_SM_CMD_LOCK_CACHE,
  9032. + VMCS_SM_CMD_UNLOCK,
  9033. + VMCS_SM_CMD_RESIZE,
  9034. + VMCS_SM_CMD_UNMAP,
  9035. + VMCS_SM_CMD_FREE,
  9036. + VMCS_SM_CMD_FLUSH,
  9037. + VMCS_SM_CMD_INVALID,
  9038. +
  9039. + VMCS_SM_CMD_SIZE_USR_HANDLE,
  9040. + VMCS_SM_CMD_CHK_USR_HANDLE,
  9041. +
  9042. + VMCS_SM_CMD_MAPPED_USR_HANDLE,
  9043. + VMCS_SM_CMD_MAPPED_USR_ADDRESS,
  9044. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,
  9045. + VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,
  9046. + VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,
  9047. +
  9048. + VMCS_SM_CMD_VC_WALK_ALLOC,
  9049. + VMCS_SM_CMD_HOST_WALK_MAP,
  9050. + VMCS_SM_CMD_HOST_WALK_PID_ALLOC,
  9051. + VMCS_SM_CMD_HOST_WALK_PID_MAP,
  9052. +
  9053. + VMCS_SM_CMD_LAST /* Do no delete */
  9054. +};
  9055. +
  9056. +/* Cache type supported, conveniently matches the user space definition in
  9057. +** user-vcsm.h.
  9058. +*/
  9059. +enum vmcs_sm_cache_e {
  9060. + VMCS_SM_CACHE_NONE,
  9061. + VMCS_SM_CACHE_HOST,
  9062. + VMCS_SM_CACHE_VC,
  9063. + VMCS_SM_CACHE_BOTH,
  9064. +};
  9065. +
  9066. +/* IOCTL Data structures */
  9067. +struct vmcs_sm_ioctl_alloc {
  9068. + /* user -> kernel */
  9069. + unsigned int size;
  9070. + unsigned int num;
  9071. + enum vmcs_sm_cache_e cached;
  9072. + char name[VMCS_SM_RESOURCE_NAME];
  9073. +
  9074. + /* kernel -> user */
  9075. + unsigned int handle;
  9076. + /* unsigned int base_addr; */
  9077. +};
  9078. +
  9079. +struct vmcs_sm_ioctl_alloc_share {
  9080. + /* user -> kernel */
  9081. + unsigned int handle;
  9082. + unsigned int size;
  9083. +};
  9084. +
  9085. +struct vmcs_sm_ioctl_free {
  9086. + /* user -> kernel */
  9087. + unsigned int handle;
  9088. + /* unsigned int base_addr; */
  9089. +};
  9090. +
  9091. +struct vmcs_sm_ioctl_lock_unlock {
  9092. + /* user -> kernel */
  9093. + unsigned int handle;
  9094. +
  9095. + /* kernel -> user */
  9096. + unsigned int addr;
  9097. +};
  9098. +
  9099. +struct vmcs_sm_ioctl_lock_cache {
  9100. + /* user -> kernel */
  9101. + unsigned int handle;
  9102. + enum vmcs_sm_cache_e cached;
  9103. +};
  9104. +
  9105. +struct vmcs_sm_ioctl_resize {
  9106. + /* user -> kernel */
  9107. + unsigned int handle;
  9108. + unsigned int new_size;
  9109. +
  9110. + /* kernel -> user */
  9111. + unsigned int old_size;
  9112. +};
  9113. +
  9114. +struct vmcs_sm_ioctl_map {
  9115. + /* user -> kernel */
  9116. + /* and kernel -> user */
  9117. + unsigned int pid;
  9118. + unsigned int handle;
  9119. + unsigned int addr;
  9120. +
  9121. + /* kernel -> user */
  9122. + unsigned int size;
  9123. +};
  9124. +
  9125. +struct vmcs_sm_ioctl_walk {
  9126. + /* user -> kernel */
  9127. + unsigned int pid;
  9128. +};
  9129. +
  9130. +struct vmcs_sm_ioctl_chk {
  9131. + /* user -> kernel */
  9132. + unsigned int handle;
  9133. +
  9134. + /* kernel -> user */
  9135. + unsigned int addr;
  9136. + unsigned int size;
  9137. + enum vmcs_sm_cache_e cache;
  9138. +};
  9139. +
  9140. +struct vmcs_sm_ioctl_size {
  9141. + /* user -> kernel */
  9142. + unsigned int handle;
  9143. +
  9144. + /* kernel -> user */
  9145. + unsigned int size;
  9146. +};
  9147. +
  9148. +struct vmcs_sm_ioctl_cache {
  9149. + /* user -> kernel */
  9150. + unsigned int handle;
  9151. + unsigned int addr;
  9152. + unsigned int size;
  9153. +};
  9154. +
  9155. +/* IOCTL numbers */
  9156. +#define VMCS_SM_IOCTL_MEM_ALLOC\
  9157. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC,\
  9158. + struct vmcs_sm_ioctl_alloc)
  9159. +#define VMCS_SM_IOCTL_MEM_ALLOC_SHARE\
  9160. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC_SHARE,\
  9161. + struct vmcs_sm_ioctl_alloc_share)
  9162. +#define VMCS_SM_IOCTL_MEM_LOCK\
  9163. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK,\
  9164. + struct vmcs_sm_ioctl_lock_unlock)
  9165. +#define VMCS_SM_IOCTL_MEM_LOCK_CACHE\
  9166. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK_CACHE,\
  9167. + struct vmcs_sm_ioctl_lock_cache)
  9168. +#define VMCS_SM_IOCTL_MEM_UNLOCK\
  9169. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_UNLOCK,\
  9170. + struct vmcs_sm_ioctl_lock_unlock)
  9171. +#define VMCS_SM_IOCTL_MEM_RESIZE\
  9172. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_RESIZE,\
  9173. + struct vmcs_sm_ioctl_resize)
  9174. +#define VMCS_SM_IOCTL_MEM_FREE\
  9175. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FREE,\
  9176. + struct vmcs_sm_ioctl_free)
  9177. +#define VMCS_SM_IOCTL_MEM_FLUSH\
  9178. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FLUSH,\
  9179. + struct vmcs_sm_ioctl_cache)
  9180. +#define VMCS_SM_IOCTL_MEM_INVALID\
  9181. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_INVALID,\
  9182. + struct vmcs_sm_ioctl_cache)
  9183. +
  9184. +#define VMCS_SM_IOCTL_SIZE_USR_HDL\
  9185. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_SIZE_USR_HANDLE,\
  9186. + struct vmcs_sm_ioctl_size)
  9187. +#define VMCS_SM_IOCTL_CHK_USR_HDL\
  9188. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CHK_USR_HANDLE,\
  9189. + struct vmcs_sm_ioctl_chk)
  9190. +
  9191. +#define VMCS_SM_IOCTL_MAP_USR_HDL\
  9192. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_HANDLE,\
  9193. + struct vmcs_sm_ioctl_map)
  9194. +#define VMCS_SM_IOCTL_MAP_USR_ADDRESS\
  9195. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_ADDRESS,\
  9196. + struct vmcs_sm_ioctl_map)
  9197. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_ADDR\
  9198. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,\
  9199. + struct vmcs_sm_ioctl_map)
  9200. +#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_HDL\
  9201. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,\
  9202. + struct vmcs_sm_ioctl_map)
  9203. +#define VMCS_SM_IOCTL_MAP_VC_ADDR_FR_HDL\
  9204. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,\
  9205. + struct vmcs_sm_ioctl_map)
  9206. +
  9207. +#define VMCS_SM_IOCTL_VC_WALK_ALLOC\
  9208. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_VC_WALK_ALLOC)
  9209. +#define VMCS_SM_IOCTL_HOST_WALK_MAP\
  9210. + _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_MAP)
  9211. +#define VMCS_SM_IOCTL_HOST_WALK_PID_ALLOC\
  9212. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_ALLOC,\
  9213. + struct vmcs_sm_ioctl_walk)
  9214. +#define VMCS_SM_IOCTL_HOST_WALK_PID_MAP\
  9215. + _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_MAP,\
  9216. + struct vmcs_sm_ioctl_walk)
  9217. +
  9218. +/* ---- Variable Externs ------------------------------------------------- */
  9219. +
  9220. +/* ---- Function Prototypes ---------------------------------------------- */
  9221. +
  9222. +#endif /* __VMCS_SM_IOCTL_H__INCLUDED__ */
  9223. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  9224. --- linux-3.12.38/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  9225. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2015-03-10 17:26:49.718216697 +0100
  9226. @@ -0,0 +1,41 @@
  9227. +menu "Broadcom BCM2708 Implementations"
  9228. + depends on ARCH_BCM2708
  9229. +
  9230. +config MACH_BCM2708
  9231. + bool "Broadcom BCM2708 Development Platform"
  9232. + select NEED_MACH_MEMORY_H
  9233. + select NEED_MACH_IO_H
  9234. + select CPU_V6
  9235. + help
  9236. + Include support for the Broadcom(R) BCM2708 platform.
  9237. +
  9238. +config BCM2708_GPIO
  9239. + bool "BCM2708 gpio support"
  9240. + depends on MACH_BCM2708
  9241. + select ARCH_REQUIRE_GPIOLIB
  9242. + default y
  9243. + help
  9244. + Include support for the Broadcom(R) BCM2708 gpio.
  9245. +
  9246. +config BCM2708_VCMEM
  9247. + bool "Videocore Memory"
  9248. + depends on MACH_BCM2708
  9249. + default y
  9250. + help
  9251. + Helper for videocore memory access and total size allocation.
  9252. +
  9253. +config BCM2708_NOL2CACHE
  9254. + bool "Videocore L2 cache disable"
  9255. + depends on MACH_BCM2708
  9256. + default n
  9257. + help
  9258. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  9259. +
  9260. +config BCM2708_SPIDEV
  9261. + bool "Bind spidev to SPI0 master"
  9262. + depends on MACH_BCM2708
  9263. + depends on SPI
  9264. + default y
  9265. + help
  9266. + Binds spidev driver to the SPI0 master
  9267. +endmenu
  9268. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  9269. --- linux-3.12.38/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  9270. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2015-03-10 17:26:49.718216697 +0100
  9271. @@ -0,0 +1,7 @@
  9272. +#
  9273. +# Makefile for the linux kernel.
  9274. +#
  9275. +
  9276. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  9277. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  9278. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  9279. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  9280. --- linux-3.12.38/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  9281. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2015-03-09 10:39:28.582893746 +0100
  9282. @@ -0,0 +1,3 @@
  9283. + zreladdr-y := 0x00008000
  9284. +params_phys-y := 0x00000100
  9285. +initrd_phys-y := 0x00800000
  9286. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  9287. --- linux-3.12.38/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  9288. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2015-03-10 17:26:49.718216697 +0100
  9289. @@ -0,0 +1,194 @@
  9290. +/*
  9291. + * linux/arch/arm/mach-bcm2708/power.c
  9292. + *
  9293. + * Copyright (C) 2010 Broadcom
  9294. + *
  9295. + * This program is free software; you can redistribute it and/or modify
  9296. + * it under the terms of the GNU General Public License version 2 as
  9297. + * published by the Free Software Foundation.
  9298. + *
  9299. + * This device provides a shared mechanism for controlling the power to
  9300. + * VideoCore subsystems.
  9301. + */
  9302. +
  9303. +#include <linux/module.h>
  9304. +#include <linux/semaphore.h>
  9305. +#include <linux/bug.h>
  9306. +#include <mach/power.h>
  9307. +#include <mach/vcio.h>
  9308. +#include <mach/arm_power.h>
  9309. +
  9310. +#define DRIVER_NAME "bcm2708_power"
  9311. +
  9312. +#define BCM_POWER_MAXCLIENTS 4
  9313. +#define BCM_POWER_NOCLIENT (1<<31)
  9314. +
  9315. +/* Some drivers expect there devices to be permanently powered */
  9316. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  9317. +
  9318. +#if 1
  9319. +#define DPRINTK printk
  9320. +#else
  9321. +#define DPRINTK if (0) printk
  9322. +#endif
  9323. +
  9324. +struct state_struct {
  9325. + uint32_t global_request;
  9326. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  9327. + struct semaphore client_mutex;
  9328. + struct semaphore mutex;
  9329. +} g_state;
  9330. +
  9331. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  9332. +{
  9333. + BCM_POWER_HANDLE_T i;
  9334. + int ret = -EBUSY;
  9335. +
  9336. + down(&g_state.client_mutex);
  9337. +
  9338. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  9339. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  9340. + g_state.client_request[i] = BCM_POWER_NONE;
  9341. + *handle = i;
  9342. + ret = 0;
  9343. + break;
  9344. + }
  9345. + }
  9346. +
  9347. + up(&g_state.client_mutex);
  9348. +
  9349. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  9350. +
  9351. + return ret;
  9352. +}
  9353. +EXPORT_SYMBOL_GPL(bcm_power_open);
  9354. +
  9355. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  9356. +{
  9357. + int rc = 0;
  9358. +
  9359. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  9360. +
  9361. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  9362. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  9363. + if (down_interruptible(&g_state.mutex) != 0) {
  9364. + DPRINTK("bcm_power_request -> interrupted\n");
  9365. + return -EINTR;
  9366. + }
  9367. +
  9368. + if (request != g_state.client_request[handle]) {
  9369. + uint32_t others_request = 0;
  9370. + uint32_t global_request;
  9371. + BCM_POWER_HANDLE_T i;
  9372. +
  9373. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  9374. + if (i != handle)
  9375. + others_request |=
  9376. + g_state.client_request[i];
  9377. + }
  9378. + others_request &= ~BCM_POWER_NOCLIENT;
  9379. +
  9380. + global_request = request | others_request;
  9381. + if (global_request != g_state.global_request) {
  9382. + uint32_t actual;
  9383. +
  9384. + /* Send a request to VideoCore */
  9385. + bcm_mailbox_write(MBOX_CHAN_POWER,
  9386. + global_request << 4);
  9387. +
  9388. + /* Wait for a response during power-up */
  9389. + if (global_request & ~g_state.global_request) {
  9390. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  9391. + &actual);
  9392. + DPRINTK
  9393. + ("bcm_mailbox_read -> %08x, %d\n",
  9394. + actual, rc);
  9395. + actual >>= 4;
  9396. + } else {
  9397. + rc = 0;
  9398. + actual = global_request;
  9399. + }
  9400. +
  9401. + if (rc == 0) {
  9402. + if (actual != global_request) {
  9403. + printk(KERN_ERR
  9404. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  9405. + __func__,
  9406. + g_state.global_request,
  9407. + global_request, actual, request, others_request);
  9408. + /* A failure */
  9409. + BUG_ON((others_request & actual)
  9410. + != others_request);
  9411. + request &= actual;
  9412. + rc = -EIO;
  9413. + }
  9414. +
  9415. + g_state.global_request = actual;
  9416. + g_state.client_request[handle] =
  9417. + request;
  9418. + }
  9419. + }
  9420. + }
  9421. + up(&g_state.mutex);
  9422. + } else {
  9423. + rc = -EINVAL;
  9424. + }
  9425. + DPRINTK("bcm_power_request -> %d\n", rc);
  9426. + return rc;
  9427. +}
  9428. +EXPORT_SYMBOL_GPL(bcm_power_request);
  9429. +
  9430. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  9431. +{
  9432. + int rc;
  9433. +
  9434. + DPRINTK("bcm_power_close(%d)\n", handle);
  9435. +
  9436. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  9437. + if (rc == 0)
  9438. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  9439. +
  9440. + return rc;
  9441. +}
  9442. +EXPORT_SYMBOL_GPL(bcm_power_close);
  9443. +
  9444. +static int __init bcm_power_init(void)
  9445. +{
  9446. +#if defined(BCM_POWER_ALWAYS_ON)
  9447. + BCM_POWER_HANDLE_T always_on_handle;
  9448. +#endif
  9449. + int rc = 0;
  9450. + int i;
  9451. +
  9452. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  9453. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  9454. +
  9455. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  9456. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  9457. +
  9458. + sema_init(&g_state.client_mutex, 1);
  9459. + sema_init(&g_state.mutex, 1);
  9460. +
  9461. + g_state.global_request = 0;
  9462. +
  9463. +#if defined(BCM_POWER_ALWAYS_ON)
  9464. + if (BCM_POWER_ALWAYS_ON) {
  9465. + bcm_power_open(&always_on_handle);
  9466. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  9467. + }
  9468. +#endif
  9469. +
  9470. + return rc;
  9471. +}
  9472. +
  9473. +static void __exit bcm_power_exit(void)
  9474. +{
  9475. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  9476. +}
  9477. +
  9478. +arch_initcall(bcm_power_init); /* Initialize early */
  9479. +module_exit(bcm_power_exit);
  9480. +
  9481. +MODULE_AUTHOR("Phil Elwell");
  9482. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  9483. +MODULE_LICENSE("GPL");
  9484. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  9485. --- linux-3.12.38/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  9486. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2015-03-10 17:26:49.718216697 +0100
  9487. @@ -0,0 +1,474 @@
  9488. +/*
  9489. + * linux/arch/arm/mach-bcm2708/vcio.c
  9490. + *
  9491. + * Copyright (C) 2010 Broadcom
  9492. + *
  9493. + * This program is free software; you can redistribute it and/or modify
  9494. + * it under the terms of the GNU General Public License version 2 as
  9495. + * published by the Free Software Foundation.
  9496. + *
  9497. + * This device provides a shared mechanism for writing to the mailboxes,
  9498. + * semaphores, doorbells etc. that are shared between the ARM and the
  9499. + * VideoCore processor
  9500. + */
  9501. +
  9502. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  9503. +#define SUPPORT_SYSRQ
  9504. +#endif
  9505. +
  9506. +#include <linux/module.h>
  9507. +#include <linux/console.h>
  9508. +#include <linux/serial_core.h>
  9509. +#include <linux/serial.h>
  9510. +#include <linux/errno.h>
  9511. +#include <linux/device.h>
  9512. +#include <linux/init.h>
  9513. +#include <linux/mm.h>
  9514. +#include <linux/dma-mapping.h>
  9515. +#include <linux/platform_device.h>
  9516. +#include <linux/sysrq.h>
  9517. +#include <linux/delay.h>
  9518. +#include <linux/slab.h>
  9519. +#include <linux/interrupt.h>
  9520. +#include <linux/irq.h>
  9521. +
  9522. +#include <linux/io.h>
  9523. +
  9524. +#include <mach/vcio.h>
  9525. +#include <mach/platform.h>
  9526. +
  9527. +#include <asm/uaccess.h>
  9528. +
  9529. +
  9530. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  9531. +
  9532. +/* ----------------------------------------------------------------------
  9533. + * Mailbox
  9534. + * -------------------------------------------------------------------- */
  9535. +
  9536. +/* offsets from a mail box base address */
  9537. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  9538. +#define MAIL_RD 0x00 /* read - and next 4 words */
  9539. +#define MAIL_POL 0x10 /* read without popping the fifo */
  9540. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  9541. +#define MAIL_STA 0x18 /* status */
  9542. +#define MAIL_CNF 0x1C /* configuration */
  9543. +
  9544. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  9545. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  9546. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  9547. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  9548. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  9549. +
  9550. +#define MBOX_MAGIC 0xd0d0c0de
  9551. +
  9552. +struct vc_mailbox {
  9553. + struct device *dev; /* parent device */
  9554. + void __iomem *status;
  9555. + void __iomem *config;
  9556. + void __iomem *read;
  9557. + void __iomem *write;
  9558. + uint32_t msg[MBOX_CHAN_COUNT];
  9559. + struct semaphore sema[MBOX_CHAN_COUNT];
  9560. + uint32_t magic;
  9561. +};
  9562. +
  9563. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  9564. + uint32_t addr_mbox)
  9565. +{
  9566. + int i;
  9567. +
  9568. + mbox_out->dev = dev;
  9569. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  9570. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  9571. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  9572. + /* Write to the other mailbox */
  9573. + mbox_out->write =
  9574. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  9575. + MAIL_WRT);
  9576. +
  9577. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  9578. + mbox_out->msg[i] = 0;
  9579. + sema_init(&mbox_out->sema[i], 0);
  9580. + }
  9581. +
  9582. + /* Enable the interrupt on data reception */
  9583. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  9584. +
  9585. + mbox_out->magic = MBOX_MAGIC;
  9586. +}
  9587. +
  9588. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  9589. +{
  9590. + int rc;
  9591. +
  9592. + if (mbox->magic != MBOX_MAGIC)
  9593. + rc = -EINVAL;
  9594. + else {
  9595. + /* wait for the mailbox FIFO to have some space in it */
  9596. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  9597. + cpu_relax();
  9598. +
  9599. + writel(MBOX_MSG(chan, data28), mbox->write);
  9600. + rc = 0;
  9601. + }
  9602. + return rc;
  9603. +}
  9604. +
  9605. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  9606. +{
  9607. + int rc;
  9608. +
  9609. + if (mbox->magic != MBOX_MAGIC)
  9610. + rc = -EINVAL;
  9611. + else {
  9612. + down(&mbox->sema[chan]);
  9613. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  9614. + mbox->msg[chan] = 0;
  9615. + rc = 0;
  9616. + }
  9617. + return rc;
  9618. +}
  9619. +
  9620. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  9621. +{
  9622. + /* wait for the mailbox FIFO to have some data in it */
  9623. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  9624. + int status = readl(mbox->status);
  9625. + int ret = IRQ_NONE;
  9626. +
  9627. + while (!(status & ARM_MS_EMPTY)) {
  9628. + uint32_t msg = readl(mbox->read);
  9629. + int chan = MBOX_CHAN(msg);
  9630. + if (chan < MBOX_CHAN_COUNT) {
  9631. + if (mbox->msg[chan]) {
  9632. + /* Overflow */
  9633. + printk(KERN_ERR DRIVER_NAME
  9634. + ": mbox chan %d overflow - drop %08x\n",
  9635. + chan, msg);
  9636. + } else {
  9637. + mbox->msg[chan] = (msg | 0xf);
  9638. + up(&mbox->sema[chan]);
  9639. + }
  9640. + } else {
  9641. + printk(KERN_ERR DRIVER_NAME
  9642. + ": invalid channel selector (msg %08x)\n", msg);
  9643. + }
  9644. + ret = IRQ_HANDLED;
  9645. + status = readl(mbox->status);
  9646. + }
  9647. + return ret;
  9648. +}
  9649. +
  9650. +static struct irqaction mbox_irqaction = {
  9651. + .name = "ARM Mailbox IRQ",
  9652. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  9653. + .handler = mbox_irq,
  9654. +};
  9655. +
  9656. +/* ----------------------------------------------------------------------
  9657. + * Mailbox Methods
  9658. + * -------------------------------------------------------------------- */
  9659. +
  9660. +static struct device *mbox_dev; /* we assume there's only one! */
  9661. +
  9662. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  9663. +{
  9664. + int rc;
  9665. +
  9666. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  9667. + device_lock(dev);
  9668. + rc = mbox_write(mailbox, chan, data28);
  9669. + device_unlock(dev);
  9670. +
  9671. + return rc;
  9672. +}
  9673. +
  9674. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  9675. +{
  9676. + int rc;
  9677. +
  9678. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  9679. + device_lock(dev);
  9680. + rc = mbox_read(mailbox, chan, data28);
  9681. + device_unlock(dev);
  9682. +
  9683. + return rc;
  9684. +}
  9685. +
  9686. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  9687. +{
  9688. + if (mbox_dev)
  9689. + return dev_mbox_write(mbox_dev, chan, data28);
  9690. + else
  9691. + return -ENODEV;
  9692. +}
  9693. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  9694. +
  9695. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  9696. +{
  9697. + if (mbox_dev)
  9698. + return dev_mbox_read(mbox_dev, chan, data28);
  9699. + else
  9700. + return -ENODEV;
  9701. +}
  9702. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  9703. +
  9704. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  9705. +{
  9706. + mbox_dev = dev;
  9707. +}
  9708. +
  9709. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  9710. +{
  9711. + if ( (uint32_t)src < TASK_SIZE)
  9712. + {
  9713. + return copy_from_user(dst, src, size);
  9714. + }
  9715. + else
  9716. + {
  9717. + memcpy( dst, src, size );
  9718. + return 0;
  9719. + }
  9720. +}
  9721. +
  9722. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  9723. +{
  9724. + if ( (uint32_t)dst < TASK_SIZE)
  9725. + {
  9726. + return copy_to_user(dst, src, size);
  9727. + }
  9728. + else
  9729. + {
  9730. + memcpy( dst, src, size );
  9731. + return 0;
  9732. + }
  9733. +}
  9734. +
  9735. +static DEFINE_MUTEX(mailbox_lock);
  9736. +extern int bcm_mailbox_property(void *data, int size)
  9737. +{
  9738. + uint32_t success;
  9739. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  9740. + void *mem_kern; /* the memory address accessed from driver */
  9741. + int s = 0;
  9742. +
  9743. + mutex_lock(&mailbox_lock);
  9744. + /* allocate some memory for the messages communicating with GPU */
  9745. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  9746. + if (mem_kern) {
  9747. + /* create the message */
  9748. + mbox_copy_from_user(mem_kern, data, size);
  9749. +
  9750. + /* send the message */
  9751. + wmb();
  9752. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  9753. + if (s == 0) {
  9754. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  9755. + }
  9756. + if (s == 0) {
  9757. + /* copy the response */
  9758. + rmb();
  9759. + mbox_copy_to_user(data, mem_kern, size);
  9760. + }
  9761. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  9762. + } else {
  9763. + s = -ENOMEM;
  9764. + }
  9765. + if (s != 0)
  9766. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  9767. +
  9768. + mutex_unlock(&mailbox_lock);
  9769. + return s;
  9770. +}
  9771. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  9772. +
  9773. +/* ----------------------------------------------------------------------
  9774. + * Platform Device for Mailbox
  9775. + * -------------------------------------------------------------------- */
  9776. +
  9777. +/*
  9778. + * Is the device open right now? Used to prevent
  9779. + * concurent access into the same device
  9780. + */
  9781. +static int Device_Open = 0;
  9782. +
  9783. +/*
  9784. + * This is called whenever a process attempts to open the device file
  9785. + */
  9786. +static int device_open(struct inode *inode, struct file *file)
  9787. +{
  9788. + /*
  9789. + * We don't want to talk to two processes at the same time
  9790. + */
  9791. + if (Device_Open)
  9792. + return -EBUSY;
  9793. +
  9794. + Device_Open++;
  9795. + /*
  9796. + * Initialize the message
  9797. + */
  9798. + try_module_get(THIS_MODULE);
  9799. + return 0;
  9800. +}
  9801. +
  9802. +static int device_release(struct inode *inode, struct file *file)
  9803. +{
  9804. + /*
  9805. + * We're now ready for our next caller
  9806. + */
  9807. + Device_Open--;
  9808. +
  9809. + module_put(THIS_MODULE);
  9810. + return 0;
  9811. +}
  9812. +
  9813. +/*
  9814. + * This function is called whenever a process tries to do an ioctl on our
  9815. + * device file. We get two extra parameters (additional to the inode and file
  9816. + * structures, which all device functions get): the number of the ioctl called
  9817. + * and the parameter given to the ioctl function.
  9818. + *
  9819. + * If the ioctl is write or read/write (meaning output is returned to the
  9820. + * calling process), the ioctl call returns the output of this function.
  9821. + *
  9822. + */
  9823. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  9824. + unsigned int ioctl_num, /* number and param for ioctl */
  9825. + unsigned long ioctl_param)
  9826. +{
  9827. + unsigned size;
  9828. + /*
  9829. + * Switch according to the ioctl called
  9830. + */
  9831. + switch (ioctl_num) {
  9832. + case IOCTL_MBOX_PROPERTY:
  9833. + /*
  9834. + * Receive a pointer to a message (in user space) and set that
  9835. + * to be the device's message. Get the parameter given to
  9836. + * ioctl by the process.
  9837. + */
  9838. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  9839. + return bcm_mailbox_property((void *)ioctl_param, size);
  9840. + break;
  9841. + default:
  9842. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  9843. + return -EINVAL;
  9844. + }
  9845. +
  9846. + return 0;
  9847. +}
  9848. +
  9849. +/* Module Declarations */
  9850. +
  9851. +/*
  9852. + * This structure will hold the functions to be called
  9853. + * when a process does something to the device we
  9854. + * created. Since a pointer to this structure is kept in
  9855. + * the devices table, it can't be local to
  9856. + * init_module. NULL is for unimplemented functios.
  9857. + */
  9858. +struct file_operations fops = {
  9859. + .unlocked_ioctl = device_ioctl,
  9860. + .open = device_open,
  9861. + .release = device_release, /* a.k.a. close */
  9862. +};
  9863. +
  9864. +static int bcm_vcio_probe(struct platform_device *pdev)
  9865. +{
  9866. + int ret = 0;
  9867. + struct vc_mailbox *mailbox;
  9868. +
  9869. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  9870. + if (NULL == mailbox) {
  9871. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  9872. + "mailbox memory\n");
  9873. + ret = -ENOMEM;
  9874. + } else {
  9875. + struct resource *res;
  9876. +
  9877. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  9878. + if (res == NULL) {
  9879. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  9880. + "resource\n");
  9881. + ret = -ENODEV;
  9882. + kfree(mailbox);
  9883. + } else {
  9884. + /* should be based on the registers from res really */
  9885. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  9886. +
  9887. + platform_set_drvdata(pdev, mailbox);
  9888. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  9889. +
  9890. + mbox_irqaction.dev_id = mailbox;
  9891. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  9892. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  9893. + __io_address(ARM_0_MAIL0_RD));
  9894. + }
  9895. + }
  9896. +
  9897. + if (ret == 0) {
  9898. + /*
  9899. + * Register the character device
  9900. + */
  9901. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  9902. +
  9903. + /*
  9904. + * Negative values signify an error
  9905. + */
  9906. + if (ret < 0) {
  9907. + printk(KERN_ERR DRIVER_NAME
  9908. + "Failed registering the character device %d\n", ret);
  9909. + return ret;
  9910. + }
  9911. + }
  9912. + return ret;
  9913. +}
  9914. +
  9915. +static int bcm_vcio_remove(struct platform_device *pdev)
  9916. +{
  9917. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  9918. +
  9919. + platform_set_drvdata(pdev, NULL);
  9920. + kfree(mailbox);
  9921. +
  9922. + return 0;
  9923. +}
  9924. +
  9925. +static struct platform_driver bcm_mbox_driver = {
  9926. + .probe = bcm_vcio_probe,
  9927. + .remove = bcm_vcio_remove,
  9928. +
  9929. + .driver = {
  9930. + .name = DRIVER_NAME,
  9931. + .owner = THIS_MODULE,
  9932. + },
  9933. +};
  9934. +
  9935. +static int __init bcm_mbox_init(void)
  9936. +{
  9937. + int ret;
  9938. +
  9939. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  9940. +
  9941. + ret = platform_driver_register(&bcm_mbox_driver);
  9942. + if (ret != 0) {
  9943. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  9944. + "on platform\n");
  9945. + }
  9946. +
  9947. + return ret;
  9948. +}
  9949. +
  9950. +static void __exit bcm_mbox_exit(void)
  9951. +{
  9952. + platform_driver_unregister(&bcm_mbox_driver);
  9953. +}
  9954. +
  9955. +arch_initcall(bcm_mbox_init); /* Initialize early */
  9956. +module_exit(bcm_mbox_exit);
  9957. +
  9958. +MODULE_AUTHOR("Gray Girling");
  9959. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  9960. +MODULE_LICENSE("GPL");
  9961. +MODULE_ALIAS("platform:bcm-mbox");
  9962. diff -Nur linux-3.12.38/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  9963. --- linux-3.12.38/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  9964. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2015-03-09 10:39:28.582893746 +0100
  9965. @@ -0,0 +1,432 @@
  9966. +/*****************************************************************************
  9967. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  9968. +*
  9969. +* Unless you and Broadcom execute a separate written software license
  9970. +* agreement governing use of this software, this software is licensed to you
  9971. +* under the terms of the GNU General Public License version 2, available at
  9972. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9973. +*
  9974. +* Notwithstanding the above, under no circumstances may you combine this
  9975. +* software in any way with any other Broadcom software provided under a
  9976. +* license other than the GPL, without Broadcom's express prior written
  9977. +* consent.
  9978. +*****************************************************************************/
  9979. +
  9980. +#include <linux/kernel.h>
  9981. +#include <linux/module.h>
  9982. +#include <linux/fs.h>
  9983. +#include <linux/device.h>
  9984. +#include <linux/cdev.h>
  9985. +#include <linux/mm.h>
  9986. +#include <linux/slab.h>
  9987. +#include <linux/debugfs.h>
  9988. +#include <asm/uaccess.h>
  9989. +#include <linux/dma-mapping.h>
  9990. +
  9991. +#ifdef CONFIG_ARCH_KONA
  9992. +#include <chal/chal_ipc.h>
  9993. +#elif CONFIG_ARCH_BCM2708
  9994. +#else
  9995. +#include <csp/chal_ipc.h>
  9996. +#endif
  9997. +
  9998. +#include "mach/vc_mem.h"
  9999. +#include <mach/vcio.h>
  10000. +
  10001. +#define DRIVER_NAME "vc-mem"
  10002. +
  10003. +// Device (/dev) related variables
  10004. +static dev_t vc_mem_devnum = 0;
  10005. +static struct class *vc_mem_class = NULL;
  10006. +static struct cdev vc_mem_cdev;
  10007. +static int vc_mem_inited = 0;
  10008. +
  10009. +#ifdef CONFIG_DEBUG_FS
  10010. +static struct dentry *vc_mem_debugfs_entry;
  10011. +#endif
  10012. +
  10013. +/*
  10014. + * Videocore memory addresses and size
  10015. + *
  10016. + * Drivers that wish to know the videocore memory addresses and sizes should
  10017. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  10018. + * headers. This allows the other drivers to not be tied down to a a certain
  10019. + * address/size at compile time.
  10020. + *
  10021. + * In the future, the goal is to have the videocore memory virtual address and
  10022. + * size be calculated at boot time rather than at compile time. The decision of
  10023. + * where the videocore memory resides and its size would be in the hands of the
  10024. + * bootloader (and/or kernel). When that happens, the values of these variables
  10025. + * would be calculated and assigned in the init function.
  10026. + */
  10027. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  10028. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  10029. +unsigned int mm_vc_mem_size = 0;
  10030. +unsigned int mm_vc_mem_base = 0;
  10031. +
  10032. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  10033. +EXPORT_SYMBOL(mm_vc_mem_size);
  10034. +EXPORT_SYMBOL(mm_vc_mem_base);
  10035. +
  10036. +static uint phys_addr = 0;
  10037. +static uint mem_size = 0;
  10038. +static uint mem_base = 0;
  10039. +
  10040. +
  10041. +/****************************************************************************
  10042. +*
  10043. +* vc_mem_open
  10044. +*
  10045. +***************************************************************************/
  10046. +
  10047. +static int
  10048. +vc_mem_open(struct inode *inode, struct file *file)
  10049. +{
  10050. + (void) inode;
  10051. + (void) file;
  10052. +
  10053. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  10054. +
  10055. + return 0;
  10056. +}
  10057. +
  10058. +/****************************************************************************
  10059. +*
  10060. +* vc_mem_release
  10061. +*
  10062. +***************************************************************************/
  10063. +
  10064. +static int
  10065. +vc_mem_release(struct inode *inode, struct file *file)
  10066. +{
  10067. + (void) inode;
  10068. + (void) file;
  10069. +
  10070. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  10071. +
  10072. + return 0;
  10073. +}
  10074. +
  10075. +/****************************************************************************
  10076. +*
  10077. +* vc_mem_get_size
  10078. +*
  10079. +***************************************************************************/
  10080. +
  10081. +static void
  10082. +vc_mem_get_size(void)
  10083. +{
  10084. +}
  10085. +
  10086. +/****************************************************************************
  10087. +*
  10088. +* vc_mem_get_base
  10089. +*
  10090. +***************************************************************************/
  10091. +
  10092. +static void
  10093. +vc_mem_get_base(void)
  10094. +{
  10095. +}
  10096. +
  10097. +/****************************************************************************
  10098. +*
  10099. +* vc_mem_get_current_size
  10100. +*
  10101. +***************************************************************************/
  10102. +
  10103. +int
  10104. +vc_mem_get_current_size(void)
  10105. +{
  10106. + return mm_vc_mem_size;
  10107. +}
  10108. +
  10109. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  10110. +
  10111. +/****************************************************************************
  10112. +*
  10113. +* vc_mem_ioctl
  10114. +*
  10115. +***************************************************************************/
  10116. +
  10117. +static long
  10118. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  10119. +{
  10120. + int rc = 0;
  10121. +
  10122. + (void) cmd;
  10123. + (void) arg;
  10124. +
  10125. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  10126. +
  10127. + switch (cmd) {
  10128. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  10129. + {
  10130. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  10131. + __func__, (void *) mm_vc_mem_phys_addr);
  10132. +
  10133. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  10134. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  10135. + rc = -EFAULT;
  10136. + }
  10137. + break;
  10138. + }
  10139. + case VC_MEM_IOC_MEM_SIZE:
  10140. + {
  10141. + // Get the videocore memory size first
  10142. + vc_mem_get_size();
  10143. +
  10144. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  10145. + mm_vc_mem_size);
  10146. +
  10147. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  10148. + sizeof (mm_vc_mem_size)) != 0) {
  10149. + rc = -EFAULT;
  10150. + }
  10151. + break;
  10152. + }
  10153. + case VC_MEM_IOC_MEM_BASE:
  10154. + {
  10155. + // Get the videocore memory base
  10156. + vc_mem_get_base();
  10157. +
  10158. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  10159. + mm_vc_mem_base);
  10160. +
  10161. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  10162. + sizeof (mm_vc_mem_base)) != 0) {
  10163. + rc = -EFAULT;
  10164. + }
  10165. + break;
  10166. + }
  10167. + case VC_MEM_IOC_MEM_LOAD:
  10168. + {
  10169. + // Get the videocore memory base
  10170. + vc_mem_get_base();
  10171. +
  10172. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  10173. + mm_vc_mem_base);
  10174. +
  10175. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  10176. + sizeof (mm_vc_mem_base)) != 0) {
  10177. + rc = -EFAULT;
  10178. + }
  10179. + break;
  10180. + }
  10181. + default:
  10182. + {
  10183. + return -ENOTTY;
  10184. + }
  10185. + }
  10186. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  10187. +
  10188. + return rc;
  10189. +}
  10190. +
  10191. +/****************************************************************************
  10192. +*
  10193. +* vc_mem_mmap
  10194. +*
  10195. +***************************************************************************/
  10196. +
  10197. +static int
  10198. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  10199. +{
  10200. + int rc = 0;
  10201. + unsigned long length = vma->vm_end - vma->vm_start;
  10202. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  10203. +
  10204. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  10205. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  10206. + (long) vma->vm_pgoff);
  10207. +
  10208. + if (offset + length > mm_vc_mem_size) {
  10209. + pr_err("%s: length %ld is too big\n", __func__, length);
  10210. + return -EINVAL;
  10211. + }
  10212. + // Do not cache the memory map
  10213. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  10214. +
  10215. + rc = remap_pfn_range(vma, vma->vm_start,
  10216. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  10217. + vma->vm_pgoff, length, vma->vm_page_prot);
  10218. + if (rc != 0) {
  10219. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  10220. + }
  10221. +
  10222. + return rc;
  10223. +}
  10224. +
  10225. +/****************************************************************************
  10226. +*
  10227. +* File Operations for the driver.
  10228. +*
  10229. +***************************************************************************/
  10230. +
  10231. +static const struct file_operations vc_mem_fops = {
  10232. + .owner = THIS_MODULE,
  10233. + .open = vc_mem_open,
  10234. + .release = vc_mem_release,
  10235. + .unlocked_ioctl = vc_mem_ioctl,
  10236. + .mmap = vc_mem_mmap,
  10237. +};
  10238. +
  10239. +#ifdef CONFIG_DEBUG_FS
  10240. +static void vc_mem_debugfs_deinit(void)
  10241. +{
  10242. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  10243. + vc_mem_debugfs_entry = NULL;
  10244. +}
  10245. +
  10246. +
  10247. +static int vc_mem_debugfs_init(
  10248. + struct device *dev)
  10249. +{
  10250. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  10251. + if (!vc_mem_debugfs_entry) {
  10252. + dev_warn(dev, "could not create debugfs entry\n");
  10253. + return -EFAULT;
  10254. + }
  10255. +
  10256. + if (!debugfs_create_x32("vc_mem_phys_addr",
  10257. + 0444,
  10258. + vc_mem_debugfs_entry,
  10259. + (u32 *)&mm_vc_mem_phys_addr)) {
  10260. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  10261. + __func__);
  10262. + goto fail;
  10263. + }
  10264. +
  10265. + if (!debugfs_create_x32("vc_mem_size",
  10266. + 0444,
  10267. + vc_mem_debugfs_entry,
  10268. + (u32 *)&mm_vc_mem_size)) {
  10269. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  10270. + __func__);
  10271. + goto fail;
  10272. + }
  10273. +
  10274. + if (!debugfs_create_x32("vc_mem_base",
  10275. + 0444,
  10276. + vc_mem_debugfs_entry,
  10277. + (u32 *)&mm_vc_mem_base)) {
  10278. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  10279. + __func__);
  10280. + goto fail;
  10281. + }
  10282. +
  10283. + return 0;
  10284. +
  10285. +fail:
  10286. + vc_mem_debugfs_deinit();
  10287. + return -EFAULT;
  10288. +}
  10289. +
  10290. +#endif /* CONFIG_DEBUG_FS */
  10291. +
  10292. +
  10293. +/****************************************************************************
  10294. +*
  10295. +* vc_mem_init
  10296. +*
  10297. +***************************************************************************/
  10298. +
  10299. +static int __init
  10300. +vc_mem_init(void)
  10301. +{
  10302. + int rc = -EFAULT;
  10303. + struct device *dev;
  10304. +
  10305. + pr_debug("%s: called\n", __func__);
  10306. +
  10307. + mm_vc_mem_phys_addr = phys_addr;
  10308. + mm_vc_mem_size = mem_size;
  10309. + mm_vc_mem_base = mem_base;
  10310. +
  10311. + vc_mem_get_size();
  10312. +
  10313. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  10314. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  10315. +
  10316. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  10317. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  10318. + __func__, rc);
  10319. + goto out_err;
  10320. + }
  10321. +
  10322. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  10323. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  10324. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  10325. + goto out_unregister;
  10326. + }
  10327. +
  10328. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  10329. + if (IS_ERR(vc_mem_class)) {
  10330. + rc = PTR_ERR(vc_mem_class);
  10331. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  10332. + goto out_cdev_del;
  10333. + }
  10334. +
  10335. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  10336. + DRIVER_NAME);
  10337. + if (IS_ERR(dev)) {
  10338. + rc = PTR_ERR(dev);
  10339. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  10340. + goto out_class_destroy;
  10341. + }
  10342. +
  10343. +#ifdef CONFIG_DEBUG_FS
  10344. + /* don't fail if the debug entries cannot be created */
  10345. + vc_mem_debugfs_init(dev);
  10346. +#endif
  10347. +
  10348. + vc_mem_inited = 1;
  10349. + return 0;
  10350. +
  10351. + device_destroy(vc_mem_class, vc_mem_devnum);
  10352. +
  10353. + out_class_destroy:
  10354. + class_destroy(vc_mem_class);
  10355. + vc_mem_class = NULL;
  10356. +
  10357. + out_cdev_del:
  10358. + cdev_del(&vc_mem_cdev);
  10359. +
  10360. + out_unregister:
  10361. + unregister_chrdev_region(vc_mem_devnum, 1);
  10362. +
  10363. + out_err:
  10364. + return -1;
  10365. +}
  10366. +
  10367. +/****************************************************************************
  10368. +*
  10369. +* vc_mem_exit
  10370. +*
  10371. +***************************************************************************/
  10372. +
  10373. +static void __exit
  10374. +vc_mem_exit(void)
  10375. +{
  10376. + pr_debug("%s: called\n", __func__);
  10377. +
  10378. + if (vc_mem_inited) {
  10379. +#if CONFIG_DEBUG_FS
  10380. + vc_mem_debugfs_deinit();
  10381. +#endif
  10382. + device_destroy(vc_mem_class, vc_mem_devnum);
  10383. + class_destroy(vc_mem_class);
  10384. + cdev_del(&vc_mem_cdev);
  10385. + unregister_chrdev_region(vc_mem_devnum, 1);
  10386. + }
  10387. +}
  10388. +
  10389. +module_init(vc_mem_init);
  10390. +module_exit(vc_mem_exit);
  10391. +MODULE_LICENSE("GPL");
  10392. +MODULE_AUTHOR("Broadcom Corporation");
  10393. +
  10394. +module_param(phys_addr, uint, 0644);
  10395. +module_param(mem_size, uint, 0644);
  10396. +module_param(mem_base, uint, 0644);
  10397. +
  10398. diff -Nur linux-3.12.38/arch/arm/mach-imx/clk-imx6q.c linux-rpi/arch/arm/mach-imx/clk-imx6q.c
  10399. --- linux-3.12.38/arch/arm/mach-imx/clk-imx6q.c 2015-02-16 16:15:42.000000000 +0100
  10400. +++ linux-rpi/arch/arm/mach-imx/clk-imx6q.c 2015-03-10 17:26:49.726216697 +0100
  10401. @@ -304,8 +304,8 @@
  10402. post_div_table[1].div = 1;
  10403. post_div_table[2].div = 1;
  10404. video_div_table[1].div = 1;
  10405. - video_div_table[3].div = 1;
  10406. - }
  10407. + video_div_table[2].div = 1;
  10408. + };
  10409. /* type name parent_name base div_mask */
  10410. clk[pll1_sys] = imx_clk_pllv3(IMX_PLLV3_SYS, "pll1_sys", "osc", base, 0x7f);
  10411. diff -Nur linux-3.12.38/arch/arm/mach-mvebu/coherency.c linux-rpi/arch/arm/mach-mvebu/coherency.c
  10412. --- linux-3.12.38/arch/arm/mach-mvebu/coherency.c 2015-02-16 16:15:42.000000000 +0100
  10413. +++ linux-rpi/arch/arm/mach-mvebu/coherency.c 2015-03-10 17:26:49.738216697 +0100
  10414. @@ -124,29 +124,6 @@
  10415. {
  10416. struct device_node *np;
  10417. - /*
  10418. - * The coherency fabric is needed:
  10419. - * - For coherency between processors on Armada XP, so only
  10420. - * when SMP is enabled.
  10421. - * - For coherency between the processor and I/O devices, but
  10422. - * this coherency requires many pre-requisites (write
  10423. - * allocate cache policy, shareable pages, SMP bit set) that
  10424. - * are only meant in SMP situations.
  10425. - *
  10426. - * Note that this means that on Armada 370, there is currently
  10427. - * no way to use hardware I/O coherency, because even when
  10428. - * CONFIG_SMP is enabled, is_smp() returns false due to the
  10429. - * Armada 370 being a single-core processor. To lift this
  10430. - * limitation, we would have to find a way to make the cache
  10431. - * policy set to write-allocate (on all Armada SoCs), and to
  10432. - * set the shareable attribute in page tables (on all Armada
  10433. - * SoCs except the Armada 370). Unfortunately, such decisions
  10434. - * are taken very early in the kernel boot process, at a point
  10435. - * where we don't know yet on which SoC we are running.
  10436. - */
  10437. - if (!is_smp())
  10438. - return 0;
  10439. -
  10440. np = of_find_matching_node(NULL, of_coherency_table);
  10441. if (np) {
  10442. struct resource res;
  10443. @@ -173,9 +150,6 @@
  10444. {
  10445. struct device_node *np;
  10446. - if (!is_smp())
  10447. - return 0;
  10448. -
  10449. np = of_find_matching_node(NULL, of_coherency_table);
  10450. if (np) {
  10451. bus_register_notifier(&platform_bus_type,
  10452. diff -Nur linux-3.12.38/arch/arm/mach-omap2/pm44xx.c linux-rpi/arch/arm/mach-omap2/pm44xx.c
  10453. --- linux-3.12.38/arch/arm/mach-omap2/pm44xx.c 2015-02-16 16:15:42.000000000 +0100
  10454. +++ linux-rpi/arch/arm/mach-omap2/pm44xx.c 2015-03-10 17:26:49.754216697 +0100
  10455. @@ -146,6 +146,26 @@
  10456. struct clockdomain *ducati_clkdm, *l3_2_clkdm;
  10457. int ret = 0;
  10458. + if (omap_rev() == OMAP4430_REV_ES1_0) {
  10459. + WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  10460. + return -ENODEV;
  10461. + }
  10462. +
  10463. + pr_err("Power Management for TI OMAP4.\n");
  10464. + /*
  10465. + * OMAP4 chip PM currently works only with certain (newer)
  10466. + * versions of bootloaders. This is due to missing code in the
  10467. + * kernel to properly reset and initialize some devices.
  10468. + * http://www.spinics.net/lists/arm-kernel/msg218641.html
  10469. + */
  10470. + pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  10471. +
  10472. + ret = pwrdm_for_each(pwrdms_setup, NULL);
  10473. + if (ret) {
  10474. + pr_err("Failed to setup powerdomains\n");
  10475. + return ret;
  10476. + }
  10477. +
  10478. /*
  10479. * The dynamic dependency between MPUSS -> MEMIF and
  10480. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  10481. @@ -196,15 +216,6 @@
  10482. pr_info("Power Management for TI OMAP4+ devices.\n");
  10483. - /*
  10484. - * OMAP4 chip PM currently works only with certain (newer)
  10485. - * versions of bootloaders. This is due to missing code in the
  10486. - * kernel to properly reset and initialize some devices.
  10487. - * http://www.spinics.net/lists/arm-kernel/msg218641.html
  10488. - */
  10489. - if (cpu_is_omap44xx())
  10490. - pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  10491. -
  10492. ret = pwrdm_for_each(pwrdms_setup, NULL);
  10493. if (ret) {
  10494. pr_err("Failed to setup powerdomains.\n");
  10495. diff -Nur linux-3.12.38/arch/arm/mach-omap2/timer.c linux-rpi/arch/arm/mach-omap2/timer.c
  10496. --- linux-3.12.38/arch/arm/mach-omap2/timer.c 2015-02-16 16:15:42.000000000 +0100
  10497. +++ linux-rpi/arch/arm/mach-omap2/timer.c 2015-03-10 17:26:49.758216697 +0100
  10498. @@ -503,11 +503,11 @@
  10499. rate = clk_get_rate(sys_clk);
  10500. /* Numerator/denumerator values refer TRM Realtime Counter section */
  10501. switch (rate) {
  10502. - case 12000000:
  10503. + case 1200000:
  10504. num = 64;
  10505. den = 125;
  10506. break;
  10507. - case 13000000:
  10508. + case 1300000:
  10509. num = 768;
  10510. den = 1625;
  10511. break;
  10512. @@ -515,11 +515,11 @@
  10513. num = 8;
  10514. den = 25;
  10515. break;
  10516. - case 26000000:
  10517. + case 2600000:
  10518. num = 384;
  10519. den = 1625;
  10520. break;
  10521. - case 27000000:
  10522. + case 2700000:
  10523. num = 256;
  10524. den = 1125;
  10525. break;
  10526. diff -Nur linux-3.12.38/arch/arm/mach-shmobile/setup-sh73a0.c linux-rpi/arch/arm/mach-shmobile/setup-sh73a0.c
  10527. --- linux-3.12.38/arch/arm/mach-shmobile/setup-sh73a0.c 2015-02-16 16:15:42.000000000 +0100
  10528. +++ linux-rpi/arch/arm/mach-shmobile/setup-sh73a0.c 2015-03-10 17:26:49.782216697 +0100
  10529. @@ -746,7 +746,6 @@
  10530. static struct renesas_intc_irqpin_config irqpin0_platform_data = {
  10531. .irq_base = irq_pin(0), /* IRQ0 -> IRQ7 */
  10532. - .control_parent = true,
  10533. };
  10534. static struct resource irqpin0_resources[] = {
  10535. @@ -808,7 +807,6 @@
  10536. static struct renesas_intc_irqpin_config irqpin2_platform_data = {
  10537. .irq_base = irq_pin(16), /* IRQ16 -> IRQ23 */
  10538. - .control_parent = true,
  10539. };
  10540. static struct resource irqpin2_resources[] = {
  10541. @@ -839,7 +837,6 @@
  10542. static struct renesas_intc_irqpin_config irqpin3_platform_data = {
  10543. .irq_base = irq_pin(24), /* IRQ24 -> IRQ31 */
  10544. - .control_parent = true,
  10545. };
  10546. static struct resource irqpin3_resources[] = {
  10547. diff -Nur linux-3.12.38/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  10548. --- linux-3.12.38/arch/arm/Makefile 2015-02-16 16:15:42.000000000 +0100
  10549. +++ linux-rpi/arch/arm/Makefile 2015-03-10 17:26:49.670216697 +0100
  10550. @@ -146,6 +146,7 @@
  10551. # by CONFIG_* macro name.
  10552. machine-$(CONFIG_ARCH_AT91) += at91
  10553. machine-$(CONFIG_ARCH_BCM) += bcm
  10554. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  10555. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  10556. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  10557. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  10558. diff -Nur linux-3.12.38/arch/arm/mm/dma-mapping.c linux-rpi/arch/arm/mm/dma-mapping.c
  10559. --- linux-3.12.38/arch/arm/mm/dma-mapping.c 2015-02-16 16:15:42.000000000 +0100
  10560. +++ linux-rpi/arch/arm/mm/dma-mapping.c 2015-03-10 17:26:49.790216697 +0100
  10561. @@ -429,21 +429,12 @@
  10562. map.type = MT_MEMORY_DMA_READY;
  10563. /*
  10564. - * Clear previous low-memory mapping to ensure that the
  10565. - * TLB does not see any conflicting entries, then flush
  10566. - * the TLB of the old entries before creating new mappings.
  10567. - *
  10568. - * This ensures that any speculatively loaded TLB entries
  10569. - * (even though they may be rare) can not cause any problems,
  10570. - * and ensures that this code is architecturally compliant.
  10571. + * Clear previous low-memory mapping
  10572. */
  10573. for (addr = __phys_to_virt(start); addr < __phys_to_virt(end);
  10574. addr += PMD_SIZE)
  10575. pmd_clear(pmd_off_k(addr));
  10576. - flush_tlb_kernel_range(__phys_to_virt(start),
  10577. - __phys_to_virt(end));
  10578. -
  10579. iotable_init(&map, 1);
  10580. }
  10581. }
  10582. diff -Nur linux-3.12.38/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  10583. --- linux-3.12.38/arch/arm/mm/Kconfig 2015-02-16 16:15:42.000000000 +0100
  10584. +++ linux-rpi/arch/arm/mm/Kconfig 2015-03-10 17:26:49.790216697 +0100
  10585. @@ -358,7 +358,7 @@
  10586. # ARMv6
  10587. config CPU_V6
  10588. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  10589. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  10590. select CPU_32v6
  10591. select CPU_ABRT_EV6
  10592. select CPU_CACHE_V6
  10593. diff -Nur linux-3.12.38/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  10594. --- linux-3.12.38/arch/arm/mm/proc-v6.S 2015-02-16 16:15:42.000000000 +0100
  10595. +++ linux-rpi/arch/arm/mm/proc-v6.S 2015-03-10 17:26:49.790216697 +0100
  10596. @@ -73,10 +73,19 @@
  10597. *
  10598. * IRQs are already disabled.
  10599. */
  10600. +
  10601. +/* See jira SW-5991 for details of this workaround */
  10602. ENTRY(cpu_v6_do_idle)
  10603. - mov r1, #0
  10604. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  10605. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  10606. + .align 5
  10607. + mov r1, #2
  10608. +1: subs r1, #1
  10609. + nop
  10610. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  10611. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  10612. + nop
  10613. + nop
  10614. + nop
  10615. + bne 1b
  10616. mov pc, lr
  10617. ENTRY(cpu_v6_dcache_clean_area)
  10618. diff -Nur linux-3.12.38/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  10619. --- linux-3.12.38/arch/arm/tools/mach-types 2015-02-16 16:15:42.000000000 +0100
  10620. +++ linux-rpi/arch/arm/tools/mach-types 2015-03-10 17:26:49.798216697 +0100
  10621. @@ -522,6 +522,7 @@
  10622. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  10623. paz00 MACH_PAZ00 PAZ00 3128
  10624. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  10625. +bcm2708 MACH_BCM2708 BCM2708 3138
  10626. ag5evm MACH_AG5EVM AG5EVM 3189
  10627. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  10628. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  10629. diff -Nur linux-3.12.38/arch/arm64/include/asm/cputype.h linux-rpi/arch/arm64/include/asm/cputype.h
  10630. --- linux-3.12.38/arch/arm64/include/asm/cputype.h 2015-02-16 16:15:42.000000000 +0100
  10631. +++ linux-rpi/arch/arm64/include/asm/cputype.h 2015-03-10 17:26:49.798216697 +0100
  10632. @@ -77,8 +77,6 @@
  10633. return read_cpuid(ID_CTR_EL0);
  10634. }
  10635. -void cpuinfo_store_cpu(void);
  10636. -
  10637. #endif /* __ASSEMBLY__ */
  10638. #endif
  10639. diff -Nur linux-3.12.38/arch/arm64/kernel/setup.c linux-rpi/arch/arm64/kernel/setup.c
  10640. --- linux-3.12.38/arch/arm64/kernel/setup.c 2015-02-16 16:15:42.000000000 +0100
  10641. +++ linux-rpi/arch/arm64/kernel/setup.c 2015-03-10 17:26:49.802216697 +0100
  10642. @@ -41,7 +41,6 @@
  10643. #include <linux/memblock.h>
  10644. #include <linux/of_fdt.h>
  10645. #include <linux/of_platform.h>
  10646. -#include <linux/personality.h>
  10647. #include <asm/cputype.h>
  10648. #include <asm/elf.h>
  10649. @@ -98,19 +97,6 @@
  10650. printk("%s", buf);
  10651. }
  10652. -struct cpuinfo_arm64 {
  10653. - struct cpu cpu;
  10654. - u32 reg_midr;
  10655. -};
  10656. -
  10657. -static DEFINE_PER_CPU(struct cpuinfo_arm64, cpu_data);
  10658. -
  10659. -void cpuinfo_store_cpu(void)
  10660. -{
  10661. - struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
  10662. - info->reg_midr = read_cpuid_id();
  10663. -}
  10664. -
  10665. static void __init setup_processor(void)
  10666. {
  10667. struct cpu_info *cpu_info;
  10668. @@ -141,8 +127,6 @@
  10669. struct boot_param_header *devtree;
  10670. unsigned long dt_root;
  10671. - cpuinfo_store_cpu();
  10672. -
  10673. /* Check we have a non-NULL DT pointer */
  10674. if (!dt_phys) {
  10675. early_print("\n"
  10676. @@ -301,12 +285,14 @@
  10677. }
  10678. arch_initcall(arm64_device_init);
  10679. +static DEFINE_PER_CPU(struct cpu, cpu_data);
  10680. +
  10681. static int __init topology_init(void)
  10682. {
  10683. int i;
  10684. for_each_possible_cpu(i) {
  10685. - struct cpu *cpu = &per_cpu(cpu_data.cpu, i);
  10686. + struct cpu *cpu = &per_cpu(cpu_data, i);
  10687. cpu->hotpluggable = 1;
  10688. register_cpu(cpu, i);
  10689. }
  10690. @@ -321,41 +307,14 @@
  10691. NULL
  10692. };
  10693. -#ifdef CONFIG_COMPAT
  10694. -static const char *compat_hwcap_str[] = {
  10695. - "swp",
  10696. - "half",
  10697. - "thumb",
  10698. - "26bit",
  10699. - "fastmult",
  10700. - "fpa",
  10701. - "vfp",
  10702. - "edsp",
  10703. - "java",
  10704. - "iwmmxt",
  10705. - "crunch",
  10706. - "thumbee",
  10707. - "neon",
  10708. - "vfpv3",
  10709. - "vfpv3d16",
  10710. - "tls",
  10711. - "vfpv4",
  10712. - "idiva",
  10713. - "idivt",
  10714. - "vfpd32",
  10715. - "lpae",
  10716. - "evtstrm"
  10717. -};
  10718. -#endif /* CONFIG_COMPAT */
  10719. -
  10720. static int c_show(struct seq_file *m, void *v)
  10721. {
  10722. - int i, j;
  10723. + int i;
  10724. - for_each_online_cpu(i) {
  10725. - struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i);
  10726. - u32 midr = cpuinfo->reg_midr;
  10727. + seq_printf(m, "Processor\t: %s rev %d (%s)\n",
  10728. + cpu_name, read_cpuid_id() & 15, ELF_PLATFORM);
  10729. + for_each_online_cpu(i) {
  10730. /*
  10731. * glibc reads /proc/cpuinfo to determine the number of
  10732. * online processors, looking for lines beginning with
  10733. @@ -364,34 +323,25 @@
  10734. #ifdef CONFIG_SMP
  10735. seq_printf(m, "processor\t: %d\n", i);
  10736. #endif
  10737. -
  10738. - /*
  10739. - * Dump out the common processor features in a single line.
  10740. - * Userspace should read the hwcaps with getauxval(AT_HWCAP)
  10741. - * rather than attempting to parse this, but there's a body of
  10742. - * software which does already (at least for 32-bit).
  10743. - */
  10744. - seq_puts(m, "Features\t:");
  10745. - if (personality(current->personality) == PER_LINUX32) {
  10746. -#ifdef CONFIG_COMPAT
  10747. - for (j = 0; compat_hwcap_str[j]; j++)
  10748. - if (COMPAT_ELF_HWCAP & (1 << j))
  10749. - seq_printf(m, " %s", compat_hwcap_str[j]);
  10750. -#endif /* CONFIG_COMPAT */
  10751. - } else {
  10752. - for (j = 0; hwcap_str[j]; j++)
  10753. - if (elf_hwcap & (1 << j))
  10754. - seq_printf(m, " %s", hwcap_str[j]);
  10755. - }
  10756. - seq_puts(m, "\n");
  10757. -
  10758. - seq_printf(m, "CPU implementer\t: 0x%02x\n", (midr >> 24));
  10759. - seq_printf(m, "CPU architecture: 8\n");
  10760. - seq_printf(m, "CPU variant\t: 0x%x\n", ((midr >> 20) & 0xf));
  10761. - seq_printf(m, "CPU part\t: 0x%03x\n", ((midr >> 4) & 0xfff));
  10762. - seq_printf(m, "CPU revision\t: %d\n\n", (midr & 0xf));
  10763. }
  10764. + /* dump out the processor features */
  10765. + seq_puts(m, "Features\t: ");
  10766. +
  10767. + for (i = 0; hwcap_str[i]; i++)
  10768. + if (elf_hwcap & (1 << i))
  10769. + seq_printf(m, "%s ", hwcap_str[i]);
  10770. +
  10771. + seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
  10772. + seq_printf(m, "CPU architecture: AArch64\n");
  10773. + seq_printf(m, "CPU variant\t: 0x%x\n", (read_cpuid_id() >> 20) & 15);
  10774. + seq_printf(m, "CPU part\t: 0x%03x\n", (read_cpuid_id() >> 4) & 0xfff);
  10775. + seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
  10776. +
  10777. + seq_puts(m, "\n");
  10778. +
  10779. + seq_printf(m, "Hardware\t: %s\n", machine_name);
  10780. +
  10781. return 0;
  10782. }
  10783. diff -Nur linux-3.12.38/arch/arm64/kernel/smp.c linux-rpi/arch/arm64/kernel/smp.c
  10784. --- linux-3.12.38/arch/arm64/kernel/smp.c 2015-02-16 16:15:42.000000000 +0100
  10785. +++ linux-rpi/arch/arm64/kernel/smp.c 2015-03-10 17:26:49.806216697 +0100
  10786. @@ -200,11 +200,6 @@
  10787. raw_spin_unlock(&boot_lock);
  10788. /*
  10789. - * Log the CPU info before it is marked online and might get read.
  10790. - */
  10791. - cpuinfo_store_cpu();
  10792. -
  10793. - /*
  10794. * OK, now it's safe to let the boot CPU continue. Wait for
  10795. * the CPU migration code to notice that the CPU is online
  10796. * before we continue.
  10797. diff -Nur linux-3.12.38/arch/mips/kernel/irq_cpu.c linux-rpi/arch/mips/kernel/irq_cpu.c
  10798. --- linux-3.12.38/arch/mips/kernel/irq_cpu.c 2015-02-16 16:15:42.000000000 +0100
  10799. +++ linux-rpi/arch/mips/kernel/irq_cpu.c 2015-03-10 17:26:49.886216696 +0100
  10800. @@ -56,8 +56,6 @@
  10801. .irq_mask_ack = mask_mips_irq,
  10802. .irq_unmask = unmask_mips_irq,
  10803. .irq_eoi = unmask_mips_irq,
  10804. - .irq_disable = mask_mips_irq,
  10805. - .irq_enable = unmask_mips_irq,
  10806. };
  10807. /*
  10808. @@ -94,8 +92,6 @@
  10809. .irq_mask_ack = mips_mt_cpu_irq_ack,
  10810. .irq_unmask = unmask_mips_irq,
  10811. .irq_eoi = unmask_mips_irq,
  10812. - .irq_disable = mask_mips_irq,
  10813. - .irq_enable = unmask_mips_irq,
  10814. };
  10815. void __init mips_cpu_irq_init(void)
  10816. diff -Nur linux-3.12.38/arch/mips/kernel/smp.c linux-rpi/arch/mips/kernel/smp.c
  10817. --- linux-3.12.38/arch/mips/kernel/smp.c 2015-02-16 16:15:42.000000000 +0100
  10818. +++ linux-rpi/arch/mips/kernel/smp.c 2015-03-10 17:26:49.886216696 +0100
  10819. @@ -109,10 +109,10 @@
  10820. else
  10821. #endif /* CONFIG_MIPS_MT_SMTC */
  10822. cpu_probe();
  10823. + cpu_report();
  10824. per_cpu_trap_init(false);
  10825. mips_clockevent_init();
  10826. mp_ops->init_secondary();
  10827. - cpu_report();
  10828. /*
  10829. * XXX parity protection should be folded in here when it's converted
  10830. diff -Nur linux-3.12.38/arch/powerpc/crypto/sha1.c linux-rpi/arch/powerpc/crypto/sha1.c
  10831. --- linux-3.12.38/arch/powerpc/crypto/sha1.c 2015-02-16 16:15:42.000000000 +0100
  10832. +++ linux-rpi/arch/powerpc/crypto/sha1.c 2015-03-10 17:26:49.930216696 +0100
  10833. @@ -154,5 +154,4 @@
  10834. MODULE_LICENSE("GPL");
  10835. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
  10836. -MODULE_ALIAS_CRYPTO("sha1");
  10837. -MODULE_ALIAS_CRYPTO("sha1-powerpc");
  10838. +MODULE_ALIAS("sha1-powerpc");
  10839. diff -Nur linux-3.12.38/arch/powerpc/include/asm/reg.h linux-rpi/arch/powerpc/include/asm/reg.h
  10840. --- linux-3.12.38/arch/powerpc/include/asm/reg.h 2015-02-16 16:15:42.000000000 +0100
  10841. +++ linux-rpi/arch/powerpc/include/asm/reg.h 2015-03-10 17:26:49.934216696 +0100
  10842. @@ -116,7 +116,6 @@
  10843. /* Server variant */
  10844. #define MSR_ (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV)
  10845. -#define MSR_IDLE (MSR_ME | MSR_SF | MSR_HV)
  10846. #define MSR_KERNEL (MSR_ | MSR_64BIT)
  10847. #define MSR_USER32 (MSR_ | MSR_PR | MSR_EE)
  10848. #define MSR_USER64 (MSR_USER32 | MSR_64BIT)
  10849. diff -Nur linux-3.12.38/arch/powerpc/kernel/idle_power7.S linux-rpi/arch/powerpc/kernel/idle_power7.S
  10850. --- linux-3.12.38/arch/powerpc/kernel/idle_power7.S 2015-02-16 16:15:42.000000000 +0100
  10851. +++ linux-rpi/arch/powerpc/kernel/idle_power7.S 2015-03-10 17:26:49.942216696 +0100
  10852. @@ -84,22 +84,6 @@
  10853. std r9,_MSR(r1)
  10854. std r1,PACAR1(r13)
  10855. - /*
  10856. - * Go to real mode to do the nap, as required by the architecture.
  10857. - * Also, we need to be in real mode before setting hwthread_state,
  10858. - * because as soon as we do that, another thread can switch
  10859. - * the MMU context to the guest.
  10860. - */
  10861. - LOAD_REG_IMMEDIATE(r5, MSR_IDLE)
  10862. - li r6, MSR_RI
  10863. - andc r6, r9, r6
  10864. - LOAD_REG_ADDR(r7, power7_enter_nap_mode)
  10865. - mtmsrd r6, 1 /* clear RI before setting SRR0/1 */
  10866. - mtspr SPRN_SRR0, r7
  10867. - mtspr SPRN_SRR1, r5
  10868. - rfid
  10869. -
  10870. -power7_enter_nap_mode:
  10871. #ifdef CONFIG_KVM_BOOK3S_64_HV
  10872. /* Tell KVM we're napping */
  10873. li r4,KVM_HWTHREAD_IN_NAP
  10874. diff -Nur linux-3.12.38/arch/powerpc/kernel/udbg_16550.c linux-rpi/arch/powerpc/kernel/udbg_16550.c
  10875. --- linux-3.12.38/arch/powerpc/kernel/udbg_16550.c 2015-02-16 16:15:42.000000000 +0100
  10876. +++ linux-rpi/arch/powerpc/kernel/udbg_16550.c 2015-03-10 17:26:49.950216696 +0100
  10877. @@ -69,12 +69,8 @@
  10878. static int udbg_uart_getc_poll(void)
  10879. {
  10880. - if (!udbg_uart_in)
  10881. - return -1;
  10882. -
  10883. - if (!(udbg_uart_in(UART_LSR) & LSR_DR))
  10884. + if (!udbg_uart_in || !(udbg_uart_in(UART_LSR) & LSR_DR))
  10885. return udbg_uart_in(UART_RBR);
  10886. -
  10887. return -1;
  10888. }
  10889. diff -Nur linux-3.12.38/arch/powerpc/platforms/cell/spufs/inode.c linux-rpi/arch/powerpc/platforms/cell/spufs/inode.c
  10890. --- linux-3.12.38/arch/powerpc/platforms/cell/spufs/inode.c 2015-02-16 16:15:42.000000000 +0100
  10891. +++ linux-rpi/arch/powerpc/platforms/cell/spufs/inode.c 2015-03-10 17:26:49.966216696 +0100
  10892. @@ -164,7 +164,7 @@
  10893. struct dentry *dentry, *tmp;
  10894. mutex_lock(&dir->d_inode->i_mutex);
  10895. - list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_child) {
  10896. + list_for_each_entry_safe(dentry, tmp, &dir->d_subdirs, d_u.d_child) {
  10897. spin_lock(&dentry->d_lock);
  10898. if (!(d_unhashed(dentry)) && dentry->d_inode) {
  10899. dget_dlock(dentry);
  10900. diff -Nur linux-3.12.38/arch/powerpc/xmon/xmon.c linux-rpi/arch/powerpc/xmon/xmon.c
  10901. --- linux-3.12.38/arch/powerpc/xmon/xmon.c 2015-02-16 16:15:42.000000000 +0100
  10902. +++ linux-rpi/arch/powerpc/xmon/xmon.c 2015-03-10 17:26:49.978216695 +0100
  10903. @@ -288,7 +288,6 @@
  10904. args.token = rtas_token("set-indicator");
  10905. if (args.token == RTAS_UNKNOWN_SERVICE)
  10906. return;
  10907. - args.token = cpu_to_be32(args.token);
  10908. args.nargs = cpu_to_be32(3);
  10909. args.nret = cpu_to_be32(1);
  10910. args.rets = &args.args[3];
  10911. diff -Nur linux-3.12.38/arch/s390/crypto/aes_s390.c linux-rpi/arch/s390/crypto/aes_s390.c
  10912. --- linux-3.12.38/arch/s390/crypto/aes_s390.c 2015-02-16 16:15:42.000000000 +0100
  10913. +++ linux-rpi/arch/s390/crypto/aes_s390.c 2015-03-10 17:26:49.982216695 +0100
  10914. @@ -967,7 +967,7 @@
  10915. module_init(aes_s390_init);
  10916. module_exit(aes_s390_fini);
  10917. -MODULE_ALIAS_CRYPTO("aes-all");
  10918. +MODULE_ALIAS("aes-all");
  10919. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
  10920. MODULE_LICENSE("GPL");
  10921. diff -Nur linux-3.12.38/arch/s390/crypto/des_s390.c linux-rpi/arch/s390/crypto/des_s390.c
  10922. --- linux-3.12.38/arch/s390/crypto/des_s390.c 2015-02-16 16:15:42.000000000 +0100
  10923. +++ linux-rpi/arch/s390/crypto/des_s390.c 2015-03-10 17:26:49.982216695 +0100
  10924. @@ -616,8 +616,8 @@
  10925. module_init(des_s390_init);
  10926. module_exit(des_s390_exit);
  10927. -MODULE_ALIAS_CRYPTO("des");
  10928. -MODULE_ALIAS_CRYPTO("des3_ede");
  10929. +MODULE_ALIAS("des");
  10930. +MODULE_ALIAS("des3_ede");
  10931. MODULE_LICENSE("GPL");
  10932. MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");
  10933. diff -Nur linux-3.12.38/arch/s390/crypto/ghash_s390.c linux-rpi/arch/s390/crypto/ghash_s390.c
  10934. --- linux-3.12.38/arch/s390/crypto/ghash_s390.c 2015-02-16 16:15:42.000000000 +0100
  10935. +++ linux-rpi/arch/s390/crypto/ghash_s390.c 2015-03-10 17:26:49.982216695 +0100
  10936. @@ -160,7 +160,7 @@
  10937. module_init(ghash_mod_init);
  10938. module_exit(ghash_mod_exit);
  10939. -MODULE_ALIAS_CRYPTO("ghash");
  10940. +MODULE_ALIAS("ghash");
  10941. MODULE_LICENSE("GPL");
  10942. MODULE_DESCRIPTION("GHASH Message Digest Algorithm, s390 implementation");
  10943. diff -Nur linux-3.12.38/arch/s390/crypto/sha1_s390.c linux-rpi/arch/s390/crypto/sha1_s390.c
  10944. --- linux-3.12.38/arch/s390/crypto/sha1_s390.c 2015-02-16 16:15:42.000000000 +0100
  10945. +++ linux-rpi/arch/s390/crypto/sha1_s390.c 2015-03-10 17:26:49.982216695 +0100
  10946. @@ -103,6 +103,6 @@
  10947. module_init(sha1_s390_init);
  10948. module_exit(sha1_s390_fini);
  10949. -MODULE_ALIAS_CRYPTO("sha1");
  10950. +MODULE_ALIAS("sha1");
  10951. MODULE_LICENSE("GPL");
  10952. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
  10953. diff -Nur linux-3.12.38/arch/s390/crypto/sha256_s390.c linux-rpi/arch/s390/crypto/sha256_s390.c
  10954. --- linux-3.12.38/arch/s390/crypto/sha256_s390.c 2015-02-16 16:15:42.000000000 +0100
  10955. +++ linux-rpi/arch/s390/crypto/sha256_s390.c 2015-03-10 17:26:49.982216695 +0100
  10956. @@ -143,7 +143,7 @@
  10957. module_init(sha256_s390_init);
  10958. module_exit(sha256_s390_fini);
  10959. -MODULE_ALIAS_CRYPTO("sha256");
  10960. -MODULE_ALIAS_CRYPTO("sha224");
  10961. +MODULE_ALIAS("sha256");
  10962. +MODULE_ALIAS("sha224");
  10963. MODULE_LICENSE("GPL");
  10964. MODULE_DESCRIPTION("SHA256 and SHA224 Secure Hash Algorithm");
  10965. diff -Nur linux-3.12.38/arch/s390/crypto/sha512_s390.c linux-rpi/arch/s390/crypto/sha512_s390.c
  10966. --- linux-3.12.38/arch/s390/crypto/sha512_s390.c 2015-02-16 16:15:42.000000000 +0100
  10967. +++ linux-rpi/arch/s390/crypto/sha512_s390.c 2015-03-10 17:26:49.982216695 +0100
  10968. @@ -86,7 +86,7 @@
  10969. }
  10970. };
  10971. -MODULE_ALIAS_CRYPTO("sha512");
  10972. +MODULE_ALIAS("sha512");
  10973. static int sha384_init(struct shash_desc *desc)
  10974. {
  10975. @@ -126,7 +126,7 @@
  10976. }
  10977. };
  10978. -MODULE_ALIAS_CRYPTO("sha384");
  10979. +MODULE_ALIAS("sha384");
  10980. static int __init init(void)
  10981. {
  10982. diff -Nur linux-3.12.38/arch/sparc/crypto/aes_glue.c linux-rpi/arch/sparc/crypto/aes_glue.c
  10983. --- linux-3.12.38/arch/sparc/crypto/aes_glue.c 2015-02-16 16:15:42.000000000 +0100
  10984. +++ linux-rpi/arch/sparc/crypto/aes_glue.c 2015-03-10 17:26:50.006216695 +0100
  10985. @@ -499,6 +499,6 @@
  10986. MODULE_LICENSE("GPL");
  10987. MODULE_DESCRIPTION("AES Secure Hash Algorithm, sparc64 aes opcode accelerated");
  10988. -MODULE_ALIAS_CRYPTO("aes");
  10989. +MODULE_ALIAS("aes");
  10990. #include "crop_devid.c"
  10991. diff -Nur linux-3.12.38/arch/sparc/crypto/camellia_glue.c linux-rpi/arch/sparc/crypto/camellia_glue.c
  10992. --- linux-3.12.38/arch/sparc/crypto/camellia_glue.c 2015-02-16 16:15:42.000000000 +0100
  10993. +++ linux-rpi/arch/sparc/crypto/camellia_glue.c 2015-03-10 17:26:50.006216695 +0100
  10994. @@ -322,6 +322,6 @@
  10995. MODULE_LICENSE("GPL");
  10996. MODULE_DESCRIPTION("Camellia Cipher Algorithm, sparc64 camellia opcode accelerated");
  10997. -MODULE_ALIAS_CRYPTO("aes");
  10998. +MODULE_ALIAS("aes");
  10999. #include "crop_devid.c"
  11000. diff -Nur linux-3.12.38/arch/sparc/crypto/crc32c_glue.c linux-rpi/arch/sparc/crypto/crc32c_glue.c
  11001. --- linux-3.12.38/arch/sparc/crypto/crc32c_glue.c 2015-02-16 16:15:42.000000000 +0100
  11002. +++ linux-rpi/arch/sparc/crypto/crc32c_glue.c 2015-03-10 17:26:50.006216695 +0100
  11003. @@ -176,6 +176,6 @@
  11004. MODULE_LICENSE("GPL");
  11005. MODULE_DESCRIPTION("CRC32c (Castagnoli), sparc64 crc32c opcode accelerated");
  11006. -MODULE_ALIAS_CRYPTO("crc32c");
  11007. +MODULE_ALIAS("crc32c");
  11008. #include "crop_devid.c"
  11009. diff -Nur linux-3.12.38/arch/sparc/crypto/des_glue.c linux-rpi/arch/sparc/crypto/des_glue.c
  11010. --- linux-3.12.38/arch/sparc/crypto/des_glue.c 2015-02-16 16:15:42.000000000 +0100
  11011. +++ linux-rpi/arch/sparc/crypto/des_glue.c 2015-03-10 17:26:50.006216695 +0100
  11012. @@ -532,6 +532,6 @@
  11013. MODULE_LICENSE("GPL");
  11014. MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated");
  11015. -MODULE_ALIAS_CRYPTO("des");
  11016. +MODULE_ALIAS("des");
  11017. #include "crop_devid.c"
  11018. diff -Nur linux-3.12.38/arch/sparc/crypto/md5_glue.c linux-rpi/arch/sparc/crypto/md5_glue.c
  11019. --- linux-3.12.38/arch/sparc/crypto/md5_glue.c 2015-02-16 16:15:42.000000000 +0100
  11020. +++ linux-rpi/arch/sparc/crypto/md5_glue.c 2015-03-10 17:26:50.006216695 +0100
  11021. @@ -185,6 +185,6 @@
  11022. MODULE_LICENSE("GPL");
  11023. MODULE_DESCRIPTION("MD5 Secure Hash Algorithm, sparc64 md5 opcode accelerated");
  11024. -MODULE_ALIAS_CRYPTO("md5");
  11025. +MODULE_ALIAS("md5");
  11026. #include "crop_devid.c"
  11027. diff -Nur linux-3.12.38/arch/sparc/crypto/sha1_glue.c linux-rpi/arch/sparc/crypto/sha1_glue.c
  11028. --- linux-3.12.38/arch/sparc/crypto/sha1_glue.c 2015-02-16 16:15:42.000000000 +0100
  11029. +++ linux-rpi/arch/sparc/crypto/sha1_glue.c 2015-03-10 17:26:50.006216695 +0100
  11030. @@ -180,6 +180,6 @@
  11031. MODULE_LICENSE("GPL");
  11032. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm, sparc64 sha1 opcode accelerated");
  11033. -MODULE_ALIAS_CRYPTO("sha1");
  11034. +MODULE_ALIAS("sha1");
  11035. #include "crop_devid.c"
  11036. diff -Nur linux-3.12.38/arch/sparc/crypto/sha256_glue.c linux-rpi/arch/sparc/crypto/sha256_glue.c
  11037. --- linux-3.12.38/arch/sparc/crypto/sha256_glue.c 2015-02-16 16:15:42.000000000 +0100
  11038. +++ linux-rpi/arch/sparc/crypto/sha256_glue.c 2015-03-10 17:26:50.006216695 +0100
  11039. @@ -237,7 +237,7 @@
  11040. MODULE_LICENSE("GPL");
  11041. MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm, sparc64 sha256 opcode accelerated");
  11042. -MODULE_ALIAS_CRYPTO("sha224");
  11043. -MODULE_ALIAS_CRYPTO("sha256");
  11044. +MODULE_ALIAS("sha224");
  11045. +MODULE_ALIAS("sha256");
  11046. #include "crop_devid.c"
  11047. diff -Nur linux-3.12.38/arch/sparc/crypto/sha512_glue.c linux-rpi/arch/sparc/crypto/sha512_glue.c
  11048. --- linux-3.12.38/arch/sparc/crypto/sha512_glue.c 2015-02-16 16:15:42.000000000 +0100
  11049. +++ linux-rpi/arch/sparc/crypto/sha512_glue.c 2015-03-10 17:26:50.006216695 +0100
  11050. @@ -222,7 +222,7 @@
  11051. MODULE_LICENSE("GPL");
  11052. MODULE_DESCRIPTION("SHA-384 and SHA-512 Secure Hash Algorithm, sparc64 sha512 opcode accelerated");
  11053. -MODULE_ALIAS_CRYPTO("sha384");
  11054. -MODULE_ALIAS_CRYPTO("sha512");
  11055. +MODULE_ALIAS("sha384");
  11056. +MODULE_ALIAS("sha512");
  11057. #include "crop_devid.c"
  11058. diff -Nur linux-3.12.38/arch/um/Kconfig.common linux-rpi/arch/um/Kconfig.common
  11059. --- linux-3.12.38/arch/um/Kconfig.common 2015-02-16 16:15:42.000000000 +0100
  11060. +++ linux-rpi/arch/um/Kconfig.common 2015-03-10 17:26:50.026216695 +0100
  11061. @@ -7,7 +7,6 @@
  11062. bool
  11063. default y
  11064. select HAVE_UID16
  11065. - select HAVE_FUTEX_CMPXCHG if FUTEX
  11066. select GENERIC_IRQ_SHOW
  11067. select GENERIC_CPU_DEVICES
  11068. select GENERIC_IO
  11069. diff -Nur linux-3.12.38/arch/x86/boot/compressed/misc.c linux-rpi/arch/x86/boot/compressed/misc.c
  11070. --- linux-3.12.38/arch/x86/boot/compressed/misc.c 2015-02-16 16:15:42.000000000 +0100
  11071. +++ linux-rpi/arch/x86/boot/compressed/misc.c 2015-03-10 17:26:50.034216695 +0100
  11072. @@ -401,8 +401,6 @@
  11073. unsigned char *output,
  11074. unsigned long output_len)
  11075. {
  11076. - unsigned char *output_orig = output;
  11077. -
  11078. real_mode = rmode;
  11079. sanitize_boot_params(real_mode);
  11080. @@ -441,12 +439,7 @@
  11081. debug_putstr("\nDecompressing Linux... ");
  11082. decompress(input_data, input_len, NULL, NULL, output, NULL, error);
  11083. parse_elf(output);
  11084. - /*
  11085. - * 32-bit always performs relocations. 64-bit relocations are only
  11086. - * needed if kASLR has chosen a different load address.
  11087. - */
  11088. - if (!IS_ENABLED(CONFIG_X86_64) || output != output_orig)
  11089. - handle_relocations(output, output_len);
  11090. + handle_relocations(output, output_len);
  11091. debug_putstr("done.\nBooting the kernel.\n");
  11092. return;
  11093. }
  11094. diff -Nur linux-3.12.38/arch/x86/crypto/aes_glue.c linux-rpi/arch/x86/crypto/aes_glue.c
  11095. --- linux-3.12.38/arch/x86/crypto/aes_glue.c 2015-02-16 16:15:42.000000000 +0100
  11096. +++ linux-rpi/arch/x86/crypto/aes_glue.c 2015-03-10 17:26:50.034216695 +0100
  11097. @@ -66,5 +66,5 @@
  11098. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, asm optimized");
  11099. MODULE_LICENSE("GPL");
  11100. -MODULE_ALIAS_CRYPTO("aes");
  11101. -MODULE_ALIAS_CRYPTO("aes-asm");
  11102. +MODULE_ALIAS("aes");
  11103. +MODULE_ALIAS("aes-asm");
  11104. diff -Nur linux-3.12.38/arch/x86/crypto/aesni-intel_glue.c linux-rpi/arch/x86/crypto/aesni-intel_glue.c
  11105. --- linux-3.12.38/arch/x86/crypto/aesni-intel_glue.c 2015-02-16 16:15:42.000000000 +0100
  11106. +++ linux-rpi/arch/x86/crypto/aesni-intel_glue.c 2015-03-10 17:26:50.034216695 +0100
  11107. @@ -1373,4 +1373,4 @@
  11108. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, Intel AES-NI instructions optimized");
  11109. MODULE_LICENSE("GPL");
  11110. -MODULE_ALIAS_CRYPTO("aes");
  11111. +MODULE_ALIAS("aes");
  11112. diff -Nur linux-3.12.38/arch/x86/crypto/blowfish_glue.c linux-rpi/arch/x86/crypto/blowfish_glue.c
  11113. --- linux-3.12.38/arch/x86/crypto/blowfish_glue.c 2015-02-16 16:15:42.000000000 +0100
  11114. +++ linux-rpi/arch/x86/crypto/blowfish_glue.c 2015-03-10 17:26:50.034216695 +0100
  11115. @@ -481,5 +481,5 @@
  11116. MODULE_LICENSE("GPL");
  11117. MODULE_DESCRIPTION("Blowfish Cipher Algorithm, asm optimized");
  11118. -MODULE_ALIAS_CRYPTO("blowfish");
  11119. -MODULE_ALIAS_CRYPTO("blowfish-asm");
  11120. +MODULE_ALIAS("blowfish");
  11121. +MODULE_ALIAS("blowfish-asm");
  11122. diff -Nur linux-3.12.38/arch/x86/crypto/camellia_aesni_avx2_glue.c linux-rpi/arch/x86/crypto/camellia_aesni_avx2_glue.c
  11123. --- linux-3.12.38/arch/x86/crypto/camellia_aesni_avx2_glue.c 2015-02-16 16:15:42.000000000 +0100
  11124. +++ linux-rpi/arch/x86/crypto/camellia_aesni_avx2_glue.c 2015-03-10 17:26:50.034216695 +0100
  11125. @@ -582,5 +582,5 @@
  11126. MODULE_LICENSE("GPL");
  11127. MODULE_DESCRIPTION("Camellia Cipher Algorithm, AES-NI/AVX2 optimized");
  11128. -MODULE_ALIAS_CRYPTO("camellia");
  11129. -MODULE_ALIAS_CRYPTO("camellia-asm");
  11130. +MODULE_ALIAS("camellia");
  11131. +MODULE_ALIAS("camellia-asm");
  11132. diff -Nur linux-3.12.38/arch/x86/crypto/camellia_aesni_avx_glue.c linux-rpi/arch/x86/crypto/camellia_aesni_avx_glue.c
  11133. --- linux-3.12.38/arch/x86/crypto/camellia_aesni_avx_glue.c 2015-02-16 16:15:42.000000000 +0100
  11134. +++ linux-rpi/arch/x86/crypto/camellia_aesni_avx_glue.c 2015-03-10 17:26:50.034216695 +0100
  11135. @@ -574,5 +574,5 @@
  11136. MODULE_LICENSE("GPL");
  11137. MODULE_DESCRIPTION("Camellia Cipher Algorithm, AES-NI/AVX optimized");
  11138. -MODULE_ALIAS_CRYPTO("camellia");
  11139. -MODULE_ALIAS_CRYPTO("camellia-asm");
  11140. +MODULE_ALIAS("camellia");
  11141. +MODULE_ALIAS("camellia-asm");
  11142. diff -Nur linux-3.12.38/arch/x86/crypto/camellia_glue.c linux-rpi/arch/x86/crypto/camellia_glue.c
  11143. --- linux-3.12.38/arch/x86/crypto/camellia_glue.c 2015-02-16 16:15:42.000000000 +0100
  11144. +++ linux-rpi/arch/x86/crypto/camellia_glue.c 2015-03-10 17:26:50.034216695 +0100
  11145. @@ -1725,5 +1725,5 @@
  11146. MODULE_LICENSE("GPL");
  11147. MODULE_DESCRIPTION("Camellia Cipher Algorithm, asm optimized");
  11148. -MODULE_ALIAS_CRYPTO("camellia");
  11149. -MODULE_ALIAS_CRYPTO("camellia-asm");
  11150. +MODULE_ALIAS("camellia");
  11151. +MODULE_ALIAS("camellia-asm");
  11152. diff -Nur linux-3.12.38/arch/x86/crypto/cast5_avx_glue.c linux-rpi/arch/x86/crypto/cast5_avx_glue.c
  11153. --- linux-3.12.38/arch/x86/crypto/cast5_avx_glue.c 2015-02-16 16:15:42.000000000 +0100
  11154. +++ linux-rpi/arch/x86/crypto/cast5_avx_glue.c 2015-03-10 17:26:50.034216695 +0100
  11155. @@ -494,4 +494,4 @@
  11156. MODULE_DESCRIPTION("Cast5 Cipher Algorithm, AVX optimized");
  11157. MODULE_LICENSE("GPL");
  11158. -MODULE_ALIAS_CRYPTO("cast5");
  11159. +MODULE_ALIAS("cast5");
  11160. diff -Nur linux-3.12.38/arch/x86/crypto/cast6_avx_glue.c linux-rpi/arch/x86/crypto/cast6_avx_glue.c
  11161. --- linux-3.12.38/arch/x86/crypto/cast6_avx_glue.c 2015-02-16 16:15:42.000000000 +0100
  11162. +++ linux-rpi/arch/x86/crypto/cast6_avx_glue.c 2015-03-10 17:26:50.034216695 +0100
  11163. @@ -611,4 +611,4 @@
  11164. MODULE_DESCRIPTION("Cast6 Cipher Algorithm, AVX optimized");
  11165. MODULE_LICENSE("GPL");
  11166. -MODULE_ALIAS_CRYPTO("cast6");
  11167. +MODULE_ALIAS("cast6");
  11168. diff -Nur linux-3.12.38/arch/x86/crypto/crc32c-intel_glue.c linux-rpi/arch/x86/crypto/crc32c-intel_glue.c
  11169. --- linux-3.12.38/arch/x86/crypto/crc32c-intel_glue.c 2015-02-16 16:15:42.000000000 +0100
  11170. +++ linux-rpi/arch/x86/crypto/crc32c-intel_glue.c 2015-03-10 17:26:50.034216695 +0100
  11171. @@ -280,5 +280,5 @@
  11172. MODULE_DESCRIPTION("CRC32c (Castagnoli) optimization using Intel Hardware.");
  11173. MODULE_LICENSE("GPL");
  11174. -MODULE_ALIAS_CRYPTO("crc32c");
  11175. -MODULE_ALIAS_CRYPTO("crc32c-intel");
  11176. +MODULE_ALIAS("crc32c");
  11177. +MODULE_ALIAS("crc32c-intel");
  11178. diff -Nur linux-3.12.38/arch/x86/crypto/crc32-pclmul_glue.c linux-rpi/arch/x86/crypto/crc32-pclmul_glue.c
  11179. --- linux-3.12.38/arch/x86/crypto/crc32-pclmul_glue.c 2015-02-16 16:15:42.000000000 +0100
  11180. +++ linux-rpi/arch/x86/crypto/crc32-pclmul_glue.c 2015-03-10 17:26:50.034216695 +0100
  11181. @@ -197,5 +197,5 @@
  11182. MODULE_AUTHOR("Alexander Boyko <alexander_boyko@xyratex.com>");
  11183. MODULE_LICENSE("GPL");
  11184. -MODULE_ALIAS_CRYPTO("crc32");
  11185. -MODULE_ALIAS_CRYPTO("crc32-pclmul");
  11186. +MODULE_ALIAS("crc32");
  11187. +MODULE_ALIAS("crc32-pclmul");
  11188. diff -Nur linux-3.12.38/arch/x86/crypto/crct10dif-pclmul_glue.c linux-rpi/arch/x86/crypto/crct10dif-pclmul_glue.c
  11189. --- linux-3.12.38/arch/x86/crypto/crct10dif-pclmul_glue.c 2015-02-16 16:15:42.000000000 +0100
  11190. +++ linux-rpi/arch/x86/crypto/crct10dif-pclmul_glue.c 2015-03-10 17:26:50.034216695 +0100
  11191. @@ -147,5 +147,5 @@
  11192. MODULE_DESCRIPTION("T10 DIF CRC calculation accelerated with PCLMULQDQ.");
  11193. MODULE_LICENSE("GPL");
  11194. -MODULE_ALIAS_CRYPTO("crct10dif");
  11195. -MODULE_ALIAS_CRYPTO("crct10dif-pclmul");
  11196. +MODULE_ALIAS("crct10dif");
  11197. +MODULE_ALIAS("crct10dif-pclmul");
  11198. diff -Nur linux-3.12.38/arch/x86/crypto/fpu.c linux-rpi/arch/x86/crypto/fpu.c
  11199. --- linux-3.12.38/arch/x86/crypto/fpu.c 2015-02-16 16:15:42.000000000 +0100
  11200. +++ linux-rpi/arch/x86/crypto/fpu.c 2015-03-10 17:26:50.034216695 +0100
  11201. @@ -17,7 +17,6 @@
  11202. #include <linux/kernel.h>
  11203. #include <linux/module.h>
  11204. #include <linux/slab.h>
  11205. -#include <linux/crypto.h>
  11206. #include <asm/i387.h>
  11207. struct crypto_fpu_ctx {
  11208. @@ -160,5 +159,3 @@
  11209. {
  11210. crypto_unregister_template(&crypto_fpu_tmpl);
  11211. }
  11212. -
  11213. -MODULE_ALIAS_CRYPTO("fpu");
  11214. diff -Nur linux-3.12.38/arch/x86/crypto/ghash-clmulni-intel_glue.c linux-rpi/arch/x86/crypto/ghash-clmulni-intel_glue.c
  11215. --- linux-3.12.38/arch/x86/crypto/ghash-clmulni-intel_glue.c 2015-02-16 16:15:42.000000000 +0100
  11216. +++ linux-rpi/arch/x86/crypto/ghash-clmulni-intel_glue.c 2015-03-10 17:26:50.034216695 +0100
  11217. @@ -341,4 +341,4 @@
  11218. MODULE_LICENSE("GPL");
  11219. MODULE_DESCRIPTION("GHASH Message Digest Algorithm, "
  11220. "acclerated by PCLMULQDQ-NI");
  11221. -MODULE_ALIAS_CRYPTO("ghash");
  11222. +MODULE_ALIAS("ghash");
  11223. diff -Nur linux-3.12.38/arch/x86/crypto/salsa20_glue.c linux-rpi/arch/x86/crypto/salsa20_glue.c
  11224. --- linux-3.12.38/arch/x86/crypto/salsa20_glue.c 2015-02-16 16:15:42.000000000 +0100
  11225. +++ linux-rpi/arch/x86/crypto/salsa20_glue.c 2015-03-10 17:26:50.034216695 +0100
  11226. @@ -119,5 +119,5 @@
  11227. MODULE_LICENSE("GPL");
  11228. MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm (optimized assembly version)");
  11229. -MODULE_ALIAS_CRYPTO("salsa20");
  11230. -MODULE_ALIAS_CRYPTO("salsa20-asm");
  11231. +MODULE_ALIAS("salsa20");
  11232. +MODULE_ALIAS("salsa20-asm");
  11233. diff -Nur linux-3.12.38/arch/x86/crypto/serpent_avx2_glue.c linux-rpi/arch/x86/crypto/serpent_avx2_glue.c
  11234. --- linux-3.12.38/arch/x86/crypto/serpent_avx2_glue.c 2015-02-16 16:15:42.000000000 +0100
  11235. +++ linux-rpi/arch/x86/crypto/serpent_avx2_glue.c 2015-03-10 17:26:50.034216695 +0100
  11236. @@ -558,5 +558,5 @@
  11237. MODULE_LICENSE("GPL");
  11238. MODULE_DESCRIPTION("Serpent Cipher Algorithm, AVX2 optimized");
  11239. -MODULE_ALIAS_CRYPTO("serpent");
  11240. -MODULE_ALIAS_CRYPTO("serpent-asm");
  11241. +MODULE_ALIAS("serpent");
  11242. +MODULE_ALIAS("serpent-asm");
  11243. diff -Nur linux-3.12.38/arch/x86/crypto/serpent_avx_glue.c linux-rpi/arch/x86/crypto/serpent_avx_glue.c
  11244. --- linux-3.12.38/arch/x86/crypto/serpent_avx_glue.c 2015-02-16 16:15:42.000000000 +0100
  11245. +++ linux-rpi/arch/x86/crypto/serpent_avx_glue.c 2015-03-10 17:26:50.034216695 +0100
  11246. @@ -617,4 +617,4 @@
  11247. MODULE_DESCRIPTION("Serpent Cipher Algorithm, AVX optimized");
  11248. MODULE_LICENSE("GPL");
  11249. -MODULE_ALIAS_CRYPTO("serpent");
  11250. +MODULE_ALIAS("serpent");
  11251. diff -Nur linux-3.12.38/arch/x86/crypto/serpent_sse2_glue.c linux-rpi/arch/x86/crypto/serpent_sse2_glue.c
  11252. --- linux-3.12.38/arch/x86/crypto/serpent_sse2_glue.c 2015-02-16 16:15:42.000000000 +0100
  11253. +++ linux-rpi/arch/x86/crypto/serpent_sse2_glue.c 2015-03-10 17:26:50.034216695 +0100
  11254. @@ -618,4 +618,4 @@
  11255. MODULE_DESCRIPTION("Serpent Cipher Algorithm, SSE2 optimized");
  11256. MODULE_LICENSE("GPL");
  11257. -MODULE_ALIAS_CRYPTO("serpent");
  11258. +MODULE_ALIAS("serpent");
  11259. diff -Nur linux-3.12.38/arch/x86/crypto/sha1_ssse3_glue.c linux-rpi/arch/x86/crypto/sha1_ssse3_glue.c
  11260. --- linux-3.12.38/arch/x86/crypto/sha1_ssse3_glue.c 2015-02-16 16:15:42.000000000 +0100
  11261. +++ linux-rpi/arch/x86/crypto/sha1_ssse3_glue.c 2015-03-10 17:26:50.034216695 +0100
  11262. @@ -237,4 +237,4 @@
  11263. MODULE_LICENSE("GPL");
  11264. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm, Supplemental SSE3 accelerated");
  11265. -MODULE_ALIAS_CRYPTO("sha1");
  11266. +MODULE_ALIAS("sha1");
  11267. diff -Nur linux-3.12.38/arch/x86/crypto/sha256_ssse3_glue.c linux-rpi/arch/x86/crypto/sha256_ssse3_glue.c
  11268. --- linux-3.12.38/arch/x86/crypto/sha256_ssse3_glue.c 2015-02-16 16:15:42.000000000 +0100
  11269. +++ linux-rpi/arch/x86/crypto/sha256_ssse3_glue.c 2015-03-10 17:26:50.034216695 +0100
  11270. @@ -318,5 +318,5 @@
  11271. MODULE_LICENSE("GPL");
  11272. MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm, Supplemental SSE3 accelerated");
  11273. -MODULE_ALIAS_CRYPTO("sha256");
  11274. -MODULE_ALIAS_CRYPTO("sha224");
  11275. +MODULE_ALIAS("sha256");
  11276. +MODULE_ALIAS("sha384");
  11277. diff -Nur linux-3.12.38/arch/x86/crypto/sha512_ssse3_glue.c linux-rpi/arch/x86/crypto/sha512_ssse3_glue.c
  11278. --- linux-3.12.38/arch/x86/crypto/sha512_ssse3_glue.c 2015-02-16 16:15:42.000000000 +0100
  11279. +++ linux-rpi/arch/x86/crypto/sha512_ssse3_glue.c 2015-03-10 17:26:50.034216695 +0100
  11280. @@ -326,5 +326,5 @@
  11281. MODULE_LICENSE("GPL");
  11282. MODULE_DESCRIPTION("SHA512 Secure Hash Algorithm, Supplemental SSE3 accelerated");
  11283. -MODULE_ALIAS_CRYPTO("sha512");
  11284. -MODULE_ALIAS_CRYPTO("sha384");
  11285. +MODULE_ALIAS("sha512");
  11286. +MODULE_ALIAS("sha384");
  11287. diff -Nur linux-3.12.38/arch/x86/crypto/twofish_avx_glue.c linux-rpi/arch/x86/crypto/twofish_avx_glue.c
  11288. --- linux-3.12.38/arch/x86/crypto/twofish_avx_glue.c 2015-02-16 16:15:42.000000000 +0100
  11289. +++ linux-rpi/arch/x86/crypto/twofish_avx_glue.c 2015-03-10 17:26:50.034216695 +0100
  11290. @@ -579,4 +579,4 @@
  11291. MODULE_DESCRIPTION("Twofish Cipher Algorithm, AVX optimized");
  11292. MODULE_LICENSE("GPL");
  11293. -MODULE_ALIAS_CRYPTO("twofish");
  11294. +MODULE_ALIAS("twofish");
  11295. diff -Nur linux-3.12.38/arch/x86/crypto/twofish_glue_3way.c linux-rpi/arch/x86/crypto/twofish_glue_3way.c
  11296. --- linux-3.12.38/arch/x86/crypto/twofish_glue_3way.c 2015-02-16 16:15:42.000000000 +0100
  11297. +++ linux-rpi/arch/x86/crypto/twofish_glue_3way.c 2015-03-10 17:26:50.034216695 +0100
  11298. @@ -495,5 +495,5 @@
  11299. MODULE_LICENSE("GPL");
  11300. MODULE_DESCRIPTION("Twofish Cipher Algorithm, 3-way parallel asm optimized");
  11301. -MODULE_ALIAS_CRYPTO("twofish");
  11302. -MODULE_ALIAS_CRYPTO("twofish-asm");
  11303. +MODULE_ALIAS("twofish");
  11304. +MODULE_ALIAS("twofish-asm");
  11305. diff -Nur linux-3.12.38/arch/x86/crypto/twofish_glue.c linux-rpi/arch/x86/crypto/twofish_glue.c
  11306. --- linux-3.12.38/arch/x86/crypto/twofish_glue.c 2015-02-16 16:15:42.000000000 +0100
  11307. +++ linux-rpi/arch/x86/crypto/twofish_glue.c 2015-03-10 17:26:50.034216695 +0100
  11308. @@ -96,5 +96,5 @@
  11309. MODULE_LICENSE("GPL");
  11310. MODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized");
  11311. -MODULE_ALIAS_CRYPTO("twofish");
  11312. -MODULE_ALIAS_CRYPTO("twofish-asm");
  11313. +MODULE_ALIAS("twofish");
  11314. +MODULE_ALIAS("twofish-asm");
  11315. diff -Nur linux-3.12.38/arch/x86/include/asm/desc.h linux-rpi/arch/x86/include/asm/desc.h
  11316. --- linux-3.12.38/arch/x86/include/asm/desc.h 2015-02-16 16:15:42.000000000 +0100
  11317. +++ linux-rpi/arch/x86/include/asm/desc.h 2015-03-10 17:26:50.038216695 +0100
  11318. @@ -251,8 +251,7 @@
  11319. gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
  11320. }
  11321. -/* This intentionally ignores lm, since 32-bit apps don't have that field. */
  11322. -#define LDT_empty(info) \
  11323. +#define _LDT_empty(info) \
  11324. ((info)->base_addr == 0 && \
  11325. (info)->limit == 0 && \
  11326. (info)->contents == 0 && \
  11327. @@ -262,18 +261,11 @@
  11328. (info)->seg_not_present == 1 && \
  11329. (info)->useable == 0)
  11330. -/* Lots of programs expect an all-zero user_desc to mean "no segment at all". */
  11331. -static inline bool LDT_zero(const struct user_desc *info)
  11332. -{
  11333. - return (info->base_addr == 0 &&
  11334. - info->limit == 0 &&
  11335. - info->contents == 0 &&
  11336. - info->read_exec_only == 0 &&
  11337. - info->seg_32bit == 0 &&
  11338. - info->limit_in_pages == 0 &&
  11339. - info->seg_not_present == 0 &&
  11340. - info->useable == 0);
  11341. -}
  11342. +#ifdef CONFIG_X86_64
  11343. +#define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
  11344. +#else
  11345. +#define LDT_empty(info) (_LDT_empty(info))
  11346. +#endif
  11347. static inline void clear_LDT(void)
  11348. {
  11349. diff -Nur linux-3.12.38/arch/x86/include/asm/vsyscall.h linux-rpi/arch/x86/include/asm/vsyscall.h
  11350. --- linux-3.12.38/arch/x86/include/asm/vsyscall.h 2015-02-16 16:15:42.000000000 +0100
  11351. +++ linux-rpi/arch/x86/include/asm/vsyscall.h 2015-03-10 17:26:50.042216695 +0100
  11352. @@ -34,7 +34,7 @@
  11353. native_read_tscp(&p);
  11354. } else {
  11355. /* Load per CPU data from GDT */
  11356. - asm volatile ("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
  11357. + asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
  11358. }
  11359. return p;
  11360. diff -Nur linux-3.12.38/arch/x86/Kconfig linux-rpi/arch/x86/Kconfig
  11361. --- linux-3.12.38/arch/x86/Kconfig 2015-02-16 16:15:42.000000000 +0100
  11362. +++ linux-rpi/arch/x86/Kconfig 2015-03-10 17:26:50.030216695 +0100
  11363. @@ -861,7 +861,7 @@
  11364. config X86_UP_APIC
  11365. bool "Local APIC support on uniprocessors"
  11366. - depends on X86_32 && !SMP && !X86_32_NON_STANDARD
  11367. + depends on X86_32 && !SMP && !X86_32_NON_STANDARD && !PCI_MSI
  11368. ---help---
  11369. A local APIC (Advanced Programmable Interrupt Controller) is an
  11370. integrated interrupt controller in the CPU. If you have a single-CPU
  11371. @@ -872,10 +872,6 @@
  11372. performance counters), and the NMI watchdog which detects hard
  11373. lockups.
  11374. -config X86_UP_APIC_MSI
  11375. - def_bool y
  11376. - select X86_UP_APIC if X86_32 && !SMP && !X86_32_NON_STANDARD && PCI_MSI
  11377. -
  11378. config X86_UP_IOAPIC
  11379. bool "IO-APIC support on uniprocessors"
  11380. depends on X86_UP_APIC
  11381. diff -Nur linux-3.12.38/arch/x86/kernel/acpi/cstate.c linux-rpi/arch/x86/kernel/acpi/cstate.c
  11382. --- linux-3.12.38/arch/x86/kernel/acpi/cstate.c 2015-02-16 16:15:42.000000000 +0100
  11383. +++ linux-rpi/arch/x86/kernel/acpi/cstate.c 2015-03-10 17:26:50.046216695 +0100
  11384. @@ -87,9 +87,7 @@
  11385. num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
  11386. retval = 0;
  11387. - /* If the HW does not support any sub-states in this C-state */
  11388. - if (num_cstate_subtype == 0) {
  11389. - pr_warn(FW_BUG "ACPI MWAIT C-state 0x%x not supported by HW (0x%x)\n", cx->address, edx_part);
  11390. + if (num_cstate_subtype < (cx->address & MWAIT_SUBSTATE_MASK)) {
  11391. retval = -1;
  11392. goto out;
  11393. }
  11394. diff -Nur linux-3.12.38/arch/x86/kernel/cpu/mshyperv.c linux-rpi/arch/x86/kernel/cpu/mshyperv.c
  11395. --- linux-3.12.38/arch/x86/kernel/cpu/mshyperv.c 2015-02-16 16:15:42.000000000 +0100
  11396. +++ linux-rpi/arch/x86/kernel/cpu/mshyperv.c 2015-03-10 17:26:50.050216695 +0100
  11397. @@ -63,7 +63,6 @@
  11398. .rating = 400, /* use this when running on Hyperv*/
  11399. .read = read_hv_clock,
  11400. .mask = CLOCKSOURCE_MASK(64),
  11401. - .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  11402. };
  11403. static void __init ms_hyperv_init_platform(void)
  11404. diff -Nur linux-3.12.38/arch/x86/kernel/cpu/perf_event_intel_uncore.c linux-rpi/arch/x86/kernel/cpu/perf_event_intel_uncore.c
  11405. --- linux-3.12.38/arch/x86/kernel/cpu/perf_event_intel_uncore.c 2015-02-16 16:15:42.000000000 +0100
  11406. +++ linux-rpi/arch/x86/kernel/cpu/perf_event_intel_uncore.c 2015-03-10 17:26:50.054216695 +0100
  11407. @@ -2764,17 +2764,6 @@
  11408. return uncore_pmu_to_box(uncore_event_to_pmu(event), smp_processor_id());
  11409. }
  11410. -/*
  11411. - * Using uncore_pmu_event_init pmu event_init callback
  11412. - * as a detection point for uncore events.
  11413. - */
  11414. -static int uncore_pmu_event_init(struct perf_event *event);
  11415. -
  11416. -static bool is_uncore_event(struct perf_event *event)
  11417. -{
  11418. - return event->pmu->event_init == uncore_pmu_event_init;
  11419. -}
  11420. -
  11421. static int
  11422. uncore_collect_events(struct intel_uncore_box *box, struct perf_event *leader, bool dogrp)
  11423. {
  11424. @@ -2789,18 +2778,13 @@
  11425. return -EINVAL;
  11426. n = box->n_events;
  11427. -
  11428. - if (is_uncore_event(leader)) {
  11429. - box->event_list[n] = leader;
  11430. - n++;
  11431. - }
  11432. -
  11433. + box->event_list[n] = leader;
  11434. + n++;
  11435. if (!dogrp)
  11436. return n;
  11437. list_for_each_entry(event, &leader->sibling_list, group_entry) {
  11438. - if (!is_uncore_event(event) ||
  11439. - event->state <= PERF_EVENT_STATE_OFF)
  11440. + if (event->state <= PERF_EVENT_STATE_OFF)
  11441. continue;
  11442. if (n >= max_count)
  11443. diff -Nur linux-3.12.38/arch/x86/kernel/early-quirks.c linux-rpi/arch/x86/kernel/early-quirks.c
  11444. --- linux-3.12.38/arch/x86/kernel/early-quirks.c 2015-02-16 16:15:42.000000000 +0100
  11445. +++ linux-rpi/arch/x86/kernel/early-quirks.c 2015-03-10 17:26:50.054216695 +0100
  11446. @@ -317,8 +317,8 @@
  11447. INTEL_I915GM_IDS(gen3_stolen_size),
  11448. INTEL_I945G_IDS(gen3_stolen_size),
  11449. INTEL_I945GM_IDS(gen3_stolen_size),
  11450. - INTEL_VLV_M_IDS(gen6_stolen_size),
  11451. - INTEL_VLV_D_IDS(gen6_stolen_size),
  11452. + INTEL_VLV_M_IDS(gen3_stolen_size),
  11453. + INTEL_VLV_D_IDS(gen3_stolen_size),
  11454. INTEL_PINEVIEW_IDS(gen3_stolen_size),
  11455. INTEL_I965G_IDS(gen3_stolen_size),
  11456. INTEL_G33_IDS(gen3_stolen_size),
  11457. diff -Nur linux-3.12.38/arch/x86/kernel/kprobes/core.c linux-rpi/arch/x86/kernel/kprobes/core.c
  11458. --- linux-3.12.38/arch/x86/kernel/kprobes/core.c 2015-02-16 16:15:42.000000000 +0100
  11459. +++ linux-rpi/arch/x86/kernel/kprobes/core.c 2015-03-10 17:26:50.054216695 +0100
  11460. @@ -1017,15 +1017,6 @@
  11461. regs->flags &= ~X86_EFLAGS_IF;
  11462. trace_hardirqs_off();
  11463. regs->ip = (unsigned long)(jp->entry);
  11464. -
  11465. - /*
  11466. - * jprobes use jprobe_return() which skips the normal return
  11467. - * path of the function, and this messes up the accounting of the
  11468. - * function graph tracer to get messed up.
  11469. - *
  11470. - * Pause function graph tracing while performing the jprobe function.
  11471. - */
  11472. - pause_graph_tracing();
  11473. return 1;
  11474. }
  11475. @@ -1051,25 +1042,24 @@
  11476. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  11477. u8 *addr = (u8 *) (regs->ip - 1);
  11478. struct jprobe *jp = container_of(p, struct jprobe, kp);
  11479. - void *saved_sp = kcb->jprobe_saved_sp;
  11480. if ((addr > (u8 *) jprobe_return) &&
  11481. (addr < (u8 *) jprobe_return_end)) {
  11482. - if (stack_addr(regs) != saved_sp) {
  11483. + if (stack_addr(regs) != kcb->jprobe_saved_sp) {
  11484. struct pt_regs *saved_regs = &kcb->jprobe_saved_regs;
  11485. printk(KERN_ERR
  11486. "current sp %p does not match saved sp %p\n",
  11487. - stack_addr(regs), saved_sp);
  11488. + stack_addr(regs), kcb->jprobe_saved_sp);
  11489. printk(KERN_ERR "Saved registers for jprobe %p\n", jp);
  11490. show_regs(saved_regs);
  11491. printk(KERN_ERR "Current registers\n");
  11492. show_regs(regs);
  11493. BUG();
  11494. }
  11495. - /* It's OK to start function graph tracing again */
  11496. - unpause_graph_tracing();
  11497. *regs = kcb->jprobe_saved_regs;
  11498. - memcpy(saved_sp, kcb->jprobes_stack, MIN_STACK_SIZE(saved_sp));
  11499. + memcpy((kprobe_opcode_t *)(kcb->jprobe_saved_sp),
  11500. + kcb->jprobes_stack,
  11501. + MIN_STACK_SIZE(kcb->jprobe_saved_sp));
  11502. preempt_enable_no_resched();
  11503. return 1;
  11504. }
  11505. diff -Nur linux-3.12.38/arch/x86/kernel/tls.c linux-rpi/arch/x86/kernel/tls.c
  11506. --- linux-3.12.38/arch/x86/kernel/tls.c 2015-02-16 16:15:42.000000000 +0100
  11507. +++ linux-rpi/arch/x86/kernel/tls.c 2015-03-10 17:26:50.058216695 +0100
  11508. @@ -29,28 +29,7 @@
  11509. static bool tls_desc_okay(const struct user_desc *info)
  11510. {
  11511. - /*
  11512. - * For historical reasons (i.e. no one ever documented how any
  11513. - * of the segmentation APIs work), user programs can and do
  11514. - * assume that a struct user_desc that's all zeros except for
  11515. - * entry_number means "no segment at all". This never actually
  11516. - * worked. In fact, up to Linux 3.19, a struct user_desc like
  11517. - * this would create a 16-bit read-write segment with base and
  11518. - * limit both equal to zero.
  11519. - *
  11520. - * That was close enough to "no segment at all" until we
  11521. - * hardened this function to disallow 16-bit TLS segments. Fix
  11522. - * it up by interpreting these zeroed segments the way that they
  11523. - * were almost certainly intended to be interpreted.
  11524. - *
  11525. - * The correct way to ask for "no segment at all" is to specify
  11526. - * a user_desc that satisfies LDT_empty. To keep everything
  11527. - * working, we accept both.
  11528. - *
  11529. - * Note that there's a similar kludge in modify_ldt -- look at
  11530. - * the distinction between modes 1 and 0x11.
  11531. - */
  11532. - if (LDT_empty(info) || LDT_zero(info))
  11533. + if (LDT_empty(info))
  11534. return true;
  11535. /*
  11536. @@ -92,7 +71,7 @@
  11537. cpu = get_cpu();
  11538. while (n-- > 0) {
  11539. - if (LDT_empty(info) || LDT_zero(info))
  11540. + if (LDT_empty(info))
  11541. desc->a = desc->b = 0;
  11542. else
  11543. fill_ldt(desc, info);
  11544. diff -Nur linux-3.12.38/arch/x86/kernel/traps.c linux-rpi/arch/x86/kernel/traps.c
  11545. --- linux-3.12.38/arch/x86/kernel/traps.c 2015-02-16 16:15:42.000000000 +0100
  11546. +++ linux-rpi/arch/x86/kernel/traps.c 2015-03-10 17:26:50.058216695 +0100
  11547. @@ -369,7 +369,7 @@
  11548. * for scheduling or signal handling. The actual stack switch is done in
  11549. * entry.S
  11550. */
  11551. -asmlinkage notrace __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
  11552. +asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
  11553. {
  11554. struct pt_regs *regs = eregs;
  11555. /* Did already sync */
  11556. @@ -394,7 +394,7 @@
  11557. struct pt_regs regs;
  11558. };
  11559. -asmlinkage __visible notrace __kprobes
  11560. +asmlinkage __visible
  11561. struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
  11562. {
  11563. /*
  11564. diff -Nur linux-3.12.38/arch/x86/kernel/tsc.c linux-rpi/arch/x86/kernel/tsc.c
  11565. --- linux-3.12.38/arch/x86/kernel/tsc.c 2015-02-16 16:15:42.000000000 +0100
  11566. +++ linux-rpi/arch/x86/kernel/tsc.c 2015-03-10 17:26:50.058216695 +0100
  11567. @@ -386,7 +386,7 @@
  11568. goto success;
  11569. }
  11570. }
  11571. - pr_info("Fast TSC calibration failed\n");
  11572. + pr_err("Fast TSC calibration failed\n");
  11573. return 0;
  11574. success:
  11575. diff -Nur linux-3.12.38/arch/x86/kvm/cpuid.c linux-rpi/arch/x86/kvm/cpuid.c
  11576. --- linux-3.12.38/arch/x86/kvm/cpuid.c 2015-02-16 16:15:42.000000000 +0100
  11577. +++ linux-rpi/arch/x86/kvm/cpuid.c 2015-03-10 17:26:50.062216695 +0100
  11578. @@ -23,14 +23,14 @@
  11579. #include "mmu.h"
  11580. #include "trace.h"
  11581. -int kvm_update_cpuid(struct kvm_vcpu *vcpu)
  11582. +void kvm_update_cpuid(struct kvm_vcpu *vcpu)
  11583. {
  11584. struct kvm_cpuid_entry2 *best;
  11585. struct kvm_lapic *apic = vcpu->arch.apic;
  11586. best = kvm_find_cpuid_entry(vcpu, 1, 0);
  11587. if (!best)
  11588. - return 0;
  11589. + return;
  11590. /* Update OSXSAVE bit */
  11591. if (cpu_has_xsave && best->function == 0x1) {
  11592. @@ -46,15 +46,7 @@
  11593. apic->lapic_timer.timer_mode_mask = 1 << 17;
  11594. }
  11595. - /* The existing code assumes virtual address is 48-bit in the canonical
  11596. - * address checks; exit if it is ever changed */
  11597. - best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
  11598. - if (best && ((best->eax & 0xff00) >> 8) != 48 &&
  11599. - ((best->eax & 0xff00) >> 8) != 0)
  11600. - return -EINVAL;
  11601. -
  11602. kvm_pmu_cpuid_update(vcpu);
  11603. - return 0;
  11604. }
  11605. static int is_efer_nx(void)
  11606. @@ -117,9 +109,10 @@
  11607. }
  11608. vcpu->arch.cpuid_nent = cpuid->nent;
  11609. cpuid_fix_nx_cap(vcpu);
  11610. + r = 0;
  11611. kvm_apic_set_version(vcpu);
  11612. kvm_x86_ops->cpuid_update(vcpu);
  11613. - r = kvm_update_cpuid(vcpu);
  11614. + kvm_update_cpuid(vcpu);
  11615. out_free:
  11616. vfree(cpuid_entries);
  11617. @@ -143,7 +136,9 @@
  11618. vcpu->arch.cpuid_nent = cpuid->nent;
  11619. kvm_apic_set_version(vcpu);
  11620. kvm_x86_ops->cpuid_update(vcpu);
  11621. - r = kvm_update_cpuid(vcpu);
  11622. + kvm_update_cpuid(vcpu);
  11623. + return 0;
  11624. +
  11625. out:
  11626. return r;
  11627. }
  11628. diff -Nur linux-3.12.38/arch/x86/kvm/cpuid.h linux-rpi/arch/x86/kvm/cpuid.h
  11629. --- linux-3.12.38/arch/x86/kvm/cpuid.h 2015-02-16 16:15:42.000000000 +0100
  11630. +++ linux-rpi/arch/x86/kvm/cpuid.h 2015-03-10 17:26:50.062216695 +0100
  11631. @@ -3,7 +3,7 @@
  11632. #include "x86.h"
  11633. -int kvm_update_cpuid(struct kvm_vcpu *vcpu);
  11634. +void kvm_update_cpuid(struct kvm_vcpu *vcpu);
  11635. struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
  11636. u32 function, u32 index);
  11637. int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
  11638. diff -Nur linux-3.12.38/arch/x86/kvm/emulate.c linux-rpi/arch/x86/kvm/emulate.c
  11639. --- linux-3.12.38/arch/x86/kvm/emulate.c 2015-02-16 16:15:42.000000000 +0100
  11640. +++ linux-rpi/arch/x86/kvm/emulate.c 2015-03-10 17:26:50.062216695 +0100
  11641. @@ -161,7 +161,6 @@
  11642. #define Fastop ((u64)1 << 44) /* Use opcode::u.fastop */
  11643. #define NoWrite ((u64)1 << 45) /* No writeback */
  11644. #define SrcWrite ((u64)1 << 46) /* Write back src operand */
  11645. -#define NearBranch ((u64)1 << 52) /* Near branches */
  11646. #define DstXacc (DstAccLo | SrcAccHi | SrcWrite)
  11647. @@ -1444,8 +1443,7 @@
  11648. /* Does not support long mode */
  11649. static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
  11650. - u16 selector, int seg,
  11651. - struct desc_struct *desc)
  11652. + u16 selector, int seg)
  11653. {
  11654. struct desc_struct seg_desc, old_desc;
  11655. u8 dpl, rpl, cpl;
  11656. @@ -1533,15 +1531,6 @@
  11657. if (rpl > cpl || dpl != cpl)
  11658. goto exception;
  11659. }
  11660. - /* in long-mode d/b must be clear if l is set */
  11661. - if (seg_desc.d && seg_desc.l) {
  11662. - u64 efer = 0;
  11663. -
  11664. - ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
  11665. - if (efer & EFER_LMA)
  11666. - goto exception;
  11667. - }
  11668. -
  11669. /* CS(RPL) <- CPL */
  11670. selector = (selector & 0xfffc) | cpl;
  11671. break;
  11672. @@ -1581,8 +1570,6 @@
  11673. }
  11674. load:
  11675. ctxt->ops->set_segment(ctxt, selector, &seg_desc, 0, seg);
  11676. - if (desc)
  11677. - *desc = seg_desc;
  11678. return X86EMUL_CONTINUE;
  11679. exception:
  11680. emulate_exception(ctxt, err_vec, err_code, true);
  11681. @@ -1789,7 +1776,7 @@
  11682. if (rc != X86EMUL_CONTINUE)
  11683. return rc;
  11684. - rc = load_segment_descriptor(ctxt, (u16)selector, seg, NULL);
  11685. + rc = load_segment_descriptor(ctxt, (u16)selector, seg);
  11686. return rc;
  11687. }
  11688. @@ -1878,7 +1865,7 @@
  11689. if (rc != X86EMUL_CONTINUE)
  11690. return rc;
  11691. - rc = load_segment_descriptor(ctxt, cs, VCPU_SREG_CS, NULL);
  11692. + rc = load_segment_descriptor(ctxt, cs, VCPU_SREG_CS);
  11693. if (rc != X86EMUL_CONTINUE)
  11694. return rc;
  11695. @@ -1944,7 +1931,7 @@
  11696. if (rc != X86EMUL_CONTINUE)
  11697. return rc;
  11698. - rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS, NULL);
  11699. + rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
  11700. if (rc != X86EMUL_CONTINUE)
  11701. return rc;
  11702. @@ -1983,47 +1970,44 @@
  11703. static int em_jmp_far(struct x86_emulate_ctxt *ctxt)
  11704. {
  11705. int rc;
  11706. - unsigned short sel, old_sel;
  11707. - struct desc_struct old_desc, new_desc;
  11708. - const struct x86_emulate_ops *ops = ctxt->ops;
  11709. -
  11710. - /* Assignment of RIP may only fail in 64-bit mode */
  11711. - if (ctxt->mode == X86EMUL_MODE_PROT64)
  11712. - ops->get_segment(ctxt, &old_sel, &old_desc, NULL,
  11713. - VCPU_SREG_CS);
  11714. + unsigned short sel;
  11715. memcpy(&sel, ctxt->src.valptr + ctxt->op_bytes, 2);
  11716. - rc = load_segment_descriptor(ctxt, sel, VCPU_SREG_CS, &new_desc);
  11717. + rc = load_segment_descriptor(ctxt, sel, VCPU_SREG_CS);
  11718. if (rc != X86EMUL_CONTINUE)
  11719. return rc;
  11720. - rc = assign_eip_far(ctxt, ctxt->src.val, new_desc.l);
  11721. - if (rc != X86EMUL_CONTINUE) {
  11722. - WARN_ON(!ctxt->mode != X86EMUL_MODE_PROT64);
  11723. - /* assigning eip failed; restore the old cs */
  11724. - ops->set_segment(ctxt, old_sel, &old_desc, 0, VCPU_SREG_CS);
  11725. - return rc;
  11726. - }
  11727. - return rc;
  11728. -}
  11729. -
  11730. -static int em_jmp_abs(struct x86_emulate_ctxt *ctxt)
  11731. -{
  11732. - return assign_eip_near(ctxt, ctxt->src.val);
  11733. + ctxt->_eip = 0;
  11734. + memcpy(&ctxt->_eip, ctxt->src.valptr, ctxt->op_bytes);
  11735. + return X86EMUL_CONTINUE;
  11736. }
  11737. -static int em_call_near_abs(struct x86_emulate_ctxt *ctxt)
  11738. +static int em_grp45(struct x86_emulate_ctxt *ctxt)
  11739. {
  11740. - int rc;
  11741. - long int old_eip;
  11742. + int rc = X86EMUL_CONTINUE;
  11743. - old_eip = ctxt->_eip;
  11744. - rc = assign_eip_near(ctxt, ctxt->src.val);
  11745. - if (rc != X86EMUL_CONTINUE)
  11746. - return rc;
  11747. - ctxt->src.val = old_eip;
  11748. - rc = em_push(ctxt);
  11749. + switch (ctxt->modrm_reg) {
  11750. + case 2: /* call near abs */ {
  11751. + long int old_eip;
  11752. + old_eip = ctxt->_eip;
  11753. + rc = assign_eip_near(ctxt, ctxt->src.val);
  11754. + if (rc != X86EMUL_CONTINUE)
  11755. + break;
  11756. + ctxt->src.val = old_eip;
  11757. + rc = em_push(ctxt);
  11758. + break;
  11759. + }
  11760. + case 4: /* jmp abs */
  11761. + rc = assign_eip_near(ctxt, ctxt->src.val);
  11762. + break;
  11763. + case 5: /* jmp far */
  11764. + rc = em_jmp_far(ctxt);
  11765. + break;
  11766. + case 6: /* push */
  11767. + rc = em_push(ctxt);
  11768. + break;
  11769. + }
  11770. return rc;
  11771. }
  11772. @@ -2060,33 +2044,21 @@
  11773. static int em_ret_far(struct x86_emulate_ctxt *ctxt)
  11774. {
  11775. int rc;
  11776. - unsigned long eip, cs;
  11777. - u16 old_cs;
  11778. + unsigned long cs;
  11779. int cpl = ctxt->ops->cpl(ctxt);
  11780. - struct desc_struct old_desc, new_desc;
  11781. - const struct x86_emulate_ops *ops = ctxt->ops;
  11782. - if (ctxt->mode == X86EMUL_MODE_PROT64)
  11783. - ops->get_segment(ctxt, &old_cs, &old_desc, NULL,
  11784. - VCPU_SREG_CS);
  11785. -
  11786. - rc = emulate_pop(ctxt, &eip, ctxt->op_bytes);
  11787. + rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
  11788. if (rc != X86EMUL_CONTINUE)
  11789. return rc;
  11790. + if (ctxt->op_bytes == 4)
  11791. + ctxt->_eip = (u32)ctxt->_eip;
  11792. rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
  11793. if (rc != X86EMUL_CONTINUE)
  11794. return rc;
  11795. /* Outer-privilege level return is not implemented */
  11796. if (ctxt->mode >= X86EMUL_MODE_PROT16 && (cs & 3) > cpl)
  11797. return X86EMUL_UNHANDLEABLE;
  11798. - rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS, &new_desc);
  11799. - if (rc != X86EMUL_CONTINUE)
  11800. - return rc;
  11801. - rc = assign_eip_far(ctxt, eip, new_desc.l);
  11802. - if (rc != X86EMUL_CONTINUE) {
  11803. - WARN_ON(!ctxt->mode != X86EMUL_MODE_PROT64);
  11804. - ops->set_segment(ctxt, old_cs, &old_desc, 0, VCPU_SREG_CS);
  11805. - }
  11806. + rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
  11807. return rc;
  11808. }
  11809. @@ -2127,7 +2099,7 @@
  11810. memcpy(&sel, ctxt->src.valptr + ctxt->op_bytes, 2);
  11811. - rc = load_segment_descriptor(ctxt, sel, seg, NULL);
  11812. + rc = load_segment_descriptor(ctxt, sel, seg);
  11813. if (rc != X86EMUL_CONTINUE)
  11814. return rc;
  11815. @@ -2372,8 +2344,6 @@
  11816. if ((msr_data & 0xfffc) == 0x0)
  11817. return emulate_gp(ctxt, 0);
  11818. ss_sel = (u16)(msr_data + 24);
  11819. - rcx = (u32)rcx;
  11820. - rdx = (u32)rdx;
  11821. break;
  11822. case X86EMUL_MODE_PROT64:
  11823. cs_sel = (u16)(msr_data + 32);
  11824. @@ -2509,19 +2479,19 @@
  11825. * Now load segment descriptors. If fault happens at this stage
  11826. * it is handled in a context of new task
  11827. */
  11828. - ret = load_segment_descriptor(ctxt, tss->ldt, VCPU_SREG_LDTR, NULL);
  11829. + ret = load_segment_descriptor(ctxt, tss->ldt, VCPU_SREG_LDTR);
  11830. if (ret != X86EMUL_CONTINUE)
  11831. return ret;
  11832. - ret = load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, NULL);
  11833. + ret = load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES);
  11834. if (ret != X86EMUL_CONTINUE)
  11835. return ret;
  11836. - ret = load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, NULL);
  11837. + ret = load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS);
  11838. if (ret != X86EMUL_CONTINUE)
  11839. return ret;
  11840. - ret = load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, NULL);
  11841. + ret = load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS);
  11842. if (ret != X86EMUL_CONTINUE)
  11843. return ret;
  11844. - ret = load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, NULL);
  11845. + ret = load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS);
  11846. if (ret != X86EMUL_CONTINUE)
  11847. return ret;
  11848. @@ -2650,26 +2620,25 @@
  11849. * Now load segment descriptors. If fault happenes at this stage
  11850. * it is handled in a context of new task
  11851. */
  11852. - ret = load_segment_descriptor(ctxt, tss->ldt_selector, VCPU_SREG_LDTR,
  11853. - NULL);
  11854. + ret = load_segment_descriptor(ctxt, tss->ldt_selector, VCPU_SREG_LDTR);
  11855. if (ret != X86EMUL_CONTINUE)
  11856. return ret;
  11857. - ret = load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES, NULL);
  11858. + ret = load_segment_descriptor(ctxt, tss->es, VCPU_SREG_ES);
  11859. if (ret != X86EMUL_CONTINUE)
  11860. return ret;
  11861. - ret = load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS, NULL);
  11862. + ret = load_segment_descriptor(ctxt, tss->cs, VCPU_SREG_CS);
  11863. if (ret != X86EMUL_CONTINUE)
  11864. return ret;
  11865. - ret = load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS, NULL);
  11866. + ret = load_segment_descriptor(ctxt, tss->ss, VCPU_SREG_SS);
  11867. if (ret != X86EMUL_CONTINUE)
  11868. return ret;
  11869. - ret = load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS, NULL);
  11870. + ret = load_segment_descriptor(ctxt, tss->ds, VCPU_SREG_DS);
  11871. if (ret != X86EMUL_CONTINUE)
  11872. return ret;
  11873. - ret = load_segment_descriptor(ctxt, tss->fs, VCPU_SREG_FS, NULL);
  11874. + ret = load_segment_descriptor(ctxt, tss->fs, VCPU_SREG_FS);
  11875. if (ret != X86EMUL_CONTINUE)
  11876. return ret;
  11877. - ret = load_segment_descriptor(ctxt, tss->gs, VCPU_SREG_GS, NULL);
  11878. + ret = load_segment_descriptor(ctxt, tss->gs, VCPU_SREG_GS);
  11879. if (ret != X86EMUL_CONTINUE)
  11880. return ret;
  11881. @@ -2949,37 +2918,24 @@
  11882. u16 sel, old_cs;
  11883. ulong old_eip;
  11884. int rc;
  11885. - struct desc_struct old_desc, new_desc;
  11886. - const struct x86_emulate_ops *ops = ctxt->ops;
  11887. + old_cs = get_segment_selector(ctxt, VCPU_SREG_CS);
  11888. old_eip = ctxt->_eip;
  11889. - ops->get_segment(ctxt, &old_cs, &old_desc, NULL, VCPU_SREG_CS);
  11890. memcpy(&sel, ctxt->src.valptr + ctxt->op_bytes, 2);
  11891. - rc = load_segment_descriptor(ctxt, sel, VCPU_SREG_CS, &new_desc);
  11892. - if (rc != X86EMUL_CONTINUE)
  11893. + if (load_segment_descriptor(ctxt, sel, VCPU_SREG_CS))
  11894. return X86EMUL_CONTINUE;
  11895. - rc = assign_eip_far(ctxt, ctxt->src.val, new_desc.l);
  11896. - if (rc != X86EMUL_CONTINUE)
  11897. - goto fail;
  11898. + ctxt->_eip = 0;
  11899. + memcpy(&ctxt->_eip, ctxt->src.valptr, ctxt->op_bytes);
  11900. ctxt->src.val = old_cs;
  11901. rc = em_push(ctxt);
  11902. if (rc != X86EMUL_CONTINUE)
  11903. - goto fail;
  11904. + return rc;
  11905. ctxt->src.val = old_eip;
  11906. - rc = em_push(ctxt);
  11907. - /* If we failed, we tainted the memory, but the very least we should
  11908. - restore cs */
  11909. - if (rc != X86EMUL_CONTINUE)
  11910. - goto fail;
  11911. - return rc;
  11912. -fail:
  11913. - ops->set_segment(ctxt, old_cs, &old_desc, 0, VCPU_SREG_CS);
  11914. - return rc;
  11915. -
  11916. + return em_push(ctxt);
  11917. }
  11918. static int em_ret_near_imm(struct x86_emulate_ctxt *ctxt)
  11919. @@ -3125,7 +3081,7 @@
  11920. /* Disable writeback. */
  11921. ctxt->dst.type = OP_NONE;
  11922. - return load_segment_descriptor(ctxt, sel, ctxt->modrm_reg, NULL);
  11923. + return load_segment_descriptor(ctxt, sel, ctxt->modrm_reg);
  11924. }
  11925. static int em_lldt(struct x86_emulate_ctxt *ctxt)
  11926. @@ -3134,7 +3090,7 @@
  11927. /* Disable writeback. */
  11928. ctxt->dst.type = OP_NONE;
  11929. - return load_segment_descriptor(ctxt, sel, VCPU_SREG_LDTR, NULL);
  11930. + return load_segment_descriptor(ctxt, sel, VCPU_SREG_LDTR);
  11931. }
  11932. static int em_ltr(struct x86_emulate_ctxt *ctxt)
  11933. @@ -3143,7 +3099,7 @@
  11934. /* Disable writeback. */
  11935. ctxt->dst.type = OP_NONE;
  11936. - return load_segment_descriptor(ctxt, sel, VCPU_SREG_TR, NULL);
  11937. + return load_segment_descriptor(ctxt, sel, VCPU_SREG_TR);
  11938. }
  11939. static int em_invlpg(struct x86_emulate_ctxt *ctxt)
  11940. @@ -3658,11 +3614,11 @@
  11941. static const struct opcode group5[] = {
  11942. F(DstMem | SrcNone | Lock, em_inc),
  11943. F(DstMem | SrcNone | Lock, em_dec),
  11944. - I(SrcMem | NearBranch, em_call_near_abs),
  11945. + I(SrcMem | Stack, em_grp45),
  11946. I(SrcMemFAddr | ImplicitOps | Stack, em_call_far),
  11947. - I(SrcMem | NearBranch, em_jmp_abs),
  11948. - I(SrcMemFAddr | ImplicitOps, em_jmp_far),
  11949. - I(SrcMem | Stack, em_push), D(Undefined),
  11950. + I(SrcMem | Stack, em_grp45),
  11951. + I(SrcMemFAddr | ImplicitOps, em_grp45),
  11952. + I(SrcMem | Stack, em_grp45), D(Undefined),
  11953. };
  11954. static const struct opcode group6[] = {
  11955. @@ -3824,7 +3780,7 @@
  11956. I2bvIP(DstDI | SrcDX | Mov | String | Unaligned, em_in, ins, check_perm_in), /* insb, insw/insd */
  11957. I2bvIP(SrcSI | DstDX | String, em_out, outs, check_perm_out), /* outsb, outsw/outsd */
  11958. /* 0x70 - 0x7F */
  11959. - X16(D(SrcImmByte | NearBranch)),
  11960. + X16(D(SrcImmByte)),
  11961. /* 0x80 - 0x87 */
  11962. G(ByteOp | DstMem | SrcImm, group1),
  11963. G(DstMem | SrcImm, group1),
  11964. @@ -3862,8 +3818,8 @@
  11965. X8(I(DstReg | SrcImm64 | Mov, em_mov)),
  11966. /* 0xC0 - 0xC7 */
  11967. G(ByteOp | Src2ImmByte, group2), G(Src2ImmByte, group2),
  11968. - I(ImplicitOps | NearBranch | SrcImmU16, em_ret_near_imm),
  11969. - I(ImplicitOps | NearBranch, em_ret),
  11970. + I(ImplicitOps | Stack | SrcImmU16, em_ret_near_imm),
  11971. + I(ImplicitOps | Stack, em_ret),
  11972. I(DstReg | SrcMemFAddr | ModRM | No64 | Src2ES, em_lseg),
  11973. I(DstReg | SrcMemFAddr | ModRM | No64 | Src2DS, em_lseg),
  11974. G(ByteOp, group11), G(0, group11),
  11975. @@ -3884,11 +3840,11 @@
  11976. N, E(0, &escape_d9), N, E(0, &escape_db), N, E(0, &escape_dd), N, N,
  11977. /* 0xE0 - 0xE7 */
  11978. X3(I(SrcImmByte, em_loop)),
  11979. - I(SrcImmByte | NearBranch, em_jcxz),
  11980. + I(SrcImmByte, em_jcxz),
  11981. I2bvIP(SrcImmUByte | DstAcc, em_in, in, check_perm_in),
  11982. I2bvIP(SrcAcc | DstImmUByte, em_out, out, check_perm_out),
  11983. /* 0xE8 - 0xEF */
  11984. - I(SrcImm | NearBranch, em_call), D(SrcImm | ImplicitOps),
  11985. + I(SrcImm | Stack, em_call), D(SrcImm | ImplicitOps),
  11986. I(SrcImmFAddr | No64, em_jmp_far), D(SrcImmByte | ImplicitOps),
  11987. I2bvIP(SrcDX | DstAcc, em_in, in, check_perm_in),
  11988. I2bvIP(SrcAcc | DstDX, em_out, out, check_perm_out),
  11989. @@ -4368,12 +4324,8 @@
  11990. if (!(ctxt->d & VendorSpecific) && ctxt->only_vendor_specific_insn)
  11991. return EMULATION_FAILED;
  11992. - if (mode == X86EMUL_MODE_PROT64) {
  11993. - if (ctxt->op_bytes == 4 && (ctxt->d & Stack))
  11994. - ctxt->op_bytes = 8;
  11995. - else if (ctxt->d & NearBranch)
  11996. - ctxt->op_bytes = 8;
  11997. - }
  11998. + if (mode == X86EMUL_MODE_PROT64 && (ctxt->d & Stack))
  11999. + ctxt->op_bytes = 8;
  12000. if (ctxt->d & Op3264) {
  12001. if (mode == X86EMUL_MODE_PROT64)
  12002. diff -Nur linux-3.12.38/arch/x86/kvm/mmu.c linux-rpi/arch/x86/kvm/mmu.c
  12003. --- linux-3.12.38/arch/x86/kvm/mmu.c 2015-02-16 16:15:42.000000000 +0100
  12004. +++ linux-rpi/arch/x86/kvm/mmu.c 2015-03-10 17:26:50.062216695 +0100
  12005. @@ -4429,7 +4429,7 @@
  12006. * zap all shadow pages.
  12007. */
  12008. if (unlikely(kvm_current_mmio_generation(kvm) == 0)) {
  12009. - printk_ratelimited(KERN_DEBUG "kvm: zapping shadow pages for mmio generation wraparound\n");
  12010. + printk_ratelimited(KERN_INFO "kvm: zapping shadow pages for mmio generation wraparound\n");
  12011. kvm_mmu_invalidate_zap_all_pages(kvm);
  12012. }
  12013. }
  12014. diff -Nur linux-3.12.38/arch/x86/kvm/vmx.c linux-rpi/arch/x86/kvm/vmx.c
  12015. --- linux-3.12.38/arch/x86/kvm/vmx.c 2015-02-16 16:15:42.000000000 +0100
  12016. +++ linux-rpi/arch/x86/kvm/vmx.c 2015-03-10 17:26:50.062216695 +0100
  12017. @@ -439,7 +439,6 @@
  12018. #endif
  12019. int gs_ldt_reload_needed;
  12020. int fs_reload_needed;
  12021. - unsigned long vmcs_host_cr4; /* May not match real cr4 */
  12022. } host_state;
  12023. struct {
  12024. int vm86_active;
  12025. @@ -2520,8 +2519,6 @@
  12026. break;
  12027. case MSR_IA32_CR_PAT:
  12028. if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
  12029. - if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
  12030. - return 1;
  12031. vmcs_write64(GUEST_IA32_PAT, data);
  12032. vcpu->arch.pat = data;
  12033. break;
  12034. @@ -4130,16 +4127,11 @@
  12035. u32 low32, high32;
  12036. unsigned long tmpl;
  12037. struct desc_ptr dt;
  12038. - unsigned long cr4;
  12039. vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
  12040. + vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
  12041. vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
  12042. - /* Save the most likely value for this task's CR4 in the VMCS. */
  12043. - cr4 = read_cr4();
  12044. - vmcs_writel(HOST_CR4, cr4); /* 22.2.3, 22.2.5 */
  12045. - vmx->host_state.vmcs_host_cr4 = cr4;
  12046. -
  12047. vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
  12048. #ifdef CONFIG_X86_64
  12049. /*
  12050. @@ -7132,7 +7124,7 @@
  12051. static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  12052. {
  12053. struct vcpu_vmx *vmx = to_vmx(vcpu);
  12054. - unsigned long debugctlmsr, cr4;
  12055. + unsigned long debugctlmsr;
  12056. /* Record the guest's net vcpu time for enforced NMI injections. */
  12057. if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked))
  12058. @@ -7153,12 +7145,6 @@
  12059. if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))
  12060. vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);
  12061. - cr4 = read_cr4();
  12062. - if (unlikely(cr4 != vmx->host_state.vmcs_host_cr4)) {
  12063. - vmcs_writel(HOST_CR4, cr4);
  12064. - vmx->host_state.vmcs_host_cr4 = cr4;
  12065. - }
  12066. -
  12067. /* When single-stepping over STI and MOV SS, we must clear the
  12068. * corresponding interruptibility bits in the guest state. Otherwise
  12069. * vmentry fails as it then expects bit 14 (BS) in pending debug
  12070. diff -Nur linux-3.12.38/arch/x86/kvm/x86.c linux-rpi/arch/x86/kvm/x86.c
  12071. --- linux-3.12.38/arch/x86/kvm/x86.c 2015-02-16 16:15:42.000000000 +0100
  12072. +++ linux-rpi/arch/x86/kvm/x86.c 2015-03-10 17:26:50.066216695 +0100
  12073. @@ -1707,7 +1707,7 @@
  12074. return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
  12075. }
  12076. -bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  12077. +static bool mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  12078. {
  12079. int i;
  12080. @@ -1733,13 +1733,12 @@
  12081. /* variable MTRRs */
  12082. return valid_mtrr_type(data & 0xff);
  12083. }
  12084. -EXPORT_SYMBOL_GPL(kvm_mtrr_valid);
  12085. static int set_msr_mtrr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
  12086. {
  12087. u64 *p = (u64 *)&vcpu->arch.mtrr_state.fixed_ranges;
  12088. - if (!kvm_mtrr_valid(vcpu, msr, data))
  12089. + if (!mtrr_valid(vcpu, msr, data))
  12090. return 1;
  12091. if (msr == MSR_MTRRdefType) {
  12092. diff -Nur linux-3.12.38/arch/x86/kvm/x86.h linux-rpi/arch/x86/kvm/x86.h
  12093. --- linux-3.12.38/arch/x86/kvm/x86.h 2015-02-16 16:15:42.000000000 +0100
  12094. +++ linux-rpi/arch/x86/kvm/x86.h 2015-03-10 17:26:50.066216695 +0100
  12095. @@ -132,8 +132,6 @@
  12096. gva_t addr, void *val, unsigned int bytes,
  12097. struct x86_exception *exception);
  12098. -bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);
  12099. -
  12100. extern u64 host_xcr0;
  12101. extern unsigned int min_timer_period_us;
  12102. diff -Nur linux-3.12.38/arch/x86/pci/common.c linux-rpi/arch/x86/pci/common.c
  12103. --- linux-3.12.38/arch/x86/pci/common.c 2015-02-16 16:15:42.000000000 +0100
  12104. +++ linux-rpi/arch/x86/pci/common.c 2015-03-10 17:26:50.070216695 +0100
  12105. @@ -448,22 +448,6 @@
  12106. DMI_MATCH(DMI_PRODUCT_NAME, "ftServer"),
  12107. },
  12108. },
  12109. - {
  12110. - .callback = set_scan_all,
  12111. - .ident = "Stratus/NEC ftServer",
  12112. - .matches = {
  12113. - DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
  12114. - DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R32"),
  12115. - },
  12116. - },
  12117. - {
  12118. - .callback = set_scan_all,
  12119. - .ident = "Stratus/NEC ftServer",
  12120. - .matches = {
  12121. - DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
  12122. - DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R31"),
  12123. - },
  12124. - },
  12125. {}
  12126. };
  12127. diff -Nur linux-3.12.38/arch/x86/platform/uv/tlb_uv.c linux-rpi/arch/x86/platform/uv/tlb_uv.c
  12128. --- linux-3.12.38/arch/x86/platform/uv/tlb_uv.c 2015-02-16 16:15:42.000000000 +0100
  12129. +++ linux-rpi/arch/x86/platform/uv/tlb_uv.c 2015-03-10 17:26:50.070216695 +0100
  12130. @@ -1367,10 +1367,6 @@
  12131. }
  12132. if (cpu < num_possible_cpus() && cpu_online(cpu)) {
  12133. bcp = &per_cpu(bau_control, cpu);
  12134. - if (bcp->nobau) {
  12135. - seq_printf(file, "cpu %d bau disabled\n", cpu);
  12136. - return 0;
  12137. - }
  12138. stat = bcp->statp;
  12139. /* source side statistics */
  12140. seq_printf(file,
  12141. diff -Nur linux-3.12.38/arch/x86/um/sys_call_table_32.c linux-rpi/arch/x86/um/sys_call_table_32.c
  12142. --- linux-3.12.38/arch/x86/um/sys_call_table_32.c 2015-02-16 16:15:42.000000000 +0100
  12143. +++ linux-rpi/arch/x86/um/sys_call_table_32.c 2015-03-10 17:26:50.074216695 +0100
  12144. @@ -34,7 +34,7 @@
  12145. extern asmlinkage void sys_ni_syscall(void);
  12146. -const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = {
  12147. +const sys_call_ptr_t sys_call_table[] __cacheline_aligned = {
  12148. /*
  12149. * Smells like a compiler bug -- it doesn't work
  12150. * when the & below is removed.
  12151. diff -Nur linux-3.12.38/arch/x86/um/sys_call_table_64.c linux-rpi/arch/x86/um/sys_call_table_64.c
  12152. --- linux-3.12.38/arch/x86/um/sys_call_table_64.c 2015-02-16 16:15:42.000000000 +0100
  12153. +++ linux-rpi/arch/x86/um/sys_call_table_64.c 2015-03-10 17:26:50.074216695 +0100
  12154. @@ -46,7 +46,7 @@
  12155. extern void sys_ni_syscall(void);
  12156. -const sys_call_ptr_t sys_call_table[] ____cacheline_aligned = {
  12157. +const sys_call_ptr_t sys_call_table[] __cacheline_aligned = {
  12158. /*
  12159. * Smells like a compiler bug -- it doesn't work
  12160. * when the & below is removed.
  12161. diff -Nur linux-3.12.38/arch/x86/vdso/vma.c linux-rpi/arch/x86/vdso/vma.c
  12162. --- linux-3.12.38/arch/x86/vdso/vma.c 2015-02-16 16:15:42.000000000 +0100
  12163. +++ linux-rpi/arch/x86/vdso/vma.c 2015-03-10 17:26:50.074216695 +0100
  12164. @@ -117,45 +117,30 @@
  12165. struct linux_binprm;
  12166. -/*
  12167. - * Put the vdso above the (randomized) stack with another randomized
  12168. - * offset. This way there is no hole in the middle of address space.
  12169. - * To save memory make sure it is still in the same PTE as the stack
  12170. - * top. This doesn't give that many random bits.
  12171. - *
  12172. - * Note that this algorithm is imperfect: the distribution of the vdso
  12173. - * start address within a PMD is biased toward the end.
  12174. - *
  12175. - * Only used for the 64-bit and x32 vdsos.
  12176. - */
  12177. +/* Put the vdso above the (randomized) stack with another randomized offset.
  12178. + This way there is no hole in the middle of address space.
  12179. + To save memory make sure it is still in the same PTE as the stack top.
  12180. + This doesn't give that many random bits */
  12181. static unsigned long vdso_addr(unsigned long start, unsigned len)
  12182. {
  12183. unsigned long addr, end;
  12184. unsigned offset;
  12185. -
  12186. - /*
  12187. - * Round up the start address. It can start out unaligned as a result
  12188. - * of stack start randomization.
  12189. - */
  12190. - start = PAGE_ALIGN(start);
  12191. -
  12192. - /* Round the lowest possible end address up to a PMD boundary. */
  12193. - end = (start + len + PMD_SIZE - 1) & PMD_MASK;
  12194. + end = (start + PMD_SIZE - 1) & PMD_MASK;
  12195. if (end >= TASK_SIZE_MAX)
  12196. end = TASK_SIZE_MAX;
  12197. end -= len;
  12198. -
  12199. - if (end > start) {
  12200. - offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1);
  12201. - addr = start + (offset << PAGE_SHIFT);
  12202. - } else {
  12203. - addr = start;
  12204. - }
  12205. + /* This loses some more bits than a modulo, but is cheaper */
  12206. + offset = get_random_int() & (PTRS_PER_PTE - 1);
  12207. + addr = start + (offset << PAGE_SHIFT);
  12208. + if (addr >= end)
  12209. + addr = end;
  12210. /*
  12211. - * Forcibly align the final address in case we have a hardware
  12212. - * issue that requires alignment for performance reasons.
  12213. + * page-align it here so that get_unmapped_area doesn't
  12214. + * align it wrongfully again to the next page. addr can come in 4K
  12215. + * unaligned here as a result of stack start randomization.
  12216. */
  12217. + addr = PAGE_ALIGN(addr);
  12218. addr = align_vdso_addr(addr);
  12219. return addr;
  12220. diff -Nur linux-3.12.38/block/genhd.c linux-rpi/block/genhd.c
  12221. --- linux-3.12.38/block/genhd.c 2015-02-16 16:15:42.000000000 +0100
  12222. +++ linux-rpi/block/genhd.c 2015-03-10 17:26:50.086216695 +0100
  12223. @@ -1070,16 +1070,9 @@
  12224. struct disk_part_tbl *old_ptbl = disk->part_tbl;
  12225. struct disk_part_tbl *new_ptbl;
  12226. int len = old_ptbl ? old_ptbl->len : 0;
  12227. - int i, target;
  12228. + int target = partno + 1;
  12229. size_t size;
  12230. -
  12231. - /*
  12232. - * check for int overflow, since we can get here from blkpg_ioctl()
  12233. - * with a user passed 'partno'.
  12234. - */
  12235. - target = partno + 1;
  12236. - if (target < 0)
  12237. - return -EINVAL;
  12238. + int i;
  12239. /* disk_max_parts() is zero during initialization, ignore if so */
  12240. if (disk_max_parts(disk) && target > disk_max_parts(disk))
  12241. diff -Nur linux-3.12.38/crypto/842.c linux-rpi/crypto/842.c
  12242. --- linux-3.12.38/crypto/842.c 2015-02-16 16:15:42.000000000 +0100
  12243. +++ linux-rpi/crypto/842.c 2015-03-10 17:26:50.086216695 +0100
  12244. @@ -180,4 +180,3 @@
  12245. MODULE_LICENSE("GPL");
  12246. MODULE_DESCRIPTION("842 Compression Algorithm");
  12247. -MODULE_ALIAS_CRYPTO("842");
  12248. diff -Nur linux-3.12.38/crypto/aes_generic.c linux-rpi/crypto/aes_generic.c
  12249. --- linux-3.12.38/crypto/aes_generic.c 2015-02-16 16:15:42.000000000 +0100
  12250. +++ linux-rpi/crypto/aes_generic.c 2015-03-10 17:26:50.086216695 +0100
  12251. @@ -1474,5 +1474,4 @@
  12252. MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
  12253. MODULE_LICENSE("Dual BSD/GPL");
  12254. -MODULE_ALIAS_CRYPTO("aes");
  12255. -MODULE_ALIAS_CRYPTO("aes-generic");
  12256. +MODULE_ALIAS("aes");
  12257. diff -Nur linux-3.12.38/crypto/algapi.c linux-rpi/crypto/algapi.c
  12258. --- linux-3.12.38/crypto/algapi.c 2015-02-16 16:15:42.000000000 +0100
  12259. +++ linux-rpi/crypto/algapi.c 2015-03-10 17:26:50.086216695 +0100
  12260. @@ -495,8 +495,8 @@
  12261. struct crypto_template *crypto_lookup_template(const char *name)
  12262. {
  12263. - return try_then_request_module(__crypto_lookup_template(name),
  12264. - "crypto-%s", name);
  12265. + return try_then_request_module(__crypto_lookup_template(name), "%s",
  12266. + name);
  12267. }
  12268. EXPORT_SYMBOL_GPL(crypto_lookup_template);
  12269. diff -Nur linux-3.12.38/crypto/ansi_cprng.c linux-rpi/crypto/ansi_cprng.c
  12270. --- linux-3.12.38/crypto/ansi_cprng.c 2015-02-16 16:15:42.000000000 +0100
  12271. +++ linux-rpi/crypto/ansi_cprng.c 2015-03-10 17:26:50.086216695 +0100
  12272. @@ -476,5 +476,4 @@
  12273. MODULE_PARM_DESC(dbg, "Boolean to enable debugging (0/1 == off/on)");
  12274. module_init(prng_mod_init);
  12275. module_exit(prng_mod_fini);
  12276. -MODULE_ALIAS_CRYPTO("stdrng");
  12277. -MODULE_ALIAS_CRYPTO("ansi_cprng");
  12278. +MODULE_ALIAS("stdrng");
  12279. diff -Nur linux-3.12.38/crypto/anubis.c linux-rpi/crypto/anubis.c
  12280. --- linux-3.12.38/crypto/anubis.c 2015-02-16 16:15:42.000000000 +0100
  12281. +++ linux-rpi/crypto/anubis.c 2015-03-10 17:26:50.086216695 +0100
  12282. @@ -704,4 +704,3 @@
  12283. MODULE_LICENSE("GPL");
  12284. MODULE_DESCRIPTION("Anubis Cryptographic Algorithm");
  12285. -MODULE_ALIAS_CRYPTO("anubis");
  12286. diff -Nur linux-3.12.38/crypto/api.c linux-rpi/crypto/api.c
  12287. --- linux-3.12.38/crypto/api.c 2015-02-16 16:15:42.000000000 +0100
  12288. +++ linux-rpi/crypto/api.c 2015-03-10 17:26:50.086216695 +0100
  12289. @@ -216,11 +216,11 @@
  12290. alg = crypto_alg_lookup(name, type, mask);
  12291. if (!alg) {
  12292. - request_module("crypto-%s", name);
  12293. + request_module("%s", name);
  12294. if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask &
  12295. CRYPTO_ALG_NEED_FALLBACK))
  12296. - request_module("crypto-%s-all", name);
  12297. + request_module("%s-all", name);
  12298. alg = crypto_alg_lookup(name, type, mask);
  12299. }
  12300. diff -Nur linux-3.12.38/crypto/arc4.c linux-rpi/crypto/arc4.c
  12301. --- linux-3.12.38/crypto/arc4.c 2015-02-16 16:15:42.000000000 +0100
  12302. +++ linux-rpi/crypto/arc4.c 2015-03-10 17:26:50.086216695 +0100
  12303. @@ -166,4 +166,3 @@
  12304. MODULE_LICENSE("GPL");
  12305. MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
  12306. MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
  12307. -MODULE_ALIAS_CRYPTO("arc4");
  12308. diff -Nur linux-3.12.38/crypto/authenc.c linux-rpi/crypto/authenc.c
  12309. --- linux-3.12.38/crypto/authenc.c 2015-02-16 16:15:42.000000000 +0100
  12310. +++ linux-rpi/crypto/authenc.c 2015-03-10 17:26:50.086216695 +0100
  12311. @@ -709,4 +709,3 @@
  12312. MODULE_LICENSE("GPL");
  12313. MODULE_DESCRIPTION("Simple AEAD wrapper for IPsec");
  12314. -MODULE_ALIAS_CRYPTO("authenc");
  12315. diff -Nur linux-3.12.38/crypto/authencesn.c linux-rpi/crypto/authencesn.c
  12316. --- linux-3.12.38/crypto/authencesn.c 2015-02-16 16:15:42.000000000 +0100
  12317. +++ linux-rpi/crypto/authencesn.c 2015-03-10 17:26:50.086216695 +0100
  12318. @@ -832,4 +832,3 @@
  12319. MODULE_LICENSE("GPL");
  12320. MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");
  12321. MODULE_DESCRIPTION("AEAD wrapper for IPsec with extended sequence numbers");
  12322. -MODULE_ALIAS_CRYPTO("authencesn");
  12323. diff -Nur linux-3.12.38/crypto/blowfish_generic.c linux-rpi/crypto/blowfish_generic.c
  12324. --- linux-3.12.38/crypto/blowfish_generic.c 2015-02-16 16:15:42.000000000 +0100
  12325. +++ linux-rpi/crypto/blowfish_generic.c 2015-03-10 17:26:50.086216695 +0100
  12326. @@ -138,5 +138,4 @@
  12327. MODULE_LICENSE("GPL");
  12328. MODULE_DESCRIPTION("Blowfish Cipher Algorithm");
  12329. -MODULE_ALIAS_CRYPTO("blowfish");
  12330. -MODULE_ALIAS_CRYPTO("blowfish-generic");
  12331. +MODULE_ALIAS("blowfish");
  12332. diff -Nur linux-3.12.38/crypto/camellia_generic.c linux-rpi/crypto/camellia_generic.c
  12333. --- linux-3.12.38/crypto/camellia_generic.c 2015-02-16 16:15:42.000000000 +0100
  12334. +++ linux-rpi/crypto/camellia_generic.c 2015-03-10 17:26:50.086216695 +0100
  12335. @@ -1098,5 +1098,4 @@
  12336. MODULE_DESCRIPTION("Camellia Cipher Algorithm");
  12337. MODULE_LICENSE("GPL");
  12338. -MODULE_ALIAS_CRYPTO("camellia");
  12339. -MODULE_ALIAS_CRYPTO("camellia-generic");
  12340. +MODULE_ALIAS("camellia");
  12341. diff -Nur linux-3.12.38/crypto/cast5_generic.c linux-rpi/crypto/cast5_generic.c
  12342. --- linux-3.12.38/crypto/cast5_generic.c 2015-02-16 16:15:42.000000000 +0100
  12343. +++ linux-rpi/crypto/cast5_generic.c 2015-03-10 17:26:50.086216695 +0100
  12344. @@ -549,5 +549,4 @@
  12345. MODULE_LICENSE("GPL");
  12346. MODULE_DESCRIPTION("Cast5 Cipher Algorithm");
  12347. -MODULE_ALIAS_CRYPTO("cast5");
  12348. -MODULE_ALIAS_CRYPTO("cast5-generic");
  12349. +MODULE_ALIAS("cast5");
  12350. diff -Nur linux-3.12.38/crypto/cast6_generic.c linux-rpi/crypto/cast6_generic.c
  12351. --- linux-3.12.38/crypto/cast6_generic.c 2015-02-16 16:15:42.000000000 +0100
  12352. +++ linux-rpi/crypto/cast6_generic.c 2015-03-10 17:26:50.086216695 +0100
  12353. @@ -291,5 +291,4 @@
  12354. MODULE_LICENSE("GPL");
  12355. MODULE_DESCRIPTION("Cast6 Cipher Algorithm");
  12356. -MODULE_ALIAS_CRYPTO("cast6");
  12357. -MODULE_ALIAS_CRYPTO("cast6-generic");
  12358. +MODULE_ALIAS("cast6");
  12359. diff -Nur linux-3.12.38/crypto/cbc.c linux-rpi/crypto/cbc.c
  12360. --- linux-3.12.38/crypto/cbc.c 2015-02-16 16:15:42.000000000 +0100
  12361. +++ linux-rpi/crypto/cbc.c 2015-03-10 17:26:50.086216695 +0100
  12362. @@ -289,4 +289,3 @@
  12363. MODULE_LICENSE("GPL");
  12364. MODULE_DESCRIPTION("CBC block cipher algorithm");
  12365. -MODULE_ALIAS_CRYPTO("cbc");
  12366. diff -Nur linux-3.12.38/crypto/ccm.c linux-rpi/crypto/ccm.c
  12367. --- linux-3.12.38/crypto/ccm.c 2015-02-16 16:15:42.000000000 +0100
  12368. +++ linux-rpi/crypto/ccm.c 2015-03-10 17:26:50.090216695 +0100
  12369. @@ -879,6 +879,5 @@
  12370. MODULE_LICENSE("GPL");
  12371. MODULE_DESCRIPTION("Counter with CBC MAC");
  12372. -MODULE_ALIAS_CRYPTO("ccm_base");
  12373. -MODULE_ALIAS_CRYPTO("rfc4309");
  12374. -MODULE_ALIAS_CRYPTO("ccm");
  12375. +MODULE_ALIAS("ccm_base");
  12376. +MODULE_ALIAS("rfc4309");
  12377. diff -Nur linux-3.12.38/crypto/chainiv.c linux-rpi/crypto/chainiv.c
  12378. --- linux-3.12.38/crypto/chainiv.c 2015-02-16 16:15:42.000000000 +0100
  12379. +++ linux-rpi/crypto/chainiv.c 2015-03-10 17:26:50.090216695 +0100
  12380. @@ -359,4 +359,3 @@
  12381. MODULE_LICENSE("GPL");
  12382. MODULE_DESCRIPTION("Chain IV Generator");
  12383. -MODULE_ALIAS_CRYPTO("chainiv");
  12384. diff -Nur linux-3.12.38/crypto/cmac.c linux-rpi/crypto/cmac.c
  12385. --- linux-3.12.38/crypto/cmac.c 2015-02-16 16:15:42.000000000 +0100
  12386. +++ linux-rpi/crypto/cmac.c 2015-03-10 17:26:50.090216695 +0100
  12387. @@ -313,4 +313,3 @@
  12388. MODULE_LICENSE("GPL");
  12389. MODULE_DESCRIPTION("CMAC keyed hash algorithm");
  12390. -MODULE_ALIAS_CRYPTO("cmac");
  12391. diff -Nur linux-3.12.38/crypto/crc32.c linux-rpi/crypto/crc32.c
  12392. --- linux-3.12.38/crypto/crc32.c 2015-02-16 16:15:42.000000000 +0100
  12393. +++ linux-rpi/crypto/crc32.c 2015-03-10 17:26:50.090216695 +0100
  12394. @@ -156,4 +156,3 @@
  12395. MODULE_AUTHOR("Alexander Boyko <alexander_boyko@xyratex.com>");
  12396. MODULE_DESCRIPTION("CRC32 calculations wrapper for lib/crc32");
  12397. MODULE_LICENSE("GPL");
  12398. -MODULE_ALIAS_CRYPTO("crc32");
  12399. diff -Nur linux-3.12.38/crypto/crc32c.c linux-rpi/crypto/crc32c.c
  12400. --- linux-3.12.38/crypto/crc32c.c 2015-02-16 16:15:42.000000000 +0100
  12401. +++ linux-rpi/crypto/crc32c.c 2015-03-10 17:26:50.090216695 +0100
  12402. @@ -170,4 +170,3 @@
  12403. MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>");
  12404. MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations wrapper for lib/crc32c");
  12405. MODULE_LICENSE("GPL");
  12406. -MODULE_ALIAS_CRYPTO("crc32c");
  12407. diff -Nur linux-3.12.38/crypto/crct10dif_generic.c linux-rpi/crypto/crct10dif_generic.c
  12408. --- linux-3.12.38/crypto/crct10dif_generic.c 2015-02-16 16:15:42.000000000 +0100
  12409. +++ linux-rpi/crypto/crct10dif_generic.c 2015-03-10 17:26:50.090216695 +0100
  12410. @@ -124,5 +124,4 @@
  12411. MODULE_AUTHOR("Tim Chen <tim.c.chen@linux.intel.com>");
  12412. MODULE_DESCRIPTION("T10 DIF CRC calculation.");
  12413. MODULE_LICENSE("GPL");
  12414. -MODULE_ALIAS_CRYPTO("crct10dif");
  12415. -MODULE_ALIAS_CRYPTO("crct10dif-generic");
  12416. +MODULE_ALIAS("crct10dif");
  12417. diff -Nur linux-3.12.38/crypto/cryptd.c linux-rpi/crypto/cryptd.c
  12418. --- linux-3.12.38/crypto/cryptd.c 2015-02-16 16:15:42.000000000 +0100
  12419. +++ linux-rpi/crypto/cryptd.c 2015-03-10 17:26:50.090216695 +0100
  12420. @@ -955,4 +955,3 @@
  12421. MODULE_LICENSE("GPL");
  12422. MODULE_DESCRIPTION("Software async crypto daemon");
  12423. -MODULE_ALIAS_CRYPTO("cryptd");
  12424. diff -Nur linux-3.12.38/crypto/crypto_null.c linux-rpi/crypto/crypto_null.c
  12425. --- linux-3.12.38/crypto/crypto_null.c 2015-02-16 16:15:42.000000000 +0100
  12426. +++ linux-rpi/crypto/crypto_null.c 2015-03-10 17:26:50.090216695 +0100
  12427. @@ -149,9 +149,9 @@
  12428. .coa_decompress = null_compress } }
  12429. } };
  12430. -MODULE_ALIAS_CRYPTO("compress_null");
  12431. -MODULE_ALIAS_CRYPTO("digest_null");
  12432. -MODULE_ALIAS_CRYPTO("cipher_null");
  12433. +MODULE_ALIAS("compress_null");
  12434. +MODULE_ALIAS("digest_null");
  12435. +MODULE_ALIAS("cipher_null");
  12436. static int __init crypto_null_mod_init(void)
  12437. {
  12438. diff -Nur linux-3.12.38/crypto/ctr.c linux-rpi/crypto/ctr.c
  12439. --- linux-3.12.38/crypto/ctr.c 2015-02-16 16:15:42.000000000 +0100
  12440. +++ linux-rpi/crypto/ctr.c 2015-03-10 17:26:50.090216695 +0100
  12441. @@ -466,5 +466,4 @@
  12442. MODULE_LICENSE("GPL");
  12443. MODULE_DESCRIPTION("CTR Counter block mode");
  12444. -MODULE_ALIAS_CRYPTO("rfc3686");
  12445. -MODULE_ALIAS_CRYPTO("ctr");
  12446. +MODULE_ALIAS("rfc3686");
  12447. diff -Nur linux-3.12.38/crypto/cts.c linux-rpi/crypto/cts.c
  12448. --- linux-3.12.38/crypto/cts.c 2015-02-16 16:15:42.000000000 +0100
  12449. +++ linux-rpi/crypto/cts.c 2015-03-10 17:26:50.090216695 +0100
  12450. @@ -350,4 +350,3 @@
  12451. MODULE_LICENSE("Dual BSD/GPL");
  12452. MODULE_DESCRIPTION("CTS-CBC CipherText Stealing for CBC");
  12453. -MODULE_ALIAS_CRYPTO("cts");
  12454. diff -Nur linux-3.12.38/crypto/deflate.c linux-rpi/crypto/deflate.c
  12455. --- linux-3.12.38/crypto/deflate.c 2015-02-16 16:15:42.000000000 +0100
  12456. +++ linux-rpi/crypto/deflate.c 2015-03-10 17:26:50.090216695 +0100
  12457. @@ -222,4 +222,4 @@
  12458. MODULE_LICENSE("GPL");
  12459. MODULE_DESCRIPTION("Deflate Compression Algorithm for IPCOMP");
  12460. MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
  12461. -MODULE_ALIAS_CRYPTO("deflate");
  12462. +
  12463. diff -Nur linux-3.12.38/crypto/des_generic.c linux-rpi/crypto/des_generic.c
  12464. --- linux-3.12.38/crypto/des_generic.c 2015-02-16 16:15:42.000000000 +0100
  12465. +++ linux-rpi/crypto/des_generic.c 2015-03-10 17:26:50.090216695 +0100
  12466. @@ -971,6 +971,8 @@
  12467. .cia_decrypt = des3_ede_decrypt } }
  12468. } };
  12469. +MODULE_ALIAS("des3_ede");
  12470. +
  12471. static int __init des_generic_mod_init(void)
  12472. {
  12473. return crypto_register_algs(des_algs, ARRAY_SIZE(des_algs));
  12474. @@ -987,7 +989,4 @@
  12475. MODULE_LICENSE("GPL");
  12476. MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");
  12477. MODULE_AUTHOR("Dag Arne Osvik <da@osvik.no>");
  12478. -MODULE_ALIAS_CRYPTO("des");
  12479. -MODULE_ALIAS_CRYPTO("des-generic");
  12480. -MODULE_ALIAS_CRYPTO("des3_ede");
  12481. -MODULE_ALIAS_CRYPTO("des3_ede-generic");
  12482. +MODULE_ALIAS("des");
  12483. diff -Nur linux-3.12.38/crypto/ecb.c linux-rpi/crypto/ecb.c
  12484. --- linux-3.12.38/crypto/ecb.c 2015-02-16 16:15:42.000000000 +0100
  12485. +++ linux-rpi/crypto/ecb.c 2015-03-10 17:26:50.090216695 +0100
  12486. @@ -185,4 +185,3 @@
  12487. MODULE_LICENSE("GPL");
  12488. MODULE_DESCRIPTION("ECB block cipher algorithm");
  12489. -MODULE_ALIAS_CRYPTO("ecb");
  12490. diff -Nur linux-3.12.38/crypto/eseqiv.c linux-rpi/crypto/eseqiv.c
  12491. --- linux-3.12.38/crypto/eseqiv.c 2015-02-16 16:15:42.000000000 +0100
  12492. +++ linux-rpi/crypto/eseqiv.c 2015-03-10 17:26:50.090216695 +0100
  12493. @@ -267,4 +267,3 @@
  12494. MODULE_LICENSE("GPL");
  12495. MODULE_DESCRIPTION("Encrypted Sequence Number IV Generator");
  12496. -MODULE_ALIAS_CRYPTO("eseqiv");
  12497. diff -Nur linux-3.12.38/crypto/fcrypt.c linux-rpi/crypto/fcrypt.c
  12498. --- linux-3.12.38/crypto/fcrypt.c 2015-02-16 16:15:42.000000000 +0100
  12499. +++ linux-rpi/crypto/fcrypt.c 2015-03-10 17:26:50.090216695 +0100
  12500. @@ -420,4 +420,3 @@
  12501. MODULE_LICENSE("Dual BSD/GPL");
  12502. MODULE_DESCRIPTION("FCrypt Cipher Algorithm");
  12503. MODULE_AUTHOR("David Howells <dhowells@redhat.com>");
  12504. -MODULE_ALIAS_CRYPTO("fcrypt");
  12505. diff -Nur linux-3.12.38/crypto/gcm.c linux-rpi/crypto/gcm.c
  12506. --- linux-3.12.38/crypto/gcm.c 2015-02-16 16:15:42.000000000 +0100
  12507. +++ linux-rpi/crypto/gcm.c 2015-03-10 17:26:50.090216695 +0100
  12508. @@ -1441,7 +1441,6 @@
  12509. MODULE_LICENSE("GPL");
  12510. MODULE_DESCRIPTION("Galois/Counter Mode");
  12511. MODULE_AUTHOR("Mikko Herranen <mh1@iki.fi>");
  12512. -MODULE_ALIAS_CRYPTO("gcm_base");
  12513. -MODULE_ALIAS_CRYPTO("rfc4106");
  12514. -MODULE_ALIAS_CRYPTO("rfc4543");
  12515. -MODULE_ALIAS_CRYPTO("gcm");
  12516. +MODULE_ALIAS("gcm_base");
  12517. +MODULE_ALIAS("rfc4106");
  12518. +MODULE_ALIAS("rfc4543");
  12519. diff -Nur linux-3.12.38/crypto/ghash-generic.c linux-rpi/crypto/ghash-generic.c
  12520. --- linux-3.12.38/crypto/ghash-generic.c 2015-02-16 16:15:42.000000000 +0100
  12521. +++ linux-rpi/crypto/ghash-generic.c 2015-03-10 17:26:50.090216695 +0100
  12522. @@ -172,5 +172,4 @@
  12523. MODULE_LICENSE("GPL");
  12524. MODULE_DESCRIPTION("GHASH Message Digest Algorithm");
  12525. -MODULE_ALIAS_CRYPTO("ghash");
  12526. -MODULE_ALIAS_CRYPTO("ghash-generic");
  12527. +MODULE_ALIAS("ghash");
  12528. diff -Nur linux-3.12.38/crypto/hmac.c linux-rpi/crypto/hmac.c
  12529. --- linux-3.12.38/crypto/hmac.c 2015-02-16 16:15:42.000000000 +0100
  12530. +++ linux-rpi/crypto/hmac.c 2015-03-10 17:26:50.090216695 +0100
  12531. @@ -271,4 +271,3 @@
  12532. MODULE_LICENSE("GPL");
  12533. MODULE_DESCRIPTION("HMAC hash algorithm");
  12534. -MODULE_ALIAS_CRYPTO("hmac");
  12535. diff -Nur linux-3.12.38/crypto/khazad.c linux-rpi/crypto/khazad.c
  12536. --- linux-3.12.38/crypto/khazad.c 2015-02-16 16:15:42.000000000 +0100
  12537. +++ linux-rpi/crypto/khazad.c 2015-03-10 17:26:50.090216695 +0100
  12538. @@ -880,4 +880,3 @@
  12539. MODULE_LICENSE("GPL");
  12540. MODULE_DESCRIPTION("Khazad Cryptographic Algorithm");
  12541. -MODULE_ALIAS_CRYPTO("khazad");
  12542. diff -Nur linux-3.12.38/crypto/krng.c linux-rpi/crypto/krng.c
  12543. --- linux-3.12.38/crypto/krng.c 2015-02-16 16:15:42.000000000 +0100
  12544. +++ linux-rpi/crypto/krng.c 2015-03-10 17:26:50.090216695 +0100
  12545. @@ -62,5 +62,4 @@
  12546. MODULE_LICENSE("GPL");
  12547. MODULE_DESCRIPTION("Kernel Random Number Generator");
  12548. -MODULE_ALIAS_CRYPTO("stdrng");
  12549. -MODULE_ALIAS_CRYPTO("krng");
  12550. +MODULE_ALIAS("stdrng");
  12551. diff -Nur linux-3.12.38/crypto/lrw.c linux-rpi/crypto/lrw.c
  12552. --- linux-3.12.38/crypto/lrw.c 2015-02-16 16:15:42.000000000 +0100
  12553. +++ linux-rpi/crypto/lrw.c 2015-03-10 17:26:50.090216695 +0100
  12554. @@ -400,4 +400,3 @@
  12555. MODULE_LICENSE("GPL");
  12556. MODULE_DESCRIPTION("LRW block cipher mode");
  12557. -MODULE_ALIAS_CRYPTO("lrw");
  12558. diff -Nur linux-3.12.38/crypto/lz4.c linux-rpi/crypto/lz4.c
  12559. --- linux-3.12.38/crypto/lz4.c 2015-02-16 16:15:42.000000000 +0100
  12560. +++ linux-rpi/crypto/lz4.c 2015-03-10 17:26:50.090216695 +0100
  12561. @@ -104,4 +104,3 @@
  12562. MODULE_LICENSE("GPL");
  12563. MODULE_DESCRIPTION("LZ4 Compression Algorithm");
  12564. -MODULE_ALIAS_CRYPTO("lz4");
  12565. diff -Nur linux-3.12.38/crypto/lz4hc.c linux-rpi/crypto/lz4hc.c
  12566. --- linux-3.12.38/crypto/lz4hc.c 2015-02-16 16:15:42.000000000 +0100
  12567. +++ linux-rpi/crypto/lz4hc.c 2015-03-10 17:26:50.090216695 +0100
  12568. @@ -104,4 +104,3 @@
  12569. MODULE_LICENSE("GPL");
  12570. MODULE_DESCRIPTION("LZ4HC Compression Algorithm");
  12571. -MODULE_ALIAS_CRYPTO("lz4hc");
  12572. diff -Nur linux-3.12.38/crypto/lzo.c linux-rpi/crypto/lzo.c
  12573. --- linux-3.12.38/crypto/lzo.c 2015-02-16 16:15:42.000000000 +0100
  12574. +++ linux-rpi/crypto/lzo.c 2015-03-10 17:26:50.090216695 +0100
  12575. @@ -103,4 +103,3 @@
  12576. MODULE_LICENSE("GPL");
  12577. MODULE_DESCRIPTION("LZO Compression Algorithm");
  12578. -MODULE_ALIAS_CRYPTO("lzo");
  12579. diff -Nur linux-3.12.38/crypto/md4.c linux-rpi/crypto/md4.c
  12580. --- linux-3.12.38/crypto/md4.c 2015-02-16 16:15:42.000000000 +0100
  12581. +++ linux-rpi/crypto/md4.c 2015-03-10 17:26:50.090216695 +0100
  12582. @@ -255,4 +255,4 @@
  12583. MODULE_LICENSE("GPL");
  12584. MODULE_DESCRIPTION("MD4 Message Digest Algorithm");
  12585. -MODULE_ALIAS_CRYPTO("md4");
  12586. +
  12587. diff -Nur linux-3.12.38/crypto/md5.c linux-rpi/crypto/md5.c
  12588. --- linux-3.12.38/crypto/md5.c 2015-02-16 16:15:42.000000000 +0100
  12589. +++ linux-rpi/crypto/md5.c 2015-03-10 17:26:50.090216695 +0100
  12590. @@ -168,4 +168,3 @@
  12591. MODULE_LICENSE("GPL");
  12592. MODULE_DESCRIPTION("MD5 Message Digest Algorithm");
  12593. -MODULE_ALIAS_CRYPTO("md5");
  12594. diff -Nur linux-3.12.38/crypto/michael_mic.c linux-rpi/crypto/michael_mic.c
  12595. --- linux-3.12.38/crypto/michael_mic.c 2015-02-16 16:15:42.000000000 +0100
  12596. +++ linux-rpi/crypto/michael_mic.c 2015-03-10 17:26:50.090216695 +0100
  12597. @@ -184,4 +184,3 @@
  12598. MODULE_LICENSE("GPL v2");
  12599. MODULE_DESCRIPTION("Michael MIC");
  12600. MODULE_AUTHOR("Jouni Malinen <j@w1.fi>");
  12601. -MODULE_ALIAS_CRYPTO("michael_mic");
  12602. diff -Nur linux-3.12.38/crypto/pcbc.c linux-rpi/crypto/pcbc.c
  12603. --- linux-3.12.38/crypto/pcbc.c 2015-02-16 16:15:42.000000000 +0100
  12604. +++ linux-rpi/crypto/pcbc.c 2015-03-10 17:26:50.090216695 +0100
  12605. @@ -295,4 +295,3 @@
  12606. MODULE_LICENSE("GPL");
  12607. MODULE_DESCRIPTION("PCBC block cipher algorithm");
  12608. -MODULE_ALIAS_CRYPTO("pcbc");
  12609. diff -Nur linux-3.12.38/crypto/pcrypt.c linux-rpi/crypto/pcrypt.c
  12610. --- linux-3.12.38/crypto/pcrypt.c 2015-02-16 16:15:42.000000000 +0100
  12611. +++ linux-rpi/crypto/pcrypt.c 2015-03-10 17:26:50.090216695 +0100
  12612. @@ -565,4 +565,3 @@
  12613. MODULE_LICENSE("GPL");
  12614. MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>");
  12615. MODULE_DESCRIPTION("Parallel crypto wrapper");
  12616. -MODULE_ALIAS_CRYPTO("pcrypt");
  12617. diff -Nur linux-3.12.38/crypto/rmd128.c linux-rpi/crypto/rmd128.c
  12618. --- linux-3.12.38/crypto/rmd128.c 2015-02-16 16:15:42.000000000 +0100
  12619. +++ linux-rpi/crypto/rmd128.c 2015-03-10 17:26:50.090216695 +0100
  12620. @@ -327,4 +327,3 @@
  12621. MODULE_LICENSE("GPL");
  12622. MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
  12623. MODULE_DESCRIPTION("RIPEMD-128 Message Digest");
  12624. -MODULE_ALIAS_CRYPTO("rmd128");
  12625. diff -Nur linux-3.12.38/crypto/rmd160.c linux-rpi/crypto/rmd160.c
  12626. --- linux-3.12.38/crypto/rmd160.c 2015-02-16 16:15:42.000000000 +0100
  12627. +++ linux-rpi/crypto/rmd160.c 2015-03-10 17:26:50.090216695 +0100
  12628. @@ -371,4 +371,3 @@
  12629. MODULE_LICENSE("GPL");
  12630. MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
  12631. MODULE_DESCRIPTION("RIPEMD-160 Message Digest");
  12632. -MODULE_ALIAS_CRYPTO("rmd160");
  12633. diff -Nur linux-3.12.38/crypto/rmd256.c linux-rpi/crypto/rmd256.c
  12634. --- linux-3.12.38/crypto/rmd256.c 2015-02-16 16:15:42.000000000 +0100
  12635. +++ linux-rpi/crypto/rmd256.c 2015-03-10 17:26:50.090216695 +0100
  12636. @@ -346,4 +346,3 @@
  12637. MODULE_LICENSE("GPL");
  12638. MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
  12639. MODULE_DESCRIPTION("RIPEMD-256 Message Digest");
  12640. -MODULE_ALIAS_CRYPTO("rmd256");
  12641. diff -Nur linux-3.12.38/crypto/rmd320.c linux-rpi/crypto/rmd320.c
  12642. --- linux-3.12.38/crypto/rmd320.c 2015-02-16 16:15:42.000000000 +0100
  12643. +++ linux-rpi/crypto/rmd320.c 2015-03-10 17:26:50.090216695 +0100
  12644. @@ -395,4 +395,3 @@
  12645. MODULE_LICENSE("GPL");
  12646. MODULE_AUTHOR("Adrian-Ken Rueegsegger <ken@codelabs.ch>");
  12647. MODULE_DESCRIPTION("RIPEMD-320 Message Digest");
  12648. -MODULE_ALIAS_CRYPTO("rmd320");
  12649. diff -Nur linux-3.12.38/crypto/salsa20_generic.c linux-rpi/crypto/salsa20_generic.c
  12650. --- linux-3.12.38/crypto/salsa20_generic.c 2015-02-16 16:15:42.000000000 +0100
  12651. +++ linux-rpi/crypto/salsa20_generic.c 2015-03-10 17:26:50.090216695 +0100
  12652. @@ -248,5 +248,4 @@
  12653. MODULE_LICENSE("GPL");
  12654. MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm");
  12655. -MODULE_ALIAS_CRYPTO("salsa20");
  12656. -MODULE_ALIAS_CRYPTO("salsa20-generic");
  12657. +MODULE_ALIAS("salsa20");
  12658. diff -Nur linux-3.12.38/crypto/seed.c linux-rpi/crypto/seed.c
  12659. --- linux-3.12.38/crypto/seed.c 2015-02-16 16:15:42.000000000 +0100
  12660. +++ linux-rpi/crypto/seed.c 2015-03-10 17:26:50.090216695 +0100
  12661. @@ -476,4 +476,3 @@
  12662. MODULE_DESCRIPTION("SEED Cipher Algorithm");
  12663. MODULE_LICENSE("GPL");
  12664. MODULE_AUTHOR("Hye-Shik Chang <perky@FreeBSD.org>, Kim Hyun <hkim@kisa.or.kr>");
  12665. -MODULE_ALIAS_CRYPTO("seed");
  12666. diff -Nur linux-3.12.38/crypto/seqiv.c linux-rpi/crypto/seqiv.c
  12667. --- linux-3.12.38/crypto/seqiv.c 2015-02-16 16:15:42.000000000 +0100
  12668. +++ linux-rpi/crypto/seqiv.c 2015-03-10 17:26:50.090216695 +0100
  12669. @@ -362,4 +362,3 @@
  12670. MODULE_LICENSE("GPL");
  12671. MODULE_DESCRIPTION("Sequence Number IV Generator");
  12672. -MODULE_ALIAS_CRYPTO("seqiv");
  12673. diff -Nur linux-3.12.38/crypto/serpent_generic.c linux-rpi/crypto/serpent_generic.c
  12674. --- linux-3.12.38/crypto/serpent_generic.c 2015-02-16 16:15:42.000000000 +0100
  12675. +++ linux-rpi/crypto/serpent_generic.c 2015-03-10 17:26:50.090216695 +0100
  12676. @@ -665,6 +665,5 @@
  12677. MODULE_LICENSE("GPL");
  12678. MODULE_DESCRIPTION("Serpent and tnepres (kerneli compatible serpent reversed) Cipher Algorithm");
  12679. MODULE_AUTHOR("Dag Arne Osvik <osvik@ii.uib.no>");
  12680. -MODULE_ALIAS_CRYPTO("tnepres");
  12681. -MODULE_ALIAS_CRYPTO("serpent");
  12682. -MODULE_ALIAS_CRYPTO("serpent-generic");
  12683. +MODULE_ALIAS("tnepres");
  12684. +MODULE_ALIAS("serpent");
  12685. diff -Nur linux-3.12.38/crypto/sha1_generic.c linux-rpi/crypto/sha1_generic.c
  12686. --- linux-3.12.38/crypto/sha1_generic.c 2015-02-16 16:15:42.000000000 +0100
  12687. +++ linux-rpi/crypto/sha1_generic.c 2015-03-10 17:26:50.090216695 +0100
  12688. @@ -153,5 +153,4 @@
  12689. MODULE_LICENSE("GPL");
  12690. MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
  12691. -MODULE_ALIAS_CRYPTO("sha1");
  12692. -MODULE_ALIAS_CRYPTO("sha1-generic");
  12693. +MODULE_ALIAS("sha1");
  12694. diff -Nur linux-3.12.38/crypto/sha256_generic.c linux-rpi/crypto/sha256_generic.c
  12695. --- linux-3.12.38/crypto/sha256_generic.c 2015-02-16 16:15:42.000000000 +0100
  12696. +++ linux-rpi/crypto/sha256_generic.c 2015-03-10 17:26:50.090216695 +0100
  12697. @@ -384,7 +384,5 @@
  12698. MODULE_LICENSE("GPL");
  12699. MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm");
  12700. -MODULE_ALIAS_CRYPTO("sha224");
  12701. -MODULE_ALIAS_CRYPTO("sha224-generic");
  12702. -MODULE_ALIAS_CRYPTO("sha256");
  12703. -MODULE_ALIAS_CRYPTO("sha256-generic");
  12704. +MODULE_ALIAS("sha224");
  12705. +MODULE_ALIAS("sha256");
  12706. diff -Nur linux-3.12.38/crypto/sha512_generic.c linux-rpi/crypto/sha512_generic.c
  12707. --- linux-3.12.38/crypto/sha512_generic.c 2015-02-16 16:15:42.000000000 +0100
  12708. +++ linux-rpi/crypto/sha512_generic.c 2015-03-10 17:26:50.090216695 +0100
  12709. @@ -287,7 +287,5 @@
  12710. MODULE_LICENSE("GPL");
  12711. MODULE_DESCRIPTION("SHA-512 and SHA-384 Secure Hash Algorithms");
  12712. -MODULE_ALIAS_CRYPTO("sha384");
  12713. -MODULE_ALIAS_CRYPTO("sha384-generic");
  12714. -MODULE_ALIAS_CRYPTO("sha512");
  12715. -MODULE_ALIAS_CRYPTO("sha512-generic");
  12716. +MODULE_ALIAS("sha384");
  12717. +MODULE_ALIAS("sha512");
  12718. diff -Nur linux-3.12.38/crypto/tea.c linux-rpi/crypto/tea.c
  12719. --- linux-3.12.38/crypto/tea.c 2015-02-16 16:15:42.000000000 +0100
  12720. +++ linux-rpi/crypto/tea.c 2015-03-10 17:26:50.090216695 +0100
  12721. @@ -270,9 +270,8 @@
  12722. crypto_unregister_algs(tea_algs, ARRAY_SIZE(tea_algs));
  12723. }
  12724. -MODULE_ALIAS_CRYPTO("tea");
  12725. -MODULE_ALIAS_CRYPTO("xtea");
  12726. -MODULE_ALIAS_CRYPTO("xeta");
  12727. +MODULE_ALIAS("xtea");
  12728. +MODULE_ALIAS("xeta");
  12729. module_init(tea_mod_init);
  12730. module_exit(tea_mod_fini);
  12731. diff -Nur linux-3.12.38/crypto/tgr192.c linux-rpi/crypto/tgr192.c
  12732. --- linux-3.12.38/crypto/tgr192.c 2015-02-16 16:15:42.000000000 +0100
  12733. +++ linux-rpi/crypto/tgr192.c 2015-03-10 17:26:50.094216695 +0100
  12734. @@ -676,9 +676,8 @@
  12735. crypto_unregister_shashes(tgr_algs, ARRAY_SIZE(tgr_algs));
  12736. }
  12737. -MODULE_ALIAS_CRYPTO("tgr192");
  12738. -MODULE_ALIAS_CRYPTO("tgr160");
  12739. -MODULE_ALIAS_CRYPTO("tgr128");
  12740. +MODULE_ALIAS("tgr160");
  12741. +MODULE_ALIAS("tgr128");
  12742. module_init(tgr192_mod_init);
  12743. module_exit(tgr192_mod_fini);
  12744. diff -Nur linux-3.12.38/crypto/twofish_generic.c linux-rpi/crypto/twofish_generic.c
  12745. --- linux-3.12.38/crypto/twofish_generic.c 2015-02-16 16:15:42.000000000 +0100
  12746. +++ linux-rpi/crypto/twofish_generic.c 2015-03-10 17:26:50.094216695 +0100
  12747. @@ -211,5 +211,4 @@
  12748. MODULE_LICENSE("GPL");
  12749. MODULE_DESCRIPTION ("Twofish Cipher Algorithm");
  12750. -MODULE_ALIAS_CRYPTO("twofish");
  12751. -MODULE_ALIAS_CRYPTO("twofish-generic");
  12752. +MODULE_ALIAS("twofish");
  12753. diff -Nur linux-3.12.38/crypto/vmac.c linux-rpi/crypto/vmac.c
  12754. --- linux-3.12.38/crypto/vmac.c 2015-02-16 16:15:42.000000000 +0100
  12755. +++ linux-rpi/crypto/vmac.c 2015-03-10 17:26:50.094216695 +0100
  12756. @@ -713,4 +713,3 @@
  12757. MODULE_LICENSE("GPL");
  12758. MODULE_DESCRIPTION("VMAC hash algorithm");
  12759. -MODULE_ALIAS_CRYPTO("vmac");
  12760. diff -Nur linux-3.12.38/crypto/wp512.c linux-rpi/crypto/wp512.c
  12761. --- linux-3.12.38/crypto/wp512.c 2015-02-16 16:15:42.000000000 +0100
  12762. +++ linux-rpi/crypto/wp512.c 2015-03-10 17:26:50.098216695 +0100
  12763. @@ -1167,9 +1167,8 @@
  12764. crypto_unregister_shashes(wp_algs, ARRAY_SIZE(wp_algs));
  12765. }
  12766. -MODULE_ALIAS_CRYPTO("wp512");
  12767. -MODULE_ALIAS_CRYPTO("wp384");
  12768. -MODULE_ALIAS_CRYPTO("wp256");
  12769. +MODULE_ALIAS("wp384");
  12770. +MODULE_ALIAS("wp256");
  12771. module_init(wp512_mod_init);
  12772. module_exit(wp512_mod_fini);
  12773. diff -Nur linux-3.12.38/crypto/xcbc.c linux-rpi/crypto/xcbc.c
  12774. --- linux-3.12.38/crypto/xcbc.c 2015-02-16 16:15:42.000000000 +0100
  12775. +++ linux-rpi/crypto/xcbc.c 2015-03-10 17:26:50.098216695 +0100
  12776. @@ -286,4 +286,3 @@
  12777. MODULE_LICENSE("GPL");
  12778. MODULE_DESCRIPTION("XCBC keyed hash algorithm");
  12779. -MODULE_ALIAS_CRYPTO("xcbc");
  12780. diff -Nur linux-3.12.38/crypto/xts.c linux-rpi/crypto/xts.c
  12781. --- linux-3.12.38/crypto/xts.c 2015-02-16 16:15:42.000000000 +0100
  12782. +++ linux-rpi/crypto/xts.c 2015-03-10 17:26:50.098216695 +0100
  12783. @@ -362,4 +362,3 @@
  12784. MODULE_LICENSE("GPL");
  12785. MODULE_DESCRIPTION("XTS block cipher mode");
  12786. -MODULE_ALIAS_CRYPTO("xts");
  12787. diff -Nur linux-3.12.38/crypto/zlib.c linux-rpi/crypto/zlib.c
  12788. --- linux-3.12.38/crypto/zlib.c 2015-02-16 16:15:42.000000000 +0100
  12789. +++ linux-rpi/crypto/zlib.c 2015-03-10 17:26:50.098216695 +0100
  12790. @@ -378,4 +378,3 @@
  12791. MODULE_LICENSE("GPL");
  12792. MODULE_DESCRIPTION("Zlib Compression Algorithm");
  12793. MODULE_AUTHOR("Sony Corporation");
  12794. -MODULE_ALIAS_CRYPTO("zlib");
  12795. diff -Nur linux-3.12.38/Documentation/kernel-parameters.txt linux-rpi/Documentation/kernel-parameters.txt
  12796. --- linux-3.12.38/Documentation/kernel-parameters.txt 2015-02-16 16:15:42.000000000 +0100
  12797. +++ linux-rpi/Documentation/kernel-parameters.txt 2015-03-10 17:26:49.638216698 +0100
  12798. @@ -1119,7 +1119,6 @@
  12799. i8042.notimeout [HW] Ignore timeout condition signalled by controller
  12800. i8042.reset [HW] Reset the controller during init and cleanup
  12801. i8042.unlock [HW] Unlock (ignore) the keylock
  12802. - i8042.kbdreset [HW] Reset device connected to KBD port
  12803. i810= [HW,DRM]
  12804. diff -Nur linux-3.12.38/Documentation/ramoops.txt linux-rpi/Documentation/ramoops.txt
  12805. --- linux-3.12.38/Documentation/ramoops.txt 2015-02-16 16:15:42.000000000 +0100
  12806. +++ linux-rpi/Documentation/ramoops.txt 2015-03-10 17:26:49.646216698 +0100
  12807. @@ -14,19 +14,11 @@
  12808. 1. Ramoops concepts
  12809. -Ramoops uses a predefined memory area to store the dump. The start and size
  12810. -and type of the memory area are set using three variables:
  12811. +Ramoops uses a predefined memory area to store the dump. The start and size of
  12812. +the memory area are set using two variables:
  12813. * "mem_address" for the start
  12814. * "mem_size" for the size. The memory size will be rounded down to a
  12815. power of two.
  12816. - * "mem_type" to specifiy if the memory type (default is pgprot_writecombine).
  12817. -
  12818. -Typically the default value of mem_type=0 should be used as that sets the pstore
  12819. -mapping to pgprot_writecombine. Setting mem_type=1 attempts to use
  12820. -pgprot_noncached, which only works on some platforms. This is because pstore
  12821. -depends on atomic operations. At least on ARM, pgprot_noncached causes the
  12822. -memory to be mapped strongly ordered, and atomic operations on strongly ordered
  12823. -memory are implementation defined, and won't work on many ARMs such as omaps.
  12824. The memory area is divided into "record_size" chunks (also rounded down to
  12825. power of two) and each oops/panic writes a "record_size" chunk of
  12826. @@ -63,7 +55,6 @@
  12827. static struct ramoops_platform_data ramoops_data = {
  12828. .mem_size = <...>,
  12829. .mem_address = <...>,
  12830. - .mem_type = <...>,
  12831. .record_size = <...>,
  12832. .dump_oops = <...>,
  12833. .ecc = <...>,
  12834. diff -Nur linux-3.12.38/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  12835. --- linux-3.12.38/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  12836. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2015-03-09 10:39:28.418893747 +0100
  12837. @@ -0,0 +1,60 @@
  12838. +
  12839. +BCM2835 (aka Raspberry Pi) V4L2 driver
  12840. +======================================
  12841. +
  12842. +1. Copyright
  12843. +============
  12844. +
  12845. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12846. +
  12847. +2. License
  12848. +==========
  12849. +
  12850. +This program is free software; you can redistribute it and/or modify
  12851. +it under the terms of the GNU General Public License as published by
  12852. +the Free Software Foundation; either version 2 of the License, or
  12853. +(at your option) any later version.
  12854. +
  12855. +This program is distributed in the hope that it will be useful,
  12856. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  12857. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12858. +GNU General Public License for more details.
  12859. +
  12860. +You should have received a copy of the GNU General Public License
  12861. +along with this program; if not, write to the Free Software
  12862. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  12863. +
  12864. +3. Quick Start
  12865. +==============
  12866. +
  12867. +You need a version 1.0 or later of v4l2-ctl, available from:
  12868. + git://git.linuxtv.org/v4l-utils.git
  12869. +
  12870. +$ sudo modprobe bcm2835-v4l2
  12871. +
  12872. +Turn on the overlay:
  12873. +
  12874. +$ v4l2-ctl --overlay=1
  12875. +
  12876. +Turn off the overlay:
  12877. +
  12878. +$ v4l2-ctl --overlay=0
  12879. +
  12880. +Set the capture format for video:
  12881. +
  12882. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  12883. +
  12884. +(Note: 1088 not 1080).
  12885. +
  12886. +Capture:
  12887. +
  12888. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  12889. +
  12890. +Stills capture:
  12891. +
  12892. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  12893. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  12894. +
  12895. +List of available formats:
  12896. +
  12897. +$ v4l2-ctl --list-formats
  12898. diff -Nur linux-3.12.38/drivers/acpi/osl.c linux-rpi/drivers/acpi/osl.c
  12899. --- linux-3.12.38/drivers/acpi/osl.c 2015-02-16 16:15:42.000000000 +0100
  12900. +++ linux-rpi/drivers/acpi/osl.c 2015-03-10 17:26:50.118216695 +0100
  12901. @@ -421,7 +421,7 @@
  12902. static void acpi_os_map_cleanup(struct acpi_ioremap *map)
  12903. {
  12904. if (!map->refcount) {
  12905. - synchronize_rcu_expedited();
  12906. + synchronize_rcu();
  12907. acpi_unmap(map->phys, map->virt);
  12908. kfree(map);
  12909. }
  12910. @@ -1748,16 +1748,6 @@
  12911. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  12912. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
  12913. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
  12914. - if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) {
  12915. - /*
  12916. - * Use acpi_os_map_generic_address to pre-map the reset
  12917. - * register if it's in system memory.
  12918. - */
  12919. - int rv;
  12920. -
  12921. - rv = acpi_os_map_generic_address(&acpi_gbl_FADT.reset_register);
  12922. - pr_debug(PREFIX "%s: map reset_reg status %d\n", __func__, rv);
  12923. - }
  12924. return AE_OK;
  12925. }
  12926. @@ -1786,8 +1776,6 @@
  12927. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
  12928. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  12929. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  12930. - if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)
  12931. - acpi_os_unmap_generic_address(&acpi_gbl_FADT.reset_register);
  12932. destroy_workqueue(kacpid_wq);
  12933. destroy_workqueue(kacpi_notify_wq);
  12934. diff -Nur linux-3.12.38/drivers/ata/libata-sff.c linux-rpi/drivers/ata/libata-sff.c
  12935. --- linux-3.12.38/drivers/ata/libata-sff.c 2015-02-16 16:15:42.000000000 +0100
  12936. +++ linux-rpi/drivers/ata/libata-sff.c 2015-03-10 17:26:50.126216695 +0100
  12937. @@ -1333,19 +1333,7 @@
  12938. DPRINTK("ENTER\n");
  12939. cancel_delayed_work_sync(&ap->sff_pio_task);
  12940. -
  12941. - /*
  12942. - * We wanna reset the HSM state to IDLE. If we do so without
  12943. - * grabbing the port lock, critical sections protected by it which
  12944. - * expect the HSM state to stay stable may get surprised. For
  12945. - * example, we may set IDLE in between the time
  12946. - * __ata_sff_port_intr() checks for HSM_ST_IDLE and before it calls
  12947. - * ata_sff_hsm_move() causing ata_sff_hsm_move() to BUG().
  12948. - */
  12949. - spin_lock_irq(ap->lock);
  12950. ap->hsm_task_state = HSM_ST_IDLE;
  12951. - spin_unlock_irq(ap->lock);
  12952. -
  12953. ap->sff_pio_task_link = NULL;
  12954. if (ata_msg_ctl(ap))
  12955. diff -Nur linux-3.12.38/drivers/ata/sata_dwc_460ex.c linux-rpi/drivers/ata/sata_dwc_460ex.c
  12956. --- linux-3.12.38/drivers/ata/sata_dwc_460ex.c 2015-02-16 16:15:42.000000000 +0100
  12957. +++ linux-rpi/drivers/ata/sata_dwc_460ex.c 2015-03-10 17:26:50.134216695 +0100
  12958. @@ -797,7 +797,7 @@
  12959. if (err) {
  12960. dev_err(host_pvt.dwc_dev, "%s: dma_request_interrupts returns"
  12961. " %d\n", __func__, err);
  12962. - return err;
  12963. + goto error_out;
  12964. }
  12965. /* Enabe DMA */
  12966. @@ -808,6 +808,11 @@
  12967. sata_dma_regs);
  12968. return 0;
  12969. +
  12970. +error_out:
  12971. + dma_dwc_exit(hsdev);
  12972. +
  12973. + return err;
  12974. }
  12975. static int sata_dwc_scr_read(struct ata_link *link, unsigned int scr, u32 *val)
  12976. @@ -1657,7 +1662,7 @@
  12977. char *ver = (char *)&versionr;
  12978. u8 *base = NULL;
  12979. int err = 0;
  12980. - int irq;
  12981. + int irq, rc;
  12982. struct ata_host *host;
  12983. struct ata_port_info pi = sata_dwc_port_info[0];
  12984. const struct ata_port_info *ppi[] = { &pi, NULL };
  12985. @@ -1720,7 +1725,7 @@
  12986. if (irq == NO_IRQ) {
  12987. dev_err(&ofdev->dev, "no SATA DMA irq\n");
  12988. err = -ENODEV;
  12989. - goto error_iomap;
  12990. + goto error_out;
  12991. }
  12992. /* Get physical SATA DMA register base address */
  12993. @@ -1729,16 +1734,14 @@
  12994. dev_err(&ofdev->dev, "ioremap failed for AHBDMA register"
  12995. " address\n");
  12996. err = -ENODEV;
  12997. - goto error_iomap;
  12998. + goto error_out;
  12999. }
  13000. /* Save dev for later use in dev_xxx() routines */
  13001. host_pvt.dwc_dev = &ofdev->dev;
  13002. /* Initialize AHB DMAC */
  13003. - err = dma_dwc_init(hsdev, irq);
  13004. - if (err)
  13005. - goto error_dma_iomap;
  13006. + dma_dwc_init(hsdev, irq);
  13007. /* Enable SATA Interrupts */
  13008. sata_dwc_enable_interrupts(hsdev);
  13009. @@ -1756,8 +1759,9 @@
  13010. * device discovery process, invoking our port_start() handler &
  13011. * error_handler() to execute a dummy Softreset EH session
  13012. */
  13013. - err = ata_host_activate(host, irq, sata_dwc_isr, 0, &sata_dwc_sht);
  13014. - if (err)
  13015. + rc = ata_host_activate(host, irq, sata_dwc_isr, 0, &sata_dwc_sht);
  13016. +
  13017. + if (rc != 0)
  13018. dev_err(&ofdev->dev, "failed to activate host");
  13019. dev_set_drvdata(&ofdev->dev, host);
  13020. @@ -1766,8 +1770,7 @@
  13021. error_out:
  13022. /* Free SATA DMA resources */
  13023. dma_dwc_exit(hsdev);
  13024. -error_dma_iomap:
  13025. - iounmap((void __iomem *)host_pvt.sata_dma_regs);
  13026. +
  13027. error_iomap:
  13028. iounmap(base);
  13029. error_kmalloc:
  13030. @@ -1788,7 +1791,6 @@
  13031. /* Free SATA DMA resources */
  13032. dma_dwc_exit(hsdev);
  13033. - iounmap((void __iomem *)host_pvt.sata_dma_regs);
  13034. iounmap(hsdev->reg_base);
  13035. kfree(hsdev);
  13036. kfree(host);
  13037. diff -Nur linux-3.12.38/drivers/base/bus.c linux-rpi/drivers/base/bus.c
  13038. --- linux-3.12.38/drivers/base/bus.c 2015-02-16 16:15:42.000000000 +0100
  13039. +++ linux-rpi/drivers/base/bus.c 2015-03-10 17:26:50.138216695 +0100
  13040. @@ -243,15 +243,13 @@
  13041. const char *buf, size_t count)
  13042. {
  13043. struct device *dev;
  13044. - int err = -EINVAL;
  13045. dev = bus_find_device_by_name(bus, NULL, buf);
  13046. if (!dev)
  13047. return -ENODEV;
  13048. - if (bus_rescan_devices_helper(dev, NULL) == 0)
  13049. - err = count;
  13050. - put_device(dev);
  13051. - return err;
  13052. + if (bus_rescan_devices_helper(dev, NULL) != 0)
  13053. + return -EINVAL;
  13054. + return count;
  13055. }
  13056. static struct device *next_device(struct klist_iter *i)
  13057. diff -Nur linux-3.12.38/drivers/block/drbd/drbd_req.c linux-rpi/drivers/block/drbd/drbd_req.c
  13058. --- linux-3.12.38/drivers/block/drbd/drbd_req.c 2015-02-16 16:15:42.000000000 +0100
  13059. +++ linux-rpi/drivers/block/drbd/drbd_req.c 2015-03-10 17:26:50.150216694 +0100
  13060. @@ -1309,7 +1309,6 @@
  13061. struct request_queue * const b =
  13062. mdev->ldev->backing_bdev->bd_disk->queue;
  13063. if (b->merge_bvec_fn) {
  13064. - bvm->bi_bdev = mdev->ldev->backing_bdev;
  13065. backing_limit = b->merge_bvec_fn(b, bvm, bvec);
  13066. limit = min(limit, backing_limit);
  13067. }
  13068. diff -Nur linux-3.12.38/drivers/block/rbd.c linux-rpi/drivers/block/rbd.c
  13069. --- linux-3.12.38/drivers/block/rbd.c 2015-02-16 16:15:42.000000000 +0100
  13070. +++ linux-rpi/drivers/block/rbd.c 2015-03-10 17:26:50.158216694 +0100
  13071. @@ -1945,26 +1945,32 @@
  13072. * If an image has a non-zero parent overlap, get a reference to its
  13073. * parent.
  13074. *
  13075. + * We must get the reference before checking for the overlap to
  13076. + * coordinate properly with zeroing the parent overlap in
  13077. + * rbd_dev_v2_parent_info() when an image gets flattened. We
  13078. + * drop it again if there is no overlap.
  13079. + *
  13080. * Returns true if the rbd device has a parent with a non-zero
  13081. * overlap and a reference for it was successfully taken, or
  13082. * false otherwise.
  13083. */
  13084. static bool rbd_dev_parent_get(struct rbd_device *rbd_dev)
  13085. {
  13086. - int counter = 0;
  13087. + int counter;
  13088. if (!rbd_dev->parent_spec)
  13089. return false;
  13090. - down_read(&rbd_dev->header_rwsem);
  13091. - if (rbd_dev->parent_overlap)
  13092. - counter = atomic_inc_return_safe(&rbd_dev->parent_ref);
  13093. - up_read(&rbd_dev->header_rwsem);
  13094. + counter = atomic_inc_return_safe(&rbd_dev->parent_ref);
  13095. + if (counter > 0 && rbd_dev->parent_overlap)
  13096. + return true;
  13097. +
  13098. + /* Image was flattened, but parent is not yet torn down */
  13099. if (counter < 0)
  13100. rbd_warn(rbd_dev, "parent reference overflow\n");
  13101. - return counter > 0;
  13102. + return false;
  13103. }
  13104. /*
  13105. @@ -2137,6 +2143,7 @@
  13106. rbd_assert(img_request->obj_request_count > 0);
  13107. rbd_assert(which != BAD_WHICH);
  13108. rbd_assert(which < img_request->obj_request_count);
  13109. + rbd_assert(which >= img_request->next_completion);
  13110. spin_lock_irq(&img_request->completion_lock);
  13111. if (which != img_request->next_completion)
  13112. @@ -3887,6 +3894,7 @@
  13113. */
  13114. if (rbd_dev->parent_overlap) {
  13115. rbd_dev->parent_overlap = 0;
  13116. + smp_mb();
  13117. rbd_dev_parent_put(rbd_dev);
  13118. pr_info("%s: clone image has been flattened\n",
  13119. rbd_dev->disk->disk_name);
  13120. @@ -3930,6 +3938,7 @@
  13121. * treat it specially.
  13122. */
  13123. rbd_dev->parent_overlap = overlap;
  13124. + smp_mb();
  13125. if (!overlap) {
  13126. /* A null parent_spec indicates it's the initial probe */
  13127. @@ -4773,7 +4782,10 @@
  13128. {
  13129. struct rbd_image_header *header;
  13130. - rbd_dev_parent_put(rbd_dev);
  13131. + /* Drop parent reference unless it's already been done (or none) */
  13132. +
  13133. + if (rbd_dev->parent_overlap)
  13134. + rbd_dev_parent_put(rbd_dev);
  13135. /* Free dynamic fields from the header, then zero it out */
  13136. diff -Nur linux-3.12.38/drivers/bluetooth/ath3k.c linux-rpi/drivers/bluetooth/ath3k.c
  13137. --- linux-3.12.38/drivers/bluetooth/ath3k.c 2015-02-16 16:15:42.000000000 +0100
  13138. +++ linux-rpi/drivers/bluetooth/ath3k.c 2015-03-10 17:26:50.158216694 +0100
  13139. @@ -168,8 +168,6 @@
  13140. #define USB_REQ_DFU_DNLOAD 1
  13141. #define BULK_SIZE 4096
  13142. #define FW_HDR_SIZE 20
  13143. -#define TIMEGAP_USEC_MIN 50
  13144. -#define TIMEGAP_USEC_MAX 100
  13145. static int ath3k_load_firmware(struct usb_device *udev,
  13146. const struct firmware *firmware)
  13147. @@ -200,9 +198,6 @@
  13148. count -= 20;
  13149. while (count) {
  13150. - /* workaround the compatibility issue with xHCI controller*/
  13151. - usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
  13152. -
  13153. size = min_t(uint, count, BULK_SIZE);
  13154. pipe = usb_sndbulkpipe(udev, 0x02);
  13155. memcpy(send_buf, firmware->data + sent, size);
  13156. @@ -299,9 +294,6 @@
  13157. count -= size;
  13158. while (count) {
  13159. - /* workaround the compatibility issue with xHCI controller*/
  13160. - usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
  13161. -
  13162. size = min_t(uint, count, BULK_SIZE);
  13163. pipe = usb_sndbulkpipe(udev, 0x02);
  13164. diff -Nur linux-3.12.38/drivers/bus/mvebu-mbus.c linux-rpi/drivers/bus/mvebu-mbus.c
  13165. --- linux-3.12.38/drivers/bus/mvebu-mbus.c 2015-02-16 16:15:42.000000000 +0100
  13166. +++ linux-rpi/drivers/bus/mvebu-mbus.c 2015-03-10 17:26:50.162216694 +0100
  13167. @@ -181,25 +181,12 @@
  13168. }
  13169. /* Checks whether the given window number is available */
  13170. -
  13171. -/* On Armada XP, 375 and 38x the MBus window 13 has the remap
  13172. - * capability, like windows 0 to 7. However, the mvebu-mbus driver
  13173. - * isn't currently taking into account this special case, which means
  13174. - * that when window 13 is actually used, the remap registers are left
  13175. - * to 0, making the device using this MBus window unavailable. The
  13176. - * quick fix for stable is to not use window 13. A follow up patch
  13177. - * will correctly handle this window.
  13178. -*/
  13179. static int mvebu_mbus_window_is_free(struct mvebu_mbus_state *mbus,
  13180. const int win)
  13181. {
  13182. void __iomem *addr = mbus->mbuswins_base +
  13183. mbus->soc->win_cfg_offset(win);
  13184. u32 ctrl = readl(addr + WIN_CTRL_OFF);
  13185. -
  13186. - if (win == 13)
  13187. - return false;
  13188. -
  13189. return !(ctrl & WIN_CTRL_ENABLE);
  13190. }
  13191. diff -Nur linux-3.12.38/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  13192. --- linux-3.12.38/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  13193. +++ linux-rpi/drivers/char/broadcom/Kconfig 2015-03-09 10:39:29.730893739 +0100
  13194. @@ -0,0 +1,22 @@
  13195. +#
  13196. +# Broadcom char driver config
  13197. +#
  13198. +
  13199. +menuconfig BRCM_CHAR_DRIVERS
  13200. + bool "Broadcom Char Drivers"
  13201. + help
  13202. + Broadcom's char drivers
  13203. +
  13204. +config BCM_VC_CMA
  13205. + bool "Videocore CMA"
  13206. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  13207. + default n
  13208. + help
  13209. + Helper for videocore CMA access.
  13210. +
  13211. +config BCM_VC_SM
  13212. + tristate "VMCS Shared Memory"
  13213. + default n
  13214. + help
  13215. + Support for the VC shared memory on the Broadcom reference
  13216. + design. Uses the VCHIQ stack.
  13217. diff -Nur linux-3.12.38/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  13218. --- linux-3.12.38/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  13219. +++ linux-rpi/drivers/char/broadcom/Makefile 2015-03-09 10:39:29.730893739 +0100
  13220. @@ -0,0 +1,2 @@
  13221. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  13222. +obj-$(CONFIG_BCM_VC_SM) += vc_sm/
  13223. diff -Nur linux-3.12.38/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  13224. --- linux-3.12.38/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  13225. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2015-03-09 10:39:29.730893739 +0100
  13226. @@ -0,0 +1,14 @@
  13227. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  13228. +ccflags-y += -Werror
  13229. +ccflags-y += -Iinclude/linux/broadcom
  13230. +ccflags-y += -Idrivers/misc/vc04_services
  13231. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  13232. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  13233. +
  13234. +ccflags-y += -D__KERNEL__
  13235. +ccflags-y += -D__linux__
  13236. +ccflags-y += -Werror
  13237. +
  13238. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  13239. +
  13240. +vc-cma-objs := vc_cma.o
  13241. diff -Nur linux-3.12.38/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  13242. --- linux-3.12.38/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  13243. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2015-03-10 17:26:50.166216694 +0100
  13244. @@ -0,0 +1,1143 @@
  13245. +/**
  13246. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  13247. + *
  13248. + * Redistribution and use in source and binary forms, with or without
  13249. + * modification, are permitted provided that the following conditions
  13250. + * are met:
  13251. + * 1. Redistributions of source code must retain the above copyright
  13252. + * notice, this list of conditions, and the following disclaimer,
  13253. + * without modification.
  13254. + * 2. Redistributions in binary form must reproduce the above copyright
  13255. + * notice, this list of conditions and the following disclaimer in the
  13256. + * documentation and/or other materials provided with the distribution.
  13257. + * 3. The names of the above-listed copyright holders may not be used
  13258. + * to endorse or promote products derived from this software without
  13259. + * specific prior written permission.
  13260. + *
  13261. + * ALTERNATIVELY, this software may be distributed under the terms of the
  13262. + * GNU General Public License ("GPL") version 2, as published by the Free
  13263. + * Software Foundation.
  13264. + *
  13265. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  13266. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  13267. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13268. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  13269. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  13270. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  13271. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  13272. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  13273. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  13274. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  13275. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13276. + */
  13277. +
  13278. +#include <linux/kernel.h>
  13279. +#include <linux/module.h>
  13280. +#include <linux/kthread.h>
  13281. +#include <linux/fs.h>
  13282. +#include <linux/device.h>
  13283. +#include <linux/cdev.h>
  13284. +#include <linux/mm.h>
  13285. +#include <linux/proc_fs.h>
  13286. +#include <linux/seq_file.h>
  13287. +#include <linux/dma-mapping.h>
  13288. +#include <linux/dma-contiguous.h>
  13289. +#include <linux/platform_device.h>
  13290. +#include <linux/uaccess.h>
  13291. +#include <asm/cacheflush.h>
  13292. +
  13293. +#include "vc_cma.h"
  13294. +
  13295. +#include "vchiq_util.h"
  13296. +#include "vchiq_connected.h"
  13297. +//#include "debug_sym.h"
  13298. +//#include "vc_mem.h"
  13299. +
  13300. +#define DRIVER_NAME "vc-cma"
  13301. +
  13302. +#define LOG_DBG(fmt, ...) \
  13303. + if (vc_cma_debug) \
  13304. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  13305. +#define LOG_ERR(fmt, ...) \
  13306. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  13307. +
  13308. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  13309. +#define VC_CMA_VERSION 2
  13310. +
  13311. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  13312. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  13313. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  13314. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  13315. +#define VC_CMA_RESERVE_COUNT_MAX 16
  13316. +
  13317. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  13318. +
  13319. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  13320. +
  13321. +#define loud_error(...) \
  13322. + LOG_ERR("===== " __VA_ARGS__)
  13323. +
  13324. +enum {
  13325. + VC_CMA_MSG_QUIT,
  13326. + VC_CMA_MSG_OPEN,
  13327. + VC_CMA_MSG_TICK,
  13328. + VC_CMA_MSG_ALLOC, /* chunk count */
  13329. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  13330. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  13331. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  13332. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  13333. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  13334. + VC_CMA_MSG_UPDATE_RESERVE,
  13335. + VC_CMA_MSG_MAX
  13336. +};
  13337. +
  13338. +struct cma_msg {
  13339. + unsigned short type;
  13340. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  13341. +};
  13342. +
  13343. +struct vc_cma_reserve_user {
  13344. + unsigned int pid;
  13345. + unsigned int reserve;
  13346. +};
  13347. +
  13348. +/* Device (/dev) related variables */
  13349. +static dev_t vc_cma_devnum;
  13350. +static struct class *vc_cma_class;
  13351. +static struct cdev vc_cma_cdev;
  13352. +static int vc_cma_inited;
  13353. +static int vc_cma_debug;
  13354. +
  13355. +/* Proc entry */
  13356. +static struct proc_dir_entry *vc_cma_proc_entry;
  13357. +
  13358. +phys_addr_t vc_cma_base;
  13359. +struct page *vc_cma_base_page;
  13360. +unsigned int vc_cma_size;
  13361. +EXPORT_SYMBOL(vc_cma_size);
  13362. +unsigned int vc_cma_initial;
  13363. +unsigned int vc_cma_chunks;
  13364. +unsigned int vc_cma_chunks_used;
  13365. +unsigned int vc_cma_chunks_reserved;
  13366. +
  13367. +static int in_loud_error;
  13368. +
  13369. +unsigned int vc_cma_reserve_total;
  13370. +unsigned int vc_cma_reserve_count;
  13371. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  13372. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  13373. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  13374. +
  13375. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  13376. +static struct platform_device vc_cma_device = {
  13377. + .name = "vc-cma",
  13378. + .id = 0,
  13379. + .dev = {
  13380. + .dma_mask = &vc_cma_dma_mask,
  13381. + .coherent_dma_mask = DMA_BIT_MASK(32),
  13382. + },
  13383. +};
  13384. +
  13385. +static VCHIQ_INSTANCE_T cma_instance;
  13386. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  13387. +static VCHIU_QUEUE_T cma_msg_queue;
  13388. +static struct task_struct *cma_worker;
  13389. +
  13390. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  13391. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  13392. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  13393. + VCHIQ_HEADER_T * header,
  13394. + VCHIQ_SERVICE_HANDLE_T service,
  13395. + void *bulk_userdata);
  13396. +static void send_vc_msg(unsigned short type,
  13397. + unsigned short param1, unsigned short param2);
  13398. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  13399. +
  13400. +static int early_vc_cma_mem(char *p)
  13401. +{
  13402. + unsigned int new_size;
  13403. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  13404. + vc_cma_size = memparse(p, &p);
  13405. + vc_cma_initial = vc_cma_size;
  13406. + if (*p == '/')
  13407. + vc_cma_size = memparse(p + 1, &p);
  13408. + if (*p == '@')
  13409. + vc_cma_base = memparse(p + 1, &p);
  13410. +
  13411. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  13412. + & ~(VC_CMA_CHUNK_SIZE - 1);
  13413. + if (new_size > vc_cma_size)
  13414. + vc_cma_size = 0;
  13415. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  13416. + & ~(VC_CMA_CHUNK_SIZE - 1);
  13417. + if (vc_cma_initial > vc_cma_size)
  13418. + vc_cma_initial = vc_cma_size;
  13419. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  13420. + & ~(VC_CMA_CHUNK_SIZE - 1);
  13421. +
  13422. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  13423. + vc_cma_size, (unsigned int)vc_cma_base);
  13424. +
  13425. + return 0;
  13426. +}
  13427. +
  13428. +early_param("vc-cma-mem", early_vc_cma_mem);
  13429. +
  13430. +void vc_cma_early_init(void)
  13431. +{
  13432. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  13433. + if (vc_cma_size) {
  13434. + int rc = platform_device_register(&vc_cma_device);
  13435. + LOG_DBG("platform_device_register -> %d", rc);
  13436. + }
  13437. +}
  13438. +
  13439. +void vc_cma_reserve(void)
  13440. +{
  13441. + /* if vc_cma_size is set, then declare vc CMA area of the same
  13442. + * size from the end of memory
  13443. + */
  13444. + if (vc_cma_size) {
  13445. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  13446. + vc_cma_base, 0) == 0) {
  13447. + } else {
  13448. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  13449. + vc_cma_size, (unsigned int)vc_cma_base);
  13450. + vc_cma_size = 0;
  13451. + }
  13452. + }
  13453. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  13454. +}
  13455. +
  13456. +/****************************************************************************
  13457. +*
  13458. +* vc_cma_open
  13459. +*
  13460. +***************************************************************************/
  13461. +
  13462. +static int vc_cma_open(struct inode *inode, struct file *file)
  13463. +{
  13464. + (void)inode;
  13465. + (void)file;
  13466. +
  13467. + return 0;
  13468. +}
  13469. +
  13470. +/****************************************************************************
  13471. +*
  13472. +* vc_cma_release
  13473. +*
  13474. +***************************************************************************/
  13475. +
  13476. +static int vc_cma_release(struct inode *inode, struct file *file)
  13477. +{
  13478. + (void)inode;
  13479. + (void)file;
  13480. +
  13481. + vc_cma_set_reserve(0, current->tgid);
  13482. +
  13483. + return 0;
  13484. +}
  13485. +
  13486. +/****************************************************************************
  13487. +*
  13488. +* vc_cma_ioctl
  13489. +*
  13490. +***************************************************************************/
  13491. +
  13492. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  13493. +{
  13494. + int rc = 0;
  13495. +
  13496. + (void)cmd;
  13497. + (void)arg;
  13498. +
  13499. + switch (cmd) {
  13500. + case VC_CMA_IOC_RESERVE:
  13501. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  13502. + if (rc >= 0)
  13503. + rc = 0;
  13504. + break;
  13505. + default:
  13506. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  13507. + return -ENOTTY;
  13508. + }
  13509. +
  13510. + return rc;
  13511. +}
  13512. +
  13513. +/****************************************************************************
  13514. +*
  13515. +* File Operations for the driver.
  13516. +*
  13517. +***************************************************************************/
  13518. +
  13519. +static const struct file_operations vc_cma_fops = {
  13520. + .owner = THIS_MODULE,
  13521. + .open = vc_cma_open,
  13522. + .release = vc_cma_release,
  13523. + .unlocked_ioctl = vc_cma_ioctl,
  13524. +};
  13525. +
  13526. +/****************************************************************************
  13527. +*
  13528. +* vc_cma_proc_open
  13529. +*
  13530. +***************************************************************************/
  13531. +
  13532. +static int vc_cma_show_info(struct seq_file *m, void *v)
  13533. +{
  13534. + int i;
  13535. +
  13536. + seq_printf(m, "Videocore CMA:\n");
  13537. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  13538. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  13539. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  13540. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  13541. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  13542. + (int)vc_cma_chunks,
  13543. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  13544. + seq_printf(m, " Used : %4d (%d bytes)\n",
  13545. + (int)vc_cma_chunks_used,
  13546. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  13547. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  13548. + (unsigned int)vc_cma_chunks_reserved,
  13549. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  13550. +
  13551. + for (i = 0; i < vc_cma_reserve_count; i++) {
  13552. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  13553. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  13554. + user->reserve);
  13555. + }
  13556. +
  13557. + seq_printf(m, "\n");
  13558. +
  13559. + return 0;
  13560. +}
  13561. +
  13562. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  13563. +{
  13564. + return single_open(file, vc_cma_show_info, NULL);
  13565. +}
  13566. +
  13567. +/****************************************************************************
  13568. +*
  13569. +* vc_cma_proc_write
  13570. +*
  13571. +***************************************************************************/
  13572. +
  13573. +static int vc_cma_proc_write(struct file *file,
  13574. + const char __user *buffer,
  13575. + size_t size, loff_t *ppos)
  13576. +{
  13577. + int rc = -EFAULT;
  13578. + char input_str[20];
  13579. +
  13580. + memset(input_str, 0, sizeof(input_str));
  13581. +
  13582. + if (size > sizeof(input_str)) {
  13583. + LOG_ERR("%s: input string length too long", __func__);
  13584. + goto out;
  13585. + }
  13586. +
  13587. + if (copy_from_user(input_str, buffer, size - 1)) {
  13588. + LOG_ERR("%s: failed to get input string", __func__);
  13589. + goto out;
  13590. + }
  13591. +#define ALLOC_STR "alloc"
  13592. +#define FREE_STR "free"
  13593. +#define DEBUG_STR "debug"
  13594. +#define RESERVE_STR "reserve"
  13595. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  13596. + int size;
  13597. + char *p = input_str + strlen(ALLOC_STR);
  13598. +
  13599. + while (*p == ' ')
  13600. + p++;
  13601. + size = memparse(p, NULL);
  13602. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  13603. + if (size)
  13604. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  13605. + size / VC_CMA_CHUNK_SIZE, 0);
  13606. + else
  13607. + LOG_ERR("invalid size '%s'", p);
  13608. + rc = size;
  13609. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  13610. + int size;
  13611. + char *p = input_str + strlen(FREE_STR);
  13612. +
  13613. + while (*p == ' ')
  13614. + p++;
  13615. + size = memparse(p, NULL);
  13616. + LOG_ERR("/proc/vc-cma: free %d", size);
  13617. + if (size)
  13618. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  13619. + size / VC_CMA_CHUNK_SIZE, 0);
  13620. + else
  13621. + LOG_ERR("invalid size '%s'", p);
  13622. + rc = size;
  13623. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  13624. + char *p = input_str + strlen(DEBUG_STR);
  13625. + while (*p == ' ')
  13626. + p++;
  13627. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  13628. + vc_cma_debug = 1;
  13629. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  13630. + vc_cma_debug = 0;
  13631. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  13632. + rc = size;
  13633. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  13634. + int size;
  13635. + int reserved;
  13636. + char *p = input_str + strlen(RESERVE_STR);
  13637. + while (*p == ' ')
  13638. + p++;
  13639. + size = memparse(p, NULL);
  13640. +
  13641. + reserved = vc_cma_set_reserve(size, current->tgid);
  13642. + rc = (reserved >= 0) ? size : reserved;
  13643. + }
  13644. +
  13645. +out:
  13646. + return rc;
  13647. +}
  13648. +
  13649. +/****************************************************************************
  13650. +*
  13651. +* File Operations for /proc interface.
  13652. +*
  13653. +***************************************************************************/
  13654. +
  13655. +static const struct file_operations vc_cma_proc_fops = {
  13656. + .open = vc_cma_proc_open,
  13657. + .read = seq_read,
  13658. + .write = vc_cma_proc_write,
  13659. + .llseek = seq_lseek,
  13660. + .release = single_release
  13661. +};
  13662. +
  13663. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  13664. +{
  13665. + struct vc_cma_reserve_user *user = NULL;
  13666. + int delta = 0;
  13667. + int i;
  13668. +
  13669. + if (down_interruptible(&vc_cma_reserve_mutex))
  13670. + return -ERESTARTSYS;
  13671. +
  13672. + for (i = 0; i < vc_cma_reserve_count; i++) {
  13673. + if (pid == vc_cma_reserve_users[i].pid) {
  13674. + user = &vc_cma_reserve_users[i];
  13675. + delta = reserve - user->reserve;
  13676. + if (reserve)
  13677. + user->reserve = reserve;
  13678. + else {
  13679. + /* Remove this entry by copying downwards */
  13680. + while ((i + 1) < vc_cma_reserve_count) {
  13681. + user[0].pid = user[1].pid;
  13682. + user[0].reserve = user[1].reserve;
  13683. + user++;
  13684. + i++;
  13685. + }
  13686. + vc_cma_reserve_count--;
  13687. + user = NULL;
  13688. + }
  13689. + break;
  13690. + }
  13691. + }
  13692. +
  13693. + if (reserve && !user) {
  13694. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  13695. + LOG_ERR("vc-cma: Too many reservations - "
  13696. + "increase CMA_RESERVE_COUNT_MAX");
  13697. + up(&vc_cma_reserve_mutex);
  13698. + return -EBUSY;
  13699. + }
  13700. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  13701. + user->pid = pid;
  13702. + user->reserve = reserve;
  13703. + delta = reserve;
  13704. + vc_cma_reserve_count++;
  13705. + }
  13706. +
  13707. + vc_cma_reserve_total += delta;
  13708. +
  13709. + send_vc_msg(VC_CMA_MSG_RESERVE,
  13710. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  13711. +
  13712. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  13713. +
  13714. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  13715. + reserve, pid, vc_cma_reserve_total);
  13716. +
  13717. + up(&vc_cma_reserve_mutex);
  13718. +
  13719. + return vc_cma_reserve_total;
  13720. +}
  13721. +
  13722. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  13723. + VCHIQ_HEADER_T * header,
  13724. + VCHIQ_SERVICE_HANDLE_T service,
  13725. + void *bulk_userdata)
  13726. +{
  13727. + switch (reason) {
  13728. + case VCHIQ_MESSAGE_AVAILABLE:
  13729. + if (!send_worker_msg(header))
  13730. + return VCHIQ_RETRY;
  13731. + break;
  13732. + case VCHIQ_SERVICE_CLOSED:
  13733. + LOG_DBG("CMA service closed");
  13734. + break;
  13735. + default:
  13736. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  13737. + break;
  13738. + }
  13739. + return VCHIQ_SUCCESS;
  13740. +}
  13741. +
  13742. +static void send_vc_msg(unsigned short type,
  13743. + unsigned short param1, unsigned short param2)
  13744. +{
  13745. + unsigned short msg[] = { type, param1, param2 };
  13746. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  13747. + VCHIQ_STATUS_T ret;
  13748. + vchiq_use_service(cma_service);
  13749. + ret = vchiq_queue_message(cma_service, &elem, 1);
  13750. + vchiq_release_service(cma_service);
  13751. + if (ret != VCHIQ_SUCCESS)
  13752. + LOG_ERR("vchiq_queue_message returned %x", ret);
  13753. +}
  13754. +
  13755. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  13756. +{
  13757. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  13758. + return false;
  13759. + vchiu_queue_push(&cma_msg_queue, msg);
  13760. + up(&vc_cma_worker_queue_push_mutex);
  13761. + return true;
  13762. +}
  13763. +
  13764. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  13765. +{
  13766. + int i;
  13767. + for (i = 0; i < num_chunks; i++) {
  13768. + struct page *chunk;
  13769. + unsigned int chunk_num;
  13770. + uint8_t *chunk_addr;
  13771. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  13772. +
  13773. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  13774. + PAGES_PER_CHUNK,
  13775. + VC_CMA_CHUNK_ORDER);
  13776. + if (!chunk)
  13777. + break;
  13778. +
  13779. + chunk_addr = page_address(chunk);
  13780. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  13781. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  13782. + chunk_size);
  13783. +
  13784. + chunk_num =
  13785. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  13786. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  13787. + VC_CMA_CHUNK_SIZE) != 0);
  13788. + if (chunk_num >= vc_cma_chunks) {
  13789. + LOG_ERR("%s: ===============================",
  13790. + __func__);
  13791. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  13792. + "bad SPARSEMEM configuration?",
  13793. + __func__, (unsigned int)page_to_phys(chunk),
  13794. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  13795. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  13796. + (void*)0/*vc_cma_device.dev.cma_area*/);
  13797. + LOG_ERR("%s: ===============================",
  13798. + __func__);
  13799. + break;
  13800. + }
  13801. + reply->params[i] = chunk_num;
  13802. + vc_cma_chunks_used++;
  13803. + }
  13804. +
  13805. + if (i < num_chunks) {
  13806. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  13807. + "for %x bytes (alloc %d of %d, %d free)",
  13808. + __func__, VC_CMA_CHUNK_SIZE, i,
  13809. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  13810. + num_chunks = i;
  13811. + }
  13812. +
  13813. + LOG_DBG("CMA allocated %d chunks -> %d used",
  13814. + num_chunks, vc_cma_chunks_used);
  13815. + reply->type = VC_CMA_MSG_ALLOCATED;
  13816. +
  13817. + {
  13818. + VCHIQ_ELEMENT_T elem = {
  13819. + reply,
  13820. + offsetof(struct cma_msg, params[0]) +
  13821. + num_chunks * sizeof(reply->params[0])
  13822. + };
  13823. + VCHIQ_STATUS_T ret;
  13824. + vchiq_use_service(cma_service);
  13825. + ret = vchiq_queue_message(cma_service, &elem, 1);
  13826. + vchiq_release_service(cma_service);
  13827. + if (ret != VCHIQ_SUCCESS)
  13828. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  13829. + }
  13830. +
  13831. + return num_chunks;
  13832. +}
  13833. +
  13834. +static int cma_worker_proc(void *param)
  13835. +{
  13836. + static struct cma_msg reply;
  13837. + (void)param;
  13838. +
  13839. + while (1) {
  13840. + VCHIQ_HEADER_T *msg;
  13841. + static struct cma_msg msg_copy;
  13842. + struct cma_msg *cma_msg = &msg_copy;
  13843. + int type, msg_size;
  13844. +
  13845. + msg = vchiu_queue_pop(&cma_msg_queue);
  13846. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  13847. + msg_size = msg->size;
  13848. + memcpy(&msg_copy, msg->data, msg_size);
  13849. + type = cma_msg->type;
  13850. + vchiq_release_message(cma_service, msg);
  13851. + } else {
  13852. + msg_size = 0;
  13853. + type = (int)msg;
  13854. + if (type == VC_CMA_MSG_QUIT)
  13855. + break;
  13856. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  13857. + msg = NULL;
  13858. + cma_msg = NULL;
  13859. + } else {
  13860. + BUG();
  13861. + continue;
  13862. + }
  13863. + }
  13864. +
  13865. + switch (type) {
  13866. + case VC_CMA_MSG_ALLOC:{
  13867. + int num_chunks, free_chunks;
  13868. + num_chunks = cma_msg->params[0];
  13869. + free_chunks =
  13870. + vc_cma_chunks - vc_cma_chunks_used;
  13871. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  13872. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  13873. + LOG_ERR
  13874. + ("CMA_MSG_ALLOC - chunk count (%d) "
  13875. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  13876. + num_chunks,
  13877. + VC_CMA_MAX_PARAMS_PER_MSG);
  13878. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  13879. + }
  13880. +
  13881. + if (num_chunks > free_chunks) {
  13882. + LOG_ERR
  13883. + ("CMA_MSG_ALLOC - chunk count (%d) "
  13884. + "exceeds free chunks (%d)",
  13885. + num_chunks, free_chunks);
  13886. + num_chunks = free_chunks;
  13887. + }
  13888. +
  13889. + vc_cma_alloc_chunks(num_chunks, &reply);
  13890. + }
  13891. + break;
  13892. +
  13893. + case VC_CMA_MSG_FREE:{
  13894. + int chunk_count =
  13895. + (msg_size -
  13896. + offsetof(struct cma_msg,
  13897. + params)) /
  13898. + sizeof(cma_msg->params[0]);
  13899. + int i;
  13900. + BUG_ON(chunk_count <= 0);
  13901. +
  13902. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  13903. + chunk_count, cma_msg->params[0]);
  13904. + for (i = 0; i < chunk_count; i++) {
  13905. + int chunk_num = cma_msg->params[i];
  13906. + struct page *page = vc_cma_base_page +
  13907. + chunk_num * PAGES_PER_CHUNK;
  13908. + if (chunk_num >= vc_cma_chunks) {
  13909. + LOG_ERR
  13910. + ("CMA_MSG_FREE - chunk %d of %d"
  13911. + " (value %x) exceeds maximum "
  13912. + "(%x)", i, chunk_count,
  13913. + chunk_num,
  13914. + vc_cma_chunks - 1);
  13915. + break;
  13916. + }
  13917. +
  13918. + if (!dma_release_from_contiguous
  13919. + (NULL /*&vc_cma_device.dev*/, page,
  13920. + PAGES_PER_CHUNK)) {
  13921. + LOG_ERR
  13922. + ("CMA_MSG_FREE - failed to "
  13923. + "release chunk %d (phys %x, "
  13924. + "page %x)", chunk_num,
  13925. + page_to_phys(page),
  13926. + (unsigned int)page);
  13927. + }
  13928. + vc_cma_chunks_used--;
  13929. + }
  13930. + LOG_DBG("CMA released %d chunks -> %d used",
  13931. + i, vc_cma_chunks_used);
  13932. + }
  13933. + break;
  13934. +
  13935. + case VC_CMA_MSG_UPDATE_RESERVE:{
  13936. + int chunks_needed =
  13937. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  13938. + 1)
  13939. + / VC_CMA_CHUNK_SIZE) -
  13940. + vc_cma_chunks_reserved;
  13941. +
  13942. + LOG_DBG
  13943. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  13944. + chunks_needed);
  13945. +
  13946. + /* Cap the reservations to what is available */
  13947. + if (chunks_needed > 0) {
  13948. + if (chunks_needed >
  13949. + (vc_cma_chunks -
  13950. + vc_cma_chunks_used))
  13951. + chunks_needed =
  13952. + (vc_cma_chunks -
  13953. + vc_cma_chunks_used);
  13954. +
  13955. + chunks_needed =
  13956. + vc_cma_alloc_chunks(chunks_needed,
  13957. + &reply);
  13958. + }
  13959. +
  13960. + LOG_DBG
  13961. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  13962. + chunks_needed);
  13963. + vc_cma_chunks_reserved += chunks_needed;
  13964. + }
  13965. + break;
  13966. +
  13967. + default:
  13968. + LOG_ERR("unexpected msg type %d", type);
  13969. + break;
  13970. + }
  13971. + }
  13972. +
  13973. + LOG_DBG("quitting...");
  13974. + return 0;
  13975. +}
  13976. +
  13977. +/****************************************************************************
  13978. +*
  13979. +* vc_cma_connected_init
  13980. +*
  13981. +* This function is called once the videocore has been connected.
  13982. +*
  13983. +***************************************************************************/
  13984. +
  13985. +static void vc_cma_connected_init(void)
  13986. +{
  13987. + VCHIQ_SERVICE_PARAMS_T service_params;
  13988. +
  13989. + LOG_DBG("vc_cma_connected_init");
  13990. +
  13991. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  13992. + LOG_ERR("could not create CMA msg queue");
  13993. + goto fail_queue;
  13994. + }
  13995. +
  13996. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  13997. + goto fail_vchiq_init;
  13998. +
  13999. + vchiq_connect(cma_instance);
  14000. +
  14001. + service_params.fourcc = VC_CMA_FOURCC;
  14002. + service_params.callback = cma_service_callback;
  14003. + service_params.userdata = NULL;
  14004. + service_params.version = VC_CMA_VERSION;
  14005. + service_params.version_min = VC_CMA_VERSION;
  14006. +
  14007. + if (vchiq_open_service(cma_instance, &service_params,
  14008. + &cma_service) != VCHIQ_SUCCESS) {
  14009. + LOG_ERR("failed to open service - already in use?");
  14010. + goto fail_vchiq_open;
  14011. + }
  14012. +
  14013. + vchiq_release_service(cma_service);
  14014. +
  14015. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  14016. + if (!cma_worker) {
  14017. + LOG_ERR("could not create CMA worker thread");
  14018. + goto fail_worker;
  14019. + }
  14020. + set_user_nice(cma_worker, -20);
  14021. + wake_up_process(cma_worker);
  14022. +
  14023. + return;
  14024. +
  14025. +fail_worker:
  14026. + vchiq_close_service(cma_service);
  14027. +fail_vchiq_open:
  14028. + vchiq_shutdown(cma_instance);
  14029. +fail_vchiq_init:
  14030. + vchiu_queue_delete(&cma_msg_queue);
  14031. +fail_queue:
  14032. + return;
  14033. +}
  14034. +
  14035. +void
  14036. +loud_error_header(void)
  14037. +{
  14038. + if (in_loud_error)
  14039. + return;
  14040. +
  14041. + LOG_ERR("============================================================"
  14042. + "================");
  14043. + LOG_ERR("============================================================"
  14044. + "================");
  14045. + LOG_ERR("=====");
  14046. +
  14047. + in_loud_error = 1;
  14048. +}
  14049. +
  14050. +void
  14051. +loud_error_footer(void)
  14052. +{
  14053. + if (!in_loud_error)
  14054. + return;
  14055. +
  14056. + LOG_ERR("=====");
  14057. + LOG_ERR("============================================================"
  14058. + "================");
  14059. + LOG_ERR("============================================================"
  14060. + "================");
  14061. +
  14062. + in_loud_error = 0;
  14063. +}
  14064. +
  14065. +#if 1
  14066. +static int check_cma_config(void) { return 1; }
  14067. +#else
  14068. +static int
  14069. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  14070. + const char *symbol,
  14071. + void *buf, size_t bufsize)
  14072. +{
  14073. + VC_MEM_ADDR_T vcMemAddr;
  14074. + size_t vcMemSize;
  14075. + uint8_t *mapAddr;
  14076. + off_t vcMapAddr;
  14077. +
  14078. + if (!LookupVideoCoreSymbol(handle, symbol,
  14079. + &vcMemAddr,
  14080. + &vcMemSize)) {
  14081. + loud_error_header();
  14082. + loud_error(
  14083. + "failed to find VC symbol \"%s\".",
  14084. + symbol);
  14085. + loud_error_footer();
  14086. + return 0;
  14087. + }
  14088. +
  14089. + if (vcMemSize != bufsize) {
  14090. + loud_error_header();
  14091. + loud_error(
  14092. + "VC symbol \"%s\" is the wrong size.",
  14093. + symbol);
  14094. + loud_error_footer();
  14095. + return 0;
  14096. + }
  14097. +
  14098. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  14099. + vcMapAddr += mm_vc_mem_phys_addr;
  14100. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  14101. + if (mapAddr == 0) {
  14102. + loud_error_header();
  14103. + loud_error(
  14104. + "failed to ioremap \"%s\" @ 0x%x "
  14105. + "(phys: 0x%x, size: %u).",
  14106. + symbol,
  14107. + (unsigned int)vcMapAddr,
  14108. + (unsigned int)vcMemAddr,
  14109. + (unsigned int)vcMemSize);
  14110. + loud_error_footer();
  14111. + return 0;
  14112. + }
  14113. +
  14114. + memcpy(buf, mapAddr, bufsize);
  14115. + iounmap(mapAddr);
  14116. +
  14117. + return 1;
  14118. +}
  14119. +
  14120. +
  14121. +static int
  14122. +check_cma_config(void)
  14123. +{
  14124. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  14125. + VC_MEM_ADDR_T mempool_start;
  14126. + VC_MEM_ADDR_T mempool_end;
  14127. + VC_MEM_ADDR_T mempool_offline_start;
  14128. + VC_MEM_ADDR_T mempool_offline_end;
  14129. + VC_MEM_ADDR_T cam_alloc_base;
  14130. + VC_MEM_ADDR_T cam_alloc_size;
  14131. + VC_MEM_ADDR_T cam_alloc_end;
  14132. + int success = 0;
  14133. +
  14134. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  14135. + goto out;
  14136. +
  14137. + /* Read the relevant VideoCore variables */
  14138. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  14139. + &mempool_start,
  14140. + sizeof(mempool_start)))
  14141. + goto close;
  14142. +
  14143. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  14144. + &mempool_end,
  14145. + sizeof(mempool_end)))
  14146. + goto close;
  14147. +
  14148. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  14149. + &mempool_offline_start,
  14150. + sizeof(mempool_offline_start)))
  14151. + goto close;
  14152. +
  14153. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  14154. + &mempool_offline_end,
  14155. + sizeof(mempool_offline_end)))
  14156. + goto close;
  14157. +
  14158. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  14159. + &cam_alloc_base,
  14160. + sizeof(cam_alloc_base)))
  14161. + goto close;
  14162. +
  14163. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  14164. + &cam_alloc_size,
  14165. + sizeof(cam_alloc_size)))
  14166. + goto close;
  14167. +
  14168. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  14169. +
  14170. + success = 1;
  14171. +
  14172. + /* Now the sanity checks */
  14173. + if (!mempool_offline_start)
  14174. + mempool_offline_start = mempool_start;
  14175. + if (!mempool_offline_end)
  14176. + mempool_offline_end = mempool_end;
  14177. +
  14178. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  14179. + loud_error_header();
  14180. + loud_error(
  14181. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  14182. + "vc_cma_base(%x)",
  14183. + mempool_offline_start,
  14184. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  14185. + vc_cma_base);
  14186. + success = 0;
  14187. + }
  14188. +
  14189. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  14190. + (vc_cma_base + vc_cma_size)) {
  14191. + loud_error_header();
  14192. + loud_error(
  14193. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  14194. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  14195. + mempool_offline_start,
  14196. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  14197. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  14198. + success = 0;
  14199. + }
  14200. +
  14201. + if (mempool_end < mempool_start) {
  14202. + loud_error_header();
  14203. + loud_error(
  14204. + "__MEMPOOL_END(%x) must not be before "
  14205. + "__MEMPOOL_START(%x)",
  14206. + mempool_end,
  14207. + mempool_start);
  14208. + success = 0;
  14209. + }
  14210. +
  14211. + if (mempool_offline_end < mempool_offline_start) {
  14212. + loud_error_header();
  14213. + loud_error(
  14214. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  14215. + "__MEMPOOL_OFFLINE_START(%x)",
  14216. + mempool_offline_end,
  14217. + mempool_offline_start);
  14218. + success = 0;
  14219. + }
  14220. +
  14221. + if (mempool_offline_start < mempool_start) {
  14222. + loud_error_header();
  14223. + loud_error(
  14224. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  14225. + "__MEMPOOL_START(%x)",
  14226. + mempool_offline_start,
  14227. + mempool_start);
  14228. + success = 0;
  14229. + }
  14230. +
  14231. + if (mempool_offline_end > mempool_end) {
  14232. + loud_error_header();
  14233. + loud_error(
  14234. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  14235. + "__MEMPOOL_END(%x)",
  14236. + mempool_offline_end,
  14237. + mempool_end);
  14238. + success = 0;
  14239. + }
  14240. +
  14241. + if ((cam_alloc_base < mempool_end) &&
  14242. + (cam_alloc_end > mempool_start)) {
  14243. + loud_error_header();
  14244. + loud_error(
  14245. + "cam_alloc pool(%x-%x) overlaps "
  14246. + "mempool(%x-%x)",
  14247. + cam_alloc_base, cam_alloc_end,
  14248. + mempool_start, mempool_end);
  14249. + success = 0;
  14250. + }
  14251. +
  14252. + loud_error_footer();
  14253. +
  14254. +close:
  14255. + CloseVideoCoreMemory(mem_hndl);
  14256. +
  14257. +out:
  14258. + return success;
  14259. +}
  14260. +#endif
  14261. +
  14262. +static int vc_cma_init(void)
  14263. +{
  14264. + int rc = -EFAULT;
  14265. + struct device *dev;
  14266. +
  14267. + if (!check_cma_config())
  14268. + goto out_release;
  14269. +
  14270. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  14271. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  14272. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  14273. + vc_cma_size, vc_cma_size / (1024 * 1024));
  14274. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  14275. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  14276. +
  14277. + vc_cma_base_page = phys_to_page(vc_cma_base);
  14278. +
  14279. + if (vc_cma_chunks) {
  14280. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  14281. +
  14282. + for (vc_cma_chunks_used = 0;
  14283. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  14284. + struct page *chunk;
  14285. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  14286. + PAGES_PER_CHUNK,
  14287. + VC_CMA_CHUNK_ORDER);
  14288. + if (!chunk)
  14289. + break;
  14290. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  14291. + VC_CMA_CHUNK_SIZE) != 0);
  14292. + }
  14293. + if (vc_cma_chunks_used != chunks_needed) {
  14294. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  14295. + "bytes, allocation %d of %d)",
  14296. + __func__, VC_CMA_CHUNK_SIZE,
  14297. + vc_cma_chunks_used, chunks_needed);
  14298. + goto out_release;
  14299. + }
  14300. +
  14301. + vchiq_add_connected_callback(vc_cma_connected_init);
  14302. + }
  14303. +
  14304. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  14305. + if (rc < 0) {
  14306. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  14307. + goto out_release;
  14308. + }
  14309. +
  14310. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  14311. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  14312. + if (rc != 0) {
  14313. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  14314. + goto out_unregister;
  14315. + }
  14316. +
  14317. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  14318. + if (IS_ERR(vc_cma_class)) {
  14319. + rc = PTR_ERR(vc_cma_class);
  14320. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  14321. + goto out_cdev_del;
  14322. + }
  14323. +
  14324. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  14325. + DRIVER_NAME);
  14326. + if (IS_ERR(dev)) {
  14327. + rc = PTR_ERR(dev);
  14328. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  14329. + goto out_class_destroy;
  14330. + }
  14331. +
  14332. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  14333. + if (vc_cma_proc_entry == NULL) {
  14334. + rc = -EFAULT;
  14335. + LOG_ERR("%s: proc_create failed", __func__);
  14336. + goto out_device_destroy;
  14337. + }
  14338. +
  14339. + vc_cma_inited = 1;
  14340. + return 0;
  14341. +
  14342. +out_device_destroy:
  14343. + device_destroy(vc_cma_class, vc_cma_devnum);
  14344. +
  14345. +out_class_destroy:
  14346. + class_destroy(vc_cma_class);
  14347. + vc_cma_class = NULL;
  14348. +
  14349. +out_cdev_del:
  14350. + cdev_del(&vc_cma_cdev);
  14351. +
  14352. +out_unregister:
  14353. + unregister_chrdev_region(vc_cma_devnum, 1);
  14354. +
  14355. +out_release:
  14356. + /* It is tempting to try to clean up by calling
  14357. + dma_release_from_contiguous for all allocated chunks, but it isn't
  14358. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  14359. + VideoCore is already using that memory, so giving it back to Linux
  14360. + is likely to be fatal.
  14361. + */
  14362. + return -1;
  14363. +}
  14364. +
  14365. +/****************************************************************************
  14366. +*
  14367. +* vc_cma_exit
  14368. +*
  14369. +***************************************************************************/
  14370. +
  14371. +static void __exit vc_cma_exit(void)
  14372. +{
  14373. + LOG_DBG("%s: called", __func__);
  14374. +
  14375. + if (vc_cma_inited) {
  14376. + remove_proc_entry(DRIVER_NAME, NULL);
  14377. + device_destroy(vc_cma_class, vc_cma_devnum);
  14378. + class_destroy(vc_cma_class);
  14379. + cdev_del(&vc_cma_cdev);
  14380. + unregister_chrdev_region(vc_cma_devnum, 1);
  14381. + }
  14382. +}
  14383. +
  14384. +module_init(vc_cma_init);
  14385. +module_exit(vc_cma_exit);
  14386. +MODULE_LICENSE("GPL");
  14387. +MODULE_AUTHOR("Broadcom Corporation");
  14388. diff -Nur linux-3.12.38/drivers/char/broadcom/vc_sm/Makefile linux-rpi/drivers/char/broadcom/vc_sm/Makefile
  14389. --- linux-3.12.38/drivers/char/broadcom/vc_sm/Makefile 1970-01-01 01:00:00.000000000 +0100
  14390. +++ linux-rpi/drivers/char/broadcom/vc_sm/Makefile 2015-03-09 10:39:29.730893739 +0100
  14391. @@ -0,0 +1,21 @@
  14392. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs -O2
  14393. +
  14394. +EXTRA_CFLAGS += -I"./arch/arm/mach-bcm2708/include/mach"
  14395. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  14396. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  14397. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  14398. +EXTRA_CFLAGS += -I"$(srctree)/fs/"
  14399. +
  14400. +EXTRA_CFLAGS += -DOS_ASSERT_FAILURE
  14401. +EXTRA_CFLAGS += -D__STDC_VERSION=199901L
  14402. +EXTRA_CFLAGS += -D__STDC_VERSION__=199901L
  14403. +EXTRA_CFLAGS += -D__VCCOREVER__=0
  14404. +EXTRA_CFLAGS += -D__KERNEL__
  14405. +EXTRA_CFLAGS += -D__linux__
  14406. +EXTRA_CFLAGS += -Werror
  14407. +
  14408. +obj-$(CONFIG_BCM_VC_SM) := vc-sm.o
  14409. +
  14410. +vc-sm-objs := \
  14411. + vmcs_sm.o \
  14412. + vc_vchi_sm.o
  14413. diff -Nur linux-3.12.38/drivers/char/broadcom/vc_sm/vc_vchi_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c
  14414. --- linux-3.12.38/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 1970-01-01 01:00:00.000000000 +0100
  14415. +++ linux-rpi/drivers/char/broadcom/vc_sm/vc_vchi_sm.c 2015-03-09 10:39:29.730893739 +0100
  14416. @@ -0,0 +1,492 @@
  14417. +/*****************************************************************************
  14418. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  14419. +*
  14420. +* Unless you and Broadcom execute a separate written software license
  14421. +* agreement governing use of this software, this software is licensed to you
  14422. +* under the terms of the GNU General Public License version 2, available at
  14423. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  14424. +*
  14425. +* Notwithstanding the above, under no circumstances may you combine this
  14426. +* software in any way with any other Broadcom software provided under a
  14427. +* license other than the GPL, without Broadcom's express prior written
  14428. +* consent.
  14429. +*****************************************************************************/
  14430. +
  14431. +/* ---- Include Files ----------------------------------------------------- */
  14432. +#include <linux/types.h>
  14433. +#include <linux/kernel.h>
  14434. +#include <linux/list.h>
  14435. +#include <linux/semaphore.h>
  14436. +#include <linux/mutex.h>
  14437. +#include <linux/slab.h>
  14438. +#include <linux/kthread.h>
  14439. +
  14440. +#include "vc_vchi_sm.h"
  14441. +
  14442. +#define VC_SM_VER 1
  14443. +#define VC_SM_MIN_VER 0
  14444. +
  14445. +/* ---- Private Constants and Types -------------------------------------- */
  14446. +
  14447. +/* Command blocks come from a pool */
  14448. +#define SM_MAX_NUM_CMD_RSP_BLKS 32
  14449. +
  14450. +struct sm_cmd_rsp_blk {
  14451. + struct list_head head; /* To create lists */
  14452. + struct semaphore sema; /* To be signaled when the response is there */
  14453. +
  14454. + uint16_t id;
  14455. + uint16_t length;
  14456. +
  14457. + uint8_t msg[VC_SM_MAX_MSG_LEN];
  14458. +
  14459. + uint32_t wait:1;
  14460. + uint32_t sent:1;
  14461. + uint32_t alloc:1;
  14462. +
  14463. +};
  14464. +
  14465. +struct sm_instance {
  14466. + uint32_t num_connections;
  14467. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  14468. + struct task_struct *io_thread;
  14469. + struct semaphore io_sema;
  14470. +
  14471. + uint32_t trans_id;
  14472. +
  14473. + struct mutex lock;
  14474. + struct list_head cmd_list;
  14475. + struct list_head rsp_list;
  14476. + struct list_head dead_list;
  14477. +
  14478. + struct sm_cmd_rsp_blk free_blk[SM_MAX_NUM_CMD_RSP_BLKS];
  14479. + struct list_head free_list;
  14480. + struct mutex free_lock;
  14481. + struct semaphore free_sema;
  14482. +
  14483. +};
  14484. +
  14485. +/* ---- Private Variables ------------------------------------------------ */
  14486. +
  14487. +/* ---- Private Function Prototypes -------------------------------------- */
  14488. +
  14489. +/* ---- Private Functions ------------------------------------------------ */
  14490. +static struct
  14491. +sm_cmd_rsp_blk *vc_vchi_cmd_create(struct sm_instance *instance,
  14492. + VC_SM_MSG_TYPE id, void *msg,
  14493. + uint32_t size, int wait)
  14494. +{
  14495. + struct sm_cmd_rsp_blk *blk;
  14496. + VC_SM_MSG_HDR_T *hdr;
  14497. +
  14498. + if (down_interruptible(&instance->free_sema)) {
  14499. + blk = kmalloc(sizeof(*blk), GFP_KERNEL);
  14500. + if (!blk)
  14501. + return NULL;
  14502. +
  14503. + blk->alloc = 1;
  14504. + sema_init(&blk->sema, 0);
  14505. + } else {
  14506. + mutex_lock(&instance->free_lock);
  14507. + blk =
  14508. + list_first_entry(&instance->free_list,
  14509. + struct sm_cmd_rsp_blk, head);
  14510. + list_del(&blk->head);
  14511. + mutex_unlock(&instance->free_lock);
  14512. + }
  14513. +
  14514. + blk->sent = 0;
  14515. + blk->wait = wait;
  14516. + blk->length = sizeof(*hdr) + size;
  14517. +
  14518. + hdr = (VC_SM_MSG_HDR_T *) blk->msg;
  14519. + hdr->type = id;
  14520. + mutex_lock(&instance->lock);
  14521. + hdr->trans_id = blk->id = ++instance->trans_id;
  14522. + mutex_unlock(&instance->lock);
  14523. +
  14524. + if (size)
  14525. + memcpy(hdr->body, msg, size);
  14526. +
  14527. + return blk;
  14528. +}
  14529. +
  14530. +static void
  14531. +vc_vchi_cmd_delete(struct sm_instance *instance, struct sm_cmd_rsp_blk *blk)
  14532. +{
  14533. + if (blk->alloc) {
  14534. + kfree(blk);
  14535. + return;
  14536. + }
  14537. +
  14538. + mutex_lock(&instance->free_lock);
  14539. + list_add(&blk->head, &instance->free_list);
  14540. + mutex_unlock(&instance->free_lock);
  14541. + up(&instance->free_sema);
  14542. +}
  14543. +
  14544. +static int vc_vchi_sm_videocore_io(void *arg)
  14545. +{
  14546. + struct sm_instance *instance = arg;
  14547. + struct sm_cmd_rsp_blk *cmd = NULL, *cmd_tmp;
  14548. + VC_SM_RESULT_T *reply;
  14549. + uint32_t reply_len;
  14550. + int32_t status;
  14551. + int svc_use = 1;
  14552. +
  14553. + while (1) {
  14554. + if (svc_use)
  14555. + vchi_service_release(instance->vchi_handle[0]);
  14556. + svc_use = 0;
  14557. + if (!down_interruptible(&instance->io_sema)) {
  14558. + vchi_service_use(instance->vchi_handle[0]);
  14559. + svc_use = 1;
  14560. +
  14561. + do {
  14562. + unsigned int flags;
  14563. + /*
  14564. + * Get new command and move it to response list
  14565. + */
  14566. + mutex_lock(&instance->lock);
  14567. + if (list_empty(&instance->cmd_list)) {
  14568. + /* no more commands to process */
  14569. + mutex_unlock(&instance->lock);
  14570. + break;
  14571. + }
  14572. + cmd =
  14573. + list_first_entry(&instance->cmd_list,
  14574. + struct sm_cmd_rsp_blk,
  14575. + head);
  14576. + list_move(&cmd->head, &instance->rsp_list);
  14577. + cmd->sent = 1;
  14578. + mutex_unlock(&instance->lock);
  14579. +
  14580. + /* Send the command */
  14581. + flags = VCHI_FLAGS_BLOCK_UNTIL_QUEUED;
  14582. + status = vchi_msg_queue(
  14583. + instance->vchi_handle[0],
  14584. + cmd->msg, cmd->length,
  14585. + flags, NULL);
  14586. + if (status) {
  14587. + pr_err("%s: failed to queue message (%d)",
  14588. + __func__, status);
  14589. + }
  14590. +
  14591. + /* If no reply is needed then we're done */
  14592. + if (!cmd->wait) {
  14593. + mutex_lock(&instance->lock);
  14594. + list_del(&cmd->head);
  14595. + mutex_unlock(&instance->lock);
  14596. + vc_vchi_cmd_delete(instance, cmd);
  14597. + continue;
  14598. + }
  14599. +
  14600. + if (status) {
  14601. + up(&cmd->sema);
  14602. + continue;
  14603. + }
  14604. +
  14605. + } while (1);
  14606. +
  14607. + while (!vchi_msg_peek
  14608. + (instance->vchi_handle[0], (void **)&reply,
  14609. + &reply_len, VCHI_FLAGS_NONE)) {
  14610. + mutex_lock(&instance->lock);
  14611. + list_for_each_entry(cmd, &instance->rsp_list,
  14612. + head) {
  14613. + if (cmd->id == reply->trans_id)
  14614. + break;
  14615. + }
  14616. + mutex_unlock(&instance->lock);
  14617. +
  14618. + if (&cmd->head == &instance->rsp_list) {
  14619. + pr_debug("%s: received response %u, throw away...",
  14620. + __func__, reply->trans_id);
  14621. + } else if (reply_len > sizeof(cmd->msg)) {
  14622. + pr_err("%s: reply too big (%u) %u, throw away...",
  14623. + __func__, reply_len,
  14624. + reply->trans_id);
  14625. + } else {
  14626. + memcpy(cmd->msg, reply, reply_len);
  14627. + up(&cmd->sema);
  14628. + }
  14629. +
  14630. + vchi_msg_remove(instance->vchi_handle[0]);
  14631. + }
  14632. +
  14633. + /* Go through the dead list and free them */
  14634. + mutex_lock(&instance->lock);
  14635. + list_for_each_entry_safe(cmd, cmd_tmp,
  14636. + &instance->dead_list, head) {
  14637. + list_del(&cmd->head);
  14638. + vc_vchi_cmd_delete(instance, cmd);
  14639. + }
  14640. + mutex_unlock(&instance->lock);
  14641. + }
  14642. + }
  14643. +
  14644. + return 0;
  14645. +}
  14646. +
  14647. +static void vc_sm_vchi_callback(void *param,
  14648. + const VCHI_CALLBACK_REASON_T reason,
  14649. + void *msg_handle)
  14650. +{
  14651. + struct sm_instance *instance = param;
  14652. +
  14653. + (void)msg_handle;
  14654. +
  14655. + switch (reason) {
  14656. + case VCHI_CALLBACK_MSG_AVAILABLE:
  14657. + up(&instance->io_sema);
  14658. + break;
  14659. +
  14660. + case VCHI_CALLBACK_SERVICE_CLOSED:
  14661. + pr_info("%s: service CLOSED!!", __func__);
  14662. + default:
  14663. + break;
  14664. + }
  14665. +}
  14666. +
  14667. +VC_VCHI_SM_HANDLE_T vc_vchi_sm_init(VCHI_INSTANCE_T vchi_instance,
  14668. + VCHI_CONNECTION_T **vchi_connections,
  14669. + uint32_t num_connections)
  14670. +{
  14671. + uint32_t i;
  14672. + struct sm_instance *instance;
  14673. + int status;
  14674. +
  14675. + pr_debug("%s: start", __func__);
  14676. +
  14677. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  14678. + pr_err("%s: unsupported number of connections %u (max=%u)",
  14679. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  14680. +
  14681. + goto err_null;
  14682. + }
  14683. + /* Allocate memory for this instance */
  14684. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  14685. +
  14686. + /* Misc initialisations */
  14687. + mutex_init(&instance->lock);
  14688. + sema_init(&instance->io_sema, 0);
  14689. + INIT_LIST_HEAD(&instance->cmd_list);
  14690. + INIT_LIST_HEAD(&instance->rsp_list);
  14691. + INIT_LIST_HEAD(&instance->dead_list);
  14692. + INIT_LIST_HEAD(&instance->free_list);
  14693. + sema_init(&instance->free_sema, SM_MAX_NUM_CMD_RSP_BLKS);
  14694. + mutex_init(&instance->free_lock);
  14695. + for (i = 0; i < SM_MAX_NUM_CMD_RSP_BLKS; i++) {
  14696. + sema_init(&instance->free_blk[i].sema, 0);
  14697. + list_add(&instance->free_blk[i].head, &instance->free_list);
  14698. + }
  14699. +
  14700. + /* Open the VCHI service connections */
  14701. + instance->num_connections = num_connections;
  14702. + for (i = 0; i < num_connections; i++) {
  14703. + SERVICE_CREATION_T params = {
  14704. + VCHI_VERSION_EX(VC_SM_VER, VC_SM_MIN_VER),
  14705. + VC_SM_SERVER_NAME,
  14706. + vchi_connections[i],
  14707. + 0,
  14708. + 0,
  14709. + vc_sm_vchi_callback,
  14710. + instance,
  14711. + 0,
  14712. + 0,
  14713. + 0,
  14714. + };
  14715. +
  14716. + status = vchi_service_open(vchi_instance,
  14717. + &params, &instance->vchi_handle[i]);
  14718. + if (status) {
  14719. + pr_err("%s: failed to open VCHI service (%d)",
  14720. + __func__, status);
  14721. +
  14722. + goto err_close_services;
  14723. + }
  14724. + }
  14725. +
  14726. + /* Create the thread which takes care of all io to/from videoocore. */
  14727. + instance->io_thread = kthread_create(&vc_vchi_sm_videocore_io,
  14728. + (void *)instance, "SMIO");
  14729. + if (instance->io_thread == NULL) {
  14730. + pr_err("%s: failed to create SMIO thread", __func__);
  14731. +
  14732. + goto err_close_services;
  14733. + }
  14734. + set_user_nice(instance->io_thread, -10);
  14735. + wake_up_process(instance->io_thread);
  14736. +
  14737. + pr_debug("%s: success - instance 0x%x", __func__, (unsigned)instance);
  14738. + return instance;
  14739. +
  14740. +err_close_services:
  14741. + for (i = 0; i < instance->num_connections; i++) {
  14742. + if (instance->vchi_handle[i] != NULL)
  14743. + vchi_service_close(instance->vchi_handle[i]);
  14744. + }
  14745. + kfree(instance);
  14746. +err_null:
  14747. + pr_debug("%s: FAILED", __func__);
  14748. + return NULL;
  14749. +}
  14750. +
  14751. +int vc_vchi_sm_stop(VC_VCHI_SM_HANDLE_T *handle)
  14752. +{
  14753. + struct sm_instance *instance;
  14754. + uint32_t i;
  14755. +
  14756. + if (handle == NULL) {
  14757. + pr_err("%s: invalid pointer to handle %p", __func__, handle);
  14758. + goto lock;
  14759. + }
  14760. +
  14761. + if (*handle == NULL) {
  14762. + pr_err("%s: invalid handle %p", __func__, *handle);
  14763. + goto lock;
  14764. + }
  14765. +
  14766. + instance = *handle;
  14767. +
  14768. + /* Close all VCHI service connections */
  14769. + for (i = 0; i < instance->num_connections; i++) {
  14770. + int32_t success;
  14771. + vchi_service_use(instance->vchi_handle[i]);
  14772. +
  14773. + success = vchi_service_close(instance->vchi_handle[i]);
  14774. + }
  14775. +
  14776. + kfree(instance);
  14777. +
  14778. + *handle = NULL;
  14779. + return 0;
  14780. +
  14781. +lock:
  14782. + return -EINVAL;
  14783. +}
  14784. +
  14785. +int vc_vchi_sm_send_msg(VC_VCHI_SM_HANDLE_T handle,
  14786. + VC_SM_MSG_TYPE msg_id,
  14787. + void *msg, uint32_t msg_size,
  14788. + void *result, uint32_t result_size,
  14789. + uint32_t *cur_trans_id, uint8_t wait_reply)
  14790. +{
  14791. + int status = 0;
  14792. + struct sm_instance *instance = handle;
  14793. + struct sm_cmd_rsp_blk *cmd_blk;
  14794. +
  14795. + if (handle == NULL) {
  14796. + pr_err("%s: invalid handle", __func__);
  14797. + return -EINVAL;
  14798. + }
  14799. + if (msg == NULL) {
  14800. + pr_err("%s: invalid msg pointer", __func__);
  14801. + return -EINVAL;
  14802. + }
  14803. +
  14804. + cmd_blk =
  14805. + vc_vchi_cmd_create(instance, msg_id, msg, msg_size, wait_reply);
  14806. + if (cmd_blk == NULL) {
  14807. + pr_err("[%s]: failed to allocate global tracking resource",
  14808. + __func__);
  14809. + return -ENOMEM;
  14810. + }
  14811. +
  14812. + if (cur_trans_id != NULL)
  14813. + *cur_trans_id = cmd_blk->id;
  14814. +
  14815. + mutex_lock(&instance->lock);
  14816. + list_add_tail(&cmd_blk->head, &instance->cmd_list);
  14817. + mutex_unlock(&instance->lock);
  14818. + up(&instance->io_sema);
  14819. +
  14820. + if (!wait_reply)
  14821. + /* We're done */
  14822. + return 0;
  14823. +
  14824. + /* Wait for the response */
  14825. + if (down_interruptible(&cmd_blk->sema)) {
  14826. + mutex_lock(&instance->lock);
  14827. + if (!cmd_blk->sent) {
  14828. + list_del(&cmd_blk->head);
  14829. + mutex_unlock(&instance->lock);
  14830. + vc_vchi_cmd_delete(instance, cmd_blk);
  14831. + return -ENXIO;
  14832. + }
  14833. + mutex_unlock(&instance->lock);
  14834. +
  14835. + mutex_lock(&instance->lock);
  14836. + list_move(&cmd_blk->head, &instance->dead_list);
  14837. + mutex_unlock(&instance->lock);
  14838. + up(&instance->io_sema);
  14839. + return -EINTR; /* We're done */
  14840. + }
  14841. +
  14842. + if (result && result_size) {
  14843. + memcpy(result, cmd_blk->msg, result_size);
  14844. + } else {
  14845. + VC_SM_RESULT_T *res = (VC_SM_RESULT_T *) cmd_blk->msg;
  14846. + status = (res->success == 0) ? 0 : -ENXIO;
  14847. + }
  14848. +
  14849. + mutex_lock(&instance->lock);
  14850. + list_del(&cmd_blk->head);
  14851. + mutex_unlock(&instance->lock);
  14852. + vc_vchi_cmd_delete(instance, cmd_blk);
  14853. + return status;
  14854. +}
  14855. +
  14856. +int vc_vchi_sm_alloc(VC_VCHI_SM_HANDLE_T handle, VC_SM_ALLOC_T *msg,
  14857. + VC_SM_ALLOC_RESULT_T *result, uint32_t *cur_trans_id)
  14858. +{
  14859. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ALLOC,
  14860. + msg, sizeof(*msg), result, sizeof(*result),
  14861. + cur_trans_id, 1);
  14862. +}
  14863. +
  14864. +int vc_vchi_sm_free(VC_VCHI_SM_HANDLE_T handle,
  14865. + VC_SM_FREE_T *msg, uint32_t *cur_trans_id)
  14866. +{
  14867. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_FREE,
  14868. + msg, sizeof(*msg), 0, 0, cur_trans_id, 0);
  14869. +}
  14870. +
  14871. +int vc_vchi_sm_lock(VC_VCHI_SM_HANDLE_T handle,
  14872. + VC_SM_LOCK_UNLOCK_T *msg,
  14873. + VC_SM_LOCK_RESULT_T *result, uint32_t *cur_trans_id)
  14874. +{
  14875. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_LOCK,
  14876. + msg, sizeof(*msg), result, sizeof(*result),
  14877. + cur_trans_id, 1);
  14878. +}
  14879. +
  14880. +int vc_vchi_sm_unlock(VC_VCHI_SM_HANDLE_T handle,
  14881. + VC_SM_LOCK_UNLOCK_T *msg,
  14882. + uint32_t *cur_trans_id, uint8_t wait_reply)
  14883. +{
  14884. + return vc_vchi_sm_send_msg(handle, wait_reply ?
  14885. + VC_SM_MSG_TYPE_UNLOCK :
  14886. + VC_SM_MSG_TYPE_UNLOCK_NOANS, msg,
  14887. + sizeof(*msg), 0, 0, cur_trans_id,
  14888. + wait_reply);
  14889. +}
  14890. +
  14891. +int vc_vchi_sm_resize(VC_VCHI_SM_HANDLE_T handle, VC_SM_RESIZE_T *msg,
  14892. + uint32_t *cur_trans_id)
  14893. +{
  14894. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_RESIZE,
  14895. + msg, sizeof(*msg), 0, 0, cur_trans_id, 1);
  14896. +}
  14897. +
  14898. +int vc_vchi_sm_walk_alloc(VC_VCHI_SM_HANDLE_T handle)
  14899. +{
  14900. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_WALK_ALLOC,
  14901. + 0, 0, 0, 0, 0, 0);
  14902. +}
  14903. +
  14904. +int vc_vchi_sm_clean_up(VC_VCHI_SM_HANDLE_T handle, VC_SM_ACTION_CLEAN_T *msg)
  14905. +{
  14906. + return vc_vchi_sm_send_msg(handle, VC_SM_MSG_TYPE_ACTION_CLEAN,
  14907. + msg, sizeof(*msg), 0, 0, 0, 0);
  14908. +}
  14909. diff -Nur linux-3.12.38/drivers/char/broadcom/vc_sm/vmcs_sm.c linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c
  14910. --- linux-3.12.38/drivers/char/broadcom/vc_sm/vmcs_sm.c 1970-01-01 01:00:00.000000000 +0100
  14911. +++ linux-rpi/drivers/char/broadcom/vc_sm/vmcs_sm.c 2015-03-09 10:39:29.730893739 +0100
  14912. @@ -0,0 +1,3163 @@
  14913. +/*****************************************************************************
  14914. +* Copyright 2011-2012 Broadcom Corporation. All rights reserved.
  14915. +*
  14916. +* Unless you and Broadcom execute a separate written software license
  14917. +* agreement governing use of this software, this software is licensed to you
  14918. +* under the terms of the GNU General Public License version 2, available at
  14919. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  14920. +*
  14921. +* Notwithstanding the above, under no circumstances may you combine this
  14922. +* software in any way with any other Broadcom software provided under a
  14923. +* license other than the GPL, without Broadcom's express prior written
  14924. +* consent.
  14925. +*****************************************************************************/
  14926. +
  14927. +/* ---- Include Files ----------------------------------------------------- */
  14928. +
  14929. +#include <linux/cdev.h>
  14930. +#include <linux/device.h>
  14931. +#include <linux/debugfs.h>
  14932. +#include <linux/dma-mapping.h>
  14933. +#include <linux/errno.h>
  14934. +#include <linux/fs.h>
  14935. +#include <linux/hugetlb.h>
  14936. +#include <linux/ioctl.h>
  14937. +#include <linux/kernel.h>
  14938. +#include <linux/list.h>
  14939. +#include <linux/module.h>
  14940. +#include <linux/mm.h>
  14941. +#include <linux/pfn.h>
  14942. +#include <linux/proc_fs.h>
  14943. +#include <linux/pagemap.h>
  14944. +#include <linux/semaphore.h>
  14945. +#include <linux/slab.h>
  14946. +#include <linux/seq_file.h>
  14947. +#include <linux/types.h>
  14948. +#include <asm/cacheflush.h>
  14949. +
  14950. +#include <vc_mem.h>
  14951. +
  14952. +#include "vchiq_connected.h"
  14953. +#include "vc_vchi_sm.h"
  14954. +
  14955. +#include <vmcs_sm_ioctl.h>
  14956. +#include "vc_sm_knl.h"
  14957. +
  14958. +/* ---- Private Constants and Types --------------------------------------- */
  14959. +
  14960. +#define DEVICE_NAME "vcsm"
  14961. +#define DEVICE_MINOR 0
  14962. +
  14963. +#define VC_SM_DIR_ROOT_NAME "vc-smem"
  14964. +#define VC_SM_DIR_ALLOC_NAME "alloc"
  14965. +#define VC_SM_STATE "state"
  14966. +#define VC_SM_STATS "statistics"
  14967. +#define VC_SM_RESOURCES "resources"
  14968. +#define VC_SM_DEBUG "debug"
  14969. +#define VC_SM_WRITE_BUF_SIZE 128
  14970. +
  14971. +/* Statistics tracked per resource and globally.
  14972. +*/
  14973. +enum SM_STATS_T {
  14974. + /* Attempt. */
  14975. + ALLOC,
  14976. + FREE,
  14977. + LOCK,
  14978. + UNLOCK,
  14979. + MAP,
  14980. + FLUSH,
  14981. + INVALID,
  14982. +
  14983. + END_ATTEMPT,
  14984. +
  14985. + /* Failure. */
  14986. + ALLOC_FAIL,
  14987. + FREE_FAIL,
  14988. + LOCK_FAIL,
  14989. + UNLOCK_FAIL,
  14990. + MAP_FAIL,
  14991. + FLUSH_FAIL,
  14992. + INVALID_FAIL,
  14993. +
  14994. + END_ALL,
  14995. +
  14996. +};
  14997. +
  14998. +static const char *const sm_stats_human_read[] = {
  14999. + "Alloc",
  15000. + "Free",
  15001. + "Lock",
  15002. + "Unlock",
  15003. + "Map",
  15004. + "Cache Flush",
  15005. + "Cache Invalidate",
  15006. +};
  15007. +
  15008. +typedef int (*VC_SM_SHOW) (struct seq_file *s, void *v);
  15009. +struct SM_PDE_T {
  15010. + VC_SM_SHOW show; /* Debug fs function hookup. */
  15011. + struct dentry *dir_entry; /* Debug fs directory entry. */
  15012. + void *priv_data; /* Private data */
  15013. +
  15014. +};
  15015. +
  15016. +/* Single resource allocation tracked for all devices.
  15017. +*/
  15018. +struct sm_mmap {
  15019. + struct list_head map_list; /* Linked list of maps. */
  15020. +
  15021. + struct SM_RESOURCE_T *resource; /* Pointer to the resource. */
  15022. +
  15023. + pid_t res_pid; /* PID owning that resource. */
  15024. + unsigned int res_vc_hdl; /* Resource handle (videocore). */
  15025. + unsigned int res_usr_hdl; /* Resource handle (user). */
  15026. +
  15027. + long unsigned int res_addr; /* Mapped virtual address. */
  15028. + struct vm_area_struct *vma; /* VM area for this mapping. */
  15029. + unsigned int ref_count; /* Reference count to this vma. */
  15030. +
  15031. + /* Used to link maps associated with a resource. */
  15032. + struct list_head resource_map_list;
  15033. +};
  15034. +
  15035. +/* Single resource allocation tracked for each opened device.
  15036. +*/
  15037. +struct SM_RESOURCE_T {
  15038. + struct list_head resource_list; /* List of resources. */
  15039. + struct list_head global_resource_list; /* Global list of resources. */
  15040. +
  15041. + pid_t pid; /* PID owning that resource. */
  15042. + uint32_t res_guid; /* Unique identifier. */
  15043. + uint32_t lock_count; /* Lock count for this resource. */
  15044. + uint32_t ref_count; /* Ref count for this resource. */
  15045. +
  15046. + uint32_t res_handle; /* Resource allocation handle. */
  15047. + void *res_base_mem; /* Resource base memory address. */
  15048. + uint32_t res_size; /* Resource size allocated. */
  15049. + enum vmcs_sm_cache_e res_cached; /* Resource cache type. */
  15050. + struct SM_RESOURCE_T *res_shared; /* Shared resource */
  15051. +
  15052. + enum SM_STATS_T res_stats[END_ALL]; /* Resource statistics. */
  15053. +
  15054. + uint8_t map_count; /* Counter of mappings for this resource. */
  15055. + struct list_head map_list; /* Maps associated with a resource. */
  15056. +
  15057. + struct SM_PRIV_DATA_T *private;
  15058. +};
  15059. +
  15060. +/* Private file data associated with each opened device.
  15061. +*/
  15062. +struct SM_PRIV_DATA_T {
  15063. + struct list_head resource_list; /* List of resources. */
  15064. +
  15065. + pid_t pid; /* PID of creator. */
  15066. +
  15067. + struct dentry *dir_pid; /* Debug fs entries root. */
  15068. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  15069. + struct SM_PDE_T dir_res; /* Debug fs resource sub-tree. */
  15070. +
  15071. + int restart_sys; /* Tracks restart on interrupt. */
  15072. + VC_SM_MSG_TYPE int_action; /* Interrupted action. */
  15073. + uint32_t int_trans_id; /* Interrupted transaction. */
  15074. +
  15075. +};
  15076. +
  15077. +/* Global state information.
  15078. +*/
  15079. +struct SM_STATE_T {
  15080. + VC_VCHI_SM_HANDLE_T sm_handle; /* Handle for videocore service. */
  15081. + struct dentry *dir_root; /* Debug fs entries root. */
  15082. + struct dentry *dir_alloc; /* Debug fs entries allocations. */
  15083. + struct SM_PDE_T dir_stats; /* Debug fs entries statistics sub-tree. */
  15084. + struct SM_PDE_T dir_state; /* Debug fs entries state sub-tree. */
  15085. + struct dentry *debug; /* Debug fs entries debug. */
  15086. +
  15087. + struct mutex map_lock; /* Global map lock. */
  15088. + struct list_head map_list; /* List of maps. */
  15089. + struct list_head resource_list; /* List of resources. */
  15090. +
  15091. + enum SM_STATS_T deceased[END_ALL]; /* Natural termination stats. */
  15092. + enum SM_STATS_T terminated[END_ALL]; /* Forced termination stats. */
  15093. + uint32_t res_deceased_cnt; /* Natural termination counter. */
  15094. + uint32_t res_terminated_cnt; /* Forced termination counter. */
  15095. +
  15096. + struct cdev sm_cdev; /* Device. */
  15097. + dev_t sm_devid; /* Device identifier. */
  15098. + struct class *sm_class; /* Class. */
  15099. + struct device *sm_dev; /* Device. */
  15100. +
  15101. + struct SM_PRIV_DATA_T *data_knl; /* Kernel internal data tracking. */
  15102. +
  15103. + struct mutex lock; /* Global lock. */
  15104. + uint32_t guid; /* GUID (next) tracker. */
  15105. +
  15106. +};
  15107. +
  15108. +/* ---- Private Variables ----------------------------------------------- */
  15109. +
  15110. +static struct SM_STATE_T *sm_state;
  15111. +static int sm_inited;
  15112. +
  15113. +static const char *const sm_cache_map_vector[] = {
  15114. + "(null)",
  15115. + "host",
  15116. + "videocore",
  15117. + "host+videocore",
  15118. +};
  15119. +
  15120. +/* ---- Private Function Prototypes -------------------------------------- */
  15121. +
  15122. +/* ---- Private Functions ------------------------------------------------ */
  15123. +
  15124. +static inline unsigned vcaddr_to_pfn(unsigned long vc_addr)
  15125. +{
  15126. + unsigned long pfn = vc_addr & 0x3FFFFFFF;
  15127. + pfn += mm_vc_mem_phys_addr;
  15128. + pfn >>= PAGE_SHIFT;
  15129. + return pfn;
  15130. +}
  15131. +
  15132. +/* Carries over to the state statistics the statistics once owned by a deceased
  15133. +** resource.
  15134. +*/
  15135. +static void vc_sm_resource_deceased(struct SM_RESOURCE_T *p_res, int terminated)
  15136. +{
  15137. + if (sm_state != NULL) {
  15138. + if (p_res != NULL) {
  15139. + int ix;
  15140. +
  15141. + if (terminated)
  15142. + sm_state->res_terminated_cnt++;
  15143. + else
  15144. + sm_state->res_deceased_cnt++;
  15145. +
  15146. + for (ix = 0; ix < END_ALL; ix++) {
  15147. + if (terminated)
  15148. + sm_state->terminated[ix] +=
  15149. + p_res->res_stats[ix];
  15150. + else
  15151. + sm_state->deceased[ix] +=
  15152. + p_res->res_stats[ix];
  15153. + }
  15154. + }
  15155. + }
  15156. +}
  15157. +
  15158. +/* Fetch a videocore handle corresponding to a mapping of the pid+address
  15159. +** returns 0 (ie NULL) if no such handle exists in the global map.
  15160. +*/
  15161. +static unsigned int vmcs_sm_vc_handle_from_pid_and_address(unsigned int pid,
  15162. + unsigned int addr)
  15163. +{
  15164. + struct sm_mmap *map = NULL;
  15165. + unsigned int handle = 0;
  15166. +
  15167. + if (!sm_state || addr == 0)
  15168. + goto out;
  15169. +
  15170. + mutex_lock(&(sm_state->map_lock));
  15171. +
  15172. + /* Lookup the resource.
  15173. + */
  15174. + if (!list_empty(&sm_state->map_list)) {
  15175. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15176. + if (map->res_pid != pid || map->res_addr != addr)
  15177. + continue;
  15178. +
  15179. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> vc-hdl %x (usr-hdl %x)\n",
  15180. + __func__, map, map->res_pid, map->res_addr,
  15181. + map->res_vc_hdl, map->res_usr_hdl);
  15182. +
  15183. + handle = map->res_vc_hdl;
  15184. + break;
  15185. + }
  15186. + }
  15187. +
  15188. + mutex_unlock(&(sm_state->map_lock));
  15189. +
  15190. +out:
  15191. + /* Use a debug log here as it may be a valid situation that we query
  15192. + ** for something that is not mapped, we do not want a kernel log each
  15193. + ** time around.
  15194. + **
  15195. + ** There are other error log that would pop up accordingly if someone
  15196. + ** subsequently tries to use something invalid after being told not to
  15197. + ** use it...
  15198. + */
  15199. + if (handle == 0) {
  15200. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  15201. + __func__, pid, addr);
  15202. + }
  15203. +
  15204. + return handle;
  15205. +}
  15206. +
  15207. +/* Fetch a user handle corresponding to a mapping of the pid+address
  15208. +** returns 0 (ie NULL) if no such handle exists in the global map.
  15209. +*/
  15210. +static unsigned int vmcs_sm_usr_handle_from_pid_and_address(unsigned int pid,
  15211. + unsigned int addr)
  15212. +{
  15213. + struct sm_mmap *map = NULL;
  15214. + unsigned int handle = 0;
  15215. +
  15216. + if (!sm_state || addr == 0)
  15217. + goto out;
  15218. +
  15219. + mutex_lock(&(sm_state->map_lock));
  15220. +
  15221. + /* Lookup the resource.
  15222. + */
  15223. + if (!list_empty(&sm_state->map_list)) {
  15224. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15225. + if (map->res_pid != pid || map->res_addr != addr)
  15226. + continue;
  15227. +
  15228. + pr_debug("[%s]: global map %p (pid %u, addr %lx) -> usr-hdl %x (vc-hdl %x)\n",
  15229. + __func__, map, map->res_pid, map->res_addr,
  15230. + map->res_usr_hdl, map->res_vc_hdl);
  15231. +
  15232. + handle = map->res_usr_hdl;
  15233. + break;
  15234. + }
  15235. + }
  15236. +
  15237. + mutex_unlock(&(sm_state->map_lock));
  15238. +
  15239. +out:
  15240. + /* Use a debug log here as it may be a valid situation that we query
  15241. + * for something that is not mapped yet.
  15242. + *
  15243. + * There are other error log that would pop up accordingly if someone
  15244. + * subsequently tries to use something invalid after being told not to
  15245. + * use it...
  15246. + */
  15247. + if (handle == 0)
  15248. + pr_debug("[%s]: not a valid map (pid %u, addr %x)\n",
  15249. + __func__, pid, addr);
  15250. +
  15251. + return handle;
  15252. +}
  15253. +
  15254. +#if defined(DO_NOT_USE)
  15255. +/* Fetch an address corresponding to a mapping of the pid+handle
  15256. +** returns 0 (ie NULL) if no such address exists in the global map.
  15257. +*/
  15258. +static unsigned int vmcs_sm_usr_address_from_pid_and_vc_handle(unsigned int pid,
  15259. + unsigned int hdl)
  15260. +{
  15261. + struct sm_mmap *map = NULL;
  15262. + unsigned int addr = 0;
  15263. +
  15264. + if (sm_state == NULL || hdl == 0)
  15265. + goto out;
  15266. +
  15267. + mutex_lock(&(sm_state->map_lock));
  15268. +
  15269. + /* Lookup the resource.
  15270. + */
  15271. + if (!list_empty(&sm_state->map_list)) {
  15272. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15273. + if (map->res_pid != pid || map->res_vc_hdl != hdl)
  15274. + continue;
  15275. +
  15276. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  15277. + __func__, map, map->res_pid, map->res_vc_hdl,
  15278. + map->res_usr_hdl, map->res_addr);
  15279. +
  15280. + addr = map->res_addr;
  15281. + break;
  15282. + }
  15283. + }
  15284. +
  15285. + mutex_unlock(&(sm_state->map_lock));
  15286. +
  15287. +out:
  15288. + /* Use a debug log here as it may be a valid situation that we query
  15289. + ** for something that is not mapped, we do not want a kernel log each
  15290. + ** time around.
  15291. + **
  15292. + ** There are other error log that would pop up accordingly if someone
  15293. + ** subsequently tries to use something invalid after being told not to
  15294. + ** use it...
  15295. + */
  15296. + if (addr == 0)
  15297. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n",
  15298. + __func__, pid, hdl);
  15299. +
  15300. + return addr;
  15301. +}
  15302. +#endif
  15303. +
  15304. +/* Fetch an address corresponding to a mapping of the pid+handle
  15305. +** returns 0 (ie NULL) if no such address exists in the global map.
  15306. +*/
  15307. +static unsigned int vmcs_sm_usr_address_from_pid_and_usr_handle(unsigned int
  15308. + pid,
  15309. + unsigned int
  15310. + hdl)
  15311. +{
  15312. + struct sm_mmap *map = NULL;
  15313. + unsigned int addr = 0;
  15314. +
  15315. + if (sm_state == NULL || hdl == 0)
  15316. + goto out;
  15317. +
  15318. + mutex_lock(&(sm_state->map_lock));
  15319. +
  15320. + /* Lookup the resource.
  15321. + */
  15322. + if (!list_empty(&sm_state->map_list)) {
  15323. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15324. + if (map->res_pid != pid || map->res_usr_hdl != hdl)
  15325. + continue;
  15326. +
  15327. + pr_debug("[%s]: global map %p (pid %u, vc-hdl %x, usr-hdl %x) -> addr %lx\n",
  15328. + __func__, map, map->res_pid, map->res_vc_hdl,
  15329. + map->res_usr_hdl, map->res_addr);
  15330. +
  15331. + addr = map->res_addr;
  15332. + break;
  15333. + }
  15334. + }
  15335. +
  15336. + mutex_unlock(&(sm_state->map_lock));
  15337. +
  15338. +out:
  15339. + /* Use a debug log here as it may be a valid situation that we query
  15340. + * for something that is not mapped, we do not want a kernel log each
  15341. + * time around.
  15342. + *
  15343. + * There are other error log that would pop up accordingly if someone
  15344. + * subsequently tries to use something invalid after being told not to
  15345. + * use it...
  15346. + */
  15347. + if (addr == 0)
  15348. + pr_debug("[%s]: not a valid map (pid %u, hdl %x)\n", __func__,
  15349. + pid, hdl);
  15350. +
  15351. + return addr;
  15352. +}
  15353. +
  15354. +/* Adds a resource mapping to the global data list.
  15355. +*/
  15356. +static void vmcs_sm_add_map(struct SM_STATE_T *state,
  15357. + struct SM_RESOURCE_T *resource, struct sm_mmap *map)
  15358. +{
  15359. + mutex_lock(&(state->map_lock));
  15360. +
  15361. + /* Add to the global list of mappings
  15362. + */
  15363. + list_add(&map->map_list, &state->map_list);
  15364. +
  15365. + /* Add to the list of mappings for this resource
  15366. + */
  15367. + list_add(&map->resource_map_list, &resource->map_list);
  15368. + resource->map_count++;
  15369. +
  15370. + mutex_unlock(&(state->map_lock));
  15371. +
  15372. + pr_debug("[%s]: added map %p (pid %u, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  15373. + __func__, map, map->res_pid, map->res_vc_hdl,
  15374. + map->res_usr_hdl, map->res_addr);
  15375. +}
  15376. +
  15377. +/* Removes a resource mapping from the global data list.
  15378. +*/
  15379. +static void vmcs_sm_remove_map(struct SM_STATE_T *state,
  15380. + struct SM_RESOURCE_T *resource,
  15381. + struct sm_mmap *map)
  15382. +{
  15383. + mutex_lock(&(state->map_lock));
  15384. +
  15385. + /* Remove from the global list of mappings
  15386. + */
  15387. + list_del(&map->map_list);
  15388. +
  15389. + /* Remove from the list of mapping for this resource
  15390. + */
  15391. + list_del(&map->resource_map_list);
  15392. + if (resource->map_count > 0)
  15393. + resource->map_count--;
  15394. +
  15395. + mutex_unlock(&(state->map_lock));
  15396. +
  15397. + pr_debug("[%s]: removed map %p (pid %d, vc-hdl %x, usr-hdl %x, addr %lx)\n",
  15398. + __func__, map, map->res_pid, map->res_vc_hdl, map->res_usr_hdl,
  15399. + map->res_addr);
  15400. +
  15401. + kfree(map);
  15402. +}
  15403. +
  15404. +/* Read callback for the global state proc entry.
  15405. +*/
  15406. +static int vc_sm_global_state_show(struct seq_file *s, void *v)
  15407. +{
  15408. + struct sm_mmap *map = NULL;
  15409. + int map_count = 0;
  15410. +
  15411. + if (sm_state == NULL)
  15412. + return 0;
  15413. +
  15414. + seq_printf(s, "\nVC-ServiceHandle 0x%x\n",
  15415. + (unsigned int)sm_state->sm_handle);
  15416. +
  15417. + /* Log all applicable mapping(s).
  15418. + */
  15419. +
  15420. + mutex_lock(&(sm_state->map_lock));
  15421. +
  15422. + if (!list_empty(&sm_state->map_list)) {
  15423. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15424. + map_count++;
  15425. +
  15426. + seq_printf(s, "\nMapping 0x%x\n",
  15427. + (unsigned int)map);
  15428. + seq_printf(s, " TGID %u\n",
  15429. + map->res_pid);
  15430. + seq_printf(s, " VC-HDL 0x%x\n",
  15431. + map->res_vc_hdl);
  15432. + seq_printf(s, " USR-HDL 0x%x\n",
  15433. + map->res_usr_hdl);
  15434. + seq_printf(s, " USR-ADDR 0x%lx\n",
  15435. + map->res_addr);
  15436. + }
  15437. + }
  15438. +
  15439. + mutex_unlock(&(sm_state->map_lock));
  15440. + seq_printf(s, "\n\nTotal map count: %d\n\n", map_count);
  15441. +
  15442. + return 0;
  15443. +}
  15444. +
  15445. +static int vc_sm_global_statistics_show(struct seq_file *s, void *v)
  15446. +{
  15447. + int ix;
  15448. +
  15449. + /* Global state tracked statistics.
  15450. + */
  15451. + if (sm_state != NULL) {
  15452. + seq_puts(s, "\nDeceased Resources Statistics\n");
  15453. +
  15454. + seq_printf(s, "\nNatural Cause (%u occurences)\n",
  15455. + sm_state->res_deceased_cnt);
  15456. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15457. + if (sm_state->deceased[ix] > 0) {
  15458. + seq_printf(s, " %u\t%s\n",
  15459. + sm_state->deceased[ix],
  15460. + sm_stats_human_read[ix]);
  15461. + }
  15462. + }
  15463. + seq_puts(s, "\n");
  15464. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15465. + if (sm_state->deceased[ix + END_ATTEMPT] > 0) {
  15466. + seq_printf(s, " %u\tFAILED %s\n",
  15467. + sm_state->deceased[ix + END_ATTEMPT],
  15468. + sm_stats_human_read[ix]);
  15469. + }
  15470. + }
  15471. +
  15472. + seq_printf(s, "\nForcefull (%u occurences)\n",
  15473. + sm_state->res_terminated_cnt);
  15474. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15475. + if (sm_state->terminated[ix] > 0) {
  15476. + seq_printf(s, " %u\t%s\n",
  15477. + sm_state->terminated[ix],
  15478. + sm_stats_human_read[ix]);
  15479. + }
  15480. + }
  15481. + seq_puts(s, "\n");
  15482. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15483. + if (sm_state->terminated[ix + END_ATTEMPT] > 0) {
  15484. + seq_printf(s, " %u\tFAILED %s\n",
  15485. + sm_state->terminated[ix +
  15486. + END_ATTEMPT],
  15487. + sm_stats_human_read[ix]);
  15488. + }
  15489. + }
  15490. + }
  15491. +
  15492. + return 0;
  15493. +}
  15494. +
  15495. +#if 0
  15496. +/* Read callback for the statistics proc entry.
  15497. +*/
  15498. +static int vc_sm_statistics_show(struct seq_file *s, void *v)
  15499. +{
  15500. + int ix;
  15501. + struct SM_PRIV_DATA_T *file_data;
  15502. + struct SM_RESOURCE_T *resource;
  15503. + int res_count = 0;
  15504. + struct SM_PDE_T *p_pde;
  15505. +
  15506. + p_pde = (struct SM_PDE_T *)(s->private);
  15507. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  15508. +
  15509. + if (file_data == NULL)
  15510. + return 0;
  15511. +
  15512. + /* Per process statistics.
  15513. + */
  15514. +
  15515. + seq_printf(s, "\nStatistics for TGID %d\n", file_data->pid);
  15516. +
  15517. + mutex_lock(&(sm_state->map_lock));
  15518. +
  15519. + if (!list_empty(&file_data->resource_list)) {
  15520. + list_for_each_entry(resource, &file_data->resource_list,
  15521. + resource_list) {
  15522. + res_count++;
  15523. +
  15524. + seq_printf(s, "\nGUID: 0x%x\n\n",
  15525. + resource->res_guid);
  15526. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15527. + if (resource->res_stats[ix] > 0) {
  15528. + seq_printf(s,
  15529. + " %u\t%s\n",
  15530. + resource->res_stats[ix],
  15531. + sm_stats_human_read[ix]);
  15532. + }
  15533. + }
  15534. + seq_puts(s, "\n");
  15535. + for (ix = 0; ix < END_ATTEMPT; ix++) {
  15536. + if (resource->res_stats[ix + END_ATTEMPT] > 0) {
  15537. + seq_printf(s,
  15538. + " %u\tFAILED %s\n",
  15539. + resource->res_stats[
  15540. + ix + END_ATTEMPT],
  15541. + sm_stats_human_read[ix]);
  15542. + }
  15543. + }
  15544. + }
  15545. + }
  15546. +
  15547. + mutex_unlock(&(sm_state->map_lock));
  15548. +
  15549. + seq_printf(s, "\nResources Count %d\n", res_count);
  15550. +
  15551. + return 0;
  15552. +}
  15553. +#endif
  15554. +
  15555. +#if 0
  15556. +/* Read callback for the allocation proc entry. */
  15557. +static int vc_sm_alloc_show(struct seq_file *s, void *v)
  15558. +{
  15559. + struct SM_PRIV_DATA_T *file_data;
  15560. + struct SM_RESOURCE_T *resource;
  15561. + int alloc_count = 0;
  15562. + struct SM_PDE_T *p_pde;
  15563. +
  15564. + p_pde = (struct SM_PDE_T *)(s->private);
  15565. + file_data = (struct SM_PRIV_DATA_T *)(p_pde->priv_data);
  15566. +
  15567. + if (!file_data)
  15568. + return 0;
  15569. +
  15570. + /* Per process statistics. */
  15571. + seq_printf(s, "\nAllocation for TGID %d\n", file_data->pid);
  15572. +
  15573. + mutex_lock(&(sm_state->map_lock));
  15574. +
  15575. + if (!list_empty(&file_data->resource_list)) {
  15576. + list_for_each_entry(resource, &file_data->resource_list,
  15577. + resource_list) {
  15578. + alloc_count++;
  15579. +
  15580. + seq_printf(s, "\nGUID: 0x%x\n",
  15581. + resource->res_guid);
  15582. + seq_printf(s, "Lock Count: %u\n",
  15583. + resource->lock_count);
  15584. + seq_printf(s, "Mapped: %s\n",
  15585. + (resource->map_count ? "yes" : "no"));
  15586. + seq_printf(s, "VC-handle: 0x%x\n",
  15587. + resource->res_handle);
  15588. + seq_printf(s, "VC-address: 0x%p\n",
  15589. + resource->res_base_mem);
  15590. + seq_printf(s, "VC-size (bytes): %u\n",
  15591. + resource->res_size);
  15592. + seq_printf(s, "Cache: %s\n",
  15593. + sm_cache_map_vector[resource->res_cached]);
  15594. + }
  15595. + }
  15596. +
  15597. + mutex_unlock(&(sm_state->map_lock));
  15598. +
  15599. + seq_printf(s, "\n\nTotal allocation count: %d\n\n", alloc_count);
  15600. +
  15601. + return 0;
  15602. +}
  15603. +#endif
  15604. +
  15605. +static int vc_sm_seq_file_show(struct seq_file *s, void *v)
  15606. +{
  15607. + struct SM_PDE_T *sm_pde;
  15608. +
  15609. + sm_pde = (struct SM_PDE_T *)(s->private);
  15610. +
  15611. + if (sm_pde && sm_pde->show)
  15612. + sm_pde->show(s, v);
  15613. +
  15614. + return 0;
  15615. +}
  15616. +
  15617. +static int vc_sm_single_open(struct inode *inode, struct file *file)
  15618. +{
  15619. + return single_open(file, vc_sm_seq_file_show, inode->i_private);
  15620. +}
  15621. +
  15622. +static const struct file_operations vc_sm_debug_fs_fops = {
  15623. + .open = vc_sm_single_open,
  15624. + .read = seq_read,
  15625. + .llseek = seq_lseek,
  15626. + .release = single_release,
  15627. +};
  15628. +
  15629. +/* Adds a resource to the private data list which tracks all the allocated
  15630. +** data.
  15631. +*/
  15632. +static void vmcs_sm_add_resource(struct SM_PRIV_DATA_T *privdata,
  15633. + struct SM_RESOURCE_T *resource)
  15634. +{
  15635. + mutex_lock(&(sm_state->map_lock));
  15636. + list_add(&resource->resource_list, &privdata->resource_list);
  15637. + list_add(&resource->global_resource_list, &sm_state->resource_list);
  15638. + mutex_unlock(&(sm_state->map_lock));
  15639. +
  15640. + pr_debug("[%s]: added resource %p (base addr %p, hdl %x, size %u, cache %u)\n",
  15641. + __func__, resource, resource->res_base_mem,
  15642. + resource->res_handle, resource->res_size, resource->res_cached);
  15643. +}
  15644. +
  15645. +/* Locates a resource and acquire a reference on it.
  15646. +** The resource won't be deleted while there is a reference on it.
  15647. +*/
  15648. +static struct SM_RESOURCE_T *vmcs_sm_acquire_resource(struct SM_PRIV_DATA_T
  15649. + *private,
  15650. + unsigned int res_guid)
  15651. +{
  15652. + struct SM_RESOURCE_T *resource, *ret = NULL;
  15653. +
  15654. + mutex_lock(&(sm_state->map_lock));
  15655. +
  15656. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  15657. + if (resource->res_guid != res_guid)
  15658. + continue;
  15659. +
  15660. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  15661. + __func__, resource, resource->res_guid,
  15662. + resource->res_base_mem, resource->res_handle,
  15663. + resource->res_size, resource->res_cached);
  15664. + resource->ref_count++;
  15665. + ret = resource;
  15666. + break;
  15667. + }
  15668. +
  15669. + mutex_unlock(&(sm_state->map_lock));
  15670. +
  15671. + return ret;
  15672. +}
  15673. +
  15674. +/* Locates a resource and acquire a reference on it.
  15675. +** The resource won't be deleted while there is a reference on it.
  15676. +*/
  15677. +static struct SM_RESOURCE_T *vmcs_sm_acquire_first_resource(
  15678. + struct SM_PRIV_DATA_T *private)
  15679. +{
  15680. + struct SM_RESOURCE_T *resource, *ret = NULL;
  15681. +
  15682. + mutex_lock(&(sm_state->map_lock));
  15683. +
  15684. + list_for_each_entry(resource, &private->resource_list, resource_list) {
  15685. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  15686. + __func__, resource, resource->res_guid,
  15687. + resource->res_base_mem, resource->res_handle,
  15688. + resource->res_size, resource->res_cached);
  15689. + resource->ref_count++;
  15690. + ret = resource;
  15691. + break;
  15692. + }
  15693. +
  15694. + mutex_unlock(&(sm_state->map_lock));
  15695. +
  15696. + return ret;
  15697. +}
  15698. +
  15699. +/* Locates a resource and acquire a reference on it.
  15700. +** The resource won't be deleted while there is a reference on it.
  15701. +*/
  15702. +static struct SM_RESOURCE_T *vmcs_sm_acquire_global_resource(unsigned int
  15703. + res_guid)
  15704. +{
  15705. + struct SM_RESOURCE_T *resource, *ret = NULL;
  15706. +
  15707. + mutex_lock(&(sm_state->map_lock));
  15708. +
  15709. + list_for_each_entry(resource, &sm_state->resource_list,
  15710. + global_resource_list) {
  15711. + if (resource->res_guid != res_guid)
  15712. + continue;
  15713. +
  15714. + pr_debug("[%s]: located resource %p (guid: %x, base addr %p, hdl %x, size %u, cache %u)\n",
  15715. + __func__, resource, resource->res_guid,
  15716. + resource->res_base_mem, resource->res_handle,
  15717. + resource->res_size, resource->res_cached);
  15718. + resource->ref_count++;
  15719. + ret = resource;
  15720. + break;
  15721. + }
  15722. +
  15723. + mutex_unlock(&(sm_state->map_lock));
  15724. +
  15725. + return ret;
  15726. +}
  15727. +
  15728. +/* Release a previously acquired resource.
  15729. +** The resource will be deleted when its refcount reaches 0.
  15730. +*/
  15731. +static void vmcs_sm_release_resource(struct SM_RESOURCE_T *resource, int force)
  15732. +{
  15733. + struct SM_PRIV_DATA_T *private = resource->private;
  15734. + struct sm_mmap *map, *map_tmp;
  15735. + struct SM_RESOURCE_T *res_tmp;
  15736. + int ret;
  15737. +
  15738. + mutex_lock(&(sm_state->map_lock));
  15739. +
  15740. + if (--resource->ref_count) {
  15741. + if (force)
  15742. + pr_err("[%s]: resource %p in use\n", __func__, resource);
  15743. +
  15744. + mutex_unlock(&(sm_state->map_lock));
  15745. + return;
  15746. + }
  15747. +
  15748. + /* Time to free the resource. Start by removing it from the list */
  15749. + list_del(&resource->resource_list);
  15750. + list_del(&resource->global_resource_list);
  15751. +
  15752. + /* Walk the global resource list, find out if the resource is used
  15753. + * somewhere else. In which case we don't want to delete it.
  15754. + */
  15755. + list_for_each_entry(res_tmp, &sm_state->resource_list,
  15756. + global_resource_list) {
  15757. + if (res_tmp->res_handle == resource->res_handle) {
  15758. + resource->res_handle = 0;
  15759. + break;
  15760. + }
  15761. + }
  15762. +
  15763. + mutex_unlock(&(sm_state->map_lock));
  15764. +
  15765. + pr_debug("[%s]: freeing data - guid %x, hdl %x, base address %p\n",
  15766. + __func__, resource->res_guid, resource->res_handle,
  15767. + resource->res_base_mem);
  15768. + resource->res_stats[FREE]++;
  15769. +
  15770. + /* Make sure the resource we're removing is unmapped first */
  15771. + if (resource->map_count && !list_empty(&resource->map_list)) {
  15772. + down_write(&current->mm->mmap_sem);
  15773. + list_for_each_entry_safe(map, map_tmp, &resource->map_list,
  15774. + resource_map_list) {
  15775. + ret =
  15776. + do_munmap(current->mm, map->res_addr,
  15777. + resource->res_size);
  15778. + if (ret) {
  15779. + pr_err("[%s]: could not unmap resource %p\n",
  15780. + __func__, resource);
  15781. + }
  15782. + }
  15783. + up_write(&current->mm->mmap_sem);
  15784. + }
  15785. +
  15786. + /* Free up the videocore allocated resource.
  15787. + */
  15788. + if (resource->res_handle) {
  15789. + VC_SM_FREE_T free = {
  15790. + resource->res_handle, resource->res_base_mem
  15791. + };
  15792. + int status = vc_vchi_sm_free(sm_state->sm_handle, &free,
  15793. + &private->int_trans_id);
  15794. + if (status != 0 && status != -EINTR) {
  15795. + pr_err("[%s]: failed to free memory on videocore (status: %u, trans_id: %u)\n",
  15796. + __func__, status, private->int_trans_id);
  15797. + resource->res_stats[FREE_FAIL]++;
  15798. + ret = -EPERM;
  15799. + }
  15800. + }
  15801. +
  15802. + /* Free up the shared resource.
  15803. + */
  15804. + if (resource->res_shared)
  15805. + vmcs_sm_release_resource(resource->res_shared, 0);
  15806. +
  15807. + /* Free up the local resource tracking this allocation.
  15808. + */
  15809. + vc_sm_resource_deceased(resource, force);
  15810. + kfree(resource);
  15811. +}
  15812. +
  15813. +/* Dump the map table for the driver. If process is -1, dumps the whole table,
  15814. +** if process is a valid pid (non -1) dump only the entries associated with the
  15815. +** pid of interest.
  15816. +*/
  15817. +static void vmcs_sm_host_walk_map_per_pid(int pid)
  15818. +{
  15819. + struct sm_mmap *map = NULL;
  15820. +
  15821. + /* Make sure the device was started properly.
  15822. + */
  15823. + if (sm_state == NULL) {
  15824. + pr_err("[%s]: invalid device\n", __func__);
  15825. + return;
  15826. + }
  15827. +
  15828. + mutex_lock(&(sm_state->map_lock));
  15829. +
  15830. + /* Log all applicable mapping(s).
  15831. + */
  15832. + if (!list_empty(&sm_state->map_list)) {
  15833. + list_for_each_entry(map, &sm_state->map_list, map_list) {
  15834. + if (pid == -1 || map->res_pid == pid) {
  15835. + pr_info("[%s]: tgid: %u - vc-hdl: %x, usr-hdl: %x, usr-addr: %lx\n",
  15836. + __func__, map->res_pid, map->res_vc_hdl,
  15837. + map->res_usr_hdl, map->res_addr);
  15838. + }
  15839. + }
  15840. + }
  15841. +
  15842. + mutex_unlock(&(sm_state->map_lock));
  15843. +
  15844. + return;
  15845. +}
  15846. +
  15847. +/* Dump the allocation table from host side point of view. This only dumps the
  15848. +** data allocated for this process/device referenced by the file_data.
  15849. +*/
  15850. +static void vmcs_sm_host_walk_alloc(struct SM_PRIV_DATA_T *file_data)
  15851. +{
  15852. + struct SM_RESOURCE_T *resource = NULL;
  15853. +
  15854. + /* Make sure the device was started properly.
  15855. + */
  15856. + if ((sm_state == NULL) || (file_data == NULL)) {
  15857. + pr_err("[%s]: invalid device\n", __func__);
  15858. + return;
  15859. + }
  15860. +
  15861. + mutex_lock(&(sm_state->map_lock));
  15862. +
  15863. + if (!list_empty(&file_data->resource_list)) {
  15864. + list_for_each_entry(resource, &file_data->resource_list,
  15865. + resource_list) {
  15866. + pr_info("[%s]: guid: %x - hdl: %x, vc-mem: %p, size: %u, cache: %u\n",
  15867. + __func__, resource->res_guid, resource->res_handle,
  15868. + resource->res_base_mem, resource->res_size,
  15869. + resource->res_cached);
  15870. + }
  15871. + }
  15872. +
  15873. + mutex_unlock(&(sm_state->map_lock));
  15874. +
  15875. + return;
  15876. +}
  15877. +
  15878. +/* Create support for private data tracking.
  15879. +*/
  15880. +static struct SM_PRIV_DATA_T *vc_sm_create_priv_data(pid_t id)
  15881. +{
  15882. + char alloc_name[32];
  15883. + struct SM_PRIV_DATA_T *file_data = NULL;
  15884. +
  15885. + /* Allocate private structure. */
  15886. + file_data = kzalloc(sizeof(*file_data), GFP_KERNEL);
  15887. +
  15888. + if (!file_data) {
  15889. + pr_err("[%s]: cannot allocate file data\n", __func__);
  15890. + goto out;
  15891. + }
  15892. +
  15893. + snprintf(alloc_name, sizeof(alloc_name), "%d", id);
  15894. +
  15895. + INIT_LIST_HEAD(&file_data->resource_list);
  15896. + file_data->pid = id;
  15897. + file_data->dir_pid = debugfs_create_dir(alloc_name,
  15898. + sm_state->dir_alloc);
  15899. +#if 0
  15900. + /* TODO: fix this to support querying statistics per pid */
  15901. +
  15902. + if (IS_ERR_OR_NULL(file_data->dir_pid)) {
  15903. + file_data->dir_pid = NULL;
  15904. + } else {
  15905. + struct dentry *dir_entry;
  15906. +
  15907. + dir_entry = debugfs_create_file(VC_SM_RESOURCES, S_IRUGO,
  15908. + file_data->dir_pid, file_data,
  15909. + vc_sm_debug_fs_fops);
  15910. +
  15911. + file_data->dir_res.dir_entry = dir_entry;
  15912. + file_data->dir_res.priv_data = file_data;
  15913. + file_data->dir_res.show = &vc_sm_alloc_show;
  15914. +
  15915. + dir_entry = debugfs_create_file(VC_SM_STATS, S_IRUGO,
  15916. + file_data->dir_pid, file_data,
  15917. + vc_sm_debug_fs_fops);
  15918. +
  15919. + file_data->dir_res.dir_entry = dir_entry;
  15920. + file_data->dir_res.priv_data = file_data;
  15921. + file_data->dir_res.show = &vc_sm_statistics_show;
  15922. + }
  15923. + pr_debug("[%s]: private data allocated %p\n", __func__, file_data);
  15924. +
  15925. +#endif
  15926. +out:
  15927. + return file_data;
  15928. +}
  15929. +
  15930. +/* Open the device. Creates a private state to help track all allocation
  15931. +** associated with this device.
  15932. +*/
  15933. +static int vc_sm_open(struct inode *inode, struct file *file)
  15934. +{
  15935. + int ret = 0;
  15936. +
  15937. + /* Make sure the device was started properly.
  15938. + */
  15939. + if (!sm_state) {
  15940. + pr_err("[%s]: invalid device\n", __func__);
  15941. + ret = -EPERM;
  15942. + goto out;
  15943. + }
  15944. +
  15945. + file->private_data = vc_sm_create_priv_data(current->tgid);
  15946. + if (file->private_data == NULL) {
  15947. + pr_err("[%s]: failed to create data tracker\n", __func__);
  15948. +
  15949. + ret = -ENOMEM;
  15950. + goto out;
  15951. + }
  15952. +
  15953. +out:
  15954. + return ret;
  15955. +}
  15956. +
  15957. +/* Close the device. Free up all resources still associated with this device
  15958. +** at the time.
  15959. +*/
  15960. +static int vc_sm_release(struct inode *inode, struct file *file)
  15961. +{
  15962. + struct SM_PRIV_DATA_T *file_data =
  15963. + (struct SM_PRIV_DATA_T *)file->private_data;
  15964. + struct SM_RESOURCE_T *resource;
  15965. + int ret = 0;
  15966. +
  15967. + /* Make sure the device was started properly.
  15968. + */
  15969. + if (sm_state == NULL || file_data == NULL) {
  15970. + pr_err("[%s]: invalid device\n", __func__);
  15971. + ret = -EPERM;
  15972. + goto out;
  15973. + }
  15974. +
  15975. + pr_debug("[%s]: using private data %p\n", __func__, file_data);
  15976. +
  15977. + if (file_data->restart_sys == -EINTR) {
  15978. + VC_SM_ACTION_CLEAN_T action_clean;
  15979. +
  15980. + pr_debug("[%s]: releasing following EINTR on %u (trans_id: %u) (likely due to signal)...\n",
  15981. + __func__, file_data->int_action,
  15982. + file_data->int_trans_id);
  15983. +
  15984. + action_clean.res_action = file_data->int_action;
  15985. + action_clean.action_trans_id = file_data->int_trans_id;
  15986. +
  15987. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  15988. + }
  15989. +
  15990. + while ((resource = vmcs_sm_acquire_first_resource(file_data)) != NULL) {
  15991. + vmcs_sm_release_resource(resource, 0);
  15992. + vmcs_sm_release_resource(resource, 1);
  15993. + }
  15994. +
  15995. + /* Remove the corresponding proc entry. */
  15996. + debugfs_remove_recursive(file_data->dir_pid);
  15997. +
  15998. + /* Terminate the private data.
  15999. + */
  16000. + kfree(file_data);
  16001. +
  16002. +out:
  16003. + return ret;
  16004. +}
  16005. +
  16006. +static void vcsm_vma_open(struct vm_area_struct *vma)
  16007. +{
  16008. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  16009. +
  16010. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  16011. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  16012. + (int)vma->vm_pgoff);
  16013. +
  16014. + map->ref_count++;
  16015. +}
  16016. +
  16017. +static void vcsm_vma_close(struct vm_area_struct *vma)
  16018. +{
  16019. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  16020. +
  16021. + pr_debug("[%s]: virt %lx-%lx, pid %i, pfn %i\n",
  16022. + __func__, vma->vm_start, vma->vm_end, (int)current->tgid,
  16023. + (int)vma->vm_pgoff);
  16024. +
  16025. + map->ref_count--;
  16026. +
  16027. + /* Remove from the map table.
  16028. + */
  16029. + if (map->ref_count == 0)
  16030. + vmcs_sm_remove_map(sm_state, map->resource, map);
  16031. +}
  16032. +
  16033. +static int vcsm_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  16034. +{
  16035. + struct sm_mmap *map = (struct sm_mmap *)vma->vm_private_data;
  16036. + struct SM_RESOURCE_T *resource = map->resource;
  16037. + pgoff_t page_offset;
  16038. + unsigned long pfn;
  16039. + int ret = 0;
  16040. +
  16041. + /* Lock the resource if necessary.
  16042. + */
  16043. + if (!resource->lock_count) {
  16044. + VC_SM_LOCK_UNLOCK_T lock_unlock;
  16045. + VC_SM_LOCK_RESULT_T lock_result;
  16046. + int status;
  16047. +
  16048. + lock_unlock.res_handle = resource->res_handle;
  16049. + lock_unlock.res_mem = resource->res_base_mem;
  16050. +
  16051. + pr_debug("[%s]: attempt to lock data - hdl %x, base address %p\n",
  16052. + __func__, lock_unlock.res_handle, lock_unlock.res_mem);
  16053. +
  16054. + /* Lock the videocore allocated resource.
  16055. + */
  16056. + status = vc_vchi_sm_lock(sm_state->sm_handle,
  16057. + &lock_unlock, &lock_result, 0);
  16058. + if ((status != 0) ||
  16059. + ((status == 0) && (lock_result.res_mem == NULL))) {
  16060. + pr_err("[%s]: failed to lock memory on videocore (status: %u)\n",
  16061. + __func__, status);
  16062. + resource->res_stats[LOCK_FAIL]++;
  16063. + return VM_FAULT_SIGBUS;
  16064. + }
  16065. +
  16066. + pfn = vcaddr_to_pfn((unsigned long)resource->res_base_mem);
  16067. + outer_inv_range(__pfn_to_phys(pfn),
  16068. + __pfn_to_phys(pfn) + resource->res_size);
  16069. +
  16070. + resource->res_stats[LOCK]++;
  16071. + resource->lock_count++;
  16072. +
  16073. + /* Keep track of the new base memory.
  16074. + */
  16075. + if ((lock_result.res_mem != NULL) &&
  16076. + (lock_result.res_old_mem != NULL) &&
  16077. + (lock_result.res_mem != lock_result.res_old_mem)) {
  16078. + resource->res_base_mem = lock_result.res_mem;
  16079. + }
  16080. + }
  16081. +
  16082. + /* We don't use vmf->pgoff since that has the fake offset */
  16083. + page_offset = ((unsigned long)vmf->virtual_address - vma->vm_start);
  16084. + pfn = (uint32_t)resource->res_base_mem & 0x3FFFFFFF;
  16085. + pfn += mm_vc_mem_phys_addr;
  16086. + pfn += page_offset;
  16087. + pfn >>= PAGE_SHIFT;
  16088. +
  16089. + /* Finally, remap it */
  16090. + ret = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
  16091. +
  16092. + switch (ret) {
  16093. + case 0:
  16094. + case -ERESTARTSYS:
  16095. + return VM_FAULT_NOPAGE;
  16096. + case -ENOMEM:
  16097. + case -EAGAIN:
  16098. + return VM_FAULT_OOM;
  16099. + default:
  16100. + return VM_FAULT_SIGBUS;
  16101. + }
  16102. +}
  16103. +
  16104. +static struct vm_operations_struct vcsm_vm_ops = {
  16105. + .open = vcsm_vma_open,
  16106. + .close = vcsm_vma_close,
  16107. + .fault = vcsm_vma_fault,
  16108. +};
  16109. +
  16110. +/* Walks a VMA and clean each valid page from the cache */
  16111. +static void vcsm_vma_cache_clean_page_range(unsigned long addr,
  16112. + unsigned long end)
  16113. +{
  16114. + pgd_t *pgd;
  16115. + pud_t *pud;
  16116. + pmd_t *pmd;
  16117. + pte_t *pte;
  16118. + unsigned long pgd_next, pud_next, pmd_next;
  16119. +
  16120. + if (addr >= end)
  16121. + return;
  16122. +
  16123. + /* Walk PGD */
  16124. + pgd = pgd_offset(current->mm, addr);
  16125. + do {
  16126. + pgd_next = pgd_addr_end(addr, end);
  16127. +
  16128. + if (pgd_none(*pgd) || pgd_bad(*pgd))
  16129. + continue;
  16130. +
  16131. + /* Walk PUD */
  16132. + pud = pud_offset(pgd, addr);
  16133. + do {
  16134. + pud_next = pud_addr_end(addr, pgd_next);
  16135. + if (pud_none(*pud) || pud_bad(*pud))
  16136. + continue;
  16137. +
  16138. + /* Walk PMD */
  16139. + pmd = pmd_offset(pud, addr);
  16140. + do {
  16141. + pmd_next = pmd_addr_end(addr, pud_next);
  16142. + if (pmd_none(*pmd) || pmd_bad(*pmd))
  16143. + continue;
  16144. +
  16145. + /* Walk PTE */
  16146. + pte = pte_offset_map(pmd, addr);
  16147. + do {
  16148. + if (pte_none(*pte)
  16149. + || !pte_present(*pte))
  16150. + continue;
  16151. +
  16152. + /* Clean + invalidate */
  16153. + dmac_flush_range((const void *) addr,
  16154. + (const void *)
  16155. + (addr + PAGE_SIZE));
  16156. +
  16157. + } while (pte++, addr +=
  16158. + PAGE_SIZE, addr != pmd_next);
  16159. + pte_unmap(pte);
  16160. +
  16161. + } while (pmd++, addr = pmd_next, addr != pud_next);
  16162. +
  16163. + } while (pud++, addr = pud_next, addr != pgd_next);
  16164. + } while (pgd++, addr = pgd_next, addr != end);
  16165. +}
  16166. +
  16167. +/* Map an allocated data into something that the user space.
  16168. +*/
  16169. +static int vc_sm_mmap(struct file *file, struct vm_area_struct *vma)
  16170. +{
  16171. + int ret = 0;
  16172. + struct SM_PRIV_DATA_T *file_data =
  16173. + (struct SM_PRIV_DATA_T *)file->private_data;
  16174. + struct SM_RESOURCE_T *resource = NULL;
  16175. + struct sm_mmap *map = NULL;
  16176. +
  16177. + /* Make sure the device was started properly.
  16178. + */
  16179. + if ((sm_state == NULL) || (file_data == NULL)) {
  16180. + pr_err("[%s]: invalid device\n", __func__);
  16181. + return -EPERM;
  16182. + }
  16183. +
  16184. + pr_debug("[%s]: private data %p, guid %x\n", __func__, file_data,
  16185. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  16186. +
  16187. + /* We lookup to make sure that the data we are being asked to mmap is
  16188. + ** something that we allocated.
  16189. + **
  16190. + ** We use the offset information as the key to tell us which resource
  16191. + ** we are mapping.
  16192. + */
  16193. + resource = vmcs_sm_acquire_resource(file_data,
  16194. + ((unsigned int)vma->vm_pgoff <<
  16195. + PAGE_SHIFT));
  16196. + if (resource == NULL) {
  16197. + pr_err("[%s]: failed to locate resource for guid %x\n", __func__,
  16198. + ((unsigned int)vma->vm_pgoff << PAGE_SHIFT));
  16199. + return -ENOMEM;
  16200. + }
  16201. +
  16202. + pr_debug("[%s]: guid %x, tgid %u, %u, %u\n",
  16203. + __func__, resource->res_guid, current->tgid, resource->pid,
  16204. + file_data->pid);
  16205. +
  16206. + /* Check permissions.
  16207. + */
  16208. + if (resource->pid && (resource->pid != current->tgid)) {
  16209. + pr_err("[%s]: current tgid %u != %u owner\n",
  16210. + __func__, current->tgid, resource->pid);
  16211. + ret = -EPERM;
  16212. + goto error;
  16213. + }
  16214. +
  16215. + /* Verify that what we are asked to mmap is proper.
  16216. + */
  16217. + if (resource->res_size != (unsigned int)(vma->vm_end - vma->vm_start)) {
  16218. + pr_err("[%s]: size inconsistency (resource: %u - mmap: %u)\n",
  16219. + __func__,
  16220. + resource->res_size,
  16221. + (unsigned int)(vma->vm_end - vma->vm_start));
  16222. +
  16223. + ret = -EINVAL;
  16224. + goto error;
  16225. + }
  16226. +
  16227. + /* Keep track of the tuple in the global resource list such that one
  16228. + * can do a mapping lookup for address/memory handle.
  16229. + */
  16230. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  16231. + if (map == NULL) {
  16232. + pr_err("[%s]: failed to allocate global tracking resource\n",
  16233. + __func__);
  16234. + ret = -ENOMEM;
  16235. + goto error;
  16236. + }
  16237. +
  16238. + map->res_pid = current->tgid;
  16239. + map->res_vc_hdl = resource->res_handle;
  16240. + map->res_usr_hdl = resource->res_guid;
  16241. + map->res_addr = (long unsigned int)vma->vm_start;
  16242. + map->resource = resource;
  16243. + map->vma = vma;
  16244. + vmcs_sm_add_map(sm_state, resource, map);
  16245. +
  16246. + /* We are not actually mapping the pages, we just provide a fault
  16247. + ** handler to allow pages to be mapped when accessed
  16248. + */
  16249. + vma->vm_flags |=
  16250. + VM_IO | VM_PFNMAP | VM_DONTCOPY | VM_DONTEXPAND;
  16251. + vma->vm_ops = &vcsm_vm_ops;
  16252. + vma->vm_private_data = map;
  16253. +
  16254. + /* vm_pgoff is the first PFN of the mapped memory */
  16255. + vma->vm_pgoff = (unsigned long)resource->res_base_mem & 0x3FFFFFFF;
  16256. + vma->vm_pgoff += mm_vc_mem_phys_addr;
  16257. + vma->vm_pgoff >>= PAGE_SHIFT;
  16258. +
  16259. + if ((resource->res_cached == VMCS_SM_CACHE_NONE) ||
  16260. + (resource->res_cached == VMCS_SM_CACHE_VC)) {
  16261. + /* Allocated non host cached memory, honour it.
  16262. + */
  16263. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  16264. + }
  16265. +
  16266. + pr_debug("[%s]: resource %p (guid %x) - cnt %u, base address %p, handle %x, size %u (%u), cache %u\n",
  16267. + __func__,
  16268. + resource, resource->res_guid, resource->lock_count,
  16269. + resource->res_base_mem, resource->res_handle,
  16270. + resource->res_size, (unsigned int)(vma->vm_end - vma->vm_start),
  16271. + resource->res_cached);
  16272. +
  16273. + pr_debug("[%s]: resource %p (base address %p, handle %x) - map-count %d, usr-addr %x\n",
  16274. + __func__, resource, resource->res_base_mem,
  16275. + resource->res_handle, resource->map_count,
  16276. + (unsigned int)vma->vm_start);
  16277. +
  16278. + vcsm_vma_open(vma);
  16279. + resource->res_stats[MAP]++;
  16280. + vmcs_sm_release_resource(resource, 0);
  16281. + return 0;
  16282. +
  16283. +error:
  16284. + vmcs_sm_release_resource(resource, 0);
  16285. + resource->res_stats[MAP_FAIL]++;
  16286. + return ret;
  16287. +}
  16288. +
  16289. +/* Allocate a shared memory handle and block.
  16290. +*/
  16291. +int vc_sm_ioctl_alloc(struct SM_PRIV_DATA_T *private,
  16292. + struct vmcs_sm_ioctl_alloc *ioparam)
  16293. +{
  16294. + int ret = 0;
  16295. + int status;
  16296. + struct SM_RESOURCE_T *resource;
  16297. + VC_SM_ALLOC_T alloc = { 0 };
  16298. + VC_SM_ALLOC_RESULT_T result = { 0 };
  16299. +
  16300. + /* Setup our allocation parameters */
  16301. + alloc.type = ((ioparam->cached == VMCS_SM_CACHE_VC)
  16302. + || (ioparam->cached ==
  16303. + VMCS_SM_CACHE_BOTH)) ? VC_SM_ALLOC_CACHED :
  16304. + VC_SM_ALLOC_NON_CACHED;
  16305. + alloc.base_unit = ioparam->size;
  16306. + alloc.num_unit = ioparam->num;
  16307. + alloc.allocator = current->tgid;
  16308. + /* Align to kernel page size */
  16309. + alloc.alignement = 4096;
  16310. + /* Align the size to the kernel page size */
  16311. + alloc.base_unit =
  16312. + (alloc.base_unit + alloc.alignement - 1) & ~(alloc.alignement - 1);
  16313. + if (*ioparam->name) {
  16314. + memcpy(alloc.name, ioparam->name, sizeof(alloc.name) - 1);
  16315. + } else {
  16316. + memcpy(alloc.name, VMCS_SM_RESOURCE_NAME_DEFAULT,
  16317. + sizeof(VMCS_SM_RESOURCE_NAME_DEFAULT));
  16318. + }
  16319. +
  16320. + pr_debug("[%s]: attempt to allocate \"%s\" data - type %u, base %u (%u), num %u, alignement %u\n",
  16321. + __func__, alloc.name, alloc.type, ioparam->size,
  16322. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  16323. +
  16324. + /* Allocate local resource to track this allocation.
  16325. + */
  16326. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  16327. + if (!resource) {
  16328. + ret = -ENOMEM;
  16329. + goto error;
  16330. + }
  16331. + INIT_LIST_HEAD(&resource->map_list);
  16332. + resource->ref_count++;
  16333. + resource->pid = current->tgid;
  16334. +
  16335. + /* Allocate the videocore resource.
  16336. + */
  16337. + status = vc_vchi_sm_alloc(sm_state->sm_handle, &alloc, &result,
  16338. + &private->int_trans_id);
  16339. + if (status == -EINTR) {
  16340. + pr_debug("[%s]: requesting allocate memory action restart (trans_id: %u)\n",
  16341. + __func__, private->int_trans_id);
  16342. + ret = -ERESTARTSYS;
  16343. + private->restart_sys = -EINTR;
  16344. + private->int_action = VC_SM_MSG_TYPE_ALLOC;
  16345. + goto error;
  16346. + } else if (status != 0 || (status == 0 && result.res_mem == NULL)) {
  16347. + pr_err("[%s]: failed to allocate memory on videocore (status: %u, trans_id: %u)\n",
  16348. + __func__, status, private->int_trans_id);
  16349. + ret = -ENOMEM;
  16350. + resource->res_stats[ALLOC_FAIL]++;
  16351. + goto error;
  16352. + }
  16353. +
  16354. + /* Keep track of the resource we created.
  16355. + */
  16356. + resource->private = private;
  16357. + resource->res_handle = result.res_handle;
  16358. + resource->res_base_mem = result.res_mem;
  16359. + resource->res_size = alloc.base_unit * alloc.num_unit;
  16360. + resource->res_cached = ioparam->cached;
  16361. +
  16362. + /* Kernel/user GUID. This global identifier is used for mmap'ing the
  16363. + * allocated region from user space, it is passed as the mmap'ing
  16364. + * offset, we use it to 'hide' the videocore handle/address.
  16365. + */
  16366. + mutex_lock(&sm_state->lock);
  16367. + resource->res_guid = ++sm_state->guid;
  16368. + mutex_unlock(&sm_state->lock);
  16369. + resource->res_guid <<= PAGE_SHIFT;
  16370. +
  16371. + vmcs_sm_add_resource(private, resource);
  16372. +
  16373. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  16374. + __func__, resource->res_guid, resource->res_handle,
  16375. + resource->res_base_mem, resource->res_size,
  16376. + resource->res_cached);
  16377. +
  16378. + /* We're done */
  16379. + resource->res_stats[ALLOC]++;
  16380. + ioparam->handle = resource->res_guid;
  16381. + return 0;
  16382. +
  16383. +error:
  16384. + pr_err("[%s]: failed to allocate \"%s\" data (%i) - type %u, base %u (%u), num %u, alignment %u\n",
  16385. + __func__, alloc.name, ret, alloc.type, ioparam->size,
  16386. + alloc.base_unit, alloc.num_unit, alloc.alignement);
  16387. + if (resource != NULL) {
  16388. + vc_sm_resource_deceased(resource, 1);
  16389. + kfree(resource);
  16390. + }
  16391. + return ret;
  16392. +}
  16393. +
  16394. +/* Share an allocate memory handle and block.
  16395. +*/
  16396. +int vc_sm_ioctl_alloc_share(struct SM_PRIV_DATA_T *private,
  16397. + struct vmcs_sm_ioctl_alloc_share *ioparam)
  16398. +{
  16399. + struct SM_RESOURCE_T *resource, *shared_resource;
  16400. + int ret = 0;
  16401. +
  16402. + pr_debug("[%s]: attempt to share resource %u\n", __func__,
  16403. + ioparam->handle);
  16404. +
  16405. + shared_resource = vmcs_sm_acquire_global_resource(ioparam->handle);
  16406. + if (shared_resource == NULL) {
  16407. + ret = -ENOMEM;
  16408. + goto error;
  16409. + }
  16410. +
  16411. + /* Allocate local resource to track this allocation.
  16412. + */
  16413. + resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  16414. + if (resource == NULL) {
  16415. + pr_err("[%s]: failed to allocate local tracking resource\n",
  16416. + __func__);
  16417. + ret = -ENOMEM;
  16418. + goto error;
  16419. + }
  16420. + INIT_LIST_HEAD(&resource->map_list);
  16421. + resource->ref_count++;
  16422. + resource->pid = current->tgid;
  16423. +
  16424. + /* Keep track of the resource we created.
  16425. + */
  16426. + resource->private = private;
  16427. + resource->res_handle = shared_resource->res_handle;
  16428. + resource->res_base_mem = shared_resource->res_base_mem;
  16429. + resource->res_size = shared_resource->res_size;
  16430. + resource->res_cached = shared_resource->res_cached;
  16431. + resource->res_shared = shared_resource;
  16432. +
  16433. + mutex_lock(&sm_state->lock);
  16434. + resource->res_guid = ++sm_state->guid;
  16435. + mutex_unlock(&sm_state->lock);
  16436. + resource->res_guid <<= PAGE_SHIFT;
  16437. +
  16438. + vmcs_sm_add_resource(private, resource);
  16439. +
  16440. + pr_debug("[%s]: allocated data - guid %x, hdl %x, base address %p, size %d, cache %d\n",
  16441. + __func__, resource->res_guid, resource->res_handle,
  16442. + resource->res_base_mem, resource->res_size,
  16443. + resource->res_cached);
  16444. +
  16445. + /* We're done */
  16446. + resource->res_stats[ALLOC]++;
  16447. + ioparam->handle = resource->res_guid;
  16448. + ioparam->size = resource->res_size;
  16449. + return 0;
  16450. +
  16451. +error:
  16452. + pr_err("[%s]: failed to share %u\n", __func__, ioparam->handle);
  16453. + if (shared_resource != NULL)
  16454. + vmcs_sm_release_resource(shared_resource, 0);
  16455. +
  16456. + return ret;
  16457. +}
  16458. +
  16459. +/* Free a previously allocated shared memory handle and block.
  16460. +*/
  16461. +static int vc_sm_ioctl_free(struct SM_PRIV_DATA_T *private,
  16462. + struct vmcs_sm_ioctl_free *ioparam)
  16463. +{
  16464. + struct SM_RESOURCE_T *resource =
  16465. + vmcs_sm_acquire_resource(private, ioparam->handle);
  16466. +
  16467. + if (resource == NULL) {
  16468. + pr_err("[%s]: resource for guid %u does not exist\n", __func__,
  16469. + ioparam->handle);
  16470. + return -EINVAL;
  16471. + }
  16472. +
  16473. + /* Check permissions.
  16474. + */
  16475. + if (resource->pid && (resource->pid != current->tgid)) {
  16476. + pr_err("[%s]: current tgid %u != %u owner\n",
  16477. + __func__, current->tgid, resource->pid);
  16478. + vmcs_sm_release_resource(resource, 0);
  16479. + return -EPERM;
  16480. + }
  16481. +
  16482. + vmcs_sm_release_resource(resource, 0);
  16483. + vmcs_sm_release_resource(resource, 0);
  16484. + return 0;
  16485. +}
  16486. +
  16487. +/* Resize a previously allocated shared memory handle and block.
  16488. +*/
  16489. +static int vc_sm_ioctl_resize(struct SM_PRIV_DATA_T *private,
  16490. + struct vmcs_sm_ioctl_resize *ioparam)
  16491. +{
  16492. + int ret = 0;
  16493. + int status;
  16494. + VC_SM_RESIZE_T resize;
  16495. + struct SM_RESOURCE_T *resource;
  16496. +
  16497. + /* Locate resource from GUID.
  16498. + */
  16499. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  16500. + if (!resource) {
  16501. + pr_err("[%s]: failed resource - guid %x\n",
  16502. + __func__, ioparam->handle);
  16503. + ret = -EFAULT;
  16504. + goto error;
  16505. + }
  16506. +
  16507. + /* If the resource is locked, its reference count will be not NULL,
  16508. + ** in which case we will not be allowed to resize it anyways, so
  16509. + ** reject the attempt here.
  16510. + */
  16511. + if (resource->lock_count != 0) {
  16512. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  16513. + __func__, ioparam->handle, resource->lock_count);
  16514. + ret = -EFAULT;
  16515. + goto error;
  16516. + }
  16517. +
  16518. + /* Check permissions.
  16519. + */
  16520. + if (resource->pid && (resource->pid != current->tgid)) {
  16521. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  16522. + current->tgid, resource->pid);
  16523. + ret = -EPERM;
  16524. + goto error;
  16525. + }
  16526. +
  16527. + if (resource->map_count != 0) {
  16528. + pr_err("[%s]: cannot resize - guid %x, ref-cnt %d\n",
  16529. + __func__, ioparam->handle, resource->map_count);
  16530. + ret = -EFAULT;
  16531. + goto error;
  16532. + }
  16533. +
  16534. + resize.res_handle = resource->res_handle;
  16535. + resize.res_mem = resource->res_base_mem;
  16536. + resize.res_new_size = ioparam->new_size;
  16537. +
  16538. + pr_debug("[%s]: attempt to resize data - guid %x, hdl %x, base address %p\n",
  16539. + __func__, ioparam->handle, resize.res_handle, resize.res_mem);
  16540. +
  16541. + /* Resize the videocore allocated resource.
  16542. + */
  16543. + status = vc_vchi_sm_resize(sm_state->sm_handle, &resize,
  16544. + &private->int_trans_id);
  16545. + if (status == -EINTR) {
  16546. + pr_debug("[%s]: requesting resize memory action restart (trans_id: %u)\n",
  16547. + __func__, private->int_trans_id);
  16548. + ret = -ERESTARTSYS;
  16549. + private->restart_sys = -EINTR;
  16550. + private->int_action = VC_SM_MSG_TYPE_RESIZE;
  16551. + goto error;
  16552. + } else if (status != 0) {
  16553. + pr_err("[%s]: failed to resize memory on videocore (status: %u, trans_id: %u)\n",
  16554. + __func__, status, private->int_trans_id);
  16555. + ret = -EPERM;
  16556. + goto error;
  16557. + }
  16558. +
  16559. + pr_debug("[%s]: success to resize data - hdl %x, size %d -> %d\n",
  16560. + __func__, resize.res_handle, resource->res_size,
  16561. + resize.res_new_size);
  16562. +
  16563. + /* Successfully resized, save the information and inform the user.
  16564. + */
  16565. + ioparam->old_size = resource->res_size;
  16566. + resource->res_size = resize.res_new_size;
  16567. +
  16568. +error:
  16569. + if (resource)
  16570. + vmcs_sm_release_resource(resource, 0);
  16571. +
  16572. + return ret;
  16573. +}
  16574. +
  16575. +/* Lock a previously allocated shared memory handle and block.
  16576. +*/
  16577. +static int vc_sm_ioctl_lock(struct SM_PRIV_DATA_T *private,
  16578. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  16579. + int change_cache, enum vmcs_sm_cache_e cache_type,
  16580. + unsigned int vc_addr)
  16581. +{
  16582. + int status;
  16583. + VC_SM_LOCK_UNLOCK_T lock;
  16584. + VC_SM_LOCK_RESULT_T result;
  16585. + struct SM_RESOURCE_T *resource;
  16586. + int ret = 0;
  16587. + struct sm_mmap *map, *map_tmp;
  16588. + long unsigned int phys_addr;
  16589. +
  16590. + map = NULL;
  16591. +
  16592. + /* Locate resource from GUID.
  16593. + */
  16594. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  16595. + if (resource == NULL) {
  16596. + ret = -EINVAL;
  16597. + goto error;
  16598. + }
  16599. +
  16600. + /* Check permissions.
  16601. + */
  16602. + if (resource->pid && (resource->pid != current->tgid)) {
  16603. + pr_err("[%s]: current tgid %u != %u owner\n", __func__,
  16604. + current->tgid, resource->pid);
  16605. + ret = -EPERM;
  16606. + goto error;
  16607. + }
  16608. +
  16609. + lock.res_handle = resource->res_handle;
  16610. + lock.res_mem = resource->res_base_mem;
  16611. +
  16612. + /* Take the lock and get the address to be mapped.
  16613. + */
  16614. + if (vc_addr == 0) {
  16615. + pr_debug("[%s]: attempt to lock data - guid %x, hdl %x, base address %p\n",
  16616. + __func__, ioparam->handle, lock.res_handle,
  16617. + lock.res_mem);
  16618. +
  16619. + /* Lock the videocore allocated resource.
  16620. + */
  16621. + status = vc_vchi_sm_lock(sm_state->sm_handle, &lock, &result,
  16622. + &private->int_trans_id);
  16623. + if (status == -EINTR) {
  16624. + pr_debug("[%s]: requesting lock memory action restart (trans_id: %u)\n",
  16625. + __func__, private->int_trans_id);
  16626. + ret = -ERESTARTSYS;
  16627. + private->restart_sys = -EINTR;
  16628. + private->int_action = VC_SM_MSG_TYPE_LOCK;
  16629. + goto error;
  16630. + } else if (status != 0 ||
  16631. + (status == 0 && result.res_mem == NULL)) {
  16632. + pr_err("[%s]: failed to lock memory on videocore (status: %u, trans_id: %u)\n",
  16633. + __func__, status, private->int_trans_id);
  16634. + ret = -EPERM;
  16635. + resource->res_stats[LOCK_FAIL]++;
  16636. + goto error;
  16637. + }
  16638. +
  16639. + pr_debug("[%s]: succeed to lock data - hdl %x, base address %p (%p), ref-cnt %d\n",
  16640. + __func__, lock.res_handle, result.res_mem,
  16641. + lock.res_mem, resource->lock_count);
  16642. + }
  16643. + /* Lock assumed taken already, address to be mapped is known.
  16644. + */
  16645. + else
  16646. + resource->res_base_mem = (void *)vc_addr;
  16647. +
  16648. + resource->res_stats[LOCK]++;
  16649. + resource->lock_count++;
  16650. +
  16651. + /* Keep track of the new base memory allocation if it has changed.
  16652. + */
  16653. + if ((vc_addr == 0) &&
  16654. + (result.res_mem != NULL) &&
  16655. + (result.res_old_mem != NULL) &&
  16656. + (result.res_mem != result.res_old_mem)) {
  16657. + resource->res_base_mem = result.res_mem;
  16658. +
  16659. + /* Kernel allocated resources.
  16660. + */
  16661. + if (resource->pid == 0) {
  16662. + if (!list_empty(&resource->map_list)) {
  16663. + list_for_each_entry_safe(map, map_tmp,
  16664. + &resource->map_list,
  16665. + resource_map_list) {
  16666. + if (map->res_addr) {
  16667. + iounmap((void *)map->res_addr);
  16668. + map->res_addr = 0;
  16669. +
  16670. + vmcs_sm_remove_map(sm_state,
  16671. + map->resource,
  16672. + map);
  16673. + break;
  16674. + }
  16675. + }
  16676. + }
  16677. + }
  16678. + }
  16679. +
  16680. + if (change_cache)
  16681. + resource->res_cached = cache_type;
  16682. +
  16683. + if (resource->map_count) {
  16684. + ioparam->addr =
  16685. + vmcs_sm_usr_address_from_pid_and_usr_handle(
  16686. + current->tgid, ioparam->handle);
  16687. +
  16688. + pr_debug("[%s] map_count %d private->pid %d current->tgid %d hnd %x addr %u\n",
  16689. + __func__, resource->map_count, private->pid,
  16690. + current->tgid, ioparam->handle, ioparam->addr);
  16691. + } else {
  16692. + /* Kernel allocated resources.
  16693. + */
  16694. + if (resource->pid == 0) {
  16695. + pr_debug("[%s]: attempt mapping kernel resource - guid %x, hdl %x\n",
  16696. + __func__, ioparam->handle, lock.res_handle);
  16697. +
  16698. + ioparam->addr = 0;
  16699. +
  16700. + map = kzalloc(sizeof(*map), GFP_KERNEL);
  16701. + if (map == NULL) {
  16702. + pr_err("[%s]: failed allocating tracker\n",
  16703. + __func__);
  16704. + ret = -ENOMEM;
  16705. + goto error;
  16706. + } else {
  16707. + phys_addr = (uint32_t)resource->res_base_mem &
  16708. + 0x3FFFFFFF;
  16709. + phys_addr += mm_vc_mem_phys_addr;
  16710. + if (resource->res_cached
  16711. + == VMCS_SM_CACHE_HOST) {
  16712. + ioparam->addr = (long unsigned int)
  16713. + /* TODO - make cached work */
  16714. + ioremap_nocache(phys_addr,
  16715. + resource->res_size);
  16716. +
  16717. + pr_debug("[%s]: mapping kernel - guid %x, hdl %x - cached mapping %u\n",
  16718. + __func__, ioparam->handle,
  16719. + lock.res_handle, ioparam->addr);
  16720. + } else {
  16721. + ioparam->addr = (long unsigned int)
  16722. + ioremap_nocache(phys_addr,
  16723. + resource->res_size);
  16724. +
  16725. + pr_debug("[%s]: mapping kernel- guid %x, hdl %x - non cached mapping %u\n",
  16726. + __func__, ioparam->handle,
  16727. + lock.res_handle, ioparam->addr);
  16728. + }
  16729. +
  16730. + map->res_pid = 0;
  16731. + map->res_vc_hdl = resource->res_handle;
  16732. + map->res_usr_hdl = resource->res_guid;
  16733. + map->res_addr = ioparam->addr;
  16734. + map->resource = resource;
  16735. + map->vma = NULL;
  16736. +
  16737. + vmcs_sm_add_map(sm_state, resource, map);
  16738. + }
  16739. + } else
  16740. + ioparam->addr = 0;
  16741. + }
  16742. +
  16743. +error:
  16744. + if (resource)
  16745. + vmcs_sm_release_resource(resource, 0);
  16746. +
  16747. + return ret;
  16748. +}
  16749. +
  16750. +/* Unlock a previously allocated shared memory handle and block.
  16751. +*/
  16752. +static int vc_sm_ioctl_unlock(struct SM_PRIV_DATA_T *private,
  16753. + struct vmcs_sm_ioctl_lock_unlock *ioparam,
  16754. + int flush, int wait_reply, int no_vc_unlock)
  16755. +{
  16756. + int status;
  16757. + VC_SM_LOCK_UNLOCK_T unlock;
  16758. + struct sm_mmap *map, *map_tmp;
  16759. + struct SM_RESOURCE_T *resource;
  16760. + int ret = 0;
  16761. +
  16762. + map = NULL;
  16763. +
  16764. + /* Locate resource from GUID.
  16765. + */
  16766. + resource = vmcs_sm_acquire_resource(private, ioparam->handle);
  16767. + if (resource == NULL) {
  16768. + ret = -EINVAL;
  16769. + goto error;
  16770. + }
  16771. +
  16772. + /* Check permissions.
  16773. + */
  16774. + if (resource->pid && (resource->pid != current->tgid)) {
  16775. + pr_err("[%s]: current tgid %u != %u owner\n",
  16776. + __func__, current->tgid, resource->pid);
  16777. + ret = -EPERM;
  16778. + goto error;
  16779. + }
  16780. +
  16781. + unlock.res_handle = resource->res_handle;
  16782. + unlock.res_mem = resource->res_base_mem;
  16783. +
  16784. + pr_debug("[%s]: attempt to unlock data - guid %x, hdl %x, base address %p\n",
  16785. + __func__, ioparam->handle, unlock.res_handle, unlock.res_mem);
  16786. +
  16787. + /* User space allocated resources.
  16788. + */
  16789. + if (resource->pid) {
  16790. + /* Flush if requested */
  16791. + if (resource->res_cached && flush) {
  16792. + dma_addr_t phys_addr = 0;
  16793. + resource->res_stats[FLUSH]++;
  16794. +
  16795. + phys_addr =
  16796. + (dma_addr_t)((uint32_t)resource->res_base_mem &
  16797. + 0x3FFFFFFF);
  16798. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  16799. +
  16800. + /* L1 cache flush */
  16801. + down_read(&current->mm->mmap_sem);
  16802. + list_for_each_entry(map, &resource->map_list,
  16803. + resource_map_list) {
  16804. + if (map->vma) {
  16805. + unsigned long start;
  16806. + unsigned long end;
  16807. + start = map->vma->vm_start;
  16808. + end = map->vma->vm_end;
  16809. +
  16810. + vcsm_vma_cache_clean_page_range(
  16811. + start, end);
  16812. + }
  16813. + }
  16814. + up_read(&current->mm->mmap_sem);
  16815. +
  16816. + /* L2 cache flush */
  16817. + outer_clean_range(phys_addr,
  16818. + phys_addr +
  16819. + (size_t) resource->res_size);
  16820. + }
  16821. +
  16822. + /* We need to zap all the vmas associated with this resource */
  16823. + if (resource->lock_count == 1) {
  16824. + down_read(&current->mm->mmap_sem);
  16825. + list_for_each_entry(map, &resource->map_list,
  16826. + resource_map_list) {
  16827. + if (map->vma) {
  16828. + zap_vma_ptes(map->vma,
  16829. + map->vma->vm_start,
  16830. + map->vma->vm_end -
  16831. + map->vma->vm_start);
  16832. + }
  16833. + }
  16834. + up_read(&current->mm->mmap_sem);
  16835. + }
  16836. + }
  16837. + /* Kernel allocated resources. */
  16838. + else {
  16839. + /* Global + Taken in this context */
  16840. + if (resource->ref_count == 2) {
  16841. + if (!list_empty(&resource->map_list)) {
  16842. + list_for_each_entry_safe(map, map_tmp,
  16843. + &resource->map_list,
  16844. + resource_map_list) {
  16845. + if (map->res_addr) {
  16846. + if (flush &&
  16847. + (resource->res_cached ==
  16848. + VMCS_SM_CACHE_HOST)) {
  16849. + long unsigned int
  16850. + phys_addr;
  16851. + phys_addr = (uint32_t)
  16852. + resource->res_base_mem & 0x3FFFFFFF;
  16853. + phys_addr +=
  16854. + mm_vc_mem_phys_addr;
  16855. +
  16856. + /* L1 cache flush */
  16857. + dmac_flush_range((const
  16858. + void
  16859. + *)
  16860. + map->res_addr, (const void *)
  16861. + (map->res_addr + resource->res_size));
  16862. +
  16863. + /* L2 cache flush */
  16864. + outer_clean_range
  16865. + (phys_addr,
  16866. + phys_addr +
  16867. + (size_t)
  16868. + resource->res_size);
  16869. + }
  16870. +
  16871. + iounmap((void *)map->res_addr);
  16872. + map->res_addr = 0;
  16873. +
  16874. + vmcs_sm_remove_map(sm_state,
  16875. + map->resource,
  16876. + map);
  16877. + break;
  16878. + }
  16879. + }
  16880. + }
  16881. + }
  16882. + }
  16883. +
  16884. + if (resource->lock_count) {
  16885. + /* Bypass the videocore unlock.
  16886. + */
  16887. + if (no_vc_unlock)
  16888. + status = 0;
  16889. + /* Unlock the videocore allocated resource.
  16890. + */
  16891. + else {
  16892. + status =
  16893. + vc_vchi_sm_unlock(sm_state->sm_handle, &unlock,
  16894. + &private->int_trans_id,
  16895. + wait_reply);
  16896. + if (status == -EINTR) {
  16897. + pr_debug("[%s]: requesting unlock memory action restart (trans_id: %u)\n",
  16898. + __func__, private->int_trans_id);
  16899. +
  16900. + ret = -ERESTARTSYS;
  16901. + resource->res_stats[UNLOCK]--;
  16902. + private->restart_sys = -EINTR;
  16903. + private->int_action = VC_SM_MSG_TYPE_UNLOCK;
  16904. + goto error;
  16905. + } else if (status != 0) {
  16906. + pr_err("[%s]: failed to unlock vc mem (status: %u, trans_id: %u)\n",
  16907. + __func__, status, private->int_trans_id);
  16908. +
  16909. + ret = -EPERM;
  16910. + resource->res_stats[UNLOCK_FAIL]++;
  16911. + goto error;
  16912. + }
  16913. + }
  16914. +
  16915. + resource->res_stats[UNLOCK]++;
  16916. + resource->lock_count--;
  16917. + }
  16918. +
  16919. + pr_debug("[%s]: success to unlock data - hdl %x, base address %p, ref-cnt %d\n",
  16920. + __func__, unlock.res_handle, unlock.res_mem,
  16921. + resource->lock_count);
  16922. +
  16923. +error:
  16924. + if (resource)
  16925. + vmcs_sm_release_resource(resource, 0);
  16926. +
  16927. + return ret;
  16928. +}
  16929. +
  16930. +/* Handle control from host. */
  16931. +static long vc_sm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  16932. +{
  16933. + int ret = 0;
  16934. + unsigned int cmdnr = _IOC_NR(cmd);
  16935. + struct SM_PRIV_DATA_T *file_data =
  16936. + (struct SM_PRIV_DATA_T *)file->private_data;
  16937. + struct SM_RESOURCE_T *resource = NULL;
  16938. +
  16939. + /* Validate we can work with this device. */
  16940. + if ((sm_state == NULL) || (file_data == NULL)) {
  16941. + pr_err("[%s]: invalid device\n", __func__);
  16942. + ret = -EPERM;
  16943. + goto out;
  16944. + }
  16945. +
  16946. + pr_debug("[%s]: cmd %x tgid %u, owner %u\n", __func__, cmdnr,
  16947. + current->tgid, file_data->pid);
  16948. +
  16949. + /* Action is a re-post of a previously interrupted action? */
  16950. + if (file_data->restart_sys == -EINTR) {
  16951. + VC_SM_ACTION_CLEAN_T action_clean;
  16952. +
  16953. + pr_debug("[%s]: clean up of action %u (trans_id: %u) following EINTR\n",
  16954. + __func__, file_data->int_action,
  16955. + file_data->int_trans_id);
  16956. +
  16957. + action_clean.res_action = file_data->int_action;
  16958. + action_clean.action_trans_id = file_data->int_trans_id;
  16959. +
  16960. + vc_vchi_sm_clean_up(sm_state->sm_handle, &action_clean);
  16961. +
  16962. + file_data->restart_sys = 0;
  16963. + }
  16964. +
  16965. + /* Now process the command.
  16966. + */
  16967. + switch (cmdnr) {
  16968. + /* New memory allocation.
  16969. + */
  16970. + case VMCS_SM_CMD_ALLOC:
  16971. + {
  16972. + struct vmcs_sm_ioctl_alloc ioparam;
  16973. +
  16974. + /* Get the parameter data.
  16975. + */
  16976. + if (copy_from_user
  16977. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  16978. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  16979. + __func__, cmdnr);
  16980. + ret = -EFAULT;
  16981. + goto out;
  16982. + }
  16983. +
  16984. + ret = vc_sm_ioctl_alloc(file_data, &ioparam);
  16985. + if (!ret &&
  16986. + (copy_to_user((void *)arg,
  16987. + &ioparam, sizeof(ioparam)) != 0)) {
  16988. + struct vmcs_sm_ioctl_free freeparam = {
  16989. + ioparam.handle
  16990. + };
  16991. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  16992. + __func__, cmdnr);
  16993. + vc_sm_ioctl_free(file_data, &freeparam);
  16994. + ret = -EFAULT;
  16995. + }
  16996. +
  16997. + /* Done.
  16998. + */
  16999. + goto out;
  17000. + }
  17001. + break;
  17002. +
  17003. + /* Share existing memory allocation.
  17004. + */
  17005. + case VMCS_SM_CMD_ALLOC_SHARE:
  17006. + {
  17007. + struct vmcs_sm_ioctl_alloc_share ioparam;
  17008. +
  17009. + /* Get the parameter data.
  17010. + */
  17011. + if (copy_from_user
  17012. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17013. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17014. + __func__, cmdnr);
  17015. + ret = -EFAULT;
  17016. + goto out;
  17017. + }
  17018. +
  17019. + ret = vc_sm_ioctl_alloc_share(file_data, &ioparam);
  17020. +
  17021. + /* Copy result back to user.
  17022. + */
  17023. + if (!ret
  17024. + && copy_to_user((void *)arg, &ioparam,
  17025. + sizeof(ioparam)) != 0) {
  17026. + struct vmcs_sm_ioctl_free freeparam = {
  17027. + ioparam.handle
  17028. + };
  17029. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17030. + __func__, cmdnr);
  17031. + vc_sm_ioctl_free(file_data, &freeparam);
  17032. + ret = -EFAULT;
  17033. + }
  17034. +
  17035. + /* Done.
  17036. + */
  17037. + goto out;
  17038. + }
  17039. + break;
  17040. +
  17041. + /* Lock (attempt to) *and* register a cache behavior change.
  17042. + */
  17043. + case VMCS_SM_CMD_LOCK_CACHE:
  17044. + {
  17045. + struct vmcs_sm_ioctl_lock_cache ioparam;
  17046. + struct vmcs_sm_ioctl_lock_unlock lock;
  17047. +
  17048. + /* Get parameter data.
  17049. + */
  17050. + if (copy_from_user
  17051. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17052. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17053. + __func__, cmdnr);
  17054. + ret = -EFAULT;
  17055. + goto out;
  17056. + }
  17057. +
  17058. + lock.handle = ioparam.handle;
  17059. + ret =
  17060. + vc_sm_ioctl_lock(file_data, &lock, 1,
  17061. + ioparam.cached, 0);
  17062. +
  17063. + /* Done.
  17064. + */
  17065. + goto out;
  17066. + }
  17067. + break;
  17068. +
  17069. + /* Lock (attempt to) existing memory allocation.
  17070. + */
  17071. + case VMCS_SM_CMD_LOCK:
  17072. + {
  17073. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  17074. +
  17075. + /* Get parameter data.
  17076. + */
  17077. + if (copy_from_user
  17078. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17079. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17080. + __func__, cmdnr);
  17081. + ret = -EFAULT;
  17082. + goto out;
  17083. + }
  17084. +
  17085. + ret = vc_sm_ioctl_lock(file_data, &ioparam, 0, 0, 0);
  17086. +
  17087. + /* Copy result back to user.
  17088. + */
  17089. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  17090. + != 0) {
  17091. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17092. + __func__, cmdnr);
  17093. + ret = -EFAULT;
  17094. + }
  17095. +
  17096. + /* Done.
  17097. + */
  17098. + goto out;
  17099. + }
  17100. + break;
  17101. +
  17102. + /* Unlock (attempt to) existing memory allocation.
  17103. + */
  17104. + case VMCS_SM_CMD_UNLOCK:
  17105. + {
  17106. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  17107. +
  17108. + /* Get parameter data.
  17109. + */
  17110. + if (copy_from_user
  17111. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17112. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17113. + __func__, cmdnr);
  17114. + ret = -EFAULT;
  17115. + goto out;
  17116. + }
  17117. +
  17118. + ret = vc_sm_ioctl_unlock(file_data, &ioparam, 0, 1, 0);
  17119. +
  17120. + /* Done.
  17121. + */
  17122. + goto out;
  17123. + }
  17124. + break;
  17125. +
  17126. + /* Resize (attempt to) existing memory allocation.
  17127. + */
  17128. + case VMCS_SM_CMD_RESIZE:
  17129. + {
  17130. + struct vmcs_sm_ioctl_resize ioparam;
  17131. +
  17132. + /* Get parameter data.
  17133. + */
  17134. + if (copy_from_user
  17135. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17136. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17137. + __func__, cmdnr);
  17138. + ret = -EFAULT;
  17139. + goto out;
  17140. + }
  17141. +
  17142. + ret = vc_sm_ioctl_resize(file_data, &ioparam);
  17143. +
  17144. + /* Copy result back to user.
  17145. + */
  17146. + if (copy_to_user((void *)arg, &ioparam, sizeof(ioparam))
  17147. + != 0) {
  17148. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17149. + __func__, cmdnr);
  17150. + ret = -EFAULT;
  17151. + }
  17152. +
  17153. + /* Done.
  17154. + */
  17155. + goto out;
  17156. + }
  17157. + break;
  17158. +
  17159. + /* Terminate existing memory allocation.
  17160. + */
  17161. + case VMCS_SM_CMD_FREE:
  17162. + {
  17163. + struct vmcs_sm_ioctl_free ioparam;
  17164. +
  17165. + /* Get parameter data.
  17166. + */
  17167. + if (copy_from_user
  17168. + (&ioparam, (void *)arg, sizeof(ioparam)) != 0) {
  17169. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17170. + __func__, cmdnr);
  17171. + ret = -EFAULT;
  17172. + goto out;
  17173. + }
  17174. +
  17175. + ret = vc_sm_ioctl_free(file_data, &ioparam);
  17176. +
  17177. + /* Done.
  17178. + */
  17179. + goto out;
  17180. + }
  17181. + break;
  17182. +
  17183. + /* Walk allocation on videocore, information shows up in the
  17184. + ** videocore log.
  17185. + */
  17186. + case VMCS_SM_CMD_VC_WALK_ALLOC:
  17187. + {
  17188. + pr_debug("[%s]: invoking walk alloc\n", __func__);
  17189. +
  17190. + if (vc_vchi_sm_walk_alloc(sm_state->sm_handle) != 0)
  17191. + pr_err("[%s]: failed to walk-alloc on videocore\n",
  17192. + __func__);
  17193. +
  17194. + /* Done.
  17195. + */
  17196. + goto out;
  17197. + }
  17198. + break;
  17199. +/* Walk mapping table on host, information shows up in the
  17200. + ** kernel log.
  17201. + */
  17202. + case VMCS_SM_CMD_HOST_WALK_MAP:
  17203. + {
  17204. + /* Use pid of -1 to tell to walk the whole map. */
  17205. + vmcs_sm_host_walk_map_per_pid(-1);
  17206. +
  17207. + /* Done. */
  17208. + goto out;
  17209. + }
  17210. + break;
  17211. +
  17212. + /* Walk mapping table per process on host. */
  17213. + case VMCS_SM_CMD_HOST_WALK_PID_ALLOC:
  17214. + {
  17215. + struct vmcs_sm_ioctl_walk ioparam;
  17216. +
  17217. + /* Get parameter data. */
  17218. + if (copy_from_user(&ioparam,
  17219. + (void *)arg, sizeof(ioparam)) != 0) {
  17220. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17221. + __func__, cmdnr);
  17222. + ret = -EFAULT;
  17223. + goto out;
  17224. + }
  17225. +
  17226. + vmcs_sm_host_walk_alloc(file_data);
  17227. +
  17228. + /* Done. */
  17229. + goto out;
  17230. + }
  17231. + break;
  17232. +
  17233. + /* Walk allocation per process on host. */
  17234. + case VMCS_SM_CMD_HOST_WALK_PID_MAP:
  17235. + {
  17236. + struct vmcs_sm_ioctl_walk ioparam;
  17237. +
  17238. + /* Get parameter data. */
  17239. + if (copy_from_user(&ioparam,
  17240. + (void *)arg, sizeof(ioparam)) != 0) {
  17241. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17242. + __func__, cmdnr);
  17243. + ret = -EFAULT;
  17244. + goto out;
  17245. + }
  17246. +
  17247. + vmcs_sm_host_walk_map_per_pid(ioparam.pid);
  17248. +
  17249. + /* Done. */
  17250. + goto out;
  17251. + }
  17252. + break;
  17253. +
  17254. + /* Gets the size of the memory associated with a user handle. */
  17255. + case VMCS_SM_CMD_SIZE_USR_HANDLE:
  17256. + {
  17257. + struct vmcs_sm_ioctl_size ioparam;
  17258. +
  17259. + /* Get parameter data. */
  17260. + if (copy_from_user(&ioparam,
  17261. + (void *)arg, sizeof(ioparam)) != 0) {
  17262. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17263. + __func__, cmdnr);
  17264. + ret = -EFAULT;
  17265. + goto out;
  17266. + }
  17267. +
  17268. + /* Locate resource from GUID. */
  17269. + resource =
  17270. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17271. + if (resource != NULL) {
  17272. + ioparam.size = resource->res_size;
  17273. + vmcs_sm_release_resource(resource, 0);
  17274. + } else {
  17275. + ioparam.size = 0;
  17276. + }
  17277. +
  17278. + if (copy_to_user((void *)arg,
  17279. + &ioparam, sizeof(ioparam)) != 0) {
  17280. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17281. + __func__, cmdnr);
  17282. + ret = -EFAULT;
  17283. + }
  17284. +
  17285. + /* Done. */
  17286. + goto out;
  17287. + }
  17288. + break;
  17289. +
  17290. + /* Verify we are dealing with a valid resource. */
  17291. + case VMCS_SM_CMD_CHK_USR_HANDLE:
  17292. + {
  17293. + struct vmcs_sm_ioctl_chk ioparam;
  17294. +
  17295. + /* Get parameter data.
  17296. + */
  17297. + if (copy_from_user(&ioparam,
  17298. + (void *)arg, sizeof(ioparam)) != 0) {
  17299. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17300. + __func__, cmdnr);
  17301. +
  17302. + ret = -EFAULT;
  17303. + goto out;
  17304. + }
  17305. +
  17306. + /* Locate resource from GUID. */
  17307. + resource =
  17308. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17309. + if (resource == NULL)
  17310. + ret = -EINVAL;
  17311. + /* If the resource is cacheable, return additional
  17312. + * information that may be needed to flush the cache.
  17313. + */
  17314. + else if ((resource->res_cached == VMCS_SM_CACHE_HOST) ||
  17315. + (resource->res_cached == VMCS_SM_CACHE_BOTH)) {
  17316. + ioparam.addr =
  17317. + vmcs_sm_usr_address_from_pid_and_usr_handle
  17318. + (current->tgid, ioparam.handle);
  17319. + ioparam.size = resource->res_size;
  17320. + ioparam.cache = resource->res_cached;
  17321. + } else {
  17322. + ioparam.addr = 0;
  17323. + ioparam.size = 0;
  17324. + ioparam.cache = resource->res_cached;
  17325. + }
  17326. +
  17327. + if (resource)
  17328. + vmcs_sm_release_resource(resource, 0);
  17329. +
  17330. + if (copy_to_user((void *)arg,
  17331. + &ioparam, sizeof(ioparam)) != 0) {
  17332. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17333. + __func__, cmdnr);
  17334. + ret = -EFAULT;
  17335. + }
  17336. +
  17337. + /* Done.
  17338. + */
  17339. + goto out;
  17340. + }
  17341. + break;
  17342. +
  17343. + /*
  17344. + * Maps a user handle given the process and the virtual address.
  17345. + */
  17346. + case VMCS_SM_CMD_MAPPED_USR_HANDLE:
  17347. + {
  17348. + struct vmcs_sm_ioctl_map ioparam;
  17349. +
  17350. + /* Get parameter data. */
  17351. + if (copy_from_user(&ioparam,
  17352. + (void *)arg, sizeof(ioparam)) != 0) {
  17353. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17354. + __func__, cmdnr);
  17355. +
  17356. + ret = -EFAULT;
  17357. + goto out;
  17358. + }
  17359. +
  17360. + ioparam.handle =
  17361. + vmcs_sm_usr_handle_from_pid_and_address(
  17362. + ioparam.pid, ioparam.addr);
  17363. +
  17364. + resource =
  17365. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17366. + if ((resource != NULL)
  17367. + && ((resource->res_cached == VMCS_SM_CACHE_HOST)
  17368. + || (resource->res_cached ==
  17369. + VMCS_SM_CACHE_BOTH))) {
  17370. + ioparam.size = resource->res_size;
  17371. + } else {
  17372. + ioparam.size = 0;
  17373. + }
  17374. +
  17375. + if (resource)
  17376. + vmcs_sm_release_resource(resource, 0);
  17377. +
  17378. + if (copy_to_user((void *)arg,
  17379. + &ioparam, sizeof(ioparam)) != 0) {
  17380. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17381. + __func__, cmdnr);
  17382. + ret = -EFAULT;
  17383. + }
  17384. +
  17385. + /* Done. */
  17386. + goto out;
  17387. + }
  17388. + break;
  17389. +
  17390. + /*
  17391. + * Maps a videocore handle given process and virtual address.
  17392. + */
  17393. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR:
  17394. + {
  17395. + struct vmcs_sm_ioctl_map ioparam;
  17396. +
  17397. + /* Get parameter data. */
  17398. + if (copy_from_user(&ioparam,
  17399. + (void *)arg, sizeof(ioparam)) != 0) {
  17400. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17401. + __func__, cmdnr);
  17402. + ret = -EFAULT;
  17403. + goto out;
  17404. + }
  17405. +
  17406. + ioparam.handle = vmcs_sm_vc_handle_from_pid_and_address(
  17407. + ioparam.pid, ioparam.addr);
  17408. +
  17409. + if (copy_to_user((void *)arg,
  17410. + &ioparam, sizeof(ioparam)) != 0) {
  17411. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17412. + __func__, cmdnr);
  17413. +
  17414. + ret = -EFAULT;
  17415. + }
  17416. +
  17417. + /* Done.
  17418. + */
  17419. + goto out;
  17420. + }
  17421. + break;
  17422. +
  17423. + /* Maps a videocore handle given process and user handle. */
  17424. + case VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL:
  17425. + {
  17426. + struct vmcs_sm_ioctl_map ioparam;
  17427. +
  17428. + /* Get parameter data. */
  17429. + if (copy_from_user(&ioparam,
  17430. + (void *)arg, sizeof(ioparam)) != 0) {
  17431. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17432. + __func__, cmdnr);
  17433. + ret = -EFAULT;
  17434. + goto out;
  17435. + }
  17436. +
  17437. + /* Locate resource from GUID. */
  17438. + resource =
  17439. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17440. + if (resource != NULL) {
  17441. + ioparam.handle = resource->res_handle;
  17442. + vmcs_sm_release_resource(resource, 0);
  17443. + } else {
  17444. + ioparam.handle = 0;
  17445. + }
  17446. +
  17447. + if (copy_to_user((void *)arg,
  17448. + &ioparam, sizeof(ioparam)) != 0) {
  17449. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17450. + __func__, cmdnr);
  17451. +
  17452. + ret = -EFAULT;
  17453. + }
  17454. +
  17455. + /* Done. */
  17456. + goto out;
  17457. + }
  17458. + break;
  17459. +
  17460. + /*
  17461. + * Maps a videocore address given process and videocore handle.
  17462. + */
  17463. + case VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL:
  17464. + {
  17465. + struct vmcs_sm_ioctl_map ioparam;
  17466. +
  17467. + /* Get parameter data. */
  17468. + if (copy_from_user(&ioparam,
  17469. + (void *)arg, sizeof(ioparam)) != 0) {
  17470. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17471. + __func__, cmdnr);
  17472. +
  17473. + ret = -EFAULT;
  17474. + goto out;
  17475. + }
  17476. +
  17477. + /* Locate resource from GUID. */
  17478. + resource =
  17479. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17480. + if (resource != NULL) {
  17481. + ioparam.addr =
  17482. + (unsigned int)resource->res_base_mem;
  17483. + vmcs_sm_release_resource(resource, 0);
  17484. + } else {
  17485. + ioparam.addr = 0;
  17486. + }
  17487. +
  17488. + if (copy_to_user((void *)arg,
  17489. + &ioparam, sizeof(ioparam)) != 0) {
  17490. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17491. + __func__, cmdnr);
  17492. + ret = -EFAULT;
  17493. + }
  17494. +
  17495. + /* Done. */
  17496. + goto out;
  17497. + }
  17498. + break;
  17499. +
  17500. + /* Maps a user address given process and vc handle.
  17501. + */
  17502. + case VMCS_SM_CMD_MAPPED_USR_ADDRESS:
  17503. + {
  17504. + struct vmcs_sm_ioctl_map ioparam;
  17505. +
  17506. + /* Get parameter data. */
  17507. + if (copy_from_user(&ioparam,
  17508. + (void *)arg, sizeof(ioparam)) != 0) {
  17509. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17510. + __func__, cmdnr);
  17511. + ret = -EFAULT;
  17512. + goto out;
  17513. + }
  17514. +
  17515. + /*
  17516. + * Return the address information from the mapping,
  17517. + * 0 (ie NULL) if it cannot locate the actual mapping.
  17518. + */
  17519. + ioparam.addr =
  17520. + vmcs_sm_usr_address_from_pid_and_usr_handle
  17521. + (ioparam.pid, ioparam.handle);
  17522. +
  17523. + if (copy_to_user((void *)arg,
  17524. + &ioparam, sizeof(ioparam)) != 0) {
  17525. + pr_err("[%s]: failed to copy-to-user for cmd %x\n",
  17526. + __func__, cmdnr);
  17527. + ret = -EFAULT;
  17528. + }
  17529. +
  17530. + /* Done. */
  17531. + goto out;
  17532. + }
  17533. + break;
  17534. +
  17535. + /* Flush the cache for a given mapping. */
  17536. + case VMCS_SM_CMD_FLUSH:
  17537. + {
  17538. + struct vmcs_sm_ioctl_cache ioparam;
  17539. +
  17540. + /* Get parameter data. */
  17541. + if (copy_from_user(&ioparam,
  17542. + (void *)arg, sizeof(ioparam)) != 0) {
  17543. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17544. + __func__, cmdnr);
  17545. + ret = -EFAULT;
  17546. + goto out;
  17547. + }
  17548. +
  17549. + /* Locate resource from GUID. */
  17550. + resource =
  17551. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17552. +
  17553. + if ((resource != NULL) && resource->res_cached) {
  17554. + dma_addr_t phys_addr = 0;
  17555. +
  17556. + resource->res_stats[FLUSH]++;
  17557. +
  17558. + phys_addr =
  17559. + (dma_addr_t)((uint32_t)
  17560. + resource->res_base_mem &
  17561. + 0x3FFFFFFF);
  17562. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  17563. +
  17564. + /* L1 cache flush */
  17565. + down_read(&current->mm->mmap_sem);
  17566. + vcsm_vma_cache_clean_page_range((unsigned long)
  17567. + ioparam.addr,
  17568. + (unsigned long)
  17569. + ioparam.addr +
  17570. + ioparam.size);
  17571. + up_read(&current->mm->mmap_sem);
  17572. +
  17573. + /* L2 cache flush */
  17574. + outer_clean_range(phys_addr,
  17575. + phys_addr +
  17576. + (size_t) ioparam.size);
  17577. + } else if (resource == NULL) {
  17578. + ret = -EINVAL;
  17579. + goto out;
  17580. + }
  17581. +
  17582. + if (resource)
  17583. + vmcs_sm_release_resource(resource, 0);
  17584. +
  17585. + /* Done. */
  17586. + goto out;
  17587. + }
  17588. + break;
  17589. +
  17590. + /* Invalidate the cache for a given mapping. */
  17591. + case VMCS_SM_CMD_INVALID:
  17592. + {
  17593. + struct vmcs_sm_ioctl_cache ioparam;
  17594. +
  17595. + /* Get parameter data. */
  17596. + if (copy_from_user(&ioparam,
  17597. + (void *)arg, sizeof(ioparam)) != 0) {
  17598. + pr_err("[%s]: failed to copy-from-user for cmd %x\n",
  17599. + __func__, cmdnr);
  17600. + ret = -EFAULT;
  17601. + goto out;
  17602. + }
  17603. +
  17604. + /* Locate resource from GUID.
  17605. + */
  17606. + resource =
  17607. + vmcs_sm_acquire_resource(file_data, ioparam.handle);
  17608. +
  17609. + if ((resource != NULL) && resource->res_cached) {
  17610. + dma_addr_t phys_addr = 0;
  17611. +
  17612. + resource->res_stats[INVALID]++;
  17613. +
  17614. + phys_addr =
  17615. + (dma_addr_t)((uint32_t)
  17616. + resource->res_base_mem &
  17617. + 0x3FFFFFFF);
  17618. + phys_addr += (dma_addr_t)mm_vc_mem_phys_addr;
  17619. +
  17620. + /* L2 cache invalidate */
  17621. + outer_inv_range(phys_addr,
  17622. + phys_addr +
  17623. + (size_t) ioparam.size);
  17624. +
  17625. + /* L1 cache invalidate */
  17626. + down_read(&current->mm->mmap_sem);
  17627. + vcsm_vma_cache_clean_page_range((unsigned long)
  17628. + ioparam.addr,
  17629. + (unsigned long)
  17630. + ioparam.addr +
  17631. + ioparam.size);
  17632. + up_read(&current->mm->mmap_sem);
  17633. + } else if (resource == NULL) {
  17634. + ret = -EINVAL;
  17635. + goto out;
  17636. + }
  17637. +
  17638. + if (resource)
  17639. + vmcs_sm_release_resource(resource, 0);
  17640. +
  17641. + /* Done.
  17642. + */
  17643. + goto out;
  17644. + }
  17645. + break;
  17646. +
  17647. + default:
  17648. + {
  17649. + ret = -EINVAL;
  17650. + goto out;
  17651. + }
  17652. + break;
  17653. + }
  17654. +
  17655. +out:
  17656. + return ret;
  17657. +}
  17658. +
  17659. +/* Device operations that we managed in this driver.
  17660. +*/
  17661. +static const struct file_operations vmcs_sm_ops = {
  17662. + .owner = THIS_MODULE,
  17663. + .unlocked_ioctl = vc_sm_ioctl,
  17664. + .open = vc_sm_open,
  17665. + .release = vc_sm_release,
  17666. + .mmap = vc_sm_mmap,
  17667. +};
  17668. +
  17669. +/* Creation of device.
  17670. +*/
  17671. +static int vc_sm_create_sharedmemory(void)
  17672. +{
  17673. + int ret;
  17674. +
  17675. + if (sm_state == NULL) {
  17676. + ret = -ENOMEM;
  17677. + goto out;
  17678. + }
  17679. +
  17680. + /* Create a device class for creating dev nodes.
  17681. + */
  17682. + sm_state->sm_class = class_create(THIS_MODULE, "vc-sm");
  17683. + if (IS_ERR(sm_state->sm_class)) {
  17684. + pr_err("[%s]: unable to create device class\n", __func__);
  17685. + ret = PTR_ERR(sm_state->sm_class);
  17686. + goto out;
  17687. + }
  17688. +
  17689. + /* Create a character driver.
  17690. + */
  17691. + ret = alloc_chrdev_region(&sm_state->sm_devid,
  17692. + DEVICE_MINOR, 1, DEVICE_NAME);
  17693. + if (ret != 0) {
  17694. + pr_err("[%s]: unable to allocate device number\n", __func__);
  17695. + goto out_dev_class_destroy;
  17696. + }
  17697. +
  17698. + cdev_init(&sm_state->sm_cdev, &vmcs_sm_ops);
  17699. + ret = cdev_add(&sm_state->sm_cdev, sm_state->sm_devid, 1);
  17700. + if (ret != 0) {
  17701. + pr_err("[%s]: unable to register device\n", __func__);
  17702. + goto out_chrdev_unreg;
  17703. + }
  17704. +
  17705. + /* Create a device node.
  17706. + */
  17707. + sm_state->sm_dev = device_create(sm_state->sm_class,
  17708. + NULL,
  17709. + MKDEV(MAJOR(sm_state->sm_devid),
  17710. + DEVICE_MINOR), NULL,
  17711. + DEVICE_NAME);
  17712. + if (IS_ERR(sm_state->sm_dev)) {
  17713. + pr_err("[%s]: unable to create device node\n", __func__);
  17714. + ret = PTR_ERR(sm_state->sm_dev);
  17715. + goto out_chrdev_del;
  17716. + }
  17717. +
  17718. + goto out;
  17719. +
  17720. +out_chrdev_del:
  17721. + cdev_del(&sm_state->sm_cdev);
  17722. +out_chrdev_unreg:
  17723. + unregister_chrdev_region(sm_state->sm_devid, 1);
  17724. +out_dev_class_destroy:
  17725. + class_destroy(sm_state->sm_class);
  17726. + sm_state->sm_class = NULL;
  17727. +out:
  17728. + return ret;
  17729. +}
  17730. +
  17731. +/* Termination of the device.
  17732. +*/
  17733. +static int vc_sm_remove_sharedmemory(void)
  17734. +{
  17735. + int ret;
  17736. +
  17737. + if (sm_state == NULL) {
  17738. + /* Nothing to do.
  17739. + */
  17740. + ret = 0;
  17741. + goto out;
  17742. + }
  17743. +
  17744. + /* Remove the sharedmemory character driver.
  17745. + */
  17746. + cdev_del(&sm_state->sm_cdev);
  17747. +
  17748. + /* Unregister region.
  17749. + */
  17750. + unregister_chrdev_region(sm_state->sm_devid, 1);
  17751. +
  17752. + ret = 0;
  17753. + goto out;
  17754. +
  17755. +out:
  17756. + return ret;
  17757. +}
  17758. +
  17759. +/* Videocore connected. */
  17760. +static void vc_sm_connected_init(void)
  17761. +{
  17762. + int ret;
  17763. + VCHI_INSTANCE_T vchi_instance;
  17764. + VCHI_CONNECTION_T *vchi_connection = NULL;
  17765. +
  17766. + pr_info("[%s]: start\n", __func__);
  17767. +
  17768. + /* Allocate memory for the state structure.
  17769. + */
  17770. + sm_state = kzalloc(sizeof(struct SM_STATE_T), GFP_KERNEL);
  17771. + if (sm_state == NULL) {
  17772. + pr_err("[%s]: failed to allocate memory\n", __func__);
  17773. + ret = -ENOMEM;
  17774. + goto out;
  17775. + }
  17776. +
  17777. + mutex_init(&sm_state->lock);
  17778. + mutex_init(&sm_state->map_lock);
  17779. +
  17780. + /* Initialize and create a VCHI connection for the shared memory service
  17781. + ** running on videocore.
  17782. + */
  17783. + ret = vchi_initialise(&vchi_instance);
  17784. + if (ret != 0) {
  17785. + pr_err("[%s]: failed to initialise VCHI instance (ret=%d)\n",
  17786. + __func__, ret);
  17787. +
  17788. + ret = -EIO;
  17789. + goto err_free_mem;
  17790. + }
  17791. +
  17792. + ret = vchi_connect(NULL, 0, vchi_instance);
  17793. + if (ret != 0) {
  17794. + pr_err("[%s]: failed to connect VCHI instance (ret=%d)\n",
  17795. + __func__, ret);
  17796. +
  17797. + ret = -EIO;
  17798. + goto err_free_mem;
  17799. + }
  17800. +
  17801. + /* Initialize an instance of the shared memory service. */
  17802. + sm_state->sm_handle =
  17803. + vc_vchi_sm_init(vchi_instance, &vchi_connection, 1);
  17804. + if (sm_state->sm_handle == NULL) {
  17805. + pr_err("[%s]: failed to initialize shared memory service\n",
  17806. + __func__);
  17807. +
  17808. + ret = -EPERM;
  17809. + goto err_free_mem;
  17810. + }
  17811. +
  17812. + /* Create a debug fs directory entry (root). */
  17813. + sm_state->dir_root = debugfs_create_dir(VC_SM_DIR_ROOT_NAME, NULL);
  17814. + if (!sm_state->dir_root) {
  17815. + pr_err("[%s]: failed to create \'%s\' directory entry\n",
  17816. + __func__, VC_SM_DIR_ROOT_NAME);
  17817. +
  17818. + ret = -EPERM;
  17819. + goto err_stop_sm_service;
  17820. + }
  17821. +
  17822. + sm_state->dir_state.show = &vc_sm_global_state_show;
  17823. + sm_state->dir_state.dir_entry = debugfs_create_file(VC_SM_STATE,
  17824. + S_IRUGO, sm_state->dir_root, &sm_state->dir_state,
  17825. + &vc_sm_debug_fs_fops);
  17826. +
  17827. + sm_state->dir_stats.show = &vc_sm_global_statistics_show;
  17828. + sm_state->dir_stats.dir_entry = debugfs_create_file(VC_SM_STATS,
  17829. + S_IRUGO, sm_state->dir_root, &sm_state->dir_stats,
  17830. + &vc_sm_debug_fs_fops);
  17831. +
  17832. + /* Create the proc entry children. */
  17833. + sm_state->dir_alloc = debugfs_create_dir(VC_SM_DIR_ALLOC_NAME,
  17834. + sm_state->dir_root);
  17835. +
  17836. + /* Create a shared memory device. */
  17837. + ret = vc_sm_create_sharedmemory();
  17838. + if (ret != 0) {
  17839. + pr_err("[%s]: failed to create shared memory device\n",
  17840. + __func__);
  17841. + goto err_remove_debugfs;
  17842. + }
  17843. +
  17844. + INIT_LIST_HEAD(&sm_state->map_list);
  17845. + INIT_LIST_HEAD(&sm_state->resource_list);
  17846. +
  17847. + sm_state->data_knl = vc_sm_create_priv_data(0);
  17848. + if (sm_state->data_knl == NULL) {
  17849. + pr_err("[%s]: failed to create kernel private data tracker\n",
  17850. + __func__);
  17851. + goto err_remove_shared_memory;
  17852. + }
  17853. +
  17854. + /* Done!
  17855. + */
  17856. + sm_inited = 1;
  17857. + goto out;
  17858. +
  17859. +err_remove_shared_memory:
  17860. + vc_sm_remove_sharedmemory();
  17861. +err_remove_debugfs:
  17862. + debugfs_remove_recursive(sm_state->dir_root);
  17863. +err_stop_sm_service:
  17864. + vc_vchi_sm_stop(&sm_state->sm_handle);
  17865. +err_free_mem:
  17866. + kfree(sm_state);
  17867. +out:
  17868. + pr_info("[%s]: end - returning %d\n", __func__, ret);
  17869. +}
  17870. +
  17871. +/* Driver loading. */
  17872. +static int __init vc_sm_init(void)
  17873. +{
  17874. + pr_info("vc-sm: Videocore shared memory driver\n");
  17875. + vchiq_add_connected_callback(vc_sm_connected_init);
  17876. + return 0;
  17877. +}
  17878. +
  17879. +/* Driver unloading. */
  17880. +static void __exit vc_sm_exit(void)
  17881. +{
  17882. + pr_debug("[%s]: start\n", __func__);
  17883. + if (sm_inited) {
  17884. + /* Remove shared memory device.
  17885. + */
  17886. + vc_sm_remove_sharedmemory();
  17887. +
  17888. + /* Remove all proc entries.
  17889. + */
  17890. + debugfs_remove_recursive(sm_state->dir_root);
  17891. +
  17892. + /* Stop the videocore shared memory service.
  17893. + */
  17894. + vc_vchi_sm_stop(&sm_state->sm_handle);
  17895. +
  17896. + /* Free the memory for the state structure.
  17897. + */
  17898. + mutex_destroy(&(sm_state->map_lock));
  17899. + kfree(sm_state);
  17900. + }
  17901. +
  17902. + pr_debug("[%s]: end\n", __func__);
  17903. +}
  17904. +
  17905. +#if defined(__KERNEL__)
  17906. +/* Allocate a shared memory handle and block. */
  17907. +int vc_sm_alloc(VC_SM_ALLOC_T *alloc, int *handle)
  17908. +{
  17909. + struct vmcs_sm_ioctl_alloc ioparam = { 0 };
  17910. + int ret;
  17911. + struct SM_RESOURCE_T *resource;
  17912. +
  17913. + /* Validate we can work with this device.
  17914. + */
  17915. + if (sm_state == NULL || alloc == NULL || handle == NULL) {
  17916. + pr_err("[%s]: invalid input\n", __func__);
  17917. + return -EPERM;
  17918. + }
  17919. +
  17920. + ioparam.size = alloc->base_unit;
  17921. + ioparam.num = alloc->num_unit;
  17922. + ioparam.cached =
  17923. + alloc->type == VC_SM_ALLOC_CACHED ? VMCS_SM_CACHE_VC : 0;
  17924. +
  17925. + ret = vc_sm_ioctl_alloc(sm_state->data_knl, &ioparam);
  17926. +
  17927. + if (ret == 0) {
  17928. + resource =
  17929. + vmcs_sm_acquire_resource(sm_state->data_knl,
  17930. + ioparam.handle);
  17931. + if (resource) {
  17932. + resource->pid = 0;
  17933. + vmcs_sm_release_resource(resource, 0);
  17934. +
  17935. + /* Assign valid handle at this time.
  17936. + */
  17937. + *handle = ioparam.handle;
  17938. + } else {
  17939. + ret = -ENOMEM;
  17940. + }
  17941. + }
  17942. +
  17943. + return ret;
  17944. +}
  17945. +EXPORT_SYMBOL_GPL(vc_sm_alloc);
  17946. +
  17947. +/* Get an internal resource handle mapped from the external one.
  17948. +*/
  17949. +int vc_sm_int_handle(int handle)
  17950. +{
  17951. + struct SM_RESOURCE_T *resource;
  17952. + int ret = 0;
  17953. +
  17954. + /* Validate we can work with this device.
  17955. + */
  17956. + if (sm_state == NULL || handle == 0) {
  17957. + pr_err("[%s]: invalid input\n", __func__);
  17958. + return 0;
  17959. + }
  17960. +
  17961. + /* Locate resource from GUID.
  17962. + */
  17963. + resource = vmcs_sm_acquire_resource(sm_state->data_knl, handle);
  17964. + if (resource) {
  17965. + ret = resource->res_handle;
  17966. + vmcs_sm_release_resource(resource, 0);
  17967. + }
  17968. +
  17969. + return ret;
  17970. +}
  17971. +EXPORT_SYMBOL_GPL(vc_sm_int_handle);
  17972. +
  17973. +/* Free a previously allocated shared memory handle and block.
  17974. +*/
  17975. +int vc_sm_free(int handle)
  17976. +{
  17977. + struct vmcs_sm_ioctl_free ioparam = { handle };
  17978. +
  17979. + /* Validate we can work with this device.
  17980. + */
  17981. + if (sm_state == NULL || handle == 0) {
  17982. + pr_err("[%s]: invalid input\n", __func__);
  17983. + return -EPERM;
  17984. + }
  17985. +
  17986. + return vc_sm_ioctl_free(sm_state->data_knl, &ioparam);
  17987. +}
  17988. +EXPORT_SYMBOL_GPL(vc_sm_free);
  17989. +
  17990. +/* Lock a memory handle for use by kernel.
  17991. +*/
  17992. +int vc_sm_lock(int handle, VC_SM_LOCK_CACHE_MODE_T mode,
  17993. + long unsigned int *data)
  17994. +{
  17995. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  17996. + int ret;
  17997. +
  17998. + /* Validate we can work with this device.
  17999. + */
  18000. + if (sm_state == NULL || handle == 0 || data == NULL) {
  18001. + pr_err("[%s]: invalid input\n", __func__);
  18002. + return -EPERM;
  18003. + }
  18004. +
  18005. + *data = 0;
  18006. +
  18007. + ioparam.handle = handle;
  18008. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  18009. + &ioparam,
  18010. + 1,
  18011. + ((mode ==
  18012. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  18013. + VMCS_SM_CACHE_NONE), 0);
  18014. +
  18015. + *data = ioparam.addr;
  18016. + return ret;
  18017. +}
  18018. +EXPORT_SYMBOL_GPL(vc_sm_lock);
  18019. +
  18020. +/* Unlock a memory handle in use by kernel.
  18021. +*/
  18022. +int vc_sm_unlock(int handle, int flush, int no_vc_unlock)
  18023. +{
  18024. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  18025. +
  18026. + /* Validate we can work with this device.
  18027. + */
  18028. + if (sm_state == NULL || handle == 0) {
  18029. + pr_err("[%s]: invalid input\n", __func__);
  18030. + return -EPERM;
  18031. + }
  18032. +
  18033. + ioparam.handle = handle;
  18034. + return vc_sm_ioctl_unlock(sm_state->data_knl,
  18035. + &ioparam, flush, 0, no_vc_unlock);
  18036. +}
  18037. +EXPORT_SYMBOL_GPL(vc_sm_unlock);
  18038. +
  18039. +/* Map a shared memory region for use by kernel.
  18040. +*/
  18041. +int vc_sm_map(int handle, unsigned int sm_addr, VC_SM_LOCK_CACHE_MODE_T mode,
  18042. + long unsigned int *data)
  18043. +{
  18044. + struct vmcs_sm_ioctl_lock_unlock ioparam;
  18045. + int ret;
  18046. +
  18047. + /* Validate we can work with this device.
  18048. + */
  18049. + if (sm_state == NULL || handle == 0 || data == NULL || sm_addr == 0) {
  18050. + pr_err("[%s]: invalid input\n", __func__);
  18051. + return -EPERM;
  18052. + }
  18053. +
  18054. + *data = 0;
  18055. +
  18056. + ioparam.handle = handle;
  18057. + ret = vc_sm_ioctl_lock(sm_state->data_knl,
  18058. + &ioparam,
  18059. + 1,
  18060. + ((mode ==
  18061. + VC_SM_LOCK_CACHED) ? VMCS_SM_CACHE_HOST :
  18062. + VMCS_SM_CACHE_NONE), sm_addr);
  18063. +
  18064. + *data = ioparam.addr;
  18065. + return ret;
  18066. +}
  18067. +EXPORT_SYMBOL_GPL(vc_sm_map);
  18068. +#endif
  18069. +
  18070. +late_initcall(vc_sm_init);
  18071. +module_exit(vc_sm_exit);
  18072. +
  18073. +MODULE_AUTHOR("Broadcom");
  18074. +MODULE_DESCRIPTION("VideoCore SharedMemory Driver");
  18075. +MODULE_LICENSE("GPL v2");
  18076. diff -Nur linux-3.12.38/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  18077. --- linux-3.12.38/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  18078. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2015-03-10 17:26:50.166216694 +0100
  18079. @@ -0,0 +1,117 @@
  18080. +/**
  18081. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18082. + *
  18083. + * Redistribution and use in source and binary forms, with or without
  18084. + * modification, are permitted provided that the following conditions
  18085. + * are met:
  18086. + * 1. Redistributions of source code must retain the above copyright
  18087. + * notice, this list of conditions, and the following disclaimer,
  18088. + * without modification.
  18089. + * 2. Redistributions in binary form must reproduce the above copyright
  18090. + * notice, this list of conditions and the following disclaimer in the
  18091. + * documentation and/or other materials provided with the distribution.
  18092. + * 3. The names of the above-listed copyright holders may not be used
  18093. + * to endorse or promote products derived from this software without
  18094. + * specific prior written permission.
  18095. + *
  18096. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18097. + * GNU General Public License ("GPL") version 2, as published by the Free
  18098. + * Software Foundation.
  18099. + *
  18100. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18101. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18102. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18103. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18104. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18105. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18106. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18107. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18108. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18109. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18110. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18111. + */
  18112. +
  18113. +#include <linux/kernel.h>
  18114. +#include <linux/module.h>
  18115. +#include <linux/init.h>
  18116. +#include <linux/hw_random.h>
  18117. +#include <linux/printk.h>
  18118. +
  18119. +#include <asm/io.h>
  18120. +#include <mach/hardware.h>
  18121. +#include <mach/platform.h>
  18122. +
  18123. +#define RNG_CTRL (0x0)
  18124. +#define RNG_STATUS (0x4)
  18125. +#define RNG_DATA (0x8)
  18126. +#define RNG_FF_THRESHOLD (0xc)
  18127. +
  18128. +/* enable rng */
  18129. +#define RNG_RBGEN 0x1
  18130. +/* double speed, less random mode */
  18131. +#define RNG_RBG2X 0x2
  18132. +
  18133. +/* the initial numbers generated are "less random" so will be discarded */
  18134. +#define RNG_WARMUP_COUNT 0x40000
  18135. +
  18136. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  18137. +{
  18138. + void __iomem *rng_base = (void __iomem *)rng->priv;
  18139. + unsigned words;
  18140. + /* wait for a random number to be in fifo */
  18141. + do {
  18142. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  18143. + }
  18144. + while (words == 0);
  18145. + /* read the random number */
  18146. + *buffer = __raw_readl(rng_base + RNG_DATA);
  18147. + return 4;
  18148. +}
  18149. +
  18150. +static struct hwrng bcm2708_rng_ops = {
  18151. + .name = "bcm2708",
  18152. + .data_read = bcm2708_rng_data_read,
  18153. +};
  18154. +
  18155. +static int __init bcm2708_rng_init(void)
  18156. +{
  18157. + void __iomem *rng_base;
  18158. + int err;
  18159. +
  18160. + /* map peripheral */
  18161. + rng_base = ioremap(RNG_BASE, 0x10);
  18162. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  18163. + if (!rng_base) {
  18164. + pr_err("bcm2708_rng_init failed to ioremap\n");
  18165. + return -ENOMEM;
  18166. + }
  18167. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  18168. + /* register driver */
  18169. + err = hwrng_register(&bcm2708_rng_ops);
  18170. + if (err) {
  18171. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  18172. + iounmap(rng_base);
  18173. + } else {
  18174. + /* set warm-up count & enable */
  18175. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  18176. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  18177. + }
  18178. + return err;
  18179. +}
  18180. +
  18181. +static void __exit bcm2708_rng_exit(void)
  18182. +{
  18183. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  18184. + pr_info("bcm2708_rng_exit\n");
  18185. + /* disable rng hardware */
  18186. + __raw_writel(0, rng_base + RNG_CTRL);
  18187. + /* unregister driver */
  18188. + hwrng_unregister(&bcm2708_rng_ops);
  18189. + iounmap(rng_base);
  18190. +}
  18191. +
  18192. +module_init(bcm2708_rng_init);
  18193. +module_exit(bcm2708_rng_exit);
  18194. +
  18195. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  18196. +MODULE_LICENSE("GPL and additional rights");
  18197. diff -Nur linux-3.12.38/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  18198. --- linux-3.12.38/drivers/char/hw_random/Kconfig 2015-02-16 16:15:42.000000000 +0100
  18199. +++ linux-rpi/drivers/char/hw_random/Kconfig 2015-03-10 17:26:50.166216694 +0100
  18200. @@ -314,3 +314,14 @@
  18201. module will be called tpm-rng.
  18202. If unsure, say Y.
  18203. +
  18204. +config HW_RANDOM_BCM2708
  18205. + tristate "BCM2708 generic true random number generator support"
  18206. + depends on HW_RANDOM && ARCH_BCM2708
  18207. + ---help---
  18208. + This driver provides the kernel-side support for the BCM2708 hardware.
  18209. +
  18210. + To compile this driver as a module, choose M here: the
  18211. + module will be called bcm2708-rng.
  18212. +
  18213. + If unsure, say N.
  18214. diff -Nur linux-3.12.38/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  18215. --- linux-3.12.38/drivers/char/hw_random/Makefile 2015-02-16 16:15:42.000000000 +0100
  18216. +++ linux-rpi/drivers/char/hw_random/Makefile 2015-03-10 17:26:50.166216694 +0100
  18217. @@ -27,3 +27,4 @@
  18218. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  18219. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  18220. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  18221. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  18222. diff -Nur linux-3.12.38/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  18223. --- linux-3.12.38/drivers/char/Kconfig 2015-02-16 16:15:42.000000000 +0100
  18224. +++ linux-rpi/drivers/char/Kconfig 2015-03-10 17:26:50.162216694 +0100
  18225. @@ -574,6 +574,8 @@
  18226. source "drivers/s390/char/Kconfig"
  18227. +source "drivers/char/broadcom/Kconfig"
  18228. +
  18229. config MSM_SMD_PKT
  18230. bool "Enable device interface for some SMD packet ports"
  18231. default n
  18232. diff -Nur linux-3.12.38/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  18233. --- linux-3.12.38/drivers/char/Makefile 2015-02-16 16:15:42.000000000 +0100
  18234. +++ linux-rpi/drivers/char/Makefile 2015-03-10 17:26:50.162216694 +0100
  18235. @@ -62,3 +62,5 @@
  18236. js-rtc-y = rtc.o
  18237. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  18238. +
  18239. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  18240. diff -Nur linux-3.12.38/drivers/clocksource/exynos_mct.c linux-rpi/drivers/clocksource/exynos_mct.c
  18241. --- linux-3.12.38/drivers/clocksource/exynos_mct.c 2015-02-16 16:15:42.000000000 +0100
  18242. +++ linux-rpi/drivers/clocksource/exynos_mct.c 2015-03-10 17:26:50.178216694 +0100
  18243. @@ -94,8 +94,8 @@
  18244. __raw_writel(value, reg_base + offset);
  18245. if (likely(offset >= EXYNOS4_MCT_L_BASE(0))) {
  18246. - stat_addr = (offset & EXYNOS4_MCT_L_MASK) + MCT_L_WSTAT_OFFSET;
  18247. - switch (offset & ~EXYNOS4_MCT_L_MASK) {
  18248. + stat_addr = (offset & ~EXYNOS4_MCT_L_MASK) + MCT_L_WSTAT_OFFSET;
  18249. + switch (offset & EXYNOS4_MCT_L_MASK) {
  18250. case MCT_L_TCON_OFFSET:
  18251. mask = 1 << 3; /* L_TCON write status */
  18252. break;
  18253. diff -Nur linux-3.12.38/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  18254. --- linux-3.12.38/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  18255. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2015-03-10 17:26:50.182216694 +0100
  18256. @@ -0,0 +1,239 @@
  18257. +/*****************************************************************************
  18258. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  18259. +*
  18260. +* Unless you and Broadcom execute a separate written software license
  18261. +* agreement governing use of this software, this software is licensed to you
  18262. +* under the terms of the GNU General Public License version 2, available at
  18263. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  18264. +*
  18265. +* Notwithstanding the above, under no circumstances may you combine this
  18266. +* software in any way with any other Broadcom software provided under a
  18267. +* license other than the GPL, without Broadcom's express prior written
  18268. +* consent.
  18269. +*****************************************************************************/
  18270. +
  18271. +/*****************************************************************************
  18272. +* FILENAME: bcm2835-cpufreq.h
  18273. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  18274. +* processor. Messages are sent to Videocore either setting or requesting the
  18275. +* frequency of the ARM in order to match an appropiate frequency to the current
  18276. +* usage of the processor. The policy which selects the frequency to use is
  18277. +* defined in the kernel .config file, but can be changed during runtime.
  18278. +*****************************************************************************/
  18279. +
  18280. +/* ---------- INCLUDES ---------- */
  18281. +#include <linux/kernel.h>
  18282. +#include <linux/init.h>
  18283. +#include <linux/module.h>
  18284. +#include <linux/cpufreq.h>
  18285. +#include <mach/vcio.h>
  18286. +
  18287. +/* ---------- DEFINES ---------- */
  18288. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  18289. +#define MODULE_NAME "bcm2835-cpufreq"
  18290. +
  18291. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  18292. +
  18293. +/* debug printk macros */
  18294. +#ifdef CPUFREQ_DEBUG_ENABLE
  18295. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  18296. +#else
  18297. +#define print_debug(fmt,...)
  18298. +#endif
  18299. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  18300. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  18301. +
  18302. +/* tag part of the message */
  18303. +struct vc_msg_tag {
  18304. + uint32_t tag_id; /* the message id */
  18305. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  18306. + uint32_t data_size; /* amount of data being sent or received */
  18307. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  18308. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  18309. +};
  18310. +
  18311. +/* message structure to be sent to videocore */
  18312. +struct vc_msg {
  18313. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  18314. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  18315. + struct vc_msg_tag tag; /* the tag structure above to make */
  18316. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  18317. +};
  18318. +
  18319. +/* ---------- GLOBALS ---------- */
  18320. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  18321. +
  18322. +/*
  18323. + ===============================================
  18324. + clk_rate either gets or sets the clock rates.
  18325. + ===============================================
  18326. +*/
  18327. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  18328. +{
  18329. + int s, actual_rate=0;
  18330. + struct vc_msg msg;
  18331. +
  18332. + /* wipe all previous message data */
  18333. + memset(&msg, 0, sizeof msg);
  18334. +
  18335. + msg.msg_size = sizeof msg;
  18336. +
  18337. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  18338. + msg.tag.buffer_size = 8;
  18339. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  18340. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  18341. + msg.tag.val = arm_rate * 1000;
  18342. +
  18343. + /* send the message */
  18344. + s = bcm_mailbox_property(&msg, sizeof msg);
  18345. +
  18346. + /* check if it was all ok and return the rate in KHz */
  18347. + if (s == 0 && (msg.request_code & 0x80000000))
  18348. + actual_rate = msg.tag.val/1000;
  18349. +
  18350. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  18351. + return actual_rate;
  18352. +}
  18353. +
  18354. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  18355. +{
  18356. + int s;
  18357. + int arm_rate = 0;
  18358. + struct vc_msg msg;
  18359. +
  18360. + /* wipe all previous message data */
  18361. + memset(&msg, 0, sizeof msg);
  18362. +
  18363. + msg.msg_size = sizeof msg;
  18364. + msg.tag.tag_id = tag;
  18365. + msg.tag.buffer_size = 8;
  18366. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  18367. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  18368. +
  18369. + /* send the message */
  18370. + s = bcm_mailbox_property(&msg, sizeof msg);
  18371. +
  18372. + /* check if it was all ok and return the rate in KHz */
  18373. + if (s == 0 && (msg.request_code & 0x80000000))
  18374. + arm_rate = msg.tag.val/1000;
  18375. +
  18376. + print_debug("%s frequency = %d\n",
  18377. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  18378. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  18379. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  18380. + "Unexpected", arm_rate);
  18381. +
  18382. + return arm_rate;
  18383. +}
  18384. +
  18385. +/*
  18386. + ====================================================
  18387. + Module Initialisation registers the cpufreq driver
  18388. + ====================================================
  18389. +*/
  18390. +static int __init bcm2835_cpufreq_module_init(void)
  18391. +{
  18392. + print_debug("IN\n");
  18393. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  18394. +}
  18395. +
  18396. +/*
  18397. + =============
  18398. + Module exit
  18399. + =============
  18400. +*/
  18401. +static void __exit bcm2835_cpufreq_module_exit(void)
  18402. +{
  18403. + print_debug("IN\n");
  18404. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  18405. + return;
  18406. +}
  18407. +
  18408. +/*
  18409. + ==============================================================
  18410. + Initialisation function sets up the CPU policy for first use
  18411. + ==============================================================
  18412. +*/
  18413. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  18414. +{
  18415. + /* measured value of how long it takes to change frequency */
  18416. + policy->cpuinfo.transition_latency = 355000; /* ns */
  18417. +
  18418. + /* now find out what the maximum and minimum frequencies are */
  18419. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  18420. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  18421. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  18422. +
  18423. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  18424. + return 0;
  18425. +}
  18426. +
  18427. +/*
  18428. + =================================================================================
  18429. + Target function chooses the most appropriate frequency from the table to enable
  18430. + =================================================================================
  18431. +*/
  18432. +
  18433. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  18434. +{
  18435. + unsigned int target = target_freq;
  18436. +#ifdef CPUFREQ_DEBUG_ENABLE
  18437. + unsigned int cur = policy->cur;
  18438. +#endif
  18439. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  18440. +
  18441. + /* if we are above min and using ondemand, then just use max */
  18442. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  18443. + target = policy->max;
  18444. + /* if the frequency is the same, just quit */
  18445. + if (target == policy->cur)
  18446. + return 0;
  18447. +
  18448. + /* otherwise were good to set the clock frequency */
  18449. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  18450. +
  18451. + if (!policy->cur)
  18452. + {
  18453. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  18454. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  18455. + return -EINVAL;
  18456. + }
  18457. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  18458. + return 0;
  18459. +}
  18460. +
  18461. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  18462. +{
  18463. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  18464. + print_debug("cpu=%d\n", actual_rate);
  18465. + return actual_rate;
  18466. +}
  18467. +
  18468. +/*
  18469. + =================================================================================
  18470. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  18471. + =================================================================================
  18472. +*/
  18473. +
  18474. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  18475. +{
  18476. + print_info("switching to governor %s\n", policy->governor->name);
  18477. + return 0;
  18478. +}
  18479. +
  18480. +
  18481. +/* the CPUFreq driver */
  18482. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  18483. + .name = "BCM2835 CPUFreq",
  18484. + .init = bcm2835_cpufreq_driver_init,
  18485. + .verify = bcm2835_cpufreq_driver_verify,
  18486. + .target = bcm2835_cpufreq_driver_target,
  18487. + .get = bcm2835_cpufreq_driver_get
  18488. +};
  18489. +
  18490. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  18491. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  18492. +MODULE_LICENSE("GPL");
  18493. +
  18494. +module_init(bcm2835_cpufreq_module_init);
  18495. +module_exit(bcm2835_cpufreq_module_exit);
  18496. diff -Nur linux-3.12.38/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  18497. --- linux-3.12.38/drivers/cpufreq/Kconfig.arm 2015-02-16 16:15:42.000000000 +0100
  18498. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2015-03-10 17:26:50.182216694 +0100
  18499. @@ -228,6 +228,14 @@
  18500. help
  18501. This adds the CPUFreq driver support for SPEAr SOCs.
  18502. +config ARM_BCM2835_CPUFREQ
  18503. + bool "BCM2835 Driver"
  18504. + default y
  18505. + help
  18506. + This adds the CPUFreq driver for BCM2835
  18507. +
  18508. + If in doubt, say N.
  18509. +
  18510. config ARM_TEGRA_CPUFREQ
  18511. bool "TEGRA CPUFreq support"
  18512. depends on ARCH_TEGRA
  18513. diff -Nur linux-3.12.38/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  18514. --- linux-3.12.38/drivers/cpufreq/Makefile 2015-02-16 16:15:42.000000000 +0100
  18515. +++ linux-rpi/drivers/cpufreq/Makefile 2015-03-10 17:26:50.182216694 +0100
  18516. @@ -76,6 +76,7 @@
  18517. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  18518. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  18519. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  18520. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  18521. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  18522. ##################################################################################
  18523. diff -Nur linux-3.12.38/drivers/crypto/padlock-aes.c linux-rpi/drivers/crypto/padlock-aes.c
  18524. --- linux-3.12.38/drivers/crypto/padlock-aes.c 2015-02-16 16:15:42.000000000 +0100
  18525. +++ linux-rpi/drivers/crypto/padlock-aes.c 2015-03-10 17:26:50.190216694 +0100
  18526. @@ -563,4 +563,4 @@
  18527. MODULE_LICENSE("GPL");
  18528. MODULE_AUTHOR("Michal Ludvig");
  18529. -MODULE_ALIAS_CRYPTO("aes");
  18530. +MODULE_ALIAS("aes");
  18531. diff -Nur linux-3.12.38/drivers/crypto/padlock-sha.c linux-rpi/drivers/crypto/padlock-sha.c
  18532. --- linux-3.12.38/drivers/crypto/padlock-sha.c 2015-02-16 16:15:42.000000000 +0100
  18533. +++ linux-rpi/drivers/crypto/padlock-sha.c 2015-03-10 17:26:50.190216694 +0100
  18534. @@ -593,7 +593,7 @@
  18535. MODULE_LICENSE("GPL");
  18536. MODULE_AUTHOR("Michal Ludvig");
  18537. -MODULE_ALIAS_CRYPTO("sha1-all");
  18538. -MODULE_ALIAS_CRYPTO("sha256-all");
  18539. -MODULE_ALIAS_CRYPTO("sha1-padlock");
  18540. -MODULE_ALIAS_CRYPTO("sha256-padlock");
  18541. +MODULE_ALIAS("sha1-all");
  18542. +MODULE_ALIAS("sha256-all");
  18543. +MODULE_ALIAS("sha1-padlock");
  18544. +MODULE_ALIAS("sha256-padlock");
  18545. diff -Nur linux-3.12.38/drivers/crypto/ux500/cryp/cryp_core.c linux-rpi/drivers/crypto/ux500/cryp/cryp_core.c
  18546. --- linux-3.12.38/drivers/crypto/ux500/cryp/cryp_core.c 2015-02-16 16:15:42.000000000 +0100
  18547. +++ linux-rpi/drivers/crypto/ux500/cryp/cryp_core.c 2015-03-10 17:26:50.194216694 +0100
  18548. @@ -1810,7 +1810,7 @@
  18549. module_param(cryp_mode, int, 0);
  18550. MODULE_DESCRIPTION("Driver for ST-Ericsson UX500 CRYP crypto engine.");
  18551. -MODULE_ALIAS_CRYPTO("aes-all");
  18552. -MODULE_ALIAS_CRYPTO("des-all");
  18553. +MODULE_ALIAS("aes-all");
  18554. +MODULE_ALIAS("des-all");
  18555. MODULE_LICENSE("GPL");
  18556. diff -Nur linux-3.12.38/drivers/crypto/ux500/hash/hash_core.c linux-rpi/drivers/crypto/ux500/hash/hash_core.c
  18557. --- linux-3.12.38/drivers/crypto/ux500/hash/hash_core.c 2015-02-16 16:15:42.000000000 +0100
  18558. +++ linux-rpi/drivers/crypto/ux500/hash/hash_core.c 2015-03-10 17:26:50.194216694 +0100
  18559. @@ -1995,7 +1995,7 @@
  18560. MODULE_DESCRIPTION("Driver for ST-Ericsson UX500 HASH engine.");
  18561. MODULE_LICENSE("GPL");
  18562. -MODULE_ALIAS_CRYPTO("sha1-all");
  18563. -MODULE_ALIAS_CRYPTO("sha256-all");
  18564. -MODULE_ALIAS_CRYPTO("hmac-sha1-all");
  18565. -MODULE_ALIAS_CRYPTO("hmac-sha256-all");
  18566. +MODULE_ALIAS("sha1-all");
  18567. +MODULE_ALIAS("sha256-all");
  18568. +MODULE_ALIAS("hmac-sha1-all");
  18569. +MODULE_ALIAS("hmac-sha256-all");
  18570. diff -Nur linux-3.12.38/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  18571. --- linux-3.12.38/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  18572. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2015-03-10 17:26:50.194216694 +0100
  18573. @@ -0,0 +1,1052 @@
  18574. +/*
  18575. + * BCM2835 DMA engine support
  18576. + *
  18577. + * This driver supports cyclic and scatter/gather DMA transfers.
  18578. + *
  18579. + * Author: Florian Meier <florian.meier@koalo.de>
  18580. + * Gellert Weisz <gellert@raspberrypi.org>
  18581. + * Copyright 2013-2014
  18582. + *
  18583. + * Based on
  18584. + * OMAP DMAengine support by Russell King
  18585. + *
  18586. + * BCM2708 DMA Driver
  18587. + * Copyright (C) 2010 Broadcom
  18588. + *
  18589. + * Raspberry Pi PCM I2S ALSA Driver
  18590. + * Copyright (c) by Phil Poole 2013
  18591. + *
  18592. + * MARVELL MMP Peripheral DMA Driver
  18593. + * Copyright 2012 Marvell International Ltd.
  18594. + *
  18595. + * This program is free software; you can redistribute it and/or modify
  18596. + * it under the terms of the GNU General Public License as published by
  18597. + * the Free Software Foundation; either version 2 of the License, or
  18598. + * (at your option) any later version.
  18599. + *
  18600. + * This program is distributed in the hope that it will be useful,
  18601. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18602. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18603. + * GNU General Public License for more details.
  18604. + */
  18605. +
  18606. +#include <linux/dmaengine.h>
  18607. +#include <linux/dma-mapping.h>
  18608. +#include <linux/err.h>
  18609. +#include <linux/init.h>
  18610. +#include <linux/interrupt.h>
  18611. +#include <linux/list.h>
  18612. +#include <linux/module.h>
  18613. +#include <linux/platform_device.h>
  18614. +#include <linux/slab.h>
  18615. +#include <linux/io.h>
  18616. +#include <linux/spinlock.h>
  18617. +
  18618. +#ifndef CONFIG_OF
  18619. +
  18620. +/* dma manager */
  18621. +#include <mach/dma.h>
  18622. +
  18623. +#define DMA_COMPLETE DMA_SUCCESS
  18624. +
  18625. +#endif
  18626. +
  18627. +#include <linux/of.h>
  18628. +#include <linux/of_dma.h>
  18629. +
  18630. +#include "virt-dma.h"
  18631. +
  18632. +
  18633. +struct bcm2835_dmadev {
  18634. + struct dma_device ddev;
  18635. + spinlock_t lock;
  18636. + void __iomem *base;
  18637. + struct device_dma_parameters dma_parms;
  18638. +};
  18639. +
  18640. +struct bcm2835_dma_cb {
  18641. + uint32_t info;
  18642. + uint32_t src;
  18643. + uint32_t dst;
  18644. + uint32_t length;
  18645. + uint32_t stride;
  18646. + uint32_t next;
  18647. + uint32_t pad[2];
  18648. +};
  18649. +
  18650. +struct bcm2835_chan {
  18651. + struct virt_dma_chan vc;
  18652. + struct list_head node;
  18653. +
  18654. + struct dma_slave_config cfg;
  18655. + bool cyclic;
  18656. +
  18657. + int ch;
  18658. + struct bcm2835_desc *desc;
  18659. +
  18660. + void __iomem *chan_base;
  18661. + int irq_number;
  18662. +
  18663. + unsigned int dreq;
  18664. +};
  18665. +
  18666. +struct bcm2835_desc {
  18667. + struct virt_dma_desc vd;
  18668. + enum dma_transfer_direction dir;
  18669. +
  18670. + unsigned int control_block_size;
  18671. + struct bcm2835_dma_cb *control_block_base;
  18672. + dma_addr_t control_block_base_phys;
  18673. +
  18674. + unsigned int frames;
  18675. + size_t size;
  18676. +};
  18677. +
  18678. +#define BCM2835_DMA_CS 0x00
  18679. +#define BCM2835_DMA_ADDR 0x04
  18680. +#define BCM2835_DMA_SOURCE_AD 0x0c
  18681. +#define BCM2835_DMA_DEST_AD 0x10
  18682. +#define BCM2835_DMA_NEXTCB 0x1C
  18683. +
  18684. +/* DMA CS Control and Status bits */
  18685. +#define BCM2835_DMA_ACTIVE BIT(0)
  18686. +#define BCM2835_DMA_INT BIT(2)
  18687. +#define BCM2835_DMA_ISPAUSED BIT(4) /* Pause requested or not active */
  18688. +#define BCM2835_DMA_ISHELD BIT(5) /* Is held by DREQ flow control */
  18689. +#define BCM2835_DMA_ERR BIT(8)
  18690. +#define BCM2835_DMA_ABORT BIT(30) /* Stop current CB, go to next, WO */
  18691. +#define BCM2835_DMA_RESET BIT(31) /* WO, self clearing */
  18692. +
  18693. +#define BCM2835_DMA_INT_EN BIT(0)
  18694. +#define BCM2835_DMA_WAIT_RESP BIT(3)
  18695. +#define BCM2835_DMA_D_INC BIT(4)
  18696. +#define BCM2835_DMA_D_WIDTH BIT(5)
  18697. +#define BCM2835_DMA_D_DREQ BIT(6)
  18698. +#define BCM2835_DMA_S_INC BIT(8)
  18699. +#define BCM2835_DMA_S_WIDTH BIT(9)
  18700. +#define BCM2835_DMA_S_DREQ BIT(10)
  18701. +
  18702. +#define BCM2835_DMA_PER_MAP(x) ((x) << 16)
  18703. +#define BCM2835_DMA_WAITS(x) (((x)&0x1f) << 21)
  18704. +
  18705. +#define SDHCI_BCM_DMA_WAITS 20 /* delays slowing DMA transfers: 0-31 */
  18706. +
  18707. +#define BCM2835_DMA_DATA_TYPE_S8 1
  18708. +#define BCM2835_DMA_DATA_TYPE_S16 2
  18709. +#define BCM2835_DMA_DATA_TYPE_S32 4
  18710. +#define BCM2835_DMA_DATA_TYPE_S128 16
  18711. +
  18712. +#define BCM2835_DMA_BULK_MASK BIT(0)
  18713. +#define BCM2835_DMA_FIQ_MASK (BIT(2) | BIT(3))
  18714. +
  18715. +
  18716. +/* Valid only for channels 0 - 14, 15 has its own base address */
  18717. +#define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
  18718. +#define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
  18719. +
  18720. +#define MAX_LITE_TRANSFER 32768
  18721. +#define MAX_NORMAL_TRANSFER 1073741824
  18722. +
  18723. +static inline struct bcm2835_dmadev *to_bcm2835_dma_dev(struct dma_device *d)
  18724. +{
  18725. + return container_of(d, struct bcm2835_dmadev, ddev);
  18726. +}
  18727. +
  18728. +static inline struct bcm2835_chan *to_bcm2835_dma_chan(struct dma_chan *c)
  18729. +{
  18730. + return container_of(c, struct bcm2835_chan, vc.chan);
  18731. +}
  18732. +
  18733. +static inline struct bcm2835_desc *to_bcm2835_dma_desc(
  18734. + struct dma_async_tx_descriptor *t)
  18735. +{
  18736. + return container_of(t, struct bcm2835_desc, vd.tx);
  18737. +}
  18738. +
  18739. +static void dma_dumpregs(struct bcm2835_chan *c)
  18740. +{
  18741. + pr_debug("-------------DMA DUMPREGS-------------\n");
  18742. + pr_debug("CS= %u\n",
  18743. + readl(c->chan_base + BCM2835_DMA_CS));
  18744. + pr_debug("ADDR= %u\n",
  18745. + readl(c->chan_base + BCM2835_DMA_ADDR));
  18746. + pr_debug("SOURCE_ADDR= %u\n",
  18747. + readl(c->chan_base + BCM2835_DMA_SOURCE_AD));
  18748. + pr_debug("DEST_AD= %u\n",
  18749. + readl(c->chan_base + BCM2835_DMA_DEST_AD));
  18750. + pr_debug("NEXTCB= %u\n",
  18751. + readl(c->chan_base + BCM2835_DMA_NEXTCB));
  18752. + pr_debug("--------------------------------------\n");
  18753. +}
  18754. +
  18755. +static void bcm2835_dma_desc_free(struct virt_dma_desc *vd)
  18756. +{
  18757. + struct bcm2835_desc *desc = container_of(vd, struct bcm2835_desc, vd);
  18758. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  18759. + desc->control_block_size,
  18760. + desc->control_block_base,
  18761. + desc->control_block_base_phys);
  18762. + kfree(desc);
  18763. +}
  18764. +
  18765. +static int bcm2835_dma_abort(void __iomem *chan_base)
  18766. +{
  18767. + unsigned long cs;
  18768. + long int timeout = 10000;
  18769. +
  18770. + cs = readl(chan_base + BCM2835_DMA_CS);
  18771. + if (!(cs & BCM2835_DMA_ACTIVE))
  18772. + return 0;
  18773. +
  18774. + /* Write 0 to the active bit - Pause the DMA */
  18775. + writel(0, chan_base + BCM2835_DMA_CS);
  18776. +
  18777. + /* Wait for any current AXI transfer to complete */
  18778. + while ((cs & BCM2835_DMA_ISPAUSED) && --timeout) {
  18779. + cpu_relax();
  18780. + cs = readl(chan_base + BCM2835_DMA_CS);
  18781. + }
  18782. +
  18783. + /* We'll un-pause when we set of our next DMA */
  18784. + if (!timeout)
  18785. + return -ETIMEDOUT;
  18786. +
  18787. + if (!(cs & BCM2835_DMA_ACTIVE))
  18788. + return 0;
  18789. +
  18790. + /* Terminate the control block chain */
  18791. + writel(0, chan_base + BCM2835_DMA_NEXTCB);
  18792. +
  18793. + /* Abort the whole DMA */
  18794. + writel(BCM2835_DMA_ABORT | BCM2835_DMA_ACTIVE,
  18795. + chan_base + BCM2835_DMA_CS);
  18796. +
  18797. + return 0;
  18798. +}
  18799. +
  18800. +
  18801. +static void bcm2835_dma_start_desc(struct bcm2835_chan *c)
  18802. +{
  18803. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  18804. + struct bcm2835_desc *d;
  18805. +
  18806. + if (!vd) {
  18807. + c->desc = NULL;
  18808. + return;
  18809. + }
  18810. +
  18811. + list_del(&vd->node);
  18812. +
  18813. + c->desc = d = to_bcm2835_dma_desc(&vd->tx);
  18814. +
  18815. + writel(d->control_block_base_phys, c->chan_base + BCM2835_DMA_ADDR);
  18816. + writel(BCM2835_DMA_ACTIVE, c->chan_base + BCM2835_DMA_CS);
  18817. +
  18818. +}
  18819. +
  18820. +static irqreturn_t bcm2835_dma_callback(int irq, void *data)
  18821. +{
  18822. + struct bcm2835_chan *c = data;
  18823. + struct bcm2835_desc *d;
  18824. + unsigned long flags;
  18825. +
  18826. + spin_lock_irqsave(&c->vc.lock, flags);
  18827. +
  18828. + /* Acknowledge interrupt */
  18829. + writel(BCM2835_DMA_INT, c->chan_base + BCM2835_DMA_CS);
  18830. +
  18831. + d = c->desc;
  18832. +
  18833. + if (d) {
  18834. + if (c->cyclic) {
  18835. + vchan_cyclic_callback(&d->vd);
  18836. +
  18837. + /* Keep the DMA engine running */
  18838. + writel(BCM2835_DMA_ACTIVE,
  18839. + c->chan_base + BCM2835_DMA_CS);
  18840. +
  18841. + } else {
  18842. + vchan_cookie_complete(&c->desc->vd);
  18843. + bcm2835_dma_start_desc(c);
  18844. + }
  18845. + }
  18846. +
  18847. + spin_unlock_irqrestore(&c->vc.lock, flags);
  18848. +
  18849. + return IRQ_HANDLED;
  18850. +}
  18851. +
  18852. +static int bcm2835_dma_alloc_chan_resources(struct dma_chan *chan)
  18853. +{
  18854. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  18855. + int ret;
  18856. +
  18857. + dev_dbg(c->vc.chan.device->dev,
  18858. + "Allocating DMA channel %d\n", c->ch);
  18859. +
  18860. + ret = request_irq(c->irq_number,
  18861. + bcm2835_dma_callback, 0, "DMA IRQ", c);
  18862. +
  18863. + return ret;
  18864. +}
  18865. +
  18866. +static void bcm2835_dma_free_chan_resources(struct dma_chan *chan)
  18867. +{
  18868. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  18869. +
  18870. + vchan_free_chan_resources(&c->vc);
  18871. + free_irq(c->irq_number, c);
  18872. +
  18873. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  18874. +}
  18875. +
  18876. +static size_t bcm2835_dma_desc_size(struct bcm2835_desc *d)
  18877. +{
  18878. + return d->size;
  18879. +}
  18880. +
  18881. +static size_t bcm2835_dma_desc_size_pos(struct bcm2835_desc *d, dma_addr_t addr)
  18882. +{
  18883. + unsigned int i;
  18884. + size_t size;
  18885. +
  18886. + for (size = i = 0; i < d->frames; i++) {
  18887. + struct bcm2835_dma_cb *control_block =
  18888. + &d->control_block_base[i];
  18889. + size_t this_size = control_block->length;
  18890. + dma_addr_t dma;
  18891. +
  18892. + if (d->dir == DMA_DEV_TO_MEM)
  18893. + dma = control_block->dst;
  18894. + else
  18895. + dma = control_block->src;
  18896. +
  18897. + if (size)
  18898. + size += this_size;
  18899. + else if (addr >= dma && addr < dma + this_size)
  18900. + size += dma + this_size - addr;
  18901. + }
  18902. +
  18903. + return size;
  18904. +}
  18905. +
  18906. +static enum dma_status bcm2835_dma_tx_status(struct dma_chan *chan,
  18907. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  18908. +{
  18909. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  18910. + struct bcm2835_desc *d;
  18911. + struct virt_dma_desc *vd;
  18912. + enum dma_status ret;
  18913. + unsigned long flags;
  18914. + dma_addr_t pos;
  18915. +
  18916. + ret = dma_cookie_status(chan, cookie, txstate);
  18917. + if (ret == DMA_COMPLETE || !txstate)
  18918. + return ret;
  18919. +
  18920. + spin_lock_irqsave(&c->vc.lock, flags);
  18921. + vd = vchan_find_desc(&c->vc, cookie);
  18922. + if (vd) {
  18923. + txstate->residue =
  18924. + bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));
  18925. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  18926. + d = c->desc;
  18927. +
  18928. + if (d->dir == DMA_MEM_TO_DEV)
  18929. + pos = readl(c->chan_base + BCM2835_DMA_SOURCE_AD);
  18930. + else if (d->dir == DMA_DEV_TO_MEM)
  18931. + pos = readl(c->chan_base + BCM2835_DMA_DEST_AD);
  18932. + else
  18933. + pos = 0;
  18934. +
  18935. + txstate->residue = bcm2835_dma_desc_size_pos(d, pos);
  18936. + } else {
  18937. + txstate->residue = 0;
  18938. + }
  18939. +
  18940. + spin_unlock_irqrestore(&c->vc.lock, flags);
  18941. +
  18942. + return ret;
  18943. +}
  18944. +
  18945. +static void bcm2835_dma_issue_pending(struct dma_chan *chan)
  18946. +{
  18947. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  18948. + unsigned long flags;
  18949. +
  18950. + spin_lock_irqsave(&c->vc.lock, flags);
  18951. + if (vchan_issue_pending(&c->vc) && !c->desc)
  18952. + bcm2835_dma_start_desc(c);
  18953. +
  18954. + spin_unlock_irqrestore(&c->vc.lock, flags);
  18955. +}
  18956. +
  18957. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
  18958. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  18959. + size_t period_len, enum dma_transfer_direction direction,
  18960. + unsigned long flags, void *context)
  18961. +{
  18962. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  18963. + enum dma_slave_buswidth dev_width;
  18964. + struct bcm2835_desc *d;
  18965. + dma_addr_t dev_addr;
  18966. + unsigned int es, sync_type;
  18967. + unsigned int frame, max_size;
  18968. +
  18969. + /* Grab configuration */
  18970. + if (!is_slave_direction(direction)) {
  18971. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  18972. + return NULL;
  18973. + }
  18974. +
  18975. + if (direction == DMA_DEV_TO_MEM) {
  18976. + dev_addr = c->cfg.src_addr;
  18977. + dev_width = c->cfg.src_addr_width;
  18978. + sync_type = BCM2835_DMA_S_DREQ;
  18979. + } else {
  18980. + dev_addr = c->cfg.dst_addr;
  18981. + dev_width = c->cfg.dst_addr_width;
  18982. + sync_type = BCM2835_DMA_D_DREQ;
  18983. + }
  18984. +
  18985. + /* Bus width translates to the element size (ES) */
  18986. + switch (dev_width) {
  18987. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  18988. + es = BCM2835_DMA_DATA_TYPE_S32;
  18989. + break;
  18990. + default:
  18991. + return NULL;
  18992. + }
  18993. +
  18994. + /* Now allocate and setup the descriptor. */
  18995. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  18996. + if (!d)
  18997. + return NULL;
  18998. +
  18999. + d->dir = direction;
  19000. +
  19001. + if (c->ch >= 8) /* we have a LITE channel */
  19002. + max_size = MAX_LITE_TRANSFER;
  19003. + else
  19004. + max_size = MAX_NORMAL_TRANSFER;
  19005. + period_len = min(period_len, max_size);
  19006. +
  19007. + d->frames = (buf_len-1) / period_len + 1;
  19008. +
  19009. + /* Allocate memory for control blocks */
  19010. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  19011. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  19012. + d->control_block_size, &d->control_block_base_phys,
  19013. + GFP_NOWAIT);
  19014. +
  19015. + if (!d->control_block_base) {
  19016. + kfree(d);
  19017. + return NULL;
  19018. + }
  19019. +
  19020. + /*
  19021. + * Iterate over all frames, create a control block
  19022. + * for each frame and link them together.
  19023. + */
  19024. + for (frame = 0; frame < d->frames; frame++) {
  19025. + struct bcm2835_dma_cb *control_block =
  19026. + &d->control_block_base[frame];
  19027. +
  19028. + /* Setup adresses */
  19029. + if (d->dir == DMA_DEV_TO_MEM) {
  19030. + control_block->info = BCM2835_DMA_D_INC;
  19031. + control_block->src = dev_addr;
  19032. + control_block->dst = buf_addr + frame * period_len;
  19033. + } else {
  19034. + control_block->info = BCM2835_DMA_S_INC;
  19035. + control_block->src = buf_addr + frame * period_len;
  19036. + control_block->dst = dev_addr;
  19037. + }
  19038. +
  19039. + /* Enable interrupt */
  19040. + control_block->info |= BCM2835_DMA_INT_EN;
  19041. +
  19042. + /* Setup synchronization */
  19043. + if (sync_type != 0)
  19044. + control_block->info |= sync_type;
  19045. +
  19046. + /* Setup DREQ channel */
  19047. + if (c->cfg.slave_id != 0)
  19048. + control_block->info |=
  19049. + BCM2835_DMA_PER_MAP(c->cfg.slave_id);
  19050. +
  19051. + /* Length of a frame */
  19052. + if (frame != d->frames-1)
  19053. + control_block->length = period_len;
  19054. + else
  19055. + control_block->length = buf_len - (d->frames - 1) * period_len;
  19056. +
  19057. + d->size += control_block->length;
  19058. +
  19059. + /*
  19060. + * Next block is the next frame.
  19061. + * This function is called on cyclic DMA transfers.
  19062. + * Therefore, wrap around at number of frames.
  19063. + */
  19064. + control_block->next = d->control_block_base_phys +
  19065. + sizeof(struct bcm2835_dma_cb)
  19066. + * ((frame + 1) % d->frames);
  19067. + }
  19068. +
  19069. + c->cyclic = true;
  19070. +
  19071. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  19072. +}
  19073. +
  19074. +
  19075. +static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg(
  19076. + struct dma_chan *chan, struct scatterlist *sgl,
  19077. + unsigned int sg_len, enum dma_transfer_direction direction,
  19078. + unsigned long flags, void *context)
  19079. +{
  19080. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  19081. + enum dma_slave_buswidth dev_width;
  19082. + struct bcm2835_desc *d;
  19083. + dma_addr_t dev_addr;
  19084. + struct scatterlist *sgent;
  19085. + unsigned int es, sync_type;
  19086. + unsigned int i, j, splitct, max_size;
  19087. +
  19088. + if (!is_slave_direction(direction)) {
  19089. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  19090. + return NULL;
  19091. + }
  19092. +
  19093. + if (direction == DMA_DEV_TO_MEM) {
  19094. + dev_addr = c->cfg.src_addr;
  19095. + dev_width = c->cfg.src_addr_width;
  19096. + sync_type = BCM2835_DMA_S_DREQ;
  19097. + } else {
  19098. + dev_addr = c->cfg.dst_addr;
  19099. + dev_width = c->cfg.dst_addr_width;
  19100. + sync_type = BCM2835_DMA_D_DREQ;
  19101. + }
  19102. +
  19103. + /* Bus width translates to the element size (ES) */
  19104. + switch (dev_width) {
  19105. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  19106. + es = BCM2835_DMA_DATA_TYPE_S32;
  19107. + break;
  19108. + default:
  19109. + return NULL;
  19110. + }
  19111. +
  19112. + /* Now allocate and setup the descriptor. */
  19113. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  19114. + if (!d)
  19115. + return NULL;
  19116. +
  19117. + d->dir = direction;
  19118. +
  19119. + if (c->ch >= 8) /* we have a LITE channel */
  19120. + max_size = MAX_LITE_TRANSFER;
  19121. + else
  19122. + max_size = MAX_NORMAL_TRANSFER;
  19123. +
  19124. + /* We store the length of the SG list in d->frames
  19125. + taking care to account for splitting up transfers
  19126. + too large for a LITE channel */
  19127. +
  19128. + d->frames = 0;
  19129. + for_each_sg(sgl, sgent, sg_len, i) {
  19130. + uint32_t len = sg_dma_len(sgent);
  19131. + d->frames += 1 + len / max_size;
  19132. + }
  19133. +
  19134. + /* Allocate memory for control blocks */
  19135. + d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  19136. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  19137. + d->control_block_size, &d->control_block_base_phys,
  19138. + GFP_NOWAIT);
  19139. +
  19140. + if (!d->control_block_base) {
  19141. + kfree(d);
  19142. + return NULL;
  19143. + }
  19144. +
  19145. + /*
  19146. + * Iterate over all SG entries, create a control block
  19147. + * for each frame and link them together.
  19148. + */
  19149. +
  19150. + /* we count the number of times an SG entry had to be splitct
  19151. + as a result of using a LITE channel */
  19152. + splitct = 0;
  19153. +
  19154. + for_each_sg(sgl, sgent, sg_len, i) {
  19155. + dma_addr_t addr = sg_dma_address(sgent);
  19156. + uint32_t len = sg_dma_len(sgent);
  19157. +
  19158. + for (j = 0; j < len; j += max_size) {
  19159. + struct bcm2835_dma_cb *control_block =
  19160. + &d->control_block_base[i+splitct];
  19161. +
  19162. + /* Setup adresses */
  19163. + if (d->dir == DMA_DEV_TO_MEM) {
  19164. + control_block->info = BCM2835_DMA_D_INC |
  19165. + BCM2835_DMA_D_WIDTH | BCM2835_DMA_S_DREQ;
  19166. + control_block->src = dev_addr;
  19167. + control_block->dst = addr + (dma_addr_t)j;
  19168. + } else {
  19169. + control_block->info = BCM2835_DMA_S_INC |
  19170. + BCM2835_DMA_S_WIDTH | BCM2835_DMA_D_DREQ;
  19171. + control_block->src = addr + (dma_addr_t)j;
  19172. + control_block->dst = dev_addr;
  19173. + }
  19174. +
  19175. + /* Common part */
  19176. + control_block->info |= BCM2835_DMA_WAITS(SDHCI_BCM_DMA_WAITS);
  19177. + control_block->info |= BCM2835_DMA_WAIT_RESP;
  19178. +
  19179. + /* Enable */
  19180. + if (i == sg_len-1 && len-j <= max_size)
  19181. + control_block->info |= BCM2835_DMA_INT_EN;
  19182. +
  19183. + /* Setup synchronization */
  19184. + if (sync_type != 0)
  19185. + control_block->info |= sync_type;
  19186. +
  19187. + /* Setup DREQ channel */
  19188. + c->dreq = c->cfg.slave_id; /* DREQ loaded from config */
  19189. +
  19190. + if (c->dreq != 0)
  19191. + control_block->info |=
  19192. + BCM2835_DMA_PER_MAP(c->dreq);
  19193. +
  19194. + /* Length of a frame */
  19195. + control_block->length = min(len-j, max_size);
  19196. + d->size += control_block->length;
  19197. +
  19198. + /*
  19199. + * Next block is the next frame.
  19200. + */
  19201. + if (i < sg_len-1 || len-j > max_size) {
  19202. + /* next block is the next frame. */
  19203. + control_block->next = d->control_block_base_phys +
  19204. + sizeof(struct bcm2835_dma_cb) * (i + splitct + 1);
  19205. + } else {
  19206. + /* next block is empty. */
  19207. + control_block->next = 0;
  19208. + }
  19209. +
  19210. + if (len-j > max_size)
  19211. + splitct++;
  19212. + }
  19213. + }
  19214. +
  19215. + c->cyclic = false;
  19216. +
  19217. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  19218. +}
  19219. +
  19220. +static int bcm2835_dma_slave_config(struct bcm2835_chan *c,
  19221. + struct dma_slave_config *cfg)
  19222. +{
  19223. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  19224. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  19225. + (cfg->direction == DMA_MEM_TO_DEV &&
  19226. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  19227. + !is_slave_direction(cfg->direction)) {
  19228. + return -EINVAL;
  19229. + }
  19230. +
  19231. + c->cfg = *cfg;
  19232. +
  19233. + return 0;
  19234. +}
  19235. +
  19236. +static int bcm2835_dma_terminate_all(struct bcm2835_chan *c)
  19237. +{
  19238. + struct bcm2835_dmadev *d = to_bcm2835_dma_dev(c->vc.chan.device);
  19239. + unsigned long flags;
  19240. + int timeout = 10000;
  19241. + LIST_HEAD(head);
  19242. +
  19243. + spin_lock_irqsave(&c->vc.lock, flags);
  19244. +
  19245. + /* Prevent this channel being scheduled */
  19246. + spin_lock(&d->lock);
  19247. + list_del_init(&c->node);
  19248. + spin_unlock(&d->lock);
  19249. +
  19250. + /*
  19251. + * Stop DMA activity: we assume the callback will not be called
  19252. + * after bcm_dma_abort() returns (even if it does, it will see
  19253. + * c->desc is NULL and exit.)
  19254. + */
  19255. + if (c->desc) {
  19256. + c->desc = NULL;
  19257. + bcm2835_dma_abort(c->chan_base);
  19258. +
  19259. + /* Wait for stopping */
  19260. + while (--timeout) {
  19261. + if (!(readl(c->chan_base + BCM2835_DMA_CS) &
  19262. + BCM2835_DMA_ACTIVE))
  19263. + break;
  19264. +
  19265. + cpu_relax();
  19266. + }
  19267. +
  19268. + if (!timeout)
  19269. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  19270. + }
  19271. +
  19272. + vchan_get_all_descriptors(&c->vc, &head);
  19273. + spin_unlock_irqrestore(&c->vc.lock, flags);
  19274. + vchan_dma_desc_free_list(&c->vc, &head);
  19275. +
  19276. + return 0;
  19277. +}
  19278. +
  19279. +static int bcm2835_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  19280. + unsigned long arg)
  19281. +{
  19282. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  19283. +
  19284. + switch (cmd) {
  19285. + case DMA_SLAVE_CONFIG:
  19286. + return bcm2835_dma_slave_config(c,
  19287. + (struct dma_slave_config *)arg);
  19288. +
  19289. + case DMA_TERMINATE_ALL:
  19290. + return bcm2835_dma_terminate_all(c);
  19291. +
  19292. + default:
  19293. + return -ENXIO;
  19294. + }
  19295. +}
  19296. +
  19297. +#ifdef CONFIG_OF
  19298. +static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
  19299. +{
  19300. + struct bcm2835_chan *c;
  19301. +
  19302. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  19303. + if (!c)
  19304. + return -ENOMEM;
  19305. +
  19306. + c->vc.desc_free = bcm2835_dma_desc_free;
  19307. + vchan_init(&c->vc, &d->ddev);
  19308. + INIT_LIST_HEAD(&c->node);
  19309. +
  19310. + d->ddev.chancnt++;
  19311. +
  19312. + c->chan_base = BCM2835_DMA_CHANIO(d->base, chan_id);
  19313. + c->ch = chan_id;
  19314. + c->irq_number = irq;
  19315. +
  19316. + return 0;
  19317. +}
  19318. +#endif
  19319. +
  19320. +static int bcm2708_dma_chan_init(struct bcm2835_dmadev *d,
  19321. + void __iomem *chan_base, int chan_id, int irq)
  19322. +{
  19323. + struct bcm2835_chan *c;
  19324. +
  19325. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  19326. + if (!c)
  19327. + return -ENOMEM;
  19328. +
  19329. + c->vc.desc_free = bcm2835_dma_desc_free;
  19330. + vchan_init(&c->vc, &d->ddev);
  19331. + INIT_LIST_HEAD(&c->node);
  19332. +
  19333. + d->ddev.chancnt++;
  19334. +
  19335. + c->chan_base = chan_base;
  19336. + c->ch = chan_id;
  19337. + c->irq_number = irq;
  19338. +
  19339. + return 0;
  19340. +}
  19341. +
  19342. +
  19343. +static void bcm2835_dma_free(struct bcm2835_dmadev *od)
  19344. +{
  19345. + struct bcm2835_chan *c, *next;
  19346. +
  19347. + list_for_each_entry_safe(c, next, &od->ddev.channels,
  19348. + vc.chan.device_node) {
  19349. + list_del(&c->vc.chan.device_node);
  19350. + tasklet_kill(&c->vc.task);
  19351. + }
  19352. +}
  19353. +
  19354. +static const struct of_device_id bcm2835_dma_of_match[] = {
  19355. + { .compatible = "brcm,bcm2835-dma", },
  19356. + {},
  19357. +};
  19358. +MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
  19359. +
  19360. +#ifdef CONFIG_OF
  19361. +static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
  19362. + struct of_dma *ofdma)
  19363. +{
  19364. + struct bcm2835_dmadev *d = ofdma->of_dma_data;
  19365. + struct dma_chan *chan;
  19366. +
  19367. + chan = dma_get_any_slave_channel(&d->ddev);
  19368. + if (!chan)
  19369. + return NULL;
  19370. +
  19371. + /* Set DREQ from param */
  19372. + to_bcm2835_dma_chan(chan)->dreq = spec->args[0];
  19373. +
  19374. + return chan;
  19375. +}
  19376. +#endif
  19377. +
  19378. +static int bcm2835_dma_device_slave_caps(struct dma_chan *dchan,
  19379. + struct dma_slave_caps *caps)
  19380. +{
  19381. + caps->src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  19382. + caps->dstn_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  19383. + caps->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  19384. + caps->cmd_pause = false;
  19385. + caps->cmd_terminate = true;
  19386. +
  19387. + return 0;
  19388. +}
  19389. +
  19390. +static int bcm2835_dma_probe(struct platform_device *pdev)
  19391. +{
  19392. + struct bcm2835_dmadev *od;
  19393. +#ifdef CONFIG_OF
  19394. + struct resource *res;
  19395. + void __iomem *base;
  19396. + uint32_t chans_available;
  19397. +#endif
  19398. + int rc;
  19399. + int i;
  19400. + int irq;
  19401. +
  19402. +
  19403. + if (!pdev->dev.dma_mask)
  19404. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  19405. +
  19406. + /* If CONFIG_OF is selected, device tree is used */
  19407. + /* hence the difference between probing */
  19408. +
  19409. +#ifndef CONFIG_OF
  19410. +
  19411. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  19412. + if (rc)
  19413. + return rc;
  19414. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  19415. +
  19416. +
  19417. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  19418. + if (!od)
  19419. + return -ENOMEM;
  19420. +
  19421. + pdev->dev.dma_parms = &od->dma_parms;
  19422. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  19423. +
  19424. +
  19425. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  19426. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  19427. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  19428. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  19429. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  19430. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  19431. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  19432. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  19433. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  19434. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  19435. + od->ddev.device_control = bcm2835_dma_control;
  19436. + od->ddev.dev = &pdev->dev;
  19437. + INIT_LIST_HEAD(&od->ddev.channels);
  19438. + spin_lock_init(&od->lock);
  19439. +
  19440. + platform_set_drvdata(pdev, od);
  19441. +
  19442. + for (i = 0; i < 5; i++) {
  19443. + void __iomem *chan_base;
  19444. + int chan_id;
  19445. +
  19446. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_LITE,
  19447. + &chan_base,
  19448. + &irq);
  19449. +
  19450. + if (chan_id < 0)
  19451. + break;
  19452. +
  19453. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  19454. + if (rc)
  19455. + goto err_no_dma;
  19456. + }
  19457. +#else
  19458. + rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  19459. + if (rc)
  19460. + return rc;
  19461. +
  19462. +
  19463. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  19464. + if (!od)
  19465. + return -ENOMEM;
  19466. +
  19467. + pdev->dev.dma_parms = &od->dma_parms;
  19468. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  19469. +
  19470. +
  19471. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  19472. + base = devm_ioremap_resource(&pdev->dev, res);
  19473. + if (IS_ERR(base))
  19474. + return PTR_ERR(base);
  19475. +
  19476. + od->base = base;
  19477. +
  19478. +
  19479. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  19480. + dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  19481. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  19482. + od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  19483. + od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  19484. + od->ddev.device_tx_status = bcm2835_dma_tx_status;
  19485. + od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  19486. + od->ddev.device_slave_caps = bcm2835_dma_device_slave_caps;
  19487. + od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  19488. + od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  19489. + od->ddev.device_control = bcm2835_dma_control;
  19490. + od->ddev.dev = &pdev->dev;
  19491. + INIT_LIST_HEAD(&od->ddev.channels);
  19492. + spin_lock_init(&od->lock);
  19493. +
  19494. + platform_set_drvdata(pdev, od);
  19495. +
  19496. +
  19497. + /* Request DMA channel mask from device tree */
  19498. + if (of_property_read_u32(pdev->dev.of_node,
  19499. + "brcm,dma-channel-mask",
  19500. + &chans_available)) {
  19501. + dev_err(&pdev->dev, "Failed to get channel mask\n");
  19502. + rc = -EINVAL;
  19503. + goto err_no_dma;
  19504. + }
  19505. +
  19506. +
  19507. + /*
  19508. + * Do not use the FIQ and BULK channels,
  19509. + * because they are used by the GPU.
  19510. + */
  19511. + chans_available &= ~(BCM2835_DMA_FIQ_MASK | BCM2835_DMA_BULK_MASK);
  19512. +
  19513. +
  19514. + for (i = 0; i < pdev->num_resources; i++) {
  19515. + irq = platform_get_irq(pdev, i);
  19516. + if (irq < 0)
  19517. + break;
  19518. +
  19519. + if (chans_available & (1 << i)) {
  19520. + rc = bcm2835_dma_chan_init(od, i, irq);
  19521. + if (rc)
  19522. + goto err_no_dma;
  19523. + }
  19524. + }
  19525. +
  19526. + dev_dbg(&pdev->dev, "Initialized %i DMA channels\n", i);
  19527. +
  19528. + /* Device-tree DMA controller registration */
  19529. + rc = of_dma_controller_register(pdev->dev.of_node,
  19530. + bcm2835_dma_xlate, od);
  19531. + if (rc) {
  19532. + dev_err(&pdev->dev, "Failed to register DMA controller\n");
  19533. + goto err_no_dma;
  19534. + }
  19535. +#endif
  19536. +
  19537. + rc = dma_async_device_register(&od->ddev);
  19538. + if (rc) {
  19539. + dev_err(&pdev->dev,
  19540. + "Failed to register slave DMA engine device: %d\n", rc);
  19541. + goto err_no_dma;
  19542. + }
  19543. +
  19544. + dev_info(&pdev->dev, "Load BCM2835 DMA engine driver\n");
  19545. +
  19546. + return 0;
  19547. +
  19548. +err_no_dma:
  19549. + bcm2835_dma_free(od);
  19550. + return rc;
  19551. +}
  19552. +
  19553. +static int bcm2835_dma_remove(struct platform_device *pdev)
  19554. +{
  19555. + struct bcm2835_dmadev *od = platform_get_drvdata(pdev);
  19556. +
  19557. + dma_async_device_unregister(&od->ddev);
  19558. + bcm2835_dma_free(od);
  19559. +
  19560. + return 0;
  19561. +}
  19562. +
  19563. +#ifndef CONFIG_OF
  19564. +
  19565. +
  19566. +static struct platform_driver bcm2835_dma_driver = {
  19567. + .probe = bcm2835_dma_probe,
  19568. + .remove = bcm2835_dma_remove,
  19569. + .driver = {
  19570. + .name = "bcm2708-dmaengine",
  19571. + .owner = THIS_MODULE,
  19572. + },
  19573. +};
  19574. +
  19575. +static struct platform_device *pdev;
  19576. +
  19577. +static const struct platform_device_info bcm2835_dma_dev_info = {
  19578. + .name = "bcm2708-dmaengine",
  19579. + .id = -1,
  19580. +};
  19581. +
  19582. +static int bcm2835_dma_init(void)
  19583. +{
  19584. + int rc = platform_driver_register(&bcm2835_dma_driver);
  19585. +
  19586. + if (rc == 0) {
  19587. + pdev = platform_device_register_full(&bcm2835_dma_dev_info);
  19588. + if (IS_ERR(pdev)) {
  19589. + platform_driver_unregister(&bcm2835_dma_driver);
  19590. + rc = PTR_ERR(pdev);
  19591. + }
  19592. + }
  19593. +
  19594. + return rc;
  19595. +}
  19596. +module_init(bcm2835_dma_init); /* preferable to subsys_initcall */
  19597. +
  19598. +static void __exit bcm2835_dma_exit(void)
  19599. +{
  19600. + platform_device_unregister(pdev);
  19601. + platform_driver_unregister(&bcm2835_dma_driver);
  19602. +}
  19603. +module_exit(bcm2835_dma_exit);
  19604. +
  19605. +#else
  19606. +
  19607. +static struct platform_driver bcm2835_dma_driver = {
  19608. + .probe = bcm2835_dma_probe,
  19609. + .remove = bcm2835_dma_remove,
  19610. + .driver = {
  19611. + .name = "bcm2835-dma",
  19612. + .owner = THIS_MODULE,
  19613. + .of_match_table = of_match_ptr(bcm2835_dma_of_match),
  19614. + },
  19615. +};
  19616. +
  19617. +module_platform_driver(bcm2835_dma_driver);
  19618. +
  19619. +#endif
  19620. +
  19621. +MODULE_ALIAS("platform:bcm2835-dma");
  19622. +MODULE_DESCRIPTION("BCM2835 DMA engine driver");
  19623. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  19624. +MODULE_AUTHOR("Gellert Weisz <gellert@raspberrypi.org>");
  19625. +MODULE_LICENSE("GPL v2");
  19626. diff -Nur linux-3.12.38/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  19627. --- linux-3.12.38/drivers/dma/Kconfig 2015-02-16 16:15:42.000000000 +0100
  19628. +++ linux-rpi/drivers/dma/Kconfig 2015-03-10 17:26:50.194216694 +0100
  19629. @@ -288,6 +288,12 @@
  19630. select DMA_ENGINE
  19631. select DMA_VIRTUAL_CHANNELS
  19632. +config DMA_BCM2708
  19633. + tristate "BCM2708 DMA engine support"
  19634. + depends on MACH_BCM2708
  19635. + select DMA_ENGINE
  19636. + select DMA_VIRTUAL_CHANNELS
  19637. +
  19638. config TI_CPPI41
  19639. tristate "AM33xx CPPI41 DMA support"
  19640. depends on ARCH_OMAP
  19641. diff -Nur linux-3.12.38/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  19642. --- linux-3.12.38/drivers/dma/Makefile 2015-02-16 16:15:42.000000000 +0100
  19643. +++ linux-rpi/drivers/dma/Makefile 2015-03-10 17:26:50.194216694 +0100
  19644. @@ -37,6 +37,7 @@
  19645. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  19646. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  19647. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  19648. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  19649. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  19650. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  19651. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  19652. diff -Nur linux-3.12.38/drivers/firmware/iscsi_ibft.c linux-rpi/drivers/firmware/iscsi_ibft.c
  19653. --- linux-3.12.38/drivers/firmware/iscsi_ibft.c 2015-02-16 16:15:42.000000000 +0100
  19654. +++ linux-rpi/drivers/firmware/iscsi_ibft.c 2015-03-10 17:26:50.210216694 +0100
  19655. @@ -756,7 +756,6 @@
  19656. */
  19657. { ACPI_SIG_IBFT },
  19658. { "iBFT" },
  19659. - { "BIFT" }, /* Broadcom iSCSI Offload */
  19660. };
  19661. static void __init acpi_find_ibft_region(void)
  19662. diff -Nur linux-3.12.38/drivers/gpio/gpiolib.c linux-rpi/drivers/gpio/gpiolib.c
  19663. --- linux-3.12.38/drivers/gpio/gpiolib.c 2015-02-16 16:15:42.000000000 +0100
  19664. +++ linux-rpi/drivers/gpio/gpiolib.c 2015-03-10 17:26:50.218216694 +0100
  19665. @@ -362,7 +362,7 @@
  19666. return status;
  19667. }
  19668. -static DEVICE_ATTR(value, 0644,
  19669. +static const DEVICE_ATTR(value, 0644,
  19670. gpio_value_show, gpio_value_store);
  19671. static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
  19672. @@ -580,16 +580,18 @@
  19673. return status ? : size;
  19674. }
  19675. -static DEVICE_ATTR(active_low, 0644,
  19676. +static const DEVICE_ATTR(active_low, 0644,
  19677. gpio_active_low_show, gpio_active_low_store);
  19678. -static struct attribute *gpio_attrs[] = {
  19679. +static const struct attribute *gpio_attrs[] = {
  19680. &dev_attr_value.attr,
  19681. &dev_attr_active_low.attr,
  19682. NULL,
  19683. };
  19684. -ATTRIBUTE_GROUPS(gpio);
  19685. +static const struct attribute_group gpio_attr_group = {
  19686. + .attrs = (struct attribute **) gpio_attrs,
  19687. +};
  19688. /*
  19689. * /sys/class/gpio/gpiochipN/
  19690. @@ -625,13 +627,16 @@
  19691. }
  19692. static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL);
  19693. -static struct attribute *gpiochip_attrs[] = {
  19694. +static const struct attribute *gpiochip_attrs[] = {
  19695. &dev_attr_base.attr,
  19696. &dev_attr_label.attr,
  19697. &dev_attr_ngpio.attr,
  19698. NULL,
  19699. };
  19700. -ATTRIBUTE_GROUPS(gpiochip);
  19701. +
  19702. +static const struct attribute_group gpiochip_attr_group = {
  19703. + .attrs = (struct attribute **) gpiochip_attrs,
  19704. +};
  19705. /*
  19706. * /sys/class/gpio/export ... write-only
  19707. @@ -786,15 +791,18 @@
  19708. if (desc->chip->names && desc->chip->names[offset])
  19709. ioname = desc->chip->names[offset];
  19710. - dev = device_create_with_groups(&gpio_class, desc->chip->dev,
  19711. - MKDEV(0, 0), desc, gpio_groups,
  19712. - ioname ? ioname : "gpio%u",
  19713. - desc_to_gpio(desc));
  19714. + dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0),
  19715. + desc, ioname ? ioname : "gpio%u",
  19716. + desc_to_gpio(desc));
  19717. if (IS_ERR(dev)) {
  19718. status = PTR_ERR(dev);
  19719. goto fail_unlock;
  19720. }
  19721. + status = sysfs_create_group(&dev->kobj, &gpio_attr_group);
  19722. + if (status)
  19723. + goto fail_unregister_device;
  19724. +
  19725. if (direction_may_change) {
  19726. status = device_create_file(dev, &dev_attr_direction);
  19727. if (status)
  19728. @@ -805,15 +813,13 @@
  19729. !test_bit(FLAG_IS_OUT, &desc->flags))) {
  19730. status = device_create_file(dev, &dev_attr_edge);
  19731. if (status)
  19732. - goto fail_remove_attr_direction;
  19733. + goto fail_unregister_device;
  19734. }
  19735. set_bit(FLAG_EXPORT, &desc->flags);
  19736. mutex_unlock(&sysfs_lock);
  19737. return 0;
  19738. -fail_remove_attr_direction:
  19739. - device_remove_file(dev, &dev_attr_direction);
  19740. fail_unregister_device:
  19741. device_unregister(dev);
  19742. fail_unlock:
  19743. @@ -864,7 +870,6 @@
  19744. if (tdev != NULL) {
  19745. status = sysfs_create_link(&dev->kobj, &tdev->kobj,
  19746. name);
  19747. - put_device(tdev);
  19748. } else {
  19749. status = -ENODEV;
  19750. }
  19751. @@ -918,7 +923,7 @@
  19752. }
  19753. status = sysfs_set_active_low(desc, dev, value);
  19754. - put_device(dev);
  19755. +
  19756. unlock:
  19757. mutex_unlock(&sysfs_lock);
  19758. @@ -966,8 +971,6 @@
  19759. mutex_unlock(&sysfs_lock);
  19760. if (dev) {
  19761. - device_remove_file(dev, &dev_attr_edge);
  19762. - device_remove_file(dev, &dev_attr_direction);
  19763. device_unregister(dev);
  19764. put_device(dev);
  19765. }
  19766. @@ -998,13 +1001,13 @@
  19767. /* use chip->base for the ID; it's already known to be unique */
  19768. mutex_lock(&sysfs_lock);
  19769. - dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0),
  19770. - chip, gpiochip_groups,
  19771. - "gpiochip%d", chip->base);
  19772. - if (IS_ERR(dev))
  19773. + dev = device_create(&gpio_class, chip->dev, MKDEV(0, 0), chip,
  19774. + "gpiochip%d", chip->base);
  19775. + if (!IS_ERR(dev)) {
  19776. + status = sysfs_create_group(&dev->kobj,
  19777. + &gpiochip_attr_group);
  19778. + } else
  19779. status = PTR_ERR(dev);
  19780. - else
  19781. - status = 0;
  19782. chip->exported = (status == 0);
  19783. mutex_unlock(&sysfs_lock);
  19784. @@ -1213,20 +1216,18 @@
  19785. spin_unlock_irqrestore(&gpio_lock, flags);
  19786. - if (status)
  19787. - goto fail;
  19788. -
  19789. #ifdef CONFIG_PINCTRL
  19790. INIT_LIST_HEAD(&chip->pin_ranges);
  19791. #endif
  19792. of_gpiochip_add(chip);
  19793. + if (status)
  19794. + goto fail;
  19795. +
  19796. status = gpiochip_export(chip);
  19797. - if (status) {
  19798. - of_gpiochip_remove(chip);
  19799. + if (status)
  19800. goto fail;
  19801. - }
  19802. pr_debug("gpiochip_add: registered GPIOs %d to %d on device: %s\n",
  19803. chip->base, chip->base + chip->ngpio - 1,
  19804. diff -Nur linux-3.12.38/drivers/gpio/gpiolib-of.c linux-rpi/drivers/gpio/gpiolib-of.c
  19805. --- linux-3.12.38/drivers/gpio/gpiolib-of.c 2015-02-16 16:15:42.000000000 +0100
  19806. +++ linux-rpi/drivers/gpio/gpiolib-of.c 2015-03-10 17:26:50.218216694 +0100
  19807. @@ -12,7 +12,6 @@
  19808. */
  19809. #include <linux/device.h>
  19810. -#include <linux/err.h>
  19811. #include <linux/errno.h>
  19812. #include <linux/module.h>
  19813. #include <linux/io.h>
  19814. @@ -43,14 +42,8 @@
  19815. return false;
  19816. ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags);
  19817. - if (ret < 0) {
  19818. - /* We've found the gpio chip, but the translation failed.
  19819. - * Return true to stop looking and return the translation
  19820. - * error via out_gpio
  19821. - */
  19822. - gg_data->out_gpio = ERR_PTR(ret);
  19823. - return true;
  19824. - }
  19825. + if (ret < 0)
  19826. + return false;
  19827. gg_data->out_gpio = ret + gc->base;
  19828. return true;
  19829. diff -Nur linux-3.12.38/drivers/gpu/drm/i915/i915_gem.c linux-rpi/drivers/gpu/drm/i915/i915_gem.c
  19830. --- linux-3.12.38/drivers/gpu/drm/i915/i915_gem.c 2015-02-16 16:15:42.000000000 +0100
  19831. +++ linux-rpi/drivers/gpu/drm/i915/i915_gem.c 2015-03-10 17:26:50.234216694 +0100
  19832. @@ -2788,13 +2788,6 @@
  19833. u32 size = i915_gem_obj_ggtt_size(obj);
  19834. uint64_t val;
  19835. - /* Adjust fence size to match tiled area */
  19836. - if (obj->tiling_mode != I915_TILING_NONE) {
  19837. - uint32_t row_size = obj->stride *
  19838. - (obj->tiling_mode == I915_TILING_Y ? 32 : 8);
  19839. - size = (size / row_size) * row_size;
  19840. - }
  19841. -
  19842. val = (uint64_t)((i915_gem_obj_ggtt_offset(obj) + size - 4096) &
  19843. 0xfffff000) << 32;
  19844. val |= i915_gem_obj_ggtt_offset(obj) & 0xfffff000;
  19845. @@ -4802,7 +4795,7 @@
  19846. if (!mutex_is_locked(mutex))
  19847. return false;
  19848. -#if defined(CONFIG_SMP) && !defined(CONFIG_DEBUG_MUTEXES)
  19849. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
  19850. return mutex->owner == task;
  19851. #else
  19852. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  19853. diff -Nur linux-3.12.38/drivers/gpu/drm/i915/i915_gem_stolen.c linux-rpi/drivers/gpu/drm/i915/i915_gem_stolen.c
  19854. --- linux-3.12.38/drivers/gpu/drm/i915/i915_gem_stolen.c 2015-02-16 16:15:42.000000000 +0100
  19855. +++ linux-rpi/drivers/gpu/drm/i915/i915_gem_stolen.c 2015-03-10 17:26:50.234216694 +0100
  19856. @@ -126,26 +126,9 @@
  19857. r = devm_request_mem_region(dev->dev, base, dev_priv->gtt.stolen_size,
  19858. "Graphics Stolen Memory");
  19859. if (r == NULL) {
  19860. - /*
  19861. - * One more attempt but this time requesting region from
  19862. - * base + 1, as we have seen that this resolves the region
  19863. - * conflict with the PCI Bus.
  19864. - * This is a BIOS w/a: Some BIOS wrap stolen in the root
  19865. - * PCI bus, but have an off-by-one error. Hence retry the
  19866. - * reservation starting from 1 instead of 0.
  19867. - */
  19868. - r = devm_request_mem_region(dev->dev, base + 1,
  19869. - dev_priv->gtt.stolen_size - 1,
  19870. - "Graphics Stolen Memory");
  19871. - /*
  19872. - * GEN3 firmware likes to smash pci bridges into the stolen
  19873. - * range. Apparently this works.
  19874. - */
  19875. - if (r == NULL && !IS_GEN3(dev)) {
  19876. - DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n",
  19877. - base, base + (uint32_t)dev_priv->gtt.stolen_size);
  19878. - base = 0;
  19879. - }
  19880. + DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n",
  19881. + base, base + (uint32_t)dev_priv->gtt.stolen_size);
  19882. + base = 0;
  19883. }
  19884. return base;
  19885. diff -Nur linux-3.12.38/drivers/gpu/drm/i915/i915_reg.h linux-rpi/drivers/gpu/drm/i915/i915_reg.h
  19886. --- linux-3.12.38/drivers/gpu/drm/i915/i915_reg.h 2015-02-16 16:15:42.000000000 +0100
  19887. +++ linux-rpi/drivers/gpu/drm/i915/i915_reg.h 2015-03-10 17:26:50.238216694 +0100
  19888. @@ -309,7 +309,6 @@
  19889. #define PIPE_CONTROL_GLOBAL_GTT_IVB (1<<24) /* gen7+ */
  19890. #define PIPE_CONTROL_CS_STALL (1<<20)
  19891. #define PIPE_CONTROL_TLB_INVALIDATE (1<<18)
  19892. -#define PIPE_CONTROL_MEDIA_STATE_CLEAR (1<<16)
  19893. #define PIPE_CONTROL_QW_WRITE (1<<14)
  19894. #define PIPE_CONTROL_DEPTH_STALL (1<<13)
  19895. #define PIPE_CONTROL_WRITE_FLUSH (1<<12)
  19896. diff -Nur linux-3.12.38/drivers/gpu/drm/i915/intel_ringbuffer.c linux-rpi/drivers/gpu/drm/i915/intel_ringbuffer.c
  19897. --- linux-3.12.38/drivers/gpu/drm/i915/intel_ringbuffer.c 2015-02-16 16:15:42.000000000 +0100
  19898. +++ linux-rpi/drivers/gpu/drm/i915/intel_ringbuffer.c 2015-03-10 17:26:50.242216694 +0100
  19899. @@ -322,15 +322,12 @@
  19900. flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE;
  19901. flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE;
  19902. flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE;
  19903. - flags |= PIPE_CONTROL_MEDIA_STATE_CLEAR;
  19904. /*
  19905. * TLB invalidate requires a post-sync write.
  19906. */
  19907. flags |= PIPE_CONTROL_QW_WRITE;
  19908. flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
  19909. - flags |= PIPE_CONTROL_STALL_AT_SCOREBOARD;
  19910. -
  19911. /* Workaround: we must issue a pipe_control with CS-stall bit
  19912. * set before a pipe_control command that has the state cache
  19913. * invalidate bit set. */
  19914. diff -Nur linux-3.12.38/drivers/gpu/drm/radeon/atombios_dp.c linux-rpi/drivers/gpu/drm/radeon/atombios_dp.c
  19915. --- linux-3.12.38/drivers/gpu/drm/radeon/atombios_dp.c 2015-02-16 16:15:42.000000000 +0100
  19916. +++ linux-rpi/drivers/gpu/drm/radeon/atombios_dp.c 2015-03-10 17:26:50.274216694 +0100
  19917. @@ -574,10 +574,6 @@
  19918. struct radeon_connector_atom_dig *dig_connector;
  19919. int dp_clock;
  19920. - if ((mode->clock > 340000) &&
  19921. - (!radeon_connector_is_dp12_capable(connector)))
  19922. - return MODE_CLOCK_HIGH;
  19923. -
  19924. if (!radeon_connector->con_priv)
  19925. return MODE_CLOCK_HIGH;
  19926. dig_connector = radeon_connector->con_priv;
  19927. diff -Nur linux-3.12.38/drivers/gpu/drm/radeon/ci_dpm.c linux-rpi/drivers/gpu/drm/radeon/ci_dpm.c
  19928. --- linux-3.12.38/drivers/gpu/drm/radeon/ci_dpm.c 2015-02-16 16:15:42.000000000 +0100
  19929. +++ linux-rpi/drivers/gpu/drm/radeon/ci_dpm.c 2015-03-10 17:26:50.274216694 +0100
  19930. @@ -4698,7 +4698,7 @@
  19931. ci_enable_spread_spectrum(rdev, false);
  19932. ci_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, false);
  19933. ci_stop_dpm(rdev);
  19934. - ci_enable_ds_master_switch(rdev, false);
  19935. + ci_enable_ds_master_switch(rdev, true);
  19936. ci_enable_ulv(rdev, false);
  19937. ci_clear_vc(rdev);
  19938. ci_reset_to_default(rdev);
  19939. diff -Nur linux-3.12.38/drivers/gpu/drm/radeon/cik.c linux-rpi/drivers/gpu/drm/radeon/cik.c
  19940. --- linux-3.12.38/drivers/gpu/drm/radeon/cik.c 2015-02-16 16:15:42.000000000 +0100
  19941. +++ linux-rpi/drivers/gpu/drm/radeon/cik.c 2015-03-10 17:26:50.278216694 +0100
  19942. @@ -5167,7 +5167,6 @@
  19943. }
  19944. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  19945. - data |= 0x00000001;
  19946. data &= 0xfffffffd;
  19947. if (orig != data)
  19948. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  19949. @@ -5199,7 +5198,7 @@
  19950. }
  19951. } else {
  19952. orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
  19953. - data |= 0x00000003;
  19954. + data |= 0x00000002;
  19955. if (orig != data)
  19956. WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
  19957. diff -Nur linux-3.12.38/drivers/gpu/drm/radeon/radeon_ttm.c linux-rpi/drivers/gpu/drm/radeon/radeon_ttm.c
  19958. --- linux-3.12.38/drivers/gpu/drm/radeon/radeon_ttm.c 2015-02-16 16:15:42.000000000 +0100
  19959. +++ linux-rpi/drivers/gpu/drm/radeon/radeon_ttm.c 2015-03-10 17:26:50.294216694 +0100
  19960. @@ -189,7 +189,7 @@
  19961. rbo = container_of(bo, struct radeon_bo, tbo);
  19962. switch (bo->mem.mem_type) {
  19963. case TTM_PL_VRAM:
  19964. - if (rbo->rdev->ring[radeon_copy_ring_index(rbo->rdev)].ready == false)
  19965. + if (rbo->rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready == false)
  19966. radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_CPU);
  19967. else
  19968. radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);
  19969. diff -Nur linux-3.12.38/drivers/gpu/drm/radeon/si_dpm.c linux-rpi/drivers/gpu/drm/radeon/si_dpm.c
  19970. --- linux-3.12.38/drivers/gpu/drm/radeon/si_dpm.c 2015-02-16 16:15:42.000000000 +0100
  19971. +++ linux-rpi/drivers/gpu/drm/radeon/si_dpm.c 2015-03-10 17:26:50.298216694 +0100
  19972. @@ -2901,22 +2901,6 @@
  19973. return ret;
  19974. }
  19975. -struct si_dpm_quirk {
  19976. - u32 chip_vendor;
  19977. - u32 chip_device;
  19978. - u32 subsys_vendor;
  19979. - u32 subsys_device;
  19980. - u32 max_sclk;
  19981. - u32 max_mclk;
  19982. -};
  19983. -
  19984. -/* cards with dpm stability problems */
  19985. -static struct si_dpm_quirk si_dpm_quirk_list[] = {
  19986. - /* PITCAIRN - https://bugs.freedesktop.org/show_bug.cgi?id=76490 */
  19987. - { PCI_VENDOR_ID_ATI, 0x6810, 0x1462, 0x3036, 0, 120000 },
  19988. - { 0, 0, 0, 0 },
  19989. -};
  19990. -
  19991. static void si_apply_state_adjust_rules(struct radeon_device *rdev,
  19992. struct radeon_ps *rps)
  19993. {
  19994. @@ -2927,22 +2911,7 @@
  19995. u32 mclk, sclk;
  19996. u16 vddc, vddci;
  19997. u32 max_sclk_vddc, max_mclk_vddci, max_mclk_vddc;
  19998. - u32 max_sclk = 0, max_mclk = 0;
  19999. int i;
  20000. - struct si_dpm_quirk *p = si_dpm_quirk_list;
  20001. -
  20002. - /* Apply dpm quirks */
  20003. - while (p && p->chip_device != 0) {
  20004. - if (rdev->pdev->vendor == p->chip_vendor &&
  20005. - rdev->pdev->device == p->chip_device &&
  20006. - rdev->pdev->subsystem_vendor == p->subsys_vendor &&
  20007. - rdev->pdev->subsystem_device == p->subsys_device) {
  20008. - max_sclk = p->max_sclk;
  20009. - max_mclk = p->max_mclk;
  20010. - break;
  20011. - }
  20012. - ++p;
  20013. - }
  20014. if ((rdev->pm.dpm.new_active_crtc_count > 1) ||
  20015. ni_dpm_vblank_too_short(rdev))
  20016. @@ -2996,14 +2965,6 @@
  20017. if (ps->performance_levels[i].mclk > max_mclk_vddc)
  20018. ps->performance_levels[i].mclk = max_mclk_vddc;
  20019. }
  20020. - if (max_mclk) {
  20021. - if (ps->performance_levels[i].mclk > max_mclk)
  20022. - ps->performance_levels[i].mclk = max_mclk;
  20023. - }
  20024. - if (max_sclk) {
  20025. - if (ps->performance_levels[i].sclk > max_sclk)
  20026. - ps->performance_levels[i].sclk = max_sclk;
  20027. - }
  20028. }
  20029. /* XXX validate the min clocks required for display */
  20030. diff -Nur linux-3.12.38/drivers/gpu/drm/ttm/ttm_page_alloc.c linux-rpi/drivers/gpu/drm/ttm/ttm_page_alloc.c
  20031. --- linux-3.12.38/drivers/gpu/drm/ttm/ttm_page_alloc.c 2015-02-16 16:15:42.000000000 +0100
  20032. +++ linux-rpi/drivers/gpu/drm/ttm/ttm_page_alloc.c 2015-03-10 17:26:50.302216694 +0100
  20033. @@ -297,12 +297,11 @@
  20034. *
  20035. * @pool: to free the pages from
  20036. * @free_all: If set to true will free all pages in pool
  20037. - * @use_static: Safe to use static buffer
  20038. + * @gfp: GFP flags.
  20039. **/
  20040. static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
  20041. - bool use_static)
  20042. + gfp_t gfp)
  20043. {
  20044. - static struct page *static_buf[NUM_PAGES_TO_ALLOC];
  20045. unsigned long irq_flags;
  20046. struct page *p;
  20047. struct page **pages_to_free;
  20048. @@ -312,11 +311,7 @@
  20049. if (NUM_PAGES_TO_ALLOC < nr_free)
  20050. npages_to_free = NUM_PAGES_TO_ALLOC;
  20051. - if (use_static)
  20052. - pages_to_free = static_buf;
  20053. - else
  20054. - pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
  20055. - GFP_KERNEL);
  20056. + pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), gfp);
  20057. if (!pages_to_free) {
  20058. pr_err("Failed to allocate memory for pool free operation\n");
  20059. return 0;
  20060. @@ -379,8 +374,7 @@
  20061. if (freed_pages)
  20062. ttm_pages_put(pages_to_free, freed_pages);
  20063. out:
  20064. - if (pages_to_free != static_buf)
  20065. - kfree(pages_to_free);
  20066. + kfree(pages_to_free);
  20067. return nr_free;
  20068. }
  20069. @@ -389,6 +383,8 @@
  20070. *
  20071. * XXX: (dchinner) Deadlock warning!
  20072. *
  20073. + * We need to pass sc->gfp_mask to ttm_page_pool_free().
  20074. + *
  20075. * This code is crying out for a shrinker per pool....
  20076. */
  20077. static unsigned long
  20078. @@ -411,8 +407,8 @@
  20079. if (shrink_pages == 0)
  20080. break;
  20081. pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
  20082. - /* OK to use static buffer since global mutex is held. */
  20083. - shrink_pages = ttm_page_pool_free(pool, nr_free, true);
  20084. + shrink_pages = ttm_page_pool_free(pool, nr_free,
  20085. + sc->gfp_mask);
  20086. freed += nr_free - shrink_pages;
  20087. }
  20088. mutex_unlock(&lock);
  20089. @@ -714,7 +710,7 @@
  20090. }
  20091. spin_unlock_irqrestore(&pool->lock, irq_flags);
  20092. if (npages)
  20093. - ttm_page_pool_free(pool, npages, false);
  20094. + ttm_page_pool_free(pool, npages, GFP_KERNEL);
  20095. }
  20096. /*
  20097. @@ -853,9 +849,9 @@
  20098. pr_info("Finalizing pool allocator\n");
  20099. ttm_pool_mm_shrink_fini(_manager);
  20100. - /* OK to use static buffer since global mutex is no longer used. */
  20101. for (i = 0; i < NUM_POOLS; ++i)
  20102. - ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, true);
  20103. + ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES,
  20104. + GFP_KERNEL);
  20105. kobject_put(&_manager->kobj);
  20106. _manager = NULL;
  20107. diff -Nur linux-3.12.38/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c linux-rpi/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
  20108. --- linux-3.12.38/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c 2015-02-16 16:15:42.000000000 +0100
  20109. +++ linux-rpi/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c 2015-03-10 17:26:50.302216694 +0100
  20110. @@ -410,12 +410,11 @@
  20111. *
  20112. * @pool: to free the pages from
  20113. * @nr_free: If set to true will free all pages in pool
  20114. - * @use_static: Safe to use static buffer
  20115. + * @gfp: GFP flags.
  20116. **/
  20117. static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
  20118. - bool use_static)
  20119. + gfp_t gfp)
  20120. {
  20121. - static struct page *static_buf[NUM_PAGES_TO_ALLOC];
  20122. unsigned long irq_flags;
  20123. struct dma_page *dma_p, *tmp;
  20124. struct page **pages_to_free;
  20125. @@ -432,11 +431,7 @@
  20126. npages_to_free, nr_free);
  20127. }
  20128. #endif
  20129. - if (use_static)
  20130. - pages_to_free = static_buf;
  20131. - else
  20132. - pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
  20133. - GFP_KERNEL);
  20134. + pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), gfp);
  20135. if (!pages_to_free) {
  20136. pr_err("%s: Failed to allocate memory for pool free operation\n",
  20137. @@ -506,8 +501,7 @@
  20138. if (freed_pages)
  20139. ttm_dma_pages_put(pool, &d_pages, pages_to_free, freed_pages);
  20140. out:
  20141. - if (pages_to_free != static_buf)
  20142. - kfree(pages_to_free);
  20143. + kfree(pages_to_free);
  20144. return nr_free;
  20145. }
  20146. @@ -536,8 +530,7 @@
  20147. if (pool->type != type)
  20148. continue;
  20149. /* Takes a spinlock.. */
  20150. - /* OK to use static buffer since global mutex is held. */
  20151. - ttm_dma_page_pool_free(pool, FREE_ALL_PAGES, true);
  20152. + ttm_dma_page_pool_free(pool, FREE_ALL_PAGES, GFP_KERNEL);
  20153. WARN_ON(((pool->npages_in_use + pool->npages_free) != 0));
  20154. /* This code path is called after _all_ references to the
  20155. * struct device has been dropped - so nobody should be
  20156. @@ -990,7 +983,7 @@
  20157. /* shrink pool if necessary (only on !is_cached pools)*/
  20158. if (npages)
  20159. - ttm_dma_page_pool_free(pool, npages, false);
  20160. + ttm_dma_page_pool_free(pool, npages, GFP_KERNEL);
  20161. ttm->state = tt_unpopulated;
  20162. }
  20163. EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
  20164. @@ -1000,6 +993,8 @@
  20165. *
  20166. * XXX: (dchinner) Deadlock warning!
  20167. *
  20168. + * We need to pass sc->gfp_mask to ttm_dma_page_pool_free().
  20169. + *
  20170. * I'm getting sadder as I hear more pathetical whimpers about needing per-pool
  20171. * shrinkers
  20172. */
  20173. @@ -1032,8 +1027,8 @@
  20174. if (++idx < pool_offset)
  20175. continue;
  20176. nr_free = shrink_pages;
  20177. - /* OK to use static buffer since global mutex is held. */
  20178. - shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
  20179. + shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free,
  20180. + sc->gfp_mask);
  20181. freed += nr_free - shrink_pages;
  20182. pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
  20183. diff -Nur linux-3.12.38/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c linux-rpi/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
  20184. --- linux-3.12.38/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2015-02-16 16:15:42.000000000 +0100
  20185. +++ linux-rpi/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2015-03-10 17:26:50.306216693 +0100
  20186. @@ -1049,8 +1049,6 @@
  20187. if (ret != 0)
  20188. goto out_no_queue;
  20189. - return 0;
  20190. -
  20191. out_no_queue:
  20192. event->base.destroy(&event->base);
  20193. out_no_event:
  20194. @@ -1125,10 +1123,17 @@
  20195. BUG_ON(fence == NULL);
  20196. - ret = vmw_event_fence_action_create(file_priv, fence,
  20197. - arg->flags,
  20198. - arg->user_data,
  20199. - true);
  20200. + if (arg->flags & DRM_VMW_FE_FLAG_REQ_TIME)
  20201. + ret = vmw_event_fence_action_create(file_priv, fence,
  20202. + arg->flags,
  20203. + arg->user_data,
  20204. + true);
  20205. + else
  20206. + ret = vmw_event_fence_action_create(file_priv, fence,
  20207. + arg->flags,
  20208. + arg->user_data,
  20209. + true);
  20210. +
  20211. if (unlikely(ret != 0)) {
  20212. if (ret != -ERESTARTSYS)
  20213. DRM_ERROR("Failed to attach event to fence.\n");
  20214. diff -Nur linux-3.12.38/drivers/hid/hid-core.c linux-rpi/drivers/hid/hid-core.c
  20215. --- linux-3.12.38/drivers/hid/hid-core.c 2015-02-16 16:15:42.000000000 +0100
  20216. +++ linux-rpi/drivers/hid/hid-core.c 2015-03-10 17:26:50.310216693 +0100
  20217. @@ -1743,7 +1743,6 @@
  20218. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  20219. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  20220. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  20221. - { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
  20222. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  20223. { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
  20224. { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
  20225. diff -Nur linux-3.12.38/drivers/hid/hid-ids.h linux-rpi/drivers/hid/hid-ids.h
  20226. --- linux-3.12.38/drivers/hid/hid-ids.h 2015-02-16 16:15:42.000000000 +0100
  20227. +++ linux-rpi/drivers/hid/hid-ids.h 2015-03-10 17:26:50.310216693 +0100
  20228. @@ -501,7 +501,6 @@
  20229. #define USB_DEVICE_ID_KYE_GPEN_560 0x5003
  20230. #define USB_DEVICE_ID_KYE_EASYPEN_I405X 0x5010
  20231. #define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011
  20232. -#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2 0x501a
  20233. #define USB_DEVICE_ID_KYE_EASYPEN_M610X 0x5013
  20234. #define USB_VENDOR_ID_LABTEC 0x1020
  20235. diff -Nur linux-3.12.38/drivers/hid/hid-input.c linux-rpi/drivers/hid/hid-input.c
  20236. --- linux-3.12.38/drivers/hid/hid-input.c 2015-02-16 16:15:42.000000000 +0100
  20237. +++ linux-rpi/drivers/hid/hid-input.c 2015-03-10 17:26:50.310216693 +0100
  20238. @@ -312,9 +312,6 @@
  20239. USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
  20240. HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
  20241. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  20242. - USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
  20243. - HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
  20244. - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
  20245. USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
  20246. HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE },
  20247. {}
  20248. diff -Nur linux-3.12.38/drivers/hid/hid-kye.c linux-rpi/drivers/hid/hid-kye.c
  20249. --- linux-3.12.38/drivers/hid/hid-kye.c 2015-02-16 16:15:42.000000000 +0100
  20250. +++ linux-rpi/drivers/hid/hid-kye.c 2015-03-10 17:26:50.310216693 +0100
  20251. @@ -323,7 +323,6 @@
  20252. }
  20253. break;
  20254. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  20255. - case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
  20256. if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
  20257. rdesc = mousepen_i608x_rdesc_fixed;
  20258. *rsize = sizeof(mousepen_i608x_rdesc_fixed);
  20259. @@ -416,7 +415,6 @@
  20260. switch (id->product) {
  20261. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  20262. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  20263. - case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
  20264. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  20265. ret = kye_tablet_enable(hdev);
  20266. if (ret) {
  20267. @@ -440,8 +438,6 @@
  20268. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  20269. USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  20270. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  20271. - USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
  20272. - { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  20273. USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  20274. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  20275. USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
  20276. diff -Nur linux-3.12.38/drivers/hid/hid-roccat-pyra.c linux-rpi/drivers/hid/hid-roccat-pyra.c
  20277. --- linux-3.12.38/drivers/hid/hid-roccat-pyra.c 2015-02-16 16:15:42.000000000 +0100
  20278. +++ linux-rpi/drivers/hid/hid-roccat-pyra.c 2015-03-10 17:26:50.314216693 +0100
  20279. @@ -35,8 +35,6 @@
  20280. static void profile_activated(struct pyra_device *pyra,
  20281. unsigned int new_profile)
  20282. {
  20283. - if (new_profile >= ARRAY_SIZE(pyra->profile_settings))
  20284. - return;
  20285. pyra->actual_profile = new_profile;
  20286. pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi;
  20287. }
  20288. @@ -259,12 +257,10 @@
  20289. if (off != 0 || count != PYRA_SIZE_SETTINGS)
  20290. return -EINVAL;
  20291. - settings = (struct pyra_settings const *)buf;
  20292. - if (settings->startup_profile >= ARRAY_SIZE(pyra->profile_settings))
  20293. - return -EINVAL;
  20294. -
  20295. mutex_lock(&pyra->pyra_lock);
  20296. + settings = (struct pyra_settings const *)buf;
  20297. +
  20298. retval = pyra_set_settings(usb_dev, settings);
  20299. if (retval) {
  20300. mutex_unlock(&pyra->pyra_lock);
  20301. diff -Nur linux-3.12.38/drivers/hid/i2c-hid/i2c-hid.c linux-rpi/drivers/hid/i2c-hid/i2c-hid.c
  20302. --- linux-3.12.38/drivers/hid/i2c-hid/i2c-hid.c 2015-02-16 16:15:42.000000000 +0100
  20303. +++ linux-rpi/drivers/hid/i2c-hid/i2c-hid.c 2015-03-10 17:26:50.314216693 +0100
  20304. @@ -136,7 +136,6 @@
  20305. * descriptor. */
  20306. unsigned int bufsize; /* i2c buffer size */
  20307. char *inbuf; /* Input buffer */
  20308. - char *rawbuf; /* Raw Input buffer */
  20309. char *cmdbuf; /* Command buffer */
  20310. char *argsbuf; /* Command arguments buffer */
  20311. @@ -356,7 +355,7 @@
  20312. static void i2c_hid_get_input(struct i2c_hid *ihid)
  20313. {
  20314. int ret, ret_size;
  20315. - int size = ihid->bufsize;
  20316. + int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
  20317. ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
  20318. if (ret != size) {
  20319. @@ -487,11 +486,9 @@
  20320. static void i2c_hid_free_buffers(struct i2c_hid *ihid)
  20321. {
  20322. kfree(ihid->inbuf);
  20323. - kfree(ihid->rawbuf);
  20324. kfree(ihid->argsbuf);
  20325. kfree(ihid->cmdbuf);
  20326. ihid->inbuf = NULL;
  20327. - ihid->rawbuf = NULL;
  20328. ihid->cmdbuf = NULL;
  20329. ihid->argsbuf = NULL;
  20330. ihid->bufsize = 0;
  20331. @@ -507,11 +504,10 @@
  20332. report_size; /* report */
  20333. ihid->inbuf = kzalloc(report_size, GFP_KERNEL);
  20334. - ihid->rawbuf = kzalloc(report_size, GFP_KERNEL);
  20335. ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
  20336. ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);
  20337. - if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) {
  20338. + if (!ihid->inbuf || !ihid->argsbuf || !ihid->cmdbuf) {
  20339. i2c_hid_free_buffers(ihid);
  20340. return -ENOMEM;
  20341. }
  20342. @@ -538,12 +534,12 @@
  20343. ret = i2c_hid_get_report(client,
  20344. report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
  20345. - report_number, ihid->rawbuf, ask_count);
  20346. + report_number, ihid->inbuf, ask_count);
  20347. if (ret < 0)
  20348. return ret;
  20349. - ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8);
  20350. + ret_count = ihid->inbuf[0] | (ihid->inbuf[1] << 8);
  20351. if (ret_count <= 2)
  20352. return 0;
  20353. @@ -552,7 +548,7 @@
  20354. /* The query buffer contains the size, dropping it in the reply */
  20355. count = min(count, ret_count - 2);
  20356. - memcpy(buf, ihid->rawbuf + 2, count);
  20357. + memcpy(buf, ihid->inbuf + 2, count);
  20358. return count;
  20359. }
  20360. diff -Nur linux-3.12.38/drivers/hid/usbhid/hid-core.c linux-rpi/drivers/hid/usbhid/hid-core.c
  20361. --- linux-3.12.38/drivers/hid/usbhid/hid-core.c 2015-02-16 16:15:42.000000000 +0100
  20362. +++ linux-rpi/drivers/hid/usbhid/hid-core.c 2015-03-10 17:26:50.314216693 +0100
  20363. @@ -49,7 +49,7 @@
  20364. * Module parameters.
  20365. */
  20366. -static unsigned int hid_mousepoll_interval;
  20367. +static unsigned int hid_mousepoll_interval = ~0;
  20368. module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
  20369. MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
  20370. @@ -1081,8 +1081,12 @@
  20371. }
  20372. /* Change the polling interval of mice. */
  20373. - if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
  20374. - interval = hid_mousepoll_interval;
  20375. + if (hid->collection->usage == HID_GD_MOUSE) {
  20376. + if (hid_mousepoll_interval == ~0 && interval < 16)
  20377. + interval = 16;
  20378. + else if (hid_mousepoll_interval != ~0 && hid_mousepoll_interval != 0)
  20379. + interval = hid_mousepoll_interval;
  20380. + }
  20381. ret = -ENOMEM;
  20382. if (usb_endpoint_dir_in(endpoint)) {
  20383. diff -Nur linux-3.12.38/drivers/hid/usbhid/hid-quirks.c linux-rpi/drivers/hid/usbhid/hid-quirks.c
  20384. --- linux-3.12.38/drivers/hid/usbhid/hid-quirks.c 2015-02-16 16:15:42.000000000 +0100
  20385. +++ linux-rpi/drivers/hid/usbhid/hid-quirks.c 2015-03-10 17:26:50.314216693 +0100
  20386. @@ -119,7 +119,6 @@
  20387. { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS, HID_QUIRK_MULTI_INPUT },
  20388. { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS },
  20389. { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
  20390. - { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2, HID_QUIRK_MULTI_INPUT },
  20391. { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
  20392. { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
  20393. { USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD, HID_QUIRK_NO_INIT_REPORTS },
  20394. diff -Nur linux-3.12.38/drivers/hv/channel_mgmt.c linux-rpi/drivers/hv/channel_mgmt.c
  20395. --- linux-3.12.38/drivers/hv/channel_mgmt.c 2015-02-16 16:15:42.000000000 +0100
  20396. +++ linux-rpi/drivers/hv/channel_mgmt.c 2015-03-10 17:26:50.314216693 +0100
  20397. @@ -202,16 +202,9 @@
  20398. unsigned long flags;
  20399. struct vmbus_channel *primary_channel;
  20400. struct vmbus_channel_relid_released msg;
  20401. - struct device *dev;
  20402. -
  20403. - if (channel->device_obj) {
  20404. - dev = get_device(&channel->device_obj->device);
  20405. - if (dev) {
  20406. - vmbus_device_unregister(channel->device_obj);
  20407. - put_device(dev);
  20408. - }
  20409. - }
  20410. + if (channel->device_obj)
  20411. + vmbus_device_unregister(channel->device_obj);
  20412. memset(&msg, 0, sizeof(struct vmbus_channel_relid_released));
  20413. msg.child_relid = channel->offermsg.child_relid;
  20414. msg.header.msgtype = CHANNELMSG_RELID_RELEASED;
  20415. diff -Nur linux-3.12.38/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  20416. --- linux-3.12.38/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  20417. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2015-03-09 10:39:30.290893736 +0100
  20418. @@ -0,0 +1,219 @@
  20419. +/*****************************************************************************
  20420. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  20421. +*
  20422. +* Unless you and Broadcom execute a separate written software license
  20423. +* agreement governing use of this software, this software is licensed to you
  20424. +* under the terms of the GNU General Public License version 2, available at
  20425. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  20426. +*
  20427. +* Notwithstanding the above, under no circumstances may you combine this
  20428. +* software in any way with any other Broadcom software provided under a
  20429. +* license other than the GPL, without Broadcom's express prior written
  20430. +* consent.
  20431. +*****************************************************************************/
  20432. +
  20433. +#include <linux/kernel.h>
  20434. +#include <linux/module.h>
  20435. +#include <linux/init.h>
  20436. +#include <linux/hwmon.h>
  20437. +#include <linux/hwmon-sysfs.h>
  20438. +#include <linux/platform_device.h>
  20439. +#include <linux/sysfs.h>
  20440. +#include <mach/vcio.h>
  20441. +#include <linux/slab.h>
  20442. +#include <linux/err.h>
  20443. +
  20444. +#define MODULE_NAME "bcm2835_hwmon"
  20445. +
  20446. +/*#define HWMON_DEBUG_ENABLE*/
  20447. +
  20448. +#ifdef HWMON_DEBUG_ENABLE
  20449. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  20450. +#else
  20451. +#define print_debug(fmt,...)
  20452. +#endif
  20453. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  20454. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  20455. +
  20456. +#define VC_TAG_GET_TEMP 0x00030006
  20457. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  20458. +
  20459. +/* --- STRUCTS --- */
  20460. +struct bcm2835_hwmon_data {
  20461. + struct device *hwmon_dev;
  20462. +};
  20463. +
  20464. +/* tag part of the message */
  20465. +struct vc_msg_tag {
  20466. + uint32_t tag_id; /* the tag ID for the temperature */
  20467. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  20468. + uint32_t request_code; /* identifies message as a request (should be 0) */
  20469. + uint32_t id; /* extra ID field (should be 0) */
  20470. + uint32_t val; /* returned value of the temperature */
  20471. +};
  20472. +
  20473. +/* message structure to be sent to videocore */
  20474. +struct vc_msg {
  20475. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  20476. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  20477. + struct vc_msg_tag tag; /* the tag structure above to make */
  20478. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  20479. +};
  20480. +
  20481. +typedef enum {
  20482. + TEMP,
  20483. + MAX_TEMP,
  20484. +} temp_type;
  20485. +
  20486. +/* --- PROTOTYPES --- */
  20487. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  20488. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  20489. +
  20490. +/* --- GLOBALS --- */
  20491. +
  20492. +static struct bcm2835_hwmon_data *bcm2835_data;
  20493. +static struct platform_driver bcm2835_hwmon_driver;
  20494. +
  20495. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  20496. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  20497. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  20498. +
  20499. +static struct attribute* bcm2835_attributes[] = {
  20500. + &sensor_dev_attr_name.dev_attr.attr,
  20501. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  20502. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  20503. + NULL,
  20504. +};
  20505. +
  20506. +static struct attribute_group bcm2835_attr_group = {
  20507. + .attrs = bcm2835_attributes,
  20508. +};
  20509. +
  20510. +/* --- FUNCTIONS --- */
  20511. +
  20512. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  20513. +{
  20514. + return sprintf(buf,"bcm2835_hwmon\n");
  20515. +}
  20516. +
  20517. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  20518. +{
  20519. + struct vc_msg msg;
  20520. + int result;
  20521. + uint temp = 0;
  20522. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  20523. +
  20524. + print_debug("IN");
  20525. +
  20526. + /* wipe all previous message data */
  20527. + memset(&msg, 0, sizeof msg);
  20528. +
  20529. + /* determine the message type */
  20530. + if(index == TEMP)
  20531. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  20532. + else if (index == MAX_TEMP)
  20533. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  20534. + else
  20535. + {
  20536. + print_debug("Unknown temperature message!");
  20537. + return -EINVAL;
  20538. + }
  20539. +
  20540. + msg.msg_size = sizeof msg;
  20541. + msg.tag.buffer_size = 8;
  20542. +
  20543. + /* send the message */
  20544. + result = bcm_mailbox_property(&msg, sizeof msg);
  20545. +
  20546. + /* check if it was all ok and return the rate in milli degrees C */
  20547. + if (result == 0 && (msg.request_code & 0x80000000))
  20548. + temp = (uint)msg.tag.val;
  20549. + #ifdef HWMON_DEBUG_ENABLE
  20550. + else
  20551. + print_debug("Failed to get temperature!");
  20552. + #endif
  20553. + print_debug("Got temperature as %u",temp);
  20554. + print_debug("OUT");
  20555. + return sprintf(buf, "%u\n", temp);
  20556. +}
  20557. +
  20558. +
  20559. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  20560. +{
  20561. + int err;
  20562. +
  20563. + print_debug("IN");
  20564. + print_debug("HWMON Driver has been probed!");
  20565. +
  20566. + /* check that the device isn't null!*/
  20567. + if(pdev == NULL)
  20568. + {
  20569. + print_debug("Platform device is empty!");
  20570. + return -ENODEV;
  20571. + }
  20572. +
  20573. + /* allocate memory for neccessary data */
  20574. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  20575. + if(!bcm2835_data)
  20576. + {
  20577. + print_debug("Unable to allocate memory for hwmon data!");
  20578. + err = -ENOMEM;
  20579. + goto kzalloc_error;
  20580. + }
  20581. +
  20582. + /* create the sysfs files */
  20583. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  20584. + {
  20585. + print_debug("Unable to create sysfs files!");
  20586. + err = -EFAULT;
  20587. + goto sysfs_error;
  20588. + }
  20589. +
  20590. + /* register the hwmon device */
  20591. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  20592. + if (IS_ERR(bcm2835_data->hwmon_dev))
  20593. + {
  20594. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  20595. + goto hwmon_error;
  20596. + }
  20597. + print_debug("OUT");
  20598. + return 0;
  20599. +
  20600. + /* error goto's */
  20601. + hwmon_error:
  20602. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  20603. +
  20604. + sysfs_error:
  20605. + kfree(bcm2835_data);
  20606. +
  20607. + kzalloc_error:
  20608. +
  20609. + return err;
  20610. +
  20611. +}
  20612. +
  20613. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  20614. +{
  20615. + print_debug("IN");
  20616. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  20617. +
  20618. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  20619. + print_debug("OUT");
  20620. + return 0;
  20621. +}
  20622. +
  20623. +/* Hwmon Driver */
  20624. +static struct platform_driver bcm2835_hwmon_driver = {
  20625. + .probe = bcm2835_hwmon_probe,
  20626. + .remove = bcm2835_hwmon_remove,
  20627. + .driver = {
  20628. + .name = "bcm2835_hwmon",
  20629. + .owner = THIS_MODULE,
  20630. + },
  20631. +};
  20632. +
  20633. +MODULE_LICENSE("GPL");
  20634. +MODULE_AUTHOR("Dorian Peake");
  20635. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  20636. +
  20637. +module_platform_driver(bcm2835_hwmon_driver);
  20638. diff -Nur linux-3.12.38/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  20639. --- linux-3.12.38/drivers/hwmon/Kconfig 2015-02-16 16:15:42.000000000 +0100
  20640. +++ linux-rpi/drivers/hwmon/Kconfig 2015-03-10 17:26:50.314216693 +0100
  20641. @@ -1553,6 +1553,16 @@
  20642. help
  20643. Support for the A/D converter on MC13783 and MC13892 PMIC.
  20644. +config SENSORS_BCM2835
  20645. + depends on THERMAL_BCM2835=n
  20646. + tristate "Broadcom BCM2835 HWMON Driver"
  20647. + help
  20648. + If you say yes here you get support for the hardware
  20649. + monitoring features of the BCM2835 Chip
  20650. +
  20651. + This driver can also be built as a module. If so, the module
  20652. + will be called bcm2835-hwmon.
  20653. +
  20654. if ACPI
  20655. comment "ACPI drivers"
  20656. diff -Nur linux-3.12.38/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  20657. --- linux-3.12.38/drivers/hwmon/Makefile 2015-02-16 16:15:42.000000000 +0100
  20658. +++ linux-rpi/drivers/hwmon/Makefile 2015-03-10 17:26:50.314216693 +0100
  20659. @@ -142,6 +142,7 @@
  20660. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  20661. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  20662. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  20663. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  20664. obj-$(CONFIG_PMBUS) += pmbus/
  20665. diff -Nur linux-3.12.38/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  20666. --- linux-3.12.38/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  20667. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2015-03-10 17:26:50.334216693 +0100
  20668. @@ -0,0 +1,489 @@
  20669. +/*
  20670. + * Driver for Broadcom BCM2708 BSC Controllers
  20671. + *
  20672. + * Copyright (C) 2012 Chris Boot & Frank Buss
  20673. + *
  20674. + * This driver is inspired by:
  20675. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  20676. + *
  20677. + * This program is free software; you can redistribute it and/or modify
  20678. + * it under the terms of the GNU General Public License as published by
  20679. + * the Free Software Foundation; either version 2 of the License, or
  20680. + * (at your option) any later version.
  20681. + *
  20682. + * This program is distributed in the hope that it will be useful,
  20683. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20684. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20685. + * GNU General Public License for more details.
  20686. + *
  20687. + * You should have received a copy of the GNU General Public License
  20688. + * along with this program; if not, write to the Free Software
  20689. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20690. + */
  20691. +
  20692. +#include <linux/kernel.h>
  20693. +#include <linux/module.h>
  20694. +#include <linux/spinlock.h>
  20695. +#include <linux/clk.h>
  20696. +#include <linux/err.h>
  20697. +#include <linux/platform_device.h>
  20698. +#include <linux/io.h>
  20699. +#include <linux/slab.h>
  20700. +#include <linux/i2c.h>
  20701. +#include <linux/interrupt.h>
  20702. +#include <linux/sched.h>
  20703. +#include <linux/wait.h>
  20704. +
  20705. +/* BSC register offsets */
  20706. +#define BSC_C 0x00
  20707. +#define BSC_S 0x04
  20708. +#define BSC_DLEN 0x08
  20709. +#define BSC_A 0x0c
  20710. +#define BSC_FIFO 0x10
  20711. +#define BSC_DIV 0x14
  20712. +#define BSC_DEL 0x18
  20713. +#define BSC_CLKT 0x1c
  20714. +
  20715. +/* Bitfields in BSC_C */
  20716. +#define BSC_C_I2CEN 0x00008000
  20717. +#define BSC_C_INTR 0x00000400
  20718. +#define BSC_C_INTT 0x00000200
  20719. +#define BSC_C_INTD 0x00000100
  20720. +#define BSC_C_ST 0x00000080
  20721. +#define BSC_C_CLEAR_1 0x00000020
  20722. +#define BSC_C_CLEAR_2 0x00000010
  20723. +#define BSC_C_READ 0x00000001
  20724. +
  20725. +/* Bitfields in BSC_S */
  20726. +#define BSC_S_CLKT 0x00000200
  20727. +#define BSC_S_ERR 0x00000100
  20728. +#define BSC_S_RXF 0x00000080
  20729. +#define BSC_S_TXE 0x00000040
  20730. +#define BSC_S_RXD 0x00000020
  20731. +#define BSC_S_TXD 0x00000010
  20732. +#define BSC_S_RXR 0x00000008
  20733. +#define BSC_S_TXW 0x00000004
  20734. +#define BSC_S_DONE 0x00000002
  20735. +#define BSC_S_TA 0x00000001
  20736. +
  20737. +#define I2C_TIMEOUT_MS 150
  20738. +#define I2C_WAIT_LOOP_COUNT 40
  20739. +
  20740. +#define DRV_NAME "bcm2708_i2c"
  20741. +
  20742. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  20743. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  20744. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  20745. +
  20746. +static bool combined = false;
  20747. +module_param(combined, bool, 0644);
  20748. +MODULE_PARM_DESC(combined, "Use combined transactions");
  20749. +
  20750. +struct bcm2708_i2c {
  20751. + struct i2c_adapter adapter;
  20752. +
  20753. + spinlock_t lock;
  20754. + void __iomem *base;
  20755. + int irq;
  20756. + struct clk *clk;
  20757. + u32 cdiv;
  20758. +
  20759. + struct completion done;
  20760. +
  20761. + struct i2c_msg *msg;
  20762. + int pos;
  20763. + int nmsgs;
  20764. + bool error;
  20765. +};
  20766. +
  20767. +/*
  20768. + * This function sets the ALT mode on the I2C pins so that we can use them with
  20769. + * the BSC hardware.
  20770. + *
  20771. + * FIXME: This is a hack. Use pinmux / pinctrl.
  20772. + */
  20773. +static void bcm2708_i2c_init_pinmode(int id)
  20774. +{
  20775. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  20776. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  20777. +
  20778. + int pin;
  20779. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  20780. +
  20781. + BUG_ON(id != 0 && id != 1);
  20782. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  20783. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  20784. + printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  20785. + INP_GPIO(pin); /* set mode to GPIO input first */
  20786. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  20787. + }
  20788. +
  20789. + iounmap(gpio);
  20790. +
  20791. +#undef INP_GPIO
  20792. +#undef SET_GPIO_ALT
  20793. +}
  20794. +
  20795. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  20796. +{
  20797. + return readl(bi->base + reg);
  20798. +}
  20799. +
  20800. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  20801. +{
  20802. + writel(val, bi->base + reg);
  20803. +}
  20804. +
  20805. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  20806. +{
  20807. + bcm2708_wr(bi, BSC_C, 0);
  20808. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  20809. +}
  20810. +
  20811. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  20812. +{
  20813. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  20814. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  20815. +}
  20816. +
  20817. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  20818. +{
  20819. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  20820. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  20821. +}
  20822. +
  20823. +static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  20824. +{
  20825. + u32 cdiv, s;
  20826. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  20827. + int wait_loops = I2C_WAIT_LOOP_COUNT;
  20828. +
  20829. + /* Can't call clk_get_rate as it locks a mutex and here we are spinlocked.
  20830. + * Use the value that we cached in the probe.
  20831. + */
  20832. + cdiv = bi->cdiv;
  20833. +
  20834. + if (bi->msg->flags & I2C_M_RD)
  20835. + c |= BSC_C_INTR | BSC_C_READ;
  20836. + else
  20837. + c |= BSC_C_INTT;
  20838. +
  20839. + bcm2708_wr(bi, BSC_DIV, cdiv);
  20840. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  20841. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  20842. + if (combined)
  20843. + {
  20844. + /* Do the next two messages meet combined transaction criteria?
  20845. + - Current message is a write, next message is a read
  20846. + - Both messages to same slave address
  20847. + - Write message can fit inside FIFO (16 bytes or less) */
  20848. + if ( (bi->nmsgs > 1) &&
  20849. + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  20850. + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  20851. + /* Fill FIFO with entire write message (16 byte FIFO) */
  20852. + while (bi->pos < bi->msg->len) {
  20853. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  20854. + }
  20855. + /* Start write transfer (no interrupts, don't clear FIFO) */
  20856. + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
  20857. +
  20858. + /* poll for transfer start bit (should only take 1-20 polls) */
  20859. + do {
  20860. + s = bcm2708_rd(bi, BSC_S);
  20861. + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)) && --wait_loops >= 0);
  20862. +
  20863. + /* did we time out or some error occured? */
  20864. + if (wait_loops < 0 || (s & (BSC_S_ERR | BSC_S_CLKT))) {
  20865. + return -1;
  20866. + }
  20867. +
  20868. + /* Send next read message before the write transfer finishes. */
  20869. + bi->nmsgs--;
  20870. + bi->msg++;
  20871. + bi->pos = 0;
  20872. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  20873. + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
  20874. + }
  20875. + }
  20876. + bcm2708_wr(bi, BSC_C, c);
  20877. +
  20878. + return 0;
  20879. +}
  20880. +
  20881. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  20882. +{
  20883. + struct bcm2708_i2c *bi = dev_id;
  20884. + bool handled = true;
  20885. + u32 s;
  20886. + int ret;
  20887. +
  20888. + spin_lock(&bi->lock);
  20889. +
  20890. + /* we may see camera interrupts on the "other" I2C channel
  20891. + Just return if we've not sent anything */
  20892. + if (!bi->nmsgs || !bi->msg) {
  20893. + goto early_exit;
  20894. + }
  20895. +
  20896. + s = bcm2708_rd(bi, BSC_S);
  20897. +
  20898. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  20899. + bcm2708_bsc_reset(bi);
  20900. + bi->error = true;
  20901. +
  20902. + bi->msg = 0; /* to inform the that all work is done */
  20903. + bi->nmsgs = 0;
  20904. + /* wake up our bh */
  20905. + complete(&bi->done);
  20906. + } else if (s & BSC_S_DONE) {
  20907. + bi->nmsgs--;
  20908. +
  20909. + if (bi->msg->flags & I2C_M_RD) {
  20910. + bcm2708_bsc_fifo_drain(bi);
  20911. + }
  20912. +
  20913. + bcm2708_bsc_reset(bi);
  20914. +
  20915. + if (bi->nmsgs) {
  20916. + /* advance to next message */
  20917. + bi->msg++;
  20918. + bi->pos = 0;
  20919. + ret = bcm2708_bsc_setup(bi);
  20920. + if (ret < 0) {
  20921. + bcm2708_bsc_reset(bi);
  20922. + bi->error = true;
  20923. + bi->msg = 0; /* to inform the that all work is done */
  20924. + bi->nmsgs = 0;
  20925. + /* wake up our bh */
  20926. + complete(&bi->done);
  20927. + goto early_exit;
  20928. + }
  20929. + } else {
  20930. + bi->msg = 0; /* to inform the that all work is done */
  20931. + bi->nmsgs = 0;
  20932. + /* wake up our bh */
  20933. + complete(&bi->done);
  20934. + }
  20935. + } else if (s & BSC_S_TXW) {
  20936. + bcm2708_bsc_fifo_fill(bi);
  20937. + } else if (s & BSC_S_RXR) {
  20938. + bcm2708_bsc_fifo_drain(bi);
  20939. + } else {
  20940. + handled = false;
  20941. + }
  20942. +
  20943. +early_exit:
  20944. + spin_unlock(&bi->lock);
  20945. +
  20946. + return handled ? IRQ_HANDLED : IRQ_NONE;
  20947. +}
  20948. +
  20949. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  20950. + struct i2c_msg *msgs, int num)
  20951. +{
  20952. + struct bcm2708_i2c *bi = adap->algo_data;
  20953. + unsigned long flags;
  20954. + int ret;
  20955. +
  20956. + spin_lock_irqsave(&bi->lock, flags);
  20957. +
  20958. + INIT_COMPLETION(bi->done);
  20959. + bi->msg = msgs;
  20960. + bi->pos = 0;
  20961. + bi->nmsgs = num;
  20962. + bi->error = false;
  20963. +
  20964. + ret = bcm2708_bsc_setup(bi);
  20965. +
  20966. + spin_unlock_irqrestore(&bi->lock, flags);
  20967. +
  20968. + /* check the result of the setup */
  20969. + if (ret < 0)
  20970. + {
  20971. + dev_err(&adap->dev, "transfer setup timed out\n");
  20972. + goto error_timeout;
  20973. + }
  20974. +
  20975. + ret = wait_for_completion_timeout(&bi->done, msecs_to_jiffies(I2C_TIMEOUT_MS));
  20976. + if (ret == 0) {
  20977. + dev_err(&adap->dev, "transfer timed out\n");
  20978. + goto error_timeout;
  20979. + }
  20980. +
  20981. + ret = bi->error ? -EIO : num;
  20982. + return ret;
  20983. +
  20984. +error_timeout:
  20985. + spin_lock_irqsave(&bi->lock, flags);
  20986. + bcm2708_bsc_reset(bi);
  20987. + bi->msg = 0; /* to inform the interrupt handler that there's nothing else to be done */
  20988. + bi->nmsgs = 0;
  20989. + spin_unlock_irqrestore(&bi->lock, flags);
  20990. + return -ETIMEDOUT;
  20991. +}
  20992. +
  20993. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  20994. +{
  20995. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  20996. +}
  20997. +
  20998. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  20999. + .master_xfer = bcm2708_i2c_master_xfer,
  21000. + .functionality = bcm2708_i2c_functionality,
  21001. +};
  21002. +
  21003. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  21004. +{
  21005. + struct resource *regs;
  21006. + int irq, err = -ENOMEM;
  21007. + struct clk *clk;
  21008. + struct bcm2708_i2c *bi;
  21009. + struct i2c_adapter *adap;
  21010. + unsigned long bus_hz;
  21011. + u32 cdiv;
  21012. +
  21013. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  21014. + if (!regs) {
  21015. + dev_err(&pdev->dev, "could not get IO memory\n");
  21016. + return -ENXIO;
  21017. + }
  21018. +
  21019. + irq = platform_get_irq(pdev, 0);
  21020. + if (irq < 0) {
  21021. + dev_err(&pdev->dev, "could not get IRQ\n");
  21022. + return irq;
  21023. + }
  21024. +
  21025. + clk = clk_get(&pdev->dev, NULL);
  21026. + if (IS_ERR(clk)) {
  21027. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  21028. + return PTR_ERR(clk);
  21029. + }
  21030. +
  21031. + bcm2708_i2c_init_pinmode(pdev->id);
  21032. +
  21033. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  21034. + if (!bi)
  21035. + goto out_clk_put;
  21036. +
  21037. + platform_set_drvdata(pdev, bi);
  21038. +
  21039. + adap = &bi->adapter;
  21040. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  21041. + adap->algo = &bcm2708_i2c_algorithm;
  21042. + adap->algo_data = bi;
  21043. + adap->dev.parent = &pdev->dev;
  21044. + adap->nr = pdev->id;
  21045. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  21046. +
  21047. + switch (pdev->id) {
  21048. + case 0:
  21049. + adap->class = I2C_CLASS_HWMON;
  21050. + break;
  21051. + case 1:
  21052. + adap->class = I2C_CLASS_DDC;
  21053. + break;
  21054. + default:
  21055. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  21056. + err = -ENXIO;
  21057. + goto out_free_bi;
  21058. + }
  21059. +
  21060. + spin_lock_init(&bi->lock);
  21061. + init_completion(&bi->done);
  21062. +
  21063. + bi->base = ioremap(regs->start, resource_size(regs));
  21064. + if (!bi->base) {
  21065. + dev_err(&pdev->dev, "could not remap memory\n");
  21066. + goto out_free_bi;
  21067. + }
  21068. +
  21069. + bi->irq = irq;
  21070. + bi->clk = clk;
  21071. +
  21072. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  21073. + dev_name(&pdev->dev), bi);
  21074. + if (err) {
  21075. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  21076. + goto out_iounmap;
  21077. + }
  21078. +
  21079. + bcm2708_bsc_reset(bi);
  21080. +
  21081. + err = i2c_add_numbered_adapter(adap);
  21082. + if (err < 0) {
  21083. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  21084. + goto out_free_irq;
  21085. + }
  21086. +
  21087. + bus_hz = clk_get_rate(bi->clk);
  21088. + cdiv = bus_hz / baudrate;
  21089. + if (cdiv > 0xffff) {
  21090. + cdiv = 0xffff;
  21091. + baudrate = bus_hz / cdiv;
  21092. + }
  21093. + bi->cdiv = cdiv;
  21094. +
  21095. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  21096. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  21097. +
  21098. + return 0;
  21099. +
  21100. +out_free_irq:
  21101. + free_irq(bi->irq, bi);
  21102. +out_iounmap:
  21103. + iounmap(bi->base);
  21104. +out_free_bi:
  21105. + kfree(bi);
  21106. +out_clk_put:
  21107. + clk_put(clk);
  21108. + return err;
  21109. +}
  21110. +
  21111. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  21112. +{
  21113. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  21114. +
  21115. + platform_set_drvdata(pdev, NULL);
  21116. +
  21117. + i2c_del_adapter(&bi->adapter);
  21118. + free_irq(bi->irq, bi);
  21119. + iounmap(bi->base);
  21120. + clk_disable(bi->clk);
  21121. + clk_put(bi->clk);
  21122. + kfree(bi);
  21123. +
  21124. + return 0;
  21125. +}
  21126. +
  21127. +static struct platform_driver bcm2708_i2c_driver = {
  21128. + .driver = {
  21129. + .name = DRV_NAME,
  21130. + .owner = THIS_MODULE,
  21131. + },
  21132. + .probe = bcm2708_i2c_probe,
  21133. + .remove = bcm2708_i2c_remove,
  21134. +};
  21135. +
  21136. +// module_platform_driver(bcm2708_i2c_driver);
  21137. +
  21138. +
  21139. +static int __init bcm2708_i2c_init(void)
  21140. +{
  21141. + return platform_driver_register(&bcm2708_i2c_driver);
  21142. +}
  21143. +
  21144. +static void __exit bcm2708_i2c_exit(void)
  21145. +{
  21146. + platform_driver_unregister(&bcm2708_i2c_driver);
  21147. +}
  21148. +
  21149. +module_init(bcm2708_i2c_init);
  21150. +module_exit(bcm2708_i2c_exit);
  21151. +
  21152. +
  21153. +
  21154. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  21155. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  21156. +MODULE_LICENSE("GPL v2");
  21157. +MODULE_ALIAS("platform:" DRV_NAME);
  21158. diff -Nur linux-3.12.38/drivers/i2c/busses/i2c-s3c2410.c linux-rpi/drivers/i2c/busses/i2c-s3c2410.c
  21159. --- linux-3.12.38/drivers/i2c/busses/i2c-s3c2410.c 2015-02-16 16:15:42.000000000 +0100
  21160. +++ linux-rpi/drivers/i2c/busses/i2c-s3c2410.c 2015-03-10 17:26:50.338216693 +0100
  21161. @@ -711,16 +711,14 @@
  21162. int ret;
  21163. pm_runtime_get_sync(&adap->dev);
  21164. - ret = clk_enable(i2c->clk);
  21165. - if (ret)
  21166. - return ret;
  21167. + clk_prepare_enable(i2c->clk);
  21168. for (retry = 0; retry < adap->retries; retry++) {
  21169. ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
  21170. if (ret != -EAGAIN) {
  21171. - clk_disable(i2c->clk);
  21172. + clk_disable_unprepare(i2c->clk);
  21173. pm_runtime_put(&adap->dev);
  21174. return ret;
  21175. }
  21176. @@ -730,7 +728,7 @@
  21177. udelay(100);
  21178. }
  21179. - clk_disable(i2c->clk);
  21180. + clk_disable_unprepare(i2c->clk);
  21181. pm_runtime_put(&adap->dev);
  21182. return -EREMOTEIO;
  21183. }
  21184. @@ -1110,7 +1108,7 @@
  21185. clk_prepare_enable(i2c->clk);
  21186. ret = s3c24xx_i2c_init(i2c);
  21187. - clk_disable(i2c->clk);
  21188. + clk_disable_unprepare(i2c->clk);
  21189. if (ret != 0) {
  21190. dev_err(&pdev->dev, "I2C controller init failed\n");
  21191. return ret;
  21192. @@ -1122,7 +1120,6 @@
  21193. i2c->irq = ret = platform_get_irq(pdev, 0);
  21194. if (ret <= 0) {
  21195. dev_err(&pdev->dev, "cannot find IRQ\n");
  21196. - clk_unprepare(i2c->clk);
  21197. return ret;
  21198. }
  21199. @@ -1131,14 +1128,12 @@
  21200. if (ret != 0) {
  21201. dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
  21202. - clk_unprepare(i2c->clk);
  21203. return ret;
  21204. }
  21205. ret = s3c24xx_i2c_register_cpufreq(i2c);
  21206. if (ret < 0) {
  21207. dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
  21208. - clk_unprepare(i2c->clk);
  21209. return ret;
  21210. }
  21211. @@ -1155,7 +1150,6 @@
  21212. if (ret < 0) {
  21213. dev_err(&pdev->dev, "failed to add bus to i2c core\n");
  21214. s3c24xx_i2c_deregister_cpufreq(i2c);
  21215. - clk_unprepare(i2c->clk);
  21216. return ret;
  21217. }
  21218. @@ -1177,8 +1171,6 @@
  21219. {
  21220. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  21221. - clk_unprepare(i2c->clk);
  21222. -
  21223. pm_runtime_disable(&i2c->adap.dev);
  21224. pm_runtime_disable(&pdev->dev);
  21225. @@ -1207,13 +1199,10 @@
  21226. {
  21227. struct platform_device *pdev = to_platform_device(dev);
  21228. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  21229. - int ret;
  21230. - ret = clk_enable(i2c->clk);
  21231. - if (ret)
  21232. - return ret;
  21233. + clk_prepare_enable(i2c->clk);
  21234. s3c24xx_i2c_init(i2c);
  21235. - clk_disable(i2c->clk);
  21236. + clk_disable_unprepare(i2c->clk);
  21237. i2c->suspended = 0;
  21238. return 0;
  21239. diff -Nur linux-3.12.38/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  21240. --- linux-3.12.38/drivers/i2c/busses/Kconfig 2015-02-16 16:15:42.000000000 +0100
  21241. +++ linux-rpi/drivers/i2c/busses/Kconfig 2015-03-10 17:26:50.334216693 +0100
  21242. @@ -348,6 +348,25 @@
  21243. This support is also available as a module. If so, the module
  21244. will be called i2c-bcm2835.
  21245. +config I2C_BCM2708
  21246. + tristate "BCM2708 BSC"
  21247. + depends on MACH_BCM2708
  21248. + help
  21249. + Enabling this option will add BSC (Broadcom Serial Controller)
  21250. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  21251. + with I2C/TWI/SMBus.
  21252. +
  21253. +config I2C_BCM2708_BAUDRATE
  21254. + prompt "BCM2708 I2C baudrate"
  21255. + depends on I2C_BCM2708
  21256. + int
  21257. + default 100000
  21258. + help
  21259. + Set the I2C baudrate. This will alter the default value. A
  21260. + different baudrate can be set by using a module parameter as well. If
  21261. + no parameter is provided when loading, this is the value that will be
  21262. + used.
  21263. +
  21264. config I2C_BLACKFIN_TWI
  21265. tristate "Blackfin TWI I2C support"
  21266. depends on BLACKFIN
  21267. diff -Nur linux-3.12.38/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  21268. --- linux-3.12.38/drivers/i2c/busses/Makefile 2015-02-16 16:15:42.000000000 +0100
  21269. +++ linux-rpi/drivers/i2c/busses/Makefile 2015-03-10 17:26:50.334216693 +0100
  21270. @@ -32,6 +32,7 @@
  21271. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  21272. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  21273. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  21274. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  21275. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  21276. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  21277. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  21278. diff -Nur linux-3.12.38/drivers/infiniband/ulp/isert/ib_isert.c linux-rpi/drivers/infiniband/ulp/isert/ib_isert.c
  21279. --- linux-3.12.38/drivers/infiniband/ulp/isert/ib_isert.c 2015-02-16 16:15:42.000000000 +0100
  21280. +++ linux-rpi/drivers/infiniband/ulp/isert/ib_isert.c 2015-03-10 17:26:50.374216693 +0100
  21281. @@ -40,7 +40,6 @@
  21282. static LIST_HEAD(device_list);
  21283. static struct workqueue_struct *isert_rx_wq;
  21284. static struct workqueue_struct *isert_comp_wq;
  21285. -static struct workqueue_struct *isert_release_wq;
  21286. static void
  21287. isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn);
  21288. @@ -52,11 +51,6 @@
  21289. static int
  21290. isert_reg_rdma_frwr(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
  21291. struct isert_rdma_wr *wr);
  21292. -static int
  21293. -isert_rdma_post_recvl(struct isert_conn *isert_conn);
  21294. -static int
  21295. -isert_rdma_accept(struct isert_conn *isert_conn);
  21296. -struct rdma_cm_id *isert_setup_id(struct isert_np *isert_np);
  21297. static void
  21298. isert_qp_event_callback(struct ib_event *e, void *context)
  21299. @@ -137,18 +131,12 @@
  21300. ret = rdma_create_qp(cma_id, isert_conn->conn_pd, &attr);
  21301. if (ret) {
  21302. pr_err("rdma_create_qp failed for cma_id %d\n", ret);
  21303. - goto err;
  21304. + return ret;
  21305. }
  21306. isert_conn->conn_qp = cma_id->qp;
  21307. pr_debug("rdma_create_qp() returned success >>>>>>>>>>>>>>>>>>>>>>>>>.\n");
  21308. return 0;
  21309. -err:
  21310. - mutex_lock(&device_list_mutex);
  21311. - device->cq_active_qps[min_index]--;
  21312. - mutex_unlock(&device_list_mutex);
  21313. -
  21314. - return ret;
  21315. }
  21316. static void
  21317. @@ -505,8 +493,8 @@
  21318. static int
  21319. isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
  21320. {
  21321. - struct isert_np *isert_np = cma_id->context;
  21322. - struct iscsi_np *np = isert_np->np;
  21323. + struct iscsi_np *np = cma_id->context;
  21324. + struct isert_np *isert_np = np->np_context;
  21325. struct isert_conn *isert_conn;
  21326. struct isert_device *device;
  21327. struct ib_device *ib_dev = cma_id->device;
  21328. @@ -531,7 +519,6 @@
  21329. isert_conn->state = ISER_CONN_INIT;
  21330. INIT_LIST_HEAD(&isert_conn->conn_accept_node);
  21331. init_completion(&isert_conn->conn_login_comp);
  21332. - init_completion(&isert_conn->login_req_comp);
  21333. init_completion(&isert_conn->conn_wait);
  21334. init_completion(&isert_conn->conn_wait_comp_err);
  21335. kref_init(&isert_conn->conn_kref);
  21336. @@ -539,6 +526,7 @@
  21337. spin_lock_init(&isert_conn->conn_lock);
  21338. INIT_LIST_HEAD(&isert_conn->conn_frwr_pool);
  21339. + cma_id->context = isert_conn;
  21340. isert_conn->conn_cm_id = cma_id;
  21341. isert_conn->responder_resources = event->param.conn.responder_resources;
  21342. isert_conn->initiator_depth = event->param.conn.initiator_depth;
  21343. @@ -598,14 +586,6 @@
  21344. if (ret)
  21345. goto out_conn_dev;
  21346. - ret = isert_rdma_post_recvl(isert_conn);
  21347. - if (ret)
  21348. - goto out_conn_dev;
  21349. -
  21350. - ret = isert_rdma_accept(isert_conn);
  21351. - if (ret)
  21352. - goto out_conn_dev;
  21353. -
  21354. mutex_lock(&isert_np->np_accept_mutex);
  21355. list_add_tail(&isert_conn->conn_accept_node, &isert_np->np_accept_list);
  21356. mutex_unlock(&isert_np->np_accept_mutex);
  21357. @@ -626,7 +606,6 @@
  21358. kfree(isert_conn->login_buf);
  21359. out:
  21360. kfree(isert_conn);
  21361. - rdma_reject(cma_id, NULL, 0);
  21362. return ret;
  21363. }
  21364. @@ -642,20 +621,18 @@
  21365. if (device && device->use_frwr)
  21366. isert_conn_free_frwr_pool(isert_conn);
  21367. - isert_free_rx_descriptors(isert_conn);
  21368. - rdma_destroy_id(isert_conn->conn_cm_id);
  21369. -
  21370. if (isert_conn->conn_qp) {
  21371. cq_index = ((struct isert_cq_desc *)
  21372. isert_conn->conn_qp->recv_cq->cq_context)->cq_index;
  21373. pr_debug("isert_connect_release: cq_index: %d\n", cq_index);
  21374. - mutex_lock(&device_list_mutex);
  21375. isert_conn->conn_device->cq_active_qps[cq_index]--;
  21376. - mutex_unlock(&device_list_mutex);
  21377. - ib_destroy_qp(isert_conn->conn_qp);
  21378. + rdma_destroy_qp(isert_conn->conn_cm_id);
  21379. }
  21380. + isert_free_rx_descriptors(isert_conn);
  21381. + rdma_destroy_id(isert_conn->conn_cm_id);
  21382. +
  21383. if (isert_conn->login_buf) {
  21384. ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma,
  21385. ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE);
  21386. @@ -675,19 +652,9 @@
  21387. static void
  21388. isert_connected_handler(struct rdma_cm_id *cma_id)
  21389. {
  21390. - struct isert_conn *isert_conn = cma_id->qp->qp_context;
  21391. -
  21392. - pr_info("conn %p\n", isert_conn);
  21393. -
  21394. - if (!kref_get_unless_zero(&isert_conn->conn_kref)) {
  21395. - pr_warn("conn %p connect_release is running\n", isert_conn);
  21396. - return;
  21397. - }
  21398. + struct isert_conn *isert_conn = cma_id->context;
  21399. - mutex_lock(&isert_conn->conn_mutex);
  21400. - if (isert_conn->state != ISER_CONN_FULL_FEATURE)
  21401. - isert_conn->state = ISER_CONN_UP;
  21402. - mutex_unlock(&isert_conn->conn_mutex);
  21403. + kref_get(&isert_conn->conn_kref);
  21404. }
  21405. static void
  21406. @@ -708,108 +675,65 @@
  21407. kref_put(&isert_conn->conn_kref, isert_release_conn_kref);
  21408. }
  21409. -/**
  21410. - * isert_conn_terminate() - Initiate connection termination
  21411. - * @isert_conn: isert connection struct
  21412. - *
  21413. - * Notes:
  21414. - * In case the connection state is FULL_FEATURE, move state
  21415. - * to TEMINATING and start teardown sequence (rdma_disconnect).
  21416. - * In case the connection state is UP, complete flush as well.
  21417. - *
  21418. - * This routine must be called with conn_mutex held. Thus it is
  21419. - * safe to call multiple times.
  21420. - */
  21421. static void
  21422. -isert_conn_terminate(struct isert_conn *isert_conn)
  21423. +isert_disconnect_work(struct work_struct *work)
  21424. {
  21425. - int err;
  21426. + struct isert_conn *isert_conn = container_of(work,
  21427. + struct isert_conn, conn_logout_work);
  21428. - switch (isert_conn->state) {
  21429. - case ISER_CONN_TERMINATING:
  21430. - break;
  21431. - case ISER_CONN_UP:
  21432. - /*
  21433. - * No flush completions will occur as we didn't
  21434. - * get to ISER_CONN_FULL_FEATURE yet, complete
  21435. - * to allow teardown progress.
  21436. - */
  21437. - complete(&isert_conn->conn_wait_comp_err);
  21438. - case ISER_CONN_FULL_FEATURE: /* FALLTHRU */
  21439. - pr_info("Terminating conn %p state %d\n",
  21440. - isert_conn, isert_conn->state);
  21441. + pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  21442. + mutex_lock(&isert_conn->conn_mutex);
  21443. + if (isert_conn->state == ISER_CONN_UP)
  21444. isert_conn->state = ISER_CONN_TERMINATING;
  21445. - err = rdma_disconnect(isert_conn->conn_cm_id);
  21446. - if (err)
  21447. - pr_warn("Failed rdma_disconnect isert_conn %p\n",
  21448. - isert_conn);
  21449. - break;
  21450. - default:
  21451. - pr_warn("conn %p teminating in state %d\n",
  21452. - isert_conn, isert_conn->state);
  21453. - }
  21454. -}
  21455. -static int
  21456. -isert_np_cma_handler(struct isert_np *isert_np,
  21457. - enum rdma_cm_event_type event)
  21458. -{
  21459. - pr_debug("isert np %p, handling event %d\n", isert_np, event);
  21460. + if (isert_conn->post_recv_buf_count == 0 &&
  21461. + atomic_read(&isert_conn->post_send_buf_count) == 0) {
  21462. + mutex_unlock(&isert_conn->conn_mutex);
  21463. + goto wake_up;
  21464. + }
  21465. + if (!isert_conn->conn_cm_id) {
  21466. + mutex_unlock(&isert_conn->conn_mutex);
  21467. + isert_put_conn(isert_conn);
  21468. + return;
  21469. + }
  21470. - switch (event) {
  21471. - case RDMA_CM_EVENT_DEVICE_REMOVAL:
  21472. - isert_np->np_cm_id = NULL;
  21473. - break;
  21474. - case RDMA_CM_EVENT_ADDR_CHANGE:
  21475. - isert_np->np_cm_id = isert_setup_id(isert_np);
  21476. - if (IS_ERR(isert_np->np_cm_id)) {
  21477. - pr_err("isert np %p setup id failed: %ld\n",
  21478. - isert_np, PTR_ERR(isert_np->np_cm_id));
  21479. - isert_np->np_cm_id = NULL;
  21480. - }
  21481. - break;
  21482. - default:
  21483. - pr_err("isert np %p Unexpected event %d\n",
  21484. - isert_np, event);
  21485. + if (isert_conn->disconnect) {
  21486. + /* Send DREQ/DREP towards our initiator */
  21487. + rdma_disconnect(isert_conn->conn_cm_id);
  21488. }
  21489. - return -1;
  21490. + mutex_unlock(&isert_conn->conn_mutex);
  21491. +
  21492. +wake_up:
  21493. + complete(&isert_conn->conn_wait);
  21494. }
  21495. static int
  21496. -isert_disconnected_handler(struct rdma_cm_id *cma_id,
  21497. - enum rdma_cm_event_type event)
  21498. +isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect)
  21499. {
  21500. - struct isert_np *isert_np = cma_id->context;
  21501. struct isert_conn *isert_conn;
  21502. - if (isert_np->np_cm_id == cma_id)
  21503. - return isert_np_cma_handler(cma_id->context, event);
  21504. + if (!cma_id->qp) {
  21505. + struct isert_np *isert_np = cma_id->context;
  21506. - isert_conn = cma_id->qp->qp_context;
  21507. + isert_np->np_cm_id = NULL;
  21508. + return -1;
  21509. + }
  21510. - mutex_lock(&isert_conn->conn_mutex);
  21511. - isert_conn_terminate(isert_conn);
  21512. - mutex_unlock(&isert_conn->conn_mutex);
  21513. + isert_conn = (struct isert_conn *)cma_id->context;
  21514. - pr_info("conn %p completing conn_wait\n", isert_conn);
  21515. - complete(&isert_conn->conn_wait);
  21516. + isert_conn->disconnect = disconnect;
  21517. + INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work);
  21518. + schedule_work(&isert_conn->conn_logout_work);
  21519. return 0;
  21520. }
  21521. -static void
  21522. -isert_connect_error(struct rdma_cm_id *cma_id)
  21523. -{
  21524. - struct isert_conn *isert_conn = cma_id->qp->qp_context;
  21525. -
  21526. - isert_put_conn(isert_conn);
  21527. -}
  21528. -
  21529. static int
  21530. isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
  21531. {
  21532. int ret = 0;
  21533. + bool disconnect = false;
  21534. pr_debug("isert_cma_handler: event %d status %d conn %p id %p\n",
  21535. event->event, event->status, cma_id->context, cma_id);
  21536. @@ -827,14 +751,11 @@
  21537. case RDMA_CM_EVENT_ADDR_CHANGE: /* FALLTHRU */
  21538. case RDMA_CM_EVENT_DISCONNECTED: /* FALLTHRU */
  21539. case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */
  21540. + disconnect = true;
  21541. case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */
  21542. - ret = isert_disconnected_handler(cma_id, event->event);
  21543. + ret = isert_disconnected_handler(cma_id, disconnect);
  21544. break;
  21545. - case RDMA_CM_EVENT_REJECTED: /* FALLTHRU */
  21546. - case RDMA_CM_EVENT_UNREACHABLE: /* FALLTHRU */
  21547. case RDMA_CM_EVENT_CONNECT_ERROR:
  21548. - isert_connect_error(cma_id);
  21549. - break;
  21550. default:
  21551. pr_err("Unhandled RDMA CMA event: %d\n", event->event);
  21552. break;
  21553. @@ -1045,10 +966,7 @@
  21554. if (ret)
  21555. return ret;
  21556. - /* Now we are in FULL_FEATURE phase */
  21557. - mutex_lock(&isert_conn->conn_mutex);
  21558. - isert_conn->state = ISER_CONN_FULL_FEATURE;
  21559. - mutex_unlock(&isert_conn->conn_mutex);
  21560. + isert_conn->state = ISER_CONN_UP;
  21561. goto post_send;
  21562. }
  21563. @@ -1065,17 +983,18 @@
  21564. }
  21565. static void
  21566. -isert_rx_login_req(struct isert_conn *isert_conn)
  21567. +isert_rx_login_req(struct iser_rx_desc *rx_desc, int rx_buflen,
  21568. + struct isert_conn *isert_conn)
  21569. {
  21570. - struct iser_rx_desc *rx_desc = (void *)isert_conn->login_req_buf;
  21571. - int rx_buflen = isert_conn->login_req_len;
  21572. struct iscsi_conn *conn = isert_conn->conn;
  21573. struct iscsi_login *login = conn->conn_login;
  21574. int size;
  21575. - pr_info("conn %p\n", isert_conn);
  21576. -
  21577. - WARN_ON_ONCE(!login);
  21578. + if (!login) {
  21579. + pr_err("conn->conn_login is NULL\n");
  21580. + dump_stack();
  21581. + return;
  21582. + }
  21583. if (login->first_request) {
  21584. struct iscsi_login_req *login_req =
  21585. @@ -1438,20 +1357,11 @@
  21586. hdr->opcode, hdr->itt, hdr->flags,
  21587. (int)(xfer_len - ISER_HEADERS_LEN));
  21588. - if ((char *)desc == isert_conn->login_req_buf) {
  21589. - isert_conn->login_req_len = xfer_len - ISER_HEADERS_LEN;
  21590. - if (isert_conn->conn) {
  21591. - struct iscsi_login *login = isert_conn->conn->conn_login;
  21592. -
  21593. - if (login && !login->first_request)
  21594. - isert_rx_login_req(isert_conn);
  21595. - }
  21596. - mutex_lock(&isert_conn->conn_mutex);
  21597. - complete(&isert_conn->login_req_comp);
  21598. - mutex_unlock(&isert_conn->conn_mutex);
  21599. - } else {
  21600. + if ((char *)desc == isert_conn->login_req_buf)
  21601. + isert_rx_login_req(desc, xfer_len - ISER_HEADERS_LEN,
  21602. + isert_conn);
  21603. + else
  21604. isert_rx_do_work(desc, isert_conn);
  21605. - }
  21606. ib_dma_sync_single_for_device(ib_dev, rx_dma, rx_buflen,
  21607. DMA_FROM_DEVICE);
  21608. @@ -1796,7 +1706,7 @@
  21609. msleep(3000);
  21610. mutex_lock(&isert_conn->conn_mutex);
  21611. - isert_conn_terminate(isert_conn);
  21612. + isert_conn->state = ISER_CONN_DOWN;
  21613. mutex_unlock(&isert_conn->conn_mutex);
  21614. iscsit_cause_connection_reinstatement(isert_conn->conn, 0);
  21615. @@ -2576,51 +2486,13 @@
  21616. return ret;
  21617. }
  21618. -struct rdma_cm_id *
  21619. -isert_setup_id(struct isert_np *isert_np)
  21620. -{
  21621. - struct iscsi_np *np = isert_np->np;
  21622. - struct rdma_cm_id *id;
  21623. - struct sockaddr *sa;
  21624. - int ret;
  21625. -
  21626. - sa = (struct sockaddr *)&np->np_sockaddr;
  21627. - pr_debug("ksockaddr: %p, sa: %p\n", &np->np_sockaddr, sa);
  21628. -
  21629. - id = rdma_create_id(isert_cma_handler, isert_np,
  21630. - RDMA_PS_TCP, IB_QPT_RC);
  21631. - if (IS_ERR(id)) {
  21632. - pr_err("rdma_create_id() failed: %ld\n", PTR_ERR(id));
  21633. - ret = PTR_ERR(id);
  21634. - goto out;
  21635. - }
  21636. - pr_debug("id %p context %p\n", id, id->context);
  21637. -
  21638. - ret = rdma_bind_addr(id, sa);
  21639. - if (ret) {
  21640. - pr_err("rdma_bind_addr() failed: %d\n", ret);
  21641. - goto out_id;
  21642. - }
  21643. -
  21644. - ret = rdma_listen(id, ISERT_RDMA_LISTEN_BACKLOG);
  21645. - if (ret) {
  21646. - pr_err("rdma_listen() failed: %d\n", ret);
  21647. - goto out_id;
  21648. - }
  21649. -
  21650. - return id;
  21651. -out_id:
  21652. - rdma_destroy_id(id);
  21653. -out:
  21654. - return ERR_PTR(ret);
  21655. -}
  21656. -
  21657. static int
  21658. isert_setup_np(struct iscsi_np *np,
  21659. struct __kernel_sockaddr_storage *ksockaddr)
  21660. {
  21661. struct isert_np *isert_np;
  21662. struct rdma_cm_id *isert_lid;
  21663. + struct sockaddr *sa;
  21664. int ret;
  21665. isert_np = kzalloc(sizeof(struct isert_np), GFP_KERNEL);
  21666. @@ -2632,8 +2504,9 @@
  21667. mutex_init(&isert_np->np_accept_mutex);
  21668. INIT_LIST_HEAD(&isert_np->np_accept_list);
  21669. init_completion(&isert_np->np_login_comp);
  21670. - isert_np->np = np;
  21671. + sa = (struct sockaddr *)ksockaddr;
  21672. + pr_debug("ksockaddr: %p, sa: %p\n", ksockaddr, sa);
  21673. /*
  21674. * Setup the np->np_sockaddr from the passed sockaddr setup
  21675. * in iscsi_target_configfs.c code..
  21676. @@ -2641,20 +2514,37 @@
  21677. memcpy(&np->np_sockaddr, ksockaddr,
  21678. sizeof(struct __kernel_sockaddr_storage));
  21679. - isert_lid = isert_setup_id(isert_np);
  21680. + isert_lid = rdma_create_id(isert_cma_handler, np, RDMA_PS_TCP,
  21681. + IB_QPT_RC);
  21682. if (IS_ERR(isert_lid)) {
  21683. + pr_err("rdma_create_id() for isert_listen_handler failed: %ld\n",
  21684. + PTR_ERR(isert_lid));
  21685. ret = PTR_ERR(isert_lid);
  21686. goto out;
  21687. }
  21688. + ret = rdma_bind_addr(isert_lid, sa);
  21689. + if (ret) {
  21690. + pr_err("rdma_bind_addr() for isert_lid failed: %d\n", ret);
  21691. + goto out_lid;
  21692. + }
  21693. +
  21694. + ret = rdma_listen(isert_lid, ISERT_RDMA_LISTEN_BACKLOG);
  21695. + if (ret) {
  21696. + pr_err("rdma_listen() for isert_lid failed: %d\n", ret);
  21697. + goto out_lid;
  21698. + }
  21699. +
  21700. isert_np->np_cm_id = isert_lid;
  21701. np->np_context = isert_np;
  21702. + pr_debug("Setup isert_lid->context: %p\n", isert_lid->context);
  21703. return 0;
  21704. +out_lid:
  21705. + rdma_destroy_id(isert_lid);
  21706. out:
  21707. kfree(isert_np);
  21708. -
  21709. return ret;
  21710. }
  21711. @@ -2690,15 +2580,7 @@
  21712. struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
  21713. int ret;
  21714. - pr_info("before login_req comp conn: %p\n", isert_conn);
  21715. - ret = wait_for_completion_interruptible(&isert_conn->login_req_comp);
  21716. - if (ret) {
  21717. - pr_err("isert_conn %p interrupted before got login req\n",
  21718. - isert_conn);
  21719. - return ret;
  21720. - }
  21721. - INIT_COMPLETION(isert_conn->login_req_comp);
  21722. -
  21723. + pr_debug("isert_get_login_rx before conn_login_comp conn: %p\n", conn);
  21724. /*
  21725. * For login requests after the first PDU, isert_rx_login_req() will
  21726. * kick schedule_delayed_work(&conn->login_work) as the packet is
  21727. @@ -2708,15 +2590,11 @@
  21728. if (!login->first_request)
  21729. return 0;
  21730. - isert_rx_login_req(isert_conn);
  21731. -
  21732. - pr_info("before conn_login_comp conn: %p\n", conn);
  21733. ret = wait_for_completion_interruptible(&isert_conn->conn_login_comp);
  21734. if (ret)
  21735. return ret;
  21736. - pr_info("processing login->req: %p\n", login->req);
  21737. -
  21738. + pr_debug("isert_get_login_rx processing login->req: %p\n", login->req);
  21739. return 0;
  21740. }
  21741. @@ -2794,10 +2672,17 @@
  21742. isert_conn->conn = conn;
  21743. max_accept = 0;
  21744. - isert_set_conn_info(np, conn, isert_conn);
  21745. + ret = isert_rdma_post_recvl(isert_conn);
  21746. + if (ret)
  21747. + return ret;
  21748. +
  21749. + ret = isert_rdma_accept(isert_conn);
  21750. + if (ret)
  21751. + return ret;
  21752. - pr_debug("Processing isert_conn: %p\n", isert_conn);
  21753. + isert_set_conn_info(np, conn, isert_conn);
  21754. + pr_debug("Processing isert_accept_np: isert_conn: %p\n", isert_conn);
  21755. return 0;
  21756. }
  21757. @@ -2813,24 +2698,6 @@
  21758. kfree(isert_np);
  21759. }
  21760. -static void isert_release_work(struct work_struct *work)
  21761. -{
  21762. - struct isert_conn *isert_conn = container_of(work,
  21763. - struct isert_conn,
  21764. - release_work);
  21765. -
  21766. - pr_info("Starting release conn %p\n", isert_conn);
  21767. -
  21768. - wait_for_completion(&isert_conn->conn_wait);
  21769. -
  21770. - mutex_lock(&isert_conn->conn_mutex);
  21771. - isert_conn->state = ISER_CONN_DOWN;
  21772. - mutex_unlock(&isert_conn->conn_mutex);
  21773. -
  21774. - pr_info("Destroying conn %p\n", isert_conn);
  21775. - isert_put_conn(isert_conn);
  21776. -}
  21777. -
  21778. static void isert_wait_conn(struct iscsi_conn *conn)
  21779. {
  21780. struct isert_conn *isert_conn = conn->context;
  21781. @@ -2838,6 +2705,10 @@
  21782. pr_debug("isert_wait_conn: Starting \n");
  21783. mutex_lock(&isert_conn->conn_mutex);
  21784. + if (isert_conn->conn_cm_id) {
  21785. + pr_debug("Calling rdma_disconnect from isert_wait_conn\n");
  21786. + rdma_disconnect(isert_conn->conn_cm_id);
  21787. + }
  21788. /*
  21789. * Only wait for conn_wait_comp_err if the isert_conn made it
  21790. * into full feature phase..
  21791. @@ -2846,13 +2717,14 @@
  21792. mutex_unlock(&isert_conn->conn_mutex);
  21793. return;
  21794. }
  21795. - isert_conn_terminate(isert_conn);
  21796. + if (isert_conn->state == ISER_CONN_UP)
  21797. + isert_conn->state = ISER_CONN_TERMINATING;
  21798. mutex_unlock(&isert_conn->conn_mutex);
  21799. wait_for_completion(&isert_conn->conn_wait_comp_err);
  21800. - INIT_WORK(&isert_conn->release_work, isert_release_work);
  21801. - queue_work(isert_release_wq, &isert_conn->release_work);
  21802. + wait_for_completion(&isert_conn->conn_wait);
  21803. + isert_put_conn(isert_conn);
  21804. }
  21805. static void isert_free_conn(struct iscsi_conn *conn)
  21806. @@ -2898,21 +2770,10 @@
  21807. goto destroy_rx_wq;
  21808. }
  21809. - isert_release_wq = alloc_workqueue("isert_release_wq", WQ_UNBOUND,
  21810. - WQ_UNBOUND_MAX_ACTIVE);
  21811. - if (!isert_release_wq) {
  21812. - pr_err("Unable to allocate isert_release_wq\n");
  21813. - ret = -ENOMEM;
  21814. - goto destroy_comp_wq;
  21815. - }
  21816. -
  21817. iscsit_register_transport(&iser_target_transport);
  21818. - pr_info("iSER_TARGET[0] - Loaded iser_target_transport\n");
  21819. -
  21820. + pr_debug("iSER_TARGET[0] - Loaded iser_target_transport\n");
  21821. return 0;
  21822. -destroy_comp_wq:
  21823. - destroy_workqueue(isert_comp_wq);
  21824. destroy_rx_wq:
  21825. destroy_workqueue(isert_rx_wq);
  21826. return ret;
  21827. @@ -2921,7 +2782,6 @@
  21828. static void __exit isert_exit(void)
  21829. {
  21830. flush_scheduled_work();
  21831. - destroy_workqueue(isert_release_wq);
  21832. destroy_workqueue(isert_comp_wq);
  21833. destroy_workqueue(isert_rx_wq);
  21834. iscsit_unregister_transport(&iser_target_transport);
  21835. diff -Nur linux-3.12.38/drivers/infiniband/ulp/isert/ib_isert.h linux-rpi/drivers/infiniband/ulp/isert/ib_isert.h
  21836. --- linux-3.12.38/drivers/infiniband/ulp/isert/ib_isert.h 2015-02-16 16:15:42.000000000 +0100
  21837. +++ linux-rpi/drivers/infiniband/ulp/isert/ib_isert.h 2015-03-10 17:26:50.374216693 +0100
  21838. @@ -23,7 +23,6 @@
  21839. enum iser_conn_state {
  21840. ISER_CONN_INIT,
  21841. ISER_CONN_UP,
  21842. - ISER_CONN_FULL_FEATURE,
  21843. ISER_CONN_TERMINATING,
  21844. ISER_CONN_DOWN,
  21845. };
  21846. @@ -100,7 +99,6 @@
  21847. char *login_req_buf;
  21848. char *login_rsp_buf;
  21849. u64 login_req_dma;
  21850. - int login_req_len;
  21851. u64 login_rsp_dma;
  21852. unsigned int conn_rx_desc_head;
  21853. struct iser_rx_desc *conn_rx_descs;
  21854. @@ -108,13 +106,13 @@
  21855. struct iscsi_conn *conn;
  21856. struct list_head conn_accept_node;
  21857. struct completion conn_login_comp;
  21858. - struct completion login_req_comp;
  21859. struct iser_tx_desc conn_login_tx_desc;
  21860. struct rdma_cm_id *conn_cm_id;
  21861. struct ib_pd *conn_pd;
  21862. struct ib_mr *conn_mr;
  21863. struct ib_qp *conn_qp;
  21864. struct isert_device *conn_device;
  21865. + struct work_struct conn_logout_work;
  21866. struct mutex conn_mutex;
  21867. struct completion conn_wait;
  21868. struct completion conn_wait_comp_err;
  21869. @@ -123,7 +121,7 @@
  21870. int conn_frwr_pool_size;
  21871. /* lock to protect frwr_pool */
  21872. spinlock_t conn_lock;
  21873. - struct work_struct release_work;
  21874. + bool disconnect;
  21875. };
  21876. #define ISERT_MAX_CQ 64
  21877. @@ -156,7 +154,6 @@
  21878. };
  21879. struct isert_np {
  21880. - struct iscsi_np *np;
  21881. struct semaphore np_sem;
  21882. struct rdma_cm_id *np_cm_id;
  21883. struct mutex np_accept_mutex;
  21884. diff -Nur linux-3.12.38/drivers/input/mouse/synaptics.c linux-rpi/drivers/input/mouse/synaptics.c
  21885. --- linux-3.12.38/drivers/input/mouse/synaptics.c 2015-02-16 16:15:42.000000000 +0100
  21886. +++ linux-rpi/drivers/input/mouse/synaptics.c 2015-03-10 17:26:50.386216693 +0100
  21887. @@ -132,9 +132,8 @@
  21888. 1232, 5710, 1156, 4696
  21889. },
  21890. {
  21891. - (const char * const []){"LEN0034", "LEN0036", "LEN0037",
  21892. - "LEN0039", "LEN2002", "LEN2004",
  21893. - NULL},
  21894. + (const char * const []){"LEN0034", "LEN0036", "LEN0039",
  21895. + "LEN2002", "LEN2004", NULL},
  21896. 1024, 5112, 2024, 4832
  21897. },
  21898. {
  21899. @@ -163,7 +162,7 @@
  21900. "LEN0034", /* T431s, L440, L540, T540, W540, X1 Carbon 2nd */
  21901. "LEN0035", /* X240 */
  21902. "LEN0036", /* T440 */
  21903. - "LEN0037", /* X1 Carbon 2nd */
  21904. + "LEN0037",
  21905. "LEN0038",
  21906. "LEN0039", /* T440s */
  21907. "LEN0041",
  21908. diff -Nur linux-3.12.38/drivers/input/serio/i8042.c linux-rpi/drivers/input/serio/i8042.c
  21909. --- linux-3.12.38/drivers/input/serio/i8042.c 2015-02-16 16:15:42.000000000 +0100
  21910. +++ linux-rpi/drivers/input/serio/i8042.c 2015-03-10 17:26:50.386216693 +0100
  21911. @@ -67,10 +67,6 @@
  21912. module_param_named(notimeout, i8042_notimeout, bool, 0);
  21913. MODULE_PARM_DESC(notimeout, "Ignore timeouts signalled by i8042");
  21914. -static bool i8042_kbdreset;
  21915. -module_param_named(kbdreset, i8042_kbdreset, bool, 0);
  21916. -MODULE_PARM_DESC(kbdreset, "Reset device connected to KBD port");
  21917. -
  21918. #ifdef CONFIG_X86
  21919. static bool i8042_dritek;
  21920. module_param_named(dritek, i8042_dritek, bool, 0);
  21921. @@ -794,16 +790,6 @@
  21922. return -1;
  21923. /*
  21924. - * Reset keyboard (needed on some laptops to successfully detect
  21925. - * touchpad, e.g., some Gigabyte laptop models with Elantech
  21926. - * touchpads).
  21927. - */
  21928. - if (i8042_kbdreset) {
  21929. - pr_warn("Attempting to reset device connected to KBD port\n");
  21930. - i8042_kbd_write(NULL, (unsigned char) 0xff);
  21931. - }
  21932. -
  21933. -/*
  21934. * Test AUX IRQ delivery to make sure BIOS did not grab the IRQ and
  21935. * used it for a PCI card or somethig else.
  21936. */
  21937. diff -Nur linux-3.12.38/drivers/input/serio/i8042-x86ia64io.h linux-rpi/drivers/input/serio/i8042-x86ia64io.h
  21938. --- linux-3.12.38/drivers/input/serio/i8042-x86ia64io.h 2015-02-16 16:15:42.000000000 +0100
  21939. +++ linux-rpi/drivers/input/serio/i8042-x86ia64io.h 2015-03-10 17:26:50.386216693 +0100
  21940. @@ -152,14 +152,6 @@
  21941. },
  21942. },
  21943. {
  21944. - /* Medion Akoya E7225 */
  21945. - .matches = {
  21946. - DMI_MATCH(DMI_SYS_VENDOR, "Medion"),
  21947. - DMI_MATCH(DMI_PRODUCT_NAME, "Akoya E7225"),
  21948. - DMI_MATCH(DMI_PRODUCT_VERSION, "1.0"),
  21949. - },
  21950. - },
  21951. - {
  21952. /* Blue FB5601 */
  21953. .matches = {
  21954. DMI_MATCH(DMI_SYS_VENDOR, "blue"),
  21955. @@ -423,13 +415,6 @@
  21956. },
  21957. },
  21958. {
  21959. - /* Acer Aspire 7738 */
  21960. - .matches = {
  21961. - DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  21962. - DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7738"),
  21963. - },
  21964. - },
  21965. - {
  21966. /* Gericom Bellagio */
  21967. .matches = {
  21968. DMI_MATCH(DMI_SYS_VENDOR, "Gericom"),
  21969. @@ -743,35 +728,6 @@
  21970. { }
  21971. };
  21972. -/*
  21973. - * Some laptops need keyboard reset before probing for the trackpad to get
  21974. - * it detected, initialised & finally work.
  21975. - */
  21976. -static const struct dmi_system_id __initconst i8042_dmi_kbdreset_table[] = {
  21977. - {
  21978. - /* Gigabyte P35 v2 - Elantech touchpad */
  21979. - .matches = {
  21980. - DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
  21981. - DMI_MATCH(DMI_PRODUCT_NAME, "P35V2"),
  21982. - },
  21983. - },
  21984. - {
  21985. - /* Aorus branded Gigabyte X3 Plus - Elantech touchpad */
  21986. - .matches = {
  21987. - DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
  21988. - DMI_MATCH(DMI_PRODUCT_NAME, "X3"),
  21989. - },
  21990. - },
  21991. - {
  21992. - /* Gigabyte P34 - Elantech touchpad */
  21993. - .matches = {
  21994. - DMI_MATCH(DMI_SYS_VENDOR, "GIGABYTE"),
  21995. - DMI_MATCH(DMI_PRODUCT_NAME, "P34"),
  21996. - },
  21997. - },
  21998. - { }
  21999. -};
  22000. -
  22001. #endif /* CONFIG_X86 */
  22002. #ifdef CONFIG_PNP
  22003. @@ -1067,9 +1023,6 @@
  22004. if (dmi_check_system(i8042_dmi_dritek_table))
  22005. i8042_dritek = true;
  22006. - if (dmi_check_system(i8042_dmi_kbdreset_table))
  22007. - i8042_kbdreset = true;
  22008. -
  22009. /*
  22010. * A20 was already enabled during early kernel init. But some buggy
  22011. * BIOSes (in MSI Laptops) require A20 to be enabled using 8042 to
  22012. diff -Nur linux-3.12.38/drivers/iommu/intel-iommu.c linux-rpi/drivers/iommu/intel-iommu.c
  22013. --- linux-3.12.38/drivers/iommu/intel-iommu.c 2015-02-16 16:15:42.000000000 +0100
  22014. +++ linux-rpi/drivers/iommu/intel-iommu.c 2015-03-10 17:26:50.398216693 +0100
  22015. @@ -1796,7 +1796,7 @@
  22016. struct dma_pte *first_pte = NULL, *pte = NULL;
  22017. phys_addr_t uninitialized_var(pteval);
  22018. int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;
  22019. - unsigned long sg_res = 0;
  22020. + unsigned long sg_res;
  22021. unsigned int largepage_lvl = 0;
  22022. unsigned long lvl_pages = 0;
  22023. @@ -1807,8 +1807,10 @@
  22024. prot &= DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP;
  22025. - if (!sg) {
  22026. - sg_res = nr_pages;
  22027. + if (sg)
  22028. + sg_res = 0;
  22029. + else {
  22030. + sg_res = nr_pages + 1;
  22031. pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | prot;
  22032. }
  22033. diff -Nur linux-3.12.38/drivers/md/bcache/btree.c linux-rpi/drivers/md/bcache/btree.c
  22034. --- linux-3.12.38/drivers/md/bcache/btree.c 2015-02-16 16:15:42.000000000 +0100
  22035. +++ linux-rpi/drivers/md/bcache/btree.c 2015-03-10 17:26:50.414216693 +0100
  22036. @@ -141,7 +141,7 @@
  22037. struct bset *i = b->sets[0].data;
  22038. struct btree_iter *iter;
  22039. - iter = mempool_alloc(b->c->fill_iter, GFP_NOIO);
  22040. + iter = mempool_alloc(b->c->fill_iter, GFP_NOWAIT);
  22041. iter->size = b->c->sb.bucket_size / b->c->sb.block_size;
  22042. iter->used = 0;
  22043. diff -Nur linux-3.12.38/drivers/md/dm.c linux-rpi/drivers/md/dm.c
  22044. --- linux-3.12.38/drivers/md/dm.c 2015-02-16 16:15:42.000000000 +0100
  22045. +++ linux-rpi/drivers/md/dm.c 2015-03-10 17:26:50.422216693 +0100
  22046. @@ -2253,8 +2253,7 @@
  22047. set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags);
  22048. else
  22049. clear_bit(DMF_MERGE_IS_OPTIONAL, &md->flags);
  22050. - if (old_map)
  22051. - dm_sync_table(md);
  22052. + dm_sync_table(md);
  22053. return old_map;
  22054. }
  22055. @@ -2695,8 +2694,7 @@
  22056. * flush_workqueue(md->wq).
  22057. */
  22058. set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
  22059. - if (map)
  22060. - synchronize_srcu(&md->io_barrier);
  22061. + synchronize_srcu(&md->io_barrier);
  22062. /*
  22063. * Stop md->queue before flushing md->wq in case request-based
  22064. @@ -2716,8 +2714,7 @@
  22065. if (noflush)
  22066. clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
  22067. - if (map)
  22068. - synchronize_srcu(&md->io_barrier);
  22069. + synchronize_srcu(&md->io_barrier);
  22070. /* were we interrupted ? */
  22071. if (r < 0) {
  22072. diff -Nur linux-3.12.38/drivers/md/dm-cache-metadata.c linux-rpi/drivers/md/dm-cache-metadata.c
  22073. --- linux-3.12.38/drivers/md/dm-cache-metadata.c 2015-02-16 16:15:42.000000000 +0100
  22074. +++ linux-rpi/drivers/md/dm-cache-metadata.c 2015-03-10 17:26:50.418216693 +0100
  22075. @@ -88,9 +88,6 @@
  22076. } __packed;
  22077. struct dm_cache_metadata {
  22078. - atomic_t ref_count;
  22079. - struct list_head list;
  22080. -
  22081. struct block_device *bdev;
  22082. struct dm_block_manager *bm;
  22083. struct dm_space_map *metadata_sm;
  22084. @@ -653,10 +650,10 @@
  22085. /*----------------------------------------------------------------*/
  22086. -static struct dm_cache_metadata *metadata_open(struct block_device *bdev,
  22087. - sector_t data_block_size,
  22088. - bool may_format_device,
  22089. - size_t policy_hint_size)
  22090. +struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
  22091. + sector_t data_block_size,
  22092. + bool may_format_device,
  22093. + size_t policy_hint_size)
  22094. {
  22095. int r;
  22096. struct dm_cache_metadata *cmd;
  22097. @@ -664,10 +661,9 @@
  22098. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  22099. if (!cmd) {
  22100. DMERR("could not allocate metadata struct");
  22101. - return ERR_PTR(-ENOMEM);
  22102. + return NULL;
  22103. }
  22104. - atomic_set(&cmd->ref_count, 1);
  22105. init_rwsem(&cmd->root_lock);
  22106. cmd->bdev = bdev;
  22107. cmd->data_block_size = data_block_size;
  22108. @@ -690,96 +686,10 @@
  22109. return cmd;
  22110. }
  22111. -/*
  22112. - * We keep a little list of ref counted metadata objects to prevent two
  22113. - * different target instances creating separate bufio instances. This is
  22114. - * an issue if a table is reloaded before the suspend.
  22115. - */
  22116. -static DEFINE_MUTEX(table_lock);
  22117. -static LIST_HEAD(table);
  22118. -
  22119. -static struct dm_cache_metadata *lookup(struct block_device *bdev)
  22120. -{
  22121. - struct dm_cache_metadata *cmd;
  22122. -
  22123. - list_for_each_entry(cmd, &table, list)
  22124. - if (cmd->bdev == bdev) {
  22125. - atomic_inc(&cmd->ref_count);
  22126. - return cmd;
  22127. - }
  22128. -
  22129. - return NULL;
  22130. -}
  22131. -
  22132. -static struct dm_cache_metadata *lookup_or_open(struct block_device *bdev,
  22133. - sector_t data_block_size,
  22134. - bool may_format_device,
  22135. - size_t policy_hint_size)
  22136. -{
  22137. - struct dm_cache_metadata *cmd, *cmd2;
  22138. -
  22139. - mutex_lock(&table_lock);
  22140. - cmd = lookup(bdev);
  22141. - mutex_unlock(&table_lock);
  22142. -
  22143. - if (cmd)
  22144. - return cmd;
  22145. -
  22146. - cmd = metadata_open(bdev, data_block_size, may_format_device, policy_hint_size);
  22147. - if (!IS_ERR(cmd)) {
  22148. - mutex_lock(&table_lock);
  22149. - cmd2 = lookup(bdev);
  22150. - if (cmd2) {
  22151. - mutex_unlock(&table_lock);
  22152. - __destroy_persistent_data_objects(cmd);
  22153. - kfree(cmd);
  22154. - return cmd2;
  22155. - }
  22156. - list_add(&cmd->list, &table);
  22157. - mutex_unlock(&table_lock);
  22158. - }
  22159. -
  22160. - return cmd;
  22161. -}
  22162. -
  22163. -static bool same_params(struct dm_cache_metadata *cmd, sector_t data_block_size)
  22164. -{
  22165. - if (cmd->data_block_size != data_block_size) {
  22166. - DMERR("data_block_size (%llu) different from that in metadata (%llu)\n",
  22167. - (unsigned long long) data_block_size,
  22168. - (unsigned long long) cmd->data_block_size);
  22169. - return false;
  22170. - }
  22171. -
  22172. - return true;
  22173. -}
  22174. -
  22175. -struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
  22176. - sector_t data_block_size,
  22177. - bool may_format_device,
  22178. - size_t policy_hint_size)
  22179. -{
  22180. - struct dm_cache_metadata *cmd = lookup_or_open(bdev, data_block_size,
  22181. - may_format_device, policy_hint_size);
  22182. -
  22183. - if (!IS_ERR(cmd) && !same_params(cmd, data_block_size)) {
  22184. - dm_cache_metadata_close(cmd);
  22185. - return ERR_PTR(-EINVAL);
  22186. - }
  22187. -
  22188. - return cmd;
  22189. -}
  22190. -
  22191. void dm_cache_metadata_close(struct dm_cache_metadata *cmd)
  22192. {
  22193. - if (atomic_dec_and_test(&cmd->ref_count)) {
  22194. - mutex_lock(&table_lock);
  22195. - list_del(&cmd->list);
  22196. - mutex_unlock(&table_lock);
  22197. -
  22198. - __destroy_persistent_data_objects(cmd);
  22199. - kfree(cmd);
  22200. - }
  22201. + __destroy_persistent_data_objects(cmd);
  22202. + kfree(cmd);
  22203. }
  22204. int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size)
  22205. diff -Nur linux-3.12.38/drivers/md/dm-cache-target.c linux-rpi/drivers/md/dm-cache-target.c
  22206. --- linux-3.12.38/drivers/md/dm-cache-target.c 2015-02-16 16:15:42.000000000 +0100
  22207. +++ linux-rpi/drivers/md/dm-cache-target.c 2015-03-10 17:26:50.418216693 +0100
  22208. @@ -146,13 +146,7 @@
  22209. struct list_head need_commit_migrations;
  22210. sector_t migration_threshold;
  22211. wait_queue_head_t migration_wait;
  22212. - atomic_t nr_allocated_migrations;
  22213. -
  22214. - /*
  22215. - * The number of in flight migrations that are performing
  22216. - * background io. eg, promotion, writeback.
  22217. - */
  22218. - atomic_t nr_io_migrations;
  22219. + atomic_t nr_migrations;
  22220. wait_queue_head_t quiescing_wait;
  22221. atomic_t quiescing_ack;
  22222. @@ -188,6 +182,7 @@
  22223. struct dm_deferred_set *all_io_ds;
  22224. mempool_t *migration_pool;
  22225. + struct dm_cache_migration *next_migration;
  22226. struct dm_cache_policy *policy;
  22227. unsigned policy_nr_args;
  22228. @@ -270,31 +265,10 @@
  22229. dm_bio_prison_free_cell(cache->prison, cell);
  22230. }
  22231. -static struct dm_cache_migration *alloc_migration(struct cache *cache)
  22232. -{
  22233. - struct dm_cache_migration *mg;
  22234. -
  22235. - mg = mempool_alloc(cache->migration_pool, GFP_NOWAIT);
  22236. - if (mg) {
  22237. - mg->cache = cache;
  22238. - atomic_inc(&mg->cache->nr_allocated_migrations);
  22239. - }
  22240. -
  22241. - return mg;
  22242. -}
  22243. -
  22244. -static void free_migration(struct dm_cache_migration *mg)
  22245. -{
  22246. - if (atomic_dec_and_test(&mg->cache->nr_allocated_migrations))
  22247. - wake_up(&mg->cache->migration_wait);
  22248. -
  22249. - mempool_free(mg, mg->cache->migration_pool);
  22250. -}
  22251. -
  22252. static int prealloc_data_structs(struct cache *cache, struct prealloc *p)
  22253. {
  22254. if (!p->mg) {
  22255. - p->mg = alloc_migration(cache);
  22256. + p->mg = mempool_alloc(cache->migration_pool, GFP_NOWAIT);
  22257. if (!p->mg)
  22258. return -ENOMEM;
  22259. }
  22260. @@ -323,7 +297,7 @@
  22261. free_prison_cell(cache, p->cell1);
  22262. if (p->mg)
  22263. - free_migration(p->mg);
  22264. + mempool_free(p->mg, cache->migration_pool);
  22265. }
  22266. static struct dm_cache_migration *prealloc_get_migration(struct prealloc *p)
  22267. @@ -734,14 +708,24 @@
  22268. * Migration covers moving data from the origin device to the cache, or
  22269. * vice versa.
  22270. *--------------------------------------------------------------*/
  22271. -static void inc_io_migrations(struct cache *cache)
  22272. +static void free_migration(struct dm_cache_migration *mg)
  22273. +{
  22274. + mempool_free(mg, mg->cache->migration_pool);
  22275. +}
  22276. +
  22277. +static void inc_nr_migrations(struct cache *cache)
  22278. {
  22279. - atomic_inc(&cache->nr_io_migrations);
  22280. + atomic_inc(&cache->nr_migrations);
  22281. }
  22282. -static void dec_io_migrations(struct cache *cache)
  22283. +static void dec_nr_migrations(struct cache *cache)
  22284. {
  22285. - atomic_dec(&cache->nr_io_migrations);
  22286. + atomic_dec(&cache->nr_migrations);
  22287. +
  22288. + /*
  22289. + * Wake the worker in case we're suspending the target.
  22290. + */
  22291. + wake_up(&cache->migration_wait);
  22292. }
  22293. static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell,
  22294. @@ -764,10 +748,11 @@
  22295. wake_worker(cache);
  22296. }
  22297. -static void free_io_migration(struct dm_cache_migration *mg)
  22298. +static void cleanup_migration(struct dm_cache_migration *mg)
  22299. {
  22300. - dec_io_migrations(mg->cache);
  22301. + struct cache *cache = mg->cache;
  22302. free_migration(mg);
  22303. + dec_nr_migrations(cache);
  22304. }
  22305. static void migration_failure(struct dm_cache_migration *mg)
  22306. @@ -792,7 +777,7 @@
  22307. cell_defer(cache, mg->new_ocell, 1);
  22308. }
  22309. - free_io_migration(mg);
  22310. + cleanup_migration(mg);
  22311. }
  22312. static void migration_success_pre_commit(struct dm_cache_migration *mg)
  22313. @@ -803,7 +788,7 @@
  22314. if (mg->writeback) {
  22315. clear_dirty(cache, mg->old_oblock, mg->cblock);
  22316. cell_defer(cache, mg->old_ocell, false);
  22317. - free_io_migration(mg);
  22318. + cleanup_migration(mg);
  22319. return;
  22320. } else if (mg->demote) {
  22321. @@ -813,14 +798,14 @@
  22322. mg->old_oblock);
  22323. if (mg->promote)
  22324. cell_defer(cache, mg->new_ocell, true);
  22325. - free_io_migration(mg);
  22326. + cleanup_migration(mg);
  22327. return;
  22328. }
  22329. } else {
  22330. if (dm_cache_insert_mapping(cache->cmd, mg->cblock, mg->new_oblock)) {
  22331. DMWARN_LIMIT("promotion failed; couldn't update on disk metadata");
  22332. policy_remove_mapping(cache->policy, mg->new_oblock);
  22333. - free_io_migration(mg);
  22334. + cleanup_migration(mg);
  22335. return;
  22336. }
  22337. }
  22338. @@ -851,12 +836,12 @@
  22339. spin_unlock_irqrestore(&cache->lock, flags);
  22340. } else
  22341. - free_io_migration(mg);
  22342. + cleanup_migration(mg);
  22343. } else {
  22344. clear_dirty(cache, mg->new_oblock, mg->cblock);
  22345. cell_defer(cache, mg->new_ocell, true);
  22346. - free_io_migration(mg);
  22347. + cleanup_migration(mg);
  22348. }
  22349. }
  22350. @@ -1017,7 +1002,7 @@
  22351. mg->new_ocell = cell;
  22352. mg->start_jiffies = jiffies;
  22353. - inc_io_migrations(cache);
  22354. + inc_nr_migrations(cache);
  22355. quiesce_migration(mg);
  22356. }
  22357. @@ -1038,7 +1023,7 @@
  22358. mg->new_ocell = NULL;
  22359. mg->start_jiffies = jiffies;
  22360. - inc_io_migrations(cache);
  22361. + inc_nr_migrations(cache);
  22362. quiesce_migration(mg);
  22363. }
  22364. @@ -1062,7 +1047,7 @@
  22365. mg->new_ocell = new_ocell;
  22366. mg->start_jiffies = jiffies;
  22367. - inc_io_migrations(cache);
  22368. + inc_nr_migrations(cache);
  22369. quiesce_migration(mg);
  22370. }
  22371. @@ -1123,7 +1108,7 @@
  22372. static bool spare_migration_bandwidth(struct cache *cache)
  22373. {
  22374. - sector_t current_volume = (atomic_read(&cache->nr_io_migrations) + 1) *
  22375. + sector_t current_volume = (atomic_read(&cache->nr_migrations) + 1) *
  22376. cache->sectors_per_block;
  22377. return current_volume < cache->migration_threshold;
  22378. }
  22379. @@ -1414,7 +1399,7 @@
  22380. static void wait_for_migrations(struct cache *cache)
  22381. {
  22382. - wait_event(cache->migration_wait, !atomic_read(&cache->nr_allocated_migrations));
  22383. + wait_event(cache->migration_wait, !atomic_read(&cache->nr_migrations));
  22384. }
  22385. static void stop_worker(struct cache *cache)
  22386. @@ -1523,6 +1508,9 @@
  22387. {
  22388. unsigned i;
  22389. + if (cache->next_migration)
  22390. + mempool_free(cache->next_migration, cache->migration_pool);
  22391. +
  22392. if (cache->migration_pool)
  22393. mempool_destroy(cache->migration_pool);
  22394. @@ -2010,8 +1998,7 @@
  22395. INIT_LIST_HEAD(&cache->quiesced_migrations);
  22396. INIT_LIST_HEAD(&cache->completed_migrations);
  22397. INIT_LIST_HEAD(&cache->need_commit_migrations);
  22398. - atomic_set(&cache->nr_allocated_migrations, 0);
  22399. - atomic_set(&cache->nr_io_migrations, 0);
  22400. + atomic_set(&cache->nr_migrations, 0);
  22401. init_waitqueue_head(&cache->migration_wait);
  22402. init_waitqueue_head(&cache->quiescing_wait);
  22403. @@ -2070,6 +2057,8 @@
  22404. goto bad;
  22405. }
  22406. + cache->next_migration = NULL;
  22407. +
  22408. cache->need_tick_bio = true;
  22409. cache->sized = false;
  22410. cache->quiescing = false;
  22411. diff -Nur linux-3.12.38/drivers/md/dm-thin.c linux-rpi/drivers/md/dm-thin.c
  22412. --- linux-3.12.38/drivers/md/dm-thin.c 2015-02-16 16:15:42.000000000 +0100
  22413. +++ linux-rpi/drivers/md/dm-thin.c 2015-03-10 17:26:50.422216693 +0100
  22414. @@ -2507,12 +2507,6 @@
  22415. struct pool_c *pt = ti->private;
  22416. struct pool *pool = pt->pool;
  22417. - if (get_pool_mode(pool) >= PM_READ_ONLY) {
  22418. - DMERR("%s: unable to service pool target messages in READ_ONLY or FAIL mode",
  22419. - dm_device_name(pool->pool_md));
  22420. - return -EINVAL;
  22421. - }
  22422. -
  22423. if (!strcasecmp(argv[0], "create_thin"))
  22424. r = process_create_thin_mesg(argc, argv, pool);
  22425. diff -Nur linux-3.12.38/drivers/md/raid5.c linux-rpi/drivers/md/raid5.c
  22426. --- linux-3.12.38/drivers/md/raid5.c 2015-02-16 16:15:42.000000000 +0100
  22427. +++ linux-rpi/drivers/md/raid5.c 2015-03-10 17:26:50.426216693 +0100
  22428. @@ -2789,8 +2789,7 @@
  22429. (s->failed >= 2 && fdev[1]->toread) ||
  22430. (sh->raid_conf->level <= 5 && s->failed && fdev[0]->towrite &&
  22431. !test_bit(R5_OVERWRITE, &fdev[0]->flags)) ||
  22432. - ((sh->raid_conf->level == 6 || sh->sector >= sh->raid_conf->mddev->recovery_cp)
  22433. - && s->failed && s->to_write))) {
  22434. + (sh->raid_conf->level == 6 && s->failed && s->to_write))) {
  22435. /* we would like to get this block, possibly by computing it,
  22436. * otherwise read it if the backing disk is insync
  22437. */
  22438. diff -Nur linux-3.12.38/drivers/media/i2c/smiapp/smiapp-core.c linux-rpi/drivers/media/i2c/smiapp/smiapp-core.c
  22439. --- linux-3.12.38/drivers/media/i2c/smiapp/smiapp-core.c 2015-02-16 16:15:42.000000000 +0100
  22440. +++ linux-rpi/drivers/media/i2c/smiapp/smiapp-core.c 2015-03-10 17:26:50.446216693 +0100
  22441. @@ -2625,9 +2625,7 @@
  22442. pll->flags |= SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE;
  22443. pll->scale_n = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
  22444. - mutex_lock(&sensor->mutex);
  22445. rval = smiapp_update_mode(sensor);
  22446. - mutex_unlock(&sensor->mutex);
  22447. if (rval) {
  22448. dev_err(&client->dev, "update mode failed\n");
  22449. goto out_nvm_release;
  22450. diff -Nur linux-3.12.38/drivers/media/i2c/smiapp-pll.c linux-rpi/drivers/media/i2c/smiapp-pll.c
  22451. --- linux-3.12.38/drivers/media/i2c/smiapp-pll.c 2015-02-16 16:15:42.000000000 +0100
  22452. +++ linux-rpi/drivers/media/i2c/smiapp-pll.c 2015-03-10 17:26:50.442216693 +0100
  22453. @@ -67,7 +67,7 @@
  22454. {
  22455. dev_dbg(dev, "pre_pll_clk_div\t%d\n", pll->pre_pll_clk_div);
  22456. dev_dbg(dev, "pll_multiplier \t%d\n", pll->pll_multiplier);
  22457. - if (!(pll->flags & SMIAPP_PLL_FLAG_NO_OP_CLOCKS)) {
  22458. + if (pll->flags != SMIAPP_PLL_FLAG_NO_OP_CLOCKS) {
  22459. dev_dbg(dev, "op_sys_clk_div \t%d\n", pll->op_sys_clk_div);
  22460. dev_dbg(dev, "op_pix_clk_div \t%d\n", pll->op_pix_clk_div);
  22461. }
  22462. @@ -77,7 +77,7 @@
  22463. dev_dbg(dev, "ext_clk_freq_hz \t%d\n", pll->ext_clk_freq_hz);
  22464. dev_dbg(dev, "pll_ip_clk_freq_hz \t%d\n", pll->pll_ip_clk_freq_hz);
  22465. dev_dbg(dev, "pll_op_clk_freq_hz \t%d\n", pll->pll_op_clk_freq_hz);
  22466. - if (!(pll->flags & SMIAPP_PLL_FLAG_NO_OP_CLOCKS)) {
  22467. + if (pll->flags & SMIAPP_PLL_FLAG_NO_OP_CLOCKS) {
  22468. dev_dbg(dev, "op_sys_clk_freq_hz \t%d\n",
  22469. pll->op_sys_clk_freq_hz);
  22470. dev_dbg(dev, "op_pix_clk_freq_hz \t%d\n",
  22471. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  22472. --- linux-3.12.38/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  22473. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2015-03-10 17:26:50.466216693 +0100
  22474. @@ -0,0 +1,1827 @@
  22475. +/*
  22476. + * Broadcom BM2835 V4L2 driver
  22477. + *
  22478. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  22479. + *
  22480. + * This file is subject to the terms and conditions of the GNU General Public
  22481. + * License. See the file COPYING in the main directory of this archive
  22482. + * for more details.
  22483. + *
  22484. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  22485. + * Dave Stevenson <dsteve@broadcom.com>
  22486. + * Simon Mellor <simellor@broadcom.com>
  22487. + * Luke Diamand <luked@broadcom.com>
  22488. + */
  22489. +
  22490. +#include <linux/errno.h>
  22491. +#include <linux/kernel.h>
  22492. +#include <linux/module.h>
  22493. +#include <linux/slab.h>
  22494. +#include <media/videobuf2-vmalloc.h>
  22495. +#include <media/videobuf2-dma-contig.h>
  22496. +#include <media/v4l2-device.h>
  22497. +#include <media/v4l2-ioctl.h>
  22498. +#include <media/v4l2-ctrls.h>
  22499. +#include <media/v4l2-fh.h>
  22500. +#include <media/v4l2-event.h>
  22501. +#include <media/v4l2-common.h>
  22502. +#include <linux/delay.h>
  22503. +
  22504. +#include "mmal-common.h"
  22505. +#include "mmal-encodings.h"
  22506. +#include "mmal-vchiq.h"
  22507. +#include "mmal-msg.h"
  22508. +#include "mmal-parameters.h"
  22509. +#include "bcm2835-camera.h"
  22510. +
  22511. +#define BM2835_MMAL_VERSION "0.0.2"
  22512. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  22513. +#define MIN_WIDTH 16
  22514. +#define MIN_HEIGHT 16
  22515. +#define MAX_WIDTH 2592
  22516. +#define MAX_HEIGHT 1944
  22517. +#define MIN_BUFFER_SIZE (80*1024)
  22518. +
  22519. +#define MAX_VIDEO_MODE_WIDTH 1280
  22520. +#define MAX_VIDEO_MODE_HEIGHT 720
  22521. +
  22522. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  22523. +MODULE_AUTHOR("Vincent Sanders");
  22524. +MODULE_LICENSE("GPL");
  22525. +MODULE_VERSION(BM2835_MMAL_VERSION);
  22526. +
  22527. +int bcm2835_v4l2_debug;
  22528. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  22529. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  22530. +
  22531. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  22532. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  22533. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  22534. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  22535. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  22536. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  22537. +
  22538. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  22539. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  22540. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  22541. + * It's happier if we just don't say anything at all, when it then
  22542. + * sets up a load of defaults that it thinks might work.
  22543. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  22544. + * our function table list (actually switch to an alternate set, but same
  22545. + * result).
  22546. + */
  22547. +int gst_v4l2src_is_broken = 0;
  22548. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  22549. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  22550. +
  22551. +static struct bm2835_mmal_dev *gdev; /* global device data */
  22552. +
  22553. +#define FPS_MIN 1
  22554. +#define FPS_MAX 90
  22555. +
  22556. +/* timeperframe: min/max and default */
  22557. +static const struct v4l2_fract
  22558. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  22559. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  22560. + tpf_default = {.numerator = 1000, .denominator = 30000};
  22561. +
  22562. +/* video formats */
  22563. +static struct mmal_fmt formats[] = {
  22564. + {
  22565. + .name = "4:2:0, packed YUV",
  22566. + .fourcc = V4L2_PIX_FMT_YUV420,
  22567. + .flags = 0,
  22568. + .mmal = MMAL_ENCODING_I420,
  22569. + .depth = 12,
  22570. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22571. + },
  22572. + {
  22573. + .name = "4:2:2, packed, YUYV",
  22574. + .fourcc = V4L2_PIX_FMT_YUYV,
  22575. + .flags = 0,
  22576. + .mmal = MMAL_ENCODING_YUYV,
  22577. + .depth = 16,
  22578. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22579. + },
  22580. + {
  22581. + .name = "RGB24 (LE)",
  22582. + .fourcc = V4L2_PIX_FMT_RGB24,
  22583. + .flags = 0,
  22584. + .mmal = MMAL_ENCODING_BGR24,
  22585. + .depth = 24,
  22586. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22587. + },
  22588. + {
  22589. + .name = "JPEG",
  22590. + .fourcc = V4L2_PIX_FMT_JPEG,
  22591. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  22592. + .mmal = MMAL_ENCODING_JPEG,
  22593. + .depth = 8,
  22594. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  22595. + },
  22596. + {
  22597. + .name = "H264",
  22598. + .fourcc = V4L2_PIX_FMT_H264,
  22599. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  22600. + .mmal = MMAL_ENCODING_H264,
  22601. + .depth = 8,
  22602. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  22603. + },
  22604. + {
  22605. + .name = "MJPEG",
  22606. + .fourcc = V4L2_PIX_FMT_MJPEG,
  22607. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  22608. + .mmal = MMAL_ENCODING_MJPEG,
  22609. + .depth = 8,
  22610. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  22611. + },
  22612. + {
  22613. + .name = "4:2:2, packed, YVYU",
  22614. + .fourcc = V4L2_PIX_FMT_YVYU,
  22615. + .flags = 0,
  22616. + .mmal = MMAL_ENCODING_YVYU,
  22617. + .depth = 16,
  22618. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22619. + },
  22620. + {
  22621. + .name = "4:2:2, packed, VYUY",
  22622. + .fourcc = V4L2_PIX_FMT_VYUY,
  22623. + .flags = 0,
  22624. + .mmal = MMAL_ENCODING_VYUY,
  22625. + .depth = 16,
  22626. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22627. + },
  22628. + {
  22629. + .name = "4:2:2, packed, UYVY",
  22630. + .fourcc = V4L2_PIX_FMT_UYVY,
  22631. + .flags = 0,
  22632. + .mmal = MMAL_ENCODING_UYVY,
  22633. + .depth = 16,
  22634. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22635. + },
  22636. + {
  22637. + .name = "4:2:0, packed, NV12",
  22638. + .fourcc = V4L2_PIX_FMT_NV12,
  22639. + .flags = 0,
  22640. + .mmal = MMAL_ENCODING_NV12,
  22641. + .depth = 12,
  22642. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22643. + },
  22644. + {
  22645. + .name = "RGB24 (BE)",
  22646. + .fourcc = V4L2_PIX_FMT_BGR24,
  22647. + .flags = 0,
  22648. + .mmal = MMAL_ENCODING_RGB24,
  22649. + .depth = 24,
  22650. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22651. + },
  22652. + {
  22653. + .name = "4:2:0, packed YVU",
  22654. + .fourcc = V4L2_PIX_FMT_YVU420,
  22655. + .flags = 0,
  22656. + .mmal = MMAL_ENCODING_YV12,
  22657. + .depth = 12,
  22658. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22659. + },
  22660. + {
  22661. + .name = "4:2:0, packed, NV21",
  22662. + .fourcc = V4L2_PIX_FMT_NV21,
  22663. + .flags = 0,
  22664. + .mmal = MMAL_ENCODING_NV21,
  22665. + .depth = 12,
  22666. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22667. + },
  22668. + {
  22669. + .name = "RGB32 (BE)",
  22670. + .fourcc = V4L2_PIX_FMT_BGR32,
  22671. + .flags = 0,
  22672. + .mmal = MMAL_ENCODING_BGRA,
  22673. + .depth = 32,
  22674. + .mmal_component = MMAL_COMPONENT_CAMERA,
  22675. + },
  22676. +};
  22677. +
  22678. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  22679. +{
  22680. + struct mmal_fmt *fmt;
  22681. + unsigned int k;
  22682. +
  22683. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  22684. + fmt = &formats[k];
  22685. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  22686. + break;
  22687. + }
  22688. +
  22689. + if (k == ARRAY_SIZE(formats))
  22690. + return NULL;
  22691. +
  22692. + return &formats[k];
  22693. +}
  22694. +
  22695. +/* ------------------------------------------------------------------
  22696. + Videobuf queue operations
  22697. + ------------------------------------------------------------------*/
  22698. +
  22699. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  22700. + unsigned int *nbuffers, unsigned int *nplanes,
  22701. + unsigned int sizes[], void *alloc_ctxs[])
  22702. +{
  22703. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  22704. + unsigned long size;
  22705. +
  22706. + /* refuse queue setup if port is not configured */
  22707. + if (dev->capture.port == NULL) {
  22708. + v4l2_err(&dev->v4l2_dev,
  22709. + "%s: capture port not configured\n", __func__);
  22710. + return -EINVAL;
  22711. + }
  22712. +
  22713. + size = dev->capture.port->current_buffer.size;
  22714. + if (size == 0) {
  22715. + v4l2_err(&dev->v4l2_dev,
  22716. + "%s: capture port buffer size is zero\n", __func__);
  22717. + return -EINVAL;
  22718. + }
  22719. +
  22720. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  22721. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  22722. +
  22723. + *nplanes = 1;
  22724. +
  22725. + sizes[0] = size;
  22726. +
  22727. + /*
  22728. + * videobuf2-vmalloc allocator is context-less so no need to set
  22729. + * alloc_ctxs array.
  22730. + */
  22731. +
  22732. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  22733. + __func__, dev);
  22734. +
  22735. + return 0;
  22736. +}
  22737. +
  22738. +static int buffer_prepare(struct vb2_buffer *vb)
  22739. +{
  22740. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  22741. + unsigned long size;
  22742. +
  22743. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  22744. + __func__, dev);
  22745. +
  22746. + BUG_ON(dev->capture.port == NULL);
  22747. + BUG_ON(dev->capture.fmt == NULL);
  22748. +
  22749. + size = dev->capture.stride * dev->capture.height;
  22750. + if (vb2_plane_size(vb, 0) < size) {
  22751. + v4l2_err(&dev->v4l2_dev,
  22752. + "%s data will not fit into plane (%lu < %lu)\n",
  22753. + __func__, vb2_plane_size(vb, 0), size);
  22754. + return -EINVAL;
  22755. + }
  22756. +
  22757. + return 0;
  22758. +}
  22759. +
  22760. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  22761. +{
  22762. + return dev->capture.camera_port ==
  22763. + &dev->
  22764. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  22765. +}
  22766. +
  22767. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  22768. + struct vchiq_mmal_port *port,
  22769. + int status,
  22770. + struct mmal_buffer *buf,
  22771. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  22772. +{
  22773. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  22774. +
  22775. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22776. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  22777. + __func__, status, buf, length, mmal_flags, pts);
  22778. +
  22779. + if (status != 0) {
  22780. + /* error in transfer */
  22781. + if (buf != NULL) {
  22782. + /* there was a buffer with the error so return it */
  22783. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  22784. + }
  22785. + return;
  22786. + } else if (length == 0) {
  22787. + /* stream ended */
  22788. + if (buf != NULL) {
  22789. + /* this should only ever happen if the port is
  22790. + * disabled and there are buffers still queued
  22791. + */
  22792. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  22793. + pr_debug("Empty buffer");
  22794. + } else if (dev->capture.frame_count) {
  22795. + /* grab another frame */
  22796. + if (is_capturing(dev)) {
  22797. + pr_debug("Grab another frame");
  22798. + vchiq_mmal_port_parameter_set(
  22799. + instance,
  22800. + dev->capture.
  22801. + camera_port,
  22802. + MMAL_PARAMETER_CAPTURE,
  22803. + &dev->capture.
  22804. + frame_count,
  22805. + sizeof(dev->capture.frame_count));
  22806. + }
  22807. + } else {
  22808. + /* signal frame completion */
  22809. + complete(&dev->capture.frame_cmplt);
  22810. + }
  22811. + } else {
  22812. + if (dev->capture.frame_count) {
  22813. + if (dev->capture.vc_start_timestamp != -1 &&
  22814. + pts != 0) {
  22815. + s64 runtime_us = pts -
  22816. + dev->capture.vc_start_timestamp;
  22817. + u32 div = 0;
  22818. + u32 rem = 0;
  22819. +
  22820. + div =
  22821. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  22822. + buf->vb.v4l2_buf.timestamp.tv_sec =
  22823. + dev->capture.kernel_start_ts.tv_sec - 1 +
  22824. + div;
  22825. + buf->vb.v4l2_buf.timestamp.tv_usec =
  22826. + dev->capture.kernel_start_ts.tv_usec + rem;
  22827. +
  22828. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  22829. + USEC_PER_SEC) {
  22830. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  22831. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  22832. + USEC_PER_SEC;
  22833. + }
  22834. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22835. + "Convert start time %d.%06d and %llu "
  22836. + "with offset %llu to %d.%06d\n",
  22837. + (int)dev->capture.kernel_start_ts.
  22838. + tv_sec,
  22839. + (int)dev->capture.kernel_start_ts.
  22840. + tv_usec,
  22841. + dev->capture.vc_start_timestamp, pts,
  22842. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  22843. + (int)buf->vb.v4l2_buf.timestamp.
  22844. + tv_usec);
  22845. + } else {
  22846. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  22847. + }
  22848. +
  22849. + vb2_set_plane_payload(&buf->vb, 0, length);
  22850. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  22851. +
  22852. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  22853. + is_capturing(dev)) {
  22854. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22855. + "Grab another frame as buffer has EOS");
  22856. + vchiq_mmal_port_parameter_set(
  22857. + instance,
  22858. + dev->capture.
  22859. + camera_port,
  22860. + MMAL_PARAMETER_CAPTURE,
  22861. + &dev->capture.
  22862. + frame_count,
  22863. + sizeof(dev->capture.frame_count));
  22864. + }
  22865. + } else {
  22866. + /* signal frame completion */
  22867. + complete(&dev->capture.frame_cmplt);
  22868. + }
  22869. + }
  22870. +}
  22871. +
  22872. +static int enable_camera(struct bm2835_mmal_dev *dev)
  22873. +{
  22874. + int ret;
  22875. + if (!dev->camera_use_count) {
  22876. + ret = vchiq_mmal_component_enable(
  22877. + dev->instance,
  22878. + dev->component[MMAL_COMPONENT_CAMERA]);
  22879. + if (ret < 0) {
  22880. + v4l2_err(&dev->v4l2_dev,
  22881. + "Failed enabling camera, ret %d\n", ret);
  22882. + return -EINVAL;
  22883. + }
  22884. + }
  22885. + dev->camera_use_count++;
  22886. + v4l2_dbg(1, bcm2835_v4l2_debug,
  22887. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  22888. + dev->camera_use_count);
  22889. + return 0;
  22890. +}
  22891. +
  22892. +static int disable_camera(struct bm2835_mmal_dev *dev)
  22893. +{
  22894. + int ret;
  22895. + if (!dev->camera_use_count) {
  22896. + v4l2_err(&dev->v4l2_dev,
  22897. + "Disabled the camera when already disabled\n");
  22898. + return -EINVAL;
  22899. + }
  22900. + dev->camera_use_count--;
  22901. + if (!dev->camera_use_count) {
  22902. + unsigned int i = 0xFFFFFFFF;
  22903. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22904. + "Disabling camera\n");
  22905. + ret =
  22906. + vchiq_mmal_component_disable(
  22907. + dev->instance,
  22908. + dev->component[MMAL_COMPONENT_CAMERA]);
  22909. + if (ret < 0) {
  22910. + v4l2_err(&dev->v4l2_dev,
  22911. + "Failed disabling camera, ret %d\n", ret);
  22912. + return -EINVAL;
  22913. + }
  22914. + vchiq_mmal_port_parameter_set(
  22915. + dev->instance,
  22916. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  22917. + MMAL_PARAMETER_CAMERA_NUM, &i,
  22918. + sizeof(i));
  22919. + }
  22920. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22921. + "Camera refcount now %d\n", dev->camera_use_count);
  22922. + return 0;
  22923. +}
  22924. +
  22925. +static void buffer_queue(struct vb2_buffer *vb)
  22926. +{
  22927. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  22928. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  22929. + int ret;
  22930. +
  22931. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22932. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  22933. +
  22934. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  22935. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  22936. +
  22937. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  22938. + if (ret < 0)
  22939. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  22940. + __func__);
  22941. +}
  22942. +
  22943. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  22944. +{
  22945. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  22946. + int ret;
  22947. + int parameter_size;
  22948. +
  22949. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  22950. + __func__, dev);
  22951. +
  22952. + /* ensure a format has actually been set */
  22953. + if (dev->capture.port == NULL)
  22954. + return -EINVAL;
  22955. +
  22956. + if (enable_camera(dev) < 0) {
  22957. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  22958. + return -EINVAL;
  22959. + }
  22960. +
  22961. + /*init_completion(&dev->capture.frame_cmplt); */
  22962. +
  22963. + /* enable frame capture */
  22964. + dev->capture.frame_count = 1;
  22965. +
  22966. + /* if the preview is not already running, wait for a few frames for AGC
  22967. + * to settle down.
  22968. + */
  22969. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  22970. + msleep(300);
  22971. +
  22972. + /* enable the connection from camera to encoder (if applicable) */
  22973. + if (dev->capture.camera_port != dev->capture.port
  22974. + && dev->capture.camera_port) {
  22975. + ret = vchiq_mmal_port_enable(dev->instance,
  22976. + dev->capture.camera_port, NULL);
  22977. + if (ret) {
  22978. + v4l2_err(&dev->v4l2_dev,
  22979. + "Failed to enable encode tunnel - error %d\n",
  22980. + ret);
  22981. + return -1;
  22982. + }
  22983. + }
  22984. +
  22985. + /* Get VC timestamp at this point in time */
  22986. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  22987. + if (vchiq_mmal_port_parameter_get(dev->instance,
  22988. + dev->capture.camera_port,
  22989. + MMAL_PARAMETER_SYSTEM_TIME,
  22990. + &dev->capture.vc_start_timestamp,
  22991. + &parameter_size)) {
  22992. + v4l2_err(&dev->v4l2_dev,
  22993. + "Failed to get VC start time - update your VC f/w\n");
  22994. +
  22995. + /* Flag to indicate just to rely on kernel timestamps */
  22996. + dev->capture.vc_start_timestamp = -1;
  22997. + } else
  22998. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  22999. + "Start time %lld size %d\n",
  23000. + dev->capture.vc_start_timestamp, parameter_size);
  23001. +
  23002. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  23003. +
  23004. + /* enable the camera port */
  23005. + dev->capture.port->cb_ctx = dev;
  23006. + ret =
  23007. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  23008. + if (ret) {
  23009. + v4l2_err(&dev->v4l2_dev,
  23010. + "Failed to enable capture port - error %d. "
  23011. + "Disabling camera port again\n", ret);
  23012. +
  23013. + vchiq_mmal_port_disable(dev->instance,
  23014. + dev->capture.camera_port);
  23015. + if (disable_camera(dev) < 0) {
  23016. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  23017. + return -EINVAL;
  23018. + }
  23019. + return -1;
  23020. + }
  23021. +
  23022. + /* capture the first frame */
  23023. + vchiq_mmal_port_parameter_set(dev->instance,
  23024. + dev->capture.camera_port,
  23025. + MMAL_PARAMETER_CAPTURE,
  23026. + &dev->capture.frame_count,
  23027. + sizeof(dev->capture.frame_count));
  23028. + return 0;
  23029. +}
  23030. +
  23031. +/* abort streaming and wait for last buffer */
  23032. +static int stop_streaming(struct vb2_queue *vq)
  23033. +{
  23034. + int ret;
  23035. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  23036. +
  23037. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  23038. + __func__, dev);
  23039. +
  23040. + init_completion(&dev->capture.frame_cmplt);
  23041. + dev->capture.frame_count = 0;
  23042. +
  23043. + /* ensure a format has actually been set */
  23044. + if (dev->capture.port == NULL)
  23045. + return -EINVAL;
  23046. +
  23047. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  23048. +
  23049. + /* stop capturing frames */
  23050. + vchiq_mmal_port_parameter_set(dev->instance,
  23051. + dev->capture.camera_port,
  23052. + MMAL_PARAMETER_CAPTURE,
  23053. + &dev->capture.frame_count,
  23054. + sizeof(dev->capture.frame_count));
  23055. +
  23056. + /* wait for last frame to complete */
  23057. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  23058. + if (ret <= 0)
  23059. + v4l2_err(&dev->v4l2_dev,
  23060. + "error %d waiting for frame completion\n", ret);
  23061. +
  23062. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23063. + "disabling connection\n");
  23064. +
  23065. + /* disable the connection from camera to encoder */
  23066. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  23067. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  23068. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23069. + "disabling port\n");
  23070. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  23071. + } else if (dev->capture.camera_port != dev->capture.port) {
  23072. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  23073. + ret);
  23074. + }
  23075. +
  23076. + if (disable_camera(dev) < 0) {
  23077. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  23078. + return -EINVAL;
  23079. + }
  23080. +
  23081. + return ret;
  23082. +}
  23083. +
  23084. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  23085. +{
  23086. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  23087. + mutex_lock(&dev->mutex);
  23088. +}
  23089. +
  23090. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  23091. +{
  23092. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  23093. + mutex_unlock(&dev->mutex);
  23094. +}
  23095. +
  23096. +static struct vb2_ops bm2835_mmal_video_qops = {
  23097. + .queue_setup = queue_setup,
  23098. + .buf_prepare = buffer_prepare,
  23099. + .buf_queue = buffer_queue,
  23100. + .start_streaming = start_streaming,
  23101. + .stop_streaming = stop_streaming,
  23102. + .wait_prepare = bm2835_mmal_unlock,
  23103. + .wait_finish = bm2835_mmal_lock,
  23104. +};
  23105. +
  23106. +/* ------------------------------------------------------------------
  23107. + IOCTL operations
  23108. + ------------------------------------------------------------------*/
  23109. +
  23110. +/* overlay ioctl */
  23111. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  23112. + struct v4l2_fmtdesc *f)
  23113. +{
  23114. + struct mmal_fmt *fmt;
  23115. +
  23116. + if (f->index >= ARRAY_SIZE(formats))
  23117. + return -EINVAL;
  23118. +
  23119. + fmt = &formats[f->index];
  23120. +
  23121. + strlcpy(f->description, fmt->name, sizeof(f->description));
  23122. + f->pixelformat = fmt->fourcc;
  23123. + f->flags = fmt->flags;
  23124. +
  23125. + return 0;
  23126. +}
  23127. +
  23128. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  23129. + struct v4l2_format *f)
  23130. +{
  23131. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23132. +
  23133. + f->fmt.win = dev->overlay;
  23134. +
  23135. + return 0;
  23136. +}
  23137. +
  23138. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  23139. + struct v4l2_format *f)
  23140. +{
  23141. + /* Only support one format so get the current one. */
  23142. + vidioc_g_fmt_vid_overlay(file, priv, f);
  23143. +
  23144. + /* todo: allow the size and/or offset to be changed. */
  23145. + return 0;
  23146. +}
  23147. +
  23148. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  23149. + struct v4l2_format *f)
  23150. +{
  23151. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23152. +
  23153. + vidioc_try_fmt_vid_overlay(file, priv, f);
  23154. +
  23155. + dev->overlay = f->fmt.win;
  23156. +
  23157. + /* todo: program the preview port parameters */
  23158. + return 0;
  23159. +}
  23160. +
  23161. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  23162. +{
  23163. + int ret;
  23164. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23165. + struct vchiq_mmal_port *src;
  23166. + struct vchiq_mmal_port *dst;
  23167. + struct mmal_parameter_displayregion prev_config = {
  23168. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  23169. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  23170. + .layer = PREVIEW_LAYER,
  23171. + .alpha = 255,
  23172. + .fullscreen = 0,
  23173. + .dest_rect = {
  23174. + .x = dev->overlay.w.left,
  23175. + .y = dev->overlay.w.top,
  23176. + .width = dev->overlay.w.width,
  23177. + .height = dev->overlay.w.height,
  23178. + },
  23179. + };
  23180. +
  23181. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  23182. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  23183. + return 0; /* already in requested state */
  23184. +
  23185. + src =
  23186. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23187. + output[MMAL_CAMERA_PORT_PREVIEW];
  23188. +
  23189. + if (!on) {
  23190. + /* disconnect preview ports and disable component */
  23191. + ret = vchiq_mmal_port_disable(dev->instance, src);
  23192. + if (!ret)
  23193. + ret =
  23194. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  23195. + NULL);
  23196. + if (ret >= 0)
  23197. + ret = vchiq_mmal_component_disable(
  23198. + dev->instance,
  23199. + dev->component[MMAL_COMPONENT_PREVIEW]);
  23200. +
  23201. + disable_camera(dev);
  23202. + return ret;
  23203. + }
  23204. +
  23205. + /* set preview port format and connect it to output */
  23206. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  23207. +
  23208. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  23209. + if (ret < 0)
  23210. + goto error;
  23211. +
  23212. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  23213. + MMAL_PARAMETER_DISPLAYREGION,
  23214. + &prev_config, sizeof(prev_config));
  23215. + if (ret < 0)
  23216. + goto error;
  23217. +
  23218. + if (enable_camera(dev) < 0)
  23219. + goto error;
  23220. +
  23221. + ret = vchiq_mmal_component_enable(
  23222. + dev->instance,
  23223. + dev->component[MMAL_COMPONENT_PREVIEW]);
  23224. + if (ret < 0)
  23225. + goto error;
  23226. +
  23227. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  23228. + src, dst);
  23229. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  23230. + if (!ret)
  23231. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  23232. +error:
  23233. + return ret;
  23234. +}
  23235. +
  23236. +static int vidioc_g_fbuf(struct file *file, void *fh,
  23237. + struct v4l2_framebuffer *a)
  23238. +{
  23239. + /* The video overlay must stay within the framebuffer and can't be
  23240. + positioned independently. */
  23241. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23242. + struct vchiq_mmal_port *preview_port =
  23243. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23244. + output[MMAL_CAMERA_PORT_PREVIEW];
  23245. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  23246. + a->fmt.width = preview_port->es.video.width;
  23247. + a->fmt.height = preview_port->es.video.height;
  23248. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  23249. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  23250. + a->fmt.sizeimage = (preview_port->es.video.width *
  23251. + preview_port->es.video.height * 3)>>1;
  23252. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  23253. +
  23254. + return 0;
  23255. +}
  23256. +
  23257. +/* input ioctls */
  23258. +static int vidioc_enum_input(struct file *file, void *priv,
  23259. + struct v4l2_input *inp)
  23260. +{
  23261. + /* only a single camera input */
  23262. + if (inp->index != 0)
  23263. + return -EINVAL;
  23264. +
  23265. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  23266. + sprintf(inp->name, "Camera %u", inp->index);
  23267. + return 0;
  23268. +}
  23269. +
  23270. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  23271. +{
  23272. + *i = 0;
  23273. + return 0;
  23274. +}
  23275. +
  23276. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  23277. +{
  23278. + if (i != 0)
  23279. + return -EINVAL;
  23280. +
  23281. + return 0;
  23282. +}
  23283. +
  23284. +/* capture ioctls */
  23285. +static int vidioc_querycap(struct file *file, void *priv,
  23286. + struct v4l2_capability *cap)
  23287. +{
  23288. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23289. + u32 major;
  23290. + u32 minor;
  23291. +
  23292. + vchiq_mmal_version(dev->instance, &major, &minor);
  23293. +
  23294. + strcpy(cap->driver, "bm2835 mmal");
  23295. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  23296. + major, minor);
  23297. +
  23298. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  23299. + "platform:%s", dev->v4l2_dev.name);
  23300. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  23301. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  23302. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  23303. +
  23304. + return 0;
  23305. +}
  23306. +
  23307. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  23308. + struct v4l2_fmtdesc *f)
  23309. +{
  23310. + struct mmal_fmt *fmt;
  23311. +
  23312. + if (f->index >= ARRAY_SIZE(formats))
  23313. + return -EINVAL;
  23314. +
  23315. + fmt = &formats[f->index];
  23316. +
  23317. + strlcpy(f->description, fmt->name, sizeof(f->description));
  23318. + f->pixelformat = fmt->fourcc;
  23319. + f->flags = fmt->flags;
  23320. +
  23321. + return 0;
  23322. +}
  23323. +
  23324. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  23325. + struct v4l2_format *f)
  23326. +{
  23327. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23328. +
  23329. + f->fmt.pix.width = dev->capture.width;
  23330. + f->fmt.pix.height = dev->capture.height;
  23331. + f->fmt.pix.field = V4L2_FIELD_NONE;
  23332. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  23333. + f->fmt.pix.bytesperline = dev->capture.stride;
  23334. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  23335. +
  23336. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  23337. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  23338. + else
  23339. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  23340. + f->fmt.pix.priv = 0;
  23341. +
  23342. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  23343. + __func__);
  23344. + return 0;
  23345. +}
  23346. +
  23347. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  23348. + struct v4l2_format *f)
  23349. +{
  23350. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23351. + struct mmal_fmt *mfmt;
  23352. +
  23353. + mfmt = get_format(f);
  23354. + if (!mfmt) {
  23355. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23356. + "Fourcc format (0x%08x) unknown.\n",
  23357. + f->fmt.pix.pixelformat);
  23358. + f->fmt.pix.pixelformat = formats[0].fourcc;
  23359. + mfmt = get_format(f);
  23360. + }
  23361. +
  23362. + f->fmt.pix.field = V4L2_FIELD_NONE;
  23363. +
  23364. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23365. + "Clipping/aligning %dx%d format %08X\n",
  23366. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  23367. +
  23368. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  23369. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  23370. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  23371. +
  23372. + /* Image buffer has to be padded to allow for alignment, even though
  23373. + * we then remove that padding before delivering the buffer.
  23374. + */
  23375. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  23376. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  23377. +
  23378. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  23379. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  23380. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  23381. +
  23382. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  23383. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  23384. + else
  23385. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  23386. + f->fmt.pix.priv = 0;
  23387. +
  23388. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23389. + "Now %dx%d format %08X\n",
  23390. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  23391. +
  23392. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  23393. + __func__);
  23394. + return 0;
  23395. +}
  23396. +
  23397. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  23398. + struct v4l2_format *f)
  23399. +{
  23400. + int ret;
  23401. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  23402. + struct vchiq_mmal_component *encode_component = NULL;
  23403. + struct mmal_fmt *mfmt = get_format(f);
  23404. +
  23405. + BUG_ON(!mfmt);
  23406. +
  23407. + if (dev->capture.encode_component) {
  23408. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23409. + "vid_cap - disconnect previous tunnel\n");
  23410. +
  23411. + /* Disconnect any previous connection */
  23412. + vchiq_mmal_port_connect_tunnel(dev->instance,
  23413. + dev->capture.camera_port, NULL);
  23414. + dev->capture.camera_port = NULL;
  23415. + ret = vchiq_mmal_component_disable(dev->instance,
  23416. + dev->capture.
  23417. + encode_component);
  23418. + if (ret)
  23419. + v4l2_err(&dev->v4l2_dev,
  23420. + "Failed to disable encode component %d\n",
  23421. + ret);
  23422. +
  23423. + dev->capture.encode_component = NULL;
  23424. + }
  23425. + /* format dependant port setup */
  23426. + switch (mfmt->mmal_component) {
  23427. + case MMAL_COMPONENT_CAMERA:
  23428. + /* Make a further decision on port based on resolution */
  23429. + if (f->fmt.pix.width <= max_video_width
  23430. + && f->fmt.pix.height <= max_video_height)
  23431. + camera_port = port =
  23432. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23433. + output[MMAL_CAMERA_PORT_VIDEO];
  23434. + else
  23435. + camera_port = port =
  23436. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23437. + output[MMAL_CAMERA_PORT_CAPTURE];
  23438. + break;
  23439. + case MMAL_COMPONENT_IMAGE_ENCODE:
  23440. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  23441. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  23442. + camera_port =
  23443. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23444. + output[MMAL_CAMERA_PORT_CAPTURE];
  23445. + break;
  23446. + case MMAL_COMPONENT_VIDEO_ENCODE:
  23447. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  23448. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  23449. + camera_port =
  23450. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23451. + output[MMAL_CAMERA_PORT_VIDEO];
  23452. + break;
  23453. + default:
  23454. + break;
  23455. + }
  23456. +
  23457. + if (!port)
  23458. + return -EINVAL;
  23459. +
  23460. + if (encode_component)
  23461. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  23462. + else
  23463. + camera_port->format.encoding = mfmt->mmal;
  23464. +
  23465. + camera_port->format.encoding_variant = 0;
  23466. + camera_port->es.video.width = f->fmt.pix.width;
  23467. + camera_port->es.video.height = f->fmt.pix.height;
  23468. + camera_port->es.video.crop.x = 0;
  23469. + camera_port->es.video.crop.y = 0;
  23470. + camera_port->es.video.crop.width = f->fmt.pix.width;
  23471. + camera_port->es.video.crop.height = f->fmt.pix.height;
  23472. + camera_port->es.video.frame_rate.num = 0;
  23473. + camera_port->es.video.frame_rate.den = 1;
  23474. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  23475. +
  23476. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  23477. +
  23478. + if (!ret
  23479. + && camera_port ==
  23480. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23481. + output[MMAL_CAMERA_PORT_VIDEO]) {
  23482. + bool overlay_enabled =
  23483. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  23484. + struct vchiq_mmal_port *preview_port =
  23485. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23486. + output[MMAL_CAMERA_PORT_PREVIEW];
  23487. + /* Preview and encode ports need to match on resolution */
  23488. + if (overlay_enabled) {
  23489. + /* Need to disable the overlay before we can update
  23490. + * the resolution
  23491. + */
  23492. + ret =
  23493. + vchiq_mmal_port_disable(dev->instance,
  23494. + preview_port);
  23495. + if (!ret)
  23496. + ret =
  23497. + vchiq_mmal_port_connect_tunnel(
  23498. + dev->instance,
  23499. + preview_port,
  23500. + NULL);
  23501. + }
  23502. + preview_port->es.video.width = f->fmt.pix.width;
  23503. + preview_port->es.video.height = f->fmt.pix.height;
  23504. + preview_port->es.video.crop.x = 0;
  23505. + preview_port->es.video.crop.y = 0;
  23506. + preview_port->es.video.crop.width = f->fmt.pix.width;
  23507. + preview_port->es.video.crop.height = f->fmt.pix.height;
  23508. + preview_port->es.video.frame_rate.num =
  23509. + dev->capture.timeperframe.denominator;
  23510. + preview_port->es.video.frame_rate.den =
  23511. + dev->capture.timeperframe.numerator;
  23512. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  23513. + if (overlay_enabled) {
  23514. + ret = vchiq_mmal_port_connect_tunnel(
  23515. + dev->instance,
  23516. + preview_port,
  23517. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  23518. + if (!ret)
  23519. + ret = vchiq_mmal_port_enable(dev->instance,
  23520. + preview_port,
  23521. + NULL);
  23522. + }
  23523. + }
  23524. +
  23525. + if (ret) {
  23526. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23527. + "%s failed to set format %dx%d %08X\n", __func__,
  23528. + f->fmt.pix.width, f->fmt.pix.height,
  23529. + f->fmt.pix.pixelformat);
  23530. + /* ensure capture is not going to be tried */
  23531. + dev->capture.port = NULL;
  23532. + } else {
  23533. + if (encode_component) {
  23534. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23535. + "vid_cap - set up encode comp\n");
  23536. +
  23537. + /* configure buffering */
  23538. + camera_port->current_buffer.size =
  23539. + camera_port->recommended_buffer.size;
  23540. + camera_port->current_buffer.num =
  23541. + camera_port->recommended_buffer.num;
  23542. +
  23543. + ret =
  23544. + vchiq_mmal_port_connect_tunnel(
  23545. + dev->instance,
  23546. + camera_port,
  23547. + &encode_component->input[0]);
  23548. + if (ret) {
  23549. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23550. + &dev->v4l2_dev,
  23551. + "%s failed to create connection\n",
  23552. + __func__);
  23553. + /* ensure capture is not going to be tried */
  23554. + dev->capture.port = NULL;
  23555. + } else {
  23556. + port->es.video.width = f->fmt.pix.width;
  23557. + port->es.video.height = f->fmt.pix.height;
  23558. + port->es.video.crop.x = 0;
  23559. + port->es.video.crop.y = 0;
  23560. + port->es.video.crop.width = f->fmt.pix.width;
  23561. + port->es.video.crop.height = f->fmt.pix.height;
  23562. + port->es.video.frame_rate.num =
  23563. + dev->capture.timeperframe.denominator;
  23564. + port->es.video.frame_rate.den =
  23565. + dev->capture.timeperframe.numerator;
  23566. +
  23567. + port->format.encoding = mfmt->mmal;
  23568. + port->format.encoding_variant = 0;
  23569. + /* Set any encoding specific parameters */
  23570. + switch (mfmt->mmal_component) {
  23571. + case MMAL_COMPONENT_VIDEO_ENCODE:
  23572. + port->format.bitrate =
  23573. + dev->capture.encode_bitrate;
  23574. + break;
  23575. + case MMAL_COMPONENT_IMAGE_ENCODE:
  23576. + /* Could set EXIF parameters here */
  23577. + break;
  23578. + default:
  23579. + break;
  23580. + }
  23581. + ret = vchiq_mmal_port_set_format(dev->instance,
  23582. + port);
  23583. + if (ret)
  23584. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23585. + &dev->v4l2_dev,
  23586. + "%s failed to set format %dx%d fmt %08X\n",
  23587. + __func__,
  23588. + f->fmt.pix.width,
  23589. + f->fmt.pix.height,
  23590. + f->fmt.pix.pixelformat
  23591. + );
  23592. + }
  23593. +
  23594. + if (!ret) {
  23595. + ret = vchiq_mmal_component_enable(
  23596. + dev->instance,
  23597. + encode_component);
  23598. + if (ret) {
  23599. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23600. + &dev->v4l2_dev,
  23601. + "%s Failed to enable encode components\n",
  23602. + __func__);
  23603. + }
  23604. + }
  23605. + if (!ret) {
  23606. + /* configure buffering */
  23607. + port->current_buffer.num = 1;
  23608. + port->current_buffer.size =
  23609. + f->fmt.pix.sizeimage;
  23610. + if (port->format.encoding ==
  23611. + MMAL_ENCODING_JPEG) {
  23612. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23613. + &dev->v4l2_dev,
  23614. + "JPG - buf size now %d was %d\n",
  23615. + f->fmt.pix.sizeimage,
  23616. + port->current_buffer.size);
  23617. + port->current_buffer.size =
  23618. + (f->fmt.pix.sizeimage <
  23619. + (100 << 10))
  23620. + ? (100 << 10) : f->fmt.pix.
  23621. + sizeimage;
  23622. + }
  23623. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23624. + &dev->v4l2_dev,
  23625. + "vid_cap - cur_buf.size set to %d\n",
  23626. + f->fmt.pix.sizeimage);
  23627. + port->current_buffer.alignment = 0;
  23628. + }
  23629. + } else {
  23630. + /* configure buffering */
  23631. + camera_port->current_buffer.num = 1;
  23632. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  23633. + camera_port->current_buffer.alignment = 0;
  23634. + }
  23635. +
  23636. + if (!ret) {
  23637. + dev->capture.fmt = mfmt;
  23638. + dev->capture.stride = f->fmt.pix.bytesperline;
  23639. + dev->capture.width = camera_port->es.video.crop.width;
  23640. + dev->capture.height = camera_port->es.video.crop.height;
  23641. + dev->capture.buffersize = port->current_buffer.size;
  23642. +
  23643. + /* select port for capture */
  23644. + dev->capture.port = port;
  23645. + dev->capture.camera_port = camera_port;
  23646. + dev->capture.encode_component = encode_component;
  23647. + v4l2_dbg(1, bcm2835_v4l2_debug,
  23648. + &dev->v4l2_dev,
  23649. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  23650. + port->format.encoding,
  23651. + dev->capture.width, dev->capture.height,
  23652. + dev->capture.stride, dev->capture.buffersize);
  23653. + }
  23654. + }
  23655. +
  23656. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  23657. + return ret;
  23658. +}
  23659. +
  23660. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  23661. + struct v4l2_format *f)
  23662. +{
  23663. + int ret;
  23664. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23665. + struct mmal_fmt *mfmt;
  23666. +
  23667. + /* try the format to set valid parameters */
  23668. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  23669. + if (ret) {
  23670. + v4l2_err(&dev->v4l2_dev,
  23671. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  23672. + return ret;
  23673. + }
  23674. +
  23675. + /* if a capture is running refuse to set format */
  23676. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  23677. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  23678. + return -EBUSY;
  23679. + }
  23680. +
  23681. + /* If the format is unsupported v4l2 says we should switch to
  23682. + * a supported one and not return an error. */
  23683. + mfmt = get_format(f);
  23684. + if (!mfmt) {
  23685. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  23686. + "Fourcc format (0x%08x) unknown.\n",
  23687. + f->fmt.pix.pixelformat);
  23688. + f->fmt.pix.pixelformat = formats[0].fourcc;
  23689. + mfmt = get_format(f);
  23690. + }
  23691. +
  23692. + ret = mmal_setup_components(dev, f);
  23693. + if (ret != 0) {
  23694. + v4l2_err(&dev->v4l2_dev,
  23695. + "%s: failed to setup mmal components: %d\n",
  23696. + __func__, ret);
  23697. + ret = -EINVAL;
  23698. + }
  23699. +
  23700. + return ret;
  23701. +}
  23702. +
  23703. +int vidioc_enum_framesizes(struct file *file, void *fh,
  23704. + struct v4l2_frmsizeenum *fsize)
  23705. +{
  23706. + static const struct v4l2_frmsize_stepwise sizes = {
  23707. + MIN_WIDTH, MAX_WIDTH, 2,
  23708. + MIN_HEIGHT, MAX_HEIGHT, 2
  23709. + };
  23710. + int i;
  23711. +
  23712. + if (fsize->index)
  23713. + return -EINVAL;
  23714. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  23715. + if (formats[i].fourcc == fsize->pixel_format)
  23716. + break;
  23717. + if (i == ARRAY_SIZE(formats))
  23718. + return -EINVAL;
  23719. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  23720. + fsize->stepwise = sizes;
  23721. + return 0;
  23722. +}
  23723. +
  23724. +/* timeperframe is arbitrary and continous */
  23725. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  23726. + struct v4l2_frmivalenum *fival)
  23727. +{
  23728. + int i;
  23729. +
  23730. + if (fival->index)
  23731. + return -EINVAL;
  23732. +
  23733. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  23734. + if (formats[i].fourcc == fival->pixel_format)
  23735. + break;
  23736. + if (i == ARRAY_SIZE(formats))
  23737. + return -EINVAL;
  23738. +
  23739. + /* regarding width & height - we support any within range */
  23740. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  23741. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  23742. + return -EINVAL;
  23743. +
  23744. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  23745. +
  23746. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  23747. + fival->stepwise.min = tpf_min;
  23748. + fival->stepwise.max = tpf_max;
  23749. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  23750. +
  23751. + return 0;
  23752. +}
  23753. +
  23754. +static int vidioc_g_parm(struct file *file, void *priv,
  23755. + struct v4l2_streamparm *parm)
  23756. +{
  23757. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23758. +
  23759. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  23760. + return -EINVAL;
  23761. +
  23762. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  23763. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  23764. + parm->parm.capture.readbuffers = 1;
  23765. + return 0;
  23766. +}
  23767. +
  23768. +#define FRACT_CMP(a, OP, b) \
  23769. + ((u64)(a).numerator * (b).denominator OP \
  23770. + (u64)(b).numerator * (a).denominator)
  23771. +
  23772. +static int vidioc_s_parm(struct file *file, void *priv,
  23773. + struct v4l2_streamparm *parm)
  23774. +{
  23775. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  23776. + struct v4l2_fract tpf;
  23777. + struct mmal_parameter_rational fps_param;
  23778. +
  23779. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  23780. + return -EINVAL;
  23781. +
  23782. + tpf = parm->parm.capture.timeperframe;
  23783. +
  23784. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  23785. + tpf = tpf.denominator ? tpf : tpf_default;
  23786. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  23787. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  23788. +
  23789. + dev->capture.timeperframe = tpf;
  23790. + parm->parm.capture.timeperframe = tpf;
  23791. + parm->parm.capture.readbuffers = 1;
  23792. +
  23793. + fps_param.num = 0; /* Select variable fps, and then use
  23794. + * FPS_RANGE to select the actual limits.
  23795. + */
  23796. + fps_param.den = 1;
  23797. + set_framerate_params(dev);
  23798. +
  23799. + return 0;
  23800. +}
  23801. +
  23802. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  23803. + /* overlay */
  23804. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  23805. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  23806. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  23807. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  23808. + .vidioc_overlay = vidioc_overlay,
  23809. + .vidioc_g_fbuf = vidioc_g_fbuf,
  23810. +
  23811. + /* inputs */
  23812. + .vidioc_enum_input = vidioc_enum_input,
  23813. + .vidioc_g_input = vidioc_g_input,
  23814. + .vidioc_s_input = vidioc_s_input,
  23815. +
  23816. + /* capture */
  23817. + .vidioc_querycap = vidioc_querycap,
  23818. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  23819. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  23820. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  23821. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  23822. +
  23823. + /* buffer management */
  23824. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  23825. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  23826. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  23827. + .vidioc_querybuf = vb2_ioctl_querybuf,
  23828. + .vidioc_qbuf = vb2_ioctl_qbuf,
  23829. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  23830. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  23831. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  23832. + .vidioc_g_parm = vidioc_g_parm,
  23833. + .vidioc_s_parm = vidioc_s_parm,
  23834. + .vidioc_streamon = vb2_ioctl_streamon,
  23835. + .vidioc_streamoff = vb2_ioctl_streamoff,
  23836. +
  23837. + .vidioc_log_status = v4l2_ctrl_log_status,
  23838. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  23839. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  23840. +};
  23841. +
  23842. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  23843. + /* overlay */
  23844. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  23845. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  23846. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  23847. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  23848. + .vidioc_overlay = vidioc_overlay,
  23849. + .vidioc_g_fbuf = vidioc_g_fbuf,
  23850. +
  23851. + /* inputs */
  23852. + .vidioc_enum_input = vidioc_enum_input,
  23853. + .vidioc_g_input = vidioc_g_input,
  23854. + .vidioc_s_input = vidioc_s_input,
  23855. +
  23856. + /* capture */
  23857. + .vidioc_querycap = vidioc_querycap,
  23858. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  23859. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  23860. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  23861. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  23862. +
  23863. + /* buffer management */
  23864. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  23865. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  23866. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  23867. + .vidioc_querybuf = vb2_ioctl_querybuf,
  23868. + .vidioc_qbuf = vb2_ioctl_qbuf,
  23869. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  23870. + /* Remove this function ptr to fix gstreamer bug
  23871. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  23872. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  23873. + .vidioc_g_parm = vidioc_g_parm,
  23874. + .vidioc_s_parm = vidioc_s_parm,
  23875. + .vidioc_streamon = vb2_ioctl_streamon,
  23876. + .vidioc_streamoff = vb2_ioctl_streamoff,
  23877. +
  23878. + .vidioc_log_status = v4l2_ctrl_log_status,
  23879. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  23880. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  23881. +};
  23882. +
  23883. +/* ------------------------------------------------------------------
  23884. + Driver init/finalise
  23885. + ------------------------------------------------------------------*/
  23886. +
  23887. +static const struct v4l2_file_operations camera0_fops = {
  23888. + .owner = THIS_MODULE,
  23889. + .open = v4l2_fh_open,
  23890. + .release = vb2_fop_release,
  23891. + .read = vb2_fop_read,
  23892. + .poll = vb2_fop_poll,
  23893. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  23894. + .mmap = vb2_fop_mmap,
  23895. +};
  23896. +
  23897. +static struct video_device vdev_template = {
  23898. + .name = "camera0",
  23899. + .fops = &camera0_fops,
  23900. + .ioctl_ops = &camera0_ioctl_ops,
  23901. + .release = video_device_release_empty,
  23902. +};
  23903. +
  23904. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  23905. + struct vchiq_mmal_component *camera)
  23906. +{
  23907. + int ret;
  23908. + struct mmal_parameter_camera_config cam_config = {
  23909. + .max_stills_w = MAX_WIDTH,
  23910. + .max_stills_h = MAX_HEIGHT,
  23911. + .stills_yuv422 = 1,
  23912. + .one_shot_stills = 1,
  23913. + .max_preview_video_w = (max_video_width > 1920) ?
  23914. + max_video_width : 1920,
  23915. + .max_preview_video_h = (max_video_height > 1088) ?
  23916. + max_video_height : 1088,
  23917. + .num_preview_video_frames = 3,
  23918. + .stills_capture_circular_buffer_height = 0,
  23919. + .fast_preview_resume = 0,
  23920. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  23921. + };
  23922. +
  23923. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  23924. + MMAL_PARAMETER_CAMERA_CONFIG,
  23925. + &cam_config, sizeof(cam_config));
  23926. + return ret;
  23927. +}
  23928. +
  23929. +/* MMAL instance and component init */
  23930. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  23931. +{
  23932. + int ret;
  23933. + struct mmal_es_format *format;
  23934. + u32 bool_true = 1;
  23935. +
  23936. + ret = vchiq_mmal_init(&dev->instance);
  23937. + if (ret < 0)
  23938. + return ret;
  23939. +
  23940. + /* get the camera component ready */
  23941. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  23942. + &dev->component[MMAL_COMPONENT_CAMERA]);
  23943. + if (ret < 0)
  23944. + goto unreg_mmal;
  23945. +
  23946. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  23947. + MMAL_CAMERA_PORT_COUNT) {
  23948. + ret = -EINVAL;
  23949. + goto unreg_camera;
  23950. + }
  23951. +
  23952. + ret = set_camera_parameters(dev->instance,
  23953. + dev->component[MMAL_COMPONENT_CAMERA]);
  23954. + if (ret < 0)
  23955. + goto unreg_camera;
  23956. +
  23957. + format =
  23958. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23959. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  23960. +
  23961. + format->encoding = MMAL_ENCODING_OPAQUE;
  23962. + format->encoding_variant = MMAL_ENCODING_I420;
  23963. +
  23964. + format->es->video.width = 1024;
  23965. + format->es->video.height = 768;
  23966. + format->es->video.crop.x = 0;
  23967. + format->es->video.crop.y = 0;
  23968. + format->es->video.crop.width = 1024;
  23969. + format->es->video.crop.height = 768;
  23970. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  23971. + format->es->video.frame_rate.den = 1;
  23972. +
  23973. + format =
  23974. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23975. + output[MMAL_CAMERA_PORT_VIDEO].format;
  23976. +
  23977. + format->encoding = MMAL_ENCODING_OPAQUE;
  23978. + format->encoding_variant = MMAL_ENCODING_I420;
  23979. +
  23980. + format->es->video.width = 1024;
  23981. + format->es->video.height = 768;
  23982. + format->es->video.crop.x = 0;
  23983. + format->es->video.crop.y = 0;
  23984. + format->es->video.crop.width = 1024;
  23985. + format->es->video.crop.height = 768;
  23986. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  23987. + format->es->video.frame_rate.den = 1;
  23988. +
  23989. + vchiq_mmal_port_parameter_set(dev->instance,
  23990. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23991. + output[MMAL_CAMERA_PORT_VIDEO],
  23992. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  23993. + &bool_true, sizeof(bool_true));
  23994. +
  23995. + format =
  23996. + &dev->component[MMAL_COMPONENT_CAMERA]->
  23997. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  23998. +
  23999. + format->encoding = MMAL_ENCODING_OPAQUE;
  24000. +
  24001. + format->es->video.width = 2592;
  24002. + format->es->video.height = 1944;
  24003. + format->es->video.crop.x = 0;
  24004. + format->es->video.crop.y = 0;
  24005. + format->es->video.crop.width = 2592;
  24006. + format->es->video.crop.height = 1944;
  24007. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  24008. + format->es->video.frame_rate.den = 1;
  24009. +
  24010. + dev->capture.width = format->es->video.width;
  24011. + dev->capture.height = format->es->video.height;
  24012. + dev->capture.fmt = &formats[0];
  24013. + dev->capture.encode_component = NULL;
  24014. + dev->capture.timeperframe = tpf_default;
  24015. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  24016. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  24017. +
  24018. + vchiq_mmal_port_parameter_set(dev->instance,
  24019. + &dev->component[MMAL_COMPONENT_CAMERA]->
  24020. + output[MMAL_CAMERA_PORT_CAPTURE],
  24021. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  24022. + &bool_true, sizeof(bool_true));
  24023. +
  24024. + /* get the preview component ready */
  24025. + ret = vchiq_mmal_component_init(
  24026. + dev->instance, "ril.video_render",
  24027. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  24028. + if (ret < 0)
  24029. + goto unreg_camera;
  24030. +
  24031. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  24032. + ret = -EINVAL;
  24033. + pr_debug("too few input ports %d needed %d\n",
  24034. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  24035. + goto unreg_preview;
  24036. + }
  24037. +
  24038. + /* get the image encoder component ready */
  24039. + ret = vchiq_mmal_component_init(
  24040. + dev->instance, "ril.image_encode",
  24041. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  24042. + if (ret < 0)
  24043. + goto unreg_preview;
  24044. +
  24045. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  24046. + ret = -EINVAL;
  24047. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  24048. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  24049. + 1);
  24050. + goto unreg_image_encoder;
  24051. + }
  24052. +
  24053. + /* get the video encoder component ready */
  24054. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  24055. + &dev->
  24056. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  24057. + if (ret < 0)
  24058. + goto unreg_image_encoder;
  24059. +
  24060. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  24061. + ret = -EINVAL;
  24062. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  24063. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  24064. + 1);
  24065. + goto unreg_vid_encoder;
  24066. + }
  24067. +
  24068. + {
  24069. + struct vchiq_mmal_port *encoder_port =
  24070. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  24071. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  24072. + ret = vchiq_mmal_port_set_format(dev->instance,
  24073. + encoder_port);
  24074. + }
  24075. +
  24076. + {
  24077. + unsigned int enable = 1;
  24078. + vchiq_mmal_port_parameter_set(
  24079. + dev->instance,
  24080. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  24081. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  24082. + &enable, sizeof(enable));
  24083. +
  24084. + vchiq_mmal_port_parameter_set(dev->instance,
  24085. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  24086. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  24087. + &enable,
  24088. + sizeof(enable));
  24089. + }
  24090. + ret = bm2835_mmal_set_all_camera_controls(dev);
  24091. + if (ret < 0)
  24092. + goto unreg_vid_encoder;
  24093. +
  24094. + return 0;
  24095. +
  24096. +unreg_vid_encoder:
  24097. + pr_err("Cleanup: Destroy video encoder\n");
  24098. + vchiq_mmal_component_finalise(
  24099. + dev->instance,
  24100. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  24101. +
  24102. +unreg_image_encoder:
  24103. + pr_err("Cleanup: Destroy image encoder\n");
  24104. + vchiq_mmal_component_finalise(
  24105. + dev->instance,
  24106. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  24107. +
  24108. +unreg_preview:
  24109. + pr_err("Cleanup: Destroy video render\n");
  24110. + vchiq_mmal_component_finalise(dev->instance,
  24111. + dev->component[MMAL_COMPONENT_PREVIEW]);
  24112. +
  24113. +unreg_camera:
  24114. + pr_err("Cleanup: Destroy camera\n");
  24115. + vchiq_mmal_component_finalise(dev->instance,
  24116. + dev->component[MMAL_COMPONENT_CAMERA]);
  24117. +
  24118. +unreg_mmal:
  24119. + vchiq_mmal_finalise(dev->instance);
  24120. + return ret;
  24121. +}
  24122. +
  24123. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  24124. + struct video_device *vfd)
  24125. +{
  24126. + int ret;
  24127. +
  24128. + *vfd = vdev_template;
  24129. + if (gst_v4l2src_is_broken) {
  24130. + v4l2_info(&dev->v4l2_dev,
  24131. + "Work-around for gstreamer issue is active.\n");
  24132. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  24133. + }
  24134. +
  24135. + vfd->v4l2_dev = &dev->v4l2_dev;
  24136. +
  24137. + vfd->lock = &dev->mutex;
  24138. +
  24139. + vfd->queue = &dev->capture.vb_vidq;
  24140. +
  24141. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  24142. +
  24143. + /* video device needs to be able to access instance data */
  24144. + video_set_drvdata(vfd, dev);
  24145. +
  24146. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  24147. + if (ret < 0)
  24148. + return ret;
  24149. +
  24150. + v4l2_info(vfd->v4l2_dev,
  24151. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  24152. + video_device_node_name(vfd), max_video_width, max_video_height);
  24153. +
  24154. + return 0;
  24155. +}
  24156. +
  24157. +static struct v4l2_format default_v4l2_format = {
  24158. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  24159. + .fmt.pix.width = 1024,
  24160. + .fmt.pix.bytesperline = 1024,
  24161. + .fmt.pix.height = 768,
  24162. + .fmt.pix.sizeimage = 1024*768,
  24163. +};
  24164. +
  24165. +static int __init bm2835_mmal_init(void)
  24166. +{
  24167. + int ret;
  24168. + struct bm2835_mmal_dev *dev;
  24169. + struct vb2_queue *q;
  24170. +
  24171. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  24172. + if (!dev)
  24173. + return -ENOMEM;
  24174. +
  24175. + /* setup device defaults */
  24176. + dev->overlay.w.left = 150;
  24177. + dev->overlay.w.top = 50;
  24178. + dev->overlay.w.width = 1024;
  24179. + dev->overlay.w.height = 768;
  24180. + dev->overlay.clipcount = 0;
  24181. + dev->overlay.field = V4L2_FIELD_NONE;
  24182. +
  24183. + dev->capture.fmt = &formats[3]; /* JPEG */
  24184. +
  24185. + /* v4l device registration */
  24186. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  24187. + "%s", BM2835_MMAL_MODULE_NAME);
  24188. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  24189. + if (ret)
  24190. + goto free_dev;
  24191. +
  24192. + /* setup v4l controls */
  24193. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  24194. + if (ret < 0)
  24195. + goto unreg_dev;
  24196. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  24197. +
  24198. + /* mmal init */
  24199. + ret = mmal_init(dev);
  24200. + if (ret < 0)
  24201. + goto unreg_dev;
  24202. +
  24203. + /* initialize queue */
  24204. + q = &dev->capture.vb_vidq;
  24205. + memset(q, 0, sizeof(*q));
  24206. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  24207. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  24208. + q->drv_priv = dev;
  24209. + q->buf_struct_size = sizeof(struct mmal_buffer);
  24210. + q->ops = &bm2835_mmal_video_qops;
  24211. + q->mem_ops = &vb2_vmalloc_memops;
  24212. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  24213. + ret = vb2_queue_init(q);
  24214. + if (ret < 0)
  24215. + goto unreg_dev;
  24216. +
  24217. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  24218. + mutex_init(&dev->mutex);
  24219. +
  24220. + /* initialise video devices */
  24221. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  24222. + if (ret < 0)
  24223. + goto unreg_dev;
  24224. +
  24225. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  24226. + * format, but currently the APIs don't join up.
  24227. + */
  24228. + ret = mmal_setup_components(dev, &default_v4l2_format);
  24229. + if (ret < 0) {
  24230. + v4l2_err(&dev->v4l2_dev,
  24231. + "%s: could not setup components\n", __func__);
  24232. + goto unreg_dev;
  24233. + }
  24234. +
  24235. + v4l2_info(&dev->v4l2_dev,
  24236. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  24237. + BM2835_MMAL_VERSION);
  24238. +
  24239. + gdev = dev;
  24240. + return 0;
  24241. +
  24242. +unreg_dev:
  24243. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  24244. + v4l2_device_unregister(&dev->v4l2_dev);
  24245. +
  24246. +free_dev:
  24247. + kfree(dev);
  24248. +
  24249. + v4l2_err(&dev->v4l2_dev,
  24250. + "%s: error %d while loading driver\n",
  24251. + BM2835_MMAL_MODULE_NAME, ret);
  24252. +
  24253. + return ret;
  24254. +}
  24255. +
  24256. +static void __exit bm2835_mmal_exit(void)
  24257. +{
  24258. + if (!gdev)
  24259. + return;
  24260. +
  24261. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  24262. + video_device_node_name(&gdev->vdev));
  24263. +
  24264. + video_unregister_device(&gdev->vdev);
  24265. +
  24266. + if (gdev->capture.encode_component) {
  24267. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  24268. + "mmal_exit - disconnect tunnel\n");
  24269. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  24270. + gdev->capture.camera_port, NULL);
  24271. + vchiq_mmal_component_disable(gdev->instance,
  24272. + gdev->capture.encode_component);
  24273. + }
  24274. + vchiq_mmal_component_disable(gdev->instance,
  24275. + gdev->component[MMAL_COMPONENT_CAMERA]);
  24276. +
  24277. + vchiq_mmal_component_finalise(gdev->instance,
  24278. + gdev->
  24279. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  24280. +
  24281. + vchiq_mmal_component_finalise(gdev->instance,
  24282. + gdev->
  24283. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  24284. +
  24285. + vchiq_mmal_component_finalise(gdev->instance,
  24286. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  24287. +
  24288. + vchiq_mmal_component_finalise(gdev->instance,
  24289. + gdev->component[MMAL_COMPONENT_CAMERA]);
  24290. +
  24291. + vchiq_mmal_finalise(gdev->instance);
  24292. +
  24293. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  24294. +
  24295. + v4l2_device_unregister(&gdev->v4l2_dev);
  24296. +
  24297. + kfree(gdev);
  24298. +}
  24299. +
  24300. +module_init(bm2835_mmal_init);
  24301. +module_exit(bm2835_mmal_exit);
  24302. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  24303. --- linux-3.12.38/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  24304. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2015-03-09 10:39:30.594893734 +0100
  24305. @@ -0,0 +1,126 @@
  24306. +/*
  24307. + * Broadcom BM2835 V4L2 driver
  24308. + *
  24309. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  24310. + *
  24311. + * This file is subject to the terms and conditions of the GNU General Public
  24312. + * License. See the file COPYING in the main directory of this archive
  24313. + * for more details.
  24314. + *
  24315. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  24316. + * Dave Stevenson <dsteve@broadcom.com>
  24317. + * Simon Mellor <simellor@broadcom.com>
  24318. + * Luke Diamand <luked@broadcom.com>
  24319. + *
  24320. + * core driver device
  24321. + */
  24322. +
  24323. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  24324. +
  24325. +enum {
  24326. + MMAL_COMPONENT_CAMERA = 0,
  24327. + MMAL_COMPONENT_PREVIEW,
  24328. + MMAL_COMPONENT_IMAGE_ENCODE,
  24329. + MMAL_COMPONENT_VIDEO_ENCODE,
  24330. + MMAL_COMPONENT_COUNT
  24331. +};
  24332. +
  24333. +enum {
  24334. + MMAL_CAMERA_PORT_PREVIEW = 0,
  24335. + MMAL_CAMERA_PORT_VIDEO,
  24336. + MMAL_CAMERA_PORT_CAPTURE,
  24337. + MMAL_CAMERA_PORT_COUNT
  24338. +};
  24339. +
  24340. +#define PREVIEW_LAYER 2
  24341. +
  24342. +extern int bcm2835_v4l2_debug;
  24343. +
  24344. +struct bm2835_mmal_dev {
  24345. + /* v4l2 devices */
  24346. + struct v4l2_device v4l2_dev;
  24347. + struct video_device vdev;
  24348. + struct mutex mutex;
  24349. +
  24350. + /* controls */
  24351. + struct v4l2_ctrl_handler ctrl_handler;
  24352. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  24353. + enum v4l2_scene_mode scene_mode;
  24354. + struct mmal_colourfx colourfx;
  24355. + int hflip;
  24356. + int vflip;
  24357. + int red_gain;
  24358. + int blue_gain;
  24359. + enum mmal_parameter_exposuremode exposure_mode_user;
  24360. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  24361. + /* active exposure mode may differ if selected via a scene mode */
  24362. + enum mmal_parameter_exposuremode exposure_mode_active;
  24363. + enum mmal_parameter_exposuremeteringmode metering_mode;
  24364. + unsigned int manual_shutter_speed;
  24365. + bool exp_auto_priority;
  24366. +
  24367. + /* allocated mmal instance and components */
  24368. + struct vchiq_mmal_instance *instance;
  24369. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  24370. + int camera_use_count;
  24371. +
  24372. + struct v4l2_window overlay;
  24373. +
  24374. + struct {
  24375. + unsigned int width; /* width */
  24376. + unsigned int height; /* height */
  24377. + unsigned int stride; /* stride */
  24378. + unsigned int buffersize; /* buffer size with padding */
  24379. + struct mmal_fmt *fmt;
  24380. + struct v4l2_fract timeperframe;
  24381. +
  24382. + /* H264 encode bitrate */
  24383. + int encode_bitrate;
  24384. + /* H264 bitrate mode. CBR/VBR */
  24385. + int encode_bitrate_mode;
  24386. + /* H264 profile */
  24387. + enum v4l2_mpeg_video_h264_profile enc_profile;
  24388. + /* H264 level */
  24389. + enum v4l2_mpeg_video_h264_level enc_level;
  24390. + /* JPEG Q-factor */
  24391. + int q_factor;
  24392. +
  24393. + struct vb2_queue vb_vidq;
  24394. +
  24395. + /* VC start timestamp for streaming */
  24396. + s64 vc_start_timestamp;
  24397. + /* Kernel start timestamp for streaming */
  24398. + struct timeval kernel_start_ts;
  24399. +
  24400. + struct vchiq_mmal_port *port; /* port being used for capture */
  24401. + /* camera port being used for capture */
  24402. + struct vchiq_mmal_port *camera_port;
  24403. + /* component being used for encode */
  24404. + struct vchiq_mmal_component *encode_component;
  24405. + /* number of frames remaining which driver should capture */
  24406. + unsigned int frame_count;
  24407. + /* last frame completion */
  24408. + struct completion frame_cmplt;
  24409. +
  24410. + } capture;
  24411. +
  24412. +};
  24413. +
  24414. +int bm2835_mmal_init_controls(
  24415. + struct bm2835_mmal_dev *dev,
  24416. + struct v4l2_ctrl_handler *hdl);
  24417. +
  24418. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  24419. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  24420. +
  24421. +/* Debug helpers */
  24422. +
  24423. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  24424. +{ \
  24425. + v4l2_dbg(level, debug, dev, \
  24426. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  24427. + desc == NULL ? "" : desc, \
  24428. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  24429. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  24430. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  24431. +}
  24432. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  24433. --- linux-3.12.38/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  24434. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2015-03-09 10:39:30.594893734 +0100
  24435. @@ -0,0 +1,1322 @@
  24436. +/*
  24437. + * Broadcom BM2835 V4L2 driver
  24438. + *
  24439. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  24440. + *
  24441. + * This file is subject to the terms and conditions of the GNU General Public
  24442. + * License. See the file COPYING in the main directory of this archive
  24443. + * for more details.
  24444. + *
  24445. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  24446. + * Dave Stevenson <dsteve@broadcom.com>
  24447. + * Simon Mellor <simellor@broadcom.com>
  24448. + * Luke Diamand <luked@broadcom.com>
  24449. + */
  24450. +
  24451. +#include <linux/errno.h>
  24452. +#include <linux/kernel.h>
  24453. +#include <linux/module.h>
  24454. +#include <linux/slab.h>
  24455. +#include <media/videobuf2-vmalloc.h>
  24456. +#include <media/v4l2-device.h>
  24457. +#include <media/v4l2-ioctl.h>
  24458. +#include <media/v4l2-ctrls.h>
  24459. +#include <media/v4l2-fh.h>
  24460. +#include <media/v4l2-event.h>
  24461. +#include <media/v4l2-common.h>
  24462. +
  24463. +#include "mmal-common.h"
  24464. +#include "mmal-vchiq.h"
  24465. +#include "mmal-parameters.h"
  24466. +#include "bcm2835-camera.h"
  24467. +
  24468. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  24469. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  24470. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  24471. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  24472. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  24473. + * -4 to +4
  24474. + */
  24475. +static const s64 ev_bias_qmenu[] = {
  24476. + -4000, -3667, -3333,
  24477. + -3000, -2667, -2333,
  24478. + -2000, -1667, -1333,
  24479. + -1000, -667, -333,
  24480. + 0, 333, 667,
  24481. + 1000, 1333, 1667,
  24482. + 2000, 2333, 2667,
  24483. + 3000, 3333, 3667,
  24484. + 4000
  24485. +};
  24486. +
  24487. +/* Supported ISO values
  24488. + * ISOO = auto ISO
  24489. + */
  24490. +static const s64 iso_qmenu[] = {
  24491. + 0, 100, 200, 400, 800,
  24492. +};
  24493. +
  24494. +static const s64 mains_freq_qmenu[] = {
  24495. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  24496. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  24497. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  24498. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  24499. +};
  24500. +
  24501. +/* Supported video encode modes */
  24502. +static const s64 bitrate_mode_qmenu[] = {
  24503. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  24504. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  24505. +};
  24506. +
  24507. +enum bm2835_mmal_ctrl_type {
  24508. + MMAL_CONTROL_TYPE_STD,
  24509. + MMAL_CONTROL_TYPE_STD_MENU,
  24510. + MMAL_CONTROL_TYPE_INT_MENU,
  24511. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  24512. +};
  24513. +
  24514. +struct bm2835_mmal_v4l2_ctrl;
  24515. +
  24516. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  24517. + struct bm2835_mmal_dev *dev,
  24518. + struct v4l2_ctrl *ctrl,
  24519. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  24520. +
  24521. +struct bm2835_mmal_v4l2_ctrl {
  24522. + u32 id; /* v4l2 control identifier */
  24523. + enum bm2835_mmal_ctrl_type type;
  24524. + /* control minimum value or
  24525. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  24526. + s32 min;
  24527. + s32 max; /* maximum value of control */
  24528. + s32 def; /* default value of control */
  24529. + s32 step; /* step size of the control */
  24530. + const s64 *imenu; /* integer menu array */
  24531. + u32 mmal_id; /* mmal parameter id */
  24532. + bm2835_mmal_v4l2_ctrl_cb *setter;
  24533. + bool ignore_errors;
  24534. +};
  24535. +
  24536. +struct v4l2_to_mmal_effects_setting {
  24537. + u32 v4l2_effect;
  24538. + u32 mmal_effect;
  24539. + s32 col_fx_enable;
  24540. + s32 col_fx_fixed_cbcr;
  24541. + u32 u;
  24542. + u32 v;
  24543. + u32 num_effect_params;
  24544. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  24545. +};
  24546. +
  24547. +static const struct v4l2_to_mmal_effects_setting
  24548. + v4l2_to_mmal_effects_values[] = {
  24549. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  24550. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24551. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  24552. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  24553. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  24554. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  24555. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  24556. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24557. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  24558. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24559. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  24560. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24561. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  24562. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24563. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  24564. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24565. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  24566. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24567. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  24568. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24569. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  24570. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  24571. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  24572. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24573. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  24574. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  24575. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  24576. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  24577. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  24578. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  24579. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  24580. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  24581. +};
  24582. +
  24583. +struct v4l2_mmal_scene_config {
  24584. + enum v4l2_scene_mode v4l2_scene;
  24585. + enum mmal_parameter_exposuremode exposure_mode;
  24586. + enum mmal_parameter_exposuremeteringmode metering_mode;
  24587. +};
  24588. +
  24589. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  24590. + /* V4L2_SCENE_MODE_NONE automatically added */
  24591. + {
  24592. + V4L2_SCENE_MODE_NIGHT,
  24593. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  24594. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  24595. + },
  24596. + {
  24597. + V4L2_SCENE_MODE_SPORTS,
  24598. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  24599. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  24600. + },
  24601. +};
  24602. +
  24603. +/* control handlers*/
  24604. +
  24605. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  24606. + struct v4l2_ctrl *ctrl,
  24607. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24608. +{
  24609. + struct mmal_parameter_rational rational_value;
  24610. + struct vchiq_mmal_port *control;
  24611. +
  24612. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24613. +
  24614. + rational_value.num = ctrl->val;
  24615. + rational_value.den = 100;
  24616. +
  24617. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24618. + mmal_ctrl->mmal_id,
  24619. + &rational_value,
  24620. + sizeof(rational_value));
  24621. +}
  24622. +
  24623. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  24624. + struct v4l2_ctrl *ctrl,
  24625. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24626. +{
  24627. + u32 u32_value;
  24628. + struct vchiq_mmal_port *control;
  24629. +
  24630. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24631. +
  24632. + u32_value = ctrl->val;
  24633. +
  24634. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24635. + mmal_ctrl->mmal_id,
  24636. + &u32_value, sizeof(u32_value));
  24637. +}
  24638. +
  24639. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  24640. + struct v4l2_ctrl *ctrl,
  24641. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24642. +{
  24643. + u32 u32_value;
  24644. + struct vchiq_mmal_port *control;
  24645. +
  24646. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  24647. + return 1;
  24648. +
  24649. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24650. +
  24651. + u32_value = mmal_ctrl->imenu[ctrl->val];
  24652. +
  24653. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24654. + mmal_ctrl->mmal_id,
  24655. + &u32_value, sizeof(u32_value));
  24656. +}
  24657. +
  24658. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  24659. + struct v4l2_ctrl *ctrl,
  24660. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24661. +{
  24662. + s32 s32_value;
  24663. + struct vchiq_mmal_port *control;
  24664. +
  24665. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24666. +
  24667. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  24668. +
  24669. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24670. + mmal_ctrl->mmal_id,
  24671. + &s32_value, sizeof(s32_value));
  24672. +}
  24673. +
  24674. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  24675. + struct v4l2_ctrl *ctrl,
  24676. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24677. +{
  24678. + int ret;
  24679. + u32 u32_value;
  24680. + struct vchiq_mmal_component *camera;
  24681. +
  24682. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  24683. +
  24684. + u32_value = ((ctrl->val % 360) / 90) * 90;
  24685. +
  24686. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  24687. + mmal_ctrl->mmal_id,
  24688. + &u32_value, sizeof(u32_value));
  24689. + if (ret < 0)
  24690. + return ret;
  24691. +
  24692. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  24693. + mmal_ctrl->mmal_id,
  24694. + &u32_value, sizeof(u32_value));
  24695. + if (ret < 0)
  24696. + return ret;
  24697. +
  24698. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  24699. + mmal_ctrl->mmal_id,
  24700. + &u32_value, sizeof(u32_value));
  24701. +
  24702. + return ret;
  24703. +}
  24704. +
  24705. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  24706. + struct v4l2_ctrl *ctrl,
  24707. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24708. +{
  24709. + int ret;
  24710. + u32 u32_value;
  24711. + struct vchiq_mmal_component *camera;
  24712. +
  24713. + if (ctrl->id == V4L2_CID_HFLIP)
  24714. + dev->hflip = ctrl->val;
  24715. + else
  24716. + dev->vflip = ctrl->val;
  24717. +
  24718. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  24719. +
  24720. + if (dev->hflip && dev->vflip)
  24721. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  24722. + else if (dev->hflip)
  24723. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  24724. + else if (dev->vflip)
  24725. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  24726. + else
  24727. + u32_value = MMAL_PARAM_MIRROR_NONE;
  24728. +
  24729. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  24730. + mmal_ctrl->mmal_id,
  24731. + &u32_value, sizeof(u32_value));
  24732. + if (ret < 0)
  24733. + return ret;
  24734. +
  24735. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  24736. + mmal_ctrl->mmal_id,
  24737. + &u32_value, sizeof(u32_value));
  24738. + if (ret < 0)
  24739. + return ret;
  24740. +
  24741. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  24742. + mmal_ctrl->mmal_id,
  24743. + &u32_value, sizeof(u32_value));
  24744. +
  24745. + return ret;
  24746. +
  24747. +}
  24748. +
  24749. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  24750. + struct v4l2_ctrl *ctrl,
  24751. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24752. +{
  24753. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  24754. + u32 shutter_speed = 0;
  24755. + struct vchiq_mmal_port *control;
  24756. + int ret = 0;
  24757. +
  24758. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24759. +
  24760. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  24761. + /* V4L2 is in 100usec increments.
  24762. + * MMAL is 1usec.
  24763. + */
  24764. + dev->manual_shutter_speed = ctrl->val * 100;
  24765. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  24766. + switch (ctrl->val) {
  24767. + case V4L2_EXPOSURE_AUTO:
  24768. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  24769. + break;
  24770. +
  24771. + case V4L2_EXPOSURE_MANUAL:
  24772. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  24773. + break;
  24774. + }
  24775. + dev->exposure_mode_user = exp_mode;
  24776. + dev->exposure_mode_v4l2_user = ctrl->val;
  24777. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  24778. + dev->exp_auto_priority = ctrl->val;
  24779. + }
  24780. +
  24781. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  24782. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  24783. + shutter_speed = dev->manual_shutter_speed;
  24784. +
  24785. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  24786. + control,
  24787. + MMAL_PARAMETER_SHUTTER_SPEED,
  24788. + &shutter_speed,
  24789. + sizeof(shutter_speed));
  24790. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  24791. + control,
  24792. + MMAL_PARAMETER_EXPOSURE_MODE,
  24793. + &exp_mode,
  24794. + sizeof(u32));
  24795. + dev->exposure_mode_active = exp_mode;
  24796. + }
  24797. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  24798. + * always apply irrespective of scene mode.
  24799. + */
  24800. + ret += set_framerate_params(dev);
  24801. +
  24802. + return ret;
  24803. +}
  24804. +
  24805. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  24806. + struct v4l2_ctrl *ctrl,
  24807. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24808. +{
  24809. + switch (ctrl->val) {
  24810. + case V4L2_EXPOSURE_METERING_AVERAGE:
  24811. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  24812. + break;
  24813. +
  24814. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  24815. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  24816. + break;
  24817. +
  24818. + case V4L2_EXPOSURE_METERING_SPOT:
  24819. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  24820. + break;
  24821. +
  24822. + /* todo matrix weighting not added to Linux API till 3.9
  24823. + case V4L2_EXPOSURE_METERING_MATRIX:
  24824. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  24825. + break;
  24826. + */
  24827. +
  24828. + }
  24829. +
  24830. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  24831. + struct vchiq_mmal_port *control;
  24832. + u32 u32_value = dev->metering_mode;
  24833. +
  24834. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24835. +
  24836. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24837. + mmal_ctrl->mmal_id,
  24838. + &u32_value, sizeof(u32_value));
  24839. + } else
  24840. + return 0;
  24841. +}
  24842. +
  24843. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  24844. + struct v4l2_ctrl *ctrl,
  24845. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24846. +{
  24847. + u32 u32_value;
  24848. + struct vchiq_mmal_port *control;
  24849. +
  24850. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24851. +
  24852. + switch (ctrl->val) {
  24853. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  24854. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  24855. + break;
  24856. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  24857. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  24858. + break;
  24859. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  24860. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  24861. + break;
  24862. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  24863. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  24864. + break;
  24865. + }
  24866. +
  24867. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24868. + mmal_ctrl->mmal_id,
  24869. + &u32_value, sizeof(u32_value));
  24870. +}
  24871. +
  24872. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  24873. + struct v4l2_ctrl *ctrl,
  24874. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24875. +{
  24876. + u32 u32_value;
  24877. + struct vchiq_mmal_port *control;
  24878. +
  24879. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24880. +
  24881. + switch (ctrl->val) {
  24882. + case V4L2_WHITE_BALANCE_MANUAL:
  24883. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  24884. + break;
  24885. +
  24886. + case V4L2_WHITE_BALANCE_AUTO:
  24887. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  24888. + break;
  24889. +
  24890. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  24891. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  24892. + break;
  24893. +
  24894. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  24895. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  24896. + break;
  24897. +
  24898. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  24899. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  24900. + break;
  24901. +
  24902. + case V4L2_WHITE_BALANCE_HORIZON:
  24903. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  24904. + break;
  24905. +
  24906. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  24907. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  24908. + break;
  24909. +
  24910. + case V4L2_WHITE_BALANCE_FLASH:
  24911. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  24912. + break;
  24913. +
  24914. + case V4L2_WHITE_BALANCE_CLOUDY:
  24915. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  24916. + break;
  24917. +
  24918. + case V4L2_WHITE_BALANCE_SHADE:
  24919. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  24920. + break;
  24921. +
  24922. + }
  24923. +
  24924. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24925. + mmal_ctrl->mmal_id,
  24926. + &u32_value, sizeof(u32_value));
  24927. +}
  24928. +
  24929. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  24930. + struct v4l2_ctrl *ctrl,
  24931. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24932. +{
  24933. + struct vchiq_mmal_port *control;
  24934. + struct mmal_parameter_awbgains gains;
  24935. +
  24936. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24937. +
  24938. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  24939. + dev->red_gain = ctrl->val;
  24940. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  24941. + dev->blue_gain = ctrl->val;
  24942. +
  24943. + gains.r_gain.num = dev->red_gain;
  24944. + gains.b_gain.num = dev->blue_gain;
  24945. + gains.r_gain.den = gains.b_gain.den = 1000;
  24946. +
  24947. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  24948. + mmal_ctrl->mmal_id,
  24949. + &gains, sizeof(gains));
  24950. +}
  24951. +
  24952. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  24953. + struct v4l2_ctrl *ctrl,
  24954. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  24955. +{
  24956. + int ret = -EINVAL;
  24957. + int i, j;
  24958. + struct vchiq_mmal_port *control;
  24959. + struct mmal_parameter_imagefx_parameters imagefx;
  24960. +
  24961. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  24962. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  24963. +
  24964. + imagefx.effect =
  24965. + v4l2_to_mmal_effects_values[i].mmal_effect;
  24966. + imagefx.num_effect_params =
  24967. + v4l2_to_mmal_effects_values[i].num_effect_params;
  24968. +
  24969. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  24970. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  24971. +
  24972. + for (j = 0; j < imagefx.num_effect_params; j++)
  24973. + imagefx.effect_parameter[j] =
  24974. + v4l2_to_mmal_effects_values[i].effect_params[j];
  24975. +
  24976. + dev->colourfx.enable =
  24977. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  24978. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  24979. + dev->colourfx.u =
  24980. + v4l2_to_mmal_effects_values[i].u;
  24981. + dev->colourfx.v =
  24982. + v4l2_to_mmal_effects_values[i].v;
  24983. + }
  24984. +
  24985. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  24986. +
  24987. + ret = vchiq_mmal_port_parameter_set(
  24988. + dev->instance, control,
  24989. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  24990. + &imagefx, sizeof(imagefx));
  24991. + if (ret)
  24992. + goto exit;
  24993. +
  24994. + ret = vchiq_mmal_port_parameter_set(
  24995. + dev->instance, control,
  24996. + MMAL_PARAMETER_COLOUR_EFFECT,
  24997. + &dev->colourfx, sizeof(dev->colourfx));
  24998. + }
  24999. + }
  25000. +
  25001. +exit:
  25002. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25003. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  25004. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  25005. + dev->colourfx.enable ? "true" : "false",
  25006. + dev->colourfx.u, dev->colourfx.v,
  25007. + ret, (ret == 0 ? 0 : -EINVAL));
  25008. + return (ret == 0 ? 0 : EINVAL);
  25009. +}
  25010. +
  25011. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  25012. + struct v4l2_ctrl *ctrl,
  25013. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25014. +{
  25015. + int ret = -EINVAL;
  25016. + struct vchiq_mmal_port *control;
  25017. +
  25018. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  25019. +
  25020. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  25021. + dev->colourfx.enable = ctrl->val & 0xff;
  25022. +
  25023. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  25024. + MMAL_PARAMETER_COLOUR_EFFECT,
  25025. + &dev->colourfx, sizeof(dev->colourfx));
  25026. +
  25027. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25028. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  25029. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  25030. + (ret == 0 ? 0 : -EINVAL));
  25031. + return (ret == 0 ? 0 : EINVAL);
  25032. +}
  25033. +
  25034. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  25035. + struct v4l2_ctrl *ctrl,
  25036. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25037. +{
  25038. + int ret;
  25039. + struct vchiq_mmal_port *encoder_out;
  25040. +
  25041. + dev->capture.encode_bitrate = ctrl->val;
  25042. +
  25043. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  25044. +
  25045. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  25046. + mmal_ctrl->mmal_id,
  25047. + &ctrl->val, sizeof(ctrl->val));
  25048. + ret = 0;
  25049. + return ret;
  25050. +}
  25051. +
  25052. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  25053. + struct v4l2_ctrl *ctrl,
  25054. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25055. +{
  25056. + u32 bitrate_mode;
  25057. + struct vchiq_mmal_port *encoder_out;
  25058. +
  25059. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  25060. +
  25061. + dev->capture.encode_bitrate_mode = ctrl->val;
  25062. + switch (ctrl->val) {
  25063. + default:
  25064. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  25065. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  25066. + break;
  25067. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  25068. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  25069. + break;
  25070. + }
  25071. +
  25072. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  25073. + mmal_ctrl->mmal_id,
  25074. + &bitrate_mode,
  25075. + sizeof(bitrate_mode));
  25076. + return 0;
  25077. +}
  25078. +
  25079. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  25080. + struct v4l2_ctrl *ctrl,
  25081. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25082. +{
  25083. + u32 u32_value;
  25084. + struct vchiq_mmal_port *jpeg_out;
  25085. +
  25086. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  25087. +
  25088. + u32_value = ctrl->val;
  25089. +
  25090. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  25091. + mmal_ctrl->mmal_id,
  25092. + &u32_value, sizeof(u32_value));
  25093. +}
  25094. +
  25095. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  25096. + struct v4l2_ctrl *ctrl,
  25097. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25098. +{
  25099. + u32 u32_value;
  25100. + struct vchiq_mmal_port *vid_enc_ctl;
  25101. +
  25102. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  25103. +
  25104. + u32_value = ctrl->val;
  25105. +
  25106. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  25107. + mmal_ctrl->mmal_id,
  25108. + &u32_value, sizeof(u32_value));
  25109. +}
  25110. +
  25111. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  25112. + struct v4l2_ctrl *ctrl,
  25113. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25114. +{
  25115. + struct mmal_parameter_video_profile param;
  25116. + int ret = 0;
  25117. +
  25118. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  25119. + switch (ctrl->val) {
  25120. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  25121. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  25122. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  25123. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  25124. + dev->capture.enc_profile = ctrl->val;
  25125. + break;
  25126. + default:
  25127. + ret = -EINVAL;
  25128. + break;
  25129. + }
  25130. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  25131. + switch (ctrl->val) {
  25132. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  25133. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  25134. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  25135. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  25136. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  25137. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  25138. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  25139. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  25140. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  25141. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  25142. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  25143. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  25144. + dev->capture.enc_level = ctrl->val;
  25145. + break;
  25146. + default:
  25147. + ret = -EINVAL;
  25148. + break;
  25149. + }
  25150. + }
  25151. +
  25152. + if (!ret) {
  25153. + switch (dev->capture.enc_profile) {
  25154. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  25155. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  25156. + break;
  25157. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  25158. + param.profile =
  25159. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  25160. + break;
  25161. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  25162. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  25163. + break;
  25164. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  25165. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  25166. + break;
  25167. + default:
  25168. + /* Should never get here */
  25169. + break;
  25170. + }
  25171. +
  25172. + switch (dev->capture.enc_level) {
  25173. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  25174. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  25175. + break;
  25176. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  25177. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  25178. + break;
  25179. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  25180. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  25181. + break;
  25182. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  25183. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  25184. + break;
  25185. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  25186. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  25187. + break;
  25188. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  25189. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  25190. + break;
  25191. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  25192. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  25193. + break;
  25194. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  25195. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  25196. + break;
  25197. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  25198. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  25199. + break;
  25200. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  25201. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  25202. + break;
  25203. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  25204. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  25205. + break;
  25206. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  25207. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  25208. + break;
  25209. + default:
  25210. + /* Should never get here */
  25211. + break;
  25212. + }
  25213. +
  25214. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  25215. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  25216. + mmal_ctrl->mmal_id,
  25217. + &param, sizeof(param));
  25218. + }
  25219. + return ret;
  25220. +}
  25221. +
  25222. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  25223. + struct v4l2_ctrl *ctrl,
  25224. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  25225. +{
  25226. + int ret = 0;
  25227. + int shutter_speed;
  25228. + struct vchiq_mmal_port *control;
  25229. +
  25230. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25231. + "scene mode selected %d, was %d\n", ctrl->val,
  25232. + dev->scene_mode);
  25233. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  25234. +
  25235. + if (ctrl->val == dev->scene_mode)
  25236. + return 0;
  25237. +
  25238. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  25239. + /* Restore all user selections */
  25240. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  25241. +
  25242. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  25243. + shutter_speed = dev->manual_shutter_speed;
  25244. + else
  25245. + shutter_speed = 0;
  25246. +
  25247. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25248. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  25249. + __func__, shutter_speed, dev->exposure_mode_user,
  25250. + dev->metering_mode);
  25251. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  25252. + control,
  25253. + MMAL_PARAMETER_SHUTTER_SPEED,
  25254. + &shutter_speed,
  25255. + sizeof(shutter_speed));
  25256. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  25257. + control,
  25258. + MMAL_PARAMETER_EXPOSURE_MODE,
  25259. + &dev->exposure_mode_user,
  25260. + sizeof(u32));
  25261. + dev->exposure_mode_active = dev->exposure_mode_user;
  25262. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  25263. + control,
  25264. + MMAL_PARAMETER_EXP_METERING_MODE,
  25265. + &dev->metering_mode,
  25266. + sizeof(u32));
  25267. + ret += set_framerate_params(dev);
  25268. + } else {
  25269. + /* Set up scene mode */
  25270. + int i;
  25271. + const struct v4l2_mmal_scene_config *scene = NULL;
  25272. + int shutter_speed;
  25273. + enum mmal_parameter_exposuremode exposure_mode;
  25274. + enum mmal_parameter_exposuremeteringmode metering_mode;
  25275. +
  25276. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  25277. + if (scene_configs[i].v4l2_scene ==
  25278. + ctrl->val) {
  25279. + scene = &scene_configs[i];
  25280. + break;
  25281. + }
  25282. + }
  25283. + if (i >= ARRAY_SIZE(scene_configs))
  25284. + return -EINVAL;
  25285. +
  25286. + /* Set all the values */
  25287. + dev->scene_mode = ctrl->val;
  25288. +
  25289. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  25290. + shutter_speed = dev->manual_shutter_speed;
  25291. + else
  25292. + shutter_speed = 0;
  25293. + exposure_mode = scene->exposure_mode;
  25294. + metering_mode = scene->metering_mode;
  25295. +
  25296. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25297. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  25298. + __func__, shutter_speed, exposure_mode, metering_mode);
  25299. +
  25300. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  25301. + MMAL_PARAMETER_SHUTTER_SPEED,
  25302. + &shutter_speed,
  25303. + sizeof(shutter_speed));
  25304. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  25305. + control,
  25306. + MMAL_PARAMETER_EXPOSURE_MODE,
  25307. + &exposure_mode,
  25308. + sizeof(u32));
  25309. + dev->exposure_mode_active = exposure_mode;
  25310. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  25311. + MMAL_PARAMETER_EXPOSURE_MODE,
  25312. + &exposure_mode,
  25313. + sizeof(u32));
  25314. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  25315. + MMAL_PARAMETER_EXP_METERING_MODE,
  25316. + &metering_mode,
  25317. + sizeof(u32));
  25318. + ret += set_framerate_params(dev);
  25319. + }
  25320. + if (ret) {
  25321. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25322. + "%s: Setting scene to %d, ret=%d\n",
  25323. + __func__, ctrl->val, ret);
  25324. + ret = -EINVAL;
  25325. + }
  25326. + return 0;
  25327. +}
  25328. +
  25329. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  25330. +{
  25331. + struct bm2835_mmal_dev *dev =
  25332. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  25333. + ctrl_handler);
  25334. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  25335. + int ret;
  25336. +
  25337. + if ((mmal_ctrl == NULL) ||
  25338. + (mmal_ctrl->id != ctrl->id) ||
  25339. + (mmal_ctrl->setter == NULL)) {
  25340. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  25341. + return -EINVAL;
  25342. + }
  25343. +
  25344. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  25345. + if (ret)
  25346. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  25347. + ctrl->id, mmal_ctrl->mmal_id, ret);
  25348. + if (mmal_ctrl->ignore_errors)
  25349. + ret = 0;
  25350. + return ret;
  25351. +}
  25352. +
  25353. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  25354. + .s_ctrl = bm2835_mmal_s_ctrl,
  25355. +};
  25356. +
  25357. +
  25358. +
  25359. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  25360. + {
  25361. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  25362. + -100, 100, 0, 1, NULL,
  25363. + MMAL_PARAMETER_SATURATION,
  25364. + &ctrl_set_rational,
  25365. + false
  25366. + },
  25367. + {
  25368. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  25369. + -100, 100, 0, 1, NULL,
  25370. + MMAL_PARAMETER_SHARPNESS,
  25371. + &ctrl_set_rational,
  25372. + false
  25373. + },
  25374. + {
  25375. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  25376. + -100, 100, 0, 1, NULL,
  25377. + MMAL_PARAMETER_CONTRAST,
  25378. + &ctrl_set_rational,
  25379. + false
  25380. + },
  25381. + {
  25382. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  25383. + 0, 100, 50, 1, NULL,
  25384. + MMAL_PARAMETER_BRIGHTNESS,
  25385. + &ctrl_set_rational,
  25386. + false
  25387. + },
  25388. + {
  25389. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  25390. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  25391. + MMAL_PARAMETER_ISO,
  25392. + &ctrl_set_value_menu,
  25393. + false
  25394. + },
  25395. + {
  25396. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  25397. + 0, 1, 0, 1, NULL,
  25398. + MMAL_PARAMETER_VIDEO_STABILISATION,
  25399. + &ctrl_set_value,
  25400. + false
  25401. + },
  25402. +/* {
  25403. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  25404. + }, */
  25405. + {
  25406. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  25407. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  25408. + MMAL_PARAMETER_EXPOSURE_MODE,
  25409. + &ctrl_set_exposure,
  25410. + false
  25411. + },
  25412. +/* todo this needs mixing in with set exposure
  25413. + {
  25414. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  25415. + },
  25416. + */
  25417. + {
  25418. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  25419. + /* Units of 100usecs */
  25420. + 1, 1*1000*10, 100*10, 1, NULL,
  25421. + MMAL_PARAMETER_SHUTTER_SPEED,
  25422. + &ctrl_set_exposure,
  25423. + false
  25424. + },
  25425. + {
  25426. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  25427. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  25428. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  25429. + MMAL_PARAMETER_EXPOSURE_COMP,
  25430. + &ctrl_set_value_ev,
  25431. + false
  25432. + },
  25433. + {
  25434. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  25435. + 0, 1,
  25436. + 0, 1, NULL,
  25437. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  25438. + &ctrl_set_exposure,
  25439. + false
  25440. + },
  25441. + {
  25442. + V4L2_CID_EXPOSURE_METERING,
  25443. + MMAL_CONTROL_TYPE_STD_MENU,
  25444. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  25445. + MMAL_PARAMETER_EXP_METERING_MODE,
  25446. + &ctrl_set_metering_mode,
  25447. + false
  25448. + },
  25449. + {
  25450. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  25451. + MMAL_CONTROL_TYPE_STD_MENU,
  25452. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  25453. + MMAL_PARAMETER_AWB_MODE,
  25454. + &ctrl_set_awb_mode,
  25455. + false
  25456. + },
  25457. + {
  25458. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  25459. + 1, 7999, 1000, 1, NULL,
  25460. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  25461. + &ctrl_set_awb_gains,
  25462. + false
  25463. + },
  25464. + {
  25465. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  25466. + 1, 7999, 1000, 1, NULL,
  25467. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  25468. + &ctrl_set_awb_gains,
  25469. + false
  25470. + },
  25471. + {
  25472. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  25473. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  25474. + MMAL_PARAMETER_IMAGE_EFFECT,
  25475. + &ctrl_set_image_effect,
  25476. + false
  25477. + },
  25478. + {
  25479. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  25480. + 0, 0xffff, 0x8080, 1, NULL,
  25481. + MMAL_PARAMETER_COLOUR_EFFECT,
  25482. + &ctrl_set_colfx,
  25483. + false
  25484. + },
  25485. + {
  25486. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  25487. + 0, 360, 0, 90, NULL,
  25488. + MMAL_PARAMETER_ROTATION,
  25489. + &ctrl_set_rotate,
  25490. + false
  25491. + },
  25492. + {
  25493. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  25494. + 0, 1, 0, 1, NULL,
  25495. + MMAL_PARAMETER_MIRROR,
  25496. + &ctrl_set_flip,
  25497. + false
  25498. + },
  25499. + {
  25500. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  25501. + 0, 1, 0, 1, NULL,
  25502. + MMAL_PARAMETER_MIRROR,
  25503. + &ctrl_set_flip,
  25504. + false
  25505. + },
  25506. + {
  25507. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  25508. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  25509. + 0, 0, bitrate_mode_qmenu,
  25510. + MMAL_PARAMETER_RATECONTROL,
  25511. + &ctrl_set_bitrate_mode,
  25512. + false
  25513. + },
  25514. + {
  25515. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  25516. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  25517. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  25518. + &ctrl_set_bitrate,
  25519. + false
  25520. + },
  25521. + {
  25522. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  25523. + 1, 100,
  25524. + 30, 1, NULL,
  25525. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  25526. + &ctrl_set_image_encode_output,
  25527. + false
  25528. + },
  25529. + {
  25530. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  25531. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  25532. + 1, 1, NULL,
  25533. + MMAL_PARAMETER_FLICKER_AVOID,
  25534. + &ctrl_set_flicker_avoidance,
  25535. + false
  25536. + },
  25537. + {
  25538. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  25539. + 0, 1,
  25540. + 0, 1, NULL,
  25541. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  25542. + &ctrl_set_video_encode_param_output,
  25543. + true /* Errors ignored as requires latest firmware to work */
  25544. + },
  25545. + {
  25546. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  25547. + MMAL_CONTROL_TYPE_STD_MENU,
  25548. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  25549. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  25550. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  25551. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  25552. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  25553. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  25554. + MMAL_PARAMETER_PROFILE,
  25555. + &ctrl_set_video_encode_profile_level,
  25556. + false
  25557. + },
  25558. + {
  25559. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  25560. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  25561. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  25562. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  25563. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  25564. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  25565. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  25566. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  25567. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  25568. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  25569. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  25570. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  25571. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  25572. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  25573. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  25574. + MMAL_PARAMETER_PROFILE,
  25575. + &ctrl_set_video_encode_profile_level,
  25576. + false
  25577. + },
  25578. + {
  25579. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  25580. + -1, /* Min is computed at runtime */
  25581. + V4L2_SCENE_MODE_TEXT,
  25582. + V4L2_SCENE_MODE_NONE, 1, NULL,
  25583. + MMAL_PARAMETER_PROFILE,
  25584. + &ctrl_set_scene_mode,
  25585. + false
  25586. + },
  25587. + {
  25588. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  25589. + 0, 0x7FFFFFFF, 60, 1, NULL,
  25590. + MMAL_PARAMETER_INTRAPERIOD,
  25591. + &ctrl_set_video_encode_param_output,
  25592. + false
  25593. + },
  25594. +};
  25595. +
  25596. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  25597. +{
  25598. + int c;
  25599. + int ret = 0;
  25600. +
  25601. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  25602. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  25603. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  25604. + &v4l2_ctrls[c]);
  25605. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  25606. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25607. + "Failed when setting default values for ctrl %d\n",
  25608. + c);
  25609. + break;
  25610. + }
  25611. + }
  25612. + }
  25613. + return ret;
  25614. +}
  25615. +
  25616. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  25617. +{
  25618. + struct mmal_parameter_fps_range fps_range;
  25619. + int ret;
  25620. +
  25621. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  25622. + (dev->exp_auto_priority)) {
  25623. + /* Variable FPS. Define min FPS as 1fps.
  25624. + * Max as max defined FPS.
  25625. + */
  25626. + fps_range.fps_low.num = 1;
  25627. + fps_range.fps_low.den = 1;
  25628. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  25629. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  25630. + } else {
  25631. + /* Fixed FPS - set min and max to be the same */
  25632. + fps_range.fps_low.num = fps_range.fps_high.num =
  25633. + dev->capture.timeperframe.denominator;
  25634. + fps_range.fps_low.den = fps_range.fps_high.den =
  25635. + dev->capture.timeperframe.numerator;
  25636. + }
  25637. +
  25638. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25639. + "Set fps range to %d/%d to %d/%d\n",
  25640. + fps_range.fps_low.num,
  25641. + fps_range.fps_low.den,
  25642. + fps_range.fps_high.num,
  25643. + fps_range.fps_high.den
  25644. + );
  25645. +
  25646. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  25647. + &dev->component[MMAL_COMPONENT_CAMERA]->
  25648. + output[MMAL_CAMERA_PORT_PREVIEW],
  25649. + MMAL_PARAMETER_FPS_RANGE,
  25650. + &fps_range, sizeof(fps_range));
  25651. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  25652. + &dev->component[MMAL_COMPONENT_CAMERA]->
  25653. + output[MMAL_CAMERA_PORT_VIDEO],
  25654. + MMAL_PARAMETER_FPS_RANGE,
  25655. + &fps_range, sizeof(fps_range));
  25656. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  25657. + &dev->component[MMAL_COMPONENT_CAMERA]->
  25658. + output[MMAL_CAMERA_PORT_CAPTURE],
  25659. + MMAL_PARAMETER_FPS_RANGE,
  25660. + &fps_range, sizeof(fps_range));
  25661. + if (ret)
  25662. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  25663. + "Failed to set fps ret %d\n",
  25664. + ret);
  25665. +
  25666. + return ret;
  25667. +
  25668. +}
  25669. +
  25670. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  25671. + struct v4l2_ctrl_handler *hdl)
  25672. +{
  25673. + int c;
  25674. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  25675. +
  25676. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  25677. +
  25678. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  25679. + ctrl = &v4l2_ctrls[c];
  25680. +
  25681. + switch (ctrl->type) {
  25682. + case MMAL_CONTROL_TYPE_STD:
  25683. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  25684. + &bm2835_mmal_ctrl_ops, ctrl->id,
  25685. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  25686. + break;
  25687. +
  25688. + case MMAL_CONTROL_TYPE_STD_MENU:
  25689. + {
  25690. + int mask = ctrl->min;
  25691. +
  25692. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  25693. + /* Special handling to work out the mask
  25694. + * value based on the scene_configs array
  25695. + * at runtime. Reduces the chance of
  25696. + * mismatches.
  25697. + */
  25698. + int i;
  25699. + mask = 1<<V4L2_SCENE_MODE_NONE;
  25700. + for (i = 0;
  25701. + i < ARRAY_SIZE(scene_configs);
  25702. + i++) {
  25703. + mask |= 1<<scene_configs[i].v4l2_scene;
  25704. + }
  25705. + mask = ~mask;
  25706. + }
  25707. +
  25708. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  25709. + &bm2835_mmal_ctrl_ops, ctrl->id,
  25710. + ctrl->max, mask, ctrl->def);
  25711. + break;
  25712. + }
  25713. +
  25714. + case MMAL_CONTROL_TYPE_INT_MENU:
  25715. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  25716. + &bm2835_mmal_ctrl_ops, ctrl->id,
  25717. + ctrl->max, ctrl->def, ctrl->imenu);
  25718. + break;
  25719. +
  25720. + case MMAL_CONTROL_TYPE_CLUSTER:
  25721. + /* skip this entry when constructing controls */
  25722. + continue;
  25723. + }
  25724. +
  25725. + if (hdl->error)
  25726. + break;
  25727. +
  25728. + dev->ctrls[c]->priv = (void *)ctrl;
  25729. + }
  25730. +
  25731. + if (hdl->error) {
  25732. + pr_err("error adding control %d/%d id 0x%x\n", c,
  25733. + V4L2_CTRL_COUNT, ctrl->id);
  25734. + return hdl->error;
  25735. + }
  25736. +
  25737. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  25738. + ctrl = &v4l2_ctrls[c];
  25739. +
  25740. + switch (ctrl->type) {
  25741. + case MMAL_CONTROL_TYPE_CLUSTER:
  25742. + v4l2_ctrl_auto_cluster(ctrl->min,
  25743. + &dev->ctrls[c+1],
  25744. + ctrl->max,
  25745. + ctrl->def);
  25746. + break;
  25747. +
  25748. + case MMAL_CONTROL_TYPE_STD:
  25749. + case MMAL_CONTROL_TYPE_STD_MENU:
  25750. + case MMAL_CONTROL_TYPE_INT_MENU:
  25751. + break;
  25752. + }
  25753. +
  25754. + }
  25755. +
  25756. + return 0;
  25757. +}
  25758. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  25759. --- linux-3.12.38/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  25760. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2015-03-10 17:26:50.466216693 +0100
  25761. @@ -0,0 +1,25 @@
  25762. +# Broadcom VideoCore IV v4l2 camera support
  25763. +
  25764. +config VIDEO_BCM2835
  25765. + bool "Broadcom BCM2835 camera interface driver"
  25766. + depends on VIDEO_V4L2 && ARCH_BCM2708
  25767. + ---help---
  25768. + Say Y here to enable camera host interface devices for
  25769. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  25770. + to a service running on VideoCore.
  25771. +
  25772. +
  25773. +if VIDEO_BCM2835
  25774. +
  25775. +config VIDEO_BCM2835_MMAL
  25776. + tristate "Broadcom BM2835 MMAL camera interface driver"
  25777. + depends on BCM2708_VCHIQ
  25778. + select VIDEOBUF2_VMALLOC
  25779. + ---help---
  25780. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  25781. +
  25782. + To compile this driver as a module, choose M here: the
  25783. + module will be called bcm2835-v4l2.o
  25784. +
  25785. +
  25786. +endif # VIDEO_BM2835
  25787. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  25788. --- linux-3.12.38/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  25789. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2015-03-09 10:39:30.594893734 +0100
  25790. @@ -0,0 +1,5 @@
  25791. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  25792. +
  25793. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  25794. +
  25795. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  25796. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  25797. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  25798. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2015-03-09 10:39:30.594893734 +0100
  25799. @@ -0,0 +1,53 @@
  25800. +/*
  25801. + * Broadcom BM2835 V4L2 driver
  25802. + *
  25803. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  25804. + *
  25805. + * This file is subject to the terms and conditions of the GNU General Public
  25806. + * License. See the file COPYING in the main directory of this archive
  25807. + * for more details.
  25808. + *
  25809. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  25810. + * Dave Stevenson <dsteve@broadcom.com>
  25811. + * Simon Mellor <simellor@broadcom.com>
  25812. + * Luke Diamand <luked@broadcom.com>
  25813. + *
  25814. + * MMAL structures
  25815. + *
  25816. + */
  25817. +
  25818. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  25819. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  25820. +
  25821. +/** Special value signalling that time is not known */
  25822. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  25823. +
  25824. +/* mapping between v4l and mmal video modes */
  25825. +struct mmal_fmt {
  25826. + char *name;
  25827. + u32 fourcc; /* v4l2 format id */
  25828. + int flags; /* v4l2 flags field */
  25829. + u32 mmal;
  25830. + int depth;
  25831. + u32 mmal_component; /* MMAL component index to be used to encode */
  25832. +};
  25833. +
  25834. +/* buffer for one video frame */
  25835. +struct mmal_buffer {
  25836. + /* v4l buffer data -- must be first */
  25837. + struct vb2_buffer vb;
  25838. +
  25839. + /* list of buffers available */
  25840. + struct list_head list;
  25841. +
  25842. + void *buffer; /* buffer pointer */
  25843. + unsigned long buffer_size; /* size of allocated buffer */
  25844. +};
  25845. +
  25846. +/* */
  25847. +struct mmal_colourfx {
  25848. + s32 enable;
  25849. + u32 u;
  25850. + u32 v;
  25851. +};
  25852. +
  25853. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  25854. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  25855. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2015-03-09 10:39:30.594893734 +0100
  25856. @@ -0,0 +1,127 @@
  25857. +/*
  25858. + * Broadcom BM2835 V4L2 driver
  25859. + *
  25860. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  25861. + *
  25862. + * This file is subject to the terms and conditions of the GNU General Public
  25863. + * License. See the file COPYING in the main directory of this archive
  25864. + * for more details.
  25865. + *
  25866. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  25867. + * Dave Stevenson <dsteve@broadcom.com>
  25868. + * Simon Mellor <simellor@broadcom.com>
  25869. + * Luke Diamand <luked@broadcom.com>
  25870. + */
  25871. +#ifndef MMAL_ENCODINGS_H
  25872. +#define MMAL_ENCODINGS_H
  25873. +
  25874. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  25875. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  25876. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  25877. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  25878. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  25879. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  25880. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  25881. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  25882. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  25883. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  25884. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  25885. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  25886. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  25887. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  25888. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  25889. +
  25890. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  25891. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  25892. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  25893. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  25894. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  25895. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  25896. +
  25897. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  25898. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  25899. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  25900. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  25901. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  25902. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  25903. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  25904. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  25905. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  25906. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  25907. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  25908. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  25909. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  25910. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  25911. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  25912. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  25913. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  25914. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  25915. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  25916. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  25917. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  25918. +
  25919. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  25920. + * This format is *not* opaque - if requested you will receive full frames
  25921. + * of YUV_UV video.
  25922. + */
  25923. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  25924. +
  25925. +/** VideoCore opaque image format, image handles are returned to
  25926. + * the host but not the actual image data.
  25927. + */
  25928. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  25929. +
  25930. +/** An EGL image handle
  25931. + */
  25932. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  25933. +
  25934. +/* }@ */
  25935. +
  25936. +/** \name Pre-defined audio encodings */
  25937. +/* @{ */
  25938. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  25939. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  25940. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  25941. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  25942. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  25943. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  25944. +
  25945. +/* Pre-defined H264 encoding variants */
  25946. +
  25947. +/** ISO 14496-10 Annex B byte stream format */
  25948. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  25949. +/** ISO 14496-15 AVC stream format */
  25950. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  25951. +/** Implicitly delineated NAL units without emulation prevention */
  25952. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  25953. +
  25954. +
  25955. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  25956. + * This defines a list of common color spaces. This list isn't exhaustive and
  25957. + * is only provided as a convenience to avoid clients having to use FourCC
  25958. + * codes directly. However components are allowed to define and use their own
  25959. + * FourCC codes.
  25960. + */
  25961. +/* @{ */
  25962. +
  25963. +/** Unknown color space */
  25964. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  25965. +/** ITU-R BT.601-5 [SDTV] */
  25966. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  25967. +/** ITU-R BT.709-3 [HDTV] */
  25968. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  25969. +/** JPEG JFIF */
  25970. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  25971. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  25972. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  25973. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  25974. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  25975. +/** ITU-R BT.470-2 System M */
  25976. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  25977. +/** ITU-R BT.470-2 System BG */
  25978. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  25979. +/** JPEG JFIF, but with 16..255 luma */
  25980. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  25981. +/* @} MmalColorSpace List */
  25982. +
  25983. +#endif /* MMAL_ENCODINGS_H */
  25984. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  25985. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  25986. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2015-03-09 10:39:30.594893734 +0100
  25987. @@ -0,0 +1,50 @@
  25988. +/*
  25989. + * Broadcom BM2835 V4L2 driver
  25990. + *
  25991. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  25992. + *
  25993. + * This file is subject to the terms and conditions of the GNU General Public
  25994. + * License. See the file COPYING in the main directory of this archive
  25995. + * for more details.
  25996. + *
  25997. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  25998. + * Dave Stevenson <dsteve@broadcom.com>
  25999. + * Simon Mellor <simellor@broadcom.com>
  26000. + * Luke Diamand <luked@broadcom.com>
  26001. + */
  26002. +
  26003. +#ifndef MMAL_MSG_COMMON_H
  26004. +#define MMAL_MSG_COMMON_H
  26005. +
  26006. +enum mmal_msg_status {
  26007. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  26008. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  26009. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  26010. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  26011. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  26012. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  26013. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  26014. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  26015. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  26016. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  26017. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  26018. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  26019. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  26020. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  26021. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  26022. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  26023. +};
  26024. +
  26025. +struct mmal_rect {
  26026. + s32 x; /**< x coordinate (from left) */
  26027. + s32 y; /**< y coordinate (from top) */
  26028. + s32 width; /**< width */
  26029. + s32 height; /**< height */
  26030. +};
  26031. +
  26032. +struct mmal_rational {
  26033. + s32 num; /**< Numerator */
  26034. + s32 den; /**< Denominator */
  26035. +};
  26036. +
  26037. +#endif /* MMAL_MSG_COMMON_H */
  26038. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  26039. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  26040. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2015-03-09 10:39:30.594893734 +0100
  26041. @@ -0,0 +1,81 @@
  26042. +/*
  26043. + * Broadcom BM2835 V4L2 driver
  26044. + *
  26045. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26046. + *
  26047. + * This file is subject to the terms and conditions of the GNU General Public
  26048. + * License. See the file COPYING in the main directory of this archive
  26049. + * for more details.
  26050. + *
  26051. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26052. + * Dave Stevenson <dsteve@broadcom.com>
  26053. + * Simon Mellor <simellor@broadcom.com>
  26054. + * Luke Diamand <luked@broadcom.com>
  26055. + */
  26056. +
  26057. +#ifndef MMAL_MSG_FORMAT_H
  26058. +#define MMAL_MSG_FORMAT_H
  26059. +
  26060. +#include "mmal-msg-common.h"
  26061. +
  26062. +/* MMAL_ES_FORMAT_T */
  26063. +
  26064. +
  26065. +struct mmal_audio_format {
  26066. + u32 channels; /**< Number of audio channels */
  26067. + u32 sample_rate; /**< Sample rate */
  26068. +
  26069. + u32 bits_per_sample; /**< Bits per sample */
  26070. + u32 block_align; /**< Size of a block of data */
  26071. +};
  26072. +
  26073. +struct mmal_video_format {
  26074. + u32 width; /**< Width of frame in pixels */
  26075. + u32 height; /**< Height of frame in rows of pixels */
  26076. + struct mmal_rect crop; /**< Visible region of the frame */
  26077. + struct mmal_rational frame_rate; /**< Frame rate */
  26078. + struct mmal_rational par; /**< Pixel aspect ratio */
  26079. +
  26080. + /* FourCC specifying the color space of the video stream. See the
  26081. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  26082. + */
  26083. + u32 color_space;
  26084. +};
  26085. +
  26086. +struct mmal_subpicture_format {
  26087. + u32 x_offset;
  26088. + u32 y_offset;
  26089. +};
  26090. +
  26091. +union mmal_es_specific_format {
  26092. + struct mmal_audio_format audio;
  26093. + struct mmal_video_format video;
  26094. + struct mmal_subpicture_format subpicture;
  26095. +};
  26096. +
  26097. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  26098. +struct mmal_es_format {
  26099. + u32 type; /* enum mmal_es_type */
  26100. +
  26101. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  26102. + u32 encoding_variant; /* FourCC specifying the specific
  26103. + * encoding variant of the elementary
  26104. + * stream.
  26105. + */
  26106. +
  26107. + union mmal_es_specific_format *es; /* TODO: pointers in
  26108. + * message serialisation?!?
  26109. + */
  26110. + /* Type specific
  26111. + * information for the
  26112. + * elementary stream
  26113. + */
  26114. +
  26115. + u32 bitrate; /**< Bitrate in bits per second */
  26116. + u32 flags; /**< Flags describing properties of the elementary stream. */
  26117. +
  26118. + u32 extradata_size; /**< Size of the codec specific data */
  26119. + u8 *extradata; /**< Codec specific data */
  26120. +};
  26121. +
  26122. +#endif /* MMAL_MSG_FORMAT_H */
  26123. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  26124. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  26125. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2015-03-09 10:39:30.594893734 +0100
  26126. @@ -0,0 +1,404 @@
  26127. +/*
  26128. + * Broadcom BM2835 V4L2 driver
  26129. + *
  26130. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26131. + *
  26132. + * This file is subject to the terms and conditions of the GNU General Public
  26133. + * License. See the file COPYING in the main directory of this archive
  26134. + * for more details.
  26135. + *
  26136. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26137. + * Dave Stevenson <dsteve@broadcom.com>
  26138. + * Simon Mellor <simellor@broadcom.com>
  26139. + * Luke Diamand <luked@broadcom.com>
  26140. + */
  26141. +
  26142. +/* all the data structures which serialise the MMAL protocol. note
  26143. + * these are directly mapped onto the recived message data.
  26144. + *
  26145. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  26146. + * structure padding!
  26147. + *
  26148. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  26149. + * than assigning values to enums to force their size the
  26150. + * implementation uses fixed size types and not the enums (though the
  26151. + * comments have the actual enum type
  26152. + */
  26153. +
  26154. +#define VC_MMAL_VER 15
  26155. +#define VC_MMAL_MIN_VER 10
  26156. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  26157. +
  26158. +/* max total message size is 512 bytes */
  26159. +#define MMAL_MSG_MAX_SIZE 512
  26160. +/* with six 32bit header elements max payload is therefore 488 bytes */
  26161. +#define MMAL_MSG_MAX_PAYLOAD 488
  26162. +
  26163. +#include "mmal-msg-common.h"
  26164. +#include "mmal-msg-format.h"
  26165. +#include "mmal-msg-port.h"
  26166. +
  26167. +enum mmal_msg_type {
  26168. + MMAL_MSG_TYPE_QUIT = 1,
  26169. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  26170. + MMAL_MSG_TYPE_GET_VERSION,
  26171. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  26172. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  26173. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  26174. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  26175. + MMAL_MSG_TYPE_PORT_INFO_GET,
  26176. + MMAL_MSG_TYPE_PORT_INFO_SET,
  26177. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  26178. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  26179. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  26180. + MMAL_MSG_TYPE_GET_STATS,
  26181. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  26182. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  26183. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  26184. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  26185. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  26186. + MMAL_MSG_TYPE_CONSUME_MEM,
  26187. + MMAL_MSG_TYPE_LMK, /* 20 */
  26188. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  26189. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  26190. + MMAL_MSG_TYPE_DRM_GET_TIME,
  26191. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  26192. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  26193. + MMAL_MSG_TYPE_HOST_LOG,
  26194. + MMAL_MSG_TYPE_MSG_LAST
  26195. +};
  26196. +
  26197. +/* port action request messages differ depending on the action type */
  26198. +enum mmal_msg_port_action_type {
  26199. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  26200. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  26201. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  26202. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  26203. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  26204. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  26205. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  26206. +};
  26207. +
  26208. +struct mmal_msg_header {
  26209. + u32 magic;
  26210. + u32 type; /** enum mmal_msg_type */
  26211. +
  26212. + /* Opaque handle to the control service */
  26213. + struct mmal_control_service *control_service;
  26214. +
  26215. + struct mmal_msg_context *context; /** a u32 per message context */
  26216. + u32 status; /** The status of the vchiq operation */
  26217. + u32 padding;
  26218. +};
  26219. +
  26220. +/* Send from VC to host to report version */
  26221. +struct mmal_msg_version {
  26222. + u32 flags;
  26223. + u32 major;
  26224. + u32 minor;
  26225. + u32 minimum;
  26226. +};
  26227. +
  26228. +/* request to VC to create component */
  26229. +struct mmal_msg_component_create {
  26230. + void *client_component; /* component context */
  26231. + char name[128];
  26232. + u32 pid; /* For debug */
  26233. +};
  26234. +
  26235. +/* reply from VC to component creation request */
  26236. +struct mmal_msg_component_create_reply {
  26237. + u32 status; /** enum mmal_msg_status - how does this differ to
  26238. + * the one in the header?
  26239. + */
  26240. + u32 component_handle; /* VideoCore handle for component */
  26241. + u32 input_num; /* Number of input ports */
  26242. + u32 output_num; /* Number of output ports */
  26243. + u32 clock_num; /* Number of clock ports */
  26244. +};
  26245. +
  26246. +/* request to VC to destroy a component */
  26247. +struct mmal_msg_component_destroy {
  26248. + u32 component_handle;
  26249. +};
  26250. +
  26251. +struct mmal_msg_component_destroy_reply {
  26252. + u32 status; /** The component destruction status */
  26253. +};
  26254. +
  26255. +
  26256. +/* request and reply to VC to enable a component */
  26257. +struct mmal_msg_component_enable {
  26258. + u32 component_handle;
  26259. +};
  26260. +
  26261. +struct mmal_msg_component_enable_reply {
  26262. + u32 status; /** The component enable status */
  26263. +};
  26264. +
  26265. +
  26266. +/* request and reply to VC to disable a component */
  26267. +struct mmal_msg_component_disable {
  26268. + u32 component_handle;
  26269. +};
  26270. +
  26271. +struct mmal_msg_component_disable_reply {
  26272. + u32 status; /** The component disable status */
  26273. +};
  26274. +
  26275. +/* request to VC to get port information */
  26276. +struct mmal_msg_port_info_get {
  26277. + u32 component_handle; /* component handle port is associated with */
  26278. + u32 port_type; /* enum mmal_msg_port_type */
  26279. + u32 index; /* port index to query */
  26280. +};
  26281. +
  26282. +/* reply from VC to get port info request */
  26283. +struct mmal_msg_port_info_get_reply {
  26284. + u32 status; /** enum mmal_msg_status */
  26285. + u32 component_handle; /* component handle port is associated with */
  26286. + u32 port_type; /* enum mmal_msg_port_type */
  26287. + u32 port_index; /* port indexed in query */
  26288. + s32 found; /* unused */
  26289. + u32 port_handle; /**< Handle to use for this port */
  26290. + struct mmal_port port;
  26291. + struct mmal_es_format format; /* elementry stream format */
  26292. + union mmal_es_specific_format es; /* es type specific data */
  26293. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  26294. +};
  26295. +
  26296. +/* request to VC to set port information */
  26297. +struct mmal_msg_port_info_set {
  26298. + u32 component_handle;
  26299. + u32 port_type; /* enum mmal_msg_port_type */
  26300. + u32 port_index; /* port indexed in query */
  26301. + struct mmal_port port;
  26302. + struct mmal_es_format format;
  26303. + union mmal_es_specific_format es;
  26304. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  26305. +};
  26306. +
  26307. +/* reply from VC to port info set request */
  26308. +struct mmal_msg_port_info_set_reply {
  26309. + u32 status;
  26310. + u32 component_handle; /* component handle port is associated with */
  26311. + u32 port_type; /* enum mmal_msg_port_type */
  26312. + u32 index; /* port indexed in query */
  26313. + s32 found; /* unused */
  26314. + u32 port_handle; /**< Handle to use for this port */
  26315. + struct mmal_port port;
  26316. + struct mmal_es_format format;
  26317. + union mmal_es_specific_format es;
  26318. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  26319. +};
  26320. +
  26321. +
  26322. +/* port action requests that take a mmal_port as a parameter */
  26323. +struct mmal_msg_port_action_port {
  26324. + u32 component_handle;
  26325. + u32 port_handle;
  26326. + u32 action; /* enum mmal_msg_port_action_type */
  26327. + struct mmal_port port;
  26328. +};
  26329. +
  26330. +/* port action requests that take handles as a parameter */
  26331. +struct mmal_msg_port_action_handle {
  26332. + u32 component_handle;
  26333. + u32 port_handle;
  26334. + u32 action; /* enum mmal_msg_port_action_type */
  26335. + u32 connect_component_handle;
  26336. + u32 connect_port_handle;
  26337. +};
  26338. +
  26339. +struct mmal_msg_port_action_reply {
  26340. + u32 status; /** The port action operation status */
  26341. +};
  26342. +
  26343. +
  26344. +
  26345. +
  26346. +/* MMAL buffer transfer */
  26347. +
  26348. +/** Size of space reserved in a buffer message for short messages. */
  26349. +#define MMAL_VC_SHORT_DATA 128
  26350. +
  26351. +/** Signals that the current payload is the end of the stream of data */
  26352. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  26353. +/** Signals that the start of the current payload starts a frame */
  26354. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  26355. +/** Signals that the end of the current payload ends a frame */
  26356. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  26357. +/** Signals that the current payload contains only complete frames (>1) */
  26358. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  26359. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  26360. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  26361. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  26362. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  26363. + * Can be used for instance by a decoder to reset its state */
  26364. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  26365. +/** Signals a buffer containing some kind of config data for the component
  26366. + * (e.g. codec config data) */
  26367. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  26368. +/** Signals an encrypted payload */
  26369. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  26370. +/** Signals a buffer containing side information */
  26371. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  26372. +/** Signals a buffer which is the snapshot/postview image from a stills
  26373. + * capture
  26374. + */
  26375. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  26376. +/** Signals a buffer which contains data known to be corrupted */
  26377. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  26378. +/** Signals that a buffer failed to be transmitted */
  26379. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  26380. +
  26381. +struct mmal_driver_buffer {
  26382. + u32 magic;
  26383. + u32 component_handle;
  26384. + u32 port_handle;
  26385. + void *client_context;
  26386. +};
  26387. +
  26388. +/* buffer header */
  26389. +struct mmal_buffer_header {
  26390. + struct mmal_buffer_header *next; /* next header */
  26391. + void *priv; /* framework private data */
  26392. + u32 cmd;
  26393. + void *data;
  26394. + u32 alloc_size;
  26395. + u32 length;
  26396. + u32 offset;
  26397. + u32 flags;
  26398. + s64 pts;
  26399. + s64 dts;
  26400. + void *type;
  26401. + void *user_data;
  26402. +};
  26403. +
  26404. +struct mmal_buffer_header_type_specific {
  26405. + union {
  26406. + struct {
  26407. + u32 planes;
  26408. + u32 offset[4];
  26409. + u32 pitch[4];
  26410. + u32 flags;
  26411. + } video;
  26412. + } u;
  26413. +};
  26414. +
  26415. +struct mmal_msg_buffer_from_host {
  26416. + /* The front 32 bytes of the buffer header are copied
  26417. + * back to us in the reply to allow for context. This
  26418. + * area is used to store two mmal_driver_buffer structures to
  26419. + * allow for multiple concurrent service users.
  26420. + */
  26421. + /* control data */
  26422. + struct mmal_driver_buffer drvbuf;
  26423. +
  26424. + /* referenced control data for passthrough buffer management */
  26425. + struct mmal_driver_buffer drvbuf_ref;
  26426. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  26427. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  26428. + s32 is_zero_copy;
  26429. + s32 has_reference;
  26430. +
  26431. + /** allows short data to be xfered in control message */
  26432. + u32 payload_in_message;
  26433. + u8 short_data[MMAL_VC_SHORT_DATA];
  26434. +};
  26435. +
  26436. +
  26437. +/* port parameter setting */
  26438. +
  26439. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  26440. +
  26441. +struct mmal_msg_port_parameter_set {
  26442. + u32 component_handle; /* component */
  26443. + u32 port_handle; /* port */
  26444. + u32 id; /* Parameter ID */
  26445. + u32 size; /* Parameter size */
  26446. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  26447. +};
  26448. +
  26449. +struct mmal_msg_port_parameter_set_reply {
  26450. + u32 status; /** enum mmal_msg_status todo: how does this
  26451. + * differ to the one in the header?
  26452. + */
  26453. +};
  26454. +
  26455. +/* port parameter getting */
  26456. +
  26457. +struct mmal_msg_port_parameter_get {
  26458. + u32 component_handle; /* component */
  26459. + u32 port_handle; /* port */
  26460. + u32 id; /* Parameter ID */
  26461. + u32 size; /* Parameter size */
  26462. +};
  26463. +
  26464. +struct mmal_msg_port_parameter_get_reply {
  26465. + u32 status; /* Status of mmal_port_parameter_get call */
  26466. + u32 id; /* Parameter ID */
  26467. + u32 size; /* Parameter size */
  26468. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  26469. +};
  26470. +
  26471. +/* event messages */
  26472. +#define MMAL_WORKER_EVENT_SPACE 256
  26473. +
  26474. +struct mmal_msg_event_to_host {
  26475. + void *client_component; /* component context */
  26476. +
  26477. + u32 port_type;
  26478. + u32 port_num;
  26479. +
  26480. + u32 cmd;
  26481. + u32 length;
  26482. + u8 data[MMAL_WORKER_EVENT_SPACE];
  26483. + struct mmal_buffer_header *delayed_buffer;
  26484. +};
  26485. +
  26486. +/* all mmal messages are serialised through this structure */
  26487. +struct mmal_msg {
  26488. + /* header */
  26489. + struct mmal_msg_header h;
  26490. + /* payload */
  26491. + union {
  26492. + struct mmal_msg_version version;
  26493. +
  26494. + struct mmal_msg_component_create component_create;
  26495. + struct mmal_msg_component_create_reply component_create_reply;
  26496. +
  26497. + struct mmal_msg_component_destroy component_destroy;
  26498. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  26499. +
  26500. + struct mmal_msg_component_enable component_enable;
  26501. + struct mmal_msg_component_enable_reply component_enable_reply;
  26502. +
  26503. + struct mmal_msg_component_disable component_disable;
  26504. + struct mmal_msg_component_disable_reply component_disable_reply;
  26505. +
  26506. + struct mmal_msg_port_info_get port_info_get;
  26507. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  26508. +
  26509. + struct mmal_msg_port_info_set port_info_set;
  26510. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  26511. +
  26512. + struct mmal_msg_port_action_port port_action_port;
  26513. + struct mmal_msg_port_action_handle port_action_handle;
  26514. + struct mmal_msg_port_action_reply port_action_reply;
  26515. +
  26516. + struct mmal_msg_buffer_from_host buffer_from_host;
  26517. +
  26518. + struct mmal_msg_port_parameter_set port_parameter_set;
  26519. + struct mmal_msg_port_parameter_set_reply
  26520. + port_parameter_set_reply;
  26521. + struct mmal_msg_port_parameter_get
  26522. + port_parameter_get;
  26523. + struct mmal_msg_port_parameter_get_reply
  26524. + port_parameter_get_reply;
  26525. +
  26526. + struct mmal_msg_event_to_host event_to_host;
  26527. +
  26528. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  26529. + } u;
  26530. +};
  26531. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  26532. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  26533. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2015-03-09 10:39:30.594893734 +0100
  26534. @@ -0,0 +1,107 @@
  26535. +/*
  26536. + * Broadcom BM2835 V4L2 driver
  26537. + *
  26538. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26539. + *
  26540. + * This file is subject to the terms and conditions of the GNU General Public
  26541. + * License. See the file COPYING in the main directory of this archive
  26542. + * for more details.
  26543. + *
  26544. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26545. + * Dave Stevenson <dsteve@broadcom.com>
  26546. + * Simon Mellor <simellor@broadcom.com>
  26547. + * Luke Diamand <luked@broadcom.com>
  26548. + */
  26549. +
  26550. +/* MMAL_PORT_TYPE_T */
  26551. +enum mmal_port_type {
  26552. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  26553. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  26554. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  26555. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  26556. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  26557. +};
  26558. +
  26559. +/** The port is pass-through and doesn't need buffer headers allocated */
  26560. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  26561. +/** The port wants to allocate the buffer payloads.
  26562. + * This signals a preference that payload allocation should be done
  26563. + * on this port for efficiency reasons. */
  26564. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  26565. +/** The port supports format change events.
  26566. + * This applies to input ports and is used to let the client know
  26567. + * whether the port supports being reconfigured via a format
  26568. + * change event (i.e. without having to disable the port). */
  26569. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  26570. +
  26571. +/* mmal port structure (MMAL_PORT_T)
  26572. + *
  26573. + * most elements are informational only, the pointer values for
  26574. + * interogation messages are generally provided as additional
  26575. + * strucures within the message. When used to set values only teh
  26576. + * buffer_num, buffer_size and userdata parameters are writable.
  26577. + */
  26578. +struct mmal_port {
  26579. + void *priv; /* Private member used by the framework */
  26580. + const char *name; /* Port name. Used for debugging purposes (RO) */
  26581. +
  26582. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  26583. + u16 index; /* Index of the port in its type list (RO) */
  26584. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  26585. +
  26586. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  26587. + struct mmal_es_format *format; /* Format of the elementary stream */
  26588. +
  26589. + u32 buffer_num_min; /* Minimum number of buffers the port
  26590. + * requires (RO). This is set by the
  26591. + * component.
  26592. + */
  26593. +
  26594. + u32 buffer_size_min; /* Minimum size of buffers the port
  26595. + * requires (RO). This is set by the
  26596. + * component.
  26597. + */
  26598. +
  26599. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  26600. + * the buffers (RO). A value of
  26601. + * zero means no special alignment
  26602. + * requirements. This is set by the
  26603. + * component.
  26604. + */
  26605. +
  26606. + u32 buffer_num_recommended; /* Number of buffers the port
  26607. + * recommends for optimal
  26608. + * performance (RO). A value of
  26609. + * zero means no special
  26610. + * recommendation. This is set
  26611. + * by the component.
  26612. + */
  26613. +
  26614. + u32 buffer_size_recommended; /* Size of buffers the port
  26615. + * recommends for optimal
  26616. + * performance (RO). A value of
  26617. + * zero means no special
  26618. + * recommendation. This is set
  26619. + * by the component.
  26620. + */
  26621. +
  26622. + u32 buffer_num; /* Actual number of buffers the port will use.
  26623. + * This is set by the client.
  26624. + */
  26625. +
  26626. + u32 buffer_size; /* Actual maximum size of the buffers that
  26627. + * will be sent to the port. This is set by
  26628. + * the client.
  26629. + */
  26630. +
  26631. + void *component; /* Component this port belongs to (Read Only) */
  26632. +
  26633. + void *userdata; /* Field reserved for use by the client */
  26634. +
  26635. + u32 capabilities; /* Flags describing the capabilities of a
  26636. + * port (RO). Bitwise combination of \ref
  26637. + * portcapabilities "Port capabilities"
  26638. + * values.
  26639. + */
  26640. +
  26641. +};
  26642. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  26643. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  26644. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2015-03-09 10:39:30.594893734 +0100
  26645. @@ -0,0 +1,656 @@
  26646. +/*
  26647. + * Broadcom BM2835 V4L2 driver
  26648. + *
  26649. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  26650. + *
  26651. + * This file is subject to the terms and conditions of the GNU General Public
  26652. + * License. See the file COPYING in the main directory of this archive
  26653. + * for more details.
  26654. + *
  26655. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  26656. + * Dave Stevenson <dsteve@broadcom.com>
  26657. + * Simon Mellor <simellor@broadcom.com>
  26658. + * Luke Diamand <luked@broadcom.com>
  26659. + */
  26660. +
  26661. +/* common parameters */
  26662. +
  26663. +/** @name Parameter groups
  26664. + * Parameters are divided into groups, and then allocated sequentially within
  26665. + * a group using an enum.
  26666. + * @{
  26667. + */
  26668. +
  26669. +/** Common parameter ID group, used with many types of component. */
  26670. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  26671. +/** Camera-specific parameter ID group. */
  26672. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  26673. +/** Video-specific parameter ID group. */
  26674. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  26675. +/** Audio-specific parameter ID group. */
  26676. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  26677. +/** Clock-specific parameter ID group. */
  26678. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  26679. +/** Miracast-specific parameter ID group. */
  26680. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  26681. +
  26682. +/* Common parameters */
  26683. +enum mmal_parameter_common_type {
  26684. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  26685. + = MMAL_PARAMETER_GROUP_COMMON,
  26686. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  26687. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  26688. +
  26689. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  26690. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  26691. +
  26692. + /** MMAL_PARAMETER_BOOLEAN_T */
  26693. + MMAL_PARAMETER_ZERO_COPY,
  26694. +
  26695. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  26696. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  26697. +
  26698. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  26699. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  26700. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  26701. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  26702. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  26703. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  26704. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  26705. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  26706. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  26707. +};
  26708. +
  26709. +/* camera parameters */
  26710. +
  26711. +enum mmal_parameter_camera_type {
  26712. + /* 0 */
  26713. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  26714. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  26715. + = MMAL_PARAMETER_GROUP_CAMERA,
  26716. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  26717. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  26718. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26719. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  26720. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  26721. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  26722. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  26723. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  26724. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  26725. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  26726. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  26727. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  26728. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  26729. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  26730. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  26731. +
  26732. + /* 0x10 */
  26733. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  26734. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26735. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  26736. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  26737. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  26738. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  26739. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  26740. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  26741. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26742. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  26743. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  26744. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  26745. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  26746. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26747. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  26748. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26749. +
  26750. + /* 0x20 */
  26751. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  26752. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26753. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26754. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  26755. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  26756. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  26757. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  26758. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  26759. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  26760. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26761. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  26762. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  26763. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  26764. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  26765. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  26766. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  26767. +
  26768. + /* 0x30 */
  26769. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  26770. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26771. +
  26772. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  26773. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  26774. +
  26775. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  26776. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  26777. +
  26778. + /** @ref MMAL_PARAMETER_UINT32_T */
  26779. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  26780. +
  26781. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  26782. + MMAL_PARAMETER_CAMERA_USE_CASE,
  26783. +
  26784. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26785. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  26786. +
  26787. + /** @ref MMAL_PARAMETER_UINT32_T */
  26788. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  26789. +
  26790. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  26791. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  26792. +
  26793. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  26794. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  26795. +
  26796. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  26797. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  26798. +
  26799. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  26800. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  26801. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26802. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  26803. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  26804. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  26805. +
  26806. + /* 0x40 */
  26807. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26808. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26809. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  26810. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  26811. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  26812. +};
  26813. +
  26814. +struct mmal_parameter_rational {
  26815. + s32 num; /**< Numerator */
  26816. + s32 den; /**< Denominator */
  26817. +};
  26818. +
  26819. +enum mmal_parameter_camera_config_timestamp_mode {
  26820. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  26821. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  26822. + * for the frame timestamp
  26823. + */
  26824. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  26825. + * but subtract the
  26826. + * timestamp of the first
  26827. + * frame sent to give a
  26828. + * zero based timestamp.
  26829. + */
  26830. +};
  26831. +
  26832. +struct mmal_parameter_fps_range {
  26833. + /**< Low end of the permitted framerate range */
  26834. + struct mmal_parameter_rational fps_low;
  26835. + /**< High end of the permitted framerate range */
  26836. + struct mmal_parameter_rational fps_high;
  26837. +};
  26838. +
  26839. +
  26840. +/* camera configuration parameter */
  26841. +struct mmal_parameter_camera_config {
  26842. + /* Parameters for setting up the image pools */
  26843. + u32 max_stills_w; /* Max size of stills capture */
  26844. + u32 max_stills_h;
  26845. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  26846. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  26847. +
  26848. + u32 max_preview_video_w; /* Max size of the preview or video
  26849. + * capture frames
  26850. + */
  26851. + u32 max_preview_video_h;
  26852. + u32 num_preview_video_frames;
  26853. +
  26854. + /** Sets the height of the circular buffer for stills capture. */
  26855. + u32 stills_capture_circular_buffer_height;
  26856. +
  26857. + /** Allows preview/encode to resume as fast as possible after the stills
  26858. + * input frame has been received, and then processes the still frame in
  26859. + * the background whilst preview/encode has resumed.
  26860. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  26861. + */
  26862. + u32 fast_preview_resume;
  26863. +
  26864. + /** Selects algorithm for timestamping frames if
  26865. + * there is no clock component connected.
  26866. + * enum mmal_parameter_camera_config_timestamp_mode
  26867. + */
  26868. + s32 use_stc_timestamp;
  26869. +};
  26870. +
  26871. +
  26872. +enum mmal_parameter_exposuremode {
  26873. + MMAL_PARAM_EXPOSUREMODE_OFF,
  26874. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  26875. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  26876. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  26877. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  26878. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  26879. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  26880. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  26881. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  26882. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  26883. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  26884. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  26885. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  26886. +};
  26887. +
  26888. +enum mmal_parameter_exposuremeteringmode {
  26889. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  26890. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  26891. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  26892. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  26893. +};
  26894. +
  26895. +enum mmal_parameter_awbmode {
  26896. + MMAL_PARAM_AWBMODE_OFF,
  26897. + MMAL_PARAM_AWBMODE_AUTO,
  26898. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  26899. + MMAL_PARAM_AWBMODE_CLOUDY,
  26900. + MMAL_PARAM_AWBMODE_SHADE,
  26901. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  26902. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  26903. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  26904. + MMAL_PARAM_AWBMODE_FLASH,
  26905. + MMAL_PARAM_AWBMODE_HORIZON,
  26906. +};
  26907. +
  26908. +enum mmal_parameter_imagefx {
  26909. + MMAL_PARAM_IMAGEFX_NONE,
  26910. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  26911. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  26912. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  26913. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  26914. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  26915. + MMAL_PARAM_IMAGEFX_SKETCH,
  26916. + MMAL_PARAM_IMAGEFX_DENOISE,
  26917. + MMAL_PARAM_IMAGEFX_EMBOSS,
  26918. + MMAL_PARAM_IMAGEFX_OILPAINT,
  26919. + MMAL_PARAM_IMAGEFX_HATCH,
  26920. + MMAL_PARAM_IMAGEFX_GPEN,
  26921. + MMAL_PARAM_IMAGEFX_PASTEL,
  26922. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  26923. + MMAL_PARAM_IMAGEFX_FILM,
  26924. + MMAL_PARAM_IMAGEFX_BLUR,
  26925. + MMAL_PARAM_IMAGEFX_SATURATION,
  26926. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  26927. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  26928. + MMAL_PARAM_IMAGEFX_POSTERISE,
  26929. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  26930. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  26931. + MMAL_PARAM_IMAGEFX_CARTOON,
  26932. +};
  26933. +
  26934. +enum MMAL_PARAM_FLICKERAVOID_T {
  26935. + MMAL_PARAM_FLICKERAVOID_OFF,
  26936. + MMAL_PARAM_FLICKERAVOID_AUTO,
  26937. + MMAL_PARAM_FLICKERAVOID_50HZ,
  26938. + MMAL_PARAM_FLICKERAVOID_60HZ,
  26939. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  26940. +};
  26941. +
  26942. +struct mmal_parameter_awbgains {
  26943. + struct mmal_parameter_rational r_gain; /**< Red gain */
  26944. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  26945. +};
  26946. +
  26947. +/** Manner of video rate control */
  26948. +enum mmal_parameter_rate_control_mode {
  26949. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  26950. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  26951. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  26952. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  26953. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  26954. +};
  26955. +
  26956. +enum mmal_video_profile {
  26957. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  26958. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  26959. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  26960. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  26961. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  26962. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  26963. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  26964. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  26965. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  26966. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  26967. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  26968. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  26969. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  26970. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  26971. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  26972. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  26973. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  26974. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  26975. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  26976. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  26977. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  26978. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  26979. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  26980. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  26981. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  26982. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  26983. + MMAL_VIDEO_PROFILE_H264_MAIN,
  26984. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  26985. + MMAL_VIDEO_PROFILE_H264_HIGH,
  26986. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  26987. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  26988. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  26989. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  26990. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  26991. +};
  26992. +
  26993. +enum mmal_video_level {
  26994. + MMAL_VIDEO_LEVEL_H263_10,
  26995. + MMAL_VIDEO_LEVEL_H263_20,
  26996. + MMAL_VIDEO_LEVEL_H263_30,
  26997. + MMAL_VIDEO_LEVEL_H263_40,
  26998. + MMAL_VIDEO_LEVEL_H263_45,
  26999. + MMAL_VIDEO_LEVEL_H263_50,
  27000. + MMAL_VIDEO_LEVEL_H263_60,
  27001. + MMAL_VIDEO_LEVEL_H263_70,
  27002. + MMAL_VIDEO_LEVEL_MP4V_0,
  27003. + MMAL_VIDEO_LEVEL_MP4V_0b,
  27004. + MMAL_VIDEO_LEVEL_MP4V_1,
  27005. + MMAL_VIDEO_LEVEL_MP4V_2,
  27006. + MMAL_VIDEO_LEVEL_MP4V_3,
  27007. + MMAL_VIDEO_LEVEL_MP4V_4,
  27008. + MMAL_VIDEO_LEVEL_MP4V_4a,
  27009. + MMAL_VIDEO_LEVEL_MP4V_5,
  27010. + MMAL_VIDEO_LEVEL_MP4V_6,
  27011. + MMAL_VIDEO_LEVEL_H264_1,
  27012. + MMAL_VIDEO_LEVEL_H264_1b,
  27013. + MMAL_VIDEO_LEVEL_H264_11,
  27014. + MMAL_VIDEO_LEVEL_H264_12,
  27015. + MMAL_VIDEO_LEVEL_H264_13,
  27016. + MMAL_VIDEO_LEVEL_H264_2,
  27017. + MMAL_VIDEO_LEVEL_H264_21,
  27018. + MMAL_VIDEO_LEVEL_H264_22,
  27019. + MMAL_VIDEO_LEVEL_H264_3,
  27020. + MMAL_VIDEO_LEVEL_H264_31,
  27021. + MMAL_VIDEO_LEVEL_H264_32,
  27022. + MMAL_VIDEO_LEVEL_H264_4,
  27023. + MMAL_VIDEO_LEVEL_H264_41,
  27024. + MMAL_VIDEO_LEVEL_H264_42,
  27025. + MMAL_VIDEO_LEVEL_H264_5,
  27026. + MMAL_VIDEO_LEVEL_H264_51,
  27027. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  27028. +};
  27029. +
  27030. +struct mmal_parameter_video_profile {
  27031. + enum mmal_video_profile profile;
  27032. + enum mmal_video_level level;
  27033. +};
  27034. +
  27035. +/* video parameters */
  27036. +
  27037. +enum mmal_parameter_video_type {
  27038. + /** @ref MMAL_DISPLAYREGION_T */
  27039. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  27040. +
  27041. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  27042. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  27043. +
  27044. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  27045. + MMAL_PARAMETER_PROFILE,
  27046. +
  27047. + /** @ref MMAL_PARAMETER_UINT32_T */
  27048. + MMAL_PARAMETER_INTRAPERIOD,
  27049. +
  27050. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  27051. + MMAL_PARAMETER_RATECONTROL,
  27052. +
  27053. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  27054. + MMAL_PARAMETER_NALUNITFORMAT,
  27055. +
  27056. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  27057. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  27058. +
  27059. + /** @ref MMAL_PARAMETER_UINT32_T.
  27060. + * Setting the value to zero resets to the default (one slice per frame).
  27061. + */
  27062. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  27063. +
  27064. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  27065. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  27066. +
  27067. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  27068. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  27069. +
  27070. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  27071. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  27072. +
  27073. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  27074. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  27075. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  27076. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  27077. +
  27078. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  27079. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  27080. +
  27081. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  27082. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  27083. +
  27084. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  27085. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  27086. +
  27087. + /** @ref MMAL_PARAMETER_UINT32_T. */
  27088. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  27089. +
  27090. + /** @ref MMAL_PARAMETER_UINT32_T. */
  27091. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  27092. +
  27093. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  27094. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  27095. +
  27096. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  27097. + /** @ref MMAL_PARAMETER_UINT32_T.
  27098. + * Changing this parameter from the default can reduce frame rate
  27099. + * because image buffers need to be re-pitched.
  27100. + */
  27101. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  27102. +
  27103. + /** @ref MMAL_PARAMETER_UINT32_T.
  27104. + * Changing this parameter from the default can reduce frame rate
  27105. + * because image buffers need to be re-pitched.
  27106. + */
  27107. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  27108. +
  27109. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  27110. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  27111. +
  27112. + /** @ref MMAL_PARAMETER_UINT32_T. */
  27113. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  27114. +
  27115. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  27116. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  27117. +
  27118. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  27119. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  27120. +
  27121. + /** @ref MMAL_PARAMETER_UINT32_T */
  27122. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  27123. +
  27124. + /** @ref MMAL_PARAMETER_UINT32_T. */
  27125. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  27126. +
  27127. + /* H264 specific parameters */
  27128. +
  27129. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  27130. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  27131. +
  27132. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  27133. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  27134. +
  27135. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  27136. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  27137. +
  27138. + /** @ref MMAL_PARAMETER_UINT32_T. */
  27139. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  27140. +
  27141. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  27142. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  27143. +
  27144. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  27145. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  27146. +
  27147. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  27148. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  27149. +
  27150. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  27151. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  27152. +
  27153. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  27154. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  27155. +
  27156. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  27157. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  27158. +
  27159. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  27160. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  27161. +
  27162. + /** @ref MMAL_PARAMETER_BYTES_T */
  27163. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  27164. +
  27165. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  27166. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  27167. +
  27168. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  27169. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  27170. +
  27171. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  27172. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  27173. +};
  27174. +
  27175. +/** Valid mirror modes */
  27176. +enum mmal_parameter_mirror {
  27177. + MMAL_PARAM_MIRROR_NONE,
  27178. + MMAL_PARAM_MIRROR_VERTICAL,
  27179. + MMAL_PARAM_MIRROR_HORIZONTAL,
  27180. + MMAL_PARAM_MIRROR_BOTH,
  27181. +};
  27182. +
  27183. +enum mmal_parameter_displaytransform {
  27184. + MMAL_DISPLAY_ROT0 = 0,
  27185. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  27186. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  27187. + MMAL_DISPLAY_ROT180 = 3,
  27188. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  27189. + MMAL_DISPLAY_ROT270 = 5,
  27190. + MMAL_DISPLAY_ROT90 = 6,
  27191. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  27192. +};
  27193. +
  27194. +enum mmal_parameter_displaymode {
  27195. + MMAL_DISPLAY_MODE_FILL = 0,
  27196. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  27197. +};
  27198. +
  27199. +enum mmal_parameter_displayset {
  27200. + MMAL_DISPLAY_SET_NONE = 0,
  27201. + MMAL_DISPLAY_SET_NUM = 1,
  27202. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  27203. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  27204. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  27205. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  27206. + MMAL_DISPLAY_SET_MODE = 0x20,
  27207. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  27208. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  27209. + MMAL_DISPLAY_SET_LAYER = 0x100,
  27210. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  27211. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  27212. +};
  27213. +
  27214. +struct mmal_parameter_displayregion {
  27215. + /** Bitfield that indicates which fields are set and should be
  27216. + * used. All other fields will maintain their current value.
  27217. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  27218. + * combined.
  27219. + */
  27220. + u32 set;
  27221. +
  27222. + /** Describes the display output device, with 0 typically
  27223. + * being a directly connected LCD display. The actual values
  27224. + * will depend on the hardware. Code using hard-wired numbers
  27225. + * (e.g. 2) is certain to fail.
  27226. + */
  27227. +
  27228. + u32 display_num;
  27229. + /** Indicates that we are using the full device screen area,
  27230. + * rather than a window of the display. If zero, then
  27231. + * dest_rect is used to specify a region of the display to
  27232. + * use.
  27233. + */
  27234. +
  27235. + s32 fullscreen;
  27236. + /** Indicates any rotation or flipping used to map frames onto
  27237. + * the natural display orientation.
  27238. + */
  27239. + u32 transform; /* enum mmal_parameter_displaytransform */
  27240. +
  27241. + /** Where to display the frame within the screen, if
  27242. + * fullscreen is zero.
  27243. + */
  27244. + struct vchiq_mmal_rect dest_rect;
  27245. +
  27246. + /** Indicates which area of the frame to display. If all
  27247. + * values are zero, the whole frame will be used.
  27248. + */
  27249. + struct vchiq_mmal_rect src_rect;
  27250. +
  27251. + /** If set to non-zero, indicates that any display scaling
  27252. + * should disregard the aspect ratio of the frame region being
  27253. + * displayed.
  27254. + */
  27255. + s32 noaspect;
  27256. +
  27257. + /** Indicates how the image should be scaled to fit the
  27258. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  27259. + * that the image should fill the screen by potentially
  27260. + * cropping the frames. Setting \code mode \endcode to \code
  27261. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  27262. + * source region should be displayed and black bars added if
  27263. + * necessary.
  27264. + */
  27265. + u32 mode; /* enum mmal_parameter_displaymode */
  27266. +
  27267. + /** If non-zero, defines the width of a source pixel relative
  27268. + * to \code pixel_y \endcode. If zero, then pixels default to
  27269. + * being square.
  27270. + */
  27271. + u32 pixel_x;
  27272. +
  27273. + /** If non-zero, defines the height of a source pixel relative
  27274. + * to \code pixel_x \endcode. If zero, then pixels default to
  27275. + * being square.
  27276. + */
  27277. + u32 pixel_y;
  27278. +
  27279. + /** Sets the relative depth of the images, with greater values
  27280. + * being in front of smaller values.
  27281. + */
  27282. + u32 layer;
  27283. +
  27284. + /** Set to non-zero to ensure copy protection is used on
  27285. + * output.
  27286. + */
  27287. + s32 copyprotect_required;
  27288. +
  27289. + /** Level of opacity of the layer, where zero is fully
  27290. + * transparent and 255 is fully opaque.
  27291. + */
  27292. + u32 alpha;
  27293. +};
  27294. +
  27295. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  27296. +
  27297. +struct mmal_parameter_imagefx_parameters {
  27298. + enum mmal_parameter_imagefx effect;
  27299. + u32 num_effect_params;
  27300. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  27301. +};
  27302. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  27303. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  27304. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2015-03-09 10:39:30.594893734 +0100
  27305. @@ -0,0 +1,1916 @@
  27306. +/*
  27307. + * Broadcom BM2835 V4L2 driver
  27308. + *
  27309. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  27310. + *
  27311. + * This file is subject to the terms and conditions of the GNU General Public
  27312. + * License. See the file COPYING in the main directory of this archive
  27313. + * for more details.
  27314. + *
  27315. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  27316. + * Dave Stevenson <dsteve@broadcom.com>
  27317. + * Simon Mellor <simellor@broadcom.com>
  27318. + * Luke Diamand <luked@broadcom.com>
  27319. + *
  27320. + * V4L2 driver MMAL vchiq interface code
  27321. + */
  27322. +
  27323. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27324. +
  27325. +#include <linux/errno.h>
  27326. +#include <linux/kernel.h>
  27327. +#include <linux/mutex.h>
  27328. +#include <linux/mm.h>
  27329. +#include <linux/slab.h>
  27330. +#include <linux/completion.h>
  27331. +#include <linux/vmalloc.h>
  27332. +#include <asm/cacheflush.h>
  27333. +#include <media/videobuf2-vmalloc.h>
  27334. +
  27335. +#include "mmal-common.h"
  27336. +#include "mmal-vchiq.h"
  27337. +#include "mmal-msg.h"
  27338. +
  27339. +#define USE_VCHIQ_ARM
  27340. +#include "interface/vchi/vchi.h"
  27341. +
  27342. +/* maximum number of components supported */
  27343. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  27344. +
  27345. +/*#define FULL_MSG_DUMP 1*/
  27346. +
  27347. +#ifdef DEBUG
  27348. +static const char *const msg_type_names[] = {
  27349. + "UNKNOWN",
  27350. + "QUIT",
  27351. + "SERVICE_CLOSED",
  27352. + "GET_VERSION",
  27353. + "COMPONENT_CREATE",
  27354. + "COMPONENT_DESTROY",
  27355. + "COMPONENT_ENABLE",
  27356. + "COMPONENT_DISABLE",
  27357. + "PORT_INFO_GET",
  27358. + "PORT_INFO_SET",
  27359. + "PORT_ACTION",
  27360. + "BUFFER_FROM_HOST",
  27361. + "BUFFER_TO_HOST",
  27362. + "GET_STATS",
  27363. + "PORT_PARAMETER_SET",
  27364. + "PORT_PARAMETER_GET",
  27365. + "EVENT_TO_HOST",
  27366. + "GET_CORE_STATS_FOR_PORT",
  27367. + "OPAQUE_ALLOCATOR",
  27368. + "CONSUME_MEM",
  27369. + "LMK",
  27370. + "OPAQUE_ALLOCATOR_DESC",
  27371. + "DRM_GET_LHS32",
  27372. + "DRM_GET_TIME",
  27373. + "BUFFER_FROM_HOST_ZEROLEN",
  27374. + "PORT_FLUSH",
  27375. + "HOST_LOG",
  27376. +};
  27377. +#endif
  27378. +
  27379. +static const char *const port_action_type_names[] = {
  27380. + "UNKNOWN",
  27381. + "ENABLE",
  27382. + "DISABLE",
  27383. + "FLUSH",
  27384. + "CONNECT",
  27385. + "DISCONNECT",
  27386. + "SET_REQUIREMENTS",
  27387. +};
  27388. +
  27389. +#if defined(DEBUG)
  27390. +#if defined(FULL_MSG_DUMP)
  27391. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  27392. + do { \
  27393. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  27394. + msg_type_names[(MSG)->h.type], \
  27395. + (MSG)->h.type, (MSG_LEN)); \
  27396. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  27397. + 16, 4, (MSG), \
  27398. + sizeof(struct mmal_msg_header), 1); \
  27399. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  27400. + 16, 4, \
  27401. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  27402. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  27403. + } while (0)
  27404. +#else
  27405. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  27406. + { \
  27407. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  27408. + msg_type_names[(MSG)->h.type], \
  27409. + (MSG)->h.type, (MSG_LEN)); \
  27410. + }
  27411. +#endif
  27412. +#else
  27413. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  27414. +#endif
  27415. +
  27416. +/* normal message context */
  27417. +struct mmal_msg_context {
  27418. + union {
  27419. + struct {
  27420. + /* work struct for defered callback - must come first */
  27421. + struct work_struct work;
  27422. + /* mmal instance */
  27423. + struct vchiq_mmal_instance *instance;
  27424. + /* mmal port */
  27425. + struct vchiq_mmal_port *port;
  27426. + /* actual buffer used to store bulk reply */
  27427. + struct mmal_buffer *buffer;
  27428. + /* amount of buffer used */
  27429. + unsigned long buffer_used;
  27430. + /* MMAL buffer flags */
  27431. + u32 mmal_flags;
  27432. + /* Presentation and Decode timestamps */
  27433. + s64 pts;
  27434. + s64 dts;
  27435. +
  27436. + int status; /* context status */
  27437. +
  27438. + } bulk; /* bulk data */
  27439. +
  27440. + struct {
  27441. + /* message handle to release */
  27442. + VCHI_HELD_MSG_T msg_handle;
  27443. + /* pointer to received message */
  27444. + struct mmal_msg *msg;
  27445. + /* received message length */
  27446. + u32 msg_len;
  27447. + /* completion upon reply */
  27448. + struct completion cmplt;
  27449. + } sync; /* synchronous response */
  27450. + } u;
  27451. +
  27452. +};
  27453. +
  27454. +struct vchiq_mmal_instance {
  27455. + VCHI_SERVICE_HANDLE_T handle;
  27456. +
  27457. + /* ensure serialised access to service */
  27458. + struct mutex vchiq_mutex;
  27459. +
  27460. + /* ensure serialised access to bulk operations */
  27461. + struct mutex bulk_mutex;
  27462. +
  27463. + /* vmalloc page to receive scratch bulk xfers into */
  27464. + void *bulk_scratch;
  27465. +
  27466. + /* component to use next */
  27467. + int component_idx;
  27468. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  27469. +};
  27470. +
  27471. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  27472. + *instance)
  27473. +{
  27474. + struct mmal_msg_context *msg_context;
  27475. +
  27476. + /* todo: should this be allocated from a pool to avoid kmalloc */
  27477. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  27478. + memset(msg_context, 0, sizeof(*msg_context));
  27479. +
  27480. + return msg_context;
  27481. +}
  27482. +
  27483. +static void release_msg_context(struct mmal_msg_context *msg_context)
  27484. +{
  27485. + kfree(msg_context);
  27486. +}
  27487. +
  27488. +/* deals with receipt of event to host message */
  27489. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  27490. + struct mmal_msg *msg, u32 msg_len)
  27491. +{
  27492. + pr_debug("unhandled event\n");
  27493. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  27494. + msg->u.event_to_host.client_component,
  27495. + msg->u.event_to_host.port_type,
  27496. + msg->u.event_to_host.port_num,
  27497. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  27498. +}
  27499. +
  27500. +/* workqueue scheduled callback
  27501. + *
  27502. + * we do this because it is important we do not call any other vchiq
  27503. + * sync calls from witin the message delivery thread
  27504. + */
  27505. +static void buffer_work_cb(struct work_struct *work)
  27506. +{
  27507. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  27508. +
  27509. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  27510. + msg_context->u.bulk.port,
  27511. + msg_context->u.bulk.status,
  27512. + msg_context->u.bulk.buffer,
  27513. + msg_context->u.bulk.buffer_used,
  27514. + msg_context->u.bulk.mmal_flags,
  27515. + msg_context->u.bulk.dts,
  27516. + msg_context->u.bulk.pts);
  27517. +
  27518. + /* release message context */
  27519. + release_msg_context(msg_context);
  27520. +}
  27521. +
  27522. +/* enqueue a bulk receive for a given message context */
  27523. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  27524. + struct mmal_msg *msg,
  27525. + struct mmal_msg_context *msg_context)
  27526. +{
  27527. + unsigned long rd_len;
  27528. + unsigned long flags = 0;
  27529. + int ret;
  27530. +
  27531. + /* bulk mutex stops other bulk operations while we have a
  27532. + * receive in progress - released in callback
  27533. + */
  27534. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  27535. + if (ret != 0)
  27536. + return ret;
  27537. +
  27538. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  27539. +
  27540. + /* take buffer from queue */
  27541. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  27542. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  27543. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  27544. + pr_err("buffer list empty trying to submit bulk receive\n");
  27545. +
  27546. + /* todo: this is a serious error, we should never have
  27547. + * commited a buffer_to_host operation to the mmal
  27548. + * port without the buffer to back it up (underflow
  27549. + * handling) and there is no obvious way to deal with
  27550. + * this - how is the mmal servie going to react when
  27551. + * we fail to do the xfer and reschedule a buffer when
  27552. + * it arrives? perhaps a starved flag to indicate a
  27553. + * waiting bulk receive?
  27554. + */
  27555. +
  27556. + mutex_unlock(&instance->bulk_mutex);
  27557. +
  27558. + return -EINVAL;
  27559. + }
  27560. +
  27561. + msg_context->u.bulk.buffer =
  27562. + list_entry(msg_context->u.bulk.port->buffers.next,
  27563. + struct mmal_buffer, list);
  27564. + list_del(&msg_context->u.bulk.buffer->list);
  27565. +
  27566. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  27567. +
  27568. + /* ensure we do not overrun the available buffer */
  27569. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  27570. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  27571. + pr_warn("short read as not enough receive buffer space\n");
  27572. + /* todo: is this the correct response, what happens to
  27573. + * the rest of the message data?
  27574. + */
  27575. + }
  27576. +
  27577. + /* store length */
  27578. + msg_context->u.bulk.buffer_used = rd_len;
  27579. + msg_context->u.bulk.mmal_flags =
  27580. + msg->u.buffer_from_host.buffer_header.flags;
  27581. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  27582. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  27583. +
  27584. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  27585. + // cache.
  27586. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  27587. +
  27588. + /* queue the bulk submission */
  27589. + vchi_service_use(instance->handle);
  27590. + ret = vchi_bulk_queue_receive(instance->handle,
  27591. + msg_context->u.bulk.buffer->buffer,
  27592. + /* Actual receive needs to be a multiple
  27593. + * of 4 bytes
  27594. + */
  27595. + (rd_len + 3) & ~3,
  27596. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  27597. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  27598. + msg_context);
  27599. +
  27600. + vchi_service_release(instance->handle);
  27601. +
  27602. + if (ret != 0) {
  27603. + /* callback will not be clearing the mutex */
  27604. + mutex_unlock(&instance->bulk_mutex);
  27605. + }
  27606. +
  27607. + return ret;
  27608. +}
  27609. +
  27610. +/* enque a dummy bulk receive for a given message context */
  27611. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  27612. + struct mmal_msg_context *msg_context)
  27613. +{
  27614. + int ret;
  27615. +
  27616. + /* bulk mutex stops other bulk operations while we have a
  27617. + * receive in progress - released in callback
  27618. + */
  27619. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  27620. + if (ret != 0)
  27621. + return ret;
  27622. +
  27623. + /* zero length indicates this was a dummy transfer */
  27624. + msg_context->u.bulk.buffer_used = 0;
  27625. +
  27626. + /* queue the bulk submission */
  27627. + vchi_service_use(instance->handle);
  27628. +
  27629. + ret = vchi_bulk_queue_receive(instance->handle,
  27630. + instance->bulk_scratch,
  27631. + 8,
  27632. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  27633. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  27634. + msg_context);
  27635. +
  27636. + vchi_service_release(instance->handle);
  27637. +
  27638. + if (ret != 0) {
  27639. + /* callback will not be clearing the mutex */
  27640. + mutex_unlock(&instance->bulk_mutex);
  27641. + }
  27642. +
  27643. + return ret;
  27644. +}
  27645. +
  27646. +/* data in message, memcpy from packet into output buffer */
  27647. +static int inline_receive(struct vchiq_mmal_instance *instance,
  27648. + struct mmal_msg *msg,
  27649. + struct mmal_msg_context *msg_context)
  27650. +{
  27651. + unsigned long flags = 0;
  27652. +
  27653. + /* take buffer from queue */
  27654. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  27655. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  27656. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  27657. + pr_err("buffer list empty trying to receive inline\n");
  27658. +
  27659. + /* todo: this is a serious error, we should never have
  27660. + * commited a buffer_to_host operation to the mmal
  27661. + * port without the buffer to back it up (with
  27662. + * underflow handling) and there is no obvious way to
  27663. + * deal with this. Less bad than the bulk case as we
  27664. + * can just drop this on the floor but...unhelpful
  27665. + */
  27666. + return -EINVAL;
  27667. + }
  27668. +
  27669. + msg_context->u.bulk.buffer =
  27670. + list_entry(msg_context->u.bulk.port->buffers.next,
  27671. + struct mmal_buffer, list);
  27672. + list_del(&msg_context->u.bulk.buffer->list);
  27673. +
  27674. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  27675. +
  27676. + memcpy(msg_context->u.bulk.buffer->buffer,
  27677. + msg->u.buffer_from_host.short_data,
  27678. + msg->u.buffer_from_host.payload_in_message);
  27679. +
  27680. + msg_context->u.bulk.buffer_used =
  27681. + msg->u.buffer_from_host.payload_in_message;
  27682. +
  27683. + return 0;
  27684. +}
  27685. +
  27686. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  27687. +static int
  27688. +buffer_from_host(struct vchiq_mmal_instance *instance,
  27689. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  27690. +{
  27691. + struct mmal_msg_context *msg_context;
  27692. + struct mmal_msg m;
  27693. + int ret;
  27694. +
  27695. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  27696. +
  27697. + /* bulk mutex stops other bulk operations while we
  27698. + * have a receive in progress
  27699. + */
  27700. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  27701. + return -EINTR;
  27702. +
  27703. + /* get context */
  27704. + msg_context = get_msg_context(instance);
  27705. + if (msg_context == NULL)
  27706. + return -ENOMEM;
  27707. +
  27708. + /* store bulk message context for when data arrives */
  27709. + msg_context->u.bulk.instance = instance;
  27710. + msg_context->u.bulk.port = port;
  27711. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  27712. + msg_context->u.bulk.buffer_used = 0;
  27713. +
  27714. + /* initialise work structure ready to schedule callback */
  27715. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  27716. +
  27717. + /* prep the buffer from host message */
  27718. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  27719. +
  27720. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  27721. + m.h.magic = MMAL_MAGIC;
  27722. + m.h.context = msg_context;
  27723. + m.h.status = 0;
  27724. +
  27725. + /* drvbuf is our private data passed back */
  27726. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  27727. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  27728. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  27729. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  27730. +
  27731. + /* buffer header */
  27732. + m.u.buffer_from_host.buffer_header.cmd = 0;
  27733. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  27734. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  27735. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  27736. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  27737. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  27738. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  27739. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  27740. +
  27741. + /* clear buffer type sepecific data */
  27742. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  27743. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  27744. +
  27745. + /* no payload in message */
  27746. + m.u.buffer_from_host.payload_in_message = 0;
  27747. +
  27748. + vchi_service_use(instance->handle);
  27749. +
  27750. + ret = vchi_msg_queue(instance->handle, &m,
  27751. + sizeof(struct mmal_msg_header) +
  27752. + sizeof(m.u.buffer_from_host),
  27753. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  27754. +
  27755. + if (ret != 0) {
  27756. + release_msg_context(msg_context);
  27757. + /* todo: is this correct error value? */
  27758. + }
  27759. +
  27760. + vchi_service_release(instance->handle);
  27761. +
  27762. + mutex_unlock(&instance->bulk_mutex);
  27763. +
  27764. + return ret;
  27765. +}
  27766. +
  27767. +/* submit a buffer to the mmal sevice
  27768. + *
  27769. + * the buffer_from_host uses size data from the ports next available
  27770. + * mmal_buffer and deals with there being no buffer available by
  27771. + * incrementing the underflow for later
  27772. + */
  27773. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  27774. + struct vchiq_mmal_port *port)
  27775. +{
  27776. + int ret;
  27777. + struct mmal_buffer *buf;
  27778. + unsigned long flags = 0;
  27779. +
  27780. + if (!port->enabled)
  27781. + return -EINVAL;
  27782. +
  27783. + /* peek buffer from queue */
  27784. + spin_lock_irqsave(&port->slock, flags);
  27785. + if (list_empty(&port->buffers)) {
  27786. + port->buffer_underflow++;
  27787. + spin_unlock_irqrestore(&port->slock, flags);
  27788. + return -ENOSPC;
  27789. + }
  27790. +
  27791. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  27792. +
  27793. + spin_unlock_irqrestore(&port->slock, flags);
  27794. +
  27795. + /* issue buffer to mmal service */
  27796. + ret = buffer_from_host(instance, port, buf);
  27797. + if (ret) {
  27798. + pr_err("adding buffer header failed\n");
  27799. + /* todo: how should this be dealt with */
  27800. + }
  27801. +
  27802. + return ret;
  27803. +}
  27804. +
  27805. +/* deals with receipt of buffer to host message */
  27806. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  27807. + struct mmal_msg *msg, u32 msg_len)
  27808. +{
  27809. + struct mmal_msg_context *msg_context;
  27810. +
  27811. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  27812. + instance, msg, msg_len);
  27813. +
  27814. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  27815. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  27816. + } else {
  27817. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  27818. + return;
  27819. + }
  27820. +
  27821. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  27822. + /* message reception had an error */
  27823. + pr_warn("error %d in reply\n", msg->h.status);
  27824. +
  27825. + msg_context->u.bulk.status = msg->h.status;
  27826. +
  27827. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  27828. + /* empty buffer */
  27829. + if (msg->u.buffer_from_host.buffer_header.flags &
  27830. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  27831. + msg_context->u.bulk.status =
  27832. + dummy_bulk_receive(instance, msg_context);
  27833. + if (msg_context->u.bulk.status == 0)
  27834. + return; /* successful bulk submission, bulk
  27835. + * completion will trigger callback
  27836. + */
  27837. + } else {
  27838. + /* do callback with empty buffer - not EOS though */
  27839. + msg_context->u.bulk.status = 0;
  27840. + msg_context->u.bulk.buffer_used = 0;
  27841. + }
  27842. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  27843. + /* data is not in message, queue a bulk receive */
  27844. + msg_context->u.bulk.status =
  27845. + bulk_receive(instance, msg, msg_context);
  27846. + if (msg_context->u.bulk.status == 0)
  27847. + return; /* successful bulk submission, bulk
  27848. + * completion will trigger callback
  27849. + */
  27850. +
  27851. + /* failed to submit buffer, this will end badly */
  27852. + pr_err("error %d on bulk submission\n",
  27853. + msg_context->u.bulk.status);
  27854. +
  27855. + } else if (msg->u.buffer_from_host.payload_in_message <=
  27856. + MMAL_VC_SHORT_DATA) {
  27857. + /* data payload within message */
  27858. + msg_context->u.bulk.status = inline_receive(instance, msg,
  27859. + msg_context);
  27860. + } else {
  27861. + pr_err("message with invalid short payload\n");
  27862. +
  27863. + /* signal error */
  27864. + msg_context->u.bulk.status = -EINVAL;
  27865. + msg_context->u.bulk.buffer_used =
  27866. + msg->u.buffer_from_host.payload_in_message;
  27867. + }
  27868. +
  27869. + /* replace the buffer header */
  27870. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  27871. +
  27872. + /* schedule the port callback */
  27873. + schedule_work(&msg_context->u.bulk.work);
  27874. +}
  27875. +
  27876. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  27877. + struct mmal_msg_context *msg_context)
  27878. +{
  27879. + /* bulk receive operation complete */
  27880. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  27881. +
  27882. + /* replace the buffer header */
  27883. + port_buffer_from_host(msg_context->u.bulk.instance,
  27884. + msg_context->u.bulk.port);
  27885. +
  27886. + msg_context->u.bulk.status = 0;
  27887. +
  27888. + /* schedule the port callback */
  27889. + schedule_work(&msg_context->u.bulk.work);
  27890. +}
  27891. +
  27892. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  27893. + struct mmal_msg_context *msg_context)
  27894. +{
  27895. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  27896. +
  27897. + /* bulk receive operation complete */
  27898. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  27899. +
  27900. + /* replace the buffer header */
  27901. + port_buffer_from_host(msg_context->u.bulk.instance,
  27902. + msg_context->u.bulk.port);
  27903. +
  27904. + msg_context->u.bulk.status = -EINTR;
  27905. +
  27906. + schedule_work(&msg_context->u.bulk.work);
  27907. +}
  27908. +
  27909. +/* incoming event service callback */
  27910. +static void service_callback(void *param,
  27911. + const VCHI_CALLBACK_REASON_T reason,
  27912. + void *bulk_ctx)
  27913. +{
  27914. + struct vchiq_mmal_instance *instance = param;
  27915. + int status;
  27916. + u32 msg_len;
  27917. + struct mmal_msg *msg;
  27918. + VCHI_HELD_MSG_T msg_handle;
  27919. +
  27920. + if (!instance) {
  27921. + pr_err("Message callback passed NULL instance\n");
  27922. + return;
  27923. + }
  27924. +
  27925. + switch (reason) {
  27926. + case VCHI_CALLBACK_MSG_AVAILABLE:
  27927. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  27928. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  27929. + if (status) {
  27930. + pr_err("Unable to dequeue a message (%d)\n", status);
  27931. + break;
  27932. + }
  27933. +
  27934. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  27935. +
  27936. + /* handling is different for buffer messages */
  27937. + switch (msg->h.type) {
  27938. +
  27939. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  27940. + vchi_held_msg_release(&msg_handle);
  27941. + break;
  27942. +
  27943. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  27944. + event_to_host_cb(instance, msg, msg_len);
  27945. + vchi_held_msg_release(&msg_handle);
  27946. +
  27947. + break;
  27948. +
  27949. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  27950. + buffer_to_host_cb(instance, msg, msg_len);
  27951. + vchi_held_msg_release(&msg_handle);
  27952. + break;
  27953. +
  27954. + default:
  27955. + /* messages dependant on header context to complete */
  27956. +
  27957. + /* todo: the msg.context really ought to be sanity
  27958. + * checked before we just use it, afaict it comes back
  27959. + * and is used raw from the videocore. Perhaps it
  27960. + * should be verified the address lies in the kernel
  27961. + * address space.
  27962. + */
  27963. + if (msg->h.context == NULL) {
  27964. + pr_err("received message context was null!\n");
  27965. + vchi_held_msg_release(&msg_handle);
  27966. + break;
  27967. + }
  27968. +
  27969. + /* fill in context values */
  27970. + msg->h.context->u.sync.msg_handle = msg_handle;
  27971. + msg->h.context->u.sync.msg = msg;
  27972. + msg->h.context->u.sync.msg_len = msg_len;
  27973. +
  27974. + /* todo: should this check (completion_done()
  27975. + * == 1) for no one waiting? or do we need a
  27976. + * flag to tell us the completion has been
  27977. + * interrupted so we can free the message and
  27978. + * its context. This probably also solves the
  27979. + * message arriving after interruption todo
  27980. + * below
  27981. + */
  27982. +
  27983. + /* complete message so caller knows it happened */
  27984. + complete(&msg->h.context->u.sync.cmplt);
  27985. + break;
  27986. + }
  27987. +
  27988. + break;
  27989. +
  27990. + case VCHI_CALLBACK_BULK_RECEIVED:
  27991. + bulk_receive_cb(instance, bulk_ctx);
  27992. + break;
  27993. +
  27994. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  27995. + bulk_abort_cb(instance, bulk_ctx);
  27996. + break;
  27997. +
  27998. + case VCHI_CALLBACK_SERVICE_CLOSED:
  27999. + /* TODO: consider if this requires action if received when
  28000. + * driver is not explicitly closing the service
  28001. + */
  28002. + break;
  28003. +
  28004. + default:
  28005. + pr_err("Received unhandled message reason %d\n", reason);
  28006. + break;
  28007. + }
  28008. +}
  28009. +
  28010. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  28011. + struct mmal_msg *msg,
  28012. + unsigned int payload_len,
  28013. + struct mmal_msg **msg_out,
  28014. + VCHI_HELD_MSG_T *msg_handle_out)
  28015. +{
  28016. + struct mmal_msg_context msg_context;
  28017. + int ret;
  28018. +
  28019. + /* payload size must not cause message to exceed max size */
  28020. + if (payload_len >
  28021. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  28022. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  28023. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  28024. + return -EINVAL;
  28025. + }
  28026. +
  28027. + init_completion(&msg_context.u.sync.cmplt);
  28028. +
  28029. + msg->h.magic = MMAL_MAGIC;
  28030. + msg->h.context = &msg_context;
  28031. + msg->h.status = 0;
  28032. +
  28033. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  28034. + ">>> sync message");
  28035. +
  28036. + vchi_service_use(instance->handle);
  28037. +
  28038. + ret = vchi_msg_queue(instance->handle,
  28039. + msg,
  28040. + sizeof(struct mmal_msg_header) + payload_len,
  28041. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  28042. +
  28043. + vchi_service_release(instance->handle);
  28044. +
  28045. + if (ret) {
  28046. + pr_err("error %d queuing message\n", ret);
  28047. + return ret;
  28048. + }
  28049. +
  28050. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  28051. + if (ret <= 0) {
  28052. + pr_err("error %d waiting for sync completion\n", ret);
  28053. + if (ret == 0)
  28054. + ret = -ETIME;
  28055. + /* todo: what happens if the message arrives after aborting */
  28056. + return ret;
  28057. + }
  28058. +
  28059. + *msg_out = msg_context.u.sync.msg;
  28060. + *msg_handle_out = msg_context.u.sync.msg_handle;
  28061. +
  28062. + return 0;
  28063. +}
  28064. +
  28065. +static void dump_port_info(struct vchiq_mmal_port *port)
  28066. +{
  28067. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  28068. +
  28069. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  28070. + port->minimum_buffer.num,
  28071. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  28072. +
  28073. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  28074. + port->recommended_buffer.num,
  28075. + port->recommended_buffer.size,
  28076. + port->recommended_buffer.alignment);
  28077. +
  28078. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  28079. + port->current_buffer.num,
  28080. + port->current_buffer.size, port->current_buffer.alignment);
  28081. +
  28082. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  28083. + port->format.type,
  28084. + port->format.encoding, port->format.encoding_variant);
  28085. +
  28086. + pr_debug(" bitrate:%d flags:0x%x\n",
  28087. + port->format.bitrate, port->format.flags);
  28088. +
  28089. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  28090. + pr_debug
  28091. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  28092. + port->es.video.width, port->es.video.height,
  28093. + port->es.video.color_space);
  28094. +
  28095. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  28096. + port->es.video.crop.x,
  28097. + port->es.video.crop.y,
  28098. + port->es.video.crop.width, port->es.video.crop.height);
  28099. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  28100. + port->es.video.frame_rate.num,
  28101. + port->es.video.frame_rate.den,
  28102. + port->es.video.par.num, port->es.video.par.den);
  28103. + }
  28104. +}
  28105. +
  28106. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  28107. +{
  28108. +
  28109. + /* todo do readonly fields need setting at all? */
  28110. + p->type = port->type;
  28111. + p->index = port->index;
  28112. + p->index_all = 0;
  28113. + p->is_enabled = port->enabled;
  28114. + p->buffer_num_min = port->minimum_buffer.num;
  28115. + p->buffer_size_min = port->minimum_buffer.size;
  28116. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  28117. + p->buffer_num_recommended = port->recommended_buffer.num;
  28118. + p->buffer_size_recommended = port->recommended_buffer.size;
  28119. +
  28120. + /* only three writable fields in a port */
  28121. + p->buffer_num = port->current_buffer.num;
  28122. + p->buffer_size = port->current_buffer.size;
  28123. + p->userdata = port;
  28124. +}
  28125. +
  28126. +static int port_info_set(struct vchiq_mmal_instance *instance,
  28127. + struct vchiq_mmal_port *port)
  28128. +{
  28129. + int ret;
  28130. + struct mmal_msg m;
  28131. + struct mmal_msg *rmsg;
  28132. + VCHI_HELD_MSG_T rmsg_handle;
  28133. +
  28134. + pr_debug("setting port info port %p\n", port);
  28135. + if (!port)
  28136. + return -1;
  28137. + dump_port_info(port);
  28138. +
  28139. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  28140. +
  28141. + m.u.port_info_set.component_handle = port->component->handle;
  28142. + m.u.port_info_set.port_type = port->type;
  28143. + m.u.port_info_set.port_index = port->index;
  28144. +
  28145. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  28146. +
  28147. + /* elementry stream format setup */
  28148. + m.u.port_info_set.format.type = port->format.type;
  28149. + m.u.port_info_set.format.encoding = port->format.encoding;
  28150. + m.u.port_info_set.format.encoding_variant =
  28151. + port->format.encoding_variant;
  28152. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  28153. + m.u.port_info_set.format.flags = port->format.flags;
  28154. +
  28155. + memcpy(&m.u.port_info_set.es, &port->es,
  28156. + sizeof(union mmal_es_specific_format));
  28157. +
  28158. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  28159. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  28160. + port->format.extradata_size);
  28161. +
  28162. + ret = send_synchronous_mmal_msg(instance, &m,
  28163. + sizeof(m.u.port_info_set),
  28164. + &rmsg, &rmsg_handle);
  28165. + if (ret)
  28166. + return ret;
  28167. +
  28168. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  28169. + /* got an unexpected message type in reply */
  28170. + ret = -EINVAL;
  28171. + goto release_msg;
  28172. + }
  28173. +
  28174. + /* return operation status */
  28175. + ret = -rmsg->u.port_info_get_reply.status;
  28176. +
  28177. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  28178. + port->component->handle, port->handle);
  28179. +
  28180. +release_msg:
  28181. + vchi_held_msg_release(&rmsg_handle);
  28182. +
  28183. + return ret;
  28184. +
  28185. +}
  28186. +
  28187. +/* use port info get message to retrive port information */
  28188. +static int port_info_get(struct vchiq_mmal_instance *instance,
  28189. + struct vchiq_mmal_port *port)
  28190. +{
  28191. + int ret;
  28192. + struct mmal_msg m;
  28193. + struct mmal_msg *rmsg;
  28194. + VCHI_HELD_MSG_T rmsg_handle;
  28195. +
  28196. + /* port info time */
  28197. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  28198. + m.u.port_info_get.component_handle = port->component->handle;
  28199. + m.u.port_info_get.port_type = port->type;
  28200. + m.u.port_info_get.index = port->index;
  28201. +
  28202. + ret = send_synchronous_mmal_msg(instance, &m,
  28203. + sizeof(m.u.port_info_get),
  28204. + &rmsg, &rmsg_handle);
  28205. + if (ret)
  28206. + return ret;
  28207. +
  28208. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  28209. + /* got an unexpected message type in reply */
  28210. + ret = -EINVAL;
  28211. + goto release_msg;
  28212. + }
  28213. +
  28214. + /* return operation status */
  28215. + ret = -rmsg->u.port_info_get_reply.status;
  28216. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  28217. + goto release_msg;
  28218. +
  28219. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  28220. + port->enabled = false;
  28221. + else
  28222. + port->enabled = true;
  28223. +
  28224. + /* copy the values out of the message */
  28225. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  28226. +
  28227. + /* port type and index cached to use on port info set becuase
  28228. + * it does not use a port handle
  28229. + */
  28230. + port->type = rmsg->u.port_info_get_reply.port_type;
  28231. + port->index = rmsg->u.port_info_get_reply.port_index;
  28232. +
  28233. + port->minimum_buffer.num =
  28234. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  28235. + port->minimum_buffer.size =
  28236. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  28237. + port->minimum_buffer.alignment =
  28238. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  28239. +
  28240. + port->recommended_buffer.alignment =
  28241. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  28242. + port->recommended_buffer.num =
  28243. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  28244. +
  28245. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  28246. + port->current_buffer.size =
  28247. + rmsg->u.port_info_get_reply.port.buffer_size;
  28248. +
  28249. + /* stream format */
  28250. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  28251. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  28252. + port->format.encoding_variant =
  28253. + rmsg->u.port_info_get_reply.format.encoding_variant;
  28254. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  28255. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  28256. +
  28257. + /* elementry stream format */
  28258. + memcpy(&port->es,
  28259. + &rmsg->u.port_info_get_reply.es,
  28260. + sizeof(union mmal_es_specific_format));
  28261. + port->format.es = &port->es;
  28262. +
  28263. + port->format.extradata_size =
  28264. + rmsg->u.port_info_get_reply.format.extradata_size;
  28265. + memcpy(port->format.extradata,
  28266. + rmsg->u.port_info_get_reply.extradata,
  28267. + port->format.extradata_size);
  28268. +
  28269. + pr_debug("received port info\n");
  28270. + dump_port_info(port);
  28271. +
  28272. +release_msg:
  28273. +
  28274. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  28275. + __func__, ret, port->component->handle, port->handle);
  28276. +
  28277. + vchi_held_msg_release(&rmsg_handle);
  28278. +
  28279. + return ret;
  28280. +}
  28281. +
  28282. +/* create comonent on vc */
  28283. +static int create_component(struct vchiq_mmal_instance *instance,
  28284. + struct vchiq_mmal_component *component,
  28285. + const char *name)
  28286. +{
  28287. + int ret;
  28288. + struct mmal_msg m;
  28289. + struct mmal_msg *rmsg;
  28290. + VCHI_HELD_MSG_T rmsg_handle;
  28291. +
  28292. + /* build component create message */
  28293. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  28294. + m.u.component_create.client_component = component;
  28295. + strncpy(m.u.component_create.name, name,
  28296. + sizeof(m.u.component_create.name));
  28297. +
  28298. + ret = send_synchronous_mmal_msg(instance, &m,
  28299. + sizeof(m.u.component_create),
  28300. + &rmsg, &rmsg_handle);
  28301. + if (ret)
  28302. + return ret;
  28303. +
  28304. + if (rmsg->h.type != m.h.type) {
  28305. + /* got an unexpected message type in reply */
  28306. + ret = -EINVAL;
  28307. + goto release_msg;
  28308. + }
  28309. +
  28310. + ret = -rmsg->u.component_create_reply.status;
  28311. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  28312. + goto release_msg;
  28313. +
  28314. + /* a valid component response received */
  28315. + component->handle = rmsg->u.component_create_reply.component_handle;
  28316. + component->inputs = rmsg->u.component_create_reply.input_num;
  28317. + component->outputs = rmsg->u.component_create_reply.output_num;
  28318. + component->clocks = rmsg->u.component_create_reply.clock_num;
  28319. +
  28320. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  28321. + component->handle,
  28322. + component->inputs, component->outputs, component->clocks);
  28323. +
  28324. +release_msg:
  28325. + vchi_held_msg_release(&rmsg_handle);
  28326. +
  28327. + return ret;
  28328. +}
  28329. +
  28330. +/* destroys a component on vc */
  28331. +static int destroy_component(struct vchiq_mmal_instance *instance,
  28332. + struct vchiq_mmal_component *component)
  28333. +{
  28334. + int ret;
  28335. + struct mmal_msg m;
  28336. + struct mmal_msg *rmsg;
  28337. + VCHI_HELD_MSG_T rmsg_handle;
  28338. +
  28339. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  28340. + m.u.component_destroy.component_handle = component->handle;
  28341. +
  28342. + ret = send_synchronous_mmal_msg(instance, &m,
  28343. + sizeof(m.u.component_destroy),
  28344. + &rmsg, &rmsg_handle);
  28345. + if (ret)
  28346. + return ret;
  28347. +
  28348. + if (rmsg->h.type != m.h.type) {
  28349. + /* got an unexpected message type in reply */
  28350. + ret = -EINVAL;
  28351. + goto release_msg;
  28352. + }
  28353. +
  28354. + ret = -rmsg->u.component_destroy_reply.status;
  28355. +
  28356. +release_msg:
  28357. +
  28358. + vchi_held_msg_release(&rmsg_handle);
  28359. +
  28360. + return ret;
  28361. +}
  28362. +
  28363. +/* enable a component on vc */
  28364. +static int enable_component(struct vchiq_mmal_instance *instance,
  28365. + struct vchiq_mmal_component *component)
  28366. +{
  28367. + int ret;
  28368. + struct mmal_msg m;
  28369. + struct mmal_msg *rmsg;
  28370. + VCHI_HELD_MSG_T rmsg_handle;
  28371. +
  28372. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  28373. + m.u.component_enable.component_handle = component->handle;
  28374. +
  28375. + ret = send_synchronous_mmal_msg(instance, &m,
  28376. + sizeof(m.u.component_enable),
  28377. + &rmsg, &rmsg_handle);
  28378. + if (ret)
  28379. + return ret;
  28380. +
  28381. + if (rmsg->h.type != m.h.type) {
  28382. + /* got an unexpected message type in reply */
  28383. + ret = -EINVAL;
  28384. + goto release_msg;
  28385. + }
  28386. +
  28387. + ret = -rmsg->u.component_enable_reply.status;
  28388. +
  28389. +release_msg:
  28390. + vchi_held_msg_release(&rmsg_handle);
  28391. +
  28392. + return ret;
  28393. +}
  28394. +
  28395. +/* disable a component on vc */
  28396. +static int disable_component(struct vchiq_mmal_instance *instance,
  28397. + struct vchiq_mmal_component *component)
  28398. +{
  28399. + int ret;
  28400. + struct mmal_msg m;
  28401. + struct mmal_msg *rmsg;
  28402. + VCHI_HELD_MSG_T rmsg_handle;
  28403. +
  28404. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  28405. + m.u.component_disable.component_handle = component->handle;
  28406. +
  28407. + ret = send_synchronous_mmal_msg(instance, &m,
  28408. + sizeof(m.u.component_disable),
  28409. + &rmsg, &rmsg_handle);
  28410. + if (ret)
  28411. + return ret;
  28412. +
  28413. + if (rmsg->h.type != m.h.type) {
  28414. + /* got an unexpected message type in reply */
  28415. + ret = -EINVAL;
  28416. + goto release_msg;
  28417. + }
  28418. +
  28419. + ret = -rmsg->u.component_disable_reply.status;
  28420. +
  28421. +release_msg:
  28422. +
  28423. + vchi_held_msg_release(&rmsg_handle);
  28424. +
  28425. + return ret;
  28426. +}
  28427. +
  28428. +/* get version of mmal implementation */
  28429. +static int get_version(struct vchiq_mmal_instance *instance,
  28430. + u32 *major_out, u32 *minor_out)
  28431. +{
  28432. + int ret;
  28433. + struct mmal_msg m;
  28434. + struct mmal_msg *rmsg;
  28435. + VCHI_HELD_MSG_T rmsg_handle;
  28436. +
  28437. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  28438. +
  28439. + ret = send_synchronous_mmal_msg(instance, &m,
  28440. + sizeof(m.u.version),
  28441. + &rmsg, &rmsg_handle);
  28442. + if (ret)
  28443. + return ret;
  28444. +
  28445. + if (rmsg->h.type != m.h.type) {
  28446. + /* got an unexpected message type in reply */
  28447. + ret = -EINVAL;
  28448. + goto release_msg;
  28449. + }
  28450. +
  28451. + *major_out = rmsg->u.version.major;
  28452. + *minor_out = rmsg->u.version.minor;
  28453. +
  28454. +release_msg:
  28455. + vchi_held_msg_release(&rmsg_handle);
  28456. +
  28457. + return ret;
  28458. +}
  28459. +
  28460. +/* do a port action with a port as a parameter */
  28461. +static int port_action_port(struct vchiq_mmal_instance *instance,
  28462. + struct vchiq_mmal_port *port,
  28463. + enum mmal_msg_port_action_type action_type)
  28464. +{
  28465. + int ret;
  28466. + struct mmal_msg m;
  28467. + struct mmal_msg *rmsg;
  28468. + VCHI_HELD_MSG_T rmsg_handle;
  28469. +
  28470. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  28471. + m.u.port_action_port.component_handle = port->component->handle;
  28472. + m.u.port_action_port.port_handle = port->handle;
  28473. + m.u.port_action_port.action = action_type;
  28474. +
  28475. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  28476. +
  28477. + ret = send_synchronous_mmal_msg(instance, &m,
  28478. + sizeof(m.u.port_action_port),
  28479. + &rmsg, &rmsg_handle);
  28480. + if (ret)
  28481. + return ret;
  28482. +
  28483. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  28484. + /* got an unexpected message type in reply */
  28485. + ret = -EINVAL;
  28486. + goto release_msg;
  28487. + }
  28488. +
  28489. + ret = -rmsg->u.port_action_reply.status;
  28490. +
  28491. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  28492. + __func__,
  28493. + ret, port->component->handle, port->handle,
  28494. + port_action_type_names[action_type], action_type);
  28495. +
  28496. +release_msg:
  28497. + vchi_held_msg_release(&rmsg_handle);
  28498. +
  28499. + return ret;
  28500. +}
  28501. +
  28502. +/* do a port action with handles as parameters */
  28503. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  28504. + struct vchiq_mmal_port *port,
  28505. + enum mmal_msg_port_action_type action_type,
  28506. + u32 connect_component_handle,
  28507. + u32 connect_port_handle)
  28508. +{
  28509. + int ret;
  28510. + struct mmal_msg m;
  28511. + struct mmal_msg *rmsg;
  28512. + VCHI_HELD_MSG_T rmsg_handle;
  28513. +
  28514. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  28515. +
  28516. + m.u.port_action_handle.component_handle = port->component->handle;
  28517. + m.u.port_action_handle.port_handle = port->handle;
  28518. + m.u.port_action_handle.action = action_type;
  28519. +
  28520. + m.u.port_action_handle.connect_component_handle =
  28521. + connect_component_handle;
  28522. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  28523. +
  28524. + ret = send_synchronous_mmal_msg(instance, &m,
  28525. + sizeof(m.u.port_action_handle),
  28526. + &rmsg, &rmsg_handle);
  28527. + if (ret)
  28528. + return ret;
  28529. +
  28530. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  28531. + /* got an unexpected message type in reply */
  28532. + ret = -EINVAL;
  28533. + goto release_msg;
  28534. + }
  28535. +
  28536. + ret = -rmsg->u.port_action_reply.status;
  28537. +
  28538. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  28539. + " connect component:0x%x connect port:%d\n",
  28540. + __func__,
  28541. + ret, port->component->handle, port->handle,
  28542. + port_action_type_names[action_type],
  28543. + action_type, connect_component_handle, connect_port_handle);
  28544. +
  28545. +release_msg:
  28546. + vchi_held_msg_release(&rmsg_handle);
  28547. +
  28548. + return ret;
  28549. +}
  28550. +
  28551. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  28552. + struct vchiq_mmal_port *port,
  28553. + u32 parameter_id, void *value, u32 value_size)
  28554. +{
  28555. + int ret;
  28556. + struct mmal_msg m;
  28557. + struct mmal_msg *rmsg;
  28558. + VCHI_HELD_MSG_T rmsg_handle;
  28559. +
  28560. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  28561. +
  28562. + m.u.port_parameter_set.component_handle = port->component->handle;
  28563. + m.u.port_parameter_set.port_handle = port->handle;
  28564. + m.u.port_parameter_set.id = parameter_id;
  28565. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  28566. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  28567. +
  28568. + ret = send_synchronous_mmal_msg(instance, &m,
  28569. + (4 * sizeof(u32)) + value_size,
  28570. + &rmsg, &rmsg_handle);
  28571. + if (ret)
  28572. + return ret;
  28573. +
  28574. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  28575. + /* got an unexpected message type in reply */
  28576. + ret = -EINVAL;
  28577. + goto release_msg;
  28578. + }
  28579. +
  28580. + ret = -rmsg->u.port_parameter_set_reply.status;
  28581. +
  28582. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  28583. + __func__,
  28584. + ret, port->component->handle, port->handle, parameter_id);
  28585. +
  28586. +release_msg:
  28587. + vchi_held_msg_release(&rmsg_handle);
  28588. +
  28589. + return ret;
  28590. +}
  28591. +
  28592. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  28593. + struct vchiq_mmal_port *port,
  28594. + u32 parameter_id, void *value, u32 *value_size)
  28595. +{
  28596. + int ret;
  28597. + struct mmal_msg m;
  28598. + struct mmal_msg *rmsg;
  28599. + VCHI_HELD_MSG_T rmsg_handle;
  28600. +
  28601. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  28602. +
  28603. + m.u.port_parameter_get.component_handle = port->component->handle;
  28604. + m.u.port_parameter_get.port_handle = port->handle;
  28605. + m.u.port_parameter_get.id = parameter_id;
  28606. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  28607. +
  28608. + ret = send_synchronous_mmal_msg(instance, &m,
  28609. + sizeof(struct
  28610. + mmal_msg_port_parameter_get),
  28611. + &rmsg, &rmsg_handle);
  28612. + if (ret)
  28613. + return ret;
  28614. +
  28615. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  28616. + /* got an unexpected message type in reply */
  28617. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  28618. + ret = -EINVAL;
  28619. + goto release_msg;
  28620. + }
  28621. +
  28622. + ret = -rmsg->u.port_parameter_get_reply.status;
  28623. + if (ret) {
  28624. + /* Copy only as much as we have space for
  28625. + * but report true size of parameter
  28626. + */
  28627. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  28628. + *value_size);
  28629. + *value_size = rmsg->u.port_parameter_get_reply.size;
  28630. + } else
  28631. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  28632. + rmsg->u.port_parameter_get_reply.size);
  28633. +
  28634. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  28635. + ret, port->component->handle, port->handle, parameter_id);
  28636. +
  28637. +release_msg:
  28638. + vchi_held_msg_release(&rmsg_handle);
  28639. +
  28640. + return ret;
  28641. +}
  28642. +
  28643. +/* disables a port and drains buffers from it */
  28644. +static int port_disable(struct vchiq_mmal_instance *instance,
  28645. + struct vchiq_mmal_port *port)
  28646. +{
  28647. + int ret;
  28648. + struct list_head *q, *buf_head;
  28649. + unsigned long flags = 0;
  28650. +
  28651. + if (!port->enabled)
  28652. + return 0;
  28653. +
  28654. + port->enabled = false;
  28655. +
  28656. + ret = port_action_port(instance, port,
  28657. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  28658. + if (ret == 0) {
  28659. +
  28660. + /* drain all queued buffers on port */
  28661. + spin_lock_irqsave(&port->slock, flags);
  28662. +
  28663. + list_for_each_safe(buf_head, q, &port->buffers) {
  28664. + struct mmal_buffer *mmalbuf;
  28665. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  28666. + list);
  28667. + list_del(buf_head);
  28668. + if (port->buffer_cb)
  28669. + port->buffer_cb(instance,
  28670. + port, 0, mmalbuf, 0, 0,
  28671. + MMAL_TIME_UNKNOWN,
  28672. + MMAL_TIME_UNKNOWN);
  28673. + }
  28674. +
  28675. + spin_unlock_irqrestore(&port->slock, flags);
  28676. +
  28677. + ret = port_info_get(instance, port);
  28678. + }
  28679. +
  28680. + return ret;
  28681. +}
  28682. +
  28683. +/* enable a port */
  28684. +static int port_enable(struct vchiq_mmal_instance *instance,
  28685. + struct vchiq_mmal_port *port)
  28686. +{
  28687. + unsigned int hdr_count;
  28688. + struct list_head *buf_head;
  28689. + int ret;
  28690. +
  28691. + if (port->enabled)
  28692. + return 0;
  28693. +
  28694. + /* ensure there are enough buffers queued to cover the buffer headers */
  28695. + if (port->buffer_cb != NULL) {
  28696. + hdr_count = 0;
  28697. + list_for_each(buf_head, &port->buffers) {
  28698. + hdr_count++;
  28699. + }
  28700. + if (hdr_count < port->current_buffer.num)
  28701. + return -ENOSPC;
  28702. + }
  28703. +
  28704. + ret = port_action_port(instance, port,
  28705. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  28706. + if (ret)
  28707. + goto done;
  28708. +
  28709. + port->enabled = true;
  28710. +
  28711. + if (port->buffer_cb) {
  28712. + /* send buffer headers to videocore */
  28713. + hdr_count = 1;
  28714. + list_for_each(buf_head, &port->buffers) {
  28715. + struct mmal_buffer *mmalbuf;
  28716. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  28717. + list);
  28718. + ret = buffer_from_host(instance, port, mmalbuf);
  28719. + if (ret)
  28720. + goto done;
  28721. +
  28722. + hdr_count++;
  28723. + if (hdr_count > port->current_buffer.num)
  28724. + break;
  28725. + }
  28726. + }
  28727. +
  28728. + ret = port_info_get(instance, port);
  28729. +
  28730. +done:
  28731. + return ret;
  28732. +}
  28733. +
  28734. +/* ------------------------------------------------------------------
  28735. + * Exported API
  28736. + *------------------------------------------------------------------*/
  28737. +
  28738. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  28739. + struct vchiq_mmal_port *port)
  28740. +{
  28741. + int ret;
  28742. +
  28743. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28744. + return -EINTR;
  28745. +
  28746. + ret = port_info_set(instance, port);
  28747. + if (ret)
  28748. + goto release_unlock;
  28749. +
  28750. + /* read what has actually been set */
  28751. + ret = port_info_get(instance, port);
  28752. +
  28753. +release_unlock:
  28754. + mutex_unlock(&instance->vchiq_mutex);
  28755. +
  28756. + return ret;
  28757. +
  28758. +}
  28759. +
  28760. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  28761. + struct vchiq_mmal_port *port,
  28762. + u32 parameter, void *value, u32 value_size)
  28763. +{
  28764. + int ret;
  28765. +
  28766. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28767. + return -EINTR;
  28768. +
  28769. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  28770. +
  28771. + mutex_unlock(&instance->vchiq_mutex);
  28772. +
  28773. + return ret;
  28774. +}
  28775. +
  28776. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  28777. + struct vchiq_mmal_port *port,
  28778. + u32 parameter, void *value, u32 *value_size)
  28779. +{
  28780. + int ret;
  28781. +
  28782. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28783. + return -EINTR;
  28784. +
  28785. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  28786. +
  28787. + mutex_unlock(&instance->vchiq_mutex);
  28788. +
  28789. + return ret;
  28790. +}
  28791. +
  28792. +/* enable a port
  28793. + *
  28794. + * enables a port and queues buffers for satisfying callbacks if we
  28795. + * provide a callback handler
  28796. + */
  28797. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  28798. + struct vchiq_mmal_port *port,
  28799. + vchiq_mmal_buffer_cb buffer_cb)
  28800. +{
  28801. + int ret;
  28802. +
  28803. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28804. + return -EINTR;
  28805. +
  28806. + /* already enabled - noop */
  28807. + if (port->enabled) {
  28808. + ret = 0;
  28809. + goto unlock;
  28810. + }
  28811. +
  28812. + port->buffer_cb = buffer_cb;
  28813. +
  28814. + ret = port_enable(instance, port);
  28815. +
  28816. +unlock:
  28817. + mutex_unlock(&instance->vchiq_mutex);
  28818. +
  28819. + return ret;
  28820. +}
  28821. +
  28822. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  28823. + struct vchiq_mmal_port *port)
  28824. +{
  28825. + int ret;
  28826. +
  28827. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28828. + return -EINTR;
  28829. +
  28830. + if (!port->enabled) {
  28831. + mutex_unlock(&instance->vchiq_mutex);
  28832. + return 0;
  28833. + }
  28834. +
  28835. + ret = port_disable(instance, port);
  28836. +
  28837. + mutex_unlock(&instance->vchiq_mutex);
  28838. +
  28839. + return ret;
  28840. +}
  28841. +
  28842. +/* ports will be connected in a tunneled manner so data buffers
  28843. + * are not handled by client.
  28844. + */
  28845. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  28846. + struct vchiq_mmal_port *src,
  28847. + struct vchiq_mmal_port *dst)
  28848. +{
  28849. + int ret;
  28850. +
  28851. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28852. + return -EINTR;
  28853. +
  28854. + /* disconnect ports if connected */
  28855. + if (src->connected != NULL) {
  28856. + ret = port_disable(instance, src);
  28857. + if (ret) {
  28858. + pr_err("failed disabling src port(%d)\n", ret);
  28859. + goto release_unlock;
  28860. + }
  28861. +
  28862. + /* do not need to disable the destination port as they
  28863. + * are connected and it is done automatically
  28864. + */
  28865. +
  28866. + ret = port_action_handle(instance, src,
  28867. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  28868. + src->connected->component->handle,
  28869. + src->connected->handle);
  28870. + if (ret < 0) {
  28871. + pr_err("failed disconnecting src port\n");
  28872. + goto release_unlock;
  28873. + }
  28874. + src->connected->enabled = false;
  28875. + src->connected = NULL;
  28876. + }
  28877. +
  28878. + if (dst == NULL) {
  28879. + /* do not make new connection */
  28880. + ret = 0;
  28881. + pr_debug("not making new connection\n");
  28882. + goto release_unlock;
  28883. + }
  28884. +
  28885. + /* copy src port format to dst */
  28886. + dst->format.encoding = src->format.encoding;
  28887. + dst->es.video.width = src->es.video.width;
  28888. + dst->es.video.height = src->es.video.height;
  28889. + dst->es.video.crop.x = src->es.video.crop.x;
  28890. + dst->es.video.crop.y = src->es.video.crop.y;
  28891. + dst->es.video.crop.width = src->es.video.crop.width;
  28892. + dst->es.video.crop.height = src->es.video.crop.height;
  28893. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  28894. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  28895. +
  28896. + /* set new format */
  28897. + ret = port_info_set(instance, dst);
  28898. + if (ret) {
  28899. + pr_debug("setting port info failed\n");
  28900. + goto release_unlock;
  28901. + }
  28902. +
  28903. + /* read what has actually been set */
  28904. + ret = port_info_get(instance, dst);
  28905. + if (ret) {
  28906. + pr_debug("read back port info failed\n");
  28907. + goto release_unlock;
  28908. + }
  28909. +
  28910. + /* connect two ports together */
  28911. + ret = port_action_handle(instance, src,
  28912. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  28913. + dst->component->handle, dst->handle);
  28914. + if (ret < 0) {
  28915. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  28916. + src->component->handle, src->handle,
  28917. + dst->component->handle, dst->handle);
  28918. + goto release_unlock;
  28919. + }
  28920. + src->connected = dst;
  28921. +
  28922. +release_unlock:
  28923. +
  28924. + mutex_unlock(&instance->vchiq_mutex);
  28925. +
  28926. + return ret;
  28927. +}
  28928. +
  28929. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  28930. + struct vchiq_mmal_port *port,
  28931. + struct mmal_buffer *buffer)
  28932. +{
  28933. + unsigned long flags = 0;
  28934. +
  28935. + spin_lock_irqsave(&port->slock, flags);
  28936. + list_add_tail(&buffer->list, &port->buffers);
  28937. + spin_unlock_irqrestore(&port->slock, flags);
  28938. +
  28939. + /* the port previously underflowed because it was missing a
  28940. + * mmal_buffer which has just been added, submit that buffer
  28941. + * to the mmal service.
  28942. + */
  28943. + if (port->buffer_underflow) {
  28944. + port_buffer_from_host(instance, port);
  28945. + port->buffer_underflow--;
  28946. + }
  28947. +
  28948. + return 0;
  28949. +}
  28950. +
  28951. +/* Initialise a mmal component and its ports
  28952. + *
  28953. + */
  28954. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  28955. + const char *name,
  28956. + struct vchiq_mmal_component **component_out)
  28957. +{
  28958. + int ret;
  28959. + int idx; /* port index */
  28960. + struct vchiq_mmal_component *component;
  28961. +
  28962. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  28963. + return -EINTR;
  28964. +
  28965. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  28966. + ret = -EINVAL; /* todo is this correct error? */
  28967. + goto unlock;
  28968. + }
  28969. +
  28970. + component = &instance->component[instance->component_idx];
  28971. +
  28972. + ret = create_component(instance, component, name);
  28973. + if (ret < 0)
  28974. + goto unlock;
  28975. +
  28976. + /* ports info needs gathering */
  28977. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  28978. + component->control.index = 0;
  28979. + component->control.component = component;
  28980. + spin_lock_init(&component->control.slock);
  28981. + INIT_LIST_HEAD(&component->control.buffers);
  28982. + ret = port_info_get(instance, &component->control);
  28983. + if (ret < 0)
  28984. + goto release_component;
  28985. +
  28986. + for (idx = 0; idx < component->inputs; idx++) {
  28987. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  28988. + component->input[idx].index = idx;
  28989. + component->input[idx].component = component;
  28990. + spin_lock_init(&component->input[idx].slock);
  28991. + INIT_LIST_HEAD(&component->input[idx].buffers);
  28992. + ret = port_info_get(instance, &component->input[idx]);
  28993. + if (ret < 0)
  28994. + goto release_component;
  28995. + }
  28996. +
  28997. + for (idx = 0; idx < component->outputs; idx++) {
  28998. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  28999. + component->output[idx].index = idx;
  29000. + component->output[idx].component = component;
  29001. + spin_lock_init(&component->output[idx].slock);
  29002. + INIT_LIST_HEAD(&component->output[idx].buffers);
  29003. + ret = port_info_get(instance, &component->output[idx]);
  29004. + if (ret < 0)
  29005. + goto release_component;
  29006. + }
  29007. +
  29008. + for (idx = 0; idx < component->clocks; idx++) {
  29009. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  29010. + component->clock[idx].index = idx;
  29011. + component->clock[idx].component = component;
  29012. + spin_lock_init(&component->clock[idx].slock);
  29013. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  29014. + ret = port_info_get(instance, &component->clock[idx]);
  29015. + if (ret < 0)
  29016. + goto release_component;
  29017. + }
  29018. +
  29019. + instance->component_idx++;
  29020. +
  29021. + *component_out = component;
  29022. +
  29023. + mutex_unlock(&instance->vchiq_mutex);
  29024. +
  29025. + return 0;
  29026. +
  29027. +release_component:
  29028. + destroy_component(instance, component);
  29029. +unlock:
  29030. + mutex_unlock(&instance->vchiq_mutex);
  29031. +
  29032. + return ret;
  29033. +}
  29034. +
  29035. +/*
  29036. + * cause a mmal component to be destroyed
  29037. + */
  29038. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  29039. + struct vchiq_mmal_component *component)
  29040. +{
  29041. + int ret;
  29042. +
  29043. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  29044. + return -EINTR;
  29045. +
  29046. + if (component->enabled)
  29047. + ret = disable_component(instance, component);
  29048. +
  29049. + ret = destroy_component(instance, component);
  29050. +
  29051. + mutex_unlock(&instance->vchiq_mutex);
  29052. +
  29053. + return ret;
  29054. +}
  29055. +
  29056. +/*
  29057. + * cause a mmal component to be enabled
  29058. + */
  29059. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  29060. + struct vchiq_mmal_component *component)
  29061. +{
  29062. + int ret;
  29063. +
  29064. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  29065. + return -EINTR;
  29066. +
  29067. + if (component->enabled) {
  29068. + mutex_unlock(&instance->vchiq_mutex);
  29069. + return 0;
  29070. + }
  29071. +
  29072. + ret = enable_component(instance, component);
  29073. + if (ret == 0)
  29074. + component->enabled = true;
  29075. +
  29076. + mutex_unlock(&instance->vchiq_mutex);
  29077. +
  29078. + return ret;
  29079. +}
  29080. +
  29081. +/*
  29082. + * cause a mmal component to be enabled
  29083. + */
  29084. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  29085. + struct vchiq_mmal_component *component)
  29086. +{
  29087. + int ret;
  29088. +
  29089. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  29090. + return -EINTR;
  29091. +
  29092. + if (!component->enabled) {
  29093. + mutex_unlock(&instance->vchiq_mutex);
  29094. + return 0;
  29095. + }
  29096. +
  29097. + ret = disable_component(instance, component);
  29098. + if (ret == 0)
  29099. + component->enabled = false;
  29100. +
  29101. + mutex_unlock(&instance->vchiq_mutex);
  29102. +
  29103. + return ret;
  29104. +}
  29105. +
  29106. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  29107. + u32 *major_out, u32 *minor_out)
  29108. +{
  29109. + int ret;
  29110. +
  29111. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  29112. + return -EINTR;
  29113. +
  29114. + ret = get_version(instance, major_out, minor_out);
  29115. +
  29116. + mutex_unlock(&instance->vchiq_mutex);
  29117. +
  29118. + return ret;
  29119. +}
  29120. +
  29121. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  29122. +{
  29123. + int status = 0;
  29124. +
  29125. + if (instance == NULL)
  29126. + return -EINVAL;
  29127. +
  29128. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  29129. + return -EINTR;
  29130. +
  29131. + vchi_service_use(instance->handle);
  29132. +
  29133. + status = vchi_service_close(instance->handle);
  29134. + if (status != 0)
  29135. + pr_err("mmal-vchiq: VCHIQ close failed");
  29136. +
  29137. + mutex_unlock(&instance->vchiq_mutex);
  29138. +
  29139. + vfree(instance->bulk_scratch);
  29140. +
  29141. + kfree(instance);
  29142. +
  29143. + return status;
  29144. +}
  29145. +
  29146. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  29147. +{
  29148. + int status;
  29149. + struct vchiq_mmal_instance *instance;
  29150. + static VCHI_CONNECTION_T *vchi_connection;
  29151. + static VCHI_INSTANCE_T vchi_instance;
  29152. + SERVICE_CREATION_T params = {
  29153. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  29154. + VC_MMAL_SERVER_NAME,
  29155. + vchi_connection,
  29156. + 0, /* rx fifo size (unused) */
  29157. + 0, /* tx fifo size (unused) */
  29158. + service_callback,
  29159. + NULL, /* service callback parameter */
  29160. + 1, /* unaligned bulk receives */
  29161. + 1, /* unaligned bulk transmits */
  29162. + 0 /* want crc check on bulk transfers */
  29163. + };
  29164. +
  29165. + /* compile time checks to ensure structure size as they are
  29166. + * directly (de)serialised from memory.
  29167. + */
  29168. +
  29169. + /* ensure the header structure has packed to the correct size */
  29170. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  29171. +
  29172. + /* ensure message structure does not exceed maximum length */
  29173. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  29174. +
  29175. + /* mmal port struct is correct size */
  29176. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  29177. +
  29178. + /* create a vchi instance */
  29179. + status = vchi_initialise(&vchi_instance);
  29180. + if (status) {
  29181. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  29182. + status);
  29183. + return -EIO;
  29184. + }
  29185. +
  29186. + status = vchi_connect(NULL, 0, vchi_instance);
  29187. + if (status) {
  29188. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  29189. + return -EIO;
  29190. + }
  29191. +
  29192. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  29193. + memset(instance, 0, sizeof(*instance));
  29194. +
  29195. + mutex_init(&instance->vchiq_mutex);
  29196. + mutex_init(&instance->bulk_mutex);
  29197. +
  29198. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  29199. +
  29200. + params.callback_param = instance;
  29201. +
  29202. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  29203. + if (status) {
  29204. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  29205. + status);
  29206. + goto err_close_services;
  29207. + }
  29208. +
  29209. + vchi_service_release(instance->handle);
  29210. +
  29211. + *out_instance = instance;
  29212. +
  29213. + return 0;
  29214. +
  29215. +err_close_services:
  29216. +
  29217. + vchi_service_close(instance->handle);
  29218. + vfree(instance->bulk_scratch);
  29219. + kfree(instance);
  29220. + return -ENODEV;
  29221. +}
  29222. diff -Nur linux-3.12.38/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  29223. --- linux-3.12.38/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  29224. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2015-03-09 10:39:30.594893734 +0100
  29225. @@ -0,0 +1,178 @@
  29226. +/*
  29227. + * Broadcom BM2835 V4L2 driver
  29228. + *
  29229. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  29230. + *
  29231. + * This file is subject to the terms and conditions of the GNU General Public
  29232. + * License. See the file COPYING in the main directory of this archive
  29233. + * for more details.
  29234. + *
  29235. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  29236. + * Dave Stevenson <dsteve@broadcom.com>
  29237. + * Simon Mellor <simellor@broadcom.com>
  29238. + * Luke Diamand <luked@broadcom.com>
  29239. + *
  29240. + * MMAL interface to VCHIQ message passing
  29241. + */
  29242. +
  29243. +#ifndef MMAL_VCHIQ_H
  29244. +#define MMAL_VCHIQ_H
  29245. +
  29246. +#include "mmal-msg-format.h"
  29247. +
  29248. +#define MAX_PORT_COUNT 4
  29249. +
  29250. +/* Maximum size of the format extradata. */
  29251. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  29252. +
  29253. +struct vchiq_mmal_instance;
  29254. +
  29255. +enum vchiq_mmal_es_type {
  29256. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  29257. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  29258. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  29259. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  29260. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  29261. +};
  29262. +
  29263. +/* rectangle, used lots so it gets its own struct */
  29264. +struct vchiq_mmal_rect {
  29265. + s32 x;
  29266. + s32 y;
  29267. + s32 width;
  29268. + s32 height;
  29269. +};
  29270. +
  29271. +struct vchiq_mmal_port_buffer {
  29272. + unsigned int num; /* number of buffers */
  29273. + u32 size; /* size of buffers */
  29274. + u32 alignment; /* alignment of buffers */
  29275. +};
  29276. +
  29277. +struct vchiq_mmal_port;
  29278. +
  29279. +typedef void (*vchiq_mmal_buffer_cb)(
  29280. + struct vchiq_mmal_instance *instance,
  29281. + struct vchiq_mmal_port *port,
  29282. + int status, struct mmal_buffer *buffer,
  29283. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  29284. +
  29285. +struct vchiq_mmal_port {
  29286. + bool enabled;
  29287. + u32 handle;
  29288. + u32 type; /* port type, cached to use on port info set */
  29289. + u32 index; /* port index, cached to use on port info set */
  29290. +
  29291. + /* component port belongs to, allows simple deref */
  29292. + struct vchiq_mmal_component *component;
  29293. +
  29294. + struct vchiq_mmal_port *connected; /* port conencted to */
  29295. +
  29296. + /* buffer info */
  29297. + struct vchiq_mmal_port_buffer minimum_buffer;
  29298. + struct vchiq_mmal_port_buffer recommended_buffer;
  29299. + struct vchiq_mmal_port_buffer current_buffer;
  29300. +
  29301. + /* stream format */
  29302. + struct mmal_es_format format;
  29303. + /* elementry stream format */
  29304. + union mmal_es_specific_format es;
  29305. +
  29306. + /* data buffers to fill */
  29307. + struct list_head buffers;
  29308. + /* lock to serialise adding and removing buffers from list */
  29309. + spinlock_t slock;
  29310. + /* count of how many buffer header refils have failed because
  29311. + * there was no buffer to satisfy them
  29312. + */
  29313. + int buffer_underflow;
  29314. + /* callback on buffer completion */
  29315. + vchiq_mmal_buffer_cb buffer_cb;
  29316. + /* callback context */
  29317. + void *cb_ctx;
  29318. +};
  29319. +
  29320. +struct vchiq_mmal_component {
  29321. + bool enabled;
  29322. + u32 handle; /* VideoCore handle for component */
  29323. + u32 inputs; /* Number of input ports */
  29324. + u32 outputs; /* Number of output ports */
  29325. + u32 clocks; /* Number of clock ports */
  29326. + struct vchiq_mmal_port control; /* control port */
  29327. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  29328. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  29329. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  29330. +};
  29331. +
  29332. +
  29333. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  29334. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  29335. +
  29336. +/* Initialise a mmal component and its ports
  29337. +*
  29338. +*/
  29339. +int vchiq_mmal_component_init(
  29340. + struct vchiq_mmal_instance *instance,
  29341. + const char *name,
  29342. + struct vchiq_mmal_component **component_out);
  29343. +
  29344. +int vchiq_mmal_component_finalise(
  29345. + struct vchiq_mmal_instance *instance,
  29346. + struct vchiq_mmal_component *component);
  29347. +
  29348. +int vchiq_mmal_component_enable(
  29349. + struct vchiq_mmal_instance *instance,
  29350. + struct vchiq_mmal_component *component);
  29351. +
  29352. +int vchiq_mmal_component_disable(
  29353. + struct vchiq_mmal_instance *instance,
  29354. + struct vchiq_mmal_component *component);
  29355. +
  29356. +
  29357. +
  29358. +/* enable a mmal port
  29359. + *
  29360. + * enables a port and if a buffer callback provided enque buffer
  29361. + * headers as apropriate for the port.
  29362. + */
  29363. +int vchiq_mmal_port_enable(
  29364. + struct vchiq_mmal_instance *instance,
  29365. + struct vchiq_mmal_port *port,
  29366. + vchiq_mmal_buffer_cb buffer_cb);
  29367. +
  29368. +/* disable a port
  29369. + *
  29370. + * disable a port will dequeue any pending buffers
  29371. + */
  29372. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  29373. + struct vchiq_mmal_port *port);
  29374. +
  29375. +
  29376. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  29377. + struct vchiq_mmal_port *port,
  29378. + u32 parameter,
  29379. + void *value,
  29380. + u32 value_size);
  29381. +
  29382. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  29383. + struct vchiq_mmal_port *port,
  29384. + u32 parameter,
  29385. + void *value,
  29386. + u32 *value_size);
  29387. +
  29388. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  29389. + struct vchiq_mmal_port *port);
  29390. +
  29391. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  29392. + struct vchiq_mmal_port *src,
  29393. + struct vchiq_mmal_port *dst);
  29394. +
  29395. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  29396. + u32 *major_out,
  29397. + u32 *minor_out);
  29398. +
  29399. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  29400. + struct vchiq_mmal_port *port,
  29401. + struct mmal_buffer *buf);
  29402. +
  29403. +#endif /* MMAL_VCHIQ_H */
  29404. diff -Nur linux-3.12.38/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  29405. --- linux-3.12.38/drivers/media/platform/Kconfig 2015-02-16 16:15:42.000000000 +0100
  29406. +++ linux-rpi/drivers/media/platform/Kconfig 2015-03-10 17:26:50.466216693 +0100
  29407. @@ -124,6 +124,7 @@
  29408. source "drivers/media/platform/soc_camera/Kconfig"
  29409. source "drivers/media/platform/exynos4-is/Kconfig"
  29410. source "drivers/media/platform/s5p-tv/Kconfig"
  29411. +source "drivers/media/platform/bcm2835/Kconfig"
  29412. endif # V4L_PLATFORM_DRIVERS
  29413. diff -Nur linux-3.12.38/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  29414. --- linux-3.12.38/drivers/media/platform/Makefile 2015-02-16 16:15:42.000000000 +0100
  29415. +++ linux-rpi/drivers/media/platform/Makefile 2015-03-10 17:26:50.466216693 +0100
  29416. @@ -52,4 +52,6 @@
  29417. obj-$(CONFIG_ARCH_OMAP) += omap/
  29418. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  29419. +
  29420. ccflags-y += -I$(srctree)/drivers/media/i2c
  29421. diff -Nur linux-3.12.38/drivers/media/rc/ir-lirc-codec.c linux-rpi/drivers/media/rc/ir-lirc-codec.c
  29422. --- linux-3.12.38/drivers/media/rc/ir-lirc-codec.c 2015-02-16 16:15:42.000000000 +0100
  29423. +++ linux-rpi/drivers/media/rc/ir-lirc-codec.c 2015-03-10 17:26:50.490216692 +0100
  29424. @@ -42,17 +42,11 @@
  29425. return -EINVAL;
  29426. /* Packet start */
  29427. - if (ev.reset) {
  29428. - /* Userspace expects a long space event before the start of
  29429. - * the signal to use as a sync. This may be done with repeat
  29430. - * packets and normal samples. But if a reset has been sent
  29431. - * then we assume that a long time has passed, so we send a
  29432. - * space with the maximum time value. */
  29433. - sample = LIRC_SPACE(LIRC_VALUE_MASK);
  29434. - IR_dprintk(2, "delivering reset sync space to lirc_dev\n");
  29435. + if (ev.reset)
  29436. + return 0;
  29437. /* Carrier reports */
  29438. - } else if (ev.carrier_report) {
  29439. + if (ev.carrier_report) {
  29440. sample = LIRC_FREQUENCY(ev.carrier);
  29441. IR_dprintk(2, "carrier report (freq: %d)\n", sample);
  29442. diff -Nur linux-3.12.38/drivers/media/usb/au0828/au0828-cards.c linux-rpi/drivers/media/usb/au0828/au0828-cards.c
  29443. --- linux-3.12.38/drivers/media/usb/au0828/au0828-cards.c 2015-02-16 16:15:42.000000000 +0100
  29444. +++ linux-rpi/drivers/media/usb/au0828/au0828-cards.c 2015-03-10 17:26:50.498216692 +0100
  29445. @@ -36,11 +36,6 @@
  29446. au0828_clear(dev, REG_000, 0x10);
  29447. }
  29448. -/*
  29449. - * WARNING: There's a quirks table at sound/usb/quirks-table.h
  29450. - * that should also be updated every time a new device with V4L2 support
  29451. - * is added here.
  29452. - */
  29453. struct au0828_board au0828_boards[] = {
  29454. [AU0828_BOARD_UNKNOWN] = {
  29455. .name = "Unknown board",
  29456. diff -Nur linux-3.12.38/drivers/media/usb/dvb-usb/af9005.c linux-rpi/drivers/media/usb/dvb-usb/af9005.c
  29457. --- linux-3.12.38/drivers/media/usb/dvb-usb/af9005.c 2015-02-16 16:15:42.000000000 +0100
  29458. +++ linux-rpi/drivers/media/usb/dvb-usb/af9005.c 2015-03-10 17:26:50.506216692 +0100
  29459. @@ -1081,12 +1081,9 @@
  29460. err("usb_register failed. (%d)", result);
  29461. return result;
  29462. }
  29463. -#if IS_MODULE(CONFIG_DVB_USB_AF9005) || defined(CONFIG_DVB_USB_AF9005_REMOTE)
  29464. - /* FIXME: convert to todays kernel IR infrastructure */
  29465. rc_decode = symbol_request(af9005_rc_decode);
  29466. rc_keys = symbol_request(rc_map_af9005_table);
  29467. rc_keys_size = symbol_request(rc_map_af9005_table_size);
  29468. -#endif
  29469. if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
  29470. err("af9005_rc_decode function not found, disabling remote");
  29471. af9005_properties.rc.legacy.rc_query = NULL;
  29472. diff -Nur linux-3.12.38/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  29473. --- linux-3.12.38/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-02-16 16:15:42.000000000 +0100
  29474. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2015-03-10 17:26:50.502216692 +0100
  29475. @@ -1390,6 +1390,10 @@
  29476. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  29477. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  29478. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  29479. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  29480. + &rtl2832u_props, "August DVB-T 205", NULL) },
  29481. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  29482. + &rtl2832u_props, "August DVB-T 205", NULL) },
  29483. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  29484. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  29485. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  29486. diff -Nur linux-3.12.38/drivers/media/usb/usbtv/usbtv.c linux-rpi/drivers/media/usb/usbtv/usbtv.c
  29487. --- linux-3.12.38/drivers/media/usb/usbtv/usbtv.c 2015-02-16 16:15:42.000000000 +0100
  29488. +++ linux-rpi/drivers/media/usb/usbtv/usbtv.c 2015-03-10 17:26:50.522216692 +0100
  29489. @@ -50,13 +50,8 @@
  29490. #define USBTV_ISOC_TRANSFERS 16
  29491. #define USBTV_ISOC_PACKETS 8
  29492. -#define USBTV_WIDTH 720
  29493. -#define USBTV_HEIGHT 480
  29494. -
  29495. #define USBTV_CHUNK_SIZE 256
  29496. #define USBTV_CHUNK 240
  29497. -#define USBTV_CHUNKS (USBTV_WIDTH * USBTV_HEIGHT \
  29498. - / 4 / USBTV_CHUNK)
  29499. /* Chunk header. */
  29500. #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
  29501. @@ -65,6 +60,27 @@
  29502. #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
  29503. #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
  29504. +#define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
  29505. +
  29506. +/* parameters for supported TV norms */
  29507. +struct usbtv_norm_params {
  29508. + v4l2_std_id norm;
  29509. + int cap_width, cap_height;
  29510. +};
  29511. +
  29512. +static struct usbtv_norm_params norm_params[] = {
  29513. + {
  29514. + .norm = V4L2_STD_525_60,
  29515. + .cap_width = 720,
  29516. + .cap_height = 480,
  29517. + },
  29518. + {
  29519. + .norm = V4L2_STD_PAL,
  29520. + .cap_width = 720,
  29521. + .cap_height = 576,
  29522. + }
  29523. +};
  29524. +
  29525. /* A single videobuf2 frame buffer. */
  29526. struct usbtv_buf {
  29527. struct vb2_buffer vb;
  29528. @@ -94,11 +110,38 @@
  29529. USBTV_COMPOSITE_INPUT,
  29530. USBTV_SVIDEO_INPUT,
  29531. } input;
  29532. + v4l2_std_id norm;
  29533. + int width, height;
  29534. + int n_chunks;
  29535. int iso_size;
  29536. unsigned int sequence;
  29537. struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
  29538. };
  29539. +static int usbtv_configure_for_norm(struct usbtv *usbtv, v4l2_std_id norm)
  29540. +{
  29541. + int i, ret = 0;
  29542. + struct usbtv_norm_params *params = NULL;
  29543. +
  29544. + for (i = 0; i < ARRAY_SIZE(norm_params); i++) {
  29545. + if (norm_params[i].norm & norm) {
  29546. + params = &norm_params[i];
  29547. + break;
  29548. + }
  29549. + }
  29550. +
  29551. + if (params) {
  29552. + usbtv->width = params->cap_width;
  29553. + usbtv->height = params->cap_height;
  29554. + usbtv->n_chunks = usbtv->width * usbtv->height
  29555. + / 4 / USBTV_CHUNK;
  29556. + usbtv->norm = params->norm;
  29557. + } else
  29558. + ret = -EINVAL;
  29559. +
  29560. + return ret;
  29561. +}
  29562. +
  29563. static int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size)
  29564. {
  29565. int ret;
  29566. @@ -158,6 +201,57 @@
  29567. return ret;
  29568. }
  29569. +static int usbtv_select_norm(struct usbtv *usbtv, v4l2_std_id norm)
  29570. +{
  29571. + int ret;
  29572. + static const u16 pal[][2] = {
  29573. + { USBTV_BASE + 0x001a, 0x0068 },
  29574. + { USBTV_BASE + 0x010e, 0x0072 },
  29575. + { USBTV_BASE + 0x010f, 0x00a2 },
  29576. + { USBTV_BASE + 0x0112, 0x00b0 },
  29577. + { USBTV_BASE + 0x0117, 0x0001 },
  29578. + { USBTV_BASE + 0x0118, 0x002c },
  29579. + { USBTV_BASE + 0x012d, 0x0010 },
  29580. + { USBTV_BASE + 0x012f, 0x0020 },
  29581. + { USBTV_BASE + 0x024f, 0x0002 },
  29582. + { USBTV_BASE + 0x0254, 0x0059 },
  29583. + { USBTV_BASE + 0x025a, 0x0016 },
  29584. + { USBTV_BASE + 0x025b, 0x0035 },
  29585. + { USBTV_BASE + 0x0263, 0x0017 },
  29586. + { USBTV_BASE + 0x0266, 0x0016 },
  29587. + { USBTV_BASE + 0x0267, 0x0036 }
  29588. + };
  29589. +
  29590. + static const u16 ntsc[][2] = {
  29591. + { USBTV_BASE + 0x001a, 0x0079 },
  29592. + { USBTV_BASE + 0x010e, 0x0068 },
  29593. + { USBTV_BASE + 0x010f, 0x009c },
  29594. + { USBTV_BASE + 0x0112, 0x00f0 },
  29595. + { USBTV_BASE + 0x0117, 0x0000 },
  29596. + { USBTV_BASE + 0x0118, 0x00fc },
  29597. + { USBTV_BASE + 0x012d, 0x0004 },
  29598. + { USBTV_BASE + 0x012f, 0x0008 },
  29599. + { USBTV_BASE + 0x024f, 0x0001 },
  29600. + { USBTV_BASE + 0x0254, 0x005f },
  29601. + { USBTV_BASE + 0x025a, 0x0012 },
  29602. + { USBTV_BASE + 0x025b, 0x0001 },
  29603. + { USBTV_BASE + 0x0263, 0x001c },
  29604. + { USBTV_BASE + 0x0266, 0x0011 },
  29605. + { USBTV_BASE + 0x0267, 0x0005 }
  29606. + };
  29607. +
  29608. + ret = usbtv_configure_for_norm(usbtv, norm);
  29609. +
  29610. + if (!ret) {
  29611. + if (norm & V4L2_STD_525_60)
  29612. + ret = usbtv_set_regs(usbtv, ntsc, ARRAY_SIZE(ntsc));
  29613. + else if (norm & V4L2_STD_PAL)
  29614. + ret = usbtv_set_regs(usbtv, pal, ARRAY_SIZE(pal));
  29615. + }
  29616. +
  29617. + return ret;
  29618. +}
  29619. +
  29620. static int usbtv_setup_capture(struct usbtv *usbtv)
  29621. {
  29622. int ret;
  29623. @@ -225,26 +319,11 @@
  29624. { USBTV_BASE + 0x0284, 0x0088 },
  29625. { USBTV_BASE + 0x0003, 0x0004 },
  29626. - { USBTV_BASE + 0x001a, 0x0079 },
  29627. { USBTV_BASE + 0x0100, 0x00d3 },
  29628. - { USBTV_BASE + 0x010e, 0x0068 },
  29629. - { USBTV_BASE + 0x010f, 0x009c },
  29630. - { USBTV_BASE + 0x0112, 0x00f0 },
  29631. { USBTV_BASE + 0x0115, 0x0015 },
  29632. - { USBTV_BASE + 0x0117, 0x0000 },
  29633. - { USBTV_BASE + 0x0118, 0x00fc },
  29634. - { USBTV_BASE + 0x012d, 0x0004 },
  29635. - { USBTV_BASE + 0x012f, 0x0008 },
  29636. { USBTV_BASE + 0x0220, 0x002e },
  29637. { USBTV_BASE + 0x0225, 0x0008 },
  29638. { USBTV_BASE + 0x024e, 0x0002 },
  29639. - { USBTV_BASE + 0x024f, 0x0001 },
  29640. - { USBTV_BASE + 0x0254, 0x005f },
  29641. - { USBTV_BASE + 0x025a, 0x0012 },
  29642. - { USBTV_BASE + 0x025b, 0x0001 },
  29643. - { USBTV_BASE + 0x0263, 0x001c },
  29644. - { USBTV_BASE + 0x0266, 0x0011 },
  29645. - { USBTV_BASE + 0x0267, 0x0005 },
  29646. { USBTV_BASE + 0x024e, 0x0002 },
  29647. { USBTV_BASE + 0x024f, 0x0002 },
  29648. };
  29649. @@ -253,6 +332,10 @@
  29650. if (ret)
  29651. return ret;
  29652. + ret = usbtv_select_norm(usbtv, usbtv->norm);
  29653. + if (ret)
  29654. + return ret;
  29655. +
  29656. ret = usbtv_select_input(usbtv, usbtv->input);
  29657. if (ret)
  29658. return ret;
  29659. @@ -296,7 +379,7 @@
  29660. frame_id = USBTV_FRAME_ID(chunk);
  29661. odd = USBTV_ODD(chunk);
  29662. chunk_no = USBTV_CHUNK_NO(chunk);
  29663. - if (chunk_no >= USBTV_CHUNKS)
  29664. + if (chunk_no >= usbtv->n_chunks)
  29665. return;
  29666. /* Beginning of a frame. */
  29667. @@ -324,10 +407,10 @@
  29668. usbtv->chunks_done++;
  29669. /* Last chunk in a frame, signalling an end */
  29670. - if (odd && chunk_no == USBTV_CHUNKS-1) {
  29671. + if (odd && chunk_no == usbtv->n_chunks-1) {
  29672. int size = vb2_plane_size(&buf->vb, 0);
  29673. enum vb2_buffer_state state = usbtv->chunks_done ==
  29674. - USBTV_CHUNKS ?
  29675. + usbtv->n_chunks ?
  29676. VB2_BUF_STATE_DONE :
  29677. VB2_BUF_STATE_ERROR;
  29678. @@ -500,6 +583,8 @@
  29679. static int usbtv_enum_input(struct file *file, void *priv,
  29680. struct v4l2_input *i)
  29681. {
  29682. + struct usbtv *dev = video_drvdata(file);
  29683. +
  29684. switch (i->index) {
  29685. case USBTV_COMPOSITE_INPUT:
  29686. strlcpy(i->name, "Composite", sizeof(i->name));
  29687. @@ -512,7 +597,7 @@
  29688. }
  29689. i->type = V4L2_INPUT_TYPE_CAMERA;
  29690. - i->std = V4L2_STD_525_60;
  29691. + i->std = dev->vdev.tvnorms;
  29692. return 0;
  29693. }
  29694. @@ -531,23 +616,37 @@
  29695. static int usbtv_fmt_vid_cap(struct file *file, void *priv,
  29696. struct v4l2_format *f)
  29697. {
  29698. - f->fmt.pix.width = USBTV_WIDTH;
  29699. - f->fmt.pix.height = USBTV_HEIGHT;
  29700. + struct usbtv *usbtv = video_drvdata(file);
  29701. +
  29702. + f->fmt.pix.width = usbtv->width;
  29703. + f->fmt.pix.height = usbtv->height;
  29704. f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
  29705. f->fmt.pix.field = V4L2_FIELD_INTERLACED;
  29706. - f->fmt.pix.bytesperline = USBTV_WIDTH * 2;
  29707. + f->fmt.pix.bytesperline = usbtv->width * 2;
  29708. f->fmt.pix.sizeimage = (f->fmt.pix.bytesperline * f->fmt.pix.height);
  29709. f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  29710. - f->fmt.pix.priv = 0;
  29711. +
  29712. return 0;
  29713. }
  29714. static int usbtv_g_std(struct file *file, void *priv, v4l2_std_id *norm)
  29715. {
  29716. - *norm = V4L2_STD_525_60;
  29717. + struct usbtv *usbtv = video_drvdata(file);
  29718. + *norm = usbtv->norm;
  29719. return 0;
  29720. }
  29721. +static int usbtv_s_std(struct file *file, void *priv, v4l2_std_id norm)
  29722. +{
  29723. + int ret = -EINVAL;
  29724. + struct usbtv *usbtv = video_drvdata(file);
  29725. +
  29726. + if ((norm & V4L2_STD_525_60) || (norm & V4L2_STD_PAL))
  29727. + ret = usbtv_select_norm(usbtv, norm);
  29728. +
  29729. + return ret;
  29730. +}
  29731. +
  29732. static int usbtv_g_input(struct file *file, void *priv, unsigned int *i)
  29733. {
  29734. struct usbtv *usbtv = video_drvdata(file);
  29735. @@ -561,13 +660,6 @@
  29736. return usbtv_select_input(usbtv, i);
  29737. }
  29738. -static int usbtv_s_std(struct file *file, void *priv, v4l2_std_id norm)
  29739. -{
  29740. - if (norm & V4L2_STD_525_60)
  29741. - return 0;
  29742. - return -EINVAL;
  29743. -}
  29744. -
  29745. struct v4l2_ioctl_ops usbtv_ioctl_ops = {
  29746. .vidioc_querycap = usbtv_querycap,
  29747. .vidioc_enum_input = usbtv_enum_input,
  29748. @@ -604,10 +696,12 @@
  29749. const struct v4l2_format *v4l_fmt, unsigned int *nbuffers,
  29750. unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
  29751. {
  29752. + struct usbtv *usbtv = vb2_get_drv_priv(vq);
  29753. +
  29754. if (*nbuffers < 2)
  29755. *nbuffers = 2;
  29756. *nplanes = 1;
  29757. - sizes[0] = USBTV_WIDTH * USBTV_HEIGHT / 2 * sizeof(u32);
  29758. + sizes[0] = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32);
  29759. return 0;
  29760. }
  29761. @@ -690,7 +784,11 @@
  29762. return -ENOMEM;
  29763. usbtv->dev = dev;
  29764. usbtv->udev = usb_get_dev(interface_to_usbdev(intf));
  29765. +
  29766. usbtv->iso_size = size;
  29767. +
  29768. + (void)usbtv_configure_for_norm(usbtv, V4L2_STD_525_60);
  29769. +
  29770. spin_lock_init(&usbtv->buflock);
  29771. mutex_init(&usbtv->v4l2_lock);
  29772. mutex_init(&usbtv->vb2q_lock);
  29773. @@ -727,7 +825,7 @@
  29774. usbtv->vdev.release = video_device_release_empty;
  29775. usbtv->vdev.fops = &usbtv_fops;
  29776. usbtv->vdev.ioctl_ops = &usbtv_ioctl_ops;
  29777. - usbtv->vdev.tvnorms = V4L2_STD_525_60;
  29778. + usbtv->vdev.tvnorms = USBTV_TV_STD;
  29779. usbtv->vdev.queue = &usbtv->vb2q;
  29780. usbtv->vdev.lock = &usbtv->v4l2_lock;
  29781. set_bit(V4L2_FL_USE_FH_PRIO, &usbtv->vdev.flags);
  29782. diff -Nur linux-3.12.38/drivers/media/usb/uvc/uvc_driver.c linux-rpi/drivers/media/usb/uvc/uvc_driver.c
  29783. --- linux-3.12.38/drivers/media/usb/uvc/uvc_driver.c 2015-02-16 16:15:42.000000000 +0100
  29784. +++ linux-rpi/drivers/media/usb/uvc/uvc_driver.c 2015-03-10 17:26:50.526216692 +0100
  29785. @@ -1603,12 +1603,12 @@
  29786. {
  29787. struct list_head *p, *n;
  29788. - uvc_status_cleanup(dev);
  29789. - uvc_ctrl_cleanup_device(dev);
  29790. -
  29791. usb_put_intf(dev->intf);
  29792. usb_put_dev(dev->udev);
  29793. + uvc_status_cleanup(dev);
  29794. + uvc_ctrl_cleanup_device(dev);
  29795. +
  29796. if (dev->vdev.dev)
  29797. v4l2_device_unregister(&dev->vdev);
  29798. #ifdef CONFIG_MEDIA_CONTROLLER
  29799. diff -Nur linux-3.12.38/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  29800. --- linux-3.12.38/drivers/misc/Kconfig 2015-02-16 16:15:42.000000000 +0100
  29801. +++ linux-rpi/drivers/misc/Kconfig 2015-03-10 17:26:50.546216692 +0100
  29802. @@ -537,4 +537,5 @@
  29803. source "drivers/misc/altera-stapl/Kconfig"
  29804. source "drivers/misc/mei/Kconfig"
  29805. source "drivers/misc/vmw_vmci/Kconfig"
  29806. +source "drivers/misc/vc04_services/Kconfig"
  29807. endmenu
  29808. diff -Nur linux-3.12.38/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  29809. --- linux-3.12.38/drivers/misc/Makefile 2015-02-16 16:15:42.000000000 +0100
  29810. +++ linux-rpi/drivers/misc/Makefile 2015-03-10 17:26:50.546216692 +0100
  29811. @@ -53,3 +53,4 @@
  29812. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  29813. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  29814. obj-$(CONFIG_SRAM) += sram.o
  29815. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  29816. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  29817. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  29818. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2015-03-09 10:39:30.718893733 +0100
  29819. @@ -0,0 +1,328 @@
  29820. +/**
  29821. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29822. + *
  29823. + * Redistribution and use in source and binary forms, with or without
  29824. + * modification, are permitted provided that the following conditions
  29825. + * are met:
  29826. + * 1. Redistributions of source code must retain the above copyright
  29827. + * notice, this list of conditions, and the following disclaimer,
  29828. + * without modification.
  29829. + * 2. Redistributions in binary form must reproduce the above copyright
  29830. + * notice, this list of conditions and the following disclaimer in the
  29831. + * documentation and/or other materials provided with the distribution.
  29832. + * 3. The names of the above-listed copyright holders may not be used
  29833. + * to endorse or promote products derived from this software without
  29834. + * specific prior written permission.
  29835. + *
  29836. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29837. + * GNU General Public License ("GPL") version 2, as published by the Free
  29838. + * Software Foundation.
  29839. + *
  29840. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29841. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29842. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29843. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29844. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29845. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29846. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29847. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29848. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29849. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29850. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29851. + */
  29852. +
  29853. +#ifndef CONNECTION_H_
  29854. +#define CONNECTION_H_
  29855. +
  29856. +#include <linux/kernel.h>
  29857. +#include <linux/types.h>
  29858. +#include <linux/semaphore.h>
  29859. +
  29860. +#include "interface/vchi/vchi_cfg_internal.h"
  29861. +#include "interface/vchi/vchi_common.h"
  29862. +#include "interface/vchi/message_drivers/message.h"
  29863. +
  29864. +/******************************************************************************
  29865. + Global defs
  29866. + *****************************************************************************/
  29867. +
  29868. +// Opaque handle for a connection / service pair
  29869. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  29870. +
  29871. +// opaque handle to the connection state information
  29872. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  29873. +
  29874. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  29875. +
  29876. +
  29877. +/******************************************************************************
  29878. + API
  29879. + *****************************************************************************/
  29880. +
  29881. +// Routine to init a connection with a particular low level driver
  29882. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  29883. + const VCHI_MESSAGE_DRIVER_T * driver );
  29884. +
  29885. +// Routine to control CRC enabling at a connection level
  29886. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  29887. + VCHI_CRC_CONTROL_T control );
  29888. +
  29889. +// Routine to create a service
  29890. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  29891. + int32_t service_id,
  29892. + uint32_t rx_fifo_size,
  29893. + uint32_t tx_fifo_size,
  29894. + int server,
  29895. + VCHI_CALLBACK_T callback,
  29896. + void *callback_param,
  29897. + int32_t want_crc,
  29898. + int32_t want_unaligned_bulk_rx,
  29899. + int32_t want_unaligned_bulk_tx,
  29900. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  29901. +
  29902. +// Routine to close a service
  29903. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  29904. +
  29905. +// Routine to queue a message
  29906. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29907. + const void *data,
  29908. + uint32_t data_size,
  29909. + VCHI_FLAGS_T flags,
  29910. + void *msg_handle );
  29911. +
  29912. +// scatter-gather (vector) message queueing
  29913. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29914. + VCHI_MSG_VECTOR_T *vector,
  29915. + uint32_t count,
  29916. + VCHI_FLAGS_T flags,
  29917. + void *msg_handle );
  29918. +
  29919. +// Routine to dequeue a message
  29920. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29921. + void *data,
  29922. + uint32_t max_data_size_to_read,
  29923. + uint32_t *actual_msg_size,
  29924. + VCHI_FLAGS_T flags );
  29925. +
  29926. +// Routine to peek at a message
  29927. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29928. + void **data,
  29929. + uint32_t *msg_size,
  29930. + VCHI_FLAGS_T flags );
  29931. +
  29932. +// Routine to hold a message
  29933. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29934. + void **data,
  29935. + uint32_t *msg_size,
  29936. + VCHI_FLAGS_T flags,
  29937. + void **message_handle );
  29938. +
  29939. +// Routine to initialise a received message iterator
  29940. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29941. + VCHI_MSG_ITER_T *iter,
  29942. + VCHI_FLAGS_T flags );
  29943. +
  29944. +// Routine to release a held message
  29945. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29946. + void *message_handle );
  29947. +
  29948. +// Routine to get info on a held message
  29949. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29950. + void *message_handle,
  29951. + void **data,
  29952. + int32_t *msg_size,
  29953. + uint32_t *tx_timestamp,
  29954. + uint32_t *rx_timestamp );
  29955. +
  29956. +// Routine to check whether the iterator has a next message
  29957. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  29958. + const VCHI_MSG_ITER_T *iter );
  29959. +
  29960. +// Routine to advance the iterator
  29961. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  29962. + VCHI_MSG_ITER_T *iter,
  29963. + void **data,
  29964. + uint32_t *msg_size );
  29965. +
  29966. +// Routine to remove the last message returned by the iterator
  29967. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  29968. + VCHI_MSG_ITER_T *iter );
  29969. +
  29970. +// Routine to hold the last message returned by the iterator
  29971. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  29972. + VCHI_MSG_ITER_T *iter,
  29973. + void **msg_handle );
  29974. +
  29975. +// Routine to transmit bulk data
  29976. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29977. + const void *data_src,
  29978. + uint32_t data_size,
  29979. + VCHI_FLAGS_T flags,
  29980. + void *bulk_handle );
  29981. +
  29982. +// Routine to receive data
  29983. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  29984. + void *data_dst,
  29985. + uint32_t data_size,
  29986. + VCHI_FLAGS_T flags,
  29987. + void *bulk_handle );
  29988. +
  29989. +// Routine to report if a server is available
  29990. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  29991. +
  29992. +// Routine to report the number of RX slots available
  29993. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  29994. +
  29995. +// Routine to report the RX slot size
  29996. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  29997. +
  29998. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  29999. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  30000. + int32_t service,
  30001. + uint32_t length,
  30002. + MESSAGE_TX_CHANNEL_T channel,
  30003. + uint32_t channel_params,
  30004. + uint32_t data_length,
  30005. + uint32_t data_offset);
  30006. +
  30007. +// Callback to inform a service that a Xon or Xoff message has been received
  30008. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  30009. +
  30010. +// Callback to inform a service that a server available reply message has been received
  30011. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  30012. +
  30013. +// Callback to indicate that bulk auxiliary messages have arrived
  30014. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  30015. +
  30016. +// Callback to indicate that bulk auxiliary messages have arrived
  30017. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  30018. +
  30019. +// Callback with all the connection info you require
  30020. +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);
  30021. +
  30022. +// Callback to inform of a disconnect
  30023. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  30024. +
  30025. +// Callback to inform of a power control request
  30026. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  30027. +
  30028. +// allocate memory suitably aligned for this connection
  30029. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  30030. +
  30031. +// free memory allocated by buffer_allocate
  30032. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  30033. +
  30034. +
  30035. +/******************************************************************************
  30036. + System driver struct
  30037. + *****************************************************************************/
  30038. +
  30039. +struct opaque_vchi_connection_api_t
  30040. +{
  30041. + // Routine to init the connection
  30042. + VCHI_CONNECTION_INIT_T init;
  30043. +
  30044. + // Connection-level CRC control
  30045. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  30046. +
  30047. + // Routine to connect to or create service
  30048. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  30049. +
  30050. + // Routine to disconnect from a service
  30051. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  30052. +
  30053. + // Routine to queue a message
  30054. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  30055. +
  30056. + // scatter-gather (vector) message queue
  30057. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  30058. +
  30059. + // Routine to dequeue a message
  30060. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  30061. +
  30062. + // Routine to peek at a message
  30063. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  30064. +
  30065. + // Routine to hold a message
  30066. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  30067. +
  30068. + // Routine to initialise a received message iterator
  30069. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  30070. +
  30071. + // Routine to release a message
  30072. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  30073. +
  30074. + // Routine to get information on a held message
  30075. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  30076. +
  30077. + // Routine to check for next message on iterator
  30078. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  30079. +
  30080. + // Routine to get next message on iterator
  30081. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  30082. +
  30083. + // Routine to remove the last message returned by iterator
  30084. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  30085. +
  30086. + // Routine to hold the last message returned by iterator
  30087. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  30088. +
  30089. + // Routine to transmit bulk data
  30090. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  30091. +
  30092. + // Routine to receive data
  30093. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  30094. +
  30095. + // Routine to report the available servers
  30096. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  30097. +
  30098. + // Routine to report the number of RX slots available
  30099. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  30100. +
  30101. + // Routine to report the RX slot size
  30102. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  30103. +
  30104. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  30105. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  30106. +
  30107. + // Callback to inform a service that a Xon or Xoff message has been received
  30108. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  30109. +
  30110. + // Callback to inform a service that a server available reply message has been received
  30111. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  30112. +
  30113. + // Callback to indicate that bulk auxiliary messages have arrived
  30114. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  30115. +
  30116. + // Callback to indicate that a bulk auxiliary message has been transmitted
  30117. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  30118. +
  30119. + // Callback to provide information about the connection
  30120. + VCHI_CONNECTION_INFO connection_info;
  30121. +
  30122. + // Callback to notify that peer has requested disconnect
  30123. + VCHI_CONNECTION_DISCONNECT disconnect;
  30124. +
  30125. + // Callback to notify that peer has requested power change
  30126. + VCHI_CONNECTION_POWER_CONTROL power_control;
  30127. +
  30128. + // allocate memory suitably aligned for this connection
  30129. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  30130. +
  30131. + // free memory allocated by buffer_allocate
  30132. + VCHI_BUFFER_FREE buffer_free;
  30133. +
  30134. +};
  30135. +
  30136. +struct vchi_connection_t {
  30137. + const VCHI_CONNECTION_API_T *api;
  30138. + VCHI_CONNECTION_STATE_T *state;
  30139. +#ifdef VCHI_COARSE_LOCKING
  30140. + struct semaphore sem;
  30141. +#endif
  30142. +};
  30143. +
  30144. +
  30145. +#endif /* CONNECTION_H_ */
  30146. +
  30147. +/****************************** End of file **********************************/
  30148. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  30149. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  30150. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2015-03-09 10:39:30.718893733 +0100
  30151. @@ -0,0 +1,204 @@
  30152. +/**
  30153. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30154. + *
  30155. + * Redistribution and use in source and binary forms, with or without
  30156. + * modification, are permitted provided that the following conditions
  30157. + * are met:
  30158. + * 1. Redistributions of source code must retain the above copyright
  30159. + * notice, this list of conditions, and the following disclaimer,
  30160. + * without modification.
  30161. + * 2. Redistributions in binary form must reproduce the above copyright
  30162. + * notice, this list of conditions and the following disclaimer in the
  30163. + * documentation and/or other materials provided with the distribution.
  30164. + * 3. The names of the above-listed copyright holders may not be used
  30165. + * to endorse or promote products derived from this software without
  30166. + * specific prior written permission.
  30167. + *
  30168. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30169. + * GNU General Public License ("GPL") version 2, as published by the Free
  30170. + * Software Foundation.
  30171. + *
  30172. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30173. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30174. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30175. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30176. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30177. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30178. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30179. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30180. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30181. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30182. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30183. + */
  30184. +
  30185. +#ifndef _VCHI_MESSAGE_H_
  30186. +#define _VCHI_MESSAGE_H_
  30187. +
  30188. +#include <linux/kernel.h>
  30189. +#include <linux/types.h>
  30190. +#include <linux/semaphore.h>
  30191. +
  30192. +#include "interface/vchi/vchi_cfg_internal.h"
  30193. +#include "interface/vchi/vchi_common.h"
  30194. +
  30195. +
  30196. +typedef enum message_event_type {
  30197. + MESSAGE_EVENT_NONE,
  30198. + MESSAGE_EVENT_NOP,
  30199. + MESSAGE_EVENT_MESSAGE,
  30200. + MESSAGE_EVENT_SLOT_COMPLETE,
  30201. + MESSAGE_EVENT_RX_BULK_PAUSED,
  30202. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  30203. + MESSAGE_EVENT_TX_COMPLETE,
  30204. + MESSAGE_EVENT_MSG_DISCARDED
  30205. +} MESSAGE_EVENT_TYPE_T;
  30206. +
  30207. +typedef enum vchi_msg_flags
  30208. +{
  30209. + VCHI_MSG_FLAGS_NONE = 0x0,
  30210. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  30211. +} VCHI_MSG_FLAGS_T;
  30212. +
  30213. +typedef enum message_tx_channel
  30214. +{
  30215. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  30216. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  30217. +} MESSAGE_TX_CHANNEL_T;
  30218. +
  30219. +// Macros used for cycling through bulk channels
  30220. +#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)
  30221. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  30222. +
  30223. +typedef enum message_rx_channel
  30224. +{
  30225. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  30226. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  30227. +} MESSAGE_RX_CHANNEL_T;
  30228. +
  30229. +// Message receive slot information
  30230. +typedef struct rx_msg_slot_info {
  30231. +
  30232. + struct rx_msg_slot_info *next;
  30233. + //struct slot_info *prev;
  30234. +#if !defined VCHI_COARSE_LOCKING
  30235. + struct semaphore sem;
  30236. +#endif
  30237. +
  30238. + uint8_t *addr; // base address of slot
  30239. + uint32_t len; // length of slot in bytes
  30240. +
  30241. + uint32_t write_ptr; // hardware causes this to advance
  30242. + uint32_t read_ptr; // this module does the reading
  30243. + int active; // is this slot in the hardware dma fifo?
  30244. + uint32_t msgs_parsed; // count how many messages are in this slot
  30245. + uint32_t msgs_released; // how many messages have been released
  30246. + void *state; // connection state information
  30247. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  30248. +} RX_MSG_SLOTINFO_T;
  30249. +
  30250. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  30251. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  30252. +// driver will be tasked with sending the aligned core section.
  30253. +typedef struct rx_bulk_slotinfo_t {
  30254. + struct rx_bulk_slotinfo_t *next;
  30255. +
  30256. + struct semaphore *blocking;
  30257. +
  30258. + // needed by DMA
  30259. + void *addr;
  30260. + uint32_t len;
  30261. +
  30262. + // needed for the callback
  30263. + void *service;
  30264. + void *handle;
  30265. + VCHI_FLAGS_T flags;
  30266. +} RX_BULK_SLOTINFO_T;
  30267. +
  30268. +
  30269. +/* ----------------------------------------------------------------------
  30270. + * each connection driver will have a pool of the following struct.
  30271. + *
  30272. + * the pool will be managed by vchi_qman_*
  30273. + * this means there will be multiple queues (single linked lists)
  30274. + * a given struct message_info will be on exactly one of these queues
  30275. + * at any one time
  30276. + * -------------------------------------------------------------------- */
  30277. +typedef struct rx_message_info {
  30278. +
  30279. + struct message_info *next;
  30280. + //struct message_info *prev;
  30281. +
  30282. + uint8_t *addr;
  30283. + uint32_t len;
  30284. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  30285. + uint32_t tx_timestamp;
  30286. + uint32_t rx_timestamp;
  30287. +
  30288. +} RX_MESSAGE_INFO_T;
  30289. +
  30290. +typedef struct {
  30291. + MESSAGE_EVENT_TYPE_T type;
  30292. +
  30293. + struct {
  30294. + // for messages
  30295. + void *addr; // address of message
  30296. + uint16_t slot_delta; // whether this message indicated slot delta
  30297. + uint32_t len; // length of message
  30298. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  30299. + int32_t service; // service id this message is destined for
  30300. + uint32_t tx_timestamp; // timestamp from the header
  30301. + uint32_t rx_timestamp; // timestamp when we parsed it
  30302. + } message;
  30303. +
  30304. + // FIXME: cleanup slot reporting...
  30305. + RX_MSG_SLOTINFO_T *rx_msg;
  30306. + RX_BULK_SLOTINFO_T *rx_bulk;
  30307. + void *tx_handle;
  30308. + MESSAGE_TX_CHANNEL_T tx_channel;
  30309. +
  30310. +} MESSAGE_EVENT_T;
  30311. +
  30312. +
  30313. +// callbacks
  30314. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  30315. +
  30316. +typedef struct {
  30317. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  30318. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  30319. +
  30320. +
  30321. +// handle to this instance of message driver (as returned by ->open)
  30322. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  30323. +
  30324. +struct opaque_vchi_message_driver_t {
  30325. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  30326. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  30327. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  30328. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  30329. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  30330. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  30331. + 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)
  30332. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  30333. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  30334. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  30335. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  30336. +
  30337. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  30338. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  30339. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  30340. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  30341. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  30342. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  30343. +
  30344. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  30345. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  30346. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  30347. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  30348. + 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 );
  30349. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  30350. +};
  30351. +
  30352. +
  30353. +#endif // _VCHI_MESSAGE_H_
  30354. +
  30355. +/****************************** End of file ***********************************/
  30356. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  30357. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  30358. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2015-03-09 10:39:30.718893733 +0100
  30359. @@ -0,0 +1,224 @@
  30360. +/**
  30361. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30362. + *
  30363. + * Redistribution and use in source and binary forms, with or without
  30364. + * modification, are permitted provided that the following conditions
  30365. + * are met:
  30366. + * 1. Redistributions of source code must retain the above copyright
  30367. + * notice, this list of conditions, and the following disclaimer,
  30368. + * without modification.
  30369. + * 2. Redistributions in binary form must reproduce the above copyright
  30370. + * notice, this list of conditions and the following disclaimer in the
  30371. + * documentation and/or other materials provided with the distribution.
  30372. + * 3. The names of the above-listed copyright holders may not be used
  30373. + * to endorse or promote products derived from this software without
  30374. + * specific prior written permission.
  30375. + *
  30376. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30377. + * GNU General Public License ("GPL") version 2, as published by the Free
  30378. + * Software Foundation.
  30379. + *
  30380. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30381. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30382. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30383. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30384. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30385. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30386. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30387. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30388. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30389. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30390. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30391. + */
  30392. +
  30393. +#ifndef VCHI_CFG_H_
  30394. +#define VCHI_CFG_H_
  30395. +
  30396. +/****************************************************************************************
  30397. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  30398. + * services.
  30399. + ***************************************************************************************/
  30400. +
  30401. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  30402. +/* Really determined by the message driver, and should be available from a run-time call. */
  30403. +#ifndef VCHI_BULK_ALIGN
  30404. +# if __VCCOREVER__ >= 0x04000000
  30405. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  30406. +# else
  30407. +# define VCHI_BULK_ALIGN 16
  30408. +# endif
  30409. +#endif
  30410. +
  30411. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  30412. +/* May be less than or greater than VCHI_BULK_ALIGN */
  30413. +/* Really determined by the message driver, and should be available from a run-time call. */
  30414. +#ifndef VCHI_BULK_GRANULARITY
  30415. +# if __VCCOREVER__ >= 0x04000000
  30416. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  30417. +# else
  30418. +# define VCHI_BULK_GRANULARITY 16
  30419. +# endif
  30420. +#endif
  30421. +
  30422. +/* The largest possible message to be queued with vchi_msg_queue. */
  30423. +#ifndef VCHI_MAX_MSG_SIZE
  30424. +# if defined VCHI_LOCAL_HOST_PORT
  30425. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  30426. +# else
  30427. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  30428. +# endif
  30429. +#endif
  30430. +
  30431. +/******************************************************************************************
  30432. + * Defines below are system configuration options, and should not be used by VCHI services.
  30433. + *****************************************************************************************/
  30434. +
  30435. +/* How many connections can we support? A localhost implementation uses 2 connections,
  30436. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  30437. + * driver. */
  30438. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  30439. +# define VCHI_MAX_NUM_CONNECTIONS 3
  30440. +#endif
  30441. +
  30442. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  30443. + * amount of static memory. */
  30444. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  30445. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  30446. +#endif
  30447. +
  30448. +/* Adjust if using a message driver that supports more logical TX channels */
  30449. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  30450. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  30451. +#endif
  30452. +
  30453. +/* Adjust if using a message driver that supports more logical RX channels */
  30454. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  30455. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  30456. +#endif
  30457. +
  30458. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  30459. + * receive queue space, less message headers. */
  30460. +#ifndef VCHI_NUM_READ_SLOTS
  30461. +# if defined(VCHI_LOCAL_HOST_PORT)
  30462. +# define VCHI_NUM_READ_SLOTS 4
  30463. +# else
  30464. +# define VCHI_NUM_READ_SLOTS 48
  30465. +# endif
  30466. +#endif
  30467. +
  30468. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  30469. + * performance. Only define on VideoCore end, talking to host.
  30470. + */
  30471. +//#define VCHI_MSG_RX_OVERRUN
  30472. +
  30473. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  30474. + * underneath VCHI will usually have its own buffering. */
  30475. +#ifndef VCHI_NUM_WRITE_SLOTS
  30476. +# define VCHI_NUM_WRITE_SLOTS 4
  30477. +#endif
  30478. +
  30479. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  30480. + * then it's taking up too much buffer space, and the peer service will be told to stop
  30481. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  30482. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  30483. + * is too high. */
  30484. +#ifndef VCHI_XOFF_THRESHOLD
  30485. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  30486. +#endif
  30487. +
  30488. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  30489. + * service has dequeued/released enough messages that it's now occupying
  30490. + * VCHI_XON_THRESHOLD slots or fewer. */
  30491. +#ifndef VCHI_XON_THRESHOLD
  30492. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  30493. +#endif
  30494. +
  30495. +/* A size below which a bulk transfer omits the handshake completely and always goes
  30496. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  30497. + * can guarantee this by enabling unaligned transmits).
  30498. + * Not API. */
  30499. +#ifndef VCHI_MIN_BULK_SIZE
  30500. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  30501. +#endif
  30502. +
  30503. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  30504. + * speed and latency; the smaller the chunk size the better change of messages and other
  30505. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  30506. + * break transmissions into chunks.
  30507. + */
  30508. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  30509. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  30510. +#endif
  30511. +
  30512. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  30513. + * with multiple-line frames. Only use if the receiver can cope. */
  30514. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  30515. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  30516. +#endif
  30517. +
  30518. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  30519. + * vchi_msg_queue will be blocked. */
  30520. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  30521. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  30522. +#endif
  30523. +
  30524. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  30525. + * will be suspended until older messages are dequeued/released. */
  30526. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  30527. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  30528. +#endif
  30529. +
  30530. +/* Really should be able to cope if we run out of received message descriptors, by
  30531. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  30532. + * under the carpet. */
  30533. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  30534. +# undef VCHI_RX_MSG_QUEUE_SIZE
  30535. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  30536. +#endif
  30537. +
  30538. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  30539. + * will be blocked. */
  30540. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  30541. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  30542. +#endif
  30543. +
  30544. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  30545. + * will be blocked. */
  30546. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  30547. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  30548. +#endif
  30549. +
  30550. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  30551. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  30552. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  30553. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  30554. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  30555. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  30556. +#endif
  30557. +
  30558. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  30559. + * transmitter on and off.
  30560. + */
  30561. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  30562. +
  30563. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  30564. +
  30565. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  30566. + * negative for no IDLE.
  30567. + */
  30568. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  30569. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  30570. +# endif
  30571. +
  30572. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  30573. + * negative for no OFF.
  30574. + */
  30575. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  30576. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  30577. +# endif
  30578. +
  30579. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  30580. +
  30581. +#endif /* VCHI_CFG_H_ */
  30582. +
  30583. +/****************************** End of file **********************************/
  30584. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  30585. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  30586. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2015-03-09 10:39:30.718893733 +0100
  30587. @@ -0,0 +1,71 @@
  30588. +/**
  30589. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30590. + *
  30591. + * Redistribution and use in source and binary forms, with or without
  30592. + * modification, are permitted provided that the following conditions
  30593. + * are met:
  30594. + * 1. Redistributions of source code must retain the above copyright
  30595. + * notice, this list of conditions, and the following disclaimer,
  30596. + * without modification.
  30597. + * 2. Redistributions in binary form must reproduce the above copyright
  30598. + * notice, this list of conditions and the following disclaimer in the
  30599. + * documentation and/or other materials provided with the distribution.
  30600. + * 3. The names of the above-listed copyright holders may not be used
  30601. + * to endorse or promote products derived from this software without
  30602. + * specific prior written permission.
  30603. + *
  30604. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30605. + * GNU General Public License ("GPL") version 2, as published by the Free
  30606. + * Software Foundation.
  30607. + *
  30608. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30609. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30610. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30611. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30612. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30613. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30614. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30615. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30616. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30617. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30618. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30619. + */
  30620. +
  30621. +#ifndef VCHI_CFG_INTERNAL_H_
  30622. +#define VCHI_CFG_INTERNAL_H_
  30623. +
  30624. +/****************************************************************************************
  30625. + * Control optimisation attempts.
  30626. + ***************************************************************************************/
  30627. +
  30628. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  30629. +#define VCHI_COARSE_LOCKING
  30630. +
  30631. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  30632. +// (only relevant if VCHI_COARSE_LOCKING)
  30633. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  30634. +
  30635. +// Avoid lock on non-blocking peek
  30636. +// (only relevant if VCHI_COARSE_LOCKING)
  30637. +#define VCHI_AVOID_PEEK_LOCK
  30638. +
  30639. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  30640. +#define VCHI_MULTIPLE_HANDLER_THREADS
  30641. +
  30642. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  30643. +// our way through the pool of descriptors.
  30644. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  30645. +
  30646. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  30647. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  30648. +
  30649. +// Don't use message descriptors for TX messages that don't need them
  30650. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  30651. +
  30652. +// Nano-locks for multiqueue
  30653. +//#define VCHI_MQUEUE_NANOLOCKS
  30654. +
  30655. +// Lock-free(er) dequeuing
  30656. +//#define VCHI_RX_NANOLOCKS
  30657. +
  30658. +#endif /*VCHI_CFG_INTERNAL_H_*/
  30659. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  30660. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  30661. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2015-03-10 17:26:50.554216692 +0100
  30662. @@ -0,0 +1,174 @@
  30663. +/**
  30664. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30665. + *
  30666. + * Redistribution and use in source and binary forms, with or without
  30667. + * modification, are permitted provided that the following conditions
  30668. + * are met:
  30669. + * 1. Redistributions of source code must retain the above copyright
  30670. + * notice, this list of conditions, and the following disclaimer,
  30671. + * without modification.
  30672. + * 2. Redistributions in binary form must reproduce the above copyright
  30673. + * notice, this list of conditions and the following disclaimer in the
  30674. + * documentation and/or other materials provided with the distribution.
  30675. + * 3. The names of the above-listed copyright holders may not be used
  30676. + * to endorse or promote products derived from this software without
  30677. + * specific prior written permission.
  30678. + *
  30679. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30680. + * GNU General Public License ("GPL") version 2, as published by the Free
  30681. + * Software Foundation.
  30682. + *
  30683. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30684. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30685. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30686. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30687. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30688. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30689. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30690. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30691. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30692. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30693. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30694. + */
  30695. +
  30696. +#ifndef VCHI_COMMON_H_
  30697. +#define VCHI_COMMON_H_
  30698. +
  30699. +
  30700. +//flags used when sending messages (must be bitmapped)
  30701. +typedef enum
  30702. +{
  30703. + VCHI_FLAGS_NONE = 0x0,
  30704. + 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)
  30705. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  30706. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  30707. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  30708. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  30709. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  30710. +
  30711. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  30712. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  30713. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  30714. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  30715. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  30716. + VCHI_FLAGS_INTERNAL = 0xFF0000
  30717. +} VCHI_FLAGS_T;
  30718. +
  30719. +// constants for vchi_crc_control()
  30720. +typedef enum {
  30721. + VCHI_CRC_NOTHING = -1,
  30722. + VCHI_CRC_PER_SERVICE = 0,
  30723. + VCHI_CRC_EVERYTHING = 1,
  30724. +} VCHI_CRC_CONTROL_T;
  30725. +
  30726. +//callback reasons when an event occurs on a service
  30727. +typedef enum
  30728. +{
  30729. + VCHI_CALLBACK_REASON_MIN,
  30730. +
  30731. + //This indicates that there is data available
  30732. + //handle is the msg id that was transmitted with the data
  30733. + // When a message is received and there was no FULL message available previously, send callback
  30734. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  30735. + VCHI_CALLBACK_MSG_AVAILABLE,
  30736. + VCHI_CALLBACK_MSG_SENT,
  30737. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  30738. +
  30739. + // This indicates that a transfer from the other side has completed
  30740. + VCHI_CALLBACK_BULK_RECEIVED,
  30741. + //This indicates that data queued up to be sent has now gone
  30742. + //handle is the msg id that was used when sending the data
  30743. + VCHI_CALLBACK_BULK_SENT,
  30744. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  30745. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  30746. +
  30747. + VCHI_CALLBACK_SERVICE_CLOSED,
  30748. +
  30749. + // this side has sent XOFF to peer due to lack of data consumption by service
  30750. + // (suggests the service may need to take some recovery action if it has
  30751. + // been deliberately holding off consuming data)
  30752. + VCHI_CALLBACK_SENT_XOFF,
  30753. + VCHI_CALLBACK_SENT_XON,
  30754. +
  30755. + // indicates that a bulk transfer has finished reading the source buffer
  30756. + VCHI_CALLBACK_BULK_DATA_READ,
  30757. +
  30758. + // power notification events (currently host side only)
  30759. + VCHI_CALLBACK_PEER_OFF,
  30760. + VCHI_CALLBACK_PEER_SUSPENDED,
  30761. + VCHI_CALLBACK_PEER_ON,
  30762. + VCHI_CALLBACK_PEER_RESUMED,
  30763. + VCHI_CALLBACK_FORCED_POWER_OFF,
  30764. +
  30765. +#ifdef USE_VCHIQ_ARM
  30766. + // some extra notifications provided by vchiq_arm
  30767. + VCHI_CALLBACK_SERVICE_OPENED,
  30768. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  30769. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  30770. +#endif
  30771. +
  30772. + VCHI_CALLBACK_REASON_MAX
  30773. +} VCHI_CALLBACK_REASON_T;
  30774. +
  30775. +// service control options
  30776. +typedef enum
  30777. +{
  30778. + VCHI_SERVICE_OPTION_MIN,
  30779. +
  30780. + VCHI_SERVICE_OPTION_TRACE,
  30781. +
  30782. + VCHI_SERVICE_OPTION_MAX
  30783. +} VCHI_SERVICE_OPTION_T;
  30784. +
  30785. +
  30786. +//Callback used by all services / bulk transfers
  30787. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  30788. + VCHI_CALLBACK_REASON_T reason,
  30789. + void *handle ); //for transmitting msg's only
  30790. +
  30791. +
  30792. +
  30793. +/*
  30794. + * Define vector struct for scatter-gather (vector) operations
  30795. + * Vectors can be nested - if a vector element has negative length, then
  30796. + * the data pointer is treated as pointing to another vector array, with
  30797. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  30798. + * you can do this:
  30799. + *
  30800. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  30801. + * {
  30802. + * VCHI_MSG_VECTOR_T nv[2];
  30803. + * nv[0].vec_base = my_header;
  30804. + * nv[0].vec_len = sizeof my_header;
  30805. + * nv[1].vec_base = v;
  30806. + * nv[1].vec_len = -n;
  30807. + * ...
  30808. + *
  30809. + */
  30810. +typedef struct vchi_msg_vector {
  30811. + const void *vec_base;
  30812. + int32_t vec_len;
  30813. +} VCHI_MSG_VECTOR_T;
  30814. +
  30815. +// Opaque type for a connection API
  30816. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  30817. +
  30818. +// Opaque type for a message driver
  30819. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  30820. +
  30821. +
  30822. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  30823. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  30824. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  30825. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  30826. +// is used again after messages for that service are removed/dequeued by any
  30827. +// means other than vchi_msg_iter_... calls on the iterator itself.
  30828. +typedef struct {
  30829. + struct opaque_vchi_service_t *service;
  30830. + void *last;
  30831. + void *next;
  30832. + void *remove;
  30833. +} VCHI_MSG_ITER_T;
  30834. +
  30835. +
  30836. +#endif // VCHI_COMMON_H_
  30837. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  30838. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  30839. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2015-03-09 10:39:30.718893733 +0100
  30840. @@ -0,0 +1,378 @@
  30841. +/**
  30842. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30843. + *
  30844. + * Redistribution and use in source and binary forms, with or without
  30845. + * modification, are permitted provided that the following conditions
  30846. + * are met:
  30847. + * 1. Redistributions of source code must retain the above copyright
  30848. + * notice, this list of conditions, and the following disclaimer,
  30849. + * without modification.
  30850. + * 2. Redistributions in binary form must reproduce the above copyright
  30851. + * notice, this list of conditions and the following disclaimer in the
  30852. + * documentation and/or other materials provided with the distribution.
  30853. + * 3. The names of the above-listed copyright holders may not be used
  30854. + * to endorse or promote products derived from this software without
  30855. + * specific prior written permission.
  30856. + *
  30857. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30858. + * GNU General Public License ("GPL") version 2, as published by the Free
  30859. + * Software Foundation.
  30860. + *
  30861. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30862. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30863. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30864. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30865. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30866. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30867. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30868. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30869. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30870. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30871. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30872. + */
  30873. +
  30874. +#ifndef VCHI_H_
  30875. +#define VCHI_H_
  30876. +
  30877. +#include "interface/vchi/vchi_cfg.h"
  30878. +#include "interface/vchi/vchi_common.h"
  30879. +#include "interface/vchi/connections/connection.h"
  30880. +#include "vchi_mh.h"
  30881. +
  30882. +
  30883. +/******************************************************************************
  30884. + Global defs
  30885. + *****************************************************************************/
  30886. +
  30887. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  30888. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  30889. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  30890. +
  30891. +#ifdef USE_VCHIQ_ARM
  30892. +#define VCHI_BULK_ALIGNED(x) 1
  30893. +#else
  30894. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  30895. +#endif
  30896. +
  30897. +struct vchi_version {
  30898. + uint32_t version;
  30899. + uint32_t version_min;
  30900. +};
  30901. +#define VCHI_VERSION(v_) { v_, v_ }
  30902. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  30903. +
  30904. +typedef enum
  30905. +{
  30906. + VCHI_VEC_POINTER,
  30907. + VCHI_VEC_HANDLE,
  30908. + VCHI_VEC_LIST
  30909. +} VCHI_MSG_VECTOR_TYPE_T;
  30910. +
  30911. +typedef struct vchi_msg_vector_ex {
  30912. +
  30913. + VCHI_MSG_VECTOR_TYPE_T type;
  30914. + union
  30915. + {
  30916. + // a memory handle
  30917. + struct
  30918. + {
  30919. + VCHI_MEM_HANDLE_T handle;
  30920. + uint32_t offset;
  30921. + int32_t vec_len;
  30922. + } handle;
  30923. +
  30924. + // an ordinary data pointer
  30925. + struct
  30926. + {
  30927. + const void *vec_base;
  30928. + int32_t vec_len;
  30929. + } ptr;
  30930. +
  30931. + // a nested vector list
  30932. + struct
  30933. + {
  30934. + struct vchi_msg_vector_ex *vec;
  30935. + uint32_t vec_len;
  30936. + } list;
  30937. + } u;
  30938. +} VCHI_MSG_VECTOR_EX_T;
  30939. +
  30940. +
  30941. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  30942. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  30943. +
  30944. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  30945. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  30946. +
  30947. +// Macros to manipulate 'FOURCC' values
  30948. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  30949. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  30950. +
  30951. +
  30952. +// Opaque service information
  30953. +struct opaque_vchi_service_t;
  30954. +
  30955. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  30956. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  30957. +typedef struct
  30958. +{
  30959. + struct opaque_vchi_service_t *service;
  30960. + void *message;
  30961. +} VCHI_HELD_MSG_T;
  30962. +
  30963. +
  30964. +
  30965. +// structure used to provide the information needed to open a server or a client
  30966. +typedef struct {
  30967. + struct vchi_version version;
  30968. + int32_t service_id;
  30969. + VCHI_CONNECTION_T *connection;
  30970. + uint32_t rx_fifo_size;
  30971. + uint32_t tx_fifo_size;
  30972. + VCHI_CALLBACK_T callback;
  30973. + void *callback_param;
  30974. + /* client intends to receive bulk transfers of
  30975. + odd lengths or into unaligned buffers */
  30976. + int32_t want_unaligned_bulk_rx;
  30977. + /* client intends to transmit bulk transfers of
  30978. + odd lengths or out of unaligned buffers */
  30979. + int32_t want_unaligned_bulk_tx;
  30980. + /* client wants to check CRCs on (bulk) xfers.
  30981. + Only needs to be set at 1 end - will do both directions. */
  30982. + int32_t want_crc;
  30983. +} SERVICE_CREATION_T;
  30984. +
  30985. +// Opaque handle for a VCHI instance
  30986. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  30987. +
  30988. +// Opaque handle for a server or client
  30989. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  30990. +
  30991. +// Service registration & startup
  30992. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  30993. +
  30994. +typedef struct service_info_tag {
  30995. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  30996. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  30997. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  30998. +} SERVICE_INFO_T;
  30999. +
  31000. +/******************************************************************************
  31001. + Global funcs - implementation is specific to which side you are on (local / remote)
  31002. + *****************************************************************************/
  31003. +
  31004. +#ifdef __cplusplus
  31005. +extern "C" {
  31006. +#endif
  31007. +
  31008. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  31009. + const VCHI_MESSAGE_DRIVER_T * low_level);
  31010. +
  31011. +
  31012. +// Routine used to initialise the vchi on both local + remote connections
  31013. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  31014. +
  31015. +extern int32_t vchi_exit( void );
  31016. +
  31017. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  31018. + const uint32_t num_connections,
  31019. + VCHI_INSTANCE_T instance_handle );
  31020. +
  31021. +//When this is called, ensure that all services have no data pending.
  31022. +//Bulk transfers can remain 'queued'
  31023. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  31024. +
  31025. +// Global control over bulk CRC checking
  31026. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  31027. + VCHI_CRC_CONTROL_T control );
  31028. +
  31029. +// helper functions
  31030. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  31031. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  31032. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  31033. +
  31034. +
  31035. +/******************************************************************************
  31036. + Global service API
  31037. + *****************************************************************************/
  31038. +// Routine to create a named service
  31039. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  31040. + SERVICE_CREATION_T *setup,
  31041. + VCHI_SERVICE_HANDLE_T *handle );
  31042. +
  31043. +// Routine to destory a service
  31044. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  31045. +
  31046. +// Routine to open a named service
  31047. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  31048. + SERVICE_CREATION_T *setup,
  31049. + VCHI_SERVICE_HANDLE_T *handle);
  31050. +
  31051. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  31052. + short *peer_version );
  31053. +
  31054. +// Routine to close a named service
  31055. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  31056. +
  31057. +// Routine to increment ref count on a named service
  31058. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  31059. +
  31060. +// Routine to decrement ref count on a named service
  31061. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  31062. +
  31063. +// Routine to set a control option for a named service
  31064. +extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle,
  31065. + VCHI_SERVICE_OPTION_T option,
  31066. + int value);
  31067. +
  31068. +// Routine to send a message across a service
  31069. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  31070. + const void *data,
  31071. + uint32_t data_size,
  31072. + VCHI_FLAGS_T flags,
  31073. + void *msg_handle );
  31074. +
  31075. +// scatter-gather (vector) and send message
  31076. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  31077. + VCHI_MSG_VECTOR_EX_T *vector,
  31078. + uint32_t count,
  31079. + VCHI_FLAGS_T flags,
  31080. + void *msg_handle );
  31081. +
  31082. +// legacy scatter-gather (vector) and send message, only handles pointers
  31083. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  31084. + VCHI_MSG_VECTOR_T *vector,
  31085. + uint32_t count,
  31086. + VCHI_FLAGS_T flags,
  31087. + void *msg_handle );
  31088. +
  31089. +// Routine to receive a msg from a service
  31090. +// Dequeue is equivalent to hold, copy into client buffer, release
  31091. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  31092. + void *data,
  31093. + uint32_t max_data_size_to_read,
  31094. + uint32_t *actual_msg_size,
  31095. + VCHI_FLAGS_T flags );
  31096. +
  31097. +// Routine to look at a message in place.
  31098. +// The message is not dequeued, so a subsequent call to peek or dequeue
  31099. +// will return the same message.
  31100. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  31101. + void **data,
  31102. + uint32_t *msg_size,
  31103. + VCHI_FLAGS_T flags );
  31104. +
  31105. +// Routine to remove a message after it has been read in place with peek
  31106. +// The first message on the queue is dequeued.
  31107. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  31108. +
  31109. +// Routine to look at a message in place.
  31110. +// The message is dequeued, so the caller is left holding it; the descriptor is
  31111. +// filled in and must be released when the user has finished with the message.
  31112. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  31113. + void **data, // } may be NULL, as info can be
  31114. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  31115. + VCHI_FLAGS_T flags,
  31116. + VCHI_HELD_MSG_T *message_descriptor );
  31117. +
  31118. +// Initialise an iterator to look through messages in place
  31119. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  31120. + VCHI_MSG_ITER_T *iter,
  31121. + VCHI_FLAGS_T flags );
  31122. +
  31123. +/******************************************************************************
  31124. + Global service support API - operations on held messages and message iterators
  31125. + *****************************************************************************/
  31126. +
  31127. +// Routine to get the address of a held message
  31128. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  31129. +
  31130. +// Routine to get the size of a held message
  31131. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  31132. +
  31133. +// Routine to get the transmit timestamp as written into the header by the peer
  31134. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  31135. +
  31136. +// Routine to get the reception timestamp, written as we parsed the header
  31137. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  31138. +
  31139. +// Routine to release a held message after it has been processed
  31140. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  31141. +
  31142. +// Indicates whether the iterator has a next message.
  31143. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  31144. +
  31145. +// Return the pointer and length for the next message and advance the iterator.
  31146. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  31147. + void **data,
  31148. + uint32_t *msg_size );
  31149. +
  31150. +// Remove the last message returned by vchi_msg_iter_next.
  31151. +// Can only be called once after each call to vchi_msg_iter_next.
  31152. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  31153. +
  31154. +// Hold the last message returned by vchi_msg_iter_next.
  31155. +// Can only be called once after each call to vchi_msg_iter_next.
  31156. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  31157. + VCHI_HELD_MSG_T *message );
  31158. +
  31159. +// Return information for the next message, and hold it, advancing the iterator.
  31160. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  31161. + void **data, // } may be NULL
  31162. + uint32_t *msg_size, // }
  31163. + VCHI_HELD_MSG_T *message );
  31164. +
  31165. +
  31166. +/******************************************************************************
  31167. + Global bulk API
  31168. + *****************************************************************************/
  31169. +
  31170. +// Routine to prepare interface for a transfer from the other side
  31171. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  31172. + void *data_dst,
  31173. + uint32_t data_size,
  31174. + VCHI_FLAGS_T flags,
  31175. + void *transfer_handle );
  31176. +
  31177. +
  31178. +// Prepare interface for a transfer from the other side into relocatable memory.
  31179. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  31180. + VCHI_MEM_HANDLE_T h_dst,
  31181. + uint32_t offset,
  31182. + uint32_t data_size,
  31183. + const VCHI_FLAGS_T flags,
  31184. + void * const bulk_handle );
  31185. +
  31186. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  31187. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  31188. + const void *data_src,
  31189. + uint32_t data_size,
  31190. + VCHI_FLAGS_T flags,
  31191. + void *transfer_handle );
  31192. +
  31193. +
  31194. +/******************************************************************************
  31195. + Configuration plumbing
  31196. + *****************************************************************************/
  31197. +
  31198. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  31199. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  31200. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  31201. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  31202. +
  31203. +// declare all message drivers here
  31204. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  31205. +
  31206. +#ifdef __cplusplus
  31207. +}
  31208. +#endif
  31209. +
  31210. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  31211. + VCHI_MEM_HANDLE_T h_src,
  31212. + uint32_t offset,
  31213. + uint32_t data_size,
  31214. + VCHI_FLAGS_T flags,
  31215. + void *transfer_handle );
  31216. +#endif /* VCHI_H_ */
  31217. +
  31218. +/****************************** End of file **********************************/
  31219. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  31220. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  31221. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2015-03-09 10:39:30.718893733 +0100
  31222. @@ -0,0 +1,42 @@
  31223. +/**
  31224. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31225. + *
  31226. + * Redistribution and use in source and binary forms, with or without
  31227. + * modification, are permitted provided that the following conditions
  31228. + * are met:
  31229. + * 1. Redistributions of source code must retain the above copyright
  31230. + * notice, this list of conditions, and the following disclaimer,
  31231. + * without modification.
  31232. + * 2. Redistributions in binary form must reproduce the above copyright
  31233. + * notice, this list of conditions and the following disclaimer in the
  31234. + * documentation and/or other materials provided with the distribution.
  31235. + * 3. The names of the above-listed copyright holders may not be used
  31236. + * to endorse or promote products derived from this software without
  31237. + * specific prior written permission.
  31238. + *
  31239. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31240. + * GNU General Public License ("GPL") version 2, as published by the Free
  31241. + * Software Foundation.
  31242. + *
  31243. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31244. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31245. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31246. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31247. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31248. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31249. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31250. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31251. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31252. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31253. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31254. + */
  31255. +
  31256. +#ifndef VCHI_MH_H_
  31257. +#define VCHI_MH_H_
  31258. +
  31259. +#include <linux/types.h>
  31260. +
  31261. +typedef int32_t VCHI_MEM_HANDLE_T;
  31262. +#define VCHI_MEM_HANDLE_INVALID 0
  31263. +
  31264. +#endif
  31265. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  31266. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  31267. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2015-03-09 10:39:30.718893733 +0100
  31268. @@ -0,0 +1,562 @@
  31269. +/**
  31270. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31271. + *
  31272. + * Redistribution and use in source and binary forms, with or without
  31273. + * modification, are permitted provided that the following conditions
  31274. + * are met:
  31275. + * 1. Redistributions of source code must retain the above copyright
  31276. + * notice, this list of conditions, and the following disclaimer,
  31277. + * without modification.
  31278. + * 2. Redistributions in binary form must reproduce the above copyright
  31279. + * notice, this list of conditions and the following disclaimer in the
  31280. + * documentation and/or other materials provided with the distribution.
  31281. + * 3. The names of the above-listed copyright holders may not be used
  31282. + * to endorse or promote products derived from this software without
  31283. + * specific prior written permission.
  31284. + *
  31285. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31286. + * GNU General Public License ("GPL") version 2, as published by the Free
  31287. + * Software Foundation.
  31288. + *
  31289. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31290. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31291. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31292. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31293. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31294. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31295. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31296. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31297. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31298. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31299. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31300. + */
  31301. +
  31302. +#include <linux/kernel.h>
  31303. +#include <linux/types.h>
  31304. +#include <linux/errno.h>
  31305. +#include <linux/interrupt.h>
  31306. +#include <linux/irq.h>
  31307. +#include <linux/pagemap.h>
  31308. +#include <linux/dma-mapping.h>
  31309. +#include <linux/version.h>
  31310. +#include <linux/io.h>
  31311. +#include <linux/uaccess.h>
  31312. +#include <asm/pgtable.h>
  31313. +
  31314. +#include <mach/irqs.h>
  31315. +
  31316. +#include <mach/platform.h>
  31317. +#include <mach/vcio.h>
  31318. +
  31319. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  31320. +
  31321. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  31322. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  31323. +
  31324. +#include "vchiq_arm.h"
  31325. +#include "vchiq_2835.h"
  31326. +#include "vchiq_connected.h"
  31327. +#include "vchiq_killable.h"
  31328. +
  31329. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  31330. +
  31331. +typedef struct vchiq_2835_state_struct {
  31332. + int inited;
  31333. + VCHIQ_ARM_STATE_T arm_state;
  31334. +} VCHIQ_2835_ARM_STATE_T;
  31335. +
  31336. +static char *g_slot_mem;
  31337. +static int g_slot_mem_size;
  31338. +dma_addr_t g_slot_phys;
  31339. +static FRAGMENTS_T *g_fragments_base;
  31340. +static FRAGMENTS_T *g_free_fragments;
  31341. +struct semaphore g_free_fragments_sema;
  31342. +
  31343. +extern int vchiq_arm_log_level;
  31344. +
  31345. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  31346. +
  31347. +static irqreturn_t
  31348. +vchiq_doorbell_irq(int irq, void *dev_id);
  31349. +
  31350. +static int
  31351. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  31352. + struct task_struct *task, PAGELIST_T ** ppagelist);
  31353. +
  31354. +static void
  31355. +free_pagelist(PAGELIST_T *pagelist, int actual);
  31356. +
  31357. +int __init
  31358. +vchiq_platform_init(VCHIQ_STATE_T *state)
  31359. +{
  31360. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  31361. + int frag_mem_size;
  31362. + int err;
  31363. + int i;
  31364. +
  31365. + /* Allocate space for the channels in coherent memory */
  31366. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  31367. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  31368. +
  31369. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  31370. + &g_slot_phys, GFP_ATOMIC);
  31371. +
  31372. + if (!g_slot_mem) {
  31373. + vchiq_log_error(vchiq_arm_log_level,
  31374. + "Unable to allocate channel memory");
  31375. + err = -ENOMEM;
  31376. + goto failed_alloc;
  31377. + }
  31378. +
  31379. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  31380. +
  31381. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  31382. + if (!vchiq_slot_zero) {
  31383. + err = -EINVAL;
  31384. + goto failed_init_slots;
  31385. + }
  31386. +
  31387. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  31388. + (int)g_slot_phys + g_slot_mem_size;
  31389. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  31390. + MAX_FRAGMENTS;
  31391. +
  31392. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  31393. + g_slot_mem_size += frag_mem_size;
  31394. +
  31395. + g_free_fragments = g_fragments_base;
  31396. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  31397. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  31398. + &g_fragments_base[i + 1];
  31399. + }
  31400. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  31401. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  31402. +
  31403. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  31404. + VCHIQ_SUCCESS) {
  31405. + err = -EINVAL;
  31406. + goto failed_vchiq_init;
  31407. + }
  31408. +
  31409. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  31410. + IRQF_IRQPOLL, "VCHIQ doorbell",
  31411. + state);
  31412. + if (err < 0) {
  31413. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  31414. + "irq=%d err=%d", __func__,
  31415. + VCHIQ_DOORBELL_IRQ, err);
  31416. + goto failed_request_irq;
  31417. + }
  31418. +
  31419. + /* Send the base address of the slots to VideoCore */
  31420. +
  31421. + dsb(); /* Ensure all writes have completed */
  31422. +
  31423. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  31424. +
  31425. + vchiq_log_info(vchiq_arm_log_level,
  31426. + "vchiq_init - done (slots %x, phys %x)",
  31427. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  31428. +
  31429. + vchiq_call_connected_callbacks();
  31430. +
  31431. + return 0;
  31432. +
  31433. +failed_request_irq:
  31434. +failed_vchiq_init:
  31435. +failed_init_slots:
  31436. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  31437. +
  31438. +failed_alloc:
  31439. + return err;
  31440. +}
  31441. +
  31442. +void __exit
  31443. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  31444. +{
  31445. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  31446. + dma_free_coherent(NULL, g_slot_mem_size,
  31447. + g_slot_mem, g_slot_phys);
  31448. +}
  31449. +
  31450. +
  31451. +VCHIQ_STATUS_T
  31452. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  31453. +{
  31454. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  31455. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  31456. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  31457. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  31458. + if(status != VCHIQ_SUCCESS)
  31459. + {
  31460. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  31461. + }
  31462. + return status;
  31463. +}
  31464. +
  31465. +VCHIQ_ARM_STATE_T*
  31466. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  31467. +{
  31468. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  31469. + {
  31470. + BUG();
  31471. + }
  31472. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  31473. +}
  31474. +
  31475. +void
  31476. +remote_event_signal(REMOTE_EVENT_T *event)
  31477. +{
  31478. + wmb();
  31479. +
  31480. + event->fired = 1;
  31481. +
  31482. + dsb(); /* data barrier operation */
  31483. +
  31484. + if (event->armed) {
  31485. + /* trigger vc interrupt */
  31486. +
  31487. + writel(0, __io_address(ARM_0_BELL2));
  31488. + }
  31489. +}
  31490. +
  31491. +int
  31492. +vchiq_copy_from_user(void *dst, const void *src, int size)
  31493. +{
  31494. + if ((uint32_t)src < TASK_SIZE) {
  31495. + return copy_from_user(dst, src, size);
  31496. + } else {
  31497. + memcpy(dst, src, size);
  31498. + return 0;
  31499. + }
  31500. +}
  31501. +
  31502. +VCHIQ_STATUS_T
  31503. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  31504. + void *offset, int size, int dir)
  31505. +{
  31506. + PAGELIST_T *pagelist;
  31507. + int ret;
  31508. +
  31509. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  31510. +
  31511. + ret = create_pagelist((char __user *)offset, size,
  31512. + (dir == VCHIQ_BULK_RECEIVE)
  31513. + ? PAGELIST_READ
  31514. + : PAGELIST_WRITE,
  31515. + current,
  31516. + &pagelist);
  31517. + if (ret != 0)
  31518. + return VCHIQ_ERROR;
  31519. +
  31520. + bulk->handle = memhandle;
  31521. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  31522. +
  31523. + /* Store the pagelist address in remote_data, which isn't used by the
  31524. + slave. */
  31525. + bulk->remote_data = pagelist;
  31526. +
  31527. + return VCHIQ_SUCCESS;
  31528. +}
  31529. +
  31530. +void
  31531. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  31532. +{
  31533. + if (bulk && bulk->remote_data && bulk->actual)
  31534. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  31535. +}
  31536. +
  31537. +void
  31538. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  31539. +{
  31540. + /*
  31541. + * This should only be called on the master (VideoCore) side, but
  31542. + * provide an implementation to avoid the need for ifdefery.
  31543. + */
  31544. + BUG();
  31545. +}
  31546. +
  31547. +void
  31548. +vchiq_dump_platform_state(void *dump_context)
  31549. +{
  31550. + char buf[80];
  31551. + int len;
  31552. + len = snprintf(buf, sizeof(buf),
  31553. + " Platform: 2835 (VC master)");
  31554. + vchiq_dump(dump_context, buf, len + 1);
  31555. +}
  31556. +
  31557. +VCHIQ_STATUS_T
  31558. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  31559. +{
  31560. + return VCHIQ_ERROR;
  31561. +}
  31562. +
  31563. +VCHIQ_STATUS_T
  31564. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  31565. +{
  31566. + return VCHIQ_SUCCESS;
  31567. +}
  31568. +
  31569. +void
  31570. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  31571. +{
  31572. +}
  31573. +
  31574. +void
  31575. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  31576. +{
  31577. +}
  31578. +
  31579. +int
  31580. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  31581. +{
  31582. + return 1; // autosuspend not supported - videocore always wanted
  31583. +}
  31584. +
  31585. +int
  31586. +vchiq_platform_use_suspend_timer(void)
  31587. +{
  31588. + return 0;
  31589. +}
  31590. +void
  31591. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  31592. +{
  31593. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  31594. +}
  31595. +void
  31596. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  31597. +{
  31598. + (void)state;
  31599. +}
  31600. +/*
  31601. + * Local functions
  31602. + */
  31603. +
  31604. +static irqreturn_t
  31605. +vchiq_doorbell_irq(int irq, void *dev_id)
  31606. +{
  31607. + VCHIQ_STATE_T *state = dev_id;
  31608. + irqreturn_t ret = IRQ_NONE;
  31609. + unsigned int status;
  31610. +
  31611. + /* Read (and clear) the doorbell */
  31612. + status = readl(__io_address(ARM_0_BELL0));
  31613. +
  31614. + if (status & 0x4) { /* Was the doorbell rung? */
  31615. + remote_event_pollall(state);
  31616. + ret = IRQ_HANDLED;
  31617. + }
  31618. +
  31619. + return ret;
  31620. +}
  31621. +
  31622. +/* There is a potential problem with partial cache lines (pages?)
  31623. +** at the ends of the block when reading. If the CPU accessed anything in
  31624. +** the same line (page?) then it may have pulled old data into the cache,
  31625. +** obscuring the new data underneath. We can solve this by transferring the
  31626. +** partial cache lines separately, and allowing the ARM to copy into the
  31627. +** cached area.
  31628. +
  31629. +** N.B. This implementation plays slightly fast and loose with the Linux
  31630. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  31631. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  31632. +** from increased speed as a result.
  31633. +*/
  31634. +
  31635. +static int
  31636. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  31637. + struct task_struct *task, PAGELIST_T ** ppagelist)
  31638. +{
  31639. + PAGELIST_T *pagelist;
  31640. + struct page **pages;
  31641. + struct page *page;
  31642. + unsigned long *addrs;
  31643. + unsigned int num_pages, offset, i;
  31644. + char *addr, *base_addr, *next_addr;
  31645. + int run, addridx, actual_pages;
  31646. + unsigned long *need_release;
  31647. +
  31648. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  31649. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  31650. +
  31651. + *ppagelist = NULL;
  31652. +
  31653. + /* Allocate enough storage to hold the page pointers and the page
  31654. + ** list
  31655. + */
  31656. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  31657. + (num_pages * sizeof(unsigned long)) +
  31658. + sizeof(unsigned long) +
  31659. + (num_pages * sizeof(pages[0])),
  31660. + GFP_KERNEL);
  31661. +
  31662. + vchiq_log_trace(vchiq_arm_log_level,
  31663. + "create_pagelist - %x", (unsigned int)pagelist);
  31664. + if (!pagelist)
  31665. + return -ENOMEM;
  31666. +
  31667. + addrs = pagelist->addrs;
  31668. + need_release = (unsigned long *)(addrs + num_pages);
  31669. + pages = (struct page **)(addrs + num_pages + 1);
  31670. +
  31671. + if (is_vmalloc_addr(buf)) {
  31672. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  31673. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  31674. + }
  31675. + *need_release = 0; /* do not try and release vmalloc pages */
  31676. + } else {
  31677. + down_read(&task->mm->mmap_sem);
  31678. + actual_pages = get_user_pages(task, task->mm,
  31679. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  31680. + num_pages,
  31681. + (type == PAGELIST_READ) /*Write */ ,
  31682. + 0 /*Force */ ,
  31683. + pages,
  31684. + NULL /*vmas */);
  31685. + up_read(&task->mm->mmap_sem);
  31686. +
  31687. + if (actual_pages != num_pages) {
  31688. + vchiq_log_info(vchiq_arm_log_level,
  31689. + "create_pagelist - only %d/%d pages locked",
  31690. + actual_pages,
  31691. + num_pages);
  31692. +
  31693. + /* This is probably due to the process being killed */
  31694. + while (actual_pages > 0)
  31695. + {
  31696. + actual_pages--;
  31697. + page_cache_release(pages[actual_pages]);
  31698. + }
  31699. + kfree(pagelist);
  31700. + if (actual_pages == 0)
  31701. + actual_pages = -ENOMEM;
  31702. + return actual_pages;
  31703. + }
  31704. + *need_release = 1; /* release user pages */
  31705. + }
  31706. +
  31707. + pagelist->length = count;
  31708. + pagelist->type = type;
  31709. + pagelist->offset = offset;
  31710. +
  31711. + /* Group the pages into runs of contiguous pages */
  31712. +
  31713. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  31714. + next_addr = base_addr + PAGE_SIZE;
  31715. + addridx = 0;
  31716. + run = 0;
  31717. +
  31718. + for (i = 1; i < num_pages; i++) {
  31719. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  31720. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  31721. + next_addr += PAGE_SIZE;
  31722. + run++;
  31723. + } else {
  31724. + addrs[addridx] = (unsigned long)base_addr + run;
  31725. + addridx++;
  31726. + base_addr = addr;
  31727. + next_addr = addr + PAGE_SIZE;
  31728. + run = 0;
  31729. + }
  31730. + }
  31731. +
  31732. + addrs[addridx] = (unsigned long)base_addr + run;
  31733. + addridx++;
  31734. +
  31735. + /* Partial cache lines (fragments) require special measures */
  31736. + if ((type == PAGELIST_READ) &&
  31737. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  31738. + ((pagelist->offset + pagelist->length) &
  31739. + (CACHE_LINE_SIZE - 1)))) {
  31740. + FRAGMENTS_T *fragments;
  31741. +
  31742. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  31743. + kfree(pagelist);
  31744. + return -EINTR;
  31745. + }
  31746. +
  31747. + WARN_ON(g_free_fragments == NULL);
  31748. +
  31749. + down(&g_free_fragments_mutex);
  31750. + fragments = (FRAGMENTS_T *) g_free_fragments;
  31751. + WARN_ON(fragments == NULL);
  31752. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  31753. + up(&g_free_fragments_mutex);
  31754. + pagelist->type =
  31755. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  31756. + g_fragments_base);
  31757. + }
  31758. +
  31759. + for (page = virt_to_page(pagelist);
  31760. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  31761. + flush_dcache_page(page);
  31762. + }
  31763. +
  31764. + *ppagelist = pagelist;
  31765. +
  31766. + return 0;
  31767. +}
  31768. +
  31769. +static void
  31770. +free_pagelist(PAGELIST_T *pagelist, int actual)
  31771. +{
  31772. + unsigned long *need_release;
  31773. + struct page **pages;
  31774. + unsigned int num_pages, i;
  31775. +
  31776. + vchiq_log_trace(vchiq_arm_log_level,
  31777. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  31778. +
  31779. + num_pages =
  31780. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  31781. + PAGE_SIZE;
  31782. +
  31783. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  31784. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  31785. +
  31786. + /* Deal with any partial cache lines (fragments) */
  31787. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  31788. + FRAGMENTS_T *fragments = g_fragments_base +
  31789. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  31790. + int head_bytes, tail_bytes;
  31791. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  31792. + (CACHE_LINE_SIZE - 1);
  31793. + tail_bytes = (pagelist->offset + actual) &
  31794. + (CACHE_LINE_SIZE - 1);
  31795. +
  31796. + if ((actual >= 0) && (head_bytes != 0)) {
  31797. + if (head_bytes > actual)
  31798. + head_bytes = actual;
  31799. +
  31800. + memcpy((char *)page_address(pages[0]) +
  31801. + pagelist->offset,
  31802. + fragments->headbuf,
  31803. + head_bytes);
  31804. + }
  31805. + if ((actual >= 0) && (head_bytes < actual) &&
  31806. + (tail_bytes != 0)) {
  31807. + memcpy((char *)page_address(pages[num_pages - 1]) +
  31808. + ((pagelist->offset + actual) &
  31809. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  31810. + fragments->tailbuf, tail_bytes);
  31811. + }
  31812. +
  31813. + down(&g_free_fragments_mutex);
  31814. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  31815. + g_free_fragments = fragments;
  31816. + up(&g_free_fragments_mutex);
  31817. + up(&g_free_fragments_sema);
  31818. + }
  31819. +
  31820. + if (*need_release) {
  31821. + for (i = 0; i < num_pages; i++) {
  31822. + if (pagelist->type != PAGELIST_WRITE)
  31823. + set_page_dirty(pages[i]);
  31824. +
  31825. + page_cache_release(pages[i]);
  31826. + }
  31827. + }
  31828. +
  31829. + kfree(pagelist);
  31830. +}
  31831. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  31832. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  31833. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2015-03-09 10:39:30.718893733 +0100
  31834. @@ -0,0 +1,42 @@
  31835. +/**
  31836. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31837. + *
  31838. + * Redistribution and use in source and binary forms, with or without
  31839. + * modification, are permitted provided that the following conditions
  31840. + * are met:
  31841. + * 1. Redistributions of source code must retain the above copyright
  31842. + * notice, this list of conditions, and the following disclaimer,
  31843. + * without modification.
  31844. + * 2. Redistributions in binary form must reproduce the above copyright
  31845. + * notice, this list of conditions and the following disclaimer in the
  31846. + * documentation and/or other materials provided with the distribution.
  31847. + * 3. The names of the above-listed copyright holders may not be used
  31848. + * to endorse or promote products derived from this software without
  31849. + * specific prior written permission.
  31850. + *
  31851. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31852. + * GNU General Public License ("GPL") version 2, as published by the Free
  31853. + * Software Foundation.
  31854. + *
  31855. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31856. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31857. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31858. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31859. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31860. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31861. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31862. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31863. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31864. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31865. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31866. + */
  31867. +
  31868. +#ifndef VCHIQ_2835_H
  31869. +#define VCHIQ_2835_H
  31870. +
  31871. +#include "vchiq_pagelist.h"
  31872. +
  31873. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  31874. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  31875. +
  31876. +#endif /* VCHIQ_2835_H */
  31877. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  31878. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  31879. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2015-03-10 17:26:50.554216692 +0100
  31880. @@ -0,0 +1,2884 @@
  31881. +/**
  31882. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  31883. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  31884. + *
  31885. + * Redistribution and use in source and binary forms, with or without
  31886. + * modification, are permitted provided that the following conditions
  31887. + * are met:
  31888. + * 1. Redistributions of source code must retain the above copyright
  31889. + * notice, this list of conditions, and the following disclaimer,
  31890. + * without modification.
  31891. + * 2. Redistributions in binary form must reproduce the above copyright
  31892. + * notice, this list of conditions and the following disclaimer in the
  31893. + * documentation and/or other materials provided with the distribution.
  31894. + * 3. The names of the above-listed copyright holders may not be used
  31895. + * to endorse or promote products derived from this software without
  31896. + * specific prior written permission.
  31897. + *
  31898. + * ALTERNATIVELY, this software may be distributed under the terms of the
  31899. + * GNU General Public License ("GPL") version 2, as published by the Free
  31900. + * Software Foundation.
  31901. + *
  31902. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  31903. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  31904. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31905. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31906. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31907. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31908. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31909. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31910. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31911. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31912. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31913. + */
  31914. +
  31915. +#include <linux/kernel.h>
  31916. +#include <linux/module.h>
  31917. +#include <linux/types.h>
  31918. +#include <linux/errno.h>
  31919. +#include <linux/cdev.h>
  31920. +#include <linux/fs.h>
  31921. +#include <linux/device.h>
  31922. +#include <linux/mm.h>
  31923. +#include <linux/highmem.h>
  31924. +#include <linux/pagemap.h>
  31925. +#include <linux/bug.h>
  31926. +#include <linux/semaphore.h>
  31927. +#include <linux/list.h>
  31928. +
  31929. +#include "vchiq_core.h"
  31930. +#include "vchiq_ioctl.h"
  31931. +#include "vchiq_arm.h"
  31932. +#include "vchiq_killable.h"
  31933. +#include "vchiq_debugfs.h"
  31934. +
  31935. +#define DEVICE_NAME "vchiq"
  31936. +
  31937. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  31938. +#undef MODULE_PARAM_PREFIX
  31939. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  31940. +
  31941. +#define VCHIQ_MINOR 0
  31942. +
  31943. +/* Some per-instance constants */
  31944. +#define MAX_COMPLETIONS 16
  31945. +#define MAX_SERVICES 64
  31946. +#define MAX_ELEMENTS 8
  31947. +#define MSG_QUEUE_SIZE 64
  31948. +
  31949. +#define KEEPALIVE_VER 1
  31950. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  31951. +
  31952. +/* Run time control of log level, based on KERN_XXX level. */
  31953. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  31954. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  31955. +
  31956. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  31957. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  31958. +
  31959. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  31960. +static const char *const suspend_state_names[] = {
  31961. + "VC_SUSPEND_FORCE_CANCELED",
  31962. + "VC_SUSPEND_REJECTED",
  31963. + "VC_SUSPEND_FAILED",
  31964. + "VC_SUSPEND_IDLE",
  31965. + "VC_SUSPEND_REQUESTED",
  31966. + "VC_SUSPEND_IN_PROGRESS",
  31967. + "VC_SUSPEND_SUSPENDED"
  31968. +};
  31969. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  31970. +static const char *const resume_state_names[] = {
  31971. + "VC_RESUME_FAILED",
  31972. + "VC_RESUME_IDLE",
  31973. + "VC_RESUME_REQUESTED",
  31974. + "VC_RESUME_IN_PROGRESS",
  31975. + "VC_RESUME_RESUMED"
  31976. +};
  31977. +/* The number of times we allow force suspend to timeout before actually
  31978. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  31979. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  31980. +*/
  31981. +#define FORCE_SUSPEND_FAIL_MAX 8
  31982. +
  31983. +/* The time in ms allowed for videocore to go idle when force suspend has been
  31984. + * requested */
  31985. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  31986. +
  31987. +
  31988. +static void suspend_timer_callback(unsigned long context);
  31989. +
  31990. +
  31991. +typedef struct user_service_struct {
  31992. + VCHIQ_SERVICE_T *service;
  31993. + void *userdata;
  31994. + VCHIQ_INSTANCE_T instance;
  31995. + char is_vchi;
  31996. + char dequeue_pending;
  31997. + char close_pending;
  31998. + int message_available_pos;
  31999. + int msg_insert;
  32000. + int msg_remove;
  32001. + struct semaphore insert_event;
  32002. + struct semaphore remove_event;
  32003. + struct semaphore close_event;
  32004. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  32005. +} USER_SERVICE_T;
  32006. +
  32007. +struct bulk_waiter_node {
  32008. + struct bulk_waiter bulk_waiter;
  32009. + int pid;
  32010. + struct list_head list;
  32011. +};
  32012. +
  32013. +struct vchiq_instance_struct {
  32014. + VCHIQ_STATE_T *state;
  32015. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  32016. + int completion_insert;
  32017. + int completion_remove;
  32018. + struct semaphore insert_event;
  32019. + struct semaphore remove_event;
  32020. + struct mutex completion_mutex;
  32021. +
  32022. + int connected;
  32023. + int closing;
  32024. + int pid;
  32025. + int mark;
  32026. + int use_close_delivered;
  32027. + int trace;
  32028. +
  32029. + struct list_head bulk_waiter_list;
  32030. + struct mutex bulk_waiter_list_mutex;
  32031. +
  32032. + VCHIQ_DEBUGFS_NODE_T debugfs_node;
  32033. +};
  32034. +
  32035. +typedef struct dump_context_struct {
  32036. + char __user *buf;
  32037. + size_t actual;
  32038. + size_t space;
  32039. + loff_t offset;
  32040. +} DUMP_CONTEXT_T;
  32041. +
  32042. +static struct cdev vchiq_cdev;
  32043. +static dev_t vchiq_devid;
  32044. +static VCHIQ_STATE_T g_state;
  32045. +static struct class *vchiq_class;
  32046. +static struct device *vchiq_dev;
  32047. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  32048. +
  32049. +static const char *const ioctl_names[] = {
  32050. + "CONNECT",
  32051. + "SHUTDOWN",
  32052. + "CREATE_SERVICE",
  32053. + "REMOVE_SERVICE",
  32054. + "QUEUE_MESSAGE",
  32055. + "QUEUE_BULK_TRANSMIT",
  32056. + "QUEUE_BULK_RECEIVE",
  32057. + "AWAIT_COMPLETION",
  32058. + "DEQUEUE_MESSAGE",
  32059. + "GET_CLIENT_ID",
  32060. + "GET_CONFIG",
  32061. + "CLOSE_SERVICE",
  32062. + "USE_SERVICE",
  32063. + "RELEASE_SERVICE",
  32064. + "SET_SERVICE_OPTION",
  32065. + "DUMP_PHYS_MEM",
  32066. + "LIB_VERSION",
  32067. + "CLOSE_DELIVERED"
  32068. +};
  32069. +
  32070. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  32071. + (VCHIQ_IOC_MAX + 1));
  32072. +
  32073. +static void
  32074. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  32075. +
  32076. +/****************************************************************************
  32077. +*
  32078. +* add_completion
  32079. +*
  32080. +***************************************************************************/
  32081. +
  32082. +static VCHIQ_STATUS_T
  32083. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  32084. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  32085. + void *bulk_userdata)
  32086. +{
  32087. + VCHIQ_COMPLETION_DATA_T *completion;
  32088. + DEBUG_INITIALISE(g_state.local)
  32089. +
  32090. + while (instance->completion_insert ==
  32091. + (instance->completion_remove + MAX_COMPLETIONS)) {
  32092. + /* Out of space - wait for the client */
  32093. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32094. + vchiq_log_trace(vchiq_arm_log_level,
  32095. + "add_completion - completion queue full");
  32096. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  32097. + if (down_interruptible(&instance->remove_event) != 0) {
  32098. + vchiq_log_info(vchiq_arm_log_level,
  32099. + "service_callback interrupted");
  32100. + return VCHIQ_RETRY;
  32101. + } else if (instance->closing) {
  32102. + vchiq_log_info(vchiq_arm_log_level,
  32103. + "service_callback closing");
  32104. + return VCHIQ_ERROR;
  32105. + }
  32106. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32107. + }
  32108. +
  32109. + completion =
  32110. + &instance->completions[instance->completion_insert &
  32111. + (MAX_COMPLETIONS - 1)];
  32112. +
  32113. + completion->header = header;
  32114. + completion->reason = reason;
  32115. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  32116. + completion->service_userdata = user_service->service;
  32117. + completion->bulk_userdata = bulk_userdata;
  32118. +
  32119. + if (reason == VCHIQ_SERVICE_CLOSED) {
  32120. + /* Take an extra reference, to be held until
  32121. + this CLOSED notification is delivered. */
  32122. + lock_service(user_service->service);
  32123. + if (instance->use_close_delivered)
  32124. + user_service->close_pending = 1;
  32125. + }
  32126. +
  32127. + /* A write barrier is needed here to ensure that the entire completion
  32128. + record is written out before the insert point. */
  32129. + wmb();
  32130. +
  32131. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  32132. + user_service->message_available_pos =
  32133. + instance->completion_insert;
  32134. + instance->completion_insert++;
  32135. +
  32136. + up(&instance->insert_event);
  32137. +
  32138. + return VCHIQ_SUCCESS;
  32139. +}
  32140. +
  32141. +/****************************************************************************
  32142. +*
  32143. +* service_callback
  32144. +*
  32145. +***************************************************************************/
  32146. +
  32147. +static VCHIQ_STATUS_T
  32148. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  32149. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  32150. +{
  32151. + /* How do we ensure the callback goes to the right client?
  32152. + ** The service_user data points to a USER_SERVICE_T record containing
  32153. + ** the original callback and the user state structure, which contains a
  32154. + ** circular buffer for completion records.
  32155. + */
  32156. + USER_SERVICE_T *user_service;
  32157. + VCHIQ_SERVICE_T *service;
  32158. + VCHIQ_INSTANCE_T instance;
  32159. + DEBUG_INITIALISE(g_state.local)
  32160. +
  32161. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32162. +
  32163. + service = handle_to_service(handle);
  32164. + BUG_ON(!service);
  32165. + user_service = (USER_SERVICE_T *)service->base.userdata;
  32166. + instance = user_service->instance;
  32167. +
  32168. + if (!instance || instance->closing)
  32169. + return VCHIQ_SUCCESS;
  32170. +
  32171. + vchiq_log_trace(vchiq_arm_log_level,
  32172. + "service_callback - service %lx(%d,%p), reason %d, header %lx, "
  32173. + "instance %lx, bulk_userdata %lx",
  32174. + (unsigned long)user_service,
  32175. + service->localport, user_service->userdata,
  32176. + reason, (unsigned long)header,
  32177. + (unsigned long)instance, (unsigned long)bulk_userdata);
  32178. +
  32179. + if (header && user_service->is_vchi) {
  32180. + spin_lock(&msg_queue_spinlock);
  32181. + while (user_service->msg_insert ==
  32182. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  32183. + spin_unlock(&msg_queue_spinlock);
  32184. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32185. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  32186. + vchiq_log_trace(vchiq_arm_log_level,
  32187. + "service_callback - msg queue full");
  32188. + /* If there is no MESSAGE_AVAILABLE in the completion
  32189. + ** queue, add one
  32190. + */
  32191. + if ((user_service->message_available_pos -
  32192. + instance->completion_remove) < 0) {
  32193. + VCHIQ_STATUS_T status;
  32194. + vchiq_log_info(vchiq_arm_log_level,
  32195. + "Inserting extra MESSAGE_AVAILABLE");
  32196. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32197. + status = add_completion(instance, reason,
  32198. + NULL, user_service, bulk_userdata);
  32199. + if (status != VCHIQ_SUCCESS) {
  32200. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32201. + return status;
  32202. + }
  32203. + }
  32204. +
  32205. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32206. + if (down_interruptible(&user_service->remove_event)
  32207. + != 0) {
  32208. + vchiq_log_info(vchiq_arm_log_level,
  32209. + "service_callback interrupted");
  32210. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32211. + return VCHIQ_RETRY;
  32212. + } else if (instance->closing) {
  32213. + vchiq_log_info(vchiq_arm_log_level,
  32214. + "service_callback closing");
  32215. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32216. + return VCHIQ_ERROR;
  32217. + }
  32218. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32219. + spin_lock(&msg_queue_spinlock);
  32220. + }
  32221. +
  32222. + user_service->msg_queue[user_service->msg_insert &
  32223. + (MSG_QUEUE_SIZE - 1)] = header;
  32224. + user_service->msg_insert++;
  32225. + spin_unlock(&msg_queue_spinlock);
  32226. +
  32227. + up(&user_service->insert_event);
  32228. +
  32229. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  32230. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  32231. + ** bypass the completion queue.
  32232. + */
  32233. + if (((user_service->message_available_pos -
  32234. + instance->completion_remove) >= 0) ||
  32235. + user_service->dequeue_pending) {
  32236. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32237. + user_service->dequeue_pending = 0;
  32238. + return VCHIQ_SUCCESS;
  32239. + }
  32240. +
  32241. + header = NULL;
  32242. + }
  32243. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  32244. +
  32245. + return add_completion(instance, reason, header, user_service,
  32246. + bulk_userdata);
  32247. +}
  32248. +
  32249. +/****************************************************************************
  32250. +*
  32251. +* user_service_free
  32252. +*
  32253. +***************************************************************************/
  32254. +static void
  32255. +user_service_free(void *userdata)
  32256. +{
  32257. + kfree(userdata);
  32258. +}
  32259. +
  32260. +/****************************************************************************
  32261. +*
  32262. +* close_delivered
  32263. +*
  32264. +***************************************************************************/
  32265. +static void close_delivered(USER_SERVICE_T *user_service)
  32266. +{
  32267. + vchiq_log_info(vchiq_arm_log_level,
  32268. + "close_delivered(handle=%x)",
  32269. + user_service->service->handle);
  32270. +
  32271. + if (user_service->close_pending) {
  32272. + /* Allow the underlying service to be culled */
  32273. + unlock_service(user_service->service);
  32274. +
  32275. + /* Wake the user-thread blocked in close_ or remove_service */
  32276. + up(&user_service->close_event);
  32277. +
  32278. + user_service->close_pending = 0;
  32279. + }
  32280. +}
  32281. +
  32282. +/****************************************************************************
  32283. +*
  32284. +* vchiq_ioctl
  32285. +*
  32286. +***************************************************************************/
  32287. +static long
  32288. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  32289. +{
  32290. + VCHIQ_INSTANCE_T instance = file->private_data;
  32291. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  32292. + VCHIQ_SERVICE_T *service = NULL;
  32293. + long ret = 0;
  32294. + int i, rc;
  32295. + DEBUG_INITIALISE(g_state.local)
  32296. +
  32297. + vchiq_log_trace(vchiq_arm_log_level,
  32298. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  32299. + (unsigned int)instance,
  32300. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  32301. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  32302. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  32303. +
  32304. + switch (cmd) {
  32305. + case VCHIQ_IOC_SHUTDOWN:
  32306. + if (!instance->connected)
  32307. + break;
  32308. +
  32309. + /* Remove all services */
  32310. + i = 0;
  32311. + while ((service = next_service_by_instance(instance->state,
  32312. + instance, &i)) != NULL) {
  32313. + status = vchiq_remove_service(service->handle);
  32314. + unlock_service(service);
  32315. + if (status != VCHIQ_SUCCESS)
  32316. + break;
  32317. + }
  32318. + service = NULL;
  32319. +
  32320. + if (status == VCHIQ_SUCCESS) {
  32321. + /* Wake the completion thread and ask it to exit */
  32322. + instance->closing = 1;
  32323. + up(&instance->insert_event);
  32324. + }
  32325. +
  32326. + break;
  32327. +
  32328. + case VCHIQ_IOC_CONNECT:
  32329. + if (instance->connected) {
  32330. + ret = -EINVAL;
  32331. + break;
  32332. + }
  32333. + rc = mutex_lock_interruptible(&instance->state->mutex);
  32334. + if (rc != 0) {
  32335. + vchiq_log_error(vchiq_arm_log_level,
  32336. + "vchiq: connect: could not lock mutex for "
  32337. + "state %d: %d",
  32338. + instance->state->id, rc);
  32339. + ret = -EINTR;
  32340. + break;
  32341. + }
  32342. + status = vchiq_connect_internal(instance->state, instance);
  32343. + mutex_unlock(&instance->state->mutex);
  32344. +
  32345. + if (status == VCHIQ_SUCCESS)
  32346. + instance->connected = 1;
  32347. + else
  32348. + vchiq_log_error(vchiq_arm_log_level,
  32349. + "vchiq: could not connect: %d", status);
  32350. + break;
  32351. +
  32352. + case VCHIQ_IOC_CREATE_SERVICE: {
  32353. + VCHIQ_CREATE_SERVICE_T args;
  32354. + USER_SERVICE_T *user_service = NULL;
  32355. + void *userdata;
  32356. + int srvstate;
  32357. +
  32358. + if (copy_from_user
  32359. + (&args, (const void __user *)arg,
  32360. + sizeof(args)) != 0) {
  32361. + ret = -EFAULT;
  32362. + break;
  32363. + }
  32364. +
  32365. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  32366. + if (!user_service) {
  32367. + ret = -ENOMEM;
  32368. + break;
  32369. + }
  32370. +
  32371. + if (args.is_open) {
  32372. + if (!instance->connected) {
  32373. + ret = -ENOTCONN;
  32374. + kfree(user_service);
  32375. + break;
  32376. + }
  32377. + srvstate = VCHIQ_SRVSTATE_OPENING;
  32378. + } else {
  32379. + srvstate =
  32380. + instance->connected ?
  32381. + VCHIQ_SRVSTATE_LISTENING :
  32382. + VCHIQ_SRVSTATE_HIDDEN;
  32383. + }
  32384. +
  32385. + userdata = args.params.userdata;
  32386. + args.params.callback = service_callback;
  32387. + args.params.userdata = user_service;
  32388. + service = vchiq_add_service_internal(
  32389. + instance->state,
  32390. + &args.params, srvstate,
  32391. + instance, user_service_free);
  32392. +
  32393. + if (service != NULL) {
  32394. + user_service->service = service;
  32395. + user_service->userdata = userdata;
  32396. + user_service->instance = instance;
  32397. + user_service->is_vchi = (args.is_vchi != 0);
  32398. + user_service->dequeue_pending = 0;
  32399. + user_service->close_pending = 0;
  32400. + user_service->message_available_pos =
  32401. + instance->completion_remove - 1;
  32402. + user_service->msg_insert = 0;
  32403. + user_service->msg_remove = 0;
  32404. + sema_init(&user_service->insert_event, 0);
  32405. + sema_init(&user_service->remove_event, 0);
  32406. + sema_init(&user_service->close_event, 0);
  32407. +
  32408. + if (args.is_open) {
  32409. + status = vchiq_open_service_internal
  32410. + (service, instance->pid);
  32411. + if (status != VCHIQ_SUCCESS) {
  32412. + vchiq_remove_service(service->handle);
  32413. + service = NULL;
  32414. + ret = (status == VCHIQ_RETRY) ?
  32415. + -EINTR : -EIO;
  32416. + break;
  32417. + }
  32418. + }
  32419. +
  32420. + if (copy_to_user((void __user *)
  32421. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  32422. + arg)->handle),
  32423. + (const void *)&service->handle,
  32424. + sizeof(service->handle)) != 0) {
  32425. + ret = -EFAULT;
  32426. + vchiq_remove_service(service->handle);
  32427. + }
  32428. +
  32429. + service = NULL;
  32430. + } else {
  32431. + ret = -EEXIST;
  32432. + kfree(user_service);
  32433. + }
  32434. + } break;
  32435. +
  32436. + case VCHIQ_IOC_CLOSE_SERVICE: {
  32437. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  32438. +
  32439. + service = find_service_for_instance(instance, handle);
  32440. + if (service != NULL) {
  32441. + USER_SERVICE_T *user_service =
  32442. + (USER_SERVICE_T *)service->base.userdata;
  32443. + /* close_pending is false on first entry, and when the
  32444. + wait in vchiq_close_service has been interrupted. */
  32445. + if (!user_service->close_pending) {
  32446. + status = vchiq_close_service(service->handle);
  32447. + if (status != VCHIQ_SUCCESS)
  32448. + break;
  32449. + }
  32450. +
  32451. + /* close_pending is true once the underlying service
  32452. + has been closed until the client library calls the
  32453. + CLOSE_DELIVERED ioctl, signalling close_event. */
  32454. + if (user_service->close_pending &&
  32455. + down_interruptible(&user_service->close_event))
  32456. + status = VCHIQ_RETRY;
  32457. + }
  32458. + else
  32459. + ret = -EINVAL;
  32460. + } break;
  32461. +
  32462. + case VCHIQ_IOC_REMOVE_SERVICE: {
  32463. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  32464. +
  32465. + service = find_service_for_instance(instance, handle);
  32466. + if (service != NULL) {
  32467. + USER_SERVICE_T *user_service =
  32468. + (USER_SERVICE_T *)service->base.userdata;
  32469. + /* close_pending is false on first entry, and when the
  32470. + wait in vchiq_close_service has been interrupted. */
  32471. + if (!user_service->close_pending) {
  32472. + status = vchiq_remove_service(service->handle);
  32473. + if (status != VCHIQ_SUCCESS)
  32474. + break;
  32475. + }
  32476. +
  32477. + /* close_pending is true once the underlying service
  32478. + has been closed until the client library calls the
  32479. + CLOSE_DELIVERED ioctl, signalling close_event. */
  32480. + if (user_service->close_pending &&
  32481. + down_interruptible(&user_service->close_event))
  32482. + status = VCHIQ_RETRY;
  32483. + }
  32484. + else
  32485. + ret = -EINVAL;
  32486. + } break;
  32487. +
  32488. + case VCHIQ_IOC_USE_SERVICE:
  32489. + case VCHIQ_IOC_RELEASE_SERVICE: {
  32490. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  32491. +
  32492. + service = find_service_for_instance(instance, handle);
  32493. + if (service != NULL) {
  32494. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  32495. + vchiq_use_service_internal(service) :
  32496. + vchiq_release_service_internal(service);
  32497. + if (status != VCHIQ_SUCCESS) {
  32498. + vchiq_log_error(vchiq_susp_log_level,
  32499. + "%s: cmd %s returned error %d for "
  32500. + "service %c%c%c%c:%03d",
  32501. + __func__,
  32502. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  32503. + "VCHIQ_IOC_USE_SERVICE" :
  32504. + "VCHIQ_IOC_RELEASE_SERVICE",
  32505. + status,
  32506. + VCHIQ_FOURCC_AS_4CHARS(
  32507. + service->base.fourcc),
  32508. + service->client_id);
  32509. + ret = -EINVAL;
  32510. + }
  32511. + } else
  32512. + ret = -EINVAL;
  32513. + } break;
  32514. +
  32515. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  32516. + VCHIQ_QUEUE_MESSAGE_T args;
  32517. + if (copy_from_user
  32518. + (&args, (const void __user *)arg,
  32519. + sizeof(args)) != 0) {
  32520. + ret = -EFAULT;
  32521. + break;
  32522. + }
  32523. +
  32524. + service = find_service_for_instance(instance, args.handle);
  32525. +
  32526. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  32527. + /* Copy elements into kernel space */
  32528. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  32529. + if (copy_from_user(elements, args.elements,
  32530. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  32531. + status = vchiq_queue_message
  32532. + (args.handle,
  32533. + elements, args.count);
  32534. + else
  32535. + ret = -EFAULT;
  32536. + } else {
  32537. + ret = -EINVAL;
  32538. + }
  32539. + } break;
  32540. +
  32541. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  32542. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  32543. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  32544. + struct bulk_waiter_node *waiter = NULL;
  32545. + VCHIQ_BULK_DIR_T dir =
  32546. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  32547. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  32548. +
  32549. + if (copy_from_user
  32550. + (&args, (const void __user *)arg,
  32551. + sizeof(args)) != 0) {
  32552. + ret = -EFAULT;
  32553. + break;
  32554. + }
  32555. +
  32556. + service = find_service_for_instance(instance, args.handle);
  32557. + if (!service) {
  32558. + ret = -EINVAL;
  32559. + break;
  32560. + }
  32561. +
  32562. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  32563. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  32564. + GFP_KERNEL);
  32565. + if (!waiter) {
  32566. + ret = -ENOMEM;
  32567. + break;
  32568. + }
  32569. + args.userdata = &waiter->bulk_waiter;
  32570. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  32571. + struct list_head *pos;
  32572. + mutex_lock(&instance->bulk_waiter_list_mutex);
  32573. + list_for_each(pos, &instance->bulk_waiter_list) {
  32574. + if (list_entry(pos, struct bulk_waiter_node,
  32575. + list)->pid == current->pid) {
  32576. + waiter = list_entry(pos,
  32577. + struct bulk_waiter_node,
  32578. + list);
  32579. + list_del(pos);
  32580. + break;
  32581. + }
  32582. +
  32583. + }
  32584. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  32585. + if (!waiter) {
  32586. + vchiq_log_error(vchiq_arm_log_level,
  32587. + "no bulk_waiter found for pid %d",
  32588. + current->pid);
  32589. + ret = -ESRCH;
  32590. + break;
  32591. + }
  32592. + vchiq_log_info(vchiq_arm_log_level,
  32593. + "found bulk_waiter %x for pid %d",
  32594. + (unsigned int)waiter, current->pid);
  32595. + args.userdata = &waiter->bulk_waiter;
  32596. + }
  32597. + status = vchiq_bulk_transfer
  32598. + (args.handle,
  32599. + VCHI_MEM_HANDLE_INVALID,
  32600. + args.data, args.size,
  32601. + args.userdata, args.mode,
  32602. + dir);
  32603. + if (!waiter)
  32604. + break;
  32605. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  32606. + !waiter->bulk_waiter.bulk) {
  32607. + if (waiter->bulk_waiter.bulk) {
  32608. + /* Cancel the signal when the transfer
  32609. + ** completes. */
  32610. + spin_lock(&bulk_waiter_spinlock);
  32611. + waiter->bulk_waiter.bulk->userdata = NULL;
  32612. + spin_unlock(&bulk_waiter_spinlock);
  32613. + }
  32614. + kfree(waiter);
  32615. + } else {
  32616. + const VCHIQ_BULK_MODE_T mode_waiting =
  32617. + VCHIQ_BULK_MODE_WAITING;
  32618. + waiter->pid = current->pid;
  32619. + mutex_lock(&instance->bulk_waiter_list_mutex);
  32620. + list_add(&waiter->list, &instance->bulk_waiter_list);
  32621. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  32622. + vchiq_log_info(vchiq_arm_log_level,
  32623. + "saved bulk_waiter %x for pid %d",
  32624. + (unsigned int)waiter, current->pid);
  32625. +
  32626. + if (copy_to_user((void __user *)
  32627. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  32628. + arg)->mode),
  32629. + (const void *)&mode_waiting,
  32630. + sizeof(mode_waiting)) != 0)
  32631. + ret = -EFAULT;
  32632. + }
  32633. + } break;
  32634. +
  32635. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  32636. + VCHIQ_AWAIT_COMPLETION_T args;
  32637. +
  32638. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32639. + if (!instance->connected) {
  32640. + ret = -ENOTCONN;
  32641. + break;
  32642. + }
  32643. +
  32644. + if (copy_from_user(&args, (const void __user *)arg,
  32645. + sizeof(args)) != 0) {
  32646. + ret = -EFAULT;
  32647. + break;
  32648. + }
  32649. +
  32650. + mutex_lock(&instance->completion_mutex);
  32651. +
  32652. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32653. + while ((instance->completion_remove ==
  32654. + instance->completion_insert)
  32655. + && !instance->closing) {
  32656. + int rc;
  32657. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32658. + mutex_unlock(&instance->completion_mutex);
  32659. + rc = down_interruptible(&instance->insert_event);
  32660. + mutex_lock(&instance->completion_mutex);
  32661. + if (rc != 0) {
  32662. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32663. + vchiq_log_info(vchiq_arm_log_level,
  32664. + "AWAIT_COMPLETION interrupted");
  32665. + ret = -EINTR;
  32666. + break;
  32667. + }
  32668. + }
  32669. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32670. +
  32671. + /* A read memory barrier is needed to stop prefetch of a stale
  32672. + ** completion record
  32673. + */
  32674. + rmb();
  32675. +
  32676. + if (ret == 0) {
  32677. + int msgbufcount = args.msgbufcount;
  32678. + for (ret = 0; ret < args.count; ret++) {
  32679. + VCHIQ_COMPLETION_DATA_T *completion;
  32680. + VCHIQ_SERVICE_T *service;
  32681. + USER_SERVICE_T *user_service;
  32682. + VCHIQ_HEADER_T *header;
  32683. + if (instance->completion_remove ==
  32684. + instance->completion_insert)
  32685. + break;
  32686. + completion = &instance->completions[
  32687. + instance->completion_remove &
  32688. + (MAX_COMPLETIONS - 1)];
  32689. +
  32690. + service = completion->service_userdata;
  32691. + user_service = service->base.userdata;
  32692. + completion->service_userdata =
  32693. + user_service->userdata;
  32694. +
  32695. + header = completion->header;
  32696. + if (header) {
  32697. + void __user *msgbuf;
  32698. + int msglen;
  32699. +
  32700. + msglen = header->size +
  32701. + sizeof(VCHIQ_HEADER_T);
  32702. + /* This must be a VCHIQ-style service */
  32703. + if (args.msgbufsize < msglen) {
  32704. + vchiq_log_error(
  32705. + vchiq_arm_log_level,
  32706. + "header %x: msgbufsize"
  32707. + " %x < msglen %x",
  32708. + (unsigned int)header,
  32709. + args.msgbufsize,
  32710. + msglen);
  32711. + WARN(1, "invalid message "
  32712. + "size\n");
  32713. + if (ret == 0)
  32714. + ret = -EMSGSIZE;
  32715. + break;
  32716. + }
  32717. + if (msgbufcount <= 0)
  32718. + /* Stall here for lack of a
  32719. + ** buffer for the message. */
  32720. + break;
  32721. + /* Get the pointer from user space */
  32722. + msgbufcount--;
  32723. + if (copy_from_user(&msgbuf,
  32724. + (const void __user *)
  32725. + &args.msgbufs[msgbufcount],
  32726. + sizeof(msgbuf)) != 0) {
  32727. + if (ret == 0)
  32728. + ret = -EFAULT;
  32729. + break;
  32730. + }
  32731. +
  32732. + /* Copy the message to user space */
  32733. + if (copy_to_user(msgbuf, header,
  32734. + msglen) != 0) {
  32735. + if (ret == 0)
  32736. + ret = -EFAULT;
  32737. + break;
  32738. + }
  32739. +
  32740. + /* Now it has been copied, the message
  32741. + ** can be released. */
  32742. + vchiq_release_message(service->handle,
  32743. + header);
  32744. +
  32745. + /* The completion must point to the
  32746. + ** msgbuf. */
  32747. + completion->header = msgbuf;
  32748. + }
  32749. +
  32750. + if ((completion->reason ==
  32751. + VCHIQ_SERVICE_CLOSED) &&
  32752. + !instance->use_close_delivered)
  32753. + unlock_service(service);
  32754. +
  32755. + if (copy_to_user((void __user *)(
  32756. + (size_t)args.buf +
  32757. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  32758. + completion,
  32759. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  32760. + if (ret == 0)
  32761. + ret = -EFAULT;
  32762. + break;
  32763. + }
  32764. +
  32765. + instance->completion_remove++;
  32766. + }
  32767. +
  32768. + if (msgbufcount != args.msgbufcount) {
  32769. + if (copy_to_user((void __user *)
  32770. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  32771. + msgbufcount,
  32772. + &msgbufcount,
  32773. + sizeof(msgbufcount)) != 0) {
  32774. + ret = -EFAULT;
  32775. + }
  32776. + }
  32777. + }
  32778. +
  32779. + if (ret != 0)
  32780. + up(&instance->remove_event);
  32781. + mutex_unlock(&instance->completion_mutex);
  32782. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  32783. + } break;
  32784. +
  32785. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  32786. + VCHIQ_DEQUEUE_MESSAGE_T args;
  32787. + USER_SERVICE_T *user_service;
  32788. + VCHIQ_HEADER_T *header;
  32789. +
  32790. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  32791. + if (copy_from_user
  32792. + (&args, (const void __user *)arg,
  32793. + sizeof(args)) != 0) {
  32794. + ret = -EFAULT;
  32795. + break;
  32796. + }
  32797. + service = find_service_for_instance(instance, args.handle);
  32798. + if (!service) {
  32799. + ret = -EINVAL;
  32800. + break;
  32801. + }
  32802. + user_service = (USER_SERVICE_T *)service->base.userdata;
  32803. + if (user_service->is_vchi == 0) {
  32804. + ret = -EINVAL;
  32805. + break;
  32806. + }
  32807. +
  32808. + spin_lock(&msg_queue_spinlock);
  32809. + if (user_service->msg_remove == user_service->msg_insert) {
  32810. + if (!args.blocking) {
  32811. + spin_unlock(&msg_queue_spinlock);
  32812. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  32813. + ret = -EWOULDBLOCK;
  32814. + break;
  32815. + }
  32816. + user_service->dequeue_pending = 1;
  32817. + do {
  32818. + spin_unlock(&msg_queue_spinlock);
  32819. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  32820. + if (down_interruptible(
  32821. + &user_service->insert_event) != 0) {
  32822. + vchiq_log_info(vchiq_arm_log_level,
  32823. + "DEQUEUE_MESSAGE interrupted");
  32824. + ret = -EINTR;
  32825. + break;
  32826. + }
  32827. + spin_lock(&msg_queue_spinlock);
  32828. + } while (user_service->msg_remove ==
  32829. + user_service->msg_insert);
  32830. +
  32831. + if (ret)
  32832. + break;
  32833. + }
  32834. +
  32835. + BUG_ON((int)(user_service->msg_insert -
  32836. + user_service->msg_remove) < 0);
  32837. +
  32838. + header = user_service->msg_queue[user_service->msg_remove &
  32839. + (MSG_QUEUE_SIZE - 1)];
  32840. + user_service->msg_remove++;
  32841. + spin_unlock(&msg_queue_spinlock);
  32842. +
  32843. + up(&user_service->remove_event);
  32844. + if (header == NULL)
  32845. + ret = -ENOTCONN;
  32846. + else if (header->size <= args.bufsize) {
  32847. + /* Copy to user space if msgbuf is not NULL */
  32848. + if ((args.buf == NULL) ||
  32849. + (copy_to_user((void __user *)args.buf,
  32850. + header->data,
  32851. + header->size) == 0)) {
  32852. + ret = header->size;
  32853. + vchiq_release_message(
  32854. + service->handle,
  32855. + header);
  32856. + } else
  32857. + ret = -EFAULT;
  32858. + } else {
  32859. + vchiq_log_error(vchiq_arm_log_level,
  32860. + "header %x: bufsize %x < size %x",
  32861. + (unsigned int)header, args.bufsize,
  32862. + header->size);
  32863. + WARN(1, "invalid size\n");
  32864. + ret = -EMSGSIZE;
  32865. + }
  32866. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  32867. + } break;
  32868. +
  32869. + case VCHIQ_IOC_GET_CLIENT_ID: {
  32870. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  32871. +
  32872. + ret = vchiq_get_client_id(handle);
  32873. + } break;
  32874. +
  32875. + case VCHIQ_IOC_GET_CONFIG: {
  32876. + VCHIQ_GET_CONFIG_T args;
  32877. + VCHIQ_CONFIG_T config;
  32878. +
  32879. + if (copy_from_user(&args, (const void __user *)arg,
  32880. + sizeof(args)) != 0) {
  32881. + ret = -EFAULT;
  32882. + break;
  32883. + }
  32884. + if (args.config_size > sizeof(config)) {
  32885. + ret = -EINVAL;
  32886. + break;
  32887. + }
  32888. + status = vchiq_get_config(instance, args.config_size, &config);
  32889. + if (status == VCHIQ_SUCCESS) {
  32890. + if (copy_to_user((void __user *)args.pconfig,
  32891. + &config, args.config_size) != 0) {
  32892. + ret = -EFAULT;
  32893. + break;
  32894. + }
  32895. + }
  32896. + } break;
  32897. +
  32898. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  32899. + VCHIQ_SET_SERVICE_OPTION_T args;
  32900. +
  32901. + if (copy_from_user(
  32902. + &args, (const void __user *)arg,
  32903. + sizeof(args)) != 0) {
  32904. + ret = -EFAULT;
  32905. + break;
  32906. + }
  32907. +
  32908. + service = find_service_for_instance(instance, args.handle);
  32909. + if (!service) {
  32910. + ret = -EINVAL;
  32911. + break;
  32912. + }
  32913. +
  32914. + status = vchiq_set_service_option(
  32915. + args.handle, args.option, args.value);
  32916. + } break;
  32917. +
  32918. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  32919. + VCHIQ_DUMP_MEM_T args;
  32920. +
  32921. + if (copy_from_user
  32922. + (&args, (const void __user *)arg,
  32923. + sizeof(args)) != 0) {
  32924. + ret = -EFAULT;
  32925. + break;
  32926. + }
  32927. + dump_phys_mem(args.virt_addr, args.num_bytes);
  32928. + } break;
  32929. +
  32930. + case VCHIQ_IOC_LIB_VERSION: {
  32931. + unsigned int lib_version = (unsigned int)arg;
  32932. +
  32933. + if (lib_version < VCHIQ_VERSION_MIN)
  32934. + ret = -EINVAL;
  32935. + else if (lib_version >= VCHIQ_VERSION_CLOSE_DELIVERED)
  32936. + instance->use_close_delivered = 1;
  32937. + } break;
  32938. +
  32939. + case VCHIQ_IOC_CLOSE_DELIVERED: {
  32940. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  32941. +
  32942. + service = find_closed_service_for_instance(instance, handle);
  32943. + if (service != NULL) {
  32944. + USER_SERVICE_T *user_service =
  32945. + (USER_SERVICE_T *)service->base.userdata;
  32946. + close_delivered(user_service);
  32947. + }
  32948. + else
  32949. + ret = -EINVAL;
  32950. + } break;
  32951. +
  32952. + default:
  32953. + ret = -ENOTTY;
  32954. + break;
  32955. + }
  32956. +
  32957. + if (service)
  32958. + unlock_service(service);
  32959. +
  32960. + if (ret == 0) {
  32961. + if (status == VCHIQ_ERROR)
  32962. + ret = -EIO;
  32963. + else if (status == VCHIQ_RETRY)
  32964. + ret = -EINTR;
  32965. + }
  32966. +
  32967. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  32968. + (ret != -EWOULDBLOCK))
  32969. + vchiq_log_info(vchiq_arm_log_level,
  32970. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  32971. + (unsigned long)instance,
  32972. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  32973. + ioctl_names[_IOC_NR(cmd)] :
  32974. + "<invalid>",
  32975. + status, ret);
  32976. + else
  32977. + vchiq_log_trace(vchiq_arm_log_level,
  32978. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  32979. + (unsigned long)instance,
  32980. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  32981. + ioctl_names[_IOC_NR(cmd)] :
  32982. + "<invalid>",
  32983. + status, ret);
  32984. +
  32985. + return ret;
  32986. +}
  32987. +
  32988. +/****************************************************************************
  32989. +*
  32990. +* vchiq_open
  32991. +*
  32992. +***************************************************************************/
  32993. +
  32994. +static int
  32995. +vchiq_open(struct inode *inode, struct file *file)
  32996. +{
  32997. + int dev = iminor(inode) & 0x0f;
  32998. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  32999. + switch (dev) {
  33000. + case VCHIQ_MINOR: {
  33001. + int ret;
  33002. + VCHIQ_STATE_T *state = vchiq_get_state();
  33003. + VCHIQ_INSTANCE_T instance;
  33004. +
  33005. + if (!state) {
  33006. + vchiq_log_error(vchiq_arm_log_level,
  33007. + "vchiq has no connection to VideoCore");
  33008. + return -ENOTCONN;
  33009. + }
  33010. +
  33011. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  33012. + if (!instance)
  33013. + return -ENOMEM;
  33014. +
  33015. + instance->state = state;
  33016. + instance->pid = current->tgid;
  33017. +
  33018. + ret = vchiq_debugfs_add_instance(instance);
  33019. + if (ret != 0) {
  33020. + kfree(instance);
  33021. + return ret;
  33022. + }
  33023. +
  33024. + sema_init(&instance->insert_event, 0);
  33025. + sema_init(&instance->remove_event, 0);
  33026. + mutex_init(&instance->completion_mutex);
  33027. + mutex_init(&instance->bulk_waiter_list_mutex);
  33028. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  33029. +
  33030. + file->private_data = instance;
  33031. + } break;
  33032. +
  33033. + default:
  33034. + vchiq_log_error(vchiq_arm_log_level,
  33035. + "Unknown minor device: %d", dev);
  33036. + return -ENXIO;
  33037. + }
  33038. +
  33039. + return 0;
  33040. +}
  33041. +
  33042. +/****************************************************************************
  33043. +*
  33044. +* vchiq_release
  33045. +*
  33046. +***************************************************************************/
  33047. +
  33048. +static int
  33049. +vchiq_release(struct inode *inode, struct file *file)
  33050. +{
  33051. + int dev = iminor(inode) & 0x0f;
  33052. + int ret = 0;
  33053. + switch (dev) {
  33054. + case VCHIQ_MINOR: {
  33055. + VCHIQ_INSTANCE_T instance = file->private_data;
  33056. + VCHIQ_STATE_T *state = vchiq_get_state();
  33057. + VCHIQ_SERVICE_T *service;
  33058. + int i;
  33059. +
  33060. + vchiq_log_info(vchiq_arm_log_level,
  33061. + "vchiq_release: instance=%lx",
  33062. + (unsigned long)instance);
  33063. +
  33064. + if (!state) {
  33065. + ret = -EPERM;
  33066. + goto out;
  33067. + }
  33068. +
  33069. + /* Ensure videocore is awake to allow termination. */
  33070. + vchiq_use_internal(instance->state, NULL,
  33071. + USE_TYPE_VCHIQ);
  33072. +
  33073. + mutex_lock(&instance->completion_mutex);
  33074. +
  33075. + /* Wake the completion thread and ask it to exit */
  33076. + instance->closing = 1;
  33077. + up(&instance->insert_event);
  33078. +
  33079. + mutex_unlock(&instance->completion_mutex);
  33080. +
  33081. + /* Wake the slot handler if the completion queue is full. */
  33082. + up(&instance->remove_event);
  33083. +
  33084. + /* Mark all services for termination... */
  33085. + i = 0;
  33086. + while ((service = next_service_by_instance(state, instance,
  33087. + &i)) != NULL) {
  33088. + USER_SERVICE_T *user_service = service->base.userdata;
  33089. +
  33090. + /* Wake the slot handler if the msg queue is full. */
  33091. + up(&user_service->remove_event);
  33092. +
  33093. + vchiq_terminate_service_internal(service);
  33094. + unlock_service(service);
  33095. + }
  33096. +
  33097. + /* ...and wait for them to die */
  33098. + i = 0;
  33099. + while ((service = next_service_by_instance(state, instance, &i))
  33100. + != NULL) {
  33101. + USER_SERVICE_T *user_service = service->base.userdata;
  33102. +
  33103. + down(&service->remove_event);
  33104. +
  33105. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  33106. +
  33107. + spin_lock(&msg_queue_spinlock);
  33108. +
  33109. + while (user_service->msg_remove !=
  33110. + user_service->msg_insert) {
  33111. + VCHIQ_HEADER_T *header = user_service->
  33112. + msg_queue[user_service->msg_remove &
  33113. + (MSG_QUEUE_SIZE - 1)];
  33114. + user_service->msg_remove++;
  33115. + spin_unlock(&msg_queue_spinlock);
  33116. +
  33117. + if (header)
  33118. + vchiq_release_message(
  33119. + service->handle,
  33120. + header);
  33121. + spin_lock(&msg_queue_spinlock);
  33122. + }
  33123. +
  33124. + spin_unlock(&msg_queue_spinlock);
  33125. +
  33126. + unlock_service(service);
  33127. + }
  33128. +
  33129. + /* Release any closed services */
  33130. + while (instance->completion_remove !=
  33131. + instance->completion_insert) {
  33132. + VCHIQ_COMPLETION_DATA_T *completion;
  33133. + VCHIQ_SERVICE_T *service;
  33134. + completion = &instance->completions[
  33135. + instance->completion_remove &
  33136. + (MAX_COMPLETIONS - 1)];
  33137. + service = completion->service_userdata;
  33138. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  33139. + {
  33140. + USER_SERVICE_T *user_service =
  33141. + service->base.userdata;
  33142. +
  33143. + /* Wake any blocked user-thread */
  33144. + if (instance->use_close_delivered)
  33145. + up(&user_service->close_event);
  33146. + unlock_service(service);
  33147. + }
  33148. + instance->completion_remove++;
  33149. + }
  33150. +
  33151. + /* Release the PEER service count. */
  33152. + vchiq_release_internal(instance->state, NULL);
  33153. +
  33154. + {
  33155. + struct list_head *pos, *next;
  33156. + list_for_each_safe(pos, next,
  33157. + &instance->bulk_waiter_list) {
  33158. + struct bulk_waiter_node *waiter;
  33159. + waiter = list_entry(pos,
  33160. + struct bulk_waiter_node,
  33161. + list);
  33162. + list_del(pos);
  33163. + vchiq_log_info(vchiq_arm_log_level,
  33164. + "bulk_waiter - cleaned up %x "
  33165. + "for pid %d",
  33166. + (unsigned int)waiter, waiter->pid);
  33167. + kfree(waiter);
  33168. + }
  33169. + }
  33170. +
  33171. + vchiq_debugfs_remove_instance(instance);
  33172. +
  33173. + kfree(instance);
  33174. + file->private_data = NULL;
  33175. + } break;
  33176. +
  33177. + default:
  33178. + vchiq_log_error(vchiq_arm_log_level,
  33179. + "Unknown minor device: %d", dev);
  33180. + ret = -ENXIO;
  33181. + }
  33182. +
  33183. +out:
  33184. + return ret;
  33185. +}
  33186. +
  33187. +/****************************************************************************
  33188. +*
  33189. +* vchiq_dump
  33190. +*
  33191. +***************************************************************************/
  33192. +
  33193. +void
  33194. +vchiq_dump(void *dump_context, const char *str, int len)
  33195. +{
  33196. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  33197. +
  33198. + if (context->actual < context->space) {
  33199. + int copy_bytes;
  33200. + if (context->offset > 0) {
  33201. + int skip_bytes = min(len, (int)context->offset);
  33202. + str += skip_bytes;
  33203. + len -= skip_bytes;
  33204. + context->offset -= skip_bytes;
  33205. + if (context->offset > 0)
  33206. + return;
  33207. + }
  33208. + copy_bytes = min(len, (int)(context->space - context->actual));
  33209. + if (copy_bytes == 0)
  33210. + return;
  33211. + if (copy_to_user(context->buf + context->actual, str,
  33212. + copy_bytes))
  33213. + context->actual = -EFAULT;
  33214. + context->actual += copy_bytes;
  33215. + len -= copy_bytes;
  33216. +
  33217. + /* If tne terminating NUL is included in the length, then it
  33218. + ** marks the end of a line and should be replaced with a
  33219. + ** carriage return. */
  33220. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  33221. + char cr = '\n';
  33222. + if (copy_to_user(context->buf + context->actual - 1,
  33223. + &cr, 1))
  33224. + context->actual = -EFAULT;
  33225. + }
  33226. + }
  33227. +}
  33228. +
  33229. +/****************************************************************************
  33230. +*
  33231. +* vchiq_dump_platform_instance_state
  33232. +*
  33233. +***************************************************************************/
  33234. +
  33235. +void
  33236. +vchiq_dump_platform_instances(void *dump_context)
  33237. +{
  33238. + VCHIQ_STATE_T *state = vchiq_get_state();
  33239. + char buf[80];
  33240. + int len;
  33241. + int i;
  33242. +
  33243. + /* There is no list of instances, so instead scan all services,
  33244. + marking those that have been dumped. */
  33245. +
  33246. + for (i = 0; i < state->unused_service; i++) {
  33247. + VCHIQ_SERVICE_T *service = state->services[i];
  33248. + VCHIQ_INSTANCE_T instance;
  33249. +
  33250. + if (service && (service->base.callback == service_callback)) {
  33251. + instance = service->instance;
  33252. + if (instance)
  33253. + instance->mark = 0;
  33254. + }
  33255. + }
  33256. +
  33257. + for (i = 0; i < state->unused_service; i++) {
  33258. + VCHIQ_SERVICE_T *service = state->services[i];
  33259. + VCHIQ_INSTANCE_T instance;
  33260. +
  33261. + if (service && (service->base.callback == service_callback)) {
  33262. + instance = service->instance;
  33263. + if (instance && !instance->mark) {
  33264. + len = snprintf(buf, sizeof(buf),
  33265. + "Instance %x: pid %d,%s completions "
  33266. + "%d/%d",
  33267. + (unsigned int)instance, instance->pid,
  33268. + instance->connected ? " connected, " :
  33269. + "",
  33270. + instance->completion_insert -
  33271. + instance->completion_remove,
  33272. + MAX_COMPLETIONS);
  33273. +
  33274. + vchiq_dump(dump_context, buf, len + 1);
  33275. +
  33276. + instance->mark = 1;
  33277. + }
  33278. + }
  33279. + }
  33280. +}
  33281. +
  33282. +/****************************************************************************
  33283. +*
  33284. +* vchiq_dump_platform_service_state
  33285. +*
  33286. +***************************************************************************/
  33287. +
  33288. +void
  33289. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  33290. +{
  33291. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  33292. + char buf[80];
  33293. + int len;
  33294. +
  33295. + len = snprintf(buf, sizeof(buf), " instance %x",
  33296. + (unsigned int)service->instance);
  33297. +
  33298. + if ((service->base.callback == service_callback) &&
  33299. + user_service->is_vchi) {
  33300. + len += snprintf(buf + len, sizeof(buf) - len,
  33301. + ", %d/%d messages",
  33302. + user_service->msg_insert - user_service->msg_remove,
  33303. + MSG_QUEUE_SIZE);
  33304. +
  33305. + if (user_service->dequeue_pending)
  33306. + len += snprintf(buf + len, sizeof(buf) - len,
  33307. + " (dequeue pending)");
  33308. + }
  33309. +
  33310. + vchiq_dump(dump_context, buf, len + 1);
  33311. +}
  33312. +
  33313. +/****************************************************************************
  33314. +*
  33315. +* dump_user_mem
  33316. +*
  33317. +***************************************************************************/
  33318. +
  33319. +static void
  33320. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  33321. +{
  33322. + int rc;
  33323. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  33324. + int num_pages;
  33325. + int offset;
  33326. + int end_offset;
  33327. + int page_idx;
  33328. + int prev_idx;
  33329. + struct page *page;
  33330. + struct page **pages;
  33331. + uint8_t *kmapped_virt_ptr;
  33332. +
  33333. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  33334. +
  33335. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  33336. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  33337. + ~0x0fuL);
  33338. +
  33339. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  33340. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  33341. +
  33342. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  33343. +
  33344. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  33345. + if (pages == NULL) {
  33346. + vchiq_log_error(vchiq_arm_log_level,
  33347. + "Unable to allocation memory for %d pages\n",
  33348. + num_pages);
  33349. + return;
  33350. + }
  33351. +
  33352. + down_read(&current->mm->mmap_sem);
  33353. + rc = get_user_pages(current, /* task */
  33354. + current->mm, /* mm */
  33355. + (unsigned long)virt_addr, /* start */
  33356. + num_pages, /* len */
  33357. + 0, /* write */
  33358. + 0, /* force */
  33359. + pages, /* pages (array of page pointers) */
  33360. + NULL); /* vmas */
  33361. + up_read(&current->mm->mmap_sem);
  33362. +
  33363. + prev_idx = -1;
  33364. + page = NULL;
  33365. +
  33366. + while (offset < end_offset) {
  33367. +
  33368. + int page_offset = offset % PAGE_SIZE;
  33369. + page_idx = offset / PAGE_SIZE;
  33370. +
  33371. + if (page_idx != prev_idx) {
  33372. +
  33373. + if (page != NULL)
  33374. + kunmap(page);
  33375. + page = pages[page_idx];
  33376. + kmapped_virt_ptr = kmap(page);
  33377. +
  33378. + prev_idx = page_idx;
  33379. + }
  33380. +
  33381. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  33382. + vchiq_log_dump_mem("ph",
  33383. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  33384. + page_offset],
  33385. + &kmapped_virt_ptr[page_offset], 16);
  33386. +
  33387. + offset += 16;
  33388. + }
  33389. + if (page != NULL)
  33390. + kunmap(page);
  33391. +
  33392. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  33393. + page_cache_release(pages[page_idx]);
  33394. +
  33395. + kfree(pages);
  33396. +}
  33397. +
  33398. +/****************************************************************************
  33399. +*
  33400. +* vchiq_read
  33401. +*
  33402. +***************************************************************************/
  33403. +
  33404. +static ssize_t
  33405. +vchiq_read(struct file *file, char __user *buf,
  33406. + size_t count, loff_t *ppos)
  33407. +{
  33408. + DUMP_CONTEXT_T context;
  33409. + context.buf = buf;
  33410. + context.actual = 0;
  33411. + context.space = count;
  33412. + context.offset = *ppos;
  33413. +
  33414. + vchiq_dump_state(&context, &g_state);
  33415. +
  33416. + *ppos += context.actual;
  33417. +
  33418. + return context.actual;
  33419. +}
  33420. +
  33421. +VCHIQ_STATE_T *
  33422. +vchiq_get_state(void)
  33423. +{
  33424. +
  33425. + if (g_state.remote == NULL)
  33426. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  33427. + else if (g_state.remote->initialised != 1)
  33428. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  33429. + __func__, g_state.remote->initialised);
  33430. +
  33431. + return ((g_state.remote != NULL) &&
  33432. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  33433. +}
  33434. +
  33435. +static const struct file_operations
  33436. +vchiq_fops = {
  33437. + .owner = THIS_MODULE,
  33438. + .unlocked_ioctl = vchiq_ioctl,
  33439. + .open = vchiq_open,
  33440. + .release = vchiq_release,
  33441. + .read = vchiq_read
  33442. +};
  33443. +
  33444. +/*
  33445. + * Autosuspend related functionality
  33446. + */
  33447. +
  33448. +int
  33449. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  33450. +{
  33451. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33452. + if (!arm_state)
  33453. + /* autosuspend not supported - always return wanted */
  33454. + return 1;
  33455. + else if (arm_state->blocked_count)
  33456. + return 1;
  33457. + else if (!arm_state->videocore_use_count)
  33458. + /* usage count zero - check for override unless we're forcing */
  33459. + if (arm_state->resume_blocked)
  33460. + return 0;
  33461. + else
  33462. + return vchiq_platform_videocore_wanted(state);
  33463. + else
  33464. + /* non-zero usage count - videocore still required */
  33465. + return 1;
  33466. +}
  33467. +
  33468. +static VCHIQ_STATUS_T
  33469. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  33470. + VCHIQ_HEADER_T *header,
  33471. + VCHIQ_SERVICE_HANDLE_T service_user,
  33472. + void *bulk_user)
  33473. +{
  33474. + vchiq_log_error(vchiq_susp_log_level,
  33475. + "%s callback reason %d", __func__, reason);
  33476. + return 0;
  33477. +}
  33478. +
  33479. +static int
  33480. +vchiq_keepalive_thread_func(void *v)
  33481. +{
  33482. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  33483. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33484. +
  33485. + VCHIQ_STATUS_T status;
  33486. + VCHIQ_INSTANCE_T instance;
  33487. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  33488. +
  33489. + VCHIQ_SERVICE_PARAMS_T params = {
  33490. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  33491. + .callback = vchiq_keepalive_vchiq_callback,
  33492. + .version = KEEPALIVE_VER,
  33493. + .version_min = KEEPALIVE_VER_MIN
  33494. + };
  33495. +
  33496. + status = vchiq_initialise(&instance);
  33497. + if (status != VCHIQ_SUCCESS) {
  33498. + vchiq_log_error(vchiq_susp_log_level,
  33499. + "%s vchiq_initialise failed %d", __func__, status);
  33500. + goto exit;
  33501. + }
  33502. +
  33503. + status = vchiq_connect(instance);
  33504. + if (status != VCHIQ_SUCCESS) {
  33505. + vchiq_log_error(vchiq_susp_log_level,
  33506. + "%s vchiq_connect failed %d", __func__, status);
  33507. + goto shutdown;
  33508. + }
  33509. +
  33510. + status = vchiq_add_service(instance, &params, &ka_handle);
  33511. + if (status != VCHIQ_SUCCESS) {
  33512. + vchiq_log_error(vchiq_susp_log_level,
  33513. + "%s vchiq_open_service failed %d", __func__, status);
  33514. + goto shutdown;
  33515. + }
  33516. +
  33517. + while (1) {
  33518. + long rc = 0, uc = 0;
  33519. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  33520. + != 0) {
  33521. + vchiq_log_error(vchiq_susp_log_level,
  33522. + "%s interrupted", __func__);
  33523. + flush_signals(current);
  33524. + continue;
  33525. + }
  33526. +
  33527. + /* read and clear counters. Do release_count then use_count to
  33528. + * prevent getting more releases than uses */
  33529. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  33530. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  33531. +
  33532. + /* Call use/release service the requisite number of times.
  33533. + * Process use before release so use counts don't go negative */
  33534. + while (uc--) {
  33535. + atomic_inc(&arm_state->ka_use_ack_count);
  33536. + status = vchiq_use_service(ka_handle);
  33537. + if (status != VCHIQ_SUCCESS) {
  33538. + vchiq_log_error(vchiq_susp_log_level,
  33539. + "%s vchiq_use_service error %d",
  33540. + __func__, status);
  33541. + }
  33542. + }
  33543. + while (rc--) {
  33544. + status = vchiq_release_service(ka_handle);
  33545. + if (status != VCHIQ_SUCCESS) {
  33546. + vchiq_log_error(vchiq_susp_log_level,
  33547. + "%s vchiq_release_service error %d",
  33548. + __func__, status);
  33549. + }
  33550. + }
  33551. + }
  33552. +
  33553. +shutdown:
  33554. + vchiq_shutdown(instance);
  33555. +exit:
  33556. + return 0;
  33557. +}
  33558. +
  33559. +
  33560. +
  33561. +VCHIQ_STATUS_T
  33562. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  33563. +{
  33564. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  33565. +
  33566. + if (arm_state) {
  33567. + rwlock_init(&arm_state->susp_res_lock);
  33568. +
  33569. + init_completion(&arm_state->ka_evt);
  33570. + atomic_set(&arm_state->ka_use_count, 0);
  33571. + atomic_set(&arm_state->ka_use_ack_count, 0);
  33572. + atomic_set(&arm_state->ka_release_count, 0);
  33573. +
  33574. + init_completion(&arm_state->vc_suspend_complete);
  33575. +
  33576. + init_completion(&arm_state->vc_resume_complete);
  33577. + /* Initialise to 'done' state. We only want to block on resume
  33578. + * completion while videocore is suspended. */
  33579. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  33580. +
  33581. + init_completion(&arm_state->resume_blocker);
  33582. + /* Initialise to 'done' state. We only want to block on this
  33583. + * completion while resume is blocked */
  33584. + complete_all(&arm_state->resume_blocker);
  33585. +
  33586. + init_completion(&arm_state->blocked_blocker);
  33587. + /* Initialise to 'done' state. We only want to block on this
  33588. + * completion while things are waiting on the resume blocker */
  33589. + complete_all(&arm_state->blocked_blocker);
  33590. +
  33591. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  33592. + arm_state->suspend_timer_running = 0;
  33593. + init_timer(&arm_state->suspend_timer);
  33594. + arm_state->suspend_timer.data = (unsigned long)(state);
  33595. + arm_state->suspend_timer.function = suspend_timer_callback;
  33596. +
  33597. + arm_state->first_connect = 0;
  33598. +
  33599. + }
  33600. + return status;
  33601. +}
  33602. +
  33603. +/*
  33604. +** Functions to modify the state variables;
  33605. +** set_suspend_state
  33606. +** set_resume_state
  33607. +**
  33608. +** There are more state variables than we might like, so ensure they remain in
  33609. +** step. Suspend and resume state are maintained separately, since most of
  33610. +** these state machines can operate independently. However, there are a few
  33611. +** states where state transitions in one state machine cause a reset to the
  33612. +** other state machine. In addition, there are some completion events which
  33613. +** need to occur on state machine reset and end-state(s), so these are also
  33614. +** dealt with in these functions.
  33615. +**
  33616. +** In all states we set the state variable according to the input, but in some
  33617. +** cases we perform additional steps outlined below;
  33618. +**
  33619. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  33620. +** The suspend completion is completed after any suspend
  33621. +** attempt. When we reset the state machine we also reset
  33622. +** the completion. This reset occurs when videocore is
  33623. +** resumed, and also if we initiate suspend after a suspend
  33624. +** failure.
  33625. +**
  33626. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  33627. +** suspend - ie from this point on we must try to suspend
  33628. +** before resuming can occur. We therefore also reset the
  33629. +** resume state machine to VC_RESUME_IDLE in this state.
  33630. +**
  33631. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  33632. +** complete_all on the suspend completion to notify
  33633. +** anything waiting for suspend to happen.
  33634. +**
  33635. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  33636. +** initiate resume, so no need to alter resume state.
  33637. +** We call complete_all on the suspend completion to notify
  33638. +** of suspend rejection.
  33639. +**
  33640. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  33641. +** suspend completion and reset the resume state machine.
  33642. +**
  33643. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  33644. +** resume completion is in it's 'done' state whenever
  33645. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  33646. +** implies that videocore is suspended.
  33647. +** Hence, any thread which needs to wait until videocore is
  33648. +** running can wait on this completion - it will only block
  33649. +** if videocore is suspended.
  33650. +**
  33651. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  33652. +** Call complete_all on the resume completion to unblock
  33653. +** any threads waiting for resume. Also reset the suspend
  33654. +** state machine to it's idle state.
  33655. +**
  33656. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  33657. +*/
  33658. +
  33659. +inline void
  33660. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  33661. + enum vc_suspend_status new_state)
  33662. +{
  33663. + /* set the state in all cases */
  33664. + arm_state->vc_suspend_state = new_state;
  33665. +
  33666. + /* state specific additional actions */
  33667. + switch (new_state) {
  33668. + case VC_SUSPEND_FORCE_CANCELED:
  33669. + complete_all(&arm_state->vc_suspend_complete);
  33670. + break;
  33671. + case VC_SUSPEND_REJECTED:
  33672. + complete_all(&arm_state->vc_suspend_complete);
  33673. + break;
  33674. + case VC_SUSPEND_FAILED:
  33675. + complete_all(&arm_state->vc_suspend_complete);
  33676. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  33677. + complete_all(&arm_state->vc_resume_complete);
  33678. + break;
  33679. + case VC_SUSPEND_IDLE:
  33680. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  33681. + break;
  33682. + case VC_SUSPEND_REQUESTED:
  33683. + break;
  33684. + case VC_SUSPEND_IN_PROGRESS:
  33685. + set_resume_state(arm_state, VC_RESUME_IDLE);
  33686. + break;
  33687. + case VC_SUSPEND_SUSPENDED:
  33688. + complete_all(&arm_state->vc_suspend_complete);
  33689. + break;
  33690. + default:
  33691. + BUG();
  33692. + break;
  33693. + }
  33694. +}
  33695. +
  33696. +inline void
  33697. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  33698. + enum vc_resume_status new_state)
  33699. +{
  33700. + /* set the state in all cases */
  33701. + arm_state->vc_resume_state = new_state;
  33702. +
  33703. + /* state specific additional actions */
  33704. + switch (new_state) {
  33705. + case VC_RESUME_FAILED:
  33706. + break;
  33707. + case VC_RESUME_IDLE:
  33708. + INIT_COMPLETION(arm_state->vc_resume_complete);
  33709. + break;
  33710. + case VC_RESUME_REQUESTED:
  33711. + break;
  33712. + case VC_RESUME_IN_PROGRESS:
  33713. + break;
  33714. + case VC_RESUME_RESUMED:
  33715. + complete_all(&arm_state->vc_resume_complete);
  33716. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  33717. + break;
  33718. + default:
  33719. + BUG();
  33720. + break;
  33721. + }
  33722. +}
  33723. +
  33724. +
  33725. +/* should be called with the write lock held */
  33726. +inline void
  33727. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  33728. +{
  33729. + del_timer(&arm_state->suspend_timer);
  33730. + arm_state->suspend_timer.expires = jiffies +
  33731. + msecs_to_jiffies(arm_state->
  33732. + suspend_timer_timeout);
  33733. + add_timer(&arm_state->suspend_timer);
  33734. + arm_state->suspend_timer_running = 1;
  33735. +}
  33736. +
  33737. +/* should be called with the write lock held */
  33738. +static inline void
  33739. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  33740. +{
  33741. + if (arm_state->suspend_timer_running) {
  33742. + del_timer(&arm_state->suspend_timer);
  33743. + arm_state->suspend_timer_running = 0;
  33744. + }
  33745. +}
  33746. +
  33747. +static inline int
  33748. +need_resume(VCHIQ_STATE_T *state)
  33749. +{
  33750. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33751. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  33752. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  33753. + vchiq_videocore_wanted(state);
  33754. +}
  33755. +
  33756. +static int
  33757. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  33758. +{
  33759. + int status = VCHIQ_SUCCESS;
  33760. + const unsigned long timeout_val =
  33761. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  33762. + int resume_count = 0;
  33763. +
  33764. + /* Allow any threads which were blocked by the last force suspend to
  33765. + * complete if they haven't already. Only give this one shot; if
  33766. + * blocked_count is incremented after blocked_blocker is completed
  33767. + * (which only happens when blocked_count hits 0) then those threads
  33768. + * will have to wait until next time around */
  33769. + if (arm_state->blocked_count) {
  33770. + INIT_COMPLETION(arm_state->blocked_blocker);
  33771. + write_unlock_bh(&arm_state->susp_res_lock);
  33772. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  33773. + "blocked clients", __func__);
  33774. + if (wait_for_completion_interruptible_timeout(
  33775. + &arm_state->blocked_blocker, timeout_val)
  33776. + <= 0) {
  33777. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  33778. + "previously blocked clients failed" , __func__);
  33779. + status = VCHIQ_ERROR;
  33780. + write_lock_bh(&arm_state->susp_res_lock);
  33781. + goto out;
  33782. + }
  33783. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  33784. + "clients resumed", __func__);
  33785. + write_lock_bh(&arm_state->susp_res_lock);
  33786. + }
  33787. +
  33788. + /* We need to wait for resume to complete if it's in process */
  33789. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  33790. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  33791. + if (resume_count > 1) {
  33792. + status = VCHIQ_ERROR;
  33793. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  33794. + "many times for resume" , __func__);
  33795. + goto out;
  33796. + }
  33797. + write_unlock_bh(&arm_state->susp_res_lock);
  33798. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  33799. + __func__);
  33800. + if (wait_for_completion_interruptible_timeout(
  33801. + &arm_state->vc_resume_complete, timeout_val)
  33802. + <= 0) {
  33803. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  33804. + "resume failed (%s)", __func__,
  33805. + resume_state_names[arm_state->vc_resume_state +
  33806. + VC_RESUME_NUM_OFFSET]);
  33807. + status = VCHIQ_ERROR;
  33808. + write_lock_bh(&arm_state->susp_res_lock);
  33809. + goto out;
  33810. + }
  33811. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  33812. + write_lock_bh(&arm_state->susp_res_lock);
  33813. + resume_count++;
  33814. + }
  33815. + INIT_COMPLETION(arm_state->resume_blocker);
  33816. + arm_state->resume_blocked = 1;
  33817. +
  33818. +out:
  33819. + return status;
  33820. +}
  33821. +
  33822. +static inline void
  33823. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  33824. +{
  33825. + complete_all(&arm_state->resume_blocker);
  33826. + arm_state->resume_blocked = 0;
  33827. +}
  33828. +
  33829. +/* Initiate suspend via slot handler. Should be called with the write lock
  33830. + * held */
  33831. +VCHIQ_STATUS_T
  33832. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  33833. +{
  33834. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  33835. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33836. +
  33837. + if (!arm_state)
  33838. + goto out;
  33839. +
  33840. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  33841. + status = VCHIQ_SUCCESS;
  33842. +
  33843. +
  33844. + switch (arm_state->vc_suspend_state) {
  33845. + case VC_SUSPEND_REQUESTED:
  33846. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  33847. + "requested", __func__);
  33848. + break;
  33849. + case VC_SUSPEND_IN_PROGRESS:
  33850. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  33851. + "progress", __func__);
  33852. + break;
  33853. +
  33854. + default:
  33855. + /* We don't expect to be in other states, so log but continue
  33856. + * anyway */
  33857. + vchiq_log_error(vchiq_susp_log_level,
  33858. + "%s unexpected suspend state %s", __func__,
  33859. + suspend_state_names[arm_state->vc_suspend_state +
  33860. + VC_SUSPEND_NUM_OFFSET]);
  33861. + /* fall through */
  33862. + case VC_SUSPEND_REJECTED:
  33863. + case VC_SUSPEND_FAILED:
  33864. + /* Ensure any idle state actions have been run */
  33865. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  33866. + /* fall through */
  33867. + case VC_SUSPEND_IDLE:
  33868. + vchiq_log_info(vchiq_susp_log_level,
  33869. + "%s: suspending", __func__);
  33870. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  33871. + /* kick the slot handler thread to initiate suspend */
  33872. + request_poll(state, NULL, 0);
  33873. + break;
  33874. + }
  33875. +
  33876. +out:
  33877. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  33878. + return status;
  33879. +}
  33880. +
  33881. +void
  33882. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  33883. +{
  33884. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33885. + int susp = 0;
  33886. +
  33887. + if (!arm_state)
  33888. + goto out;
  33889. +
  33890. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  33891. +
  33892. + write_lock_bh(&arm_state->susp_res_lock);
  33893. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  33894. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  33895. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  33896. + susp = 1;
  33897. + }
  33898. + write_unlock_bh(&arm_state->susp_res_lock);
  33899. +
  33900. + if (susp)
  33901. + vchiq_platform_suspend(state);
  33902. +
  33903. +out:
  33904. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  33905. + return;
  33906. +}
  33907. +
  33908. +
  33909. +static void
  33910. +output_timeout_error(VCHIQ_STATE_T *state)
  33911. +{
  33912. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33913. + char service_err[50] = "";
  33914. + int vc_use_count = arm_state->videocore_use_count;
  33915. + int active_services = state->unused_service;
  33916. + int i;
  33917. +
  33918. + if (!arm_state->videocore_use_count) {
  33919. + snprintf(service_err, 50, " Videocore usecount is 0");
  33920. + goto output_msg;
  33921. + }
  33922. + for (i = 0; i < active_services; i++) {
  33923. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  33924. + if (service_ptr && service_ptr->service_use_count &&
  33925. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  33926. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  33927. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  33928. + service_ptr->base.fourcc),
  33929. + service_ptr->client_id,
  33930. + service_ptr->service_use_count,
  33931. + service_ptr->service_use_count ==
  33932. + vc_use_count ? "" : " (+ more)");
  33933. + break;
  33934. + }
  33935. + }
  33936. +
  33937. +output_msg:
  33938. + vchiq_log_error(vchiq_susp_log_level,
  33939. + "timed out waiting for vc suspend (%d).%s",
  33940. + arm_state->autosuspend_override, service_err);
  33941. +
  33942. +}
  33943. +
  33944. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  33945. +** We don't actually force suspend, since videocore may get into a bad state
  33946. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  33947. +** determine a good point to suspend. If this doesn't happen within 100ms we
  33948. +** report failure.
  33949. +**
  33950. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  33951. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  33952. +*/
  33953. +VCHIQ_STATUS_T
  33954. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  33955. +{
  33956. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  33957. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  33958. + long rc = 0;
  33959. + int repeat = -1;
  33960. +
  33961. + if (!arm_state)
  33962. + goto out;
  33963. +
  33964. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  33965. +
  33966. + write_lock_bh(&arm_state->susp_res_lock);
  33967. +
  33968. + status = block_resume(arm_state);
  33969. + if (status != VCHIQ_SUCCESS)
  33970. + goto unlock;
  33971. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  33972. + /* Already suspended - just block resume and exit */
  33973. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  33974. + __func__);
  33975. + status = VCHIQ_SUCCESS;
  33976. + goto unlock;
  33977. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  33978. + /* initiate suspend immediately in the case that we're waiting
  33979. + * for the timeout */
  33980. + stop_suspend_timer(arm_state);
  33981. + if (!vchiq_videocore_wanted(state)) {
  33982. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  33983. + "idle, initiating suspend", __func__);
  33984. + status = vchiq_arm_vcsuspend(state);
  33985. + } else if (arm_state->autosuspend_override <
  33986. + FORCE_SUSPEND_FAIL_MAX) {
  33987. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  33988. + "videocore go idle", __func__);
  33989. + status = VCHIQ_SUCCESS;
  33990. + } else {
  33991. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  33992. + "many times - attempting suspend", __func__);
  33993. + status = vchiq_arm_vcsuspend(state);
  33994. + }
  33995. + } else {
  33996. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  33997. + "in progress - wait for completion", __func__);
  33998. + status = VCHIQ_SUCCESS;
  33999. + }
  34000. +
  34001. + /* Wait for suspend to happen due to system idle (not forced..) */
  34002. + if (status != VCHIQ_SUCCESS)
  34003. + goto unblock_resume;
  34004. +
  34005. + do {
  34006. + write_unlock_bh(&arm_state->susp_res_lock);
  34007. +
  34008. + rc = wait_for_completion_interruptible_timeout(
  34009. + &arm_state->vc_suspend_complete,
  34010. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  34011. +
  34012. + write_lock_bh(&arm_state->susp_res_lock);
  34013. + if (rc < 0) {
  34014. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  34015. + "interrupted waiting for suspend", __func__);
  34016. + status = VCHIQ_ERROR;
  34017. + goto unblock_resume;
  34018. + } else if (rc == 0) {
  34019. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  34020. + /* Repeat timeout once if in progress */
  34021. + if (repeat < 0) {
  34022. + repeat = 1;
  34023. + continue;
  34024. + }
  34025. + }
  34026. + arm_state->autosuspend_override++;
  34027. + output_timeout_error(state);
  34028. +
  34029. + status = VCHIQ_RETRY;
  34030. + goto unblock_resume;
  34031. + }
  34032. + } while (0 < (repeat--));
  34033. +
  34034. + /* Check and report state in case we need to abort ARM suspend */
  34035. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  34036. + status = VCHIQ_RETRY;
  34037. + vchiq_log_error(vchiq_susp_log_level,
  34038. + "%s videocore suspend failed (state %s)", __func__,
  34039. + suspend_state_names[arm_state->vc_suspend_state +
  34040. + VC_SUSPEND_NUM_OFFSET]);
  34041. + /* Reset the state only if it's still in an error state.
  34042. + * Something could have already initiated another suspend. */
  34043. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  34044. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  34045. +
  34046. + goto unblock_resume;
  34047. + }
  34048. +
  34049. + /* successfully suspended - unlock and exit */
  34050. + goto unlock;
  34051. +
  34052. +unblock_resume:
  34053. + /* all error states need to unblock resume before exit */
  34054. + unblock_resume(arm_state);
  34055. +
  34056. +unlock:
  34057. + write_unlock_bh(&arm_state->susp_res_lock);
  34058. +
  34059. +out:
  34060. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  34061. + return status;
  34062. +}
  34063. +
  34064. +void
  34065. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  34066. +{
  34067. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34068. +
  34069. + if (!arm_state)
  34070. + goto out;
  34071. +
  34072. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34073. +
  34074. + write_lock_bh(&arm_state->susp_res_lock);
  34075. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  34076. + arm_state->first_connect &&
  34077. + !vchiq_videocore_wanted(state)) {
  34078. + vchiq_arm_vcsuspend(state);
  34079. + }
  34080. + write_unlock_bh(&arm_state->susp_res_lock);
  34081. +
  34082. +out:
  34083. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  34084. + return;
  34085. +}
  34086. +
  34087. +
  34088. +int
  34089. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  34090. +{
  34091. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34092. + int resume = 0;
  34093. + int ret = -1;
  34094. +
  34095. + if (!arm_state)
  34096. + goto out;
  34097. +
  34098. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34099. +
  34100. + write_lock_bh(&arm_state->susp_res_lock);
  34101. + unblock_resume(arm_state);
  34102. + resume = vchiq_check_resume(state);
  34103. + write_unlock_bh(&arm_state->susp_res_lock);
  34104. +
  34105. + if (resume) {
  34106. + if (wait_for_completion_interruptible(
  34107. + &arm_state->vc_resume_complete) < 0) {
  34108. + vchiq_log_error(vchiq_susp_log_level,
  34109. + "%s interrupted", __func__);
  34110. + /* failed, cannot accurately derive suspend
  34111. + * state, so exit early. */
  34112. + goto out;
  34113. + }
  34114. + }
  34115. +
  34116. + read_lock_bh(&arm_state->susp_res_lock);
  34117. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  34118. + vchiq_log_info(vchiq_susp_log_level,
  34119. + "%s: Videocore remains suspended", __func__);
  34120. + } else {
  34121. + vchiq_log_info(vchiq_susp_log_level,
  34122. + "%s: Videocore resumed", __func__);
  34123. + ret = 0;
  34124. + }
  34125. + read_unlock_bh(&arm_state->susp_res_lock);
  34126. +out:
  34127. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  34128. + return ret;
  34129. +}
  34130. +
  34131. +/* This function should be called with the write lock held */
  34132. +int
  34133. +vchiq_check_resume(VCHIQ_STATE_T *state)
  34134. +{
  34135. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34136. + int resume = 0;
  34137. +
  34138. + if (!arm_state)
  34139. + goto out;
  34140. +
  34141. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34142. +
  34143. + if (need_resume(state)) {
  34144. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  34145. + request_poll(state, NULL, 0);
  34146. + resume = 1;
  34147. + }
  34148. +
  34149. +out:
  34150. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  34151. + return resume;
  34152. +}
  34153. +
  34154. +void
  34155. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  34156. +{
  34157. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34158. + int res = 0;
  34159. +
  34160. + if (!arm_state)
  34161. + goto out;
  34162. +
  34163. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34164. +
  34165. + write_lock_bh(&arm_state->susp_res_lock);
  34166. + if (arm_state->wake_address == 0) {
  34167. + vchiq_log_info(vchiq_susp_log_level,
  34168. + "%s: already awake", __func__);
  34169. + goto unlock;
  34170. + }
  34171. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  34172. + vchiq_log_info(vchiq_susp_log_level,
  34173. + "%s: already resuming", __func__);
  34174. + goto unlock;
  34175. + }
  34176. +
  34177. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  34178. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  34179. + res = 1;
  34180. + } else
  34181. + vchiq_log_trace(vchiq_susp_log_level,
  34182. + "%s: not resuming (resume state %s)", __func__,
  34183. + resume_state_names[arm_state->vc_resume_state +
  34184. + VC_RESUME_NUM_OFFSET]);
  34185. +
  34186. +unlock:
  34187. + write_unlock_bh(&arm_state->susp_res_lock);
  34188. +
  34189. + if (res)
  34190. + vchiq_platform_resume(state);
  34191. +
  34192. +out:
  34193. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  34194. + return;
  34195. +
  34196. +}
  34197. +
  34198. +
  34199. +
  34200. +VCHIQ_STATUS_T
  34201. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  34202. + enum USE_TYPE_E use_type)
  34203. +{
  34204. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34205. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  34206. + char entity[16];
  34207. + int *entity_uc;
  34208. + int local_uc, local_entity_uc;
  34209. +
  34210. + if (!arm_state)
  34211. + goto out;
  34212. +
  34213. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34214. +
  34215. + if (use_type == USE_TYPE_VCHIQ) {
  34216. + sprintf(entity, "VCHIQ: ");
  34217. + entity_uc = &arm_state->peer_use_count;
  34218. + } else if (service) {
  34219. + sprintf(entity, "%c%c%c%c:%03d",
  34220. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  34221. + service->client_id);
  34222. + entity_uc = &service->service_use_count;
  34223. + } else {
  34224. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  34225. + "ptr", __func__);
  34226. + ret = VCHIQ_ERROR;
  34227. + goto out;
  34228. + }
  34229. +
  34230. + write_lock_bh(&arm_state->susp_res_lock);
  34231. + while (arm_state->resume_blocked) {
  34232. + /* If we call 'use' while force suspend is waiting for suspend,
  34233. + * then we're about to block the thread which the force is
  34234. + * waiting to complete, so we're bound to just time out. In this
  34235. + * case, set the suspend state such that the wait will be
  34236. + * canceled, so we can complete as quickly as possible. */
  34237. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  34238. + VC_SUSPEND_IDLE) {
  34239. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  34240. + break;
  34241. + }
  34242. + /* If suspend is already in progress then we need to block */
  34243. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  34244. + /* Indicate that there are threads waiting on the resume
  34245. + * blocker. These need to be allowed to complete before
  34246. + * a _second_ call to force suspend can complete,
  34247. + * otherwise low priority threads might never actually
  34248. + * continue */
  34249. + arm_state->blocked_count++;
  34250. + write_unlock_bh(&arm_state->susp_res_lock);
  34251. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  34252. + "blocked - waiting...", __func__, entity);
  34253. + if (wait_for_completion_killable(
  34254. + &arm_state->resume_blocker) != 0) {
  34255. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  34256. + "wait for resume blocker interrupted",
  34257. + __func__, entity);
  34258. + ret = VCHIQ_ERROR;
  34259. + write_lock_bh(&arm_state->susp_res_lock);
  34260. + arm_state->blocked_count--;
  34261. + write_unlock_bh(&arm_state->susp_res_lock);
  34262. + goto out;
  34263. + }
  34264. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  34265. + "unblocked", __func__, entity);
  34266. + write_lock_bh(&arm_state->susp_res_lock);
  34267. + if (--arm_state->blocked_count == 0)
  34268. + complete_all(&arm_state->blocked_blocker);
  34269. + }
  34270. + }
  34271. +
  34272. + stop_suspend_timer(arm_state);
  34273. +
  34274. + local_uc = ++arm_state->videocore_use_count;
  34275. + local_entity_uc = ++(*entity_uc);
  34276. +
  34277. + /* If there's a pending request which hasn't yet been serviced then
  34278. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  34279. + * vc_resume_complete will block until we either resume or fail to
  34280. + * suspend */
  34281. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  34282. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  34283. +
  34284. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  34285. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  34286. + vchiq_log_info(vchiq_susp_log_level,
  34287. + "%s %s count %d, state count %d",
  34288. + __func__, entity, local_entity_uc, local_uc);
  34289. + request_poll(state, NULL, 0);
  34290. + } else
  34291. + vchiq_log_trace(vchiq_susp_log_level,
  34292. + "%s %s count %d, state count %d",
  34293. + __func__, entity, *entity_uc, local_uc);
  34294. +
  34295. +
  34296. + write_unlock_bh(&arm_state->susp_res_lock);
  34297. +
  34298. + /* Completion is in a done state when we're not suspended, so this won't
  34299. + * block for the non-suspended case. */
  34300. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  34301. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  34302. + __func__, entity);
  34303. + if (wait_for_completion_killable(
  34304. + &arm_state->vc_resume_complete) != 0) {
  34305. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  34306. + "resume interrupted", __func__, entity);
  34307. + ret = VCHIQ_ERROR;
  34308. + goto out;
  34309. + }
  34310. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  34311. + entity);
  34312. + }
  34313. +
  34314. + if (ret == VCHIQ_SUCCESS) {
  34315. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  34316. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  34317. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  34318. + /* Send the use notify to videocore */
  34319. + status = vchiq_send_remote_use_active(state);
  34320. + if (status == VCHIQ_SUCCESS)
  34321. + ack_cnt--;
  34322. + else
  34323. + atomic_add(ack_cnt,
  34324. + &arm_state->ka_use_ack_count);
  34325. + }
  34326. + }
  34327. +
  34328. +out:
  34329. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  34330. + return ret;
  34331. +}
  34332. +
  34333. +VCHIQ_STATUS_T
  34334. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  34335. +{
  34336. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34337. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  34338. + char entity[16];
  34339. + int *entity_uc;
  34340. + int local_uc, local_entity_uc;
  34341. +
  34342. + if (!arm_state)
  34343. + goto out;
  34344. +
  34345. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34346. +
  34347. + if (service) {
  34348. + sprintf(entity, "%c%c%c%c:%03d",
  34349. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  34350. + service->client_id);
  34351. + entity_uc = &service->service_use_count;
  34352. + } else {
  34353. + sprintf(entity, "PEER: ");
  34354. + entity_uc = &arm_state->peer_use_count;
  34355. + }
  34356. +
  34357. + write_lock_bh(&arm_state->susp_res_lock);
  34358. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  34359. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  34360. + WARN_ON(!arm_state->videocore_use_count);
  34361. + WARN_ON(!(*entity_uc));
  34362. + ret = VCHIQ_ERROR;
  34363. + goto unlock;
  34364. + }
  34365. + local_uc = --arm_state->videocore_use_count;
  34366. + local_entity_uc = --(*entity_uc);
  34367. +
  34368. + if (!vchiq_videocore_wanted(state)) {
  34369. + if (vchiq_platform_use_suspend_timer() &&
  34370. + !arm_state->resume_blocked) {
  34371. + /* Only use the timer if we're not trying to force
  34372. + * suspend (=> resume_blocked) */
  34373. + start_suspend_timer(arm_state);
  34374. + } else {
  34375. + vchiq_log_info(vchiq_susp_log_level,
  34376. + "%s %s count %d, state count %d - suspending",
  34377. + __func__, entity, *entity_uc,
  34378. + arm_state->videocore_use_count);
  34379. + vchiq_arm_vcsuspend(state);
  34380. + }
  34381. + } else
  34382. + vchiq_log_trace(vchiq_susp_log_level,
  34383. + "%s %s count %d, state count %d",
  34384. + __func__, entity, *entity_uc,
  34385. + arm_state->videocore_use_count);
  34386. +
  34387. +unlock:
  34388. + write_unlock_bh(&arm_state->susp_res_lock);
  34389. +
  34390. +out:
  34391. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  34392. + return ret;
  34393. +}
  34394. +
  34395. +void
  34396. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  34397. +{
  34398. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34399. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34400. + atomic_inc(&arm_state->ka_use_count);
  34401. + complete(&arm_state->ka_evt);
  34402. +}
  34403. +
  34404. +void
  34405. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  34406. +{
  34407. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34408. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34409. + atomic_inc(&arm_state->ka_release_count);
  34410. + complete(&arm_state->ka_evt);
  34411. +}
  34412. +
  34413. +VCHIQ_STATUS_T
  34414. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  34415. +{
  34416. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  34417. +}
  34418. +
  34419. +VCHIQ_STATUS_T
  34420. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  34421. +{
  34422. + return vchiq_release_internal(service->state, service);
  34423. +}
  34424. +
  34425. +VCHIQ_DEBUGFS_NODE_T *
  34426. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance)
  34427. +{
  34428. + return &instance->debugfs_node;
  34429. +}
  34430. +
  34431. +int
  34432. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  34433. +{
  34434. + VCHIQ_SERVICE_T *service;
  34435. + int use_count = 0, i;
  34436. + i = 0;
  34437. + while ((service = next_service_by_instance(instance->state,
  34438. + instance, &i)) != NULL) {
  34439. + use_count += service->service_use_count;
  34440. + unlock_service(service);
  34441. + }
  34442. + return use_count;
  34443. +}
  34444. +
  34445. +int
  34446. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance)
  34447. +{
  34448. + return instance->pid;
  34449. +}
  34450. +
  34451. +int
  34452. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance)
  34453. +{
  34454. + return instance->trace;
  34455. +}
  34456. +
  34457. +void
  34458. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace)
  34459. +{
  34460. + VCHIQ_SERVICE_T *service;
  34461. + int i;
  34462. + i = 0;
  34463. + while ((service = next_service_by_instance(instance->state,
  34464. + instance, &i)) != NULL) {
  34465. + service->trace = trace;
  34466. + unlock_service(service);
  34467. + }
  34468. + instance->trace = (trace != 0);
  34469. +}
  34470. +
  34471. +static void suspend_timer_callback(unsigned long context)
  34472. +{
  34473. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  34474. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34475. + if (!arm_state)
  34476. + goto out;
  34477. + vchiq_log_info(vchiq_susp_log_level,
  34478. + "%s - suspend timer expired - check suspend", __func__);
  34479. + vchiq_check_suspend(state);
  34480. +out:
  34481. + return;
  34482. +}
  34483. +
  34484. +VCHIQ_STATUS_T
  34485. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  34486. +{
  34487. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  34488. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  34489. + if (service) {
  34490. + ret = vchiq_use_internal(service->state, service,
  34491. + USE_TYPE_SERVICE_NO_RESUME);
  34492. + unlock_service(service);
  34493. + }
  34494. + return ret;
  34495. +}
  34496. +
  34497. +VCHIQ_STATUS_T
  34498. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  34499. +{
  34500. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  34501. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  34502. + if (service) {
  34503. + ret = vchiq_use_internal(service->state, service,
  34504. + USE_TYPE_SERVICE);
  34505. + unlock_service(service);
  34506. + }
  34507. + return ret;
  34508. +}
  34509. +
  34510. +VCHIQ_STATUS_T
  34511. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  34512. +{
  34513. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  34514. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  34515. + if (service) {
  34516. + ret = vchiq_release_internal(service->state, service);
  34517. + unlock_service(service);
  34518. + }
  34519. + return ret;
  34520. +}
  34521. +
  34522. +void
  34523. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  34524. +{
  34525. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34526. + int i, j = 0;
  34527. + /* Only dump 64 services */
  34528. + static const int local_max_services = 64;
  34529. + /* If there's more than 64 services, only dump ones with
  34530. + * non-zero counts */
  34531. + int only_nonzero = 0;
  34532. + static const char *nz = "<-- preventing suspend";
  34533. +
  34534. + enum vc_suspend_status vc_suspend_state;
  34535. + enum vc_resume_status vc_resume_state;
  34536. + int peer_count;
  34537. + int vc_use_count;
  34538. + int active_services;
  34539. + struct service_data_struct {
  34540. + int fourcc;
  34541. + int clientid;
  34542. + int use_count;
  34543. + } service_data[local_max_services];
  34544. +
  34545. + if (!arm_state)
  34546. + return;
  34547. +
  34548. + read_lock_bh(&arm_state->susp_res_lock);
  34549. + vc_suspend_state = arm_state->vc_suspend_state;
  34550. + vc_resume_state = arm_state->vc_resume_state;
  34551. + peer_count = arm_state->peer_use_count;
  34552. + vc_use_count = arm_state->videocore_use_count;
  34553. + active_services = state->unused_service;
  34554. + if (active_services > local_max_services)
  34555. + only_nonzero = 1;
  34556. +
  34557. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  34558. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  34559. + if (!service_ptr)
  34560. + continue;
  34561. +
  34562. + if (only_nonzero && !service_ptr->service_use_count)
  34563. + continue;
  34564. +
  34565. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  34566. + service_data[j].fourcc = service_ptr->base.fourcc;
  34567. + service_data[j].clientid = service_ptr->client_id;
  34568. + service_data[j++].use_count = service_ptr->
  34569. + service_use_count;
  34570. + }
  34571. + }
  34572. +
  34573. + read_unlock_bh(&arm_state->susp_res_lock);
  34574. +
  34575. + vchiq_log_warning(vchiq_susp_log_level,
  34576. + "-- Videcore suspend state: %s --",
  34577. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  34578. + vchiq_log_warning(vchiq_susp_log_level,
  34579. + "-- Videcore resume state: %s --",
  34580. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  34581. +
  34582. + if (only_nonzero)
  34583. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  34584. + "services (%d). Only dumping up to first %d services "
  34585. + "with non-zero use-count", active_services,
  34586. + local_max_services);
  34587. +
  34588. + for (i = 0; i < j; i++) {
  34589. + vchiq_log_warning(vchiq_susp_log_level,
  34590. + "----- %c%c%c%c:%d service count %d %s",
  34591. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  34592. + service_data[i].clientid,
  34593. + service_data[i].use_count,
  34594. + service_data[i].use_count ? nz : "");
  34595. + }
  34596. + vchiq_log_warning(vchiq_susp_log_level,
  34597. + "----- VCHIQ use count count %d", peer_count);
  34598. + vchiq_log_warning(vchiq_susp_log_level,
  34599. + "--- Overall vchiq instance use count %d", vc_use_count);
  34600. +
  34601. + vchiq_dump_platform_use_state(state);
  34602. +}
  34603. +
  34604. +VCHIQ_STATUS_T
  34605. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  34606. +{
  34607. + VCHIQ_ARM_STATE_T *arm_state;
  34608. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  34609. +
  34610. + if (!service || !service->state)
  34611. + goto out;
  34612. +
  34613. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  34614. +
  34615. + arm_state = vchiq_platform_get_arm_state(service->state);
  34616. +
  34617. + read_lock_bh(&arm_state->susp_res_lock);
  34618. + if (service->service_use_count)
  34619. + ret = VCHIQ_SUCCESS;
  34620. + read_unlock_bh(&arm_state->susp_res_lock);
  34621. +
  34622. + if (ret == VCHIQ_ERROR) {
  34623. + vchiq_log_error(vchiq_susp_log_level,
  34624. + "%s ERROR - %c%c%c%c:%d service count %d, "
  34625. + "state count %d, videocore suspend state %s", __func__,
  34626. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  34627. + service->client_id, service->service_use_count,
  34628. + arm_state->videocore_use_count,
  34629. + suspend_state_names[arm_state->vc_suspend_state +
  34630. + VC_SUSPEND_NUM_OFFSET]);
  34631. + vchiq_dump_service_use_state(service->state);
  34632. + }
  34633. +out:
  34634. + return ret;
  34635. +}
  34636. +
  34637. +/* stub functions */
  34638. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  34639. +{
  34640. + (void)state;
  34641. +}
  34642. +
  34643. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  34644. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  34645. +{
  34646. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  34647. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  34648. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  34649. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  34650. + write_lock_bh(&arm_state->susp_res_lock);
  34651. + if (!arm_state->first_connect) {
  34652. + char threadname[10];
  34653. + arm_state->first_connect = 1;
  34654. + write_unlock_bh(&arm_state->susp_res_lock);
  34655. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  34656. + state->id);
  34657. + arm_state->ka_thread = kthread_create(
  34658. + &vchiq_keepalive_thread_func,
  34659. + (void *)state,
  34660. + threadname);
  34661. + if (arm_state->ka_thread == NULL) {
  34662. + vchiq_log_error(vchiq_susp_log_level,
  34663. + "vchiq: FATAL: couldn't create thread %s",
  34664. + threadname);
  34665. + } else {
  34666. + wake_up_process(arm_state->ka_thread);
  34667. + }
  34668. + } else
  34669. + write_unlock_bh(&arm_state->susp_res_lock);
  34670. + }
  34671. +}
  34672. +
  34673. +
  34674. +/****************************************************************************
  34675. +*
  34676. +* vchiq_init - called when the module is loaded.
  34677. +*
  34678. +***************************************************************************/
  34679. +
  34680. +static int __init
  34681. +vchiq_init(void)
  34682. +{
  34683. + int err;
  34684. + void *ptr_err;
  34685. +
  34686. + /* create debugfs entries */
  34687. + err = vchiq_debugfs_init();
  34688. + if (err != 0)
  34689. + goto failed_debugfs_init;
  34690. +
  34691. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  34692. + if (err != 0) {
  34693. + vchiq_log_error(vchiq_arm_log_level,
  34694. + "Unable to allocate device number");
  34695. + goto failed_alloc_chrdev;
  34696. + }
  34697. + cdev_init(&vchiq_cdev, &vchiq_fops);
  34698. + vchiq_cdev.owner = THIS_MODULE;
  34699. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  34700. + if (err != 0) {
  34701. + vchiq_log_error(vchiq_arm_log_level,
  34702. + "Unable to register device");
  34703. + goto failed_cdev_add;
  34704. + }
  34705. +
  34706. + /* create sysfs entries */
  34707. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  34708. + ptr_err = vchiq_class;
  34709. + if (IS_ERR(ptr_err))
  34710. + goto failed_class_create;
  34711. +
  34712. + vchiq_dev = device_create(vchiq_class, NULL,
  34713. + vchiq_devid, NULL, "vchiq");
  34714. + ptr_err = vchiq_dev;
  34715. + if (IS_ERR(ptr_err))
  34716. + goto failed_device_create;
  34717. +
  34718. + err = vchiq_platform_init(&g_state);
  34719. + if (err != 0)
  34720. + goto failed_platform_init;
  34721. +
  34722. + vchiq_log_info(vchiq_arm_log_level,
  34723. + "vchiq: initialised - version %d (min %d), device %d.%d",
  34724. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  34725. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  34726. +
  34727. + return 0;
  34728. +
  34729. +failed_platform_init:
  34730. + device_destroy(vchiq_class, vchiq_devid);
  34731. +failed_device_create:
  34732. + class_destroy(vchiq_class);
  34733. +failed_class_create:
  34734. + cdev_del(&vchiq_cdev);
  34735. + err = PTR_ERR(ptr_err);
  34736. +failed_cdev_add:
  34737. + unregister_chrdev_region(vchiq_devid, 1);
  34738. +failed_alloc_chrdev:
  34739. + vchiq_debugfs_deinit();
  34740. +failed_debugfs_init:
  34741. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  34742. + return err;
  34743. +}
  34744. +
  34745. +/****************************************************************************
  34746. +*
  34747. +* vchiq_exit - called when the module is unloaded.
  34748. +*
  34749. +***************************************************************************/
  34750. +
  34751. +static void __exit
  34752. +vchiq_exit(void)
  34753. +{
  34754. + vchiq_platform_exit(&g_state);
  34755. + device_destroy(vchiq_class, vchiq_devid);
  34756. + class_destroy(vchiq_class);
  34757. + cdev_del(&vchiq_cdev);
  34758. + unregister_chrdev_region(vchiq_devid, 1);
  34759. +}
  34760. +
  34761. +module_init(vchiq_init);
  34762. +module_exit(vchiq_exit);
  34763. +MODULE_LICENSE("GPL");
  34764. +MODULE_AUTHOR("Broadcom Corporation");
  34765. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  34766. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  34767. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2015-03-09 10:39:30.718893733 +0100
  34768. @@ -0,0 +1,223 @@
  34769. +/**
  34770. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  34771. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34772. + *
  34773. + * Redistribution and use in source and binary forms, with or without
  34774. + * modification, are permitted provided that the following conditions
  34775. + * are met:
  34776. + * 1. Redistributions of source code must retain the above copyright
  34777. + * notice, this list of conditions, and the following disclaimer,
  34778. + * without modification.
  34779. + * 2. Redistributions in binary form must reproduce the above copyright
  34780. + * notice, this list of conditions and the following disclaimer in the
  34781. + * documentation and/or other materials provided with the distribution.
  34782. + * 3. The names of the above-listed copyright holders may not be used
  34783. + * to endorse or promote products derived from this software without
  34784. + * specific prior written permission.
  34785. + *
  34786. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34787. + * GNU General Public License ("GPL") version 2, as published by the Free
  34788. + * Software Foundation.
  34789. + *
  34790. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34791. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34792. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34793. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34794. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34795. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34796. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34797. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34798. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34799. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34800. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34801. + */
  34802. +
  34803. +#ifndef VCHIQ_ARM_H
  34804. +#define VCHIQ_ARM_H
  34805. +
  34806. +#include <linux/mutex.h>
  34807. +#include <linux/semaphore.h>
  34808. +#include <linux/atomic.h>
  34809. +#include "vchiq_core.h"
  34810. +#include "vchiq_debugfs.h"
  34811. +
  34812. +
  34813. +enum vc_suspend_status {
  34814. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  34815. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  34816. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  34817. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  34818. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  34819. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  34820. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  34821. +};
  34822. +
  34823. +enum vc_resume_status {
  34824. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  34825. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  34826. + VC_RESUME_REQUESTED, /* User has requested resume */
  34827. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  34828. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  34829. +};
  34830. +
  34831. +
  34832. +enum USE_TYPE_E {
  34833. + USE_TYPE_SERVICE,
  34834. + USE_TYPE_SERVICE_NO_RESUME,
  34835. + USE_TYPE_VCHIQ
  34836. +};
  34837. +
  34838. +
  34839. +
  34840. +typedef struct vchiq_arm_state_struct {
  34841. + /* Keepalive-related data */
  34842. + struct task_struct *ka_thread;
  34843. + struct completion ka_evt;
  34844. + atomic_t ka_use_count;
  34845. + atomic_t ka_use_ack_count;
  34846. + atomic_t ka_release_count;
  34847. +
  34848. + struct completion vc_suspend_complete;
  34849. + struct completion vc_resume_complete;
  34850. +
  34851. + rwlock_t susp_res_lock;
  34852. + enum vc_suspend_status vc_suspend_state;
  34853. + enum vc_resume_status vc_resume_state;
  34854. +
  34855. + unsigned int wake_address;
  34856. +
  34857. + struct timer_list suspend_timer;
  34858. + int suspend_timer_timeout;
  34859. + int suspend_timer_running;
  34860. +
  34861. + /* Global use count for videocore.
  34862. + ** This is equal to the sum of the use counts for all services. When
  34863. + ** this hits zero the videocore suspend procedure will be initiated.
  34864. + */
  34865. + int videocore_use_count;
  34866. +
  34867. + /* Use count to track requests from videocore peer.
  34868. + ** This use count is not associated with a service, so needs to be
  34869. + ** tracked separately with the state.
  34870. + */
  34871. + int peer_use_count;
  34872. +
  34873. + /* Flag to indicate whether resume is blocked. This happens when the
  34874. + ** ARM is suspending
  34875. + */
  34876. + struct completion resume_blocker;
  34877. + int resume_blocked;
  34878. + struct completion blocked_blocker;
  34879. + int blocked_count;
  34880. +
  34881. + int autosuspend_override;
  34882. +
  34883. + /* Flag to indicate that the first vchiq connect has made it through.
  34884. + ** This means that both sides should be fully ready, and we should
  34885. + ** be able to suspend after this point.
  34886. + */
  34887. + int first_connect;
  34888. +
  34889. + unsigned long long suspend_start_time;
  34890. + unsigned long long sleep_start_time;
  34891. + unsigned long long resume_start_time;
  34892. + unsigned long long last_wake_time;
  34893. +
  34894. +} VCHIQ_ARM_STATE_T;
  34895. +
  34896. +extern int vchiq_arm_log_level;
  34897. +extern int vchiq_susp_log_level;
  34898. +
  34899. +extern int __init
  34900. +vchiq_platform_init(VCHIQ_STATE_T *state);
  34901. +
  34902. +extern void __exit
  34903. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  34904. +
  34905. +extern VCHIQ_STATE_T *
  34906. +vchiq_get_state(void);
  34907. +
  34908. +extern VCHIQ_STATUS_T
  34909. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  34910. +
  34911. +extern VCHIQ_STATUS_T
  34912. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  34913. +
  34914. +extern int
  34915. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  34916. +
  34917. +extern VCHIQ_STATUS_T
  34918. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  34919. +
  34920. +extern VCHIQ_STATUS_T
  34921. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  34922. +
  34923. +extern int
  34924. +vchiq_check_resume(VCHIQ_STATE_T *state);
  34925. +
  34926. +extern void
  34927. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  34928. + VCHIQ_STATUS_T
  34929. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  34930. +
  34931. +extern VCHIQ_STATUS_T
  34932. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  34933. +
  34934. +extern VCHIQ_STATUS_T
  34935. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  34936. +
  34937. +extern VCHIQ_STATUS_T
  34938. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  34939. +
  34940. +extern int
  34941. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  34942. +
  34943. +extern int
  34944. +vchiq_platform_use_suspend_timer(void);
  34945. +
  34946. +extern void
  34947. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  34948. +
  34949. +extern void
  34950. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  34951. +
  34952. +extern VCHIQ_ARM_STATE_T*
  34953. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  34954. +
  34955. +extern int
  34956. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  34957. +
  34958. +extern VCHIQ_STATUS_T
  34959. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  34960. + enum USE_TYPE_E use_type);
  34961. +extern VCHIQ_STATUS_T
  34962. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  34963. +
  34964. +extern VCHIQ_DEBUGFS_NODE_T *
  34965. +vchiq_instance_get_debugfs_node(VCHIQ_INSTANCE_T instance);
  34966. +
  34967. +extern int
  34968. +vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance);
  34969. +
  34970. +extern int
  34971. +vchiq_instance_get_pid(VCHIQ_INSTANCE_T instance);
  34972. +
  34973. +extern int
  34974. +vchiq_instance_get_trace(VCHIQ_INSTANCE_T instance);
  34975. +
  34976. +extern void
  34977. +vchiq_instance_set_trace(VCHIQ_INSTANCE_T instance, int trace);
  34978. +
  34979. +extern void
  34980. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  34981. + enum vc_suspend_status new_state);
  34982. +
  34983. +extern void
  34984. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  34985. + enum vc_resume_status new_state);
  34986. +
  34987. +extern void
  34988. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  34989. +
  34990. +
  34991. +#endif /* VCHIQ_ARM_H */
  34992. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  34993. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  34994. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2015-03-09 10:39:30.718893733 +0100
  34995. @@ -0,0 +1,37 @@
  34996. +/**
  34997. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  34998. + *
  34999. + * Redistribution and use in source and binary forms, with or without
  35000. + * modification, are permitted provided that the following conditions
  35001. + * are met:
  35002. + * 1. Redistributions of source code must retain the above copyright
  35003. + * notice, this list of conditions, and the following disclaimer,
  35004. + * without modification.
  35005. + * 2. Redistributions in binary form must reproduce the above copyright
  35006. + * notice, this list of conditions and the following disclaimer in the
  35007. + * documentation and/or other materials provided with the distribution.
  35008. + * 3. The names of the above-listed copyright holders may not be used
  35009. + * to endorse or promote products derived from this software without
  35010. + * specific prior written permission.
  35011. + *
  35012. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35013. + * GNU General Public License ("GPL") version 2, as published by the Free
  35014. + * Software Foundation.
  35015. + *
  35016. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35017. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35018. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35019. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35020. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35021. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35022. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35023. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35024. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35025. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35026. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35027. + */
  35028. +
  35029. +const char *vchiq_get_build_hostname(void);
  35030. +const char *vchiq_get_build_version(void);
  35031. +const char *vchiq_get_build_time(void);
  35032. +const char *vchiq_get_build_date(void);
  35033. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  35034. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  35035. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2015-03-10 17:26:50.554216692 +0100
  35036. @@ -0,0 +1,66 @@
  35037. +/**
  35038. + * Copyright (c) 2010-2014 Broadcom. All rights reserved.
  35039. + *
  35040. + * Redistribution and use in source and binary forms, with or without
  35041. + * modification, are permitted provided that the following conditions
  35042. + * are met:
  35043. + * 1. Redistributions of source code must retain the above copyright
  35044. + * notice, this list of conditions, and the following disclaimer,
  35045. + * without modification.
  35046. + * 2. Redistributions in binary form must reproduce the above copyright
  35047. + * notice, this list of conditions and the following disclaimer in the
  35048. + * documentation and/or other materials provided with the distribution.
  35049. + * 3. The names of the above-listed copyright holders may not be used
  35050. + * to endorse or promote products derived from this software without
  35051. + * specific prior written permission.
  35052. + *
  35053. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35054. + * GNU General Public License ("GPL") version 2, as published by the Free
  35055. + * Software Foundation.
  35056. + *
  35057. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35058. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35059. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35060. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35061. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35062. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35063. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35064. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35065. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35066. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35067. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35068. + */
  35069. +
  35070. +#ifndef VCHIQ_CFG_H
  35071. +#define VCHIQ_CFG_H
  35072. +
  35073. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  35074. +/* The version of VCHIQ - change with any non-trivial change */
  35075. +#define VCHIQ_VERSION 7
  35076. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  35077. +** incompatible change */
  35078. +#define VCHIQ_VERSION_MIN 3
  35079. +
  35080. +/* The version that introduced the VCHIQ_IOC_LIB_VERSION ioctl */
  35081. +#define VCHIQ_VERSION_LIB_VERSION 7
  35082. +
  35083. +/* The version that introduced the VCHIQ_IOC_CLOSE_DELIVERED ioctl */
  35084. +#define VCHIQ_VERSION_CLOSE_DELIVERED 7
  35085. +
  35086. +#define VCHIQ_MAX_STATES 1
  35087. +#define VCHIQ_MAX_SERVICES 4096
  35088. +#define VCHIQ_MAX_SLOTS 128
  35089. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  35090. +
  35091. +#define VCHIQ_NUM_CURRENT_BULKS 32
  35092. +#define VCHIQ_NUM_SERVICE_BULKS 4
  35093. +
  35094. +#ifndef VCHIQ_ENABLE_DEBUG
  35095. +#define VCHIQ_ENABLE_DEBUG 1
  35096. +#endif
  35097. +
  35098. +#ifndef VCHIQ_ENABLE_STATS
  35099. +#define VCHIQ_ENABLE_STATS 1
  35100. +#endif
  35101. +
  35102. +#endif /* VCHIQ_CFG_H */
  35103. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  35104. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  35105. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2015-03-09 10:39:30.722893733 +0100
  35106. @@ -0,0 +1,120 @@
  35107. +/**
  35108. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35109. + *
  35110. + * Redistribution and use in source and binary forms, with or without
  35111. + * modification, are permitted provided that the following conditions
  35112. + * are met:
  35113. + * 1. Redistributions of source code must retain the above copyright
  35114. + * notice, this list of conditions, and the following disclaimer,
  35115. + * without modification.
  35116. + * 2. Redistributions in binary form must reproduce the above copyright
  35117. + * notice, this list of conditions and the following disclaimer in the
  35118. + * documentation and/or other materials provided with the distribution.
  35119. + * 3. The names of the above-listed copyright holders may not be used
  35120. + * to endorse or promote products derived from this software without
  35121. + * specific prior written permission.
  35122. + *
  35123. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35124. + * GNU General Public License ("GPL") version 2, as published by the Free
  35125. + * Software Foundation.
  35126. + *
  35127. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35128. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35129. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35130. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35131. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35132. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35133. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35134. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35135. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35136. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35137. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35138. + */
  35139. +
  35140. +#include "vchiq_connected.h"
  35141. +#include "vchiq_core.h"
  35142. +#include "vchiq_killable.h"
  35143. +#include <linux/module.h>
  35144. +#include <linux/mutex.h>
  35145. +
  35146. +#define MAX_CALLBACKS 10
  35147. +
  35148. +static int g_connected;
  35149. +static int g_num_deferred_callbacks;
  35150. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  35151. +static int g_once_init;
  35152. +static struct mutex g_connected_mutex;
  35153. +
  35154. +/****************************************************************************
  35155. +*
  35156. +* Function to initialize our lock.
  35157. +*
  35158. +***************************************************************************/
  35159. +
  35160. +static void connected_init(void)
  35161. +{
  35162. + if (!g_once_init) {
  35163. + mutex_init(&g_connected_mutex);
  35164. + g_once_init = 1;
  35165. + }
  35166. +}
  35167. +
  35168. +/****************************************************************************
  35169. +*
  35170. +* This function is used to defer initialization until the vchiq stack is
  35171. +* initialized. If the stack is already initialized, then the callback will
  35172. +* be made immediately, otherwise it will be deferred until
  35173. +* vchiq_call_connected_callbacks is called.
  35174. +*
  35175. +***************************************************************************/
  35176. +
  35177. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  35178. +{
  35179. + connected_init();
  35180. +
  35181. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  35182. + return;
  35183. +
  35184. + if (g_connected)
  35185. + /* We're already connected. Call the callback immediately. */
  35186. +
  35187. + callback();
  35188. + else {
  35189. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  35190. + vchiq_log_error(vchiq_core_log_level,
  35191. + "There already %d callback registered - "
  35192. + "please increase MAX_CALLBACKS",
  35193. + g_num_deferred_callbacks);
  35194. + else {
  35195. + g_deferred_callback[g_num_deferred_callbacks] =
  35196. + callback;
  35197. + g_num_deferred_callbacks++;
  35198. + }
  35199. + }
  35200. + mutex_unlock(&g_connected_mutex);
  35201. +}
  35202. +
  35203. +/****************************************************************************
  35204. +*
  35205. +* This function is called by the vchiq stack once it has been connected to
  35206. +* the videocore and clients can start to use the stack.
  35207. +*
  35208. +***************************************************************************/
  35209. +
  35210. +void vchiq_call_connected_callbacks(void)
  35211. +{
  35212. + int i;
  35213. +
  35214. + connected_init();
  35215. +
  35216. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  35217. + return;
  35218. +
  35219. + for (i = 0; i < g_num_deferred_callbacks; i++)
  35220. + g_deferred_callback[i]();
  35221. +
  35222. + g_num_deferred_callbacks = 0;
  35223. + g_connected = 1;
  35224. + mutex_unlock(&g_connected_mutex);
  35225. +}
  35226. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  35227. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  35228. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  35229. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2015-03-09 10:39:30.722893733 +0100
  35230. @@ -0,0 +1,50 @@
  35231. +/**
  35232. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35233. + *
  35234. + * Redistribution and use in source and binary forms, with or without
  35235. + * modification, are permitted provided that the following conditions
  35236. + * are met:
  35237. + * 1. Redistributions of source code must retain the above copyright
  35238. + * notice, this list of conditions, and the following disclaimer,
  35239. + * without modification.
  35240. + * 2. Redistributions in binary form must reproduce the above copyright
  35241. + * notice, this list of conditions and the following disclaimer in the
  35242. + * documentation and/or other materials provided with the distribution.
  35243. + * 3. The names of the above-listed copyright holders may not be used
  35244. + * to endorse or promote products derived from this software without
  35245. + * specific prior written permission.
  35246. + *
  35247. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35248. + * GNU General Public License ("GPL") version 2, as published by the Free
  35249. + * Software Foundation.
  35250. + *
  35251. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35252. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35253. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35254. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35255. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35256. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35257. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35258. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35259. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35260. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35261. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35262. + */
  35263. +
  35264. +#ifndef VCHIQ_CONNECTED_H
  35265. +#define VCHIQ_CONNECTED_H
  35266. +
  35267. +/* ---- Include Files ----------------------------------------------------- */
  35268. +
  35269. +/* ---- Constants and Types ---------------------------------------------- */
  35270. +
  35271. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  35272. +
  35273. +/* ---- Variable Externs ------------------------------------------------- */
  35274. +
  35275. +/* ---- Function Prototypes ---------------------------------------------- */
  35276. +
  35277. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  35278. +void vchiq_call_connected_callbacks(void);
  35279. +
  35280. +#endif /* VCHIQ_CONNECTED_H */
  35281. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  35282. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  35283. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2015-03-10 17:26:50.554216692 +0100
  35284. @@ -0,0 +1,3862 @@
  35285. +/**
  35286. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  35287. + *
  35288. + * Redistribution and use in source and binary forms, with or without
  35289. + * modification, are permitted provided that the following conditions
  35290. + * are met:
  35291. + * 1. Redistributions of source code must retain the above copyright
  35292. + * notice, this list of conditions, and the following disclaimer,
  35293. + * without modification.
  35294. + * 2. Redistributions in binary form must reproduce the above copyright
  35295. + * notice, this list of conditions and the following disclaimer in the
  35296. + * documentation and/or other materials provided with the distribution.
  35297. + * 3. The names of the above-listed copyright holders may not be used
  35298. + * to endorse or promote products derived from this software without
  35299. + * specific prior written permission.
  35300. + *
  35301. + * ALTERNATIVELY, this software may be distributed under the terms of the
  35302. + * GNU General Public License ("GPL") version 2, as published by the Free
  35303. + * Software Foundation.
  35304. + *
  35305. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  35306. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  35307. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35308. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35309. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  35310. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35311. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35312. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35313. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35314. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35315. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35316. + */
  35317. +
  35318. +#include "vchiq_core.h"
  35319. +#include "vchiq_killable.h"
  35320. +
  35321. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  35322. +
  35323. +#define HANDLE_STATE_SHIFT 12
  35324. +
  35325. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  35326. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  35327. +#define SLOT_INDEX_FROM_DATA(state, data) \
  35328. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  35329. + VCHIQ_SLOT_SIZE)
  35330. +#define SLOT_INDEX_FROM_INFO(state, info) \
  35331. + ((unsigned int)(info - state->slot_info))
  35332. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  35333. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  35334. +
  35335. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  35336. +
  35337. +#define SRVTRACE_LEVEL(srv) \
  35338. + (((srv) && (srv)->trace) ? VCHIQ_LOG_TRACE : vchiq_core_msg_log_level)
  35339. +#define SRVTRACE_ENABLED(srv, lev) \
  35340. + (((srv) && (srv)->trace) || (vchiq_core_msg_log_level >= (lev)))
  35341. +
  35342. +struct vchiq_open_payload {
  35343. + int fourcc;
  35344. + int client_id;
  35345. + short version;
  35346. + short version_min;
  35347. +};
  35348. +
  35349. +struct vchiq_openack_payload {
  35350. + short version;
  35351. +};
  35352. +
  35353. +/* we require this for consistency between endpoints */
  35354. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  35355. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  35356. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  35357. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  35358. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  35359. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  35360. +
  35361. +/* Run time control of log level, based on KERN_XXX level. */
  35362. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  35363. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  35364. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  35365. +
  35366. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  35367. +
  35368. +static DEFINE_SPINLOCK(service_spinlock);
  35369. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  35370. +DEFINE_SPINLOCK(quota_spinlock);
  35371. +
  35372. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  35373. +static unsigned int handle_seq;
  35374. +
  35375. +static const char *const srvstate_names[] = {
  35376. + "FREE",
  35377. + "HIDDEN",
  35378. + "LISTENING",
  35379. + "OPENING",
  35380. + "OPEN",
  35381. + "OPENSYNC",
  35382. + "CLOSESENT",
  35383. + "CLOSERECVD",
  35384. + "CLOSEWAIT",
  35385. + "CLOSED"
  35386. +};
  35387. +
  35388. +static const char *const reason_names[] = {
  35389. + "SERVICE_OPENED",
  35390. + "SERVICE_CLOSED",
  35391. + "MESSAGE_AVAILABLE",
  35392. + "BULK_TRANSMIT_DONE",
  35393. + "BULK_RECEIVE_DONE",
  35394. + "BULK_TRANSMIT_ABORTED",
  35395. + "BULK_RECEIVE_ABORTED"
  35396. +};
  35397. +
  35398. +static const char *const conn_state_names[] = {
  35399. + "DISCONNECTED",
  35400. + "CONNECTING",
  35401. + "CONNECTED",
  35402. + "PAUSING",
  35403. + "PAUSE_SENT",
  35404. + "PAUSED",
  35405. + "RESUMING",
  35406. + "PAUSE_TIMEOUT",
  35407. + "RESUME_TIMEOUT"
  35408. +};
  35409. +
  35410. +
  35411. +static void
  35412. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  35413. +
  35414. +static const char *msg_type_str(unsigned int msg_type)
  35415. +{
  35416. + switch (msg_type) {
  35417. + case VCHIQ_MSG_PADDING: return "PADDING";
  35418. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  35419. + case VCHIQ_MSG_OPEN: return "OPEN";
  35420. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  35421. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  35422. + case VCHIQ_MSG_DATA: return "DATA";
  35423. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  35424. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  35425. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  35426. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  35427. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  35428. + case VCHIQ_MSG_RESUME: return "RESUME";
  35429. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  35430. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  35431. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  35432. + }
  35433. + return "???";
  35434. +}
  35435. +
  35436. +static inline void
  35437. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  35438. +{
  35439. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  35440. + service->state->id, service->localport,
  35441. + srvstate_names[service->srvstate],
  35442. + srvstate_names[newstate]);
  35443. + service->srvstate = newstate;
  35444. +}
  35445. +
  35446. +VCHIQ_SERVICE_T *
  35447. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  35448. +{
  35449. + VCHIQ_SERVICE_T *service;
  35450. +
  35451. + spin_lock(&service_spinlock);
  35452. + service = handle_to_service(handle);
  35453. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  35454. + (service->handle == handle)) {
  35455. + BUG_ON(service->ref_count == 0);
  35456. + service->ref_count++;
  35457. + } else
  35458. + service = NULL;
  35459. + spin_unlock(&service_spinlock);
  35460. +
  35461. + if (!service)
  35462. + vchiq_log_info(vchiq_core_log_level,
  35463. + "Invalid service handle 0x%x", handle);
  35464. +
  35465. + return service;
  35466. +}
  35467. +
  35468. +VCHIQ_SERVICE_T *
  35469. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  35470. +{
  35471. + VCHIQ_SERVICE_T *service = NULL;
  35472. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  35473. + spin_lock(&service_spinlock);
  35474. + service = state->services[localport];
  35475. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  35476. + BUG_ON(service->ref_count == 0);
  35477. + service->ref_count++;
  35478. + } else
  35479. + service = NULL;
  35480. + spin_unlock(&service_spinlock);
  35481. + }
  35482. +
  35483. + if (!service)
  35484. + vchiq_log_info(vchiq_core_log_level,
  35485. + "Invalid port %d", localport);
  35486. +
  35487. + return service;
  35488. +}
  35489. +
  35490. +VCHIQ_SERVICE_T *
  35491. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  35492. + VCHIQ_SERVICE_HANDLE_T handle) {
  35493. + VCHIQ_SERVICE_T *service;
  35494. +
  35495. + spin_lock(&service_spinlock);
  35496. + service = handle_to_service(handle);
  35497. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  35498. + (service->handle == handle) &&
  35499. + (service->instance == instance)) {
  35500. + BUG_ON(service->ref_count == 0);
  35501. + service->ref_count++;
  35502. + } else
  35503. + service = NULL;
  35504. + spin_unlock(&service_spinlock);
  35505. +
  35506. + if (!service)
  35507. + vchiq_log_info(vchiq_core_log_level,
  35508. + "Invalid service handle 0x%x", handle);
  35509. +
  35510. + return service;
  35511. +}
  35512. +
  35513. +VCHIQ_SERVICE_T *
  35514. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  35515. + VCHIQ_SERVICE_HANDLE_T handle) {
  35516. + VCHIQ_SERVICE_T *service;
  35517. +
  35518. + spin_lock(&service_spinlock);
  35519. + service = handle_to_service(handle);
  35520. + if (service &&
  35521. + ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  35522. + (service->srvstate == VCHIQ_SRVSTATE_CLOSED)) &&
  35523. + (service->handle == handle) &&
  35524. + (service->instance == instance)) {
  35525. + BUG_ON(service->ref_count == 0);
  35526. + service->ref_count++;
  35527. + } else
  35528. + service = NULL;
  35529. + spin_unlock(&service_spinlock);
  35530. +
  35531. + if (!service)
  35532. + vchiq_log_info(vchiq_core_log_level,
  35533. + "Invalid service handle 0x%x", handle);
  35534. +
  35535. + return service;
  35536. +}
  35537. +
  35538. +VCHIQ_SERVICE_T *
  35539. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  35540. + int *pidx)
  35541. +{
  35542. + VCHIQ_SERVICE_T *service = NULL;
  35543. + int idx = *pidx;
  35544. +
  35545. + spin_lock(&service_spinlock);
  35546. + while (idx < state->unused_service) {
  35547. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  35548. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  35549. + (srv->instance == instance)) {
  35550. + service = srv;
  35551. + BUG_ON(service->ref_count == 0);
  35552. + service->ref_count++;
  35553. + break;
  35554. + }
  35555. + }
  35556. + spin_unlock(&service_spinlock);
  35557. +
  35558. + *pidx = idx;
  35559. +
  35560. + return service;
  35561. +}
  35562. +
  35563. +void
  35564. +lock_service(VCHIQ_SERVICE_T *service)
  35565. +{
  35566. + spin_lock(&service_spinlock);
  35567. + BUG_ON(!service || (service->ref_count == 0));
  35568. + if (service)
  35569. + service->ref_count++;
  35570. + spin_unlock(&service_spinlock);
  35571. +}
  35572. +
  35573. +void
  35574. +unlock_service(VCHIQ_SERVICE_T *service)
  35575. +{
  35576. + VCHIQ_STATE_T *state = service->state;
  35577. + spin_lock(&service_spinlock);
  35578. + BUG_ON(!service || (service->ref_count == 0));
  35579. + if (service && service->ref_count) {
  35580. + service->ref_count--;
  35581. + if (!service->ref_count) {
  35582. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  35583. + state->services[service->localport] = NULL;
  35584. + } else
  35585. + service = NULL;
  35586. + }
  35587. + spin_unlock(&service_spinlock);
  35588. +
  35589. + if (service && service->userdata_term)
  35590. + service->userdata_term(service->base.userdata);
  35591. +
  35592. + kfree(service);
  35593. +}
  35594. +
  35595. +int
  35596. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  35597. +{
  35598. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  35599. + int id;
  35600. +
  35601. + id = service ? service->client_id : 0;
  35602. + if (service)
  35603. + unlock_service(service);
  35604. +
  35605. + return id;
  35606. +}
  35607. +
  35608. +void *
  35609. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  35610. +{
  35611. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  35612. +
  35613. + return service ? service->base.userdata : NULL;
  35614. +}
  35615. +
  35616. +int
  35617. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  35618. +{
  35619. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  35620. +
  35621. + return service ? service->base.fourcc : 0;
  35622. +}
  35623. +
  35624. +static void
  35625. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  35626. +{
  35627. + VCHIQ_STATE_T *state = service->state;
  35628. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  35629. +
  35630. + service->closing = 1;
  35631. +
  35632. + /* Synchronise with other threads. */
  35633. + mutex_lock(&state->recycle_mutex);
  35634. + mutex_unlock(&state->recycle_mutex);
  35635. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  35636. + /* If we're pausing then the slot_mutex is held until resume
  35637. + * by the slot handler. Therefore don't try to acquire this
  35638. + * mutex if we're the slot handler and in the pause sent state.
  35639. + * We don't need to in this case anyway. */
  35640. + mutex_lock(&state->slot_mutex);
  35641. + mutex_unlock(&state->slot_mutex);
  35642. + }
  35643. +
  35644. + /* Unblock any sending thread. */
  35645. + service_quota = &state->service_quotas[service->localport];
  35646. + up(&service_quota->quota_event);
  35647. +}
  35648. +
  35649. +static void
  35650. +mark_service_closing(VCHIQ_SERVICE_T *service)
  35651. +{
  35652. + mark_service_closing_internal(service, 0);
  35653. +}
  35654. +
  35655. +static inline VCHIQ_STATUS_T
  35656. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  35657. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  35658. +{
  35659. + VCHIQ_STATUS_T status;
  35660. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  35661. + service->state->id, service->localport, reason_names[reason],
  35662. + (unsigned int)header, (unsigned int)bulk_userdata);
  35663. + status = service->base.callback(reason, header, service->handle,
  35664. + bulk_userdata);
  35665. + if (status == VCHIQ_ERROR) {
  35666. + vchiq_log_warning(vchiq_core_log_level,
  35667. + "%d: ignoring ERROR from callback to service %x",
  35668. + service->state->id, service->handle);
  35669. + status = VCHIQ_SUCCESS;
  35670. + }
  35671. + return status;
  35672. +}
  35673. +
  35674. +inline void
  35675. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  35676. +{
  35677. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  35678. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  35679. + conn_state_names[oldstate],
  35680. + conn_state_names[newstate]);
  35681. + state->conn_state = newstate;
  35682. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  35683. +}
  35684. +
  35685. +static inline void
  35686. +remote_event_create(REMOTE_EVENT_T *event)
  35687. +{
  35688. + event->armed = 0;
  35689. + /* Don't clear the 'fired' flag because it may already have been set
  35690. + ** by the other side. */
  35691. + sema_init(event->event, 0);
  35692. +}
  35693. +
  35694. +static inline void
  35695. +remote_event_destroy(REMOTE_EVENT_T *event)
  35696. +{
  35697. + (void)event;
  35698. +}
  35699. +
  35700. +static inline int
  35701. +remote_event_wait(REMOTE_EVENT_T *event)
  35702. +{
  35703. + if (!event->fired) {
  35704. + event->armed = 1;
  35705. + dsb();
  35706. + if (!event->fired) {
  35707. + if (down_interruptible(event->event) != 0) {
  35708. + event->armed = 0;
  35709. + return 0;
  35710. + }
  35711. + }
  35712. + event->armed = 0;
  35713. + wmb();
  35714. + }
  35715. +
  35716. + event->fired = 0;
  35717. + return 1;
  35718. +}
  35719. +
  35720. +static inline void
  35721. +remote_event_signal_local(REMOTE_EVENT_T *event)
  35722. +{
  35723. + event->armed = 0;
  35724. + up(event->event);
  35725. +}
  35726. +
  35727. +static inline void
  35728. +remote_event_poll(REMOTE_EVENT_T *event)
  35729. +{
  35730. + if (event->fired && event->armed)
  35731. + remote_event_signal_local(event);
  35732. +}
  35733. +
  35734. +void
  35735. +remote_event_pollall(VCHIQ_STATE_T *state)
  35736. +{
  35737. + remote_event_poll(&state->local->sync_trigger);
  35738. + remote_event_poll(&state->local->sync_release);
  35739. + remote_event_poll(&state->local->trigger);
  35740. + remote_event_poll(&state->local->recycle);
  35741. +}
  35742. +
  35743. +/* Round up message sizes so that any space at the end of a slot is always big
  35744. +** enough for a header. This relies on header size being a power of two, which
  35745. +** has been verified earlier by a static assertion. */
  35746. +
  35747. +static inline unsigned int
  35748. +calc_stride(unsigned int size)
  35749. +{
  35750. + /* Allow room for the header */
  35751. + size += sizeof(VCHIQ_HEADER_T);
  35752. +
  35753. + /* Round up */
  35754. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  35755. + - 1);
  35756. +}
  35757. +
  35758. +/* Called by the slot handler thread */
  35759. +static VCHIQ_SERVICE_T *
  35760. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  35761. +{
  35762. + int i;
  35763. +
  35764. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  35765. +
  35766. + for (i = 0; i < state->unused_service; i++) {
  35767. + VCHIQ_SERVICE_T *service = state->services[i];
  35768. + if (service &&
  35769. + (service->public_fourcc == fourcc) &&
  35770. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  35771. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  35772. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  35773. + lock_service(service);
  35774. + return service;
  35775. + }
  35776. + }
  35777. +
  35778. + return NULL;
  35779. +}
  35780. +
  35781. +/* Called by the slot handler thread */
  35782. +static VCHIQ_SERVICE_T *
  35783. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  35784. +{
  35785. + int i;
  35786. + for (i = 0; i < state->unused_service; i++) {
  35787. + VCHIQ_SERVICE_T *service = state->services[i];
  35788. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  35789. + && (service->remoteport == port)) {
  35790. + lock_service(service);
  35791. + return service;
  35792. + }
  35793. + }
  35794. + return NULL;
  35795. +}
  35796. +
  35797. +inline void
  35798. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  35799. +{
  35800. + uint32_t value;
  35801. +
  35802. + if (service) {
  35803. + do {
  35804. + value = atomic_read(&service->poll_flags);
  35805. + } while (atomic_cmpxchg(&service->poll_flags, value,
  35806. + value | (1 << poll_type)) != value);
  35807. +
  35808. + do {
  35809. + value = atomic_read(&state->poll_services[
  35810. + service->localport>>5]);
  35811. + } while (atomic_cmpxchg(
  35812. + &state->poll_services[service->localport>>5],
  35813. + value, value | (1 << (service->localport & 0x1f)))
  35814. + != value);
  35815. + }
  35816. +
  35817. + state->poll_needed = 1;
  35818. + wmb();
  35819. +
  35820. + /* ... and ensure the slot handler runs. */
  35821. + remote_event_signal_local(&state->local->trigger);
  35822. +}
  35823. +
  35824. +/* Called from queue_message, by the slot handler and application threads,
  35825. +** with slot_mutex held */
  35826. +static VCHIQ_HEADER_T *
  35827. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  35828. +{
  35829. + VCHIQ_SHARED_STATE_T *local = state->local;
  35830. + int tx_pos = state->local_tx_pos;
  35831. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  35832. +
  35833. + if (space > slot_space) {
  35834. + VCHIQ_HEADER_T *header;
  35835. + /* Fill the remaining space with padding */
  35836. + WARN_ON(state->tx_data == NULL);
  35837. + header = (VCHIQ_HEADER_T *)
  35838. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  35839. + header->msgid = VCHIQ_MSGID_PADDING;
  35840. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  35841. +
  35842. + tx_pos += slot_space;
  35843. + }
  35844. +
  35845. + /* If necessary, get the next slot. */
  35846. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  35847. + int slot_index;
  35848. +
  35849. + /* If there is no free slot... */
  35850. +
  35851. + if (down_trylock(&state->slot_available_event) != 0) {
  35852. + /* ...wait for one. */
  35853. +
  35854. + VCHIQ_STATS_INC(state, slot_stalls);
  35855. +
  35856. + /* But first, flush through the last slot. */
  35857. + state->local_tx_pos = tx_pos;
  35858. + local->tx_pos = tx_pos;
  35859. + remote_event_signal(&state->remote->trigger);
  35860. +
  35861. + if (!is_blocking ||
  35862. + (down_interruptible(
  35863. + &state->slot_available_event) != 0))
  35864. + return NULL; /* No space available */
  35865. + }
  35866. +
  35867. + BUG_ON(tx_pos ==
  35868. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  35869. +
  35870. + slot_index = local->slot_queue[
  35871. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  35872. + VCHIQ_SLOT_QUEUE_MASK];
  35873. + state->tx_data =
  35874. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  35875. + }
  35876. +
  35877. + state->local_tx_pos = tx_pos + space;
  35878. +
  35879. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  35880. +}
  35881. +
  35882. +/* Called by the recycle thread. */
  35883. +static void
  35884. +process_free_queue(VCHIQ_STATE_T *state)
  35885. +{
  35886. + VCHIQ_SHARED_STATE_T *local = state->local;
  35887. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  35888. + int slot_queue_available;
  35889. +
  35890. + /* Use a read memory barrier to ensure that any state that may have
  35891. + ** been modified by another thread is not masked by stale prefetched
  35892. + ** values. */
  35893. + rmb();
  35894. +
  35895. + /* Find slots which have been freed by the other side, and return them
  35896. + ** to the available queue. */
  35897. + slot_queue_available = state->slot_queue_available;
  35898. +
  35899. + while (slot_queue_available != local->slot_queue_recycle) {
  35900. + unsigned int pos;
  35901. + int slot_index = local->slot_queue[slot_queue_available++ &
  35902. + VCHIQ_SLOT_QUEUE_MASK];
  35903. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  35904. + int data_found = 0;
  35905. +
  35906. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  35907. + state->id, slot_index, (unsigned int)data,
  35908. + local->slot_queue_recycle, slot_queue_available);
  35909. +
  35910. + /* Initialise the bitmask for services which have used this
  35911. + ** slot */
  35912. + BITSET_ZERO(service_found);
  35913. +
  35914. + pos = 0;
  35915. +
  35916. + while (pos < VCHIQ_SLOT_SIZE) {
  35917. + VCHIQ_HEADER_T *header =
  35918. + (VCHIQ_HEADER_T *)(data + pos);
  35919. + int msgid = header->msgid;
  35920. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  35921. + int port = VCHIQ_MSG_SRCPORT(msgid);
  35922. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  35923. + &state->service_quotas[port];
  35924. + int count;
  35925. + spin_lock(&quota_spinlock);
  35926. + count = service_quota->message_use_count;
  35927. + if (count > 0)
  35928. + service_quota->message_use_count =
  35929. + count - 1;
  35930. + spin_unlock(&quota_spinlock);
  35931. +
  35932. + if (count == service_quota->message_quota)
  35933. + /* Signal the service that it
  35934. + ** has dropped below its quota
  35935. + */
  35936. + up(&service_quota->quota_event);
  35937. + else if (count == 0) {
  35938. + vchiq_log_error(vchiq_core_log_level,
  35939. + "service %d "
  35940. + "message_use_count=%d "
  35941. + "(header %x, msgid %x, "
  35942. + "header->msgid %x, "
  35943. + "header->size %x)",
  35944. + port,
  35945. + service_quota->
  35946. + message_use_count,
  35947. + (unsigned int)header, msgid,
  35948. + header->msgid,
  35949. + header->size);
  35950. + WARN(1, "invalid message use count\n");
  35951. + }
  35952. + if (!BITSET_IS_SET(service_found, port)) {
  35953. + /* Set the found bit for this service */
  35954. + BITSET_SET(service_found, port);
  35955. +
  35956. + spin_lock(&quota_spinlock);
  35957. + count = service_quota->slot_use_count;
  35958. + if (count > 0)
  35959. + service_quota->slot_use_count =
  35960. + count - 1;
  35961. + spin_unlock(&quota_spinlock);
  35962. +
  35963. + if (count > 0) {
  35964. + /* Signal the service in case
  35965. + ** it has dropped below its
  35966. + ** quota */
  35967. + up(&service_quota->quota_event);
  35968. + vchiq_log_trace(
  35969. + vchiq_core_log_level,
  35970. + "%d: pfq:%d %x@%x - "
  35971. + "slot_use->%d",
  35972. + state->id, port,
  35973. + header->size,
  35974. + (unsigned int)header,
  35975. + count - 1);
  35976. + } else {
  35977. + vchiq_log_error(
  35978. + vchiq_core_log_level,
  35979. + "service %d "
  35980. + "slot_use_count"
  35981. + "=%d (header %x"
  35982. + ", msgid %x, "
  35983. + "header->msgid"
  35984. + " %x, header->"
  35985. + "size %x)",
  35986. + port, count,
  35987. + (unsigned int)header,
  35988. + msgid,
  35989. + header->msgid,
  35990. + header->size);
  35991. + WARN(1, "bad slot use count\n");
  35992. + }
  35993. + }
  35994. +
  35995. + data_found = 1;
  35996. + }
  35997. +
  35998. + pos += calc_stride(header->size);
  35999. + if (pos > VCHIQ_SLOT_SIZE) {
  36000. + vchiq_log_error(vchiq_core_log_level,
  36001. + "pfq - pos %x: header %x, msgid %x, "
  36002. + "header->msgid %x, header->size %x",
  36003. + pos, (unsigned int)header, msgid,
  36004. + header->msgid, header->size);
  36005. + WARN(1, "invalid slot position\n");
  36006. + }
  36007. + }
  36008. +
  36009. + if (data_found) {
  36010. + int count;
  36011. + spin_lock(&quota_spinlock);
  36012. + count = state->data_use_count;
  36013. + if (count > 0)
  36014. + state->data_use_count =
  36015. + count - 1;
  36016. + spin_unlock(&quota_spinlock);
  36017. + if (count == state->data_quota)
  36018. + up(&state->data_quota_event);
  36019. + }
  36020. +
  36021. + state->slot_queue_available = slot_queue_available;
  36022. + up(&state->slot_available_event);
  36023. + }
  36024. +}
  36025. +
  36026. +/* Called by the slot handler and application threads */
  36027. +static VCHIQ_STATUS_T
  36028. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  36029. + int msgid, const VCHIQ_ELEMENT_T *elements,
  36030. + int count, int size, int is_blocking)
  36031. +{
  36032. + VCHIQ_SHARED_STATE_T *local;
  36033. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  36034. + VCHIQ_HEADER_T *header;
  36035. + int type = VCHIQ_MSG_TYPE(msgid);
  36036. +
  36037. + unsigned int stride;
  36038. +
  36039. + local = state->local;
  36040. +
  36041. + stride = calc_stride(size);
  36042. +
  36043. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  36044. +
  36045. + if ((type != VCHIQ_MSG_RESUME) &&
  36046. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  36047. + return VCHIQ_RETRY;
  36048. +
  36049. + if (type == VCHIQ_MSG_DATA) {
  36050. + int tx_end_index;
  36051. +
  36052. + BUG_ON(!service);
  36053. +
  36054. + if (service->closing) {
  36055. + /* The service has been closed */
  36056. + mutex_unlock(&state->slot_mutex);
  36057. + return VCHIQ_ERROR;
  36058. + }
  36059. +
  36060. + service_quota = &state->service_quotas[service->localport];
  36061. +
  36062. + spin_lock(&quota_spinlock);
  36063. +
  36064. + /* Ensure this service doesn't use more than its quota of
  36065. + ** messages or slots */
  36066. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  36067. + state->local_tx_pos + stride - 1);
  36068. +
  36069. + /* Ensure data messages don't use more than their quota of
  36070. + ** slots */
  36071. + while ((tx_end_index != state->previous_data_index) &&
  36072. + (state->data_use_count == state->data_quota)) {
  36073. + VCHIQ_STATS_INC(state, data_stalls);
  36074. + spin_unlock(&quota_spinlock);
  36075. + mutex_unlock(&state->slot_mutex);
  36076. +
  36077. + if (down_interruptible(&state->data_quota_event)
  36078. + != 0)
  36079. + return VCHIQ_RETRY;
  36080. +
  36081. + mutex_lock(&state->slot_mutex);
  36082. + spin_lock(&quota_spinlock);
  36083. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  36084. + state->local_tx_pos + stride - 1);
  36085. + if ((tx_end_index == state->previous_data_index) ||
  36086. + (state->data_use_count < state->data_quota)) {
  36087. + /* Pass the signal on to other waiters */
  36088. + up(&state->data_quota_event);
  36089. + break;
  36090. + }
  36091. + }
  36092. +
  36093. + while ((service_quota->message_use_count ==
  36094. + service_quota->message_quota) ||
  36095. + ((tx_end_index != service_quota->previous_tx_index) &&
  36096. + (service_quota->slot_use_count ==
  36097. + service_quota->slot_quota))) {
  36098. + spin_unlock(&quota_spinlock);
  36099. + vchiq_log_trace(vchiq_core_log_level,
  36100. + "%d: qm:%d %s,%x - quota stall "
  36101. + "(msg %d, slot %d)",
  36102. + state->id, service->localport,
  36103. + msg_type_str(type), size,
  36104. + service_quota->message_use_count,
  36105. + service_quota->slot_use_count);
  36106. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  36107. + mutex_unlock(&state->slot_mutex);
  36108. + if (down_interruptible(&service_quota->quota_event)
  36109. + != 0)
  36110. + return VCHIQ_RETRY;
  36111. + if (service->closing)
  36112. + return VCHIQ_ERROR;
  36113. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  36114. + return VCHIQ_RETRY;
  36115. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  36116. + /* The service has been closed */
  36117. + mutex_unlock(&state->slot_mutex);
  36118. + return VCHIQ_ERROR;
  36119. + }
  36120. + spin_lock(&quota_spinlock);
  36121. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  36122. + state->local_tx_pos + stride - 1);
  36123. + }
  36124. +
  36125. + spin_unlock(&quota_spinlock);
  36126. + }
  36127. +
  36128. + header = reserve_space(state, stride, is_blocking);
  36129. +
  36130. + if (!header) {
  36131. + if (service)
  36132. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  36133. + mutex_unlock(&state->slot_mutex);
  36134. + return VCHIQ_RETRY;
  36135. + }
  36136. +
  36137. + if (type == VCHIQ_MSG_DATA) {
  36138. + int i, pos;
  36139. + int tx_end_index;
  36140. + int slot_use_count;
  36141. +
  36142. + vchiq_log_info(vchiq_core_log_level,
  36143. + "%d: qm %s@%x,%x (%d->%d)",
  36144. + state->id,
  36145. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36146. + (unsigned int)header, size,
  36147. + VCHIQ_MSG_SRCPORT(msgid),
  36148. + VCHIQ_MSG_DSTPORT(msgid));
  36149. +
  36150. + BUG_ON(!service);
  36151. +
  36152. + for (i = 0, pos = 0; i < (unsigned int)count;
  36153. + pos += elements[i++].size)
  36154. + if (elements[i].size) {
  36155. + if (vchiq_copy_from_user
  36156. + (header->data + pos, elements[i].data,
  36157. + (size_t) elements[i].size) !=
  36158. + VCHIQ_SUCCESS) {
  36159. + mutex_unlock(&state->slot_mutex);
  36160. + VCHIQ_SERVICE_STATS_INC(service,
  36161. + error_count);
  36162. + return VCHIQ_ERROR;
  36163. + }
  36164. + if (i == 0) {
  36165. + if (SRVTRACE_ENABLED(service,
  36166. + VCHIQ_LOG_INFO))
  36167. + vchiq_log_dump_mem("Sent", 0,
  36168. + header->data + pos,
  36169. + min(64u,
  36170. + elements[0].size));
  36171. + }
  36172. + }
  36173. +
  36174. + spin_lock(&quota_spinlock);
  36175. + service_quota->message_use_count++;
  36176. +
  36177. + tx_end_index =
  36178. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  36179. +
  36180. + /* If this transmission can't fit in the last slot used by any
  36181. + ** service, the data_use_count must be increased. */
  36182. + if (tx_end_index != state->previous_data_index) {
  36183. + state->previous_data_index = tx_end_index;
  36184. + state->data_use_count++;
  36185. + }
  36186. +
  36187. + /* If this isn't the same slot last used by this service,
  36188. + ** the service's slot_use_count must be increased. */
  36189. + if (tx_end_index != service_quota->previous_tx_index) {
  36190. + service_quota->previous_tx_index = tx_end_index;
  36191. + slot_use_count = ++service_quota->slot_use_count;
  36192. + } else {
  36193. + slot_use_count = 0;
  36194. + }
  36195. +
  36196. + spin_unlock(&quota_spinlock);
  36197. +
  36198. + if (slot_use_count)
  36199. + vchiq_log_trace(vchiq_core_log_level,
  36200. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  36201. + state->id, service->localport,
  36202. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  36203. + slot_use_count, header);
  36204. +
  36205. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  36206. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  36207. + } else {
  36208. + vchiq_log_info(vchiq_core_log_level,
  36209. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  36210. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36211. + (unsigned int)header, size,
  36212. + VCHIQ_MSG_SRCPORT(msgid),
  36213. + VCHIQ_MSG_DSTPORT(msgid));
  36214. + if (size != 0) {
  36215. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  36216. + memcpy(header->data, elements[0].data,
  36217. + elements[0].size);
  36218. + }
  36219. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  36220. + }
  36221. +
  36222. + header->msgid = msgid;
  36223. + header->size = size;
  36224. +
  36225. + {
  36226. + int svc_fourcc;
  36227. +
  36228. + svc_fourcc = service
  36229. + ? service->base.fourcc
  36230. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  36231. +
  36232. + vchiq_log_info(SRVTRACE_LEVEL(service),
  36233. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  36234. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36235. + VCHIQ_MSG_TYPE(msgid),
  36236. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  36237. + VCHIQ_MSG_SRCPORT(msgid),
  36238. + VCHIQ_MSG_DSTPORT(msgid),
  36239. + size);
  36240. + }
  36241. +
  36242. + /* Make sure the new header is visible to the peer. */
  36243. + wmb();
  36244. +
  36245. + /* Make the new tx_pos visible to the peer. */
  36246. + local->tx_pos = state->local_tx_pos;
  36247. + wmb();
  36248. +
  36249. + if (service && (type == VCHIQ_MSG_CLOSE))
  36250. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  36251. +
  36252. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  36253. + mutex_unlock(&state->slot_mutex);
  36254. +
  36255. + remote_event_signal(&state->remote->trigger);
  36256. +
  36257. + return VCHIQ_SUCCESS;
  36258. +}
  36259. +
  36260. +/* Called by the slot handler and application threads */
  36261. +static VCHIQ_STATUS_T
  36262. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  36263. + int msgid, const VCHIQ_ELEMENT_T *elements,
  36264. + int count, int size, int is_blocking)
  36265. +{
  36266. + VCHIQ_SHARED_STATE_T *local;
  36267. + VCHIQ_HEADER_T *header;
  36268. +
  36269. + local = state->local;
  36270. +
  36271. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  36272. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  36273. + return VCHIQ_RETRY;
  36274. +
  36275. + remote_event_wait(&local->sync_release);
  36276. +
  36277. + rmb();
  36278. +
  36279. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  36280. + local->slot_sync);
  36281. +
  36282. + {
  36283. + int oldmsgid = header->msgid;
  36284. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  36285. + vchiq_log_error(vchiq_core_log_level,
  36286. + "%d: qms - msgid %x, not PADDING",
  36287. + state->id, oldmsgid);
  36288. + }
  36289. +
  36290. + if (service) {
  36291. + int i, pos;
  36292. +
  36293. + vchiq_log_info(vchiq_sync_log_level,
  36294. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  36295. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36296. + (unsigned int)header, size,
  36297. + VCHIQ_MSG_SRCPORT(msgid),
  36298. + VCHIQ_MSG_DSTPORT(msgid));
  36299. +
  36300. + for (i = 0, pos = 0; i < (unsigned int)count;
  36301. + pos += elements[i++].size)
  36302. + if (elements[i].size) {
  36303. + if (vchiq_copy_from_user
  36304. + (header->data + pos, elements[i].data,
  36305. + (size_t) elements[i].size) !=
  36306. + VCHIQ_SUCCESS) {
  36307. + mutex_unlock(&state->sync_mutex);
  36308. + VCHIQ_SERVICE_STATS_INC(service,
  36309. + error_count);
  36310. + return VCHIQ_ERROR;
  36311. + }
  36312. + if (i == 0) {
  36313. + if (vchiq_sync_log_level >=
  36314. + VCHIQ_LOG_TRACE)
  36315. + vchiq_log_dump_mem("Sent Sync",
  36316. + 0, header->data + pos,
  36317. + min(64u,
  36318. + elements[0].size));
  36319. + }
  36320. + }
  36321. +
  36322. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  36323. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  36324. + } else {
  36325. + vchiq_log_info(vchiq_sync_log_level,
  36326. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  36327. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36328. + (unsigned int)header, size,
  36329. + VCHIQ_MSG_SRCPORT(msgid),
  36330. + VCHIQ_MSG_DSTPORT(msgid));
  36331. + if (size != 0) {
  36332. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  36333. + memcpy(header->data, elements[0].data,
  36334. + elements[0].size);
  36335. + }
  36336. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  36337. + }
  36338. +
  36339. + header->size = size;
  36340. + header->msgid = msgid;
  36341. +
  36342. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  36343. + int svc_fourcc;
  36344. +
  36345. + svc_fourcc = service
  36346. + ? service->base.fourcc
  36347. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  36348. +
  36349. + vchiq_log_trace(vchiq_sync_log_level,
  36350. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  36351. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  36352. + VCHIQ_MSG_TYPE(msgid),
  36353. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  36354. + VCHIQ_MSG_SRCPORT(msgid),
  36355. + VCHIQ_MSG_DSTPORT(msgid),
  36356. + size);
  36357. + }
  36358. +
  36359. + /* Make sure the new header is visible to the peer. */
  36360. + wmb();
  36361. +
  36362. + remote_event_signal(&state->remote->sync_trigger);
  36363. +
  36364. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  36365. + mutex_unlock(&state->sync_mutex);
  36366. +
  36367. + return VCHIQ_SUCCESS;
  36368. +}
  36369. +
  36370. +static inline void
  36371. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  36372. +{
  36373. + slot->use_count++;
  36374. +}
  36375. +
  36376. +static void
  36377. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  36378. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  36379. +{
  36380. + int release_count;
  36381. +
  36382. + mutex_lock(&state->recycle_mutex);
  36383. +
  36384. + if (header) {
  36385. + int msgid = header->msgid;
  36386. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  36387. + (service && service->closing)) {
  36388. + mutex_unlock(&state->recycle_mutex);
  36389. + return;
  36390. + }
  36391. +
  36392. + /* Rewrite the message header to prevent a double
  36393. + ** release */
  36394. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  36395. + }
  36396. +
  36397. + release_count = slot_info->release_count;
  36398. + slot_info->release_count = ++release_count;
  36399. +
  36400. + if (release_count == slot_info->use_count) {
  36401. + int slot_queue_recycle;
  36402. + /* Add to the freed queue */
  36403. +
  36404. + /* A read barrier is necessary here to prevent speculative
  36405. + ** fetches of remote->slot_queue_recycle from overtaking the
  36406. + ** mutex. */
  36407. + rmb();
  36408. +
  36409. + slot_queue_recycle = state->remote->slot_queue_recycle;
  36410. + state->remote->slot_queue[slot_queue_recycle &
  36411. + VCHIQ_SLOT_QUEUE_MASK] =
  36412. + SLOT_INDEX_FROM_INFO(state, slot_info);
  36413. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  36414. + vchiq_log_info(vchiq_core_log_level,
  36415. + "%d: release_slot %d - recycle->%x",
  36416. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  36417. + state->remote->slot_queue_recycle);
  36418. +
  36419. + /* A write barrier is necessary, but remote_event_signal
  36420. + ** contains one. */
  36421. + remote_event_signal(&state->remote->recycle);
  36422. + }
  36423. +
  36424. + mutex_unlock(&state->recycle_mutex);
  36425. +}
  36426. +
  36427. +/* Called by the slot handler - don't hold the bulk mutex */
  36428. +static VCHIQ_STATUS_T
  36429. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  36430. + int retry_poll)
  36431. +{
  36432. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  36433. +
  36434. + vchiq_log_trace(vchiq_core_log_level,
  36435. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  36436. + service->state->id, service->localport,
  36437. + (queue == &service->bulk_tx) ? 't' : 'r',
  36438. + queue->process, queue->remote_notify, queue->remove);
  36439. +
  36440. + if (service->state->is_master) {
  36441. + while (queue->remote_notify != queue->process) {
  36442. + VCHIQ_BULK_T *bulk =
  36443. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  36444. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  36445. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  36446. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  36447. + service->remoteport);
  36448. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  36449. + /* Only reply to non-dummy bulk requests */
  36450. + if (bulk->remote_data) {
  36451. + status = queue_message(service->state, NULL,
  36452. + msgid, &element, 1, 4, 0);
  36453. + if (status != VCHIQ_SUCCESS)
  36454. + break;
  36455. + }
  36456. + queue->remote_notify++;
  36457. + }
  36458. + } else {
  36459. + queue->remote_notify = queue->process;
  36460. + }
  36461. +
  36462. + if (status == VCHIQ_SUCCESS) {
  36463. + while (queue->remove != queue->remote_notify) {
  36464. + VCHIQ_BULK_T *bulk =
  36465. + &queue->bulks[BULK_INDEX(queue->remove)];
  36466. +
  36467. + /* Only generate callbacks for non-dummy bulk
  36468. + ** requests, and non-terminated services */
  36469. + if (bulk->data && service->instance) {
  36470. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  36471. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  36472. + VCHIQ_SERVICE_STATS_INC(service,
  36473. + bulk_tx_count);
  36474. + VCHIQ_SERVICE_STATS_ADD(service,
  36475. + bulk_tx_bytes,
  36476. + bulk->actual);
  36477. + } else {
  36478. + VCHIQ_SERVICE_STATS_INC(service,
  36479. + bulk_rx_count);
  36480. + VCHIQ_SERVICE_STATS_ADD(service,
  36481. + bulk_rx_bytes,
  36482. + bulk->actual);
  36483. + }
  36484. + } else {
  36485. + VCHIQ_SERVICE_STATS_INC(service,
  36486. + bulk_aborted_count);
  36487. + }
  36488. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  36489. + struct bulk_waiter *waiter;
  36490. + spin_lock(&bulk_waiter_spinlock);
  36491. + waiter = bulk->userdata;
  36492. + if (waiter) {
  36493. + waiter->actual = bulk->actual;
  36494. + up(&waiter->event);
  36495. + }
  36496. + spin_unlock(&bulk_waiter_spinlock);
  36497. + } else if (bulk->mode ==
  36498. + VCHIQ_BULK_MODE_CALLBACK) {
  36499. + VCHIQ_REASON_T reason = (bulk->dir ==
  36500. + VCHIQ_BULK_TRANSMIT) ?
  36501. + ((bulk->actual ==
  36502. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  36503. + VCHIQ_BULK_TRANSMIT_ABORTED :
  36504. + VCHIQ_BULK_TRANSMIT_DONE) :
  36505. + ((bulk->actual ==
  36506. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  36507. + VCHIQ_BULK_RECEIVE_ABORTED :
  36508. + VCHIQ_BULK_RECEIVE_DONE);
  36509. + status = make_service_callback(service,
  36510. + reason, NULL, bulk->userdata);
  36511. + if (status == VCHIQ_RETRY)
  36512. + break;
  36513. + }
  36514. + }
  36515. +
  36516. + queue->remove++;
  36517. + up(&service->bulk_remove_event);
  36518. + }
  36519. + if (!retry_poll)
  36520. + status = VCHIQ_SUCCESS;
  36521. + }
  36522. +
  36523. + if (status == VCHIQ_RETRY)
  36524. + request_poll(service->state, service,
  36525. + (queue == &service->bulk_tx) ?
  36526. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  36527. +
  36528. + return status;
  36529. +}
  36530. +
  36531. +/* Called by the slot handler thread */
  36532. +static void
  36533. +poll_services(VCHIQ_STATE_T *state)
  36534. +{
  36535. + int group, i;
  36536. +
  36537. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  36538. + uint32_t flags;
  36539. + flags = atomic_xchg(&state->poll_services[group], 0);
  36540. + for (i = 0; flags; i++) {
  36541. + if (flags & (1 << i)) {
  36542. + VCHIQ_SERVICE_T *service =
  36543. + find_service_by_port(state,
  36544. + (group<<5) + i);
  36545. + uint32_t service_flags;
  36546. + flags &= ~(1 << i);
  36547. + if (!service)
  36548. + continue;
  36549. + service_flags =
  36550. + atomic_xchg(&service->poll_flags, 0);
  36551. + if (service_flags &
  36552. + (1 << VCHIQ_POLL_REMOVE)) {
  36553. + vchiq_log_info(vchiq_core_log_level,
  36554. + "%d: ps - remove %d<->%d",
  36555. + state->id, service->localport,
  36556. + service->remoteport);
  36557. +
  36558. + /* Make it look like a client, because
  36559. + it must be removed and not left in
  36560. + the LISTENING state. */
  36561. + service->public_fourcc =
  36562. + VCHIQ_FOURCC_INVALID;
  36563. +
  36564. + if (vchiq_close_service_internal(
  36565. + service, 0/*!close_recvd*/) !=
  36566. + VCHIQ_SUCCESS)
  36567. + request_poll(state, service,
  36568. + VCHIQ_POLL_REMOVE);
  36569. + } else if (service_flags &
  36570. + (1 << VCHIQ_POLL_TERMINATE)) {
  36571. + vchiq_log_info(vchiq_core_log_level,
  36572. + "%d: ps - terminate %d<->%d",
  36573. + state->id, service->localport,
  36574. + service->remoteport);
  36575. + if (vchiq_close_service_internal(
  36576. + service, 0/*!close_recvd*/) !=
  36577. + VCHIQ_SUCCESS)
  36578. + request_poll(state, service,
  36579. + VCHIQ_POLL_TERMINATE);
  36580. + }
  36581. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  36582. + notify_bulks(service,
  36583. + &service->bulk_tx,
  36584. + 1/*retry_poll*/);
  36585. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  36586. + notify_bulks(service,
  36587. + &service->bulk_rx,
  36588. + 1/*retry_poll*/);
  36589. + unlock_service(service);
  36590. + }
  36591. + }
  36592. + }
  36593. +}
  36594. +
  36595. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  36596. +static int
  36597. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  36598. +{
  36599. + VCHIQ_STATE_T *state = service->state;
  36600. + int resolved = 0;
  36601. + int rc;
  36602. +
  36603. + while ((queue->process != queue->local_insert) &&
  36604. + (queue->process != queue->remote_insert)) {
  36605. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  36606. +
  36607. + vchiq_log_trace(vchiq_core_log_level,
  36608. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  36609. + state->id, service->localport,
  36610. + (queue == &service->bulk_tx) ? 't' : 'r',
  36611. + queue->local_insert, queue->remote_insert,
  36612. + queue->process);
  36613. +
  36614. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  36615. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  36616. +
  36617. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  36618. + if (rc != 0)
  36619. + break;
  36620. +
  36621. + vchiq_transfer_bulk(bulk);
  36622. + mutex_unlock(&state->bulk_transfer_mutex);
  36623. +
  36624. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  36625. + const char *header = (queue == &service->bulk_tx) ?
  36626. + "Send Bulk to" : "Recv Bulk from";
  36627. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  36628. + vchiq_log_info(SRVTRACE_LEVEL(service),
  36629. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  36630. + header,
  36631. + VCHIQ_FOURCC_AS_4CHARS(
  36632. + service->base.fourcc),
  36633. + service->remoteport,
  36634. + bulk->size,
  36635. + (unsigned int)bulk->data,
  36636. + (unsigned int)bulk->remote_data);
  36637. + else
  36638. + vchiq_log_info(SRVTRACE_LEVEL(service),
  36639. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  36640. + " rx len:%d %x<->%x",
  36641. + header,
  36642. + VCHIQ_FOURCC_AS_4CHARS(
  36643. + service->base.fourcc),
  36644. + service->remoteport,
  36645. + bulk->size,
  36646. + bulk->remote_size,
  36647. + (unsigned int)bulk->data,
  36648. + (unsigned int)bulk->remote_data);
  36649. + }
  36650. +
  36651. + vchiq_complete_bulk(bulk);
  36652. + queue->process++;
  36653. + resolved++;
  36654. + }
  36655. + return resolved;
  36656. +}
  36657. +
  36658. +/* Called with the bulk_mutex held */
  36659. +static void
  36660. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  36661. +{
  36662. + int is_tx = (queue == &service->bulk_tx);
  36663. + vchiq_log_trace(vchiq_core_log_level,
  36664. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  36665. + service->state->id, service->localport, is_tx ? 't' : 'r',
  36666. + queue->local_insert, queue->remote_insert, queue->process);
  36667. +
  36668. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  36669. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  36670. +
  36671. + while ((queue->process != queue->local_insert) ||
  36672. + (queue->process != queue->remote_insert)) {
  36673. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  36674. +
  36675. + if (queue->process == queue->remote_insert) {
  36676. + /* fabricate a matching dummy bulk */
  36677. + bulk->remote_data = NULL;
  36678. + bulk->remote_size = 0;
  36679. + queue->remote_insert++;
  36680. + }
  36681. +
  36682. + if (queue->process != queue->local_insert) {
  36683. + vchiq_complete_bulk(bulk);
  36684. +
  36685. + vchiq_log_info(SRVTRACE_LEVEL(service),
  36686. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  36687. + "rx len:%d",
  36688. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  36689. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  36690. + service->remoteport,
  36691. + bulk->size,
  36692. + bulk->remote_size);
  36693. + } else {
  36694. + /* fabricate a matching dummy bulk */
  36695. + bulk->data = NULL;
  36696. + bulk->size = 0;
  36697. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  36698. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  36699. + VCHIQ_BULK_RECEIVE;
  36700. + queue->local_insert++;
  36701. + }
  36702. +
  36703. + queue->process++;
  36704. + }
  36705. +}
  36706. +
  36707. +/* Called from the slot handler thread */
  36708. +static void
  36709. +pause_bulks(VCHIQ_STATE_T *state)
  36710. +{
  36711. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  36712. + WARN_ON_ONCE(1);
  36713. + atomic_set(&pause_bulks_count, 1);
  36714. + return;
  36715. + }
  36716. +
  36717. + /* Block bulk transfers from all services */
  36718. + mutex_lock(&state->bulk_transfer_mutex);
  36719. +}
  36720. +
  36721. +/* Called from the slot handler thread */
  36722. +static void
  36723. +resume_bulks(VCHIQ_STATE_T *state)
  36724. +{
  36725. + int i;
  36726. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  36727. + WARN_ON_ONCE(1);
  36728. + atomic_set(&pause_bulks_count, 0);
  36729. + return;
  36730. + }
  36731. +
  36732. + /* Allow bulk transfers from all services */
  36733. + mutex_unlock(&state->bulk_transfer_mutex);
  36734. +
  36735. + if (state->deferred_bulks == 0)
  36736. + return;
  36737. +
  36738. + /* Deal with any bulks which had to be deferred due to being in
  36739. + * paused state. Don't try to match up to number of deferred bulks
  36740. + * in case we've had something come and close the service in the
  36741. + * interim - just process all bulk queues for all services */
  36742. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  36743. + __func__, state->deferred_bulks);
  36744. +
  36745. + for (i = 0; i < state->unused_service; i++) {
  36746. + VCHIQ_SERVICE_T *service = state->services[i];
  36747. + int resolved_rx = 0;
  36748. + int resolved_tx = 0;
  36749. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  36750. + continue;
  36751. +
  36752. + mutex_lock(&service->bulk_mutex);
  36753. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  36754. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  36755. + mutex_unlock(&service->bulk_mutex);
  36756. + if (resolved_rx)
  36757. + notify_bulks(service, &service->bulk_rx, 1);
  36758. + if (resolved_tx)
  36759. + notify_bulks(service, &service->bulk_tx, 1);
  36760. + }
  36761. + state->deferred_bulks = 0;
  36762. +}
  36763. +
  36764. +static int
  36765. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  36766. +{
  36767. + VCHIQ_SERVICE_T *service = NULL;
  36768. + int msgid, size;
  36769. + int type;
  36770. + unsigned int localport, remoteport;
  36771. +
  36772. + msgid = header->msgid;
  36773. + size = header->size;
  36774. + type = VCHIQ_MSG_TYPE(msgid);
  36775. + localport = VCHIQ_MSG_DSTPORT(msgid);
  36776. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  36777. + if (size >= sizeof(struct vchiq_open_payload)) {
  36778. + const struct vchiq_open_payload *payload =
  36779. + (struct vchiq_open_payload *)header->data;
  36780. + unsigned int fourcc;
  36781. +
  36782. + fourcc = payload->fourcc;
  36783. + vchiq_log_info(vchiq_core_log_level,
  36784. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  36785. + state->id, (unsigned int)header,
  36786. + localport,
  36787. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  36788. +
  36789. + service = get_listening_service(state, fourcc);
  36790. +
  36791. + if (service) {
  36792. + /* A matching service exists */
  36793. + short version = payload->version;
  36794. + short version_min = payload->version_min;
  36795. + if ((service->version < version_min) ||
  36796. + (version < service->version_min)) {
  36797. + /* Version mismatch */
  36798. + vchiq_loud_error_header();
  36799. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  36800. + "version mismatch - local (%d, min %d)"
  36801. + " vs. remote (%d, min %d)",
  36802. + state->id, service->localport,
  36803. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  36804. + service->version, service->version_min,
  36805. + version, version_min);
  36806. + vchiq_loud_error_footer();
  36807. + unlock_service(service);
  36808. + service = NULL;
  36809. + goto fail_open;
  36810. + }
  36811. + service->peer_version = version;
  36812. +
  36813. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  36814. + struct vchiq_openack_payload ack_payload = {
  36815. + service->version
  36816. + };
  36817. + VCHIQ_ELEMENT_T body = {
  36818. + &ack_payload,
  36819. + sizeof(ack_payload)
  36820. + };
  36821. +
  36822. + /* Acknowledge the OPEN */
  36823. + if (service->sync) {
  36824. + if (queue_message_sync(state, NULL,
  36825. + VCHIQ_MAKE_MSG(
  36826. + VCHIQ_MSG_OPENACK,
  36827. + service->localport,
  36828. + remoteport),
  36829. + &body, 1, sizeof(ack_payload),
  36830. + 0) == VCHIQ_RETRY)
  36831. + goto bail_not_ready;
  36832. + } else {
  36833. + if (queue_message(state, NULL,
  36834. + VCHIQ_MAKE_MSG(
  36835. + VCHIQ_MSG_OPENACK,
  36836. + service->localport,
  36837. + remoteport),
  36838. + &body, 1, sizeof(ack_payload),
  36839. + 0) == VCHIQ_RETRY)
  36840. + goto bail_not_ready;
  36841. + }
  36842. +
  36843. + /* The service is now open */
  36844. + vchiq_set_service_state(service,
  36845. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  36846. + : VCHIQ_SRVSTATE_OPEN);
  36847. + }
  36848. +
  36849. + service->remoteport = remoteport;
  36850. + service->client_id = ((int *)header->data)[1];
  36851. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  36852. + NULL, NULL) == VCHIQ_RETRY) {
  36853. + /* Bail out if not ready */
  36854. + service->remoteport = VCHIQ_PORT_FREE;
  36855. + goto bail_not_ready;
  36856. + }
  36857. +
  36858. + /* Success - the message has been dealt with */
  36859. + unlock_service(service);
  36860. + return 1;
  36861. + }
  36862. + }
  36863. +
  36864. +fail_open:
  36865. + /* No available service, or an invalid request - send a CLOSE */
  36866. + if (queue_message(state, NULL,
  36867. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  36868. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  36869. + goto bail_not_ready;
  36870. +
  36871. + return 1;
  36872. +
  36873. +bail_not_ready:
  36874. + if (service)
  36875. + unlock_service(service);
  36876. +
  36877. + return 0;
  36878. +}
  36879. +
  36880. +/* Called by the slot handler thread */
  36881. +static void
  36882. +parse_rx_slots(VCHIQ_STATE_T *state)
  36883. +{
  36884. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  36885. + VCHIQ_SERVICE_T *service = NULL;
  36886. + int tx_pos;
  36887. + DEBUG_INITIALISE(state->local)
  36888. +
  36889. + tx_pos = remote->tx_pos;
  36890. +
  36891. + while (state->rx_pos != tx_pos) {
  36892. + VCHIQ_HEADER_T *header;
  36893. + int msgid, size;
  36894. + int type;
  36895. + unsigned int localport, remoteport;
  36896. +
  36897. + DEBUG_TRACE(PARSE_LINE);
  36898. + if (!state->rx_data) {
  36899. + int rx_index;
  36900. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  36901. + rx_index = remote->slot_queue[
  36902. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  36903. + VCHIQ_SLOT_QUEUE_MASK];
  36904. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  36905. + rx_index);
  36906. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  36907. +
  36908. + /* Initialise use_count to one, and increment
  36909. + ** release_count at the end of the slot to avoid
  36910. + ** releasing the slot prematurely. */
  36911. + state->rx_info->use_count = 1;
  36912. + state->rx_info->release_count = 0;
  36913. + }
  36914. +
  36915. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  36916. + (state->rx_pos & VCHIQ_SLOT_MASK));
  36917. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  36918. + msgid = header->msgid;
  36919. + DEBUG_VALUE(PARSE_MSGID, msgid);
  36920. + size = header->size;
  36921. + type = VCHIQ_MSG_TYPE(msgid);
  36922. + localport = VCHIQ_MSG_DSTPORT(msgid);
  36923. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  36924. +
  36925. + if (type != VCHIQ_MSG_DATA)
  36926. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  36927. +
  36928. + switch (type) {
  36929. + case VCHIQ_MSG_OPENACK:
  36930. + case VCHIQ_MSG_CLOSE:
  36931. + case VCHIQ_MSG_DATA:
  36932. + case VCHIQ_MSG_BULK_RX:
  36933. + case VCHIQ_MSG_BULK_TX:
  36934. + case VCHIQ_MSG_BULK_RX_DONE:
  36935. + case VCHIQ_MSG_BULK_TX_DONE:
  36936. + service = find_service_by_port(state, localport);
  36937. + if ((!service ||
  36938. + ((service->remoteport != remoteport) &&
  36939. + (service->remoteport != VCHIQ_PORT_FREE))) &&
  36940. + (localport == 0) &&
  36941. + (type == VCHIQ_MSG_CLOSE)) {
  36942. + /* This could be a CLOSE from a client which
  36943. + hadn't yet received the OPENACK - look for
  36944. + the connected service */
  36945. + if (service)
  36946. + unlock_service(service);
  36947. + service = get_connected_service(state,
  36948. + remoteport);
  36949. + if (service)
  36950. + vchiq_log_warning(vchiq_core_log_level,
  36951. + "%d: prs %s@%x (%d->%d) - "
  36952. + "found connected service %d",
  36953. + state->id, msg_type_str(type),
  36954. + (unsigned int)header,
  36955. + remoteport, localport,
  36956. + service->localport);
  36957. + }
  36958. +
  36959. + if (!service) {
  36960. + vchiq_log_error(vchiq_core_log_level,
  36961. + "%d: prs %s@%x (%d->%d) - "
  36962. + "invalid/closed service %d",
  36963. + state->id, msg_type_str(type),
  36964. + (unsigned int)header,
  36965. + remoteport, localport, localport);
  36966. + goto skip_message;
  36967. + }
  36968. + break;
  36969. + default:
  36970. + break;
  36971. + }
  36972. +
  36973. + if (SRVTRACE_ENABLED(service, VCHIQ_LOG_INFO)) {
  36974. + int svc_fourcc;
  36975. +
  36976. + svc_fourcc = service
  36977. + ? service->base.fourcc
  36978. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  36979. + vchiq_log_info(SRVTRACE_LEVEL(service),
  36980. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  36981. + "len:%d",
  36982. + msg_type_str(type), type,
  36983. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  36984. + remoteport, localport, size);
  36985. + if (size > 0)
  36986. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  36987. + min(64, size));
  36988. + }
  36989. +
  36990. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  36991. + > VCHIQ_SLOT_SIZE) {
  36992. + vchiq_log_error(vchiq_core_log_level,
  36993. + "header %x (msgid %x) - size %x too big for "
  36994. + "slot",
  36995. + (unsigned int)header, (unsigned int)msgid,
  36996. + (unsigned int)size);
  36997. + WARN(1, "oversized for slot\n");
  36998. + }
  36999. +
  37000. + switch (type) {
  37001. + case VCHIQ_MSG_OPEN:
  37002. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  37003. + if (!parse_open(state, header))
  37004. + goto bail_not_ready;
  37005. + break;
  37006. + case VCHIQ_MSG_OPENACK:
  37007. + if (size >= sizeof(struct vchiq_openack_payload)) {
  37008. + const struct vchiq_openack_payload *payload =
  37009. + (struct vchiq_openack_payload *)
  37010. + header->data;
  37011. + service->peer_version = payload->version;
  37012. + }
  37013. + vchiq_log_info(vchiq_core_log_level,
  37014. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  37015. + state->id, (unsigned int)header, size,
  37016. + remoteport, localport, service->peer_version);
  37017. + if (service->srvstate ==
  37018. + VCHIQ_SRVSTATE_OPENING) {
  37019. + service->remoteport = remoteport;
  37020. + vchiq_set_service_state(service,
  37021. + VCHIQ_SRVSTATE_OPEN);
  37022. + up(&service->remove_event);
  37023. + } else
  37024. + vchiq_log_error(vchiq_core_log_level,
  37025. + "OPENACK received in state %s",
  37026. + srvstate_names[service->srvstate]);
  37027. + break;
  37028. + case VCHIQ_MSG_CLOSE:
  37029. + WARN_ON(size != 0); /* There should be no data */
  37030. +
  37031. + vchiq_log_info(vchiq_core_log_level,
  37032. + "%d: prs CLOSE@%x (%d->%d)",
  37033. + state->id, (unsigned int)header,
  37034. + remoteport, localport);
  37035. +
  37036. + mark_service_closing_internal(service, 1);
  37037. +
  37038. + if (vchiq_close_service_internal(service,
  37039. + 1/*close_recvd*/) == VCHIQ_RETRY)
  37040. + goto bail_not_ready;
  37041. +
  37042. + vchiq_log_info(vchiq_core_log_level,
  37043. + "Close Service %c%c%c%c s:%u d:%d",
  37044. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  37045. + service->localport,
  37046. + service->remoteport);
  37047. + break;
  37048. + case VCHIQ_MSG_DATA:
  37049. + vchiq_log_trace(vchiq_core_log_level,
  37050. + "%d: prs DATA@%x,%x (%d->%d)",
  37051. + state->id, (unsigned int)header, size,
  37052. + remoteport, localport);
  37053. +
  37054. + if ((service->remoteport == remoteport)
  37055. + && (service->srvstate ==
  37056. + VCHIQ_SRVSTATE_OPEN)) {
  37057. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  37058. + claim_slot(state->rx_info);
  37059. + DEBUG_TRACE(PARSE_LINE);
  37060. + if (make_service_callback(service,
  37061. + VCHIQ_MESSAGE_AVAILABLE, header,
  37062. + NULL) == VCHIQ_RETRY) {
  37063. + DEBUG_TRACE(PARSE_LINE);
  37064. + goto bail_not_ready;
  37065. + }
  37066. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  37067. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  37068. + size);
  37069. + } else {
  37070. + VCHIQ_STATS_INC(state, error_count);
  37071. + }
  37072. + break;
  37073. + case VCHIQ_MSG_CONNECT:
  37074. + vchiq_log_info(vchiq_core_log_level,
  37075. + "%d: prs CONNECT@%x",
  37076. + state->id, (unsigned int)header);
  37077. + up(&state->connect);
  37078. + break;
  37079. + case VCHIQ_MSG_BULK_RX:
  37080. + case VCHIQ_MSG_BULK_TX: {
  37081. + VCHIQ_BULK_QUEUE_T *queue;
  37082. + WARN_ON(!state->is_master);
  37083. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  37084. + &service->bulk_tx : &service->bulk_rx;
  37085. + if ((service->remoteport == remoteport)
  37086. + && (service->srvstate ==
  37087. + VCHIQ_SRVSTATE_OPEN)) {
  37088. + VCHIQ_BULK_T *bulk;
  37089. + int resolved = 0;
  37090. +
  37091. + DEBUG_TRACE(PARSE_LINE);
  37092. + if (mutex_lock_interruptible(
  37093. + &service->bulk_mutex) != 0) {
  37094. + DEBUG_TRACE(PARSE_LINE);
  37095. + goto bail_not_ready;
  37096. + }
  37097. +
  37098. + WARN_ON(!(queue->remote_insert < queue->remove +
  37099. + VCHIQ_NUM_SERVICE_BULKS));
  37100. + bulk = &queue->bulks[
  37101. + BULK_INDEX(queue->remote_insert)];
  37102. + bulk->remote_data =
  37103. + (void *)((int *)header->data)[0];
  37104. + bulk->remote_size = ((int *)header->data)[1];
  37105. + wmb();
  37106. +
  37107. + vchiq_log_info(vchiq_core_log_level,
  37108. + "%d: prs %s@%x (%d->%d) %x@%x",
  37109. + state->id, msg_type_str(type),
  37110. + (unsigned int)header,
  37111. + remoteport, localport,
  37112. + bulk->remote_size,
  37113. + (unsigned int)bulk->remote_data);
  37114. +
  37115. + queue->remote_insert++;
  37116. +
  37117. + if (atomic_read(&pause_bulks_count)) {
  37118. + state->deferred_bulks++;
  37119. + vchiq_log_info(vchiq_core_log_level,
  37120. + "%s: deferring bulk (%d)",
  37121. + __func__,
  37122. + state->deferred_bulks);
  37123. + if (state->conn_state !=
  37124. + VCHIQ_CONNSTATE_PAUSE_SENT)
  37125. + vchiq_log_error(
  37126. + vchiq_core_log_level,
  37127. + "%s: bulks paused in "
  37128. + "unexpected state %s",
  37129. + __func__,
  37130. + conn_state_names[
  37131. + state->conn_state]);
  37132. + } else if (state->conn_state ==
  37133. + VCHIQ_CONNSTATE_CONNECTED) {
  37134. + DEBUG_TRACE(PARSE_LINE);
  37135. + resolved = resolve_bulks(service,
  37136. + queue);
  37137. + }
  37138. +
  37139. + mutex_unlock(&service->bulk_mutex);
  37140. + if (resolved)
  37141. + notify_bulks(service, queue,
  37142. + 1/*retry_poll*/);
  37143. + }
  37144. + } break;
  37145. + case VCHIQ_MSG_BULK_RX_DONE:
  37146. + case VCHIQ_MSG_BULK_TX_DONE:
  37147. + WARN_ON(state->is_master);
  37148. + if ((service->remoteport == remoteport)
  37149. + && (service->srvstate !=
  37150. + VCHIQ_SRVSTATE_FREE)) {
  37151. + VCHIQ_BULK_QUEUE_T *queue;
  37152. + VCHIQ_BULK_T *bulk;
  37153. +
  37154. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  37155. + &service->bulk_rx : &service->bulk_tx;
  37156. +
  37157. + DEBUG_TRACE(PARSE_LINE);
  37158. + if (mutex_lock_interruptible(
  37159. + &service->bulk_mutex) != 0) {
  37160. + DEBUG_TRACE(PARSE_LINE);
  37161. + goto bail_not_ready;
  37162. + }
  37163. + if ((int)(queue->remote_insert -
  37164. + queue->local_insert) >= 0) {
  37165. + vchiq_log_error(vchiq_core_log_level,
  37166. + "%d: prs %s@%x (%d->%d) "
  37167. + "unexpected (ri=%d,li=%d)",
  37168. + state->id, msg_type_str(type),
  37169. + (unsigned int)header,
  37170. + remoteport, localport,
  37171. + queue->remote_insert,
  37172. + queue->local_insert);
  37173. + mutex_unlock(&service->bulk_mutex);
  37174. + break;
  37175. + }
  37176. +
  37177. + BUG_ON(queue->process == queue->local_insert);
  37178. + BUG_ON(queue->process != queue->remote_insert);
  37179. +
  37180. + bulk = &queue->bulks[
  37181. + BULK_INDEX(queue->remote_insert)];
  37182. + bulk->actual = *(int *)header->data;
  37183. + queue->remote_insert++;
  37184. +
  37185. + vchiq_log_info(vchiq_core_log_level,
  37186. + "%d: prs %s@%x (%d->%d) %x@%x",
  37187. + state->id, msg_type_str(type),
  37188. + (unsigned int)header,
  37189. + remoteport, localport,
  37190. + bulk->actual, (unsigned int)bulk->data);
  37191. +
  37192. + vchiq_log_trace(vchiq_core_log_level,
  37193. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  37194. + state->id, localport,
  37195. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  37196. + 'r' : 't',
  37197. + queue->local_insert,
  37198. + queue->remote_insert, queue->process);
  37199. +
  37200. + DEBUG_TRACE(PARSE_LINE);
  37201. + WARN_ON(queue->process == queue->local_insert);
  37202. + vchiq_complete_bulk(bulk);
  37203. + queue->process++;
  37204. + mutex_unlock(&service->bulk_mutex);
  37205. + DEBUG_TRACE(PARSE_LINE);
  37206. + notify_bulks(service, queue, 1/*retry_poll*/);
  37207. + DEBUG_TRACE(PARSE_LINE);
  37208. + }
  37209. + break;
  37210. + case VCHIQ_MSG_PADDING:
  37211. + vchiq_log_trace(vchiq_core_log_level,
  37212. + "%d: prs PADDING@%x,%x",
  37213. + state->id, (unsigned int)header, size);
  37214. + break;
  37215. + case VCHIQ_MSG_PAUSE:
  37216. + /* If initiated, signal the application thread */
  37217. + vchiq_log_trace(vchiq_core_log_level,
  37218. + "%d: prs PAUSE@%x,%x",
  37219. + state->id, (unsigned int)header, size);
  37220. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  37221. + vchiq_log_error(vchiq_core_log_level,
  37222. + "%d: PAUSE received in state PAUSED",
  37223. + state->id);
  37224. + break;
  37225. + }
  37226. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  37227. + /* Send a PAUSE in response */
  37228. + if (queue_message(state, NULL,
  37229. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  37230. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  37231. + goto bail_not_ready;
  37232. + if (state->is_master)
  37233. + pause_bulks(state);
  37234. + }
  37235. + /* At this point slot_mutex is held */
  37236. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  37237. + vchiq_platform_paused(state);
  37238. + break;
  37239. + case VCHIQ_MSG_RESUME:
  37240. + vchiq_log_trace(vchiq_core_log_level,
  37241. + "%d: prs RESUME@%x,%x",
  37242. + state->id, (unsigned int)header, size);
  37243. + /* Release the slot mutex */
  37244. + mutex_unlock(&state->slot_mutex);
  37245. + if (state->is_master)
  37246. + resume_bulks(state);
  37247. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  37248. + vchiq_platform_resumed(state);
  37249. + break;
  37250. +
  37251. + case VCHIQ_MSG_REMOTE_USE:
  37252. + vchiq_on_remote_use(state);
  37253. + break;
  37254. + case VCHIQ_MSG_REMOTE_RELEASE:
  37255. + vchiq_on_remote_release(state);
  37256. + break;
  37257. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  37258. + vchiq_on_remote_use_active(state);
  37259. + break;
  37260. +
  37261. + default:
  37262. + vchiq_log_error(vchiq_core_log_level,
  37263. + "%d: prs invalid msgid %x@%x,%x",
  37264. + state->id, msgid, (unsigned int)header, size);
  37265. + WARN(1, "invalid message\n");
  37266. + break;
  37267. + }
  37268. +
  37269. +skip_message:
  37270. + if (service) {
  37271. + unlock_service(service);
  37272. + service = NULL;
  37273. + }
  37274. +
  37275. + state->rx_pos += calc_stride(size);
  37276. +
  37277. + DEBUG_TRACE(PARSE_LINE);
  37278. + /* Perform some housekeeping when the end of the slot is
  37279. + ** reached. */
  37280. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  37281. + /* Remove the extra reference count. */
  37282. + release_slot(state, state->rx_info, NULL, NULL);
  37283. + state->rx_data = NULL;
  37284. + }
  37285. + }
  37286. +
  37287. +bail_not_ready:
  37288. + if (service)
  37289. + unlock_service(service);
  37290. +}
  37291. +
  37292. +/* Called by the slot handler thread */
  37293. +static int
  37294. +slot_handler_func(void *v)
  37295. +{
  37296. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  37297. + VCHIQ_SHARED_STATE_T *local = state->local;
  37298. + DEBUG_INITIALISE(local)
  37299. +
  37300. + while (1) {
  37301. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  37302. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  37303. + remote_event_wait(&local->trigger);
  37304. +
  37305. + rmb();
  37306. +
  37307. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  37308. + if (state->poll_needed) {
  37309. + /* Check if we need to suspend - may change our
  37310. + * conn_state */
  37311. + vchiq_platform_check_suspend(state);
  37312. +
  37313. + state->poll_needed = 0;
  37314. +
  37315. + /* Handle service polling and other rare conditions here
  37316. + ** out of the mainline code */
  37317. + switch (state->conn_state) {
  37318. + case VCHIQ_CONNSTATE_CONNECTED:
  37319. + /* Poll the services as requested */
  37320. + poll_services(state);
  37321. + break;
  37322. +
  37323. + case VCHIQ_CONNSTATE_PAUSING:
  37324. + if (state->is_master)
  37325. + pause_bulks(state);
  37326. + if (queue_message(state, NULL,
  37327. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  37328. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  37329. + vchiq_set_conn_state(state,
  37330. + VCHIQ_CONNSTATE_PAUSE_SENT);
  37331. + } else {
  37332. + if (state->is_master)
  37333. + resume_bulks(state);
  37334. + /* Retry later */
  37335. + state->poll_needed = 1;
  37336. + }
  37337. + break;
  37338. +
  37339. + case VCHIQ_CONNSTATE_PAUSED:
  37340. + vchiq_platform_resume(state);
  37341. + break;
  37342. +
  37343. + case VCHIQ_CONNSTATE_RESUMING:
  37344. + if (queue_message(state, NULL,
  37345. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  37346. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  37347. + if (state->is_master)
  37348. + resume_bulks(state);
  37349. + vchiq_set_conn_state(state,
  37350. + VCHIQ_CONNSTATE_CONNECTED);
  37351. + vchiq_platform_resumed(state);
  37352. + } else {
  37353. + /* This should really be impossible,
  37354. + ** since the PAUSE should have flushed
  37355. + ** through outstanding messages. */
  37356. + vchiq_log_error(vchiq_core_log_level,
  37357. + "Failed to send RESUME "
  37358. + "message");
  37359. + BUG();
  37360. + }
  37361. + break;
  37362. +
  37363. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  37364. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  37365. + vchiq_platform_handle_timeout(state);
  37366. + break;
  37367. + default:
  37368. + break;
  37369. + }
  37370. +
  37371. +
  37372. + }
  37373. +
  37374. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  37375. + parse_rx_slots(state);
  37376. + }
  37377. + return 0;
  37378. +}
  37379. +
  37380. +
  37381. +/* Called by the recycle thread */
  37382. +static int
  37383. +recycle_func(void *v)
  37384. +{
  37385. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  37386. + VCHIQ_SHARED_STATE_T *local = state->local;
  37387. +
  37388. + while (1) {
  37389. + remote_event_wait(&local->recycle);
  37390. +
  37391. + process_free_queue(state);
  37392. + }
  37393. + return 0;
  37394. +}
  37395. +
  37396. +
  37397. +/* Called by the sync thread */
  37398. +static int
  37399. +sync_func(void *v)
  37400. +{
  37401. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  37402. + VCHIQ_SHARED_STATE_T *local = state->local;
  37403. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  37404. + state->remote->slot_sync);
  37405. +
  37406. + while (1) {
  37407. + VCHIQ_SERVICE_T *service;
  37408. + int msgid, size;
  37409. + int type;
  37410. + unsigned int localport, remoteport;
  37411. +
  37412. + remote_event_wait(&local->sync_trigger);
  37413. +
  37414. + rmb();
  37415. +
  37416. + msgid = header->msgid;
  37417. + size = header->size;
  37418. + type = VCHIQ_MSG_TYPE(msgid);
  37419. + localport = VCHIQ_MSG_DSTPORT(msgid);
  37420. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  37421. +
  37422. + service = find_service_by_port(state, localport);
  37423. +
  37424. + if (!service) {
  37425. + vchiq_log_error(vchiq_sync_log_level,
  37426. + "%d: sf %s@%x (%d->%d) - "
  37427. + "invalid/closed service %d",
  37428. + state->id, msg_type_str(type),
  37429. + (unsigned int)header,
  37430. + remoteport, localport, localport);
  37431. + release_message_sync(state, header);
  37432. + continue;
  37433. + }
  37434. +
  37435. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  37436. + int svc_fourcc;
  37437. +
  37438. + svc_fourcc = service
  37439. + ? service->base.fourcc
  37440. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  37441. + vchiq_log_trace(vchiq_sync_log_level,
  37442. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  37443. + msg_type_str(type),
  37444. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  37445. + remoteport, localport, size);
  37446. + if (size > 0)
  37447. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  37448. + min(64, size));
  37449. + }
  37450. +
  37451. + switch (type) {
  37452. + case VCHIQ_MSG_OPENACK:
  37453. + if (size >= sizeof(struct vchiq_openack_payload)) {
  37454. + const struct vchiq_openack_payload *payload =
  37455. + (struct vchiq_openack_payload *)
  37456. + header->data;
  37457. + service->peer_version = payload->version;
  37458. + }
  37459. + vchiq_log_info(vchiq_sync_log_level,
  37460. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  37461. + state->id, (unsigned int)header, size,
  37462. + remoteport, localport, service->peer_version);
  37463. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  37464. + service->remoteport = remoteport;
  37465. + vchiq_set_service_state(service,
  37466. + VCHIQ_SRVSTATE_OPENSYNC);
  37467. + up(&service->remove_event);
  37468. + }
  37469. + release_message_sync(state, header);
  37470. + break;
  37471. +
  37472. + case VCHIQ_MSG_DATA:
  37473. + vchiq_log_trace(vchiq_sync_log_level,
  37474. + "%d: sf DATA@%x,%x (%d->%d)",
  37475. + state->id, (unsigned int)header, size,
  37476. + remoteport, localport);
  37477. +
  37478. + if ((service->remoteport == remoteport) &&
  37479. + (service->srvstate ==
  37480. + VCHIQ_SRVSTATE_OPENSYNC)) {
  37481. + if (make_service_callback(service,
  37482. + VCHIQ_MESSAGE_AVAILABLE, header,
  37483. + NULL) == VCHIQ_RETRY)
  37484. + vchiq_log_error(vchiq_sync_log_level,
  37485. + "synchronous callback to "
  37486. + "service %d returns "
  37487. + "VCHIQ_RETRY",
  37488. + localport);
  37489. + }
  37490. + break;
  37491. +
  37492. + default:
  37493. + vchiq_log_error(vchiq_sync_log_level,
  37494. + "%d: sf unexpected msgid %x@%x,%x",
  37495. + state->id, msgid, (unsigned int)header, size);
  37496. + release_message_sync(state, header);
  37497. + break;
  37498. + }
  37499. +
  37500. + unlock_service(service);
  37501. + }
  37502. +
  37503. + return 0;
  37504. +}
  37505. +
  37506. +
  37507. +static void
  37508. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  37509. +{
  37510. + queue->local_insert = 0;
  37511. + queue->remote_insert = 0;
  37512. + queue->process = 0;
  37513. + queue->remote_notify = 0;
  37514. + queue->remove = 0;
  37515. +}
  37516. +
  37517. +
  37518. +inline const char *
  37519. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  37520. +{
  37521. + return conn_state_names[conn_state];
  37522. +}
  37523. +
  37524. +
  37525. +VCHIQ_SLOT_ZERO_T *
  37526. +vchiq_init_slots(void *mem_base, int mem_size)
  37527. +{
  37528. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  37529. + VCHIQ_SLOT_ZERO_T *slot_zero =
  37530. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  37531. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  37532. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  37533. +
  37534. + /* Ensure there is enough memory to run an absolutely minimum system */
  37535. + num_slots -= first_data_slot;
  37536. +
  37537. + if (num_slots < 4) {
  37538. + vchiq_log_error(vchiq_core_log_level,
  37539. + "vchiq_init_slots - insufficient memory %x bytes",
  37540. + mem_size);
  37541. + return NULL;
  37542. + }
  37543. +
  37544. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  37545. +
  37546. + slot_zero->magic = VCHIQ_MAGIC;
  37547. + slot_zero->version = VCHIQ_VERSION;
  37548. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  37549. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  37550. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  37551. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  37552. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  37553. +
  37554. + slot_zero->master.slot_sync = first_data_slot;
  37555. + slot_zero->master.slot_first = first_data_slot + 1;
  37556. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  37557. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  37558. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  37559. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  37560. +
  37561. + return slot_zero;
  37562. +}
  37563. +
  37564. +VCHIQ_STATUS_T
  37565. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  37566. + int is_master)
  37567. +{
  37568. + VCHIQ_SHARED_STATE_T *local;
  37569. + VCHIQ_SHARED_STATE_T *remote;
  37570. + VCHIQ_STATUS_T status;
  37571. + char threadname[10];
  37572. + static int id;
  37573. + int i;
  37574. +
  37575. + vchiq_log_warning(vchiq_core_log_level,
  37576. + "%s: slot_zero = 0x%08lx, is_master = %d",
  37577. + __func__, (unsigned long)slot_zero, is_master);
  37578. +
  37579. + /* Check the input configuration */
  37580. +
  37581. + if (slot_zero->magic != VCHIQ_MAGIC) {
  37582. + vchiq_loud_error_header();
  37583. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  37584. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  37585. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  37586. + vchiq_loud_error_footer();
  37587. + return VCHIQ_ERROR;
  37588. + }
  37589. +
  37590. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  37591. + vchiq_loud_error_header();
  37592. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  37593. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  37594. + "(minimum %d)",
  37595. + (unsigned int)slot_zero, slot_zero->version,
  37596. + VCHIQ_VERSION_MIN);
  37597. + vchiq_loud_error("Restart with a newer VideoCore image.");
  37598. + vchiq_loud_error_footer();
  37599. + return VCHIQ_ERROR;
  37600. + }
  37601. +
  37602. + if (VCHIQ_VERSION < slot_zero->version_min) {
  37603. + vchiq_loud_error_header();
  37604. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  37605. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  37606. + "minimum %d)",
  37607. + (unsigned int)slot_zero, VCHIQ_VERSION,
  37608. + slot_zero->version_min);
  37609. + vchiq_loud_error("Restart with a newer kernel.");
  37610. + vchiq_loud_error_footer();
  37611. + return VCHIQ_ERROR;
  37612. + }
  37613. +
  37614. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  37615. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  37616. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  37617. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  37618. + vchiq_loud_error_header();
  37619. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  37620. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  37621. + "(expected %x)",
  37622. + (unsigned int)slot_zero,
  37623. + slot_zero->slot_zero_size,
  37624. + sizeof(VCHIQ_SLOT_ZERO_T));
  37625. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  37626. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  37627. + "(expected %d",
  37628. + (unsigned int)slot_zero, slot_zero->slot_size,
  37629. + VCHIQ_SLOT_SIZE);
  37630. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  37631. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  37632. + "(expected %d)",
  37633. + (unsigned int)slot_zero, slot_zero->max_slots,
  37634. + VCHIQ_MAX_SLOTS);
  37635. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  37636. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  37637. + "(expected %d)",
  37638. + (unsigned int)slot_zero,
  37639. + slot_zero->max_slots_per_side,
  37640. + VCHIQ_MAX_SLOTS_PER_SIDE);
  37641. + vchiq_loud_error_footer();
  37642. + return VCHIQ_ERROR;
  37643. + }
  37644. +
  37645. + if (is_master) {
  37646. + local = &slot_zero->master;
  37647. + remote = &slot_zero->slave;
  37648. + } else {
  37649. + local = &slot_zero->slave;
  37650. + remote = &slot_zero->master;
  37651. + }
  37652. +
  37653. + if (local->initialised) {
  37654. + vchiq_loud_error_header();
  37655. + if (remote->initialised)
  37656. + vchiq_loud_error("local state has already been "
  37657. + "initialised");
  37658. + else
  37659. + vchiq_loud_error("master/slave mismatch - two %ss",
  37660. + is_master ? "master" : "slave");
  37661. + vchiq_loud_error_footer();
  37662. + return VCHIQ_ERROR;
  37663. + }
  37664. +
  37665. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  37666. +
  37667. + state->id = id++;
  37668. + state->is_master = is_master;
  37669. +
  37670. + /*
  37671. + initialize shared state pointers
  37672. + */
  37673. +
  37674. + state->local = local;
  37675. + state->remote = remote;
  37676. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  37677. +
  37678. + /*
  37679. + initialize events and mutexes
  37680. + */
  37681. +
  37682. + sema_init(&state->connect, 0);
  37683. + mutex_init(&state->mutex);
  37684. + sema_init(&state->trigger_event, 0);
  37685. + sema_init(&state->recycle_event, 0);
  37686. + sema_init(&state->sync_trigger_event, 0);
  37687. + sema_init(&state->sync_release_event, 0);
  37688. +
  37689. + mutex_init(&state->slot_mutex);
  37690. + mutex_init(&state->recycle_mutex);
  37691. + mutex_init(&state->sync_mutex);
  37692. + mutex_init(&state->bulk_transfer_mutex);
  37693. +
  37694. + sema_init(&state->slot_available_event, 0);
  37695. + sema_init(&state->slot_remove_event, 0);
  37696. + sema_init(&state->data_quota_event, 0);
  37697. +
  37698. + state->slot_queue_available = 0;
  37699. +
  37700. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  37701. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  37702. + &state->service_quotas[i];
  37703. + sema_init(&service_quota->quota_event, 0);
  37704. + }
  37705. +
  37706. + for (i = local->slot_first; i <= local->slot_last; i++) {
  37707. + local->slot_queue[state->slot_queue_available++] = i;
  37708. + up(&state->slot_available_event);
  37709. + }
  37710. +
  37711. + state->default_slot_quota = state->slot_queue_available/2;
  37712. + state->default_message_quota =
  37713. + min((unsigned short)(state->default_slot_quota * 256),
  37714. + (unsigned short)~0);
  37715. +
  37716. + state->previous_data_index = -1;
  37717. + state->data_use_count = 0;
  37718. + state->data_quota = state->slot_queue_available - 1;
  37719. +
  37720. + local->trigger.event = &state->trigger_event;
  37721. + remote_event_create(&local->trigger);
  37722. + local->tx_pos = 0;
  37723. +
  37724. + local->recycle.event = &state->recycle_event;
  37725. + remote_event_create(&local->recycle);
  37726. + local->slot_queue_recycle = state->slot_queue_available;
  37727. +
  37728. + local->sync_trigger.event = &state->sync_trigger_event;
  37729. + remote_event_create(&local->sync_trigger);
  37730. +
  37731. + local->sync_release.event = &state->sync_release_event;
  37732. + remote_event_create(&local->sync_release);
  37733. +
  37734. + /* At start-of-day, the slot is empty and available */
  37735. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  37736. + = VCHIQ_MSGID_PADDING;
  37737. + remote_event_signal_local(&local->sync_release);
  37738. +
  37739. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  37740. +
  37741. + status = vchiq_platform_init_state(state);
  37742. +
  37743. + /*
  37744. + bring up slot handler thread
  37745. + */
  37746. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  37747. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  37748. + (void *)state,
  37749. + threadname);
  37750. +
  37751. + if (state->slot_handler_thread == NULL) {
  37752. + vchiq_loud_error_header();
  37753. + vchiq_loud_error("couldn't create thread %s", threadname);
  37754. + vchiq_loud_error_footer();
  37755. + return VCHIQ_ERROR;
  37756. + }
  37757. + set_user_nice(state->slot_handler_thread, -19);
  37758. + wake_up_process(state->slot_handler_thread);
  37759. +
  37760. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  37761. + state->recycle_thread = kthread_create(&recycle_func,
  37762. + (void *)state,
  37763. + threadname);
  37764. + if (state->recycle_thread == NULL) {
  37765. + vchiq_loud_error_header();
  37766. + vchiq_loud_error("couldn't create thread %s", threadname);
  37767. + vchiq_loud_error_footer();
  37768. + return VCHIQ_ERROR;
  37769. + }
  37770. + set_user_nice(state->recycle_thread, -19);
  37771. + wake_up_process(state->recycle_thread);
  37772. +
  37773. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  37774. + state->sync_thread = kthread_create(&sync_func,
  37775. + (void *)state,
  37776. + threadname);
  37777. + if (state->sync_thread == NULL) {
  37778. + vchiq_loud_error_header();
  37779. + vchiq_loud_error("couldn't create thread %s", threadname);
  37780. + vchiq_loud_error_footer();
  37781. + return VCHIQ_ERROR;
  37782. + }
  37783. + set_user_nice(state->sync_thread, -20);
  37784. + wake_up_process(state->sync_thread);
  37785. +
  37786. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  37787. + vchiq_states[state->id] = state;
  37788. +
  37789. + /* Indicate readiness to the other side */
  37790. + local->initialised = 1;
  37791. +
  37792. + return status;
  37793. +}
  37794. +
  37795. +/* Called from application thread when a client or server service is created. */
  37796. +VCHIQ_SERVICE_T *
  37797. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  37798. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  37799. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  37800. +{
  37801. + VCHIQ_SERVICE_T *service;
  37802. +
  37803. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  37804. + if (service) {
  37805. + service->base.fourcc = params->fourcc;
  37806. + service->base.callback = params->callback;
  37807. + service->base.userdata = params->userdata;
  37808. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  37809. + service->ref_count = 1;
  37810. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  37811. + service->userdata_term = userdata_term;
  37812. + service->localport = VCHIQ_PORT_FREE;
  37813. + service->remoteport = VCHIQ_PORT_FREE;
  37814. +
  37815. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  37816. + VCHIQ_FOURCC_INVALID : params->fourcc;
  37817. + service->client_id = 0;
  37818. + service->auto_close = 1;
  37819. + service->sync = 0;
  37820. + service->closing = 0;
  37821. + service->trace = 0;
  37822. + atomic_set(&service->poll_flags, 0);
  37823. + service->version = params->version;
  37824. + service->version_min = params->version_min;
  37825. + service->state = state;
  37826. + service->instance = instance;
  37827. + service->service_use_count = 0;
  37828. + init_bulk_queue(&service->bulk_tx);
  37829. + init_bulk_queue(&service->bulk_rx);
  37830. + sema_init(&service->remove_event, 0);
  37831. + sema_init(&service->bulk_remove_event, 0);
  37832. + mutex_init(&service->bulk_mutex);
  37833. + memset(&service->stats, 0, sizeof(service->stats));
  37834. + } else {
  37835. + vchiq_log_error(vchiq_core_log_level,
  37836. + "Out of memory");
  37837. + }
  37838. +
  37839. + if (service) {
  37840. + VCHIQ_SERVICE_T **pservice = NULL;
  37841. + int i;
  37842. +
  37843. + /* Although it is perfectly possible to use service_spinlock
  37844. + ** to protect the creation of services, it is overkill as it
  37845. + ** disables interrupts while the array is searched.
  37846. + ** The only danger is of another thread trying to create a
  37847. + ** service - service deletion is safe.
  37848. + ** Therefore it is preferable to use state->mutex which,
  37849. + ** although slower to claim, doesn't block interrupts while
  37850. + ** it is held.
  37851. + */
  37852. +
  37853. + mutex_lock(&state->mutex);
  37854. +
  37855. + /* Prepare to use a previously unused service */
  37856. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  37857. + pservice = &state->services[state->unused_service];
  37858. +
  37859. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  37860. + for (i = 0; i < state->unused_service; i++) {
  37861. + VCHIQ_SERVICE_T *srv = state->services[i];
  37862. + if (!srv) {
  37863. + pservice = &state->services[i];
  37864. + break;
  37865. + }
  37866. + }
  37867. + } else {
  37868. + for (i = (state->unused_service - 1); i >= 0; i--) {
  37869. + VCHIQ_SERVICE_T *srv = state->services[i];
  37870. + if (!srv)
  37871. + pservice = &state->services[i];
  37872. + else if ((srv->public_fourcc == params->fourcc)
  37873. + && ((srv->instance != instance) ||
  37874. + (srv->base.callback !=
  37875. + params->callback))) {
  37876. + /* There is another server using this
  37877. + ** fourcc which doesn't match. */
  37878. + pservice = NULL;
  37879. + break;
  37880. + }
  37881. + }
  37882. + }
  37883. +
  37884. + if (pservice) {
  37885. + service->localport = (pservice - state->services);
  37886. + if (!handle_seq)
  37887. + handle_seq = VCHIQ_MAX_STATES *
  37888. + VCHIQ_MAX_SERVICES;
  37889. + service->handle = handle_seq |
  37890. + (state->id * VCHIQ_MAX_SERVICES) |
  37891. + service->localport;
  37892. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  37893. + *pservice = service;
  37894. + if (pservice == &state->services[state->unused_service])
  37895. + state->unused_service++;
  37896. + }
  37897. +
  37898. + mutex_unlock(&state->mutex);
  37899. +
  37900. + if (!pservice) {
  37901. + kfree(service);
  37902. + service = NULL;
  37903. + }
  37904. + }
  37905. +
  37906. + if (service) {
  37907. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  37908. + &state->service_quotas[service->localport];
  37909. + service_quota->slot_quota = state->default_slot_quota;
  37910. + service_quota->message_quota = state->default_message_quota;
  37911. + if (service_quota->slot_use_count == 0)
  37912. + service_quota->previous_tx_index =
  37913. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  37914. + - 1;
  37915. +
  37916. + /* Bring this service online */
  37917. + vchiq_set_service_state(service, srvstate);
  37918. +
  37919. + vchiq_log_info(vchiq_core_msg_log_level,
  37920. + "%s Service %c%c%c%c SrcPort:%d",
  37921. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  37922. + ? "Open" : "Add",
  37923. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  37924. + service->localport);
  37925. + }
  37926. +
  37927. + /* Don't unlock the service - leave it with a ref_count of 1. */
  37928. +
  37929. + return service;
  37930. +}
  37931. +
  37932. +VCHIQ_STATUS_T
  37933. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  37934. +{
  37935. + struct vchiq_open_payload payload = {
  37936. + service->base.fourcc,
  37937. + client_id,
  37938. + service->version,
  37939. + service->version_min
  37940. + };
  37941. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  37942. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  37943. +
  37944. + service->client_id = client_id;
  37945. + vchiq_use_service_internal(service);
  37946. + status = queue_message(service->state, NULL,
  37947. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  37948. + &body, 1, sizeof(payload), 1);
  37949. + if (status == VCHIQ_SUCCESS) {
  37950. + /* Wait for the ACK/NAK */
  37951. + if (down_interruptible(&service->remove_event) != 0) {
  37952. + status = VCHIQ_RETRY;
  37953. + vchiq_release_service_internal(service);
  37954. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  37955. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  37956. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  37957. + vchiq_log_error(vchiq_core_log_level,
  37958. + "%d: osi - srvstate = %s (ref %d)",
  37959. + service->state->id,
  37960. + srvstate_names[service->srvstate],
  37961. + service->ref_count);
  37962. + status = VCHIQ_ERROR;
  37963. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  37964. + vchiq_release_service_internal(service);
  37965. + }
  37966. + }
  37967. + return status;
  37968. +}
  37969. +
  37970. +static void
  37971. +release_service_messages(VCHIQ_SERVICE_T *service)
  37972. +{
  37973. + VCHIQ_STATE_T *state = service->state;
  37974. + int slot_last = state->remote->slot_last;
  37975. + int i;
  37976. +
  37977. + /* Release any claimed messages */
  37978. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  37979. + VCHIQ_SLOT_INFO_T *slot_info =
  37980. + SLOT_INFO_FROM_INDEX(state, i);
  37981. + if (slot_info->release_count != slot_info->use_count) {
  37982. + char *data =
  37983. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  37984. + unsigned int pos, end;
  37985. +
  37986. + end = VCHIQ_SLOT_SIZE;
  37987. + if (data == state->rx_data)
  37988. + /* This buffer is still being read from - stop
  37989. + ** at the current read position */
  37990. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  37991. +
  37992. + pos = 0;
  37993. +
  37994. + while (pos < end) {
  37995. + VCHIQ_HEADER_T *header =
  37996. + (VCHIQ_HEADER_T *)(data + pos);
  37997. + int msgid = header->msgid;
  37998. + int port = VCHIQ_MSG_DSTPORT(msgid);
  37999. + if ((port == service->localport) &&
  38000. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  38001. + vchiq_log_info(vchiq_core_log_level,
  38002. + " fsi - hdr %x",
  38003. + (unsigned int)header);
  38004. + release_slot(state, slot_info, header,
  38005. + NULL);
  38006. + }
  38007. + pos += calc_stride(header->size);
  38008. + if (pos > VCHIQ_SLOT_SIZE) {
  38009. + vchiq_log_error(vchiq_core_log_level,
  38010. + "fsi - pos %x: header %x, "
  38011. + "msgid %x, header->msgid %x, "
  38012. + "header->size %x",
  38013. + pos, (unsigned int)header,
  38014. + msgid, header->msgid,
  38015. + header->size);
  38016. + WARN(1, "invalid slot position\n");
  38017. + }
  38018. + }
  38019. + }
  38020. + }
  38021. +}
  38022. +
  38023. +static int
  38024. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  38025. +{
  38026. + VCHIQ_STATUS_T status;
  38027. +
  38028. + /* Abort any outstanding bulk transfers */
  38029. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  38030. + return 0;
  38031. + abort_outstanding_bulks(service, &service->bulk_tx);
  38032. + abort_outstanding_bulks(service, &service->bulk_rx);
  38033. + mutex_unlock(&service->bulk_mutex);
  38034. +
  38035. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  38036. + if (status == VCHIQ_SUCCESS)
  38037. + status = notify_bulks(service, &service->bulk_rx,
  38038. + 0/*!retry_poll*/);
  38039. + return (status == VCHIQ_SUCCESS);
  38040. +}
  38041. +
  38042. +static VCHIQ_STATUS_T
  38043. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  38044. +{
  38045. + VCHIQ_STATUS_T status;
  38046. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  38047. + int newstate;
  38048. +
  38049. + switch (service->srvstate) {
  38050. + case VCHIQ_SRVSTATE_OPEN:
  38051. + case VCHIQ_SRVSTATE_CLOSESENT:
  38052. + case VCHIQ_SRVSTATE_CLOSERECVD:
  38053. + if (is_server) {
  38054. + if (service->auto_close) {
  38055. + service->client_id = 0;
  38056. + service->remoteport = VCHIQ_PORT_FREE;
  38057. + newstate = VCHIQ_SRVSTATE_LISTENING;
  38058. + } else
  38059. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  38060. + } else
  38061. + newstate = VCHIQ_SRVSTATE_CLOSED;
  38062. + vchiq_set_service_state(service, newstate);
  38063. + break;
  38064. + case VCHIQ_SRVSTATE_LISTENING:
  38065. + break;
  38066. + default:
  38067. + vchiq_log_error(vchiq_core_log_level,
  38068. + "close_service_complete(%x) called in state %s",
  38069. + service->handle, srvstate_names[service->srvstate]);
  38070. + WARN(1, "close_service_complete in unexpected state\n");
  38071. + return VCHIQ_ERROR;
  38072. + }
  38073. +
  38074. + status = make_service_callback(service,
  38075. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  38076. +
  38077. + if (status != VCHIQ_RETRY) {
  38078. + int uc = service->service_use_count;
  38079. + int i;
  38080. + /* Complete the close process */
  38081. + for (i = 0; i < uc; i++)
  38082. + /* cater for cases where close is forced and the
  38083. + ** client may not close all it's handles */
  38084. + vchiq_release_service_internal(service);
  38085. +
  38086. + service->client_id = 0;
  38087. + service->remoteport = VCHIQ_PORT_FREE;
  38088. +
  38089. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  38090. + vchiq_free_service_internal(service);
  38091. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  38092. + if (is_server)
  38093. + service->closing = 0;
  38094. +
  38095. + up(&service->remove_event);
  38096. + }
  38097. + } else
  38098. + vchiq_set_service_state(service, failstate);
  38099. +
  38100. + return status;
  38101. +}
  38102. +
  38103. +/* Called by the slot handler */
  38104. +VCHIQ_STATUS_T
  38105. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  38106. +{
  38107. + VCHIQ_STATE_T *state = service->state;
  38108. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  38109. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  38110. +
  38111. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  38112. + service->state->id, service->localport, close_recvd,
  38113. + srvstate_names[service->srvstate]);
  38114. +
  38115. + switch (service->srvstate) {
  38116. + case VCHIQ_SRVSTATE_CLOSED:
  38117. + case VCHIQ_SRVSTATE_HIDDEN:
  38118. + case VCHIQ_SRVSTATE_LISTENING:
  38119. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  38120. + if (close_recvd)
  38121. + vchiq_log_error(vchiq_core_log_level,
  38122. + "vchiq_close_service_internal(1) called "
  38123. + "in state %s",
  38124. + srvstate_names[service->srvstate]);
  38125. + else if (is_server) {
  38126. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  38127. + status = VCHIQ_ERROR;
  38128. + } else {
  38129. + service->client_id = 0;
  38130. + service->remoteport = VCHIQ_PORT_FREE;
  38131. + if (service->srvstate ==
  38132. + VCHIQ_SRVSTATE_CLOSEWAIT)
  38133. + vchiq_set_service_state(service,
  38134. + VCHIQ_SRVSTATE_LISTENING);
  38135. + }
  38136. + up(&service->remove_event);
  38137. + } else
  38138. + vchiq_free_service_internal(service);
  38139. + break;
  38140. + case VCHIQ_SRVSTATE_OPENING:
  38141. + if (close_recvd) {
  38142. + /* The open was rejected - tell the user */
  38143. + vchiq_set_service_state(service,
  38144. + VCHIQ_SRVSTATE_CLOSEWAIT);
  38145. + up(&service->remove_event);
  38146. + } else {
  38147. + /* Shutdown mid-open - let the other side know */
  38148. + status = queue_message(state, service,
  38149. + VCHIQ_MAKE_MSG
  38150. + (VCHIQ_MSG_CLOSE,
  38151. + service->localport,
  38152. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  38153. + NULL, 0, 0, 0);
  38154. + }
  38155. + break;
  38156. +
  38157. + case VCHIQ_SRVSTATE_OPENSYNC:
  38158. + mutex_lock(&state->sync_mutex);
  38159. + /* Drop through */
  38160. +
  38161. + case VCHIQ_SRVSTATE_OPEN:
  38162. + if (state->is_master || close_recvd) {
  38163. + if (!do_abort_bulks(service))
  38164. + status = VCHIQ_RETRY;
  38165. + }
  38166. +
  38167. + release_service_messages(service);
  38168. +
  38169. + if (status == VCHIQ_SUCCESS)
  38170. + status = queue_message(state, service,
  38171. + VCHIQ_MAKE_MSG
  38172. + (VCHIQ_MSG_CLOSE,
  38173. + service->localport,
  38174. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  38175. + NULL, 0, 0, 0);
  38176. +
  38177. + if (status == VCHIQ_SUCCESS) {
  38178. + if (!close_recvd)
  38179. + break;
  38180. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  38181. + mutex_unlock(&state->sync_mutex);
  38182. + break;
  38183. + } else
  38184. + break;
  38185. +
  38186. + status = close_service_complete(service,
  38187. + VCHIQ_SRVSTATE_CLOSERECVD);
  38188. + break;
  38189. +
  38190. + case VCHIQ_SRVSTATE_CLOSESENT:
  38191. + if (!close_recvd)
  38192. + /* This happens when a process is killed mid-close */
  38193. + break;
  38194. +
  38195. + if (!state->is_master) {
  38196. + if (!do_abort_bulks(service)) {
  38197. + status = VCHIQ_RETRY;
  38198. + break;
  38199. + }
  38200. + }
  38201. +
  38202. + if (status == VCHIQ_SUCCESS)
  38203. + status = close_service_complete(service,
  38204. + VCHIQ_SRVSTATE_CLOSERECVD);
  38205. + break;
  38206. +
  38207. + case VCHIQ_SRVSTATE_CLOSERECVD:
  38208. + if (!close_recvd && is_server)
  38209. + /* Force into LISTENING mode */
  38210. + vchiq_set_service_state(service,
  38211. + VCHIQ_SRVSTATE_LISTENING);
  38212. + status = close_service_complete(service,
  38213. + VCHIQ_SRVSTATE_CLOSERECVD);
  38214. + break;
  38215. +
  38216. + default:
  38217. + vchiq_log_error(vchiq_core_log_level,
  38218. + "vchiq_close_service_internal(%d) called in state %s",
  38219. + close_recvd, srvstate_names[service->srvstate]);
  38220. + break;
  38221. + }
  38222. +
  38223. + return status;
  38224. +}
  38225. +
  38226. +/* Called from the application process upon process death */
  38227. +void
  38228. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  38229. +{
  38230. + VCHIQ_STATE_T *state = service->state;
  38231. +
  38232. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  38233. + state->id, service->localport, service->remoteport);
  38234. +
  38235. + mark_service_closing(service);
  38236. +
  38237. + /* Mark the service for removal by the slot handler */
  38238. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  38239. +}
  38240. +
  38241. +/* Called from the slot handler */
  38242. +void
  38243. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  38244. +{
  38245. + VCHIQ_STATE_T *state = service->state;
  38246. +
  38247. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  38248. + state->id, service->localport);
  38249. +
  38250. + switch (service->srvstate) {
  38251. + case VCHIQ_SRVSTATE_OPENING:
  38252. + case VCHIQ_SRVSTATE_CLOSED:
  38253. + case VCHIQ_SRVSTATE_HIDDEN:
  38254. + case VCHIQ_SRVSTATE_LISTENING:
  38255. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  38256. + break;
  38257. + default:
  38258. + vchiq_log_error(vchiq_core_log_level,
  38259. + "%d: fsi - (%d) in state %s",
  38260. + state->id, service->localport,
  38261. + srvstate_names[service->srvstate]);
  38262. + return;
  38263. + }
  38264. +
  38265. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  38266. +
  38267. + up(&service->remove_event);
  38268. +
  38269. + /* Release the initial lock */
  38270. + unlock_service(service);
  38271. +}
  38272. +
  38273. +VCHIQ_STATUS_T
  38274. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  38275. +{
  38276. + VCHIQ_SERVICE_T *service;
  38277. + int i;
  38278. +
  38279. + /* Find all services registered to this client and enable them. */
  38280. + i = 0;
  38281. + while ((service = next_service_by_instance(state, instance,
  38282. + &i)) != NULL) {
  38283. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  38284. + vchiq_set_service_state(service,
  38285. + VCHIQ_SRVSTATE_LISTENING);
  38286. + unlock_service(service);
  38287. + }
  38288. +
  38289. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  38290. + if (queue_message(state, NULL,
  38291. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  38292. + 0, 1) == VCHIQ_RETRY)
  38293. + return VCHIQ_RETRY;
  38294. +
  38295. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  38296. + }
  38297. +
  38298. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  38299. + if (down_interruptible(&state->connect) != 0)
  38300. + return VCHIQ_RETRY;
  38301. +
  38302. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  38303. + up(&state->connect);
  38304. + }
  38305. +
  38306. + return VCHIQ_SUCCESS;
  38307. +}
  38308. +
  38309. +VCHIQ_STATUS_T
  38310. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  38311. +{
  38312. + VCHIQ_SERVICE_T *service;
  38313. + int i;
  38314. +
  38315. + /* Find all services registered to this client and enable them. */
  38316. + i = 0;
  38317. + while ((service = next_service_by_instance(state, instance,
  38318. + &i)) != NULL) {
  38319. + (void)vchiq_remove_service(service->handle);
  38320. + unlock_service(service);
  38321. + }
  38322. +
  38323. + return VCHIQ_SUCCESS;
  38324. +}
  38325. +
  38326. +VCHIQ_STATUS_T
  38327. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  38328. +{
  38329. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  38330. +
  38331. + switch (state->conn_state) {
  38332. + case VCHIQ_CONNSTATE_CONNECTED:
  38333. + /* Request a pause */
  38334. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  38335. + request_poll(state, NULL, 0);
  38336. + break;
  38337. + default:
  38338. + vchiq_log_error(vchiq_core_log_level,
  38339. + "vchiq_pause_internal in state %s\n",
  38340. + conn_state_names[state->conn_state]);
  38341. + status = VCHIQ_ERROR;
  38342. + VCHIQ_STATS_INC(state, error_count);
  38343. + break;
  38344. + }
  38345. +
  38346. + return status;
  38347. +}
  38348. +
  38349. +VCHIQ_STATUS_T
  38350. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  38351. +{
  38352. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  38353. +
  38354. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  38355. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  38356. + request_poll(state, NULL, 0);
  38357. + } else {
  38358. + status = VCHIQ_ERROR;
  38359. + VCHIQ_STATS_INC(state, error_count);
  38360. + }
  38361. +
  38362. + return status;
  38363. +}
  38364. +
  38365. +VCHIQ_STATUS_T
  38366. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  38367. +{
  38368. + /* Unregister the service */
  38369. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38370. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  38371. +
  38372. + if (!service)
  38373. + return VCHIQ_ERROR;
  38374. +
  38375. + vchiq_log_info(vchiq_core_log_level,
  38376. + "%d: close_service:%d",
  38377. + service->state->id, service->localport);
  38378. +
  38379. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  38380. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  38381. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  38382. + unlock_service(service);
  38383. + return VCHIQ_ERROR;
  38384. + }
  38385. +
  38386. + mark_service_closing(service);
  38387. +
  38388. + if (current == service->state->slot_handler_thread) {
  38389. + status = vchiq_close_service_internal(service,
  38390. + 0/*!close_recvd*/);
  38391. + BUG_ON(status == VCHIQ_RETRY);
  38392. + } else {
  38393. + /* Mark the service for termination by the slot handler */
  38394. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  38395. + }
  38396. +
  38397. + while (1) {
  38398. + if (down_interruptible(&service->remove_event) != 0) {
  38399. + status = VCHIQ_RETRY;
  38400. + break;
  38401. + }
  38402. +
  38403. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  38404. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  38405. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  38406. + break;
  38407. +
  38408. + vchiq_log_warning(vchiq_core_log_level,
  38409. + "%d: close_service:%d - waiting in state %s",
  38410. + service->state->id, service->localport,
  38411. + srvstate_names[service->srvstate]);
  38412. + }
  38413. +
  38414. + if ((status == VCHIQ_SUCCESS) &&
  38415. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  38416. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  38417. + status = VCHIQ_ERROR;
  38418. +
  38419. + unlock_service(service);
  38420. +
  38421. + return status;
  38422. +}
  38423. +
  38424. +VCHIQ_STATUS_T
  38425. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  38426. +{
  38427. + /* Unregister the service */
  38428. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38429. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  38430. +
  38431. + if (!service)
  38432. + return VCHIQ_ERROR;
  38433. +
  38434. + vchiq_log_info(vchiq_core_log_level,
  38435. + "%d: remove_service:%d",
  38436. + service->state->id, service->localport);
  38437. +
  38438. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  38439. + unlock_service(service);
  38440. + return VCHIQ_ERROR;
  38441. + }
  38442. +
  38443. + mark_service_closing(service);
  38444. +
  38445. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  38446. + (current == service->state->slot_handler_thread)) {
  38447. + /* Make it look like a client, because it must be removed and
  38448. + not left in the LISTENING state. */
  38449. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  38450. +
  38451. + status = vchiq_close_service_internal(service,
  38452. + 0/*!close_recvd*/);
  38453. + BUG_ON(status == VCHIQ_RETRY);
  38454. + } else {
  38455. + /* Mark the service for removal by the slot handler */
  38456. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  38457. + }
  38458. + while (1) {
  38459. + if (down_interruptible(&service->remove_event) != 0) {
  38460. + status = VCHIQ_RETRY;
  38461. + break;
  38462. + }
  38463. +
  38464. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  38465. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  38466. + break;
  38467. +
  38468. + vchiq_log_warning(vchiq_core_log_level,
  38469. + "%d: remove_service:%d - waiting in state %s",
  38470. + service->state->id, service->localport,
  38471. + srvstate_names[service->srvstate]);
  38472. + }
  38473. +
  38474. + if ((status == VCHIQ_SUCCESS) &&
  38475. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  38476. + status = VCHIQ_ERROR;
  38477. +
  38478. + unlock_service(service);
  38479. +
  38480. + return status;
  38481. +}
  38482. +
  38483. +
  38484. +/* This function may be called by kernel threads or user threads.
  38485. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  38486. + * received and the call should be retried after being returned to user
  38487. + * context.
  38488. + * When called in blocking mode, the userdata field points to a bulk_waiter
  38489. + * structure.
  38490. + */
  38491. +VCHIQ_STATUS_T
  38492. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  38493. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  38494. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  38495. +{
  38496. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38497. + VCHIQ_BULK_QUEUE_T *queue;
  38498. + VCHIQ_BULK_T *bulk;
  38499. + VCHIQ_STATE_T *state;
  38500. + struct bulk_waiter *bulk_waiter = NULL;
  38501. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  38502. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  38503. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  38504. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  38505. +
  38506. + if (!service ||
  38507. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  38508. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  38509. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  38510. + goto error_exit;
  38511. +
  38512. + switch (mode) {
  38513. + case VCHIQ_BULK_MODE_NOCALLBACK:
  38514. + case VCHIQ_BULK_MODE_CALLBACK:
  38515. + break;
  38516. + case VCHIQ_BULK_MODE_BLOCKING:
  38517. + bulk_waiter = (struct bulk_waiter *)userdata;
  38518. + sema_init(&bulk_waiter->event, 0);
  38519. + bulk_waiter->actual = 0;
  38520. + bulk_waiter->bulk = NULL;
  38521. + break;
  38522. + case VCHIQ_BULK_MODE_WAITING:
  38523. + bulk_waiter = (struct bulk_waiter *)userdata;
  38524. + bulk = bulk_waiter->bulk;
  38525. + goto waiting;
  38526. + default:
  38527. + goto error_exit;
  38528. + }
  38529. +
  38530. + state = service->state;
  38531. +
  38532. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  38533. + &service->bulk_tx : &service->bulk_rx;
  38534. +
  38535. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  38536. + status = VCHIQ_RETRY;
  38537. + goto error_exit;
  38538. + }
  38539. +
  38540. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  38541. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  38542. + do {
  38543. + mutex_unlock(&service->bulk_mutex);
  38544. + if (down_interruptible(&service->bulk_remove_event)
  38545. + != 0) {
  38546. + status = VCHIQ_RETRY;
  38547. + goto error_exit;
  38548. + }
  38549. + if (mutex_lock_interruptible(&service->bulk_mutex)
  38550. + != 0) {
  38551. + status = VCHIQ_RETRY;
  38552. + goto error_exit;
  38553. + }
  38554. + } while (queue->local_insert == queue->remove +
  38555. + VCHIQ_NUM_SERVICE_BULKS);
  38556. + }
  38557. +
  38558. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  38559. +
  38560. + bulk->mode = mode;
  38561. + bulk->dir = dir;
  38562. + bulk->userdata = userdata;
  38563. + bulk->size = size;
  38564. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  38565. +
  38566. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  38567. + VCHIQ_SUCCESS)
  38568. + goto unlock_error_exit;
  38569. +
  38570. + wmb();
  38571. +
  38572. + vchiq_log_info(vchiq_core_log_level,
  38573. + "%d: bt (%d->%d) %cx %x@%x %x",
  38574. + state->id,
  38575. + service->localport, service->remoteport, dir_char,
  38576. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  38577. +
  38578. + if (state->is_master) {
  38579. + queue->local_insert++;
  38580. + if (resolve_bulks(service, queue))
  38581. + request_poll(state, service,
  38582. + (dir == VCHIQ_BULK_TRANSMIT) ?
  38583. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  38584. + } else {
  38585. + int payload[2] = { (int)bulk->data, bulk->size };
  38586. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  38587. +
  38588. + status = queue_message(state, NULL,
  38589. + VCHIQ_MAKE_MSG(dir_msgtype,
  38590. + service->localport, service->remoteport),
  38591. + &element, 1, sizeof(payload), 1);
  38592. + if (status != VCHIQ_SUCCESS) {
  38593. + vchiq_complete_bulk(bulk);
  38594. + goto unlock_error_exit;
  38595. + }
  38596. + queue->local_insert++;
  38597. + }
  38598. +
  38599. + mutex_unlock(&service->bulk_mutex);
  38600. +
  38601. + vchiq_log_trace(vchiq_core_log_level,
  38602. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  38603. + state->id,
  38604. + service->localport, dir_char,
  38605. + queue->local_insert, queue->remote_insert, queue->process);
  38606. +
  38607. +waiting:
  38608. + unlock_service(service);
  38609. +
  38610. + status = VCHIQ_SUCCESS;
  38611. +
  38612. + if (bulk_waiter) {
  38613. + bulk_waiter->bulk = bulk;
  38614. + if (down_interruptible(&bulk_waiter->event) != 0)
  38615. + status = VCHIQ_RETRY;
  38616. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  38617. + status = VCHIQ_ERROR;
  38618. + }
  38619. +
  38620. + return status;
  38621. +
  38622. +unlock_error_exit:
  38623. + mutex_unlock(&service->bulk_mutex);
  38624. +
  38625. +error_exit:
  38626. + if (service)
  38627. + unlock_service(service);
  38628. + return status;
  38629. +}
  38630. +
  38631. +VCHIQ_STATUS_T
  38632. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  38633. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  38634. +{
  38635. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38636. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  38637. +
  38638. + unsigned int size = 0;
  38639. + unsigned int i;
  38640. +
  38641. + if (!service ||
  38642. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  38643. + goto error_exit;
  38644. +
  38645. + for (i = 0; i < (unsigned int)count; i++) {
  38646. + if (elements[i].size) {
  38647. + if (elements[i].data == NULL) {
  38648. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  38649. + goto error_exit;
  38650. + }
  38651. + size += elements[i].size;
  38652. + }
  38653. + }
  38654. +
  38655. + if (size > VCHIQ_MAX_MSG_SIZE) {
  38656. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  38657. + goto error_exit;
  38658. + }
  38659. +
  38660. + switch (service->srvstate) {
  38661. + case VCHIQ_SRVSTATE_OPEN:
  38662. + status = queue_message(service->state, service,
  38663. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  38664. + service->localport,
  38665. + service->remoteport),
  38666. + elements, count, size, 1);
  38667. + break;
  38668. + case VCHIQ_SRVSTATE_OPENSYNC:
  38669. + status = queue_message_sync(service->state, service,
  38670. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  38671. + service->localport,
  38672. + service->remoteport),
  38673. + elements, count, size, 1);
  38674. + break;
  38675. + default:
  38676. + status = VCHIQ_ERROR;
  38677. + break;
  38678. + }
  38679. +
  38680. +error_exit:
  38681. + if (service)
  38682. + unlock_service(service);
  38683. +
  38684. + return status;
  38685. +}
  38686. +
  38687. +void
  38688. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  38689. +{
  38690. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38691. + VCHIQ_SHARED_STATE_T *remote;
  38692. + VCHIQ_STATE_T *state;
  38693. + int slot_index;
  38694. +
  38695. + if (!service)
  38696. + return;
  38697. +
  38698. + state = service->state;
  38699. + remote = state->remote;
  38700. +
  38701. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  38702. +
  38703. + if ((slot_index >= remote->slot_first) &&
  38704. + (slot_index <= remote->slot_last)) {
  38705. + int msgid = header->msgid;
  38706. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  38707. + VCHIQ_SLOT_INFO_T *slot_info =
  38708. + SLOT_INFO_FROM_INDEX(state, slot_index);
  38709. +
  38710. + release_slot(state, slot_info, header, service);
  38711. + }
  38712. + } else if (slot_index == remote->slot_sync)
  38713. + release_message_sync(state, header);
  38714. +
  38715. + unlock_service(service);
  38716. +}
  38717. +
  38718. +static void
  38719. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  38720. +{
  38721. + header->msgid = VCHIQ_MSGID_PADDING;
  38722. + wmb();
  38723. + remote_event_signal(&state->remote->sync_release);
  38724. +}
  38725. +
  38726. +VCHIQ_STATUS_T
  38727. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  38728. +{
  38729. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  38730. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38731. +
  38732. + if (!service ||
  38733. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  38734. + !peer_version)
  38735. + goto exit;
  38736. + *peer_version = service->peer_version;
  38737. + status = VCHIQ_SUCCESS;
  38738. +
  38739. +exit:
  38740. + if (service)
  38741. + unlock_service(service);
  38742. + return status;
  38743. +}
  38744. +
  38745. +VCHIQ_STATUS_T
  38746. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  38747. + int config_size, VCHIQ_CONFIG_T *pconfig)
  38748. +{
  38749. + VCHIQ_CONFIG_T config;
  38750. +
  38751. + (void)instance;
  38752. +
  38753. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  38754. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  38755. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  38756. + config.max_services = VCHIQ_MAX_SERVICES;
  38757. + config.version = VCHIQ_VERSION;
  38758. + config.version_min = VCHIQ_VERSION_MIN;
  38759. +
  38760. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  38761. + return VCHIQ_ERROR;
  38762. +
  38763. + memcpy(pconfig, &config,
  38764. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  38765. +
  38766. + return VCHIQ_SUCCESS;
  38767. +}
  38768. +
  38769. +VCHIQ_STATUS_T
  38770. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  38771. + VCHIQ_SERVICE_OPTION_T option, int value)
  38772. +{
  38773. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  38774. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  38775. +
  38776. + if (service) {
  38777. + switch (option) {
  38778. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  38779. + service->auto_close = value;
  38780. + status = VCHIQ_SUCCESS;
  38781. + break;
  38782. +
  38783. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  38784. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  38785. + &service->state->service_quotas[
  38786. + service->localport];
  38787. + if (value == 0)
  38788. + value = service->state->default_slot_quota;
  38789. + if ((value >= service_quota->slot_use_count) &&
  38790. + (value < (unsigned short)~0)) {
  38791. + service_quota->slot_quota = value;
  38792. + if ((value >= service_quota->slot_use_count) &&
  38793. + (service_quota->message_quota >=
  38794. + service_quota->message_use_count)) {
  38795. + /* Signal the service that it may have
  38796. + ** dropped below its quota */
  38797. + up(&service_quota->quota_event);
  38798. + }
  38799. + status = VCHIQ_SUCCESS;
  38800. + }
  38801. + } break;
  38802. +
  38803. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  38804. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  38805. + &service->state->service_quotas[
  38806. + service->localport];
  38807. + if (value == 0)
  38808. + value = service->state->default_message_quota;
  38809. + if ((value >= service_quota->message_use_count) &&
  38810. + (value < (unsigned short)~0)) {
  38811. + service_quota->message_quota = value;
  38812. + if ((value >=
  38813. + service_quota->message_use_count) &&
  38814. + (service_quota->slot_quota >=
  38815. + service_quota->slot_use_count))
  38816. + /* Signal the service that it may have
  38817. + ** dropped below its quota */
  38818. + up(&service_quota->quota_event);
  38819. + status = VCHIQ_SUCCESS;
  38820. + }
  38821. + } break;
  38822. +
  38823. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  38824. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  38825. + (service->srvstate ==
  38826. + VCHIQ_SRVSTATE_LISTENING)) {
  38827. + service->sync = value;
  38828. + status = VCHIQ_SUCCESS;
  38829. + }
  38830. + break;
  38831. +
  38832. + case VCHIQ_SERVICE_OPTION_TRACE:
  38833. + service->trace = value;
  38834. + status = VCHIQ_SUCCESS;
  38835. + break;
  38836. +
  38837. + default:
  38838. + break;
  38839. + }
  38840. + unlock_service(service);
  38841. + }
  38842. +
  38843. + return status;
  38844. +}
  38845. +
  38846. +void
  38847. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  38848. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  38849. +{
  38850. + static const char *const debug_names[] = {
  38851. + "<entries>",
  38852. + "SLOT_HANDLER_COUNT",
  38853. + "SLOT_HANDLER_LINE",
  38854. + "PARSE_LINE",
  38855. + "PARSE_HEADER",
  38856. + "PARSE_MSGID",
  38857. + "AWAIT_COMPLETION_LINE",
  38858. + "DEQUEUE_MESSAGE_LINE",
  38859. + "SERVICE_CALLBACK_LINE",
  38860. + "MSG_QUEUE_FULL_COUNT",
  38861. + "COMPLETION_QUEUE_FULL_COUNT"
  38862. + };
  38863. + int i;
  38864. +
  38865. + char buf[80];
  38866. + int len;
  38867. + len = snprintf(buf, sizeof(buf),
  38868. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  38869. + label, shared->slot_first, shared->slot_last,
  38870. + shared->tx_pos, shared->slot_queue_recycle);
  38871. + vchiq_dump(dump_context, buf, len + 1);
  38872. +
  38873. + len = snprintf(buf, sizeof(buf),
  38874. + " Slots claimed:");
  38875. + vchiq_dump(dump_context, buf, len + 1);
  38876. +
  38877. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  38878. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  38879. + if (slot_info.use_count != slot_info.release_count) {
  38880. + len = snprintf(buf, sizeof(buf),
  38881. + " %d: %d/%d", i, slot_info.use_count,
  38882. + slot_info.release_count);
  38883. + vchiq_dump(dump_context, buf, len + 1);
  38884. + }
  38885. + }
  38886. +
  38887. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  38888. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  38889. + debug_names[i], shared->debug[i], shared->debug[i]);
  38890. + vchiq_dump(dump_context, buf, len + 1);
  38891. + }
  38892. +}
  38893. +
  38894. +void
  38895. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  38896. +{
  38897. + char buf[80];
  38898. + int len;
  38899. + int i;
  38900. +
  38901. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  38902. + conn_state_names[state->conn_state]);
  38903. + vchiq_dump(dump_context, buf, len + 1);
  38904. +
  38905. + len = snprintf(buf, sizeof(buf),
  38906. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  38907. + state->local->tx_pos,
  38908. + (uint32_t)state->tx_data +
  38909. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  38910. + state->rx_pos,
  38911. + (uint32_t)state->rx_data +
  38912. + (state->rx_pos & VCHIQ_SLOT_MASK));
  38913. + vchiq_dump(dump_context, buf, len + 1);
  38914. +
  38915. + len = snprintf(buf, sizeof(buf),
  38916. + " Version: %d (min %d)",
  38917. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  38918. + vchiq_dump(dump_context, buf, len + 1);
  38919. +
  38920. + if (VCHIQ_ENABLE_STATS) {
  38921. + len = snprintf(buf, sizeof(buf),
  38922. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  38923. + "error_count=%d",
  38924. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  38925. + state->stats.error_count);
  38926. + vchiq_dump(dump_context, buf, len + 1);
  38927. + }
  38928. +
  38929. + len = snprintf(buf, sizeof(buf),
  38930. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  38931. + "(%d data)",
  38932. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  38933. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  38934. + state->data_quota - state->data_use_count,
  38935. + state->local->slot_queue_recycle - state->slot_queue_available,
  38936. + state->stats.slot_stalls, state->stats.data_stalls);
  38937. + vchiq_dump(dump_context, buf, len + 1);
  38938. +
  38939. + vchiq_dump_platform_state(dump_context);
  38940. +
  38941. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  38942. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  38943. +
  38944. + vchiq_dump_platform_instances(dump_context);
  38945. +
  38946. + for (i = 0; i < state->unused_service; i++) {
  38947. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  38948. +
  38949. + if (service) {
  38950. + vchiq_dump_service_state(dump_context, service);
  38951. + unlock_service(service);
  38952. + }
  38953. + }
  38954. +}
  38955. +
  38956. +void
  38957. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  38958. +{
  38959. + char buf[80];
  38960. + int len;
  38961. +
  38962. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  38963. + service->localport, srvstate_names[service->srvstate],
  38964. + service->ref_count - 1); /*Don't include the lock just taken*/
  38965. +
  38966. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  38967. + char remoteport[30];
  38968. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  38969. + &service->state->service_quotas[service->localport];
  38970. + int fourcc = service->base.fourcc;
  38971. + int tx_pending, rx_pending;
  38972. + if (service->remoteport != VCHIQ_PORT_FREE) {
  38973. + int len2 = snprintf(remoteport, sizeof(remoteport),
  38974. + "%d", service->remoteport);
  38975. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  38976. + snprintf(remoteport + len2,
  38977. + sizeof(remoteport) - len2,
  38978. + " (client %x)", service->client_id);
  38979. + } else
  38980. + strcpy(remoteport, "n/a");
  38981. +
  38982. + len += snprintf(buf + len, sizeof(buf) - len,
  38983. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  38984. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  38985. + remoteport,
  38986. + service_quota->message_use_count,
  38987. + service_quota->message_quota,
  38988. + service_quota->slot_use_count,
  38989. + service_quota->slot_quota);
  38990. +
  38991. + vchiq_dump(dump_context, buf, len + 1);
  38992. +
  38993. + tx_pending = service->bulk_tx.local_insert -
  38994. + service->bulk_tx.remote_insert;
  38995. +
  38996. + rx_pending = service->bulk_rx.local_insert -
  38997. + service->bulk_rx.remote_insert;
  38998. +
  38999. + len = snprintf(buf, sizeof(buf),
  39000. + " Bulk: tx_pending=%d (size %d),"
  39001. + " rx_pending=%d (size %d)",
  39002. + tx_pending,
  39003. + tx_pending ? service->bulk_tx.bulks[
  39004. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  39005. + rx_pending,
  39006. + rx_pending ? service->bulk_rx.bulks[
  39007. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  39008. +
  39009. + if (VCHIQ_ENABLE_STATS) {
  39010. + vchiq_dump(dump_context, buf, len + 1);
  39011. +
  39012. + len = snprintf(buf, sizeof(buf),
  39013. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  39014. + "rx_count=%d, rx_bytes=%llu",
  39015. + service->stats.ctrl_tx_count,
  39016. + service->stats.ctrl_tx_bytes,
  39017. + service->stats.ctrl_rx_count,
  39018. + service->stats.ctrl_rx_bytes);
  39019. + vchiq_dump(dump_context, buf, len + 1);
  39020. +
  39021. + len = snprintf(buf, sizeof(buf),
  39022. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  39023. + "rx_count=%d, rx_bytes=%llu",
  39024. + service->stats.bulk_tx_count,
  39025. + service->stats.bulk_tx_bytes,
  39026. + service->stats.bulk_rx_count,
  39027. + service->stats.bulk_rx_bytes);
  39028. + vchiq_dump(dump_context, buf, len + 1);
  39029. +
  39030. + len = snprintf(buf, sizeof(buf),
  39031. + " %d quota stalls, %d slot stalls, "
  39032. + "%d bulk stalls, %d aborted, %d errors",
  39033. + service->stats.quota_stalls,
  39034. + service->stats.slot_stalls,
  39035. + service->stats.bulk_stalls,
  39036. + service->stats.bulk_aborted_count,
  39037. + service->stats.error_count);
  39038. + }
  39039. + }
  39040. +
  39041. + vchiq_dump(dump_context, buf, len + 1);
  39042. +
  39043. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  39044. + vchiq_dump_platform_service_state(dump_context, service);
  39045. +}
  39046. +
  39047. +
  39048. +void
  39049. +vchiq_loud_error_header(void)
  39050. +{
  39051. + vchiq_log_error(vchiq_core_log_level,
  39052. + "============================================================"
  39053. + "================");
  39054. + vchiq_log_error(vchiq_core_log_level,
  39055. + "============================================================"
  39056. + "================");
  39057. + vchiq_log_error(vchiq_core_log_level, "=====");
  39058. +}
  39059. +
  39060. +void
  39061. +vchiq_loud_error_footer(void)
  39062. +{
  39063. + vchiq_log_error(vchiq_core_log_level, "=====");
  39064. + vchiq_log_error(vchiq_core_log_level,
  39065. + "============================================================"
  39066. + "================");
  39067. + vchiq_log_error(vchiq_core_log_level,
  39068. + "============================================================"
  39069. + "================");
  39070. +}
  39071. +
  39072. +
  39073. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  39074. +{
  39075. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  39076. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  39077. + status = queue_message(state, NULL,
  39078. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  39079. + NULL, 0, 0, 0);
  39080. + return status;
  39081. +}
  39082. +
  39083. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  39084. +{
  39085. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  39086. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  39087. + status = queue_message(state, NULL,
  39088. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  39089. + NULL, 0, 0, 0);
  39090. + return status;
  39091. +}
  39092. +
  39093. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  39094. +{
  39095. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  39096. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  39097. + status = queue_message(state, NULL,
  39098. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  39099. + NULL, 0, 0, 0);
  39100. + return status;
  39101. +}
  39102. +
  39103. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  39104. + size_t numBytes)
  39105. +{
  39106. + const uint8_t *mem = (const uint8_t *)voidMem;
  39107. + size_t offset;
  39108. + char lineBuf[100];
  39109. + char *s;
  39110. +
  39111. + while (numBytes > 0) {
  39112. + s = lineBuf;
  39113. +
  39114. + for (offset = 0; offset < 16; offset++) {
  39115. + if (offset < numBytes)
  39116. + s += snprintf(s, 4, "%02x ", mem[offset]);
  39117. + else
  39118. + s += snprintf(s, 4, " ");
  39119. + }
  39120. +
  39121. + for (offset = 0; offset < 16; offset++) {
  39122. + if (offset < numBytes) {
  39123. + uint8_t ch = mem[offset];
  39124. +
  39125. + if ((ch < ' ') || (ch > '~'))
  39126. + ch = '.';
  39127. + *s++ = (char)ch;
  39128. + }
  39129. + }
  39130. + *s++ = '\0';
  39131. +
  39132. + if ((label != NULL) && (*label != '\0'))
  39133. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  39134. + "%s: %08x: %s", label, addr, lineBuf);
  39135. + else
  39136. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  39137. + "%08x: %s", addr, lineBuf);
  39138. +
  39139. + addr += 16;
  39140. + mem += 16;
  39141. + if (numBytes > 16)
  39142. + numBytes -= 16;
  39143. + else
  39144. + numBytes = 0;
  39145. + }
  39146. +}
  39147. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  39148. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  39149. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2015-03-10 17:26:50.554216692 +0100
  39150. @@ -0,0 +1,711 @@
  39151. +/**
  39152. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  39153. + *
  39154. + * Redistribution and use in source and binary forms, with or without
  39155. + * modification, are permitted provided that the following conditions
  39156. + * are met:
  39157. + * 1. Redistributions of source code must retain the above copyright
  39158. + * notice, this list of conditions, and the following disclaimer,
  39159. + * without modification.
  39160. + * 2. Redistributions in binary form must reproduce the above copyright
  39161. + * notice, this list of conditions and the following disclaimer in the
  39162. + * documentation and/or other materials provided with the distribution.
  39163. + * 3. The names of the above-listed copyright holders may not be used
  39164. + * to endorse or promote products derived from this software without
  39165. + * specific prior written permission.
  39166. + *
  39167. + * ALTERNATIVELY, this software may be distributed under the terms of the
  39168. + * GNU General Public License ("GPL") version 2, as published by the Free
  39169. + * Software Foundation.
  39170. + *
  39171. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  39172. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  39173. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39174. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  39175. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39176. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39177. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39178. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  39179. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  39180. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  39181. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39182. + */
  39183. +
  39184. +#ifndef VCHIQ_CORE_H
  39185. +#define VCHIQ_CORE_H
  39186. +
  39187. +#include <linux/mutex.h>
  39188. +#include <linux/semaphore.h>
  39189. +#include <linux/kthread.h>
  39190. +
  39191. +#include "vchiq_cfg.h"
  39192. +
  39193. +#include "vchiq.h"
  39194. +
  39195. +/* Run time control of log level, based on KERN_XXX level. */
  39196. +#define VCHIQ_LOG_DEFAULT 4
  39197. +#define VCHIQ_LOG_ERROR 3
  39198. +#define VCHIQ_LOG_WARNING 4
  39199. +#define VCHIQ_LOG_INFO 6
  39200. +#define VCHIQ_LOG_TRACE 7
  39201. +
  39202. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  39203. +
  39204. +#ifndef vchiq_log_error
  39205. +#define vchiq_log_error(cat, fmt, ...) \
  39206. + do { if (cat >= VCHIQ_LOG_ERROR) \
  39207. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  39208. +#endif
  39209. +#ifndef vchiq_log_warning
  39210. +#define vchiq_log_warning(cat, fmt, ...) \
  39211. + do { if (cat >= VCHIQ_LOG_WARNING) \
  39212. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  39213. +#endif
  39214. +#ifndef vchiq_log_info
  39215. +#define vchiq_log_info(cat, fmt, ...) \
  39216. + do { if (cat >= VCHIQ_LOG_INFO) \
  39217. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  39218. +#endif
  39219. +#ifndef vchiq_log_trace
  39220. +#define vchiq_log_trace(cat, fmt, ...) \
  39221. + do { if (cat >= VCHIQ_LOG_TRACE) \
  39222. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  39223. +#endif
  39224. +
  39225. +#define vchiq_loud_error(...) \
  39226. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  39227. +
  39228. +#ifndef vchiq_static_assert
  39229. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  39230. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  39231. +#endif
  39232. +
  39233. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  39234. +
  39235. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  39236. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  39237. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  39238. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  39239. +
  39240. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  39241. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  39242. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  39243. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  39244. +
  39245. +#define VCHIQ_MSG_PADDING 0 /* - */
  39246. +#define VCHIQ_MSG_CONNECT 1 /* - */
  39247. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  39248. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  39249. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  39250. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  39251. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  39252. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  39253. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  39254. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  39255. +#define VCHIQ_MSG_PAUSE 10 /* - */
  39256. +#define VCHIQ_MSG_RESUME 11 /* - */
  39257. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  39258. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  39259. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  39260. +
  39261. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  39262. +#define VCHIQ_PORT_FREE 0x1000
  39263. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  39264. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  39265. + ((type<<24) | (srcport<<12) | (dstport<<0))
  39266. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  39267. +#define VCHIQ_MSG_SRCPORT(msgid) \
  39268. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  39269. +#define VCHIQ_MSG_DSTPORT(msgid) \
  39270. + ((unsigned short)msgid & 0xfff)
  39271. +
  39272. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  39273. + ((fourcc) >> 24) & 0xff, \
  39274. + ((fourcc) >> 16) & 0xff, \
  39275. + ((fourcc) >> 8) & 0xff, \
  39276. + (fourcc) & 0xff
  39277. +
  39278. +/* Ensure the fields are wide enough */
  39279. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  39280. + == 0);
  39281. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  39282. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  39283. + (unsigned int)VCHIQ_PORT_FREE);
  39284. +
  39285. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  39286. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  39287. +
  39288. +#define VCHIQ_FOURCC_INVALID 0x00000000
  39289. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  39290. +
  39291. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  39292. +
  39293. +typedef uint32_t BITSET_T;
  39294. +
  39295. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  39296. +
  39297. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  39298. +#define BITSET_WORD(b) (b >> 5)
  39299. +#define BITSET_BIT(b) (1 << (b & 31))
  39300. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  39301. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  39302. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  39303. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  39304. +
  39305. +#if VCHIQ_ENABLE_STATS
  39306. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  39307. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  39308. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  39309. + (service->stats. stat += addend)
  39310. +#else
  39311. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  39312. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  39313. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  39314. +#endif
  39315. +
  39316. +enum {
  39317. + DEBUG_ENTRIES,
  39318. +#if VCHIQ_ENABLE_DEBUG
  39319. + DEBUG_SLOT_HANDLER_COUNT,
  39320. + DEBUG_SLOT_HANDLER_LINE,
  39321. + DEBUG_PARSE_LINE,
  39322. + DEBUG_PARSE_HEADER,
  39323. + DEBUG_PARSE_MSGID,
  39324. + DEBUG_AWAIT_COMPLETION_LINE,
  39325. + DEBUG_DEQUEUE_MESSAGE_LINE,
  39326. + DEBUG_SERVICE_CALLBACK_LINE,
  39327. + DEBUG_MSG_QUEUE_FULL_COUNT,
  39328. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  39329. +#endif
  39330. + DEBUG_MAX
  39331. +};
  39332. +
  39333. +#if VCHIQ_ENABLE_DEBUG
  39334. +
  39335. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  39336. +#define DEBUG_TRACE(d) \
  39337. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  39338. +#define DEBUG_VALUE(d, v) \
  39339. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  39340. +#define DEBUG_COUNT(d) \
  39341. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  39342. +
  39343. +#else /* VCHIQ_ENABLE_DEBUG */
  39344. +
  39345. +#define DEBUG_INITIALISE(local)
  39346. +#define DEBUG_TRACE(d)
  39347. +#define DEBUG_VALUE(d, v)
  39348. +#define DEBUG_COUNT(d)
  39349. +
  39350. +#endif /* VCHIQ_ENABLE_DEBUG */
  39351. +
  39352. +typedef enum {
  39353. + VCHIQ_CONNSTATE_DISCONNECTED,
  39354. + VCHIQ_CONNSTATE_CONNECTING,
  39355. + VCHIQ_CONNSTATE_CONNECTED,
  39356. + VCHIQ_CONNSTATE_PAUSING,
  39357. + VCHIQ_CONNSTATE_PAUSE_SENT,
  39358. + VCHIQ_CONNSTATE_PAUSED,
  39359. + VCHIQ_CONNSTATE_RESUMING,
  39360. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  39361. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  39362. +} VCHIQ_CONNSTATE_T;
  39363. +
  39364. +enum {
  39365. + VCHIQ_SRVSTATE_FREE,
  39366. + VCHIQ_SRVSTATE_HIDDEN,
  39367. + VCHIQ_SRVSTATE_LISTENING,
  39368. + VCHIQ_SRVSTATE_OPENING,
  39369. + VCHIQ_SRVSTATE_OPEN,
  39370. + VCHIQ_SRVSTATE_OPENSYNC,
  39371. + VCHIQ_SRVSTATE_CLOSESENT,
  39372. + VCHIQ_SRVSTATE_CLOSERECVD,
  39373. + VCHIQ_SRVSTATE_CLOSEWAIT,
  39374. + VCHIQ_SRVSTATE_CLOSED
  39375. +};
  39376. +
  39377. +enum {
  39378. + VCHIQ_POLL_TERMINATE,
  39379. + VCHIQ_POLL_REMOVE,
  39380. + VCHIQ_POLL_TXNOTIFY,
  39381. + VCHIQ_POLL_RXNOTIFY,
  39382. + VCHIQ_POLL_COUNT
  39383. +};
  39384. +
  39385. +typedef enum {
  39386. + VCHIQ_BULK_TRANSMIT,
  39387. + VCHIQ_BULK_RECEIVE
  39388. +} VCHIQ_BULK_DIR_T;
  39389. +
  39390. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  39391. +
  39392. +typedef struct vchiq_bulk_struct {
  39393. + short mode;
  39394. + short dir;
  39395. + void *userdata;
  39396. + VCHI_MEM_HANDLE_T handle;
  39397. + void *data;
  39398. + int size;
  39399. + void *remote_data;
  39400. + int remote_size;
  39401. + int actual;
  39402. +} VCHIQ_BULK_T;
  39403. +
  39404. +typedef struct vchiq_bulk_queue_struct {
  39405. + int local_insert; /* Where to insert the next local bulk */
  39406. + int remote_insert; /* Where to insert the next remote bulk (master) */
  39407. + int process; /* Bulk to transfer next */
  39408. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  39409. + int remove; /* Bulk to notify the local client of, and remove,
  39410. + ** next */
  39411. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  39412. +} VCHIQ_BULK_QUEUE_T;
  39413. +
  39414. +typedef struct remote_event_struct {
  39415. + int armed;
  39416. + int fired;
  39417. + struct semaphore *event;
  39418. +} REMOTE_EVENT_T;
  39419. +
  39420. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  39421. +
  39422. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  39423. +
  39424. +typedef struct vchiq_slot_struct {
  39425. + char data[VCHIQ_SLOT_SIZE];
  39426. +} VCHIQ_SLOT_T;
  39427. +
  39428. +typedef struct vchiq_slot_info_struct {
  39429. + /* Use two counters rather than one to avoid the need for a mutex. */
  39430. + short use_count;
  39431. + short release_count;
  39432. +} VCHIQ_SLOT_INFO_T;
  39433. +
  39434. +typedef struct vchiq_service_struct {
  39435. + VCHIQ_SERVICE_BASE_T base;
  39436. + VCHIQ_SERVICE_HANDLE_T handle;
  39437. + unsigned int ref_count;
  39438. + int srvstate;
  39439. + VCHIQ_USERDATA_TERM_T userdata_term;
  39440. + unsigned int localport;
  39441. + unsigned int remoteport;
  39442. + int public_fourcc;
  39443. + int client_id;
  39444. + char auto_close;
  39445. + char sync;
  39446. + char closing;
  39447. + char trace;
  39448. + atomic_t poll_flags;
  39449. + short version;
  39450. + short version_min;
  39451. + short peer_version;
  39452. +
  39453. + VCHIQ_STATE_T *state;
  39454. + VCHIQ_INSTANCE_T instance;
  39455. +
  39456. + int service_use_count;
  39457. +
  39458. + VCHIQ_BULK_QUEUE_T bulk_tx;
  39459. + VCHIQ_BULK_QUEUE_T bulk_rx;
  39460. +
  39461. + struct semaphore remove_event;
  39462. + struct semaphore bulk_remove_event;
  39463. + struct mutex bulk_mutex;
  39464. +
  39465. + struct service_stats_struct {
  39466. + int quota_stalls;
  39467. + int slot_stalls;
  39468. + int bulk_stalls;
  39469. + int error_count;
  39470. + int ctrl_tx_count;
  39471. + int ctrl_rx_count;
  39472. + int bulk_tx_count;
  39473. + int bulk_rx_count;
  39474. + int bulk_aborted_count;
  39475. + uint64_t ctrl_tx_bytes;
  39476. + uint64_t ctrl_rx_bytes;
  39477. + uint64_t bulk_tx_bytes;
  39478. + uint64_t bulk_rx_bytes;
  39479. + } stats;
  39480. +} VCHIQ_SERVICE_T;
  39481. +
  39482. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  39483. + statically allocated, since for accounting reasons a service's slot
  39484. + usage is carried over between users of the same port number.
  39485. + */
  39486. +typedef struct vchiq_service_quota_struct {
  39487. + unsigned short slot_quota;
  39488. + unsigned short slot_use_count;
  39489. + unsigned short message_quota;
  39490. + unsigned short message_use_count;
  39491. + struct semaphore quota_event;
  39492. + int previous_tx_index;
  39493. +} VCHIQ_SERVICE_QUOTA_T;
  39494. +
  39495. +typedef struct vchiq_shared_state_struct {
  39496. +
  39497. + /* A non-zero value here indicates that the content is valid. */
  39498. + int initialised;
  39499. +
  39500. + /* The first and last (inclusive) slots allocated to the owner. */
  39501. + int slot_first;
  39502. + int slot_last;
  39503. +
  39504. + /* The slot allocated to synchronous messages from the owner. */
  39505. + int slot_sync;
  39506. +
  39507. + /* Signalling this event indicates that owner's slot handler thread
  39508. + ** should run. */
  39509. + REMOTE_EVENT_T trigger;
  39510. +
  39511. + /* Indicates the byte position within the stream where the next message
  39512. + ** will be written. The least significant bits are an index into the
  39513. + ** slot. The next bits are the index of the slot in slot_queue. */
  39514. + int tx_pos;
  39515. +
  39516. + /* This event should be signalled when a slot is recycled. */
  39517. + REMOTE_EVENT_T recycle;
  39518. +
  39519. + /* The slot_queue index where the next recycled slot will be written. */
  39520. + int slot_queue_recycle;
  39521. +
  39522. + /* This event should be signalled when a synchronous message is sent. */
  39523. + REMOTE_EVENT_T sync_trigger;
  39524. +
  39525. + /* This event should be signalled when a synchronous message has been
  39526. + ** released. */
  39527. + REMOTE_EVENT_T sync_release;
  39528. +
  39529. + /* A circular buffer of slot indexes. */
  39530. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  39531. +
  39532. + /* Debugging state */
  39533. + int debug[DEBUG_MAX];
  39534. +} VCHIQ_SHARED_STATE_T;
  39535. +
  39536. +typedef struct vchiq_slot_zero_struct {
  39537. + int magic;
  39538. + short version;
  39539. + short version_min;
  39540. + int slot_zero_size;
  39541. + int slot_size;
  39542. + int max_slots;
  39543. + int max_slots_per_side;
  39544. + int platform_data[2];
  39545. + VCHIQ_SHARED_STATE_T master;
  39546. + VCHIQ_SHARED_STATE_T slave;
  39547. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  39548. +} VCHIQ_SLOT_ZERO_T;
  39549. +
  39550. +struct vchiq_state_struct {
  39551. + int id;
  39552. + int initialised;
  39553. + VCHIQ_CONNSTATE_T conn_state;
  39554. + int is_master;
  39555. +
  39556. + VCHIQ_SHARED_STATE_T *local;
  39557. + VCHIQ_SHARED_STATE_T *remote;
  39558. + VCHIQ_SLOT_T *slot_data;
  39559. +
  39560. + unsigned short default_slot_quota;
  39561. + unsigned short default_message_quota;
  39562. +
  39563. + /* Event indicating connect message received */
  39564. + struct semaphore connect;
  39565. +
  39566. + /* Mutex protecting services */
  39567. + struct mutex mutex;
  39568. + VCHIQ_INSTANCE_T *instance;
  39569. +
  39570. + /* Processes incoming messages */
  39571. + struct task_struct *slot_handler_thread;
  39572. +
  39573. + /* Processes recycled slots */
  39574. + struct task_struct *recycle_thread;
  39575. +
  39576. + /* Processes synchronous messages */
  39577. + struct task_struct *sync_thread;
  39578. +
  39579. + /* Local implementation of the trigger remote event */
  39580. + struct semaphore trigger_event;
  39581. +
  39582. + /* Local implementation of the recycle remote event */
  39583. + struct semaphore recycle_event;
  39584. +
  39585. + /* Local implementation of the sync trigger remote event */
  39586. + struct semaphore sync_trigger_event;
  39587. +
  39588. + /* Local implementation of the sync release remote event */
  39589. + struct semaphore sync_release_event;
  39590. +
  39591. + char *tx_data;
  39592. + char *rx_data;
  39593. + VCHIQ_SLOT_INFO_T *rx_info;
  39594. +
  39595. + struct mutex slot_mutex;
  39596. +
  39597. + struct mutex recycle_mutex;
  39598. +
  39599. + struct mutex sync_mutex;
  39600. +
  39601. + struct mutex bulk_transfer_mutex;
  39602. +
  39603. + /* Indicates the byte position within the stream from where the next
  39604. + ** message will be read. The least significant bits are an index into
  39605. + ** the slot.The next bits are the index of the slot in
  39606. + ** remote->slot_queue. */
  39607. + int rx_pos;
  39608. +
  39609. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  39610. + from remote->tx_pos. */
  39611. + int local_tx_pos;
  39612. +
  39613. + /* The slot_queue index of the slot to become available next. */
  39614. + int slot_queue_available;
  39615. +
  39616. + /* A flag to indicate if any poll has been requested */
  39617. + int poll_needed;
  39618. +
  39619. + /* Ths index of the previous slot used for data messages. */
  39620. + int previous_data_index;
  39621. +
  39622. + /* The number of slots occupied by data messages. */
  39623. + unsigned short data_use_count;
  39624. +
  39625. + /* The maximum number of slots to be occupied by data messages. */
  39626. + unsigned short data_quota;
  39627. +
  39628. + /* An array of bit sets indicating which services must be polled. */
  39629. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  39630. +
  39631. + /* The number of the first unused service */
  39632. + int unused_service;
  39633. +
  39634. + /* Signalled when a free slot becomes available. */
  39635. + struct semaphore slot_available_event;
  39636. +
  39637. + struct semaphore slot_remove_event;
  39638. +
  39639. + /* Signalled when a free data slot becomes available. */
  39640. + struct semaphore data_quota_event;
  39641. +
  39642. + /* Incremented when there are bulk transfers which cannot be processed
  39643. + * whilst paused and must be processed on resume */
  39644. + int deferred_bulks;
  39645. +
  39646. + struct state_stats_struct {
  39647. + int slot_stalls;
  39648. + int data_stalls;
  39649. + int ctrl_tx_count;
  39650. + int ctrl_rx_count;
  39651. + int error_count;
  39652. + } stats;
  39653. +
  39654. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  39655. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  39656. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  39657. +
  39658. + VCHIQ_PLATFORM_STATE_T platform_state;
  39659. +};
  39660. +
  39661. +struct bulk_waiter {
  39662. + VCHIQ_BULK_T *bulk;
  39663. + struct semaphore event;
  39664. + int actual;
  39665. +};
  39666. +
  39667. +extern spinlock_t bulk_waiter_spinlock;
  39668. +
  39669. +extern int vchiq_core_log_level;
  39670. +extern int vchiq_core_msg_log_level;
  39671. +extern int vchiq_sync_log_level;
  39672. +
  39673. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  39674. +
  39675. +extern const char *
  39676. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  39677. +
  39678. +extern VCHIQ_SLOT_ZERO_T *
  39679. +vchiq_init_slots(void *mem_base, int mem_size);
  39680. +
  39681. +extern VCHIQ_STATUS_T
  39682. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  39683. + int is_master);
  39684. +
  39685. +extern VCHIQ_STATUS_T
  39686. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  39687. +
  39688. +extern VCHIQ_SERVICE_T *
  39689. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  39690. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  39691. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  39692. +
  39693. +extern VCHIQ_STATUS_T
  39694. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  39695. +
  39696. +extern VCHIQ_STATUS_T
  39697. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  39698. +
  39699. +extern void
  39700. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  39701. +
  39702. +extern void
  39703. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  39704. +
  39705. +extern VCHIQ_STATUS_T
  39706. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  39707. +
  39708. +extern VCHIQ_STATUS_T
  39709. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  39710. +
  39711. +extern VCHIQ_STATUS_T
  39712. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  39713. +
  39714. +extern void
  39715. +remote_event_pollall(VCHIQ_STATE_T *state);
  39716. +
  39717. +extern VCHIQ_STATUS_T
  39718. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  39719. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  39720. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  39721. +
  39722. +extern void
  39723. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  39724. +
  39725. +extern void
  39726. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  39727. +
  39728. +extern void
  39729. +vchiq_loud_error_header(void);
  39730. +
  39731. +extern void
  39732. +vchiq_loud_error_footer(void);
  39733. +
  39734. +extern void
  39735. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  39736. +
  39737. +static inline VCHIQ_SERVICE_T *
  39738. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  39739. +{
  39740. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  39741. + (VCHIQ_MAX_STATES - 1)];
  39742. + if (!state)
  39743. + return NULL;
  39744. +
  39745. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  39746. +}
  39747. +
  39748. +extern VCHIQ_SERVICE_T *
  39749. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  39750. +
  39751. +extern VCHIQ_SERVICE_T *
  39752. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  39753. +
  39754. +extern VCHIQ_SERVICE_T *
  39755. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  39756. + VCHIQ_SERVICE_HANDLE_T handle);
  39757. +
  39758. +extern VCHIQ_SERVICE_T *
  39759. +find_closed_service_for_instance(VCHIQ_INSTANCE_T instance,
  39760. + VCHIQ_SERVICE_HANDLE_T handle);
  39761. +
  39762. +extern VCHIQ_SERVICE_T *
  39763. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  39764. + int *pidx);
  39765. +
  39766. +extern void
  39767. +lock_service(VCHIQ_SERVICE_T *service);
  39768. +
  39769. +extern void
  39770. +unlock_service(VCHIQ_SERVICE_T *service);
  39771. +
  39772. +/* The following functions are called from vchiq_core, and external
  39773. +** implementations must be provided. */
  39774. +
  39775. +extern VCHIQ_STATUS_T
  39776. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  39777. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  39778. +
  39779. +extern void
  39780. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  39781. +
  39782. +extern void
  39783. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  39784. +
  39785. +extern VCHIQ_STATUS_T
  39786. +vchiq_copy_from_user(void *dst, const void *src, int size);
  39787. +
  39788. +extern void
  39789. +remote_event_signal(REMOTE_EVENT_T *event);
  39790. +
  39791. +void
  39792. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  39793. +
  39794. +extern void
  39795. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  39796. +
  39797. +extern VCHIQ_STATUS_T
  39798. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  39799. +
  39800. +extern void
  39801. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  39802. +
  39803. +extern void
  39804. +vchiq_dump(void *dump_context, const char *str, int len);
  39805. +
  39806. +extern void
  39807. +vchiq_dump_platform_state(void *dump_context);
  39808. +
  39809. +extern void
  39810. +vchiq_dump_platform_instances(void *dump_context);
  39811. +
  39812. +extern void
  39813. +vchiq_dump_platform_service_state(void *dump_context,
  39814. + VCHIQ_SERVICE_T *service);
  39815. +
  39816. +extern VCHIQ_STATUS_T
  39817. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  39818. +
  39819. +extern VCHIQ_STATUS_T
  39820. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  39821. +
  39822. +extern void
  39823. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  39824. +
  39825. +extern void
  39826. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  39827. +
  39828. +extern VCHIQ_STATUS_T
  39829. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  39830. +
  39831. +extern VCHIQ_STATUS_T
  39832. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  39833. +
  39834. +extern void
  39835. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  39836. +
  39837. +extern VCHIQ_STATUS_T
  39838. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  39839. +
  39840. +extern VCHIQ_STATUS_T
  39841. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  39842. +
  39843. +extern VCHIQ_STATUS_T
  39844. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  39845. +
  39846. +extern void
  39847. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  39848. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  39849. +
  39850. +extern void
  39851. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  39852. +
  39853. +extern void
  39854. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  39855. +
  39856. +
  39857. +extern void
  39858. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  39859. + size_t numBytes);
  39860. +
  39861. +#endif
  39862. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c
  39863. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 1970-01-01 01:00:00.000000000 +0100
  39864. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.c 2015-03-09 10:39:30.722893733 +0100
  39865. @@ -0,0 +1,383 @@
  39866. +/**
  39867. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  39868. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  39869. + *
  39870. + * Redistribution and use in source and binary forms, with or without
  39871. + * modification, are permitted provided that the following conditions
  39872. + * are met:
  39873. + * 1. Redistributions of source code must retain the above copyright
  39874. + * notice, this list of conditions, and the following disclaimer,
  39875. + * without modification.
  39876. + * 2. Redistributions in binary form must reproduce the above copyright
  39877. + * notice, this list of conditions and the following disclaimer in the
  39878. + * documentation and/or other materials provided with the distribution.
  39879. + * 3. The names of the above-listed copyright holders may not be used
  39880. + * to endorse or promote products derived from this software without
  39881. + * specific prior written permission.
  39882. + *
  39883. + * ALTERNATIVELY, this software may be distributed under the terms of the
  39884. + * GNU General Public License ("GPL") version 2, as published by the Free
  39885. + * Software Foundation.
  39886. + *
  39887. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  39888. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  39889. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39890. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  39891. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39892. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39893. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39894. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  39895. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  39896. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  39897. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39898. + */
  39899. +
  39900. +
  39901. +#include <linux/debugfs.h>
  39902. +#include "vchiq_core.h"
  39903. +#include "vchiq_arm.h"
  39904. +#include "vchiq_debugfs.h"
  39905. +
  39906. +#ifdef CONFIG_DEBUG_FS
  39907. +
  39908. +/****************************************************************************
  39909. +*
  39910. +* log category entries
  39911. +*
  39912. +***************************************************************************/
  39913. +#define DEBUGFS_WRITE_BUF_SIZE 256
  39914. +
  39915. +#define VCHIQ_LOG_ERROR_STR "error"
  39916. +#define VCHIQ_LOG_WARNING_STR "warning"
  39917. +#define VCHIQ_LOG_INFO_STR "info"
  39918. +#define VCHIQ_LOG_TRACE_STR "trace"
  39919. +
  39920. +
  39921. +/* Top-level debug info */
  39922. +struct vchiq_debugfs_info {
  39923. + /* Global 'vchiq' debugfs entry used by all instances */
  39924. + struct dentry *vchiq_cfg_dir;
  39925. +
  39926. + /* one entry per client process */
  39927. + struct dentry *clients;
  39928. +
  39929. + /* log categories */
  39930. + struct dentry *log_categories;
  39931. +};
  39932. +
  39933. +static struct vchiq_debugfs_info debugfs_info;
  39934. +
  39935. +/* Log category debugfs entries */
  39936. +struct vchiq_debugfs_log_entry {
  39937. + const char *name;
  39938. + int *plevel;
  39939. + struct dentry *dir;
  39940. +};
  39941. +
  39942. +static struct vchiq_debugfs_log_entry vchiq_debugfs_log_entries[] = {
  39943. + { "core", &vchiq_core_log_level },
  39944. + { "msg", &vchiq_core_msg_log_level },
  39945. + { "sync", &vchiq_sync_log_level },
  39946. + { "susp", &vchiq_susp_log_level },
  39947. + { "arm", &vchiq_arm_log_level },
  39948. +};
  39949. +static int n_log_entries =
  39950. + sizeof(vchiq_debugfs_log_entries)/sizeof(vchiq_debugfs_log_entries[0]);
  39951. +
  39952. +
  39953. +static struct dentry *vchiq_clients_top(void);
  39954. +static struct dentry *vchiq_debugfs_top(void);
  39955. +
  39956. +static int debugfs_log_show(struct seq_file *f, void *offset)
  39957. +{
  39958. + int *levp = f->private;
  39959. + char *log_value = NULL;
  39960. +
  39961. + switch (*levp) {
  39962. + case VCHIQ_LOG_ERROR:
  39963. + log_value = VCHIQ_LOG_ERROR_STR;
  39964. + break;
  39965. + case VCHIQ_LOG_WARNING:
  39966. + log_value = VCHIQ_LOG_WARNING_STR;
  39967. + break;
  39968. + case VCHIQ_LOG_INFO:
  39969. + log_value = VCHIQ_LOG_INFO_STR;
  39970. + break;
  39971. + case VCHIQ_LOG_TRACE:
  39972. + log_value = VCHIQ_LOG_TRACE_STR;
  39973. + break;
  39974. + default:
  39975. + break;
  39976. + }
  39977. +
  39978. + seq_printf(f, "%s\n", log_value ? log_value : "(null)");
  39979. +
  39980. + return 0;
  39981. +}
  39982. +
  39983. +static int debugfs_log_open(struct inode *inode, struct file *file)
  39984. +{
  39985. + return single_open(file, debugfs_log_show, inode->i_private);
  39986. +}
  39987. +
  39988. +static int debugfs_log_write(struct file *file,
  39989. + const char __user *buffer,
  39990. + size_t count, loff_t *ppos)
  39991. +{
  39992. + struct seq_file *f = (struct seq_file *)file->private_data;
  39993. + int *levp = f->private;
  39994. + char kbuf[DEBUGFS_WRITE_BUF_SIZE + 1];
  39995. +
  39996. + memset(kbuf, 0, DEBUGFS_WRITE_BUF_SIZE + 1);
  39997. + if (count >= DEBUGFS_WRITE_BUF_SIZE)
  39998. + count = DEBUGFS_WRITE_BUF_SIZE;
  39999. +
  40000. + if (copy_from_user(kbuf, buffer, count) != 0)
  40001. + return -EFAULT;
  40002. + kbuf[count - 1] = 0;
  40003. +
  40004. + if (strncmp("error", kbuf, strlen("error")) == 0)
  40005. + *levp = VCHIQ_LOG_ERROR;
  40006. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  40007. + *levp = VCHIQ_LOG_WARNING;
  40008. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  40009. + *levp = VCHIQ_LOG_INFO;
  40010. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  40011. + *levp = VCHIQ_LOG_TRACE;
  40012. + else
  40013. + *levp = VCHIQ_LOG_DEFAULT;
  40014. +
  40015. + *ppos += count;
  40016. +
  40017. + return count;
  40018. +}
  40019. +
  40020. +static const struct file_operations debugfs_log_fops = {
  40021. + .owner = THIS_MODULE,
  40022. + .open = debugfs_log_open,
  40023. + .write = debugfs_log_write,
  40024. + .read = seq_read,
  40025. + .llseek = seq_lseek,
  40026. + .release = single_release,
  40027. +};
  40028. +
  40029. +/* create an entry under <debugfs>/vchiq/log for each log category */
  40030. +static int vchiq_debugfs_create_log_entries(struct dentry *top)
  40031. +{
  40032. + struct dentry *dir;
  40033. + size_t i;
  40034. + int ret = 0;
  40035. + dir = debugfs_create_dir("log", vchiq_debugfs_top());
  40036. + if (!dir)
  40037. + return -ENOMEM;
  40038. + debugfs_info.log_categories = dir;
  40039. +
  40040. + for (i = 0; i < n_log_entries; i++) {
  40041. + void *levp = (void *)vchiq_debugfs_log_entries[i].plevel;
  40042. + dir = debugfs_create_file(vchiq_debugfs_log_entries[i].name,
  40043. + 0644,
  40044. + debugfs_info.log_categories,
  40045. + levp,
  40046. + &debugfs_log_fops);
  40047. + if (!dir) {
  40048. + ret = -ENOMEM;
  40049. + break;
  40050. + }
  40051. +
  40052. + vchiq_debugfs_log_entries[i].dir = dir;
  40053. + }
  40054. + return ret;
  40055. +}
  40056. +
  40057. +static int debugfs_usecount_show(struct seq_file *f, void *offset)
  40058. +{
  40059. + VCHIQ_INSTANCE_T instance = f->private;
  40060. + int use_count;
  40061. +
  40062. + use_count = vchiq_instance_get_use_count(instance);
  40063. + seq_printf(f, "%d\n", use_count);
  40064. +
  40065. + return 0;
  40066. +}
  40067. +
  40068. +static int debugfs_usecount_open(struct inode *inode, struct file *file)
  40069. +{
  40070. + return single_open(file, debugfs_usecount_show, inode->i_private);
  40071. +}
  40072. +
  40073. +static const struct file_operations debugfs_usecount_fops = {
  40074. + .owner = THIS_MODULE,
  40075. + .open = debugfs_usecount_open,
  40076. + .read = seq_read,
  40077. + .llseek = seq_lseek,
  40078. + .release = single_release,
  40079. +};
  40080. +
  40081. +static int debugfs_trace_show(struct seq_file *f, void *offset)
  40082. +{
  40083. + VCHIQ_INSTANCE_T instance = f->private;
  40084. + int trace;
  40085. +
  40086. + trace = vchiq_instance_get_trace(instance);
  40087. + seq_printf(f, "%s\n", trace ? "Y" : "N");
  40088. +
  40089. + return 0;
  40090. +}
  40091. +
  40092. +static int debugfs_trace_open(struct inode *inode, struct file *file)
  40093. +{
  40094. + return single_open(file, debugfs_trace_show, inode->i_private);
  40095. +}
  40096. +
  40097. +static int debugfs_trace_write(struct file *file,
  40098. + const char __user *buffer,
  40099. + size_t count, loff_t *ppos)
  40100. +{
  40101. + struct seq_file *f = (struct seq_file *)file->private_data;
  40102. + VCHIQ_INSTANCE_T instance = f->private;
  40103. + char firstchar;
  40104. +
  40105. + if (copy_from_user(&firstchar, buffer, 1) != 0)
  40106. + return -EFAULT;
  40107. +
  40108. + switch (firstchar) {
  40109. + case 'Y':
  40110. + case 'y':
  40111. + case '1':
  40112. + vchiq_instance_set_trace(instance, 1);
  40113. + break;
  40114. + case 'N':
  40115. + case 'n':
  40116. + case '0':
  40117. + vchiq_instance_set_trace(instance, 0);
  40118. + break;
  40119. + default:
  40120. + break;
  40121. + }
  40122. +
  40123. + *ppos += count;
  40124. +
  40125. + return count;
  40126. +}
  40127. +
  40128. +static const struct file_operations debugfs_trace_fops = {
  40129. + .owner = THIS_MODULE,
  40130. + .open = debugfs_trace_open,
  40131. + .write = debugfs_trace_write,
  40132. + .read = seq_read,
  40133. + .llseek = seq_lseek,
  40134. + .release = single_release,
  40135. +};
  40136. +
  40137. +/* add an instance (process) to the debugfs entries */
  40138. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  40139. +{
  40140. + char pidstr[16];
  40141. + struct dentry *top, *use_count, *trace;
  40142. + struct dentry *clients = vchiq_clients_top();
  40143. +
  40144. + snprintf(pidstr, sizeof(pidstr), "%d",
  40145. + vchiq_instance_get_pid(instance));
  40146. +
  40147. + top = debugfs_create_dir(pidstr, clients);
  40148. + if (!top)
  40149. + goto fail_top;
  40150. +
  40151. + use_count = debugfs_create_file("use_count",
  40152. + 0444, top,
  40153. + instance,
  40154. + &debugfs_usecount_fops);
  40155. + if (!use_count)
  40156. + goto fail_use_count;
  40157. +
  40158. + trace = debugfs_create_file("trace",
  40159. + 0644, top,
  40160. + instance,
  40161. + &debugfs_trace_fops);
  40162. + if (!trace)
  40163. + goto fail_trace;
  40164. +
  40165. + vchiq_instance_get_debugfs_node(instance)->dentry = top;
  40166. +
  40167. + return 0;
  40168. +
  40169. +fail_trace:
  40170. + debugfs_remove(use_count);
  40171. +fail_use_count:
  40172. + debugfs_remove(top);
  40173. +fail_top:
  40174. + return -ENOMEM;
  40175. +}
  40176. +
  40177. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  40178. +{
  40179. + VCHIQ_DEBUGFS_NODE_T *node = vchiq_instance_get_debugfs_node(instance);
  40180. + debugfs_remove_recursive(node->dentry);
  40181. +}
  40182. +
  40183. +
  40184. +int vchiq_debugfs_init(void)
  40185. +{
  40186. + BUG_ON(debugfs_info.vchiq_cfg_dir != NULL);
  40187. +
  40188. + debugfs_info.vchiq_cfg_dir = debugfs_create_dir("vchiq", NULL);
  40189. + if (debugfs_info.vchiq_cfg_dir == NULL)
  40190. + goto fail;
  40191. +
  40192. + debugfs_info.clients = debugfs_create_dir("clients",
  40193. + vchiq_debugfs_top());
  40194. + if (!debugfs_info.clients)
  40195. + goto fail;
  40196. +
  40197. + if (vchiq_debugfs_create_log_entries(vchiq_debugfs_top()) != 0)
  40198. + goto fail;
  40199. +
  40200. + return 0;
  40201. +
  40202. +fail:
  40203. + vchiq_debugfs_deinit();
  40204. + vchiq_log_error(vchiq_arm_log_level,
  40205. + "%s: failed to create debugfs directory",
  40206. + __func__);
  40207. +
  40208. + return -ENOMEM;
  40209. +}
  40210. +
  40211. +/* remove all the debugfs entries */
  40212. +void vchiq_debugfs_deinit(void)
  40213. +{
  40214. + debugfs_remove_recursive(vchiq_debugfs_top());
  40215. +}
  40216. +
  40217. +static struct dentry *vchiq_clients_top(void)
  40218. +{
  40219. + return debugfs_info.clients;
  40220. +}
  40221. +
  40222. +static struct dentry *vchiq_debugfs_top(void)
  40223. +{
  40224. + BUG_ON(debugfs_info.vchiq_cfg_dir == NULL);
  40225. + return debugfs_info.vchiq_cfg_dir;
  40226. +}
  40227. +
  40228. +#else /* CONFIG_DEBUG_FS */
  40229. +
  40230. +int vchiq_debugfs_init(void)
  40231. +{
  40232. + return 0;
  40233. +}
  40234. +
  40235. +void vchiq_debugfs_deinit(void)
  40236. +{
  40237. +}
  40238. +
  40239. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance)
  40240. +{
  40241. + return 0;
  40242. +}
  40243. +
  40244. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance)
  40245. +{
  40246. +}
  40247. +
  40248. +#endif /* CONFIG_DEBUG_FS */
  40249. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
  40250. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 1970-01-01 01:00:00.000000000 +0100
  40251. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_debugfs.h 2015-03-09 10:39:30.722893733 +0100
  40252. @@ -0,0 +1,52 @@
  40253. +/**
  40254. + * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  40255. + *
  40256. + * Redistribution and use in source and binary forms, with or without
  40257. + * modification, are permitted provided that the following conditions
  40258. + * are met:
  40259. + * 1. Redistributions of source code must retain the above copyright
  40260. + * notice, this list of conditions, and the following disclaimer,
  40261. + * without modification.
  40262. + * 2. Redistributions in binary form must reproduce the above copyright
  40263. + * notice, this list of conditions and the following disclaimer in the
  40264. + * documentation and/or other materials provided with the distribution.
  40265. + * 3. The names of the above-listed copyright holders may not be used
  40266. + * to endorse or promote products derived from this software without
  40267. + * specific prior written permission.
  40268. + *
  40269. + * ALTERNATIVELY, this software may be distributed under the terms of the
  40270. + * GNU General Public License ("GPL") version 2, as published by the Free
  40271. + * Software Foundation.
  40272. + *
  40273. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  40274. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40275. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40276. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40277. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40278. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40279. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40280. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  40281. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40282. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40283. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40284. + */
  40285. +
  40286. +#ifndef VCHIQ_DEBUGFS_H
  40287. +#define VCHIQ_DEBUGFS_H
  40288. +
  40289. +#include "vchiq_core.h"
  40290. +
  40291. +typedef struct vchiq_debugfs_node_struct
  40292. +{
  40293. + struct dentry *dentry;
  40294. +} VCHIQ_DEBUGFS_NODE_T;
  40295. +
  40296. +int vchiq_debugfs_init(void);
  40297. +
  40298. +void vchiq_debugfs_deinit(void);
  40299. +
  40300. +int vchiq_debugfs_add_instance(VCHIQ_INSTANCE_T instance);
  40301. +
  40302. +void vchiq_debugfs_remove_instance(VCHIQ_INSTANCE_T instance);
  40303. +
  40304. +#endif /* VCHIQ_DEBUGFS_H */
  40305. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  40306. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  40307. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2015-03-09 10:39:30.722893733 +0100
  40308. @@ -0,0 +1,87 @@
  40309. +#!/usr/bin/perl -w
  40310. +
  40311. +use strict;
  40312. +
  40313. +#
  40314. +# Generate a version from available information
  40315. +#
  40316. +
  40317. +my $prefix = shift @ARGV;
  40318. +my $root = shift @ARGV;
  40319. +
  40320. +
  40321. +if ( not defined $root ) {
  40322. + die "usage: $0 prefix root-dir\n";
  40323. +}
  40324. +
  40325. +if ( ! -d $root ) {
  40326. + die "root directory $root not found\n";
  40327. +}
  40328. +
  40329. +my $version = "unknown";
  40330. +my $tainted = "";
  40331. +
  40332. +if ( -d "$root/.git" ) {
  40333. + # attempt to work out git version. only do so
  40334. + # on a linux build host, as cygwin builds are
  40335. + # already slow enough
  40336. +
  40337. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  40338. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  40339. + $version = "no git version";
  40340. + }
  40341. + else {
  40342. + $version = <F>;
  40343. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  40344. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  40345. + }
  40346. +
  40347. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  40348. + $tainted = <G>;
  40349. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  40350. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  40351. + if (length $tainted) {
  40352. + $version = join ' ', $version, "(tainted)";
  40353. + }
  40354. + else {
  40355. + $version = join ' ', $version, "(clean)";
  40356. + }
  40357. + }
  40358. + }
  40359. +}
  40360. +
  40361. +my $hostname = `hostname`;
  40362. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  40363. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  40364. +
  40365. +
  40366. +print STDERR "Version $version\n";
  40367. +print <<EOF;
  40368. +#include "${prefix}_build_info.h"
  40369. +#include <linux/broadcom/vc_debug_sym.h>
  40370. +
  40371. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  40372. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  40373. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  40374. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  40375. +
  40376. +const char *vchiq_get_build_hostname( void )
  40377. +{
  40378. + return vchiq_build_hostname;
  40379. +}
  40380. +
  40381. +const char *vchiq_get_build_version( void )
  40382. +{
  40383. + return vchiq_build_version;
  40384. +}
  40385. +
  40386. +const char *vchiq_get_build_date( void )
  40387. +{
  40388. + return vchiq_build_date;
  40389. +}
  40390. +
  40391. +const char *vchiq_get_build_time( void )
  40392. +{
  40393. + return vchiq_build_time;
  40394. +}
  40395. +EOF
  40396. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  40397. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  40398. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2015-03-09 10:39:30.718893733 +0100
  40399. @@ -0,0 +1,40 @@
  40400. +/**
  40401. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  40402. + *
  40403. + * Redistribution and use in source and binary forms, with or without
  40404. + * modification, are permitted provided that the following conditions
  40405. + * are met:
  40406. + * 1. Redistributions of source code must retain the above copyright
  40407. + * notice, this list of conditions, and the following disclaimer,
  40408. + * without modification.
  40409. + * 2. Redistributions in binary form must reproduce the above copyright
  40410. + * notice, this list of conditions and the following disclaimer in the
  40411. + * documentation and/or other materials provided with the distribution.
  40412. + * 3. The names of the above-listed copyright holders may not be used
  40413. + * to endorse or promote products derived from this software without
  40414. + * specific prior written permission.
  40415. + *
  40416. + * ALTERNATIVELY, this software may be distributed under the terms of the
  40417. + * GNU General Public License ("GPL") version 2, as published by the Free
  40418. + * Software Foundation.
  40419. + *
  40420. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  40421. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40422. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40423. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40424. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40425. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40426. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40427. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  40428. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40429. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40430. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40431. + */
  40432. +
  40433. +#ifndef VCHIQ_VCHIQ_H
  40434. +#define VCHIQ_VCHIQ_H
  40435. +
  40436. +#include "vchiq_if.h"
  40437. +#include "vchiq_util.h"
  40438. +
  40439. +#endif
  40440. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  40441. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  40442. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2015-03-09 10:39:30.722893733 +0100
  40443. @@ -0,0 +1,189 @@
  40444. +/**
  40445. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  40446. + *
  40447. + * Redistribution and use in source and binary forms, with or without
  40448. + * modification, are permitted provided that the following conditions
  40449. + * are met:
  40450. + * 1. Redistributions of source code must retain the above copyright
  40451. + * notice, this list of conditions, and the following disclaimer,
  40452. + * without modification.
  40453. + * 2. Redistributions in binary form must reproduce the above copyright
  40454. + * notice, this list of conditions and the following disclaimer in the
  40455. + * documentation and/or other materials provided with the distribution.
  40456. + * 3. The names of the above-listed copyright holders may not be used
  40457. + * to endorse or promote products derived from this software without
  40458. + * specific prior written permission.
  40459. + *
  40460. + * ALTERNATIVELY, this software may be distributed under the terms of the
  40461. + * GNU General Public License ("GPL") version 2, as published by the Free
  40462. + * Software Foundation.
  40463. + *
  40464. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  40465. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40466. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40467. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40468. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40469. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40470. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40471. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  40472. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40473. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40474. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40475. + */
  40476. +
  40477. +#ifndef VCHIQ_IF_H
  40478. +#define VCHIQ_IF_H
  40479. +
  40480. +#include "interface/vchi/vchi_mh.h"
  40481. +
  40482. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  40483. +
  40484. +#define VCHIQ_SLOT_SIZE 4096
  40485. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  40486. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  40487. +
  40488. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  40489. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  40490. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  40491. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  40492. +
  40493. +typedef enum {
  40494. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  40495. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  40496. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  40497. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  40498. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  40499. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  40500. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  40501. +} VCHIQ_REASON_T;
  40502. +
  40503. +typedef enum {
  40504. + VCHIQ_ERROR = -1,
  40505. + VCHIQ_SUCCESS = 0,
  40506. + VCHIQ_RETRY = 1
  40507. +} VCHIQ_STATUS_T;
  40508. +
  40509. +typedef enum {
  40510. + VCHIQ_BULK_MODE_CALLBACK,
  40511. + VCHIQ_BULK_MODE_BLOCKING,
  40512. + VCHIQ_BULK_MODE_NOCALLBACK,
  40513. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  40514. +} VCHIQ_BULK_MODE_T;
  40515. +
  40516. +typedef enum {
  40517. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  40518. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  40519. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  40520. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
  40521. + VCHIQ_SERVICE_OPTION_TRACE
  40522. +} VCHIQ_SERVICE_OPTION_T;
  40523. +
  40524. +typedef struct vchiq_header_struct {
  40525. + /* The message identifier - opaque to applications. */
  40526. + int msgid;
  40527. +
  40528. + /* Size of message data. */
  40529. + unsigned int size;
  40530. +
  40531. + char data[0]; /* message */
  40532. +} VCHIQ_HEADER_T;
  40533. +
  40534. +typedef struct {
  40535. + const void *data;
  40536. + unsigned int size;
  40537. +} VCHIQ_ELEMENT_T;
  40538. +
  40539. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  40540. +
  40541. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  40542. + VCHIQ_SERVICE_HANDLE_T, void *);
  40543. +
  40544. +typedef struct vchiq_service_base_struct {
  40545. + int fourcc;
  40546. + VCHIQ_CALLBACK_T callback;
  40547. + void *userdata;
  40548. +} VCHIQ_SERVICE_BASE_T;
  40549. +
  40550. +typedef struct vchiq_service_params_struct {
  40551. + int fourcc;
  40552. + VCHIQ_CALLBACK_T callback;
  40553. + void *userdata;
  40554. + short version; /* Increment for non-trivial changes */
  40555. + short version_min; /* Update for incompatible changes */
  40556. +} VCHIQ_SERVICE_PARAMS_T;
  40557. +
  40558. +typedef struct vchiq_config_struct {
  40559. + unsigned int max_msg_size;
  40560. + unsigned int bulk_threshold; /* The message size above which it
  40561. + is better to use a bulk transfer
  40562. + (<= max_msg_size) */
  40563. + unsigned int max_outstanding_bulks;
  40564. + unsigned int max_services;
  40565. + short version; /* The version of VCHIQ */
  40566. + short version_min; /* The minimum compatible version of VCHIQ */
  40567. +} VCHIQ_CONFIG_T;
  40568. +
  40569. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  40570. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  40571. +
  40572. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  40573. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  40574. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  40575. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  40576. + const VCHIQ_SERVICE_PARAMS_T *params,
  40577. + VCHIQ_SERVICE_HANDLE_T *pservice);
  40578. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  40579. + const VCHIQ_SERVICE_PARAMS_T *params,
  40580. + VCHIQ_SERVICE_HANDLE_T *pservice);
  40581. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  40582. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  40583. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  40584. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  40585. + VCHIQ_SERVICE_HANDLE_T service);
  40586. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  40587. +
  40588. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  40589. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  40590. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  40591. + VCHIQ_HEADER_T *header);
  40592. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  40593. + const void *data, unsigned int size, void *userdata);
  40594. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  40595. + void *data, unsigned int size, void *userdata);
  40596. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  40597. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  40598. + const void *offset, unsigned int size, void *userdata);
  40599. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  40600. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  40601. + void *offset, unsigned int size, void *userdata);
  40602. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  40603. + const void *data, unsigned int size, void *userdata,
  40604. + VCHIQ_BULK_MODE_T mode);
  40605. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  40606. + void *data, unsigned int size, void *userdata,
  40607. + VCHIQ_BULK_MODE_T mode);
  40608. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  40609. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  40610. + void *userdata, VCHIQ_BULK_MODE_T mode);
  40611. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  40612. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  40613. + void *userdata, VCHIQ_BULK_MODE_T mode);
  40614. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  40615. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  40616. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  40617. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  40618. + int config_size, VCHIQ_CONFIG_T *pconfig);
  40619. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  40620. + VCHIQ_SERVICE_OPTION_T option, int value);
  40621. +
  40622. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  40623. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  40624. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  40625. +
  40626. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  40627. + void *ptr, size_t num_bytes);
  40628. +
  40629. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  40630. + short *peer_version);
  40631. +
  40632. +#endif /* VCHIQ_IF_H */
  40633. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  40634. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  40635. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2015-03-09 10:39:30.722893733 +0100
  40636. @@ -0,0 +1,131 @@
  40637. +/**
  40638. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  40639. + *
  40640. + * Redistribution and use in source and binary forms, with or without
  40641. + * modification, are permitted provided that the following conditions
  40642. + * are met:
  40643. + * 1. Redistributions of source code must retain the above copyright
  40644. + * notice, this list of conditions, and the following disclaimer,
  40645. + * without modification.
  40646. + * 2. Redistributions in binary form must reproduce the above copyright
  40647. + * notice, this list of conditions and the following disclaimer in the
  40648. + * documentation and/or other materials provided with the distribution.
  40649. + * 3. The names of the above-listed copyright holders may not be used
  40650. + * to endorse or promote products derived from this software without
  40651. + * specific prior written permission.
  40652. + *
  40653. + * ALTERNATIVELY, this software may be distributed under the terms of the
  40654. + * GNU General Public License ("GPL") version 2, as published by the Free
  40655. + * Software Foundation.
  40656. + *
  40657. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  40658. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40659. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40660. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40661. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40662. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40663. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40664. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  40665. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40666. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40667. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40668. + */
  40669. +
  40670. +#ifndef VCHIQ_IOCTLS_H
  40671. +#define VCHIQ_IOCTLS_H
  40672. +
  40673. +#include <linux/ioctl.h>
  40674. +#include "vchiq_if.h"
  40675. +
  40676. +#define VCHIQ_IOC_MAGIC 0xc4
  40677. +#define VCHIQ_INVALID_HANDLE (~0)
  40678. +
  40679. +typedef struct {
  40680. + VCHIQ_SERVICE_PARAMS_T params;
  40681. + int is_open;
  40682. + int is_vchi;
  40683. + unsigned int handle; /* OUT */
  40684. +} VCHIQ_CREATE_SERVICE_T;
  40685. +
  40686. +typedef struct {
  40687. + unsigned int handle;
  40688. + unsigned int count;
  40689. + const VCHIQ_ELEMENT_T *elements;
  40690. +} VCHIQ_QUEUE_MESSAGE_T;
  40691. +
  40692. +typedef struct {
  40693. + unsigned int handle;
  40694. + void *data;
  40695. + unsigned int size;
  40696. + void *userdata;
  40697. + VCHIQ_BULK_MODE_T mode;
  40698. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  40699. +
  40700. +typedef struct {
  40701. + VCHIQ_REASON_T reason;
  40702. + VCHIQ_HEADER_T *header;
  40703. + void *service_userdata;
  40704. + void *bulk_userdata;
  40705. +} VCHIQ_COMPLETION_DATA_T;
  40706. +
  40707. +typedef struct {
  40708. + unsigned int count;
  40709. + VCHIQ_COMPLETION_DATA_T *buf;
  40710. + unsigned int msgbufsize;
  40711. + unsigned int msgbufcount; /* IN/OUT */
  40712. + void **msgbufs;
  40713. +} VCHIQ_AWAIT_COMPLETION_T;
  40714. +
  40715. +typedef struct {
  40716. + unsigned int handle;
  40717. + int blocking;
  40718. + unsigned int bufsize;
  40719. + void *buf;
  40720. +} VCHIQ_DEQUEUE_MESSAGE_T;
  40721. +
  40722. +typedef struct {
  40723. + unsigned int config_size;
  40724. + VCHIQ_CONFIG_T *pconfig;
  40725. +} VCHIQ_GET_CONFIG_T;
  40726. +
  40727. +typedef struct {
  40728. + unsigned int handle;
  40729. + VCHIQ_SERVICE_OPTION_T option;
  40730. + int value;
  40731. +} VCHIQ_SET_SERVICE_OPTION_T;
  40732. +
  40733. +typedef struct {
  40734. + void *virt_addr;
  40735. + size_t num_bytes;
  40736. +} VCHIQ_DUMP_MEM_T;
  40737. +
  40738. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  40739. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  40740. +#define VCHIQ_IOC_CREATE_SERVICE \
  40741. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  40742. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  40743. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  40744. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  40745. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  40746. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  40747. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  40748. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  40749. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  40750. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  40751. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  40752. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  40753. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  40754. +#define VCHIQ_IOC_GET_CONFIG \
  40755. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  40756. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  40757. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  40758. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  40759. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  40760. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  40761. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  40762. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  40763. +#define VCHIQ_IOC_LIB_VERSION _IO(VCHIQ_IOC_MAGIC, 16)
  40764. +#define VCHIQ_IOC_CLOSE_DELIVERED _IO(VCHIQ_IOC_MAGIC, 17)
  40765. +#define VCHIQ_IOC_MAX 17
  40766. +
  40767. +#endif
  40768. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  40769. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  40770. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2015-03-09 10:39:30.722893733 +0100
  40771. @@ -0,0 +1,458 @@
  40772. +/**
  40773. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  40774. + *
  40775. + * Redistribution and use in source and binary forms, with or without
  40776. + * modification, are permitted provided that the following conditions
  40777. + * are met:
  40778. + * 1. Redistributions of source code must retain the above copyright
  40779. + * notice, this list of conditions, and the following disclaimer,
  40780. + * without modification.
  40781. + * 2. Redistributions in binary form must reproduce the above copyright
  40782. + * notice, this list of conditions and the following disclaimer in the
  40783. + * documentation and/or other materials provided with the distribution.
  40784. + * 3. The names of the above-listed copyright holders may not be used
  40785. + * to endorse or promote products derived from this software without
  40786. + * specific prior written permission.
  40787. + *
  40788. + * ALTERNATIVELY, this software may be distributed under the terms of the
  40789. + * GNU General Public License ("GPL") version 2, as published by the Free
  40790. + * Software Foundation.
  40791. + *
  40792. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  40793. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  40794. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40795. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40796. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  40797. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  40798. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  40799. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  40800. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40801. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  40802. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40803. + */
  40804. +
  40805. +/* ---- Include Files ---------------------------------------------------- */
  40806. +
  40807. +#include <linux/kernel.h>
  40808. +#include <linux/module.h>
  40809. +#include <linux/mutex.h>
  40810. +
  40811. +#include "vchiq_core.h"
  40812. +#include "vchiq_arm.h"
  40813. +#include "vchiq_killable.h"
  40814. +
  40815. +/* ---- Public Variables ------------------------------------------------- */
  40816. +
  40817. +/* ---- Private Constants and Types -------------------------------------- */
  40818. +
  40819. +struct bulk_waiter_node {
  40820. + struct bulk_waiter bulk_waiter;
  40821. + int pid;
  40822. + struct list_head list;
  40823. +};
  40824. +
  40825. +struct vchiq_instance_struct {
  40826. + VCHIQ_STATE_T *state;
  40827. +
  40828. + int connected;
  40829. +
  40830. + struct list_head bulk_waiter_list;
  40831. + struct mutex bulk_waiter_list_mutex;
  40832. +};
  40833. +
  40834. +static VCHIQ_STATUS_T
  40835. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  40836. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  40837. +
  40838. +/****************************************************************************
  40839. +*
  40840. +* vchiq_initialise
  40841. +*
  40842. +***************************************************************************/
  40843. +#define VCHIQ_INIT_RETRIES 10
  40844. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  40845. +{
  40846. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  40847. + VCHIQ_STATE_T *state;
  40848. + VCHIQ_INSTANCE_T instance = NULL;
  40849. + int i;
  40850. +
  40851. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  40852. +
  40853. + /* VideoCore may not be ready due to boot up timing.
  40854. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  40855. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  40856. + state = vchiq_get_state();
  40857. + if (state)
  40858. + break;
  40859. + udelay(500);
  40860. + }
  40861. + if (i==VCHIQ_INIT_RETRIES) {
  40862. + vchiq_log_error(vchiq_core_log_level,
  40863. + "%s: videocore not initialized\n", __func__);
  40864. + goto failed;
  40865. + } else if (i>0) {
  40866. + vchiq_log_warning(vchiq_core_log_level,
  40867. + "%s: videocore initialized after %d retries\n", __func__, i);
  40868. + }
  40869. +
  40870. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  40871. + if (!instance) {
  40872. + vchiq_log_error(vchiq_core_log_level,
  40873. + "%s: error allocating vchiq instance\n", __func__);
  40874. + goto failed;
  40875. + }
  40876. +
  40877. + instance->connected = 0;
  40878. + instance->state = state;
  40879. + mutex_init(&instance->bulk_waiter_list_mutex);
  40880. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  40881. +
  40882. + *instanceOut = instance;
  40883. +
  40884. + status = VCHIQ_SUCCESS;
  40885. +
  40886. +failed:
  40887. + vchiq_log_trace(vchiq_core_log_level,
  40888. + "%s(%p): returning %d", __func__, instance, status);
  40889. +
  40890. + return status;
  40891. +}
  40892. +EXPORT_SYMBOL(vchiq_initialise);
  40893. +
  40894. +/****************************************************************************
  40895. +*
  40896. +* vchiq_shutdown
  40897. +*
  40898. +***************************************************************************/
  40899. +
  40900. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  40901. +{
  40902. + VCHIQ_STATUS_T status;
  40903. + VCHIQ_STATE_T *state = instance->state;
  40904. +
  40905. + vchiq_log_trace(vchiq_core_log_level,
  40906. + "%s(%p) called", __func__, instance);
  40907. +
  40908. + if (mutex_lock_interruptible(&state->mutex) != 0)
  40909. + return VCHIQ_RETRY;
  40910. +
  40911. + /* Remove all services */
  40912. + status = vchiq_shutdown_internal(state, instance);
  40913. +
  40914. + mutex_unlock(&state->mutex);
  40915. +
  40916. + vchiq_log_trace(vchiq_core_log_level,
  40917. + "%s(%p): returning %d", __func__, instance, status);
  40918. +
  40919. + if (status == VCHIQ_SUCCESS) {
  40920. + struct list_head *pos, *next;
  40921. + list_for_each_safe(pos, next,
  40922. + &instance->bulk_waiter_list) {
  40923. + struct bulk_waiter_node *waiter;
  40924. + waiter = list_entry(pos,
  40925. + struct bulk_waiter_node,
  40926. + list);
  40927. + list_del(pos);
  40928. + vchiq_log_info(vchiq_arm_log_level,
  40929. + "bulk_waiter - cleaned up %x "
  40930. + "for pid %d",
  40931. + (unsigned int)waiter, waiter->pid);
  40932. + kfree(waiter);
  40933. + }
  40934. + kfree(instance);
  40935. + }
  40936. +
  40937. + return status;
  40938. +}
  40939. +EXPORT_SYMBOL(vchiq_shutdown);
  40940. +
  40941. +/****************************************************************************
  40942. +*
  40943. +* vchiq_is_connected
  40944. +*
  40945. +***************************************************************************/
  40946. +
  40947. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  40948. +{
  40949. + return instance->connected;
  40950. +}
  40951. +
  40952. +/****************************************************************************
  40953. +*
  40954. +* vchiq_connect
  40955. +*
  40956. +***************************************************************************/
  40957. +
  40958. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  40959. +{
  40960. + VCHIQ_STATUS_T status;
  40961. + VCHIQ_STATE_T *state = instance->state;
  40962. +
  40963. + vchiq_log_trace(vchiq_core_log_level,
  40964. + "%s(%p) called", __func__, instance);
  40965. +
  40966. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  40967. + vchiq_log_trace(vchiq_core_log_level,
  40968. + "%s: call to mutex_lock failed", __func__);
  40969. + status = VCHIQ_RETRY;
  40970. + goto failed;
  40971. + }
  40972. + status = vchiq_connect_internal(state, instance);
  40973. +
  40974. + if (status == VCHIQ_SUCCESS)
  40975. + instance->connected = 1;
  40976. +
  40977. + mutex_unlock(&state->mutex);
  40978. +
  40979. +failed:
  40980. + vchiq_log_trace(vchiq_core_log_level,
  40981. + "%s(%p): returning %d", __func__, instance, status);
  40982. +
  40983. + return status;
  40984. +}
  40985. +EXPORT_SYMBOL(vchiq_connect);
  40986. +
  40987. +/****************************************************************************
  40988. +*
  40989. +* vchiq_add_service
  40990. +*
  40991. +***************************************************************************/
  40992. +
  40993. +VCHIQ_STATUS_T vchiq_add_service(
  40994. + VCHIQ_INSTANCE_T instance,
  40995. + const VCHIQ_SERVICE_PARAMS_T *params,
  40996. + VCHIQ_SERVICE_HANDLE_T *phandle)
  40997. +{
  40998. + VCHIQ_STATUS_T status;
  40999. + VCHIQ_STATE_T *state = instance->state;
  41000. + VCHIQ_SERVICE_T *service = NULL;
  41001. + int srvstate;
  41002. +
  41003. + vchiq_log_trace(vchiq_core_log_level,
  41004. + "%s(%p) called", __func__, instance);
  41005. +
  41006. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  41007. +
  41008. + srvstate = vchiq_is_connected(instance)
  41009. + ? VCHIQ_SRVSTATE_LISTENING
  41010. + : VCHIQ_SRVSTATE_HIDDEN;
  41011. +
  41012. + service = vchiq_add_service_internal(
  41013. + state,
  41014. + params,
  41015. + srvstate,
  41016. + instance,
  41017. + NULL);
  41018. +
  41019. + if (service) {
  41020. + *phandle = service->handle;
  41021. + status = VCHIQ_SUCCESS;
  41022. + } else
  41023. + status = VCHIQ_ERROR;
  41024. +
  41025. + vchiq_log_trace(vchiq_core_log_level,
  41026. + "%s(%p): returning %d", __func__, instance, status);
  41027. +
  41028. + return status;
  41029. +}
  41030. +EXPORT_SYMBOL(vchiq_add_service);
  41031. +
  41032. +/****************************************************************************
  41033. +*
  41034. +* vchiq_open_service
  41035. +*
  41036. +***************************************************************************/
  41037. +
  41038. +VCHIQ_STATUS_T vchiq_open_service(
  41039. + VCHIQ_INSTANCE_T instance,
  41040. + const VCHIQ_SERVICE_PARAMS_T *params,
  41041. + VCHIQ_SERVICE_HANDLE_T *phandle)
  41042. +{
  41043. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  41044. + VCHIQ_STATE_T *state = instance->state;
  41045. + VCHIQ_SERVICE_T *service = NULL;
  41046. +
  41047. + vchiq_log_trace(vchiq_core_log_level,
  41048. + "%s(%p) called", __func__, instance);
  41049. +
  41050. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  41051. +
  41052. + if (!vchiq_is_connected(instance))
  41053. + goto failed;
  41054. +
  41055. + service = vchiq_add_service_internal(state,
  41056. + params,
  41057. + VCHIQ_SRVSTATE_OPENING,
  41058. + instance,
  41059. + NULL);
  41060. +
  41061. + if (service) {
  41062. + *phandle = service->handle;
  41063. + status = vchiq_open_service_internal(service, current->pid);
  41064. + if (status != VCHIQ_SUCCESS) {
  41065. + vchiq_remove_service(service->handle);
  41066. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  41067. + }
  41068. + }
  41069. +
  41070. +failed:
  41071. + vchiq_log_trace(vchiq_core_log_level,
  41072. + "%s(%p): returning %d", __func__, instance, status);
  41073. +
  41074. + return status;
  41075. +}
  41076. +EXPORT_SYMBOL(vchiq_open_service);
  41077. +
  41078. +VCHIQ_STATUS_T
  41079. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  41080. + const void *data, unsigned int size, void *userdata)
  41081. +{
  41082. + return vchiq_bulk_transfer(handle,
  41083. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  41084. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  41085. +}
  41086. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  41087. +
  41088. +VCHIQ_STATUS_T
  41089. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  41090. + unsigned int size, void *userdata)
  41091. +{
  41092. + return vchiq_bulk_transfer(handle,
  41093. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  41094. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  41095. +}
  41096. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  41097. +
  41098. +VCHIQ_STATUS_T
  41099. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  41100. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  41101. +{
  41102. + VCHIQ_STATUS_T status;
  41103. +
  41104. + switch (mode) {
  41105. + case VCHIQ_BULK_MODE_NOCALLBACK:
  41106. + case VCHIQ_BULK_MODE_CALLBACK:
  41107. + status = vchiq_bulk_transfer(handle,
  41108. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  41109. + mode, VCHIQ_BULK_TRANSMIT);
  41110. + break;
  41111. + case VCHIQ_BULK_MODE_BLOCKING:
  41112. + status = vchiq_blocking_bulk_transfer(handle,
  41113. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  41114. + break;
  41115. + default:
  41116. + return VCHIQ_ERROR;
  41117. + }
  41118. +
  41119. + return status;
  41120. +}
  41121. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  41122. +
  41123. +VCHIQ_STATUS_T
  41124. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  41125. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  41126. +{
  41127. + VCHIQ_STATUS_T status;
  41128. +
  41129. + switch (mode) {
  41130. + case VCHIQ_BULK_MODE_NOCALLBACK:
  41131. + case VCHIQ_BULK_MODE_CALLBACK:
  41132. + status = vchiq_bulk_transfer(handle,
  41133. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  41134. + mode, VCHIQ_BULK_RECEIVE);
  41135. + break;
  41136. + case VCHIQ_BULK_MODE_BLOCKING:
  41137. + status = vchiq_blocking_bulk_transfer(handle,
  41138. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  41139. + break;
  41140. + default:
  41141. + return VCHIQ_ERROR;
  41142. + }
  41143. +
  41144. + return status;
  41145. +}
  41146. +EXPORT_SYMBOL(vchiq_bulk_receive);
  41147. +
  41148. +static VCHIQ_STATUS_T
  41149. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  41150. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  41151. +{
  41152. + VCHIQ_INSTANCE_T instance;
  41153. + VCHIQ_SERVICE_T *service;
  41154. + VCHIQ_STATUS_T status;
  41155. + struct bulk_waiter_node *waiter = NULL;
  41156. + struct list_head *pos;
  41157. +
  41158. + service = find_service_by_handle(handle);
  41159. + if (!service)
  41160. + return VCHIQ_ERROR;
  41161. +
  41162. + instance = service->instance;
  41163. +
  41164. + unlock_service(service);
  41165. +
  41166. + mutex_lock(&instance->bulk_waiter_list_mutex);
  41167. + list_for_each(pos, &instance->bulk_waiter_list) {
  41168. + if (list_entry(pos, struct bulk_waiter_node,
  41169. + list)->pid == current->pid) {
  41170. + waiter = list_entry(pos,
  41171. + struct bulk_waiter_node,
  41172. + list);
  41173. + list_del(pos);
  41174. + break;
  41175. + }
  41176. + }
  41177. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  41178. +
  41179. + if (waiter) {
  41180. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  41181. + if (bulk) {
  41182. + /* This thread has an outstanding bulk transfer. */
  41183. + if ((bulk->data != data) ||
  41184. + (bulk->size != size)) {
  41185. + /* This is not a retry of the previous one.
  41186. + ** Cancel the signal when the transfer
  41187. + ** completes. */
  41188. + spin_lock(&bulk_waiter_spinlock);
  41189. + bulk->userdata = NULL;
  41190. + spin_unlock(&bulk_waiter_spinlock);
  41191. + }
  41192. + }
  41193. + }
  41194. +
  41195. + if (!waiter) {
  41196. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  41197. + if (!waiter) {
  41198. + vchiq_log_error(vchiq_core_log_level,
  41199. + "%s - out of memory", __func__);
  41200. + return VCHIQ_ERROR;
  41201. + }
  41202. + }
  41203. +
  41204. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  41205. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  41206. + dir);
  41207. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  41208. + !waiter->bulk_waiter.bulk) {
  41209. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  41210. + if (bulk) {
  41211. + /* Cancel the signal when the transfer
  41212. + ** completes. */
  41213. + spin_lock(&bulk_waiter_spinlock);
  41214. + bulk->userdata = NULL;
  41215. + spin_unlock(&bulk_waiter_spinlock);
  41216. + }
  41217. + kfree(waiter);
  41218. + } else {
  41219. + waiter->pid = current->pid;
  41220. + mutex_lock(&instance->bulk_waiter_list_mutex);
  41221. + list_add(&waiter->list, &instance->bulk_waiter_list);
  41222. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  41223. + vchiq_log_info(vchiq_arm_log_level,
  41224. + "saved bulk_waiter %x for pid %d",
  41225. + (unsigned int)waiter, current->pid);
  41226. + }
  41227. +
  41228. + return status;
  41229. +}
  41230. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
  41231. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 1970-01-01 01:00:00.000000000 +0100
  41232. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 2015-03-09 10:39:30.722893733 +0100
  41233. @@ -0,0 +1,69 @@
  41234. +/**
  41235. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  41236. + *
  41237. + * Redistribution and use in source and binary forms, with or without
  41238. + * modification, are permitted provided that the following conditions
  41239. + * are met:
  41240. + * 1. Redistributions of source code must retain the above copyright
  41241. + * notice, this list of conditions, and the following disclaimer,
  41242. + * without modification.
  41243. + * 2. Redistributions in binary form must reproduce the above copyright
  41244. + * notice, this list of conditions and the following disclaimer in the
  41245. + * documentation and/or other materials provided with the distribution.
  41246. + * 3. The names of the above-listed copyright holders may not be used
  41247. + * to endorse or promote products derived from this software without
  41248. + * specific prior written permission.
  41249. + *
  41250. + * ALTERNATIVELY, this software may be distributed under the terms of the
  41251. + * GNU General Public License ("GPL") version 2, as published by the Free
  41252. + * Software Foundation.
  41253. + *
  41254. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  41255. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  41256. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41257. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  41258. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41259. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  41260. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  41261. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  41262. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  41263. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  41264. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41265. + */
  41266. +
  41267. +#ifndef VCHIQ_KILLABLE_H
  41268. +#define VCHIQ_KILLABLE_H
  41269. +
  41270. +#include <linux/mutex.h>
  41271. +#include <linux/semaphore.h>
  41272. +
  41273. +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
  41274. +
  41275. +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
  41276. +{
  41277. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  41278. + int ret;
  41279. + sigset_t blocked, oldset;
  41280. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  41281. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  41282. + ret = down_interruptible(sem);
  41283. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  41284. + return ret;
  41285. +}
  41286. +#define down_interruptible down_interruptible_killable
  41287. +
  41288. +
  41289. +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
  41290. +{
  41291. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  41292. + int ret;
  41293. + sigset_t blocked, oldset;
  41294. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  41295. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  41296. + ret = mutex_lock_interruptible(lock);
  41297. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  41298. + return ret;
  41299. +}
  41300. +#define mutex_lock_interruptible mutex_lock_interruptible_killable
  41301. +
  41302. +#endif
  41303. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  41304. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  41305. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2015-03-09 10:39:30.722893733 +0100
  41306. @@ -0,0 +1,71 @@
  41307. +/**
  41308. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  41309. + *
  41310. + * Redistribution and use in source and binary forms, with or without
  41311. + * modification, are permitted provided that the following conditions
  41312. + * are met:
  41313. + * 1. Redistributions of source code must retain the above copyright
  41314. + * notice, this list of conditions, and the following disclaimer,
  41315. + * without modification.
  41316. + * 2. Redistributions in binary form must reproduce the above copyright
  41317. + * notice, this list of conditions and the following disclaimer in the
  41318. + * documentation and/or other materials provided with the distribution.
  41319. + * 3. The names of the above-listed copyright holders may not be used
  41320. + * to endorse or promote products derived from this software without
  41321. + * specific prior written permission.
  41322. + *
  41323. + * ALTERNATIVELY, this software may be distributed under the terms of the
  41324. + * GNU General Public License ("GPL") version 2, as published by the Free
  41325. + * Software Foundation.
  41326. + *
  41327. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  41328. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  41329. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41330. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  41331. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41332. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  41333. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  41334. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  41335. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  41336. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  41337. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41338. + */
  41339. +
  41340. +#ifndef VCHIQ_MEMDRV_H
  41341. +#define VCHIQ_MEMDRV_H
  41342. +
  41343. +/* ---- Include Files ----------------------------------------------------- */
  41344. +
  41345. +#include <linux/kernel.h>
  41346. +#include "vchiq_if.h"
  41347. +
  41348. +/* ---- Constants and Types ---------------------------------------------- */
  41349. +
  41350. +typedef struct {
  41351. + void *armSharedMemVirt;
  41352. + dma_addr_t armSharedMemPhys;
  41353. + size_t armSharedMemSize;
  41354. +
  41355. + void *vcSharedMemVirt;
  41356. + dma_addr_t vcSharedMemPhys;
  41357. + size_t vcSharedMemSize;
  41358. +} VCHIQ_SHARED_MEM_INFO_T;
  41359. +
  41360. +/* ---- Variable Externs ------------------------------------------------- */
  41361. +
  41362. +/* ---- Function Prototypes ---------------------------------------------- */
  41363. +
  41364. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  41365. +
  41366. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  41367. +
  41368. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  41369. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  41370. +
  41371. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  41372. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  41373. +
  41374. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  41375. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  41376. +
  41377. +#endif
  41378. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  41379. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  41380. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2015-03-09 10:39:30.722893733 +0100
  41381. @@ -0,0 +1,58 @@
  41382. +/**
  41383. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  41384. + *
  41385. + * Redistribution and use in source and binary forms, with or without
  41386. + * modification, are permitted provided that the following conditions
  41387. + * are met:
  41388. + * 1. Redistributions of source code must retain the above copyright
  41389. + * notice, this list of conditions, and the following disclaimer,
  41390. + * without modification.
  41391. + * 2. Redistributions in binary form must reproduce the above copyright
  41392. + * notice, this list of conditions and the following disclaimer in the
  41393. + * documentation and/or other materials provided with the distribution.
  41394. + * 3. The names of the above-listed copyright holders may not be used
  41395. + * to endorse or promote products derived from this software without
  41396. + * specific prior written permission.
  41397. + *
  41398. + * ALTERNATIVELY, this software may be distributed under the terms of the
  41399. + * GNU General Public License ("GPL") version 2, as published by the Free
  41400. + * Software Foundation.
  41401. + *
  41402. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  41403. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  41404. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41405. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  41406. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41407. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  41408. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  41409. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  41410. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  41411. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  41412. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41413. + */
  41414. +
  41415. +#ifndef VCHIQ_PAGELIST_H
  41416. +#define VCHIQ_PAGELIST_H
  41417. +
  41418. +#ifndef PAGE_SIZE
  41419. +#define PAGE_SIZE 4096
  41420. +#endif
  41421. +#define CACHE_LINE_SIZE 32
  41422. +#define PAGELIST_WRITE 0
  41423. +#define PAGELIST_READ 1
  41424. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  41425. +
  41426. +typedef struct pagelist_struct {
  41427. + unsigned long length;
  41428. + unsigned short type;
  41429. + unsigned short offset;
  41430. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  41431. + pages at consecutive addresses. */
  41432. +} PAGELIST_T;
  41433. +
  41434. +typedef struct fragments_struct {
  41435. + char headbuf[CACHE_LINE_SIZE];
  41436. + char tailbuf[CACHE_LINE_SIZE];
  41437. +} FRAGMENTS_T;
  41438. +
  41439. +#endif /* VCHIQ_PAGELIST_H */
  41440. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  41441. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  41442. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2015-03-10 17:26:50.554216692 +0100
  41443. @@ -0,0 +1,857 @@
  41444. +/**
  41445. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  41446. + *
  41447. + * Redistribution and use in source and binary forms, with or without
  41448. + * modification, are permitted provided that the following conditions
  41449. + * are met:
  41450. + * 1. Redistributions of source code must retain the above copyright
  41451. + * notice, this list of conditions, and the following disclaimer,
  41452. + * without modification.
  41453. + * 2. Redistributions in binary form must reproduce the above copyright
  41454. + * notice, this list of conditions and the following disclaimer in the
  41455. + * documentation and/or other materials provided with the distribution.
  41456. + * 3. The names of the above-listed copyright holders may not be used
  41457. + * to endorse or promote products derived from this software without
  41458. + * specific prior written permission.
  41459. + *
  41460. + * ALTERNATIVELY, this software may be distributed under the terms of the
  41461. + * GNU General Public License ("GPL") version 2, as published by the Free
  41462. + * Software Foundation.
  41463. + *
  41464. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  41465. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  41466. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  41467. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  41468. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41469. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  41470. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  41471. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  41472. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  41473. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  41474. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  41475. + */
  41476. +#include <linux/module.h>
  41477. +#include <linux/types.h>
  41478. +
  41479. +#include "interface/vchi/vchi.h"
  41480. +#include "vchiq.h"
  41481. +#include "vchiq_core.h"
  41482. +
  41483. +#include "vchiq_util.h"
  41484. +
  41485. +#include <stddef.h>
  41486. +
  41487. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  41488. +
  41489. +typedef struct {
  41490. + VCHIQ_SERVICE_HANDLE_T handle;
  41491. +
  41492. + VCHIU_QUEUE_T queue;
  41493. +
  41494. + VCHI_CALLBACK_T callback;
  41495. + void *callback_param;
  41496. +} SHIM_SERVICE_T;
  41497. +
  41498. +/* ----------------------------------------------------------------------
  41499. + * return pointer to the mphi message driver function table
  41500. + * -------------------------------------------------------------------- */
  41501. +const VCHI_MESSAGE_DRIVER_T *
  41502. +vchi_mphi_message_driver_func_table(void)
  41503. +{
  41504. + return NULL;
  41505. +}
  41506. +
  41507. +/* ----------------------------------------------------------------------
  41508. + * return a pointer to the 'single' connection driver fops
  41509. + * -------------------------------------------------------------------- */
  41510. +const VCHI_CONNECTION_API_T *
  41511. +single_get_func_table(void)
  41512. +{
  41513. + return NULL;
  41514. +}
  41515. +
  41516. +VCHI_CONNECTION_T *vchi_create_connection(
  41517. + const VCHI_CONNECTION_API_T *function_table,
  41518. + const VCHI_MESSAGE_DRIVER_T *low_level)
  41519. +{
  41520. + (void)function_table;
  41521. + (void)low_level;
  41522. + return NULL;
  41523. +}
  41524. +
  41525. +/***********************************************************
  41526. + * Name: vchi_msg_peek
  41527. + *
  41528. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  41529. + * void **data,
  41530. + * uint32_t *msg_size,
  41531. +
  41532. +
  41533. + * VCHI_FLAGS_T flags
  41534. + *
  41535. + * Description: Routine to return a pointer to the current message (to allow in
  41536. + * place processing). The message can be removed using
  41537. + * vchi_msg_remove when you're finished
  41538. + *
  41539. + * Returns: int32_t - success == 0
  41540. + *
  41541. + ***********************************************************/
  41542. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  41543. + void **data,
  41544. + uint32_t *msg_size,
  41545. + VCHI_FLAGS_T flags)
  41546. +{
  41547. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41548. + VCHIQ_HEADER_T *header;
  41549. +
  41550. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  41551. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  41552. +
  41553. + if (flags == VCHI_FLAGS_NONE)
  41554. + if (vchiu_queue_is_empty(&service->queue))
  41555. + return -1;
  41556. +
  41557. + header = vchiu_queue_peek(&service->queue);
  41558. +
  41559. + *data = header->data;
  41560. + *msg_size = header->size;
  41561. +
  41562. + return 0;
  41563. +}
  41564. +EXPORT_SYMBOL(vchi_msg_peek);
  41565. +
  41566. +/***********************************************************
  41567. + * Name: vchi_msg_remove
  41568. + *
  41569. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  41570. + *
  41571. + * Description: Routine to remove a message (after it has been read with
  41572. + * vchi_msg_peek)
  41573. + *
  41574. + * Returns: int32_t - success == 0
  41575. + *
  41576. + ***********************************************************/
  41577. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  41578. +{
  41579. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41580. + VCHIQ_HEADER_T *header;
  41581. +
  41582. + header = vchiu_queue_pop(&service->queue);
  41583. +
  41584. + vchiq_release_message(service->handle, header);
  41585. +
  41586. + return 0;
  41587. +}
  41588. +EXPORT_SYMBOL(vchi_msg_remove);
  41589. +
  41590. +/***********************************************************
  41591. + * Name: vchi_msg_queue
  41592. + *
  41593. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  41594. + * const void *data,
  41595. + * uint32_t data_size,
  41596. + * VCHI_FLAGS_T flags,
  41597. + * void *msg_handle,
  41598. + *
  41599. + * Description: Thin wrapper to queue a message onto a connection
  41600. + *
  41601. + * Returns: int32_t - success == 0
  41602. + *
  41603. + ***********************************************************/
  41604. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  41605. + const void *data,
  41606. + uint32_t data_size,
  41607. + VCHI_FLAGS_T flags,
  41608. + void *msg_handle)
  41609. +{
  41610. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41611. + VCHIQ_ELEMENT_T element = {data, data_size};
  41612. + VCHIQ_STATUS_T status;
  41613. +
  41614. + (void)msg_handle;
  41615. +
  41616. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  41617. +
  41618. + status = vchiq_queue_message(service->handle, &element, 1);
  41619. +
  41620. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  41621. + ** implement a retry mechanism since this function is supposed
  41622. + ** to block until queued
  41623. + */
  41624. + while (status == VCHIQ_RETRY) {
  41625. + msleep(1);
  41626. + status = vchiq_queue_message(service->handle, &element, 1);
  41627. + }
  41628. +
  41629. + return vchiq_status_to_vchi(status);
  41630. +}
  41631. +EXPORT_SYMBOL(vchi_msg_queue);
  41632. +
  41633. +/***********************************************************
  41634. + * Name: vchi_bulk_queue_receive
  41635. + *
  41636. + * Arguments: VCHI_BULK_HANDLE_T handle,
  41637. + * void *data_dst,
  41638. + * const uint32_t data_size,
  41639. + * VCHI_FLAGS_T flags
  41640. + * void *bulk_handle
  41641. + *
  41642. + * Description: Routine to setup a rcv buffer
  41643. + *
  41644. + * Returns: int32_t - success == 0
  41645. + *
  41646. + ***********************************************************/
  41647. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  41648. + void *data_dst,
  41649. + uint32_t data_size,
  41650. + VCHI_FLAGS_T flags,
  41651. + void *bulk_handle)
  41652. +{
  41653. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41654. + VCHIQ_BULK_MODE_T mode;
  41655. + VCHIQ_STATUS_T status;
  41656. +
  41657. + switch ((int)flags) {
  41658. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  41659. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  41660. + WARN_ON(!service->callback);
  41661. + mode = VCHIQ_BULK_MODE_CALLBACK;
  41662. + break;
  41663. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  41664. + mode = VCHIQ_BULK_MODE_BLOCKING;
  41665. + break;
  41666. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  41667. + case VCHI_FLAGS_NONE:
  41668. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  41669. + break;
  41670. + default:
  41671. + WARN(1, "unsupported message\n");
  41672. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  41673. + }
  41674. +
  41675. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  41676. + bulk_handle, mode);
  41677. +
  41678. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  41679. + ** implement a retry mechanism since this function is supposed
  41680. + ** to block until queued
  41681. + */
  41682. + while (status == VCHIQ_RETRY) {
  41683. + msleep(1);
  41684. + status = vchiq_bulk_receive(service->handle, data_dst,
  41685. + data_size, bulk_handle, mode);
  41686. + }
  41687. +
  41688. + return vchiq_status_to_vchi(status);
  41689. +}
  41690. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  41691. +
  41692. +/***********************************************************
  41693. + * Name: vchi_bulk_queue_transmit
  41694. + *
  41695. + * Arguments: VCHI_BULK_HANDLE_T handle,
  41696. + * const void *data_src,
  41697. + * uint32_t data_size,
  41698. + * VCHI_FLAGS_T flags,
  41699. + * void *bulk_handle
  41700. + *
  41701. + * Description: Routine to transmit some data
  41702. + *
  41703. + * Returns: int32_t - success == 0
  41704. + *
  41705. + ***********************************************************/
  41706. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  41707. + const void *data_src,
  41708. + uint32_t data_size,
  41709. + VCHI_FLAGS_T flags,
  41710. + void *bulk_handle)
  41711. +{
  41712. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41713. + VCHIQ_BULK_MODE_T mode;
  41714. + VCHIQ_STATUS_T status;
  41715. +
  41716. + switch ((int)flags) {
  41717. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  41718. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  41719. + WARN_ON(!service->callback);
  41720. + mode = VCHIQ_BULK_MODE_CALLBACK;
  41721. + break;
  41722. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  41723. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  41724. + mode = VCHIQ_BULK_MODE_BLOCKING;
  41725. + break;
  41726. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  41727. + case VCHI_FLAGS_NONE:
  41728. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  41729. + break;
  41730. + default:
  41731. + WARN(1, "unsupported message\n");
  41732. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  41733. + }
  41734. +
  41735. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  41736. + bulk_handle, mode);
  41737. +
  41738. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  41739. + ** implement a retry mechanism since this function is supposed
  41740. + ** to block until queued
  41741. + */
  41742. + while (status == VCHIQ_RETRY) {
  41743. + msleep(1);
  41744. + status = vchiq_bulk_transmit(service->handle, data_src,
  41745. + data_size, bulk_handle, mode);
  41746. + }
  41747. +
  41748. + return vchiq_status_to_vchi(status);
  41749. +}
  41750. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  41751. +
  41752. +/***********************************************************
  41753. + * Name: vchi_msg_dequeue
  41754. + *
  41755. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  41756. + * void *data,
  41757. + * uint32_t max_data_size_to_read,
  41758. + * uint32_t *actual_msg_size
  41759. + * VCHI_FLAGS_T flags
  41760. + *
  41761. + * Description: Routine to dequeue a message into the supplied buffer
  41762. + *
  41763. + * Returns: int32_t - success == 0
  41764. + *
  41765. + ***********************************************************/
  41766. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  41767. + void *data,
  41768. + uint32_t max_data_size_to_read,
  41769. + uint32_t *actual_msg_size,
  41770. + VCHI_FLAGS_T flags)
  41771. +{
  41772. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41773. + VCHIQ_HEADER_T *header;
  41774. +
  41775. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  41776. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  41777. +
  41778. + if (flags == VCHI_FLAGS_NONE)
  41779. + if (vchiu_queue_is_empty(&service->queue))
  41780. + return -1;
  41781. +
  41782. + header = vchiu_queue_pop(&service->queue);
  41783. +
  41784. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  41785. + header->size : max_data_size_to_read);
  41786. +
  41787. + *actual_msg_size = header->size;
  41788. +
  41789. + vchiq_release_message(service->handle, header);
  41790. +
  41791. + return 0;
  41792. +}
  41793. +EXPORT_SYMBOL(vchi_msg_dequeue);
  41794. +
  41795. +/***********************************************************
  41796. + * Name: vchi_msg_queuev
  41797. + *
  41798. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  41799. + * VCHI_MSG_VECTOR_T *vector,
  41800. + * uint32_t count,
  41801. + * VCHI_FLAGS_T flags,
  41802. + * void *msg_handle
  41803. + *
  41804. + * Description: Thin wrapper to queue a message onto a connection
  41805. + *
  41806. + * Returns: int32_t - success == 0
  41807. + *
  41808. + ***********************************************************/
  41809. +
  41810. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  41811. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  41812. + offsetof(VCHIQ_ELEMENT_T, data));
  41813. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  41814. + offsetof(VCHIQ_ELEMENT_T, size));
  41815. +
  41816. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  41817. + VCHI_MSG_VECTOR_T *vector,
  41818. + uint32_t count,
  41819. + VCHI_FLAGS_T flags,
  41820. + void *msg_handle)
  41821. +{
  41822. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41823. +
  41824. + (void)msg_handle;
  41825. +
  41826. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  41827. +
  41828. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  41829. + (const VCHIQ_ELEMENT_T *)vector, count));
  41830. +}
  41831. +EXPORT_SYMBOL(vchi_msg_queuev);
  41832. +
  41833. +/***********************************************************
  41834. + * Name: vchi_held_msg_release
  41835. + *
  41836. + * Arguments: VCHI_HELD_MSG_T *message
  41837. + *
  41838. + * Description: Routine to release a held message (after it has been read with
  41839. + * vchi_msg_hold)
  41840. + *
  41841. + * Returns: int32_t - success == 0
  41842. + *
  41843. + ***********************************************************/
  41844. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  41845. +{
  41846. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  41847. + (VCHIQ_HEADER_T *)message->message);
  41848. +
  41849. + return 0;
  41850. +}
  41851. +EXPORT_SYMBOL(vchi_held_msg_release);
  41852. +
  41853. +/***********************************************************
  41854. + * Name: vchi_msg_hold
  41855. + *
  41856. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  41857. + * void **data,
  41858. + * uint32_t *msg_size,
  41859. + * VCHI_FLAGS_T flags,
  41860. + * VCHI_HELD_MSG_T *message_handle
  41861. + *
  41862. + * Description: Routine to return a pointer to the current message (to allow
  41863. + * in place processing). The message is dequeued - don't forget
  41864. + * to release the message using vchi_held_msg_release when you're
  41865. + * finished.
  41866. + *
  41867. + * Returns: int32_t - success == 0
  41868. + *
  41869. + ***********************************************************/
  41870. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  41871. + void **data,
  41872. + uint32_t *msg_size,
  41873. + VCHI_FLAGS_T flags,
  41874. + VCHI_HELD_MSG_T *message_handle)
  41875. +{
  41876. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  41877. + VCHIQ_HEADER_T *header;
  41878. +
  41879. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  41880. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  41881. +
  41882. + if (flags == VCHI_FLAGS_NONE)
  41883. + if (vchiu_queue_is_empty(&service->queue))
  41884. + return -1;
  41885. +
  41886. + header = vchiu_queue_pop(&service->queue);
  41887. +
  41888. + *data = header->data;
  41889. + *msg_size = header->size;
  41890. +
  41891. + message_handle->service =
  41892. + (struct opaque_vchi_service_t *)service->handle;
  41893. + message_handle->message = header;
  41894. +
  41895. + return 0;
  41896. +}
  41897. +EXPORT_SYMBOL(vchi_msg_hold);
  41898. +
  41899. +/***********************************************************
  41900. + * Name: vchi_initialise
  41901. + *
  41902. + * Arguments: VCHI_INSTANCE_T *instance_handle
  41903. + *
  41904. + * Description: Initialises the hardware but does not transmit anything
  41905. + * When run as a Host App this will be called twice hence the need
  41906. + * to malloc the state information
  41907. + *
  41908. + * Returns: 0 if successful, failure otherwise
  41909. + *
  41910. + ***********************************************************/
  41911. +
  41912. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  41913. +{
  41914. + VCHIQ_INSTANCE_T instance;
  41915. + VCHIQ_STATUS_T status;
  41916. +
  41917. + status = vchiq_initialise(&instance);
  41918. +
  41919. + *instance_handle = (VCHI_INSTANCE_T)instance;
  41920. +
  41921. + return vchiq_status_to_vchi(status);
  41922. +}
  41923. +EXPORT_SYMBOL(vchi_initialise);
  41924. +
  41925. +/***********************************************************
  41926. + * Name: vchi_connect
  41927. + *
  41928. + * Arguments: VCHI_CONNECTION_T **connections
  41929. + * const uint32_t num_connections
  41930. + * VCHI_INSTANCE_T instance_handle)
  41931. + *
  41932. + * Description: Starts the command service on each connection,
  41933. + * causing INIT messages to be pinged back and forth
  41934. + *
  41935. + * Returns: 0 if successful, failure otherwise
  41936. + *
  41937. + ***********************************************************/
  41938. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  41939. + const uint32_t num_connections,
  41940. + VCHI_INSTANCE_T instance_handle)
  41941. +{
  41942. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  41943. +
  41944. + (void)connections;
  41945. + (void)num_connections;
  41946. +
  41947. + return vchiq_connect(instance);
  41948. +}
  41949. +EXPORT_SYMBOL(vchi_connect);
  41950. +
  41951. +
  41952. +/***********************************************************
  41953. + * Name: vchi_disconnect
  41954. + *
  41955. + * Arguments: VCHI_INSTANCE_T instance_handle
  41956. + *
  41957. + * Description: Stops the command service on each connection,
  41958. + * causing DE-INIT messages to be pinged back and forth
  41959. + *
  41960. + * Returns: 0 if successful, failure otherwise
  41961. + *
  41962. + ***********************************************************/
  41963. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  41964. +{
  41965. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  41966. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  41967. +}
  41968. +EXPORT_SYMBOL(vchi_disconnect);
  41969. +
  41970. +
  41971. +/***********************************************************
  41972. + * Name: vchi_service_open
  41973. + * Name: vchi_service_create
  41974. + *
  41975. + * Arguments: VCHI_INSTANCE_T *instance_handle
  41976. + * SERVICE_CREATION_T *setup,
  41977. + * VCHI_SERVICE_HANDLE_T *handle
  41978. + *
  41979. + * Description: Routine to open a service
  41980. + *
  41981. + * Returns: int32_t - success == 0
  41982. + *
  41983. + ***********************************************************/
  41984. +
  41985. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  41986. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  41987. +{
  41988. + SHIM_SERVICE_T *service =
  41989. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  41990. +
  41991. + if (!service->callback)
  41992. + goto release;
  41993. +
  41994. + switch (reason) {
  41995. + case VCHIQ_MESSAGE_AVAILABLE:
  41996. + vchiu_queue_push(&service->queue, header);
  41997. +
  41998. + service->callback(service->callback_param,
  41999. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  42000. +
  42001. + goto done;
  42002. + break;
  42003. +
  42004. + case VCHIQ_BULK_TRANSMIT_DONE:
  42005. + service->callback(service->callback_param,
  42006. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  42007. + break;
  42008. +
  42009. + case VCHIQ_BULK_RECEIVE_DONE:
  42010. + service->callback(service->callback_param,
  42011. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  42012. + break;
  42013. +
  42014. + case VCHIQ_SERVICE_CLOSED:
  42015. + service->callback(service->callback_param,
  42016. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  42017. + break;
  42018. +
  42019. + case VCHIQ_SERVICE_OPENED:
  42020. + /* No equivalent VCHI reason */
  42021. + break;
  42022. +
  42023. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  42024. + service->callback(service->callback_param,
  42025. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  42026. + bulk_user);
  42027. + break;
  42028. +
  42029. + case VCHIQ_BULK_RECEIVE_ABORTED:
  42030. + service->callback(service->callback_param,
  42031. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  42032. + bulk_user);
  42033. + break;
  42034. +
  42035. + default:
  42036. + WARN(1, "not supported\n");
  42037. + break;
  42038. + }
  42039. +
  42040. +release:
  42041. + vchiq_release_message(service->handle, header);
  42042. +done:
  42043. + return VCHIQ_SUCCESS;
  42044. +}
  42045. +
  42046. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  42047. + SERVICE_CREATION_T *setup)
  42048. +{
  42049. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  42050. +
  42051. + (void)instance;
  42052. +
  42053. + if (service) {
  42054. + if (vchiu_queue_init(&service->queue, 64)) {
  42055. + service->callback = setup->callback;
  42056. + service->callback_param = setup->callback_param;
  42057. + } else {
  42058. + kfree(service);
  42059. + service = NULL;
  42060. + }
  42061. + }
  42062. +
  42063. + return service;
  42064. +}
  42065. +
  42066. +static void service_free(SHIM_SERVICE_T *service)
  42067. +{
  42068. + if (service) {
  42069. + vchiu_queue_delete(&service->queue);
  42070. + kfree(service);
  42071. + }
  42072. +}
  42073. +
  42074. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  42075. + SERVICE_CREATION_T *setup,
  42076. + VCHI_SERVICE_HANDLE_T *handle)
  42077. +{
  42078. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  42079. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  42080. +
  42081. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  42082. +
  42083. + if (service) {
  42084. + VCHIQ_SERVICE_PARAMS_T params;
  42085. + VCHIQ_STATUS_T status;
  42086. +
  42087. + memset(&params, 0, sizeof(params));
  42088. + params.fourcc = setup->service_id;
  42089. + params.callback = shim_callback;
  42090. + params.userdata = service;
  42091. + params.version = setup->version.version;
  42092. + params.version_min = setup->version.version_min;
  42093. +
  42094. + status = vchiq_open_service(instance, &params,
  42095. + &service->handle);
  42096. + if (status != VCHIQ_SUCCESS) {
  42097. + service_free(service);
  42098. + service = NULL;
  42099. + *handle = NULL;
  42100. + }
  42101. + }
  42102. +
  42103. + return (service != NULL) ? 0 : -1;
  42104. +}
  42105. +EXPORT_SYMBOL(vchi_service_open);
  42106. +
  42107. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  42108. + SERVICE_CREATION_T *setup,
  42109. + VCHI_SERVICE_HANDLE_T *handle)
  42110. +{
  42111. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  42112. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  42113. +
  42114. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  42115. +
  42116. + if (service) {
  42117. + VCHIQ_SERVICE_PARAMS_T params;
  42118. + VCHIQ_STATUS_T status;
  42119. +
  42120. + memset(&params, 0, sizeof(params));
  42121. + params.fourcc = setup->service_id;
  42122. + params.callback = shim_callback;
  42123. + params.userdata = service;
  42124. + params.version = setup->version.version;
  42125. + params.version_min = setup->version.version_min;
  42126. + status = vchiq_add_service(instance, &params, &service->handle);
  42127. +
  42128. + if (status != VCHIQ_SUCCESS) {
  42129. + service_free(service);
  42130. + service = NULL;
  42131. + *handle = NULL;
  42132. + }
  42133. + }
  42134. +
  42135. + return (service != NULL) ? 0 : -1;
  42136. +}
  42137. +EXPORT_SYMBOL(vchi_service_create);
  42138. +
  42139. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  42140. +{
  42141. + int32_t ret = -1;
  42142. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42143. + if (service) {
  42144. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  42145. + if (status == VCHIQ_SUCCESS) {
  42146. + service_free(service);
  42147. + service = NULL;
  42148. + }
  42149. +
  42150. + ret = vchiq_status_to_vchi(status);
  42151. + }
  42152. + return ret;
  42153. +}
  42154. +EXPORT_SYMBOL(vchi_service_close);
  42155. +
  42156. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  42157. +{
  42158. + int32_t ret = -1;
  42159. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42160. + if (service) {
  42161. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  42162. + if (status == VCHIQ_SUCCESS) {
  42163. + service_free(service);
  42164. + service = NULL;
  42165. + }
  42166. +
  42167. + ret = vchiq_status_to_vchi(status);
  42168. + }
  42169. + return ret;
  42170. +}
  42171. +EXPORT_SYMBOL(vchi_service_destroy);
  42172. +
  42173. +int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
  42174. + VCHI_SERVICE_OPTION_T option,
  42175. + int value)
  42176. +{
  42177. + int32_t ret = -1;
  42178. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42179. + VCHIQ_SERVICE_OPTION_T vchiq_option;
  42180. + switch (option) {
  42181. + case VCHI_SERVICE_OPTION_TRACE:
  42182. + vchiq_option = VCHIQ_SERVICE_OPTION_TRACE;
  42183. + break;
  42184. + default:
  42185. + service = NULL;
  42186. + break;
  42187. + }
  42188. + if (service) {
  42189. + VCHIQ_STATUS_T status =
  42190. + vchiq_set_service_option(service->handle,
  42191. + vchiq_option,
  42192. + value);
  42193. +
  42194. + ret = vchiq_status_to_vchi(status);
  42195. + }
  42196. + return ret;
  42197. +}
  42198. +EXPORT_SYMBOL(vchi_service_set_option);
  42199. +
  42200. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  42201. +{
  42202. + int32_t ret = -1;
  42203. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42204. + if(service)
  42205. + {
  42206. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  42207. + ret = vchiq_status_to_vchi( status );
  42208. + }
  42209. + return ret;
  42210. +}
  42211. +EXPORT_SYMBOL(vchi_get_peer_version);
  42212. +
  42213. +/* ----------------------------------------------------------------------
  42214. + * read a uint32_t from buffer.
  42215. + * network format is defined to be little endian
  42216. + * -------------------------------------------------------------------- */
  42217. +uint32_t
  42218. +vchi_readbuf_uint32(const void *_ptr)
  42219. +{
  42220. + const unsigned char *ptr = _ptr;
  42221. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  42222. +}
  42223. +
  42224. +/* ----------------------------------------------------------------------
  42225. + * write a uint32_t to buffer.
  42226. + * network format is defined to be little endian
  42227. + * -------------------------------------------------------------------- */
  42228. +void
  42229. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  42230. +{
  42231. + unsigned char *ptr = _ptr;
  42232. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  42233. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  42234. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  42235. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  42236. +}
  42237. +
  42238. +/* ----------------------------------------------------------------------
  42239. + * read a uint16_t from buffer.
  42240. + * network format is defined to be little endian
  42241. + * -------------------------------------------------------------------- */
  42242. +uint16_t
  42243. +vchi_readbuf_uint16(const void *_ptr)
  42244. +{
  42245. + const unsigned char *ptr = _ptr;
  42246. + return ptr[0] | (ptr[1] << 8);
  42247. +}
  42248. +
  42249. +/* ----------------------------------------------------------------------
  42250. + * write a uint16_t into the buffer.
  42251. + * network format is defined to be little endian
  42252. + * -------------------------------------------------------------------- */
  42253. +void
  42254. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  42255. +{
  42256. + unsigned char *ptr = _ptr;
  42257. + ptr[0] = (value >> 0) & 0xFF;
  42258. + ptr[1] = (value >> 8) & 0xFF;
  42259. +}
  42260. +
  42261. +/***********************************************************
  42262. + * Name: vchi_service_use
  42263. + *
  42264. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  42265. + *
  42266. + * Description: Routine to increment refcount on a service
  42267. + *
  42268. + * Returns: void
  42269. + *
  42270. + ***********************************************************/
  42271. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  42272. +{
  42273. + int32_t ret = -1;
  42274. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42275. + if (service)
  42276. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  42277. + return ret;
  42278. +}
  42279. +EXPORT_SYMBOL(vchi_service_use);
  42280. +
  42281. +/***********************************************************
  42282. + * Name: vchi_service_release
  42283. + *
  42284. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  42285. + *
  42286. + * Description: Routine to decrement refcount on a service
  42287. + *
  42288. + * Returns: void
  42289. + *
  42290. + ***********************************************************/
  42291. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  42292. +{
  42293. + int32_t ret = -1;
  42294. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  42295. + if (service)
  42296. + ret = vchiq_status_to_vchi(
  42297. + vchiq_release_service(service->handle));
  42298. + return ret;
  42299. +}
  42300. +EXPORT_SYMBOL(vchi_service_release);
  42301. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  42302. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  42303. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2015-03-09 10:39:30.722893733 +0100
  42304. @@ -0,0 +1,152 @@
  42305. +/**
  42306. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  42307. + *
  42308. + * Redistribution and use in source and binary forms, with or without
  42309. + * modification, are permitted provided that the following conditions
  42310. + * are met:
  42311. + * 1. Redistributions of source code must retain the above copyright
  42312. + * notice, this list of conditions, and the following disclaimer,
  42313. + * without modification.
  42314. + * 2. Redistributions in binary form must reproduce the above copyright
  42315. + * notice, this list of conditions and the following disclaimer in the
  42316. + * documentation and/or other materials provided with the distribution.
  42317. + * 3. The names of the above-listed copyright holders may not be used
  42318. + * to endorse or promote products derived from this software without
  42319. + * specific prior written permission.
  42320. + *
  42321. + * ALTERNATIVELY, this software may be distributed under the terms of the
  42322. + * GNU General Public License ("GPL") version 2, as published by the Free
  42323. + * Software Foundation.
  42324. + *
  42325. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  42326. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42327. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42328. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42329. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42330. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42331. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42332. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42333. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42334. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42335. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42336. + */
  42337. +
  42338. +#include "vchiq_util.h"
  42339. +#include "vchiq_killable.h"
  42340. +
  42341. +static inline int is_pow2(int i)
  42342. +{
  42343. + return i && !(i & (i - 1));
  42344. +}
  42345. +
  42346. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  42347. +{
  42348. + WARN_ON(!is_pow2(size));
  42349. +
  42350. + queue->size = size;
  42351. + queue->read = 0;
  42352. + queue->write = 0;
  42353. +
  42354. + sema_init(&queue->pop, 0);
  42355. + sema_init(&queue->push, 0);
  42356. +
  42357. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  42358. + if (queue->storage == NULL) {
  42359. + vchiu_queue_delete(queue);
  42360. + return 0;
  42361. + }
  42362. + return 1;
  42363. +}
  42364. +
  42365. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  42366. +{
  42367. + if (queue->storage != NULL)
  42368. + kfree(queue->storage);
  42369. +}
  42370. +
  42371. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  42372. +{
  42373. + return queue->read == queue->write;
  42374. +}
  42375. +
  42376. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  42377. +{
  42378. + return queue->write == queue->read + queue->size;
  42379. +}
  42380. +
  42381. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  42382. +{
  42383. + while (queue->write == queue->read + queue->size) {
  42384. + if (down_interruptible(&queue->pop) != 0) {
  42385. + flush_signals(current);
  42386. + }
  42387. + }
  42388. +
  42389. + /*
  42390. + * Write to queue->storage must be visible after read from
  42391. + * queue->read
  42392. + */
  42393. + smp_mb();
  42394. +
  42395. + queue->storage[queue->write & (queue->size - 1)] = header;
  42396. +
  42397. + /*
  42398. + * Write to queue->storage must be visible before write to
  42399. + * queue->write
  42400. + */
  42401. + smp_wmb();
  42402. +
  42403. + queue->write++;
  42404. +
  42405. + up(&queue->push);
  42406. +}
  42407. +
  42408. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  42409. +{
  42410. + while (queue->write == queue->read) {
  42411. + if (down_interruptible(&queue->push) != 0) {
  42412. + flush_signals(current);
  42413. + }
  42414. + }
  42415. +
  42416. + up(&queue->push); // We haven't removed anything from the queue.
  42417. +
  42418. + /*
  42419. + * Read from queue->storage must be visible after read from
  42420. + * queue->write
  42421. + */
  42422. + smp_rmb();
  42423. +
  42424. + return queue->storage[queue->read & (queue->size - 1)];
  42425. +}
  42426. +
  42427. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  42428. +{
  42429. + VCHIQ_HEADER_T *header;
  42430. +
  42431. + while (queue->write == queue->read) {
  42432. + if (down_interruptible(&queue->push) != 0) {
  42433. + flush_signals(current);
  42434. + }
  42435. + }
  42436. +
  42437. + /*
  42438. + * Read from queue->storage must be visible after read from
  42439. + * queue->write
  42440. + */
  42441. + smp_rmb();
  42442. +
  42443. + header = queue->storage[queue->read & (queue->size - 1)];
  42444. +
  42445. + /*
  42446. + * Read from queue->storage must be visible before write to
  42447. + * queue->read
  42448. + */
  42449. + smp_mb();
  42450. +
  42451. + queue->read++;
  42452. +
  42453. + up(&queue->pop);
  42454. +
  42455. + return header;
  42456. +}
  42457. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  42458. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  42459. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2015-03-09 10:39:30.722893733 +0100
  42460. @@ -0,0 +1,81 @@
  42461. +/**
  42462. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  42463. + *
  42464. + * Redistribution and use in source and binary forms, with or without
  42465. + * modification, are permitted provided that the following conditions
  42466. + * are met:
  42467. + * 1. Redistributions of source code must retain the above copyright
  42468. + * notice, this list of conditions, and the following disclaimer,
  42469. + * without modification.
  42470. + * 2. Redistributions in binary form must reproduce the above copyright
  42471. + * notice, this list of conditions and the following disclaimer in the
  42472. + * documentation and/or other materials provided with the distribution.
  42473. + * 3. The names of the above-listed copyright holders may not be used
  42474. + * to endorse or promote products derived from this software without
  42475. + * specific prior written permission.
  42476. + *
  42477. + * ALTERNATIVELY, this software may be distributed under the terms of the
  42478. + * GNU General Public License ("GPL") version 2, as published by the Free
  42479. + * Software Foundation.
  42480. + *
  42481. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  42482. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42483. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42484. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42485. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42486. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42487. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42488. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42489. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42490. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42491. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42492. + */
  42493. +
  42494. +#ifndef VCHIQ_UTIL_H
  42495. +#define VCHIQ_UTIL_H
  42496. +
  42497. +#include <linux/types.h>
  42498. +#include <linux/semaphore.h>
  42499. +#include <linux/mutex.h>
  42500. +#include <linux/bitops.h>
  42501. +#include <linux/kthread.h>
  42502. +#include <linux/wait.h>
  42503. +#include <linux/vmalloc.h>
  42504. +#include <linux/jiffies.h>
  42505. +#include <linux/delay.h>
  42506. +#include <linux/string.h>
  42507. +#include <linux/types.h>
  42508. +#include <linux/interrupt.h>
  42509. +#include <linux/random.h>
  42510. +#include <linux/sched.h>
  42511. +#include <linux/ctype.h>
  42512. +#include <linux/uaccess.h>
  42513. +#include <linux/time.h> /* for time_t */
  42514. +#include <linux/slab.h>
  42515. +#include <linux/vmalloc.h>
  42516. +
  42517. +#include "vchiq_if.h"
  42518. +
  42519. +typedef struct {
  42520. + int size;
  42521. + int read;
  42522. + int write;
  42523. +
  42524. + struct semaphore pop;
  42525. + struct semaphore push;
  42526. +
  42527. + VCHIQ_HEADER_T **storage;
  42528. +} VCHIU_QUEUE_T;
  42529. +
  42530. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  42531. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  42532. +
  42533. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  42534. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  42535. +
  42536. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  42537. +
  42538. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  42539. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  42540. +
  42541. +#endif
  42542. diff -Nur linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  42543. --- linux-3.12.38/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  42544. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2015-03-09 10:39:30.722893733 +0100
  42545. @@ -0,0 +1,59 @@
  42546. +/**
  42547. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  42548. + *
  42549. + * Redistribution and use in source and binary forms, with or without
  42550. + * modification, are permitted provided that the following conditions
  42551. + * are met:
  42552. + * 1. Redistributions of source code must retain the above copyright
  42553. + * notice, this list of conditions, and the following disclaimer,
  42554. + * without modification.
  42555. + * 2. Redistributions in binary form must reproduce the above copyright
  42556. + * notice, this list of conditions and the following disclaimer in the
  42557. + * documentation and/or other materials provided with the distribution.
  42558. + * 3. The names of the above-listed copyright holders may not be used
  42559. + * to endorse or promote products derived from this software without
  42560. + * specific prior written permission.
  42561. + *
  42562. + * ALTERNATIVELY, this software may be distributed under the terms of the
  42563. + * GNU General Public License ("GPL") version 2, as published by the Free
  42564. + * Software Foundation.
  42565. + *
  42566. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  42567. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  42568. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42569. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  42570. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42571. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42572. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  42573. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42574. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42575. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42576. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42577. + */
  42578. +#include "vchiq_build_info.h"
  42579. +#include <linux/broadcom/vc_debug_sym.h>
  42580. +
  42581. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  42582. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  42583. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  42584. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  42585. +
  42586. +const char *vchiq_get_build_hostname( void )
  42587. +{
  42588. + return vchiq_build_hostname;
  42589. +}
  42590. +
  42591. +const char *vchiq_get_build_version( void )
  42592. +{
  42593. + return vchiq_build_version;
  42594. +}
  42595. +
  42596. +const char *vchiq_get_build_date( void )
  42597. +{
  42598. + return vchiq_build_date;
  42599. +}
  42600. +
  42601. +const char *vchiq_get_build_time( void )
  42602. +{
  42603. + return vchiq_build_time;
  42604. +}
  42605. diff -Nur linux-3.12.38/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  42606. --- linux-3.12.38/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  42607. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2015-03-10 17:26:50.554216692 +0100
  42608. @@ -0,0 +1,9 @@
  42609. +config BCM2708_VCHIQ
  42610. + tristate "Videocore VCHIQ"
  42611. + depends on MACH_BCM2708
  42612. + default y
  42613. + help
  42614. + Kernel to VideoCore communication interface for the
  42615. + BCM2708 family of products.
  42616. + Defaults to Y when the Broadcom Videocore services
  42617. + are included in the build, N otherwise.
  42618. diff -Nur linux-3.12.38/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  42619. --- linux-3.12.38/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  42620. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2015-03-10 17:26:50.554216692 +0100
  42621. @@ -0,0 +1,17 @@
  42622. +ifeq ($(CONFIG_MACH_BCM2708),y)
  42623. +
  42624. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  42625. +
  42626. +vchiq-objs := \
  42627. + interface/vchiq_arm/vchiq_core.o \
  42628. + interface/vchiq_arm/vchiq_arm.o \
  42629. + interface/vchiq_arm/vchiq_kern_lib.o \
  42630. + interface/vchiq_arm/vchiq_2835_arm.o \
  42631. + interface/vchiq_arm/vchiq_debugfs.o \
  42632. + interface/vchiq_arm/vchiq_shim.o \
  42633. + interface/vchiq_arm/vchiq_util.o \
  42634. + interface/vchiq_arm/vchiq_connected.o \
  42635. +
  42636. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  42637. +
  42638. +endif
  42639. diff -Nur linux-3.12.38/drivers/mmc/card/block.c linux-rpi/drivers/mmc/card/block.c
  42640. --- linux-3.12.38/drivers/mmc/card/block.c 2015-02-16 16:15:42.000000000 +0100
  42641. +++ linux-rpi/drivers/mmc/card/block.c 2015-03-10 17:26:50.554216692 +0100
  42642. @@ -1361,7 +1361,7 @@
  42643. brq->data.blocks = 1;
  42644. }
  42645. - if (brq->data.blocks > 1 || do_rel_wr) {
  42646. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  42647. /* SPI multiblock writes terminate using a special
  42648. * token, not a STOP_TRANSMISSION request.
  42649. */
  42650. diff -Nur linux-3.12.38/drivers/mmc/core/sd.c linux-rpi/drivers/mmc/core/sd.c
  42651. --- linux-3.12.38/drivers/mmc/core/sd.c 2015-02-16 16:15:42.000000000 +0100
  42652. +++ linux-rpi/drivers/mmc/core/sd.c 2015-03-10 17:26:50.554216692 +0100
  42653. @@ -14,6 +14,8 @@
  42654. #include <linux/sizes.h>
  42655. #include <linux/slab.h>
  42656. #include <linux/stat.h>
  42657. +#include <linux/jiffies.h>
  42658. +#include <linux/nmi.h>
  42659. #include <linux/mmc/host.h>
  42660. #include <linux/mmc/card.h>
  42661. @@ -66,6 +68,15 @@
  42662. __res & __mask; \
  42663. })
  42664. +// timeout for tries
  42665. +static const unsigned long retry_timeout_ms= 10*1000;
  42666. +
  42667. +// try at least 10 times, even if timeout is reached
  42668. +static const int retry_min_tries= 10;
  42669. +
  42670. +// delay between tries
  42671. +static const unsigned long retry_delay_ms= 10;
  42672. +
  42673. /*
  42674. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  42675. */
  42676. @@ -218,12 +229,63 @@
  42677. }
  42678. /*
  42679. - * Fetch and process SD Status register.
  42680. + * Fetch and process SD Configuration Register.
  42681. + */
  42682. +static int mmc_read_scr(struct mmc_card *card)
  42683. +{
  42684. + unsigned long timeout_at;
  42685. + int err, tries;
  42686. +
  42687. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  42688. + tries= 0;
  42689. +
  42690. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  42691. + {
  42692. + unsigned long delay_at;
  42693. + tries++;
  42694. +
  42695. + err = mmc_app_send_scr(card, card->raw_scr);
  42696. + if( !err )
  42697. + break; // success!!!
  42698. +
  42699. + touch_nmi_watchdog(); // we are still alive!
  42700. +
  42701. + // delay
  42702. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  42703. + while( time_before( jiffies, delay_at ) )
  42704. + {
  42705. + mdelay( 1 );
  42706. + touch_nmi_watchdog(); // we are still alive!
  42707. + }
  42708. + }
  42709. +
  42710. + if( err)
  42711. + {
  42712. + 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 );
  42713. + return err;
  42714. + }
  42715. +
  42716. + if( tries > 1 )
  42717. + {
  42718. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  42719. + }
  42720. +
  42721. + err = mmc_decode_scr(card);
  42722. + if (err)
  42723. + return err;
  42724. +
  42725. + return err;
  42726. +}
  42727. +
  42728. +/*
  42729. + * Fetch and process SD Status Register.
  42730. */
  42731. static int mmc_read_ssr(struct mmc_card *card)
  42732. {
  42733. + unsigned long timeout_at;
  42734. unsigned int au, es, et, eo;
  42735. int err, i;
  42736. + int tries;
  42737. u32 *ssr;
  42738. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  42739. @@ -236,14 +298,40 @@
  42740. if (!ssr)
  42741. return -ENOMEM;
  42742. - err = mmc_app_sd_status(card, ssr);
  42743. - if (err) {
  42744. - pr_warning("%s: problem reading SD Status "
  42745. - "register.\n", mmc_hostname(card->host));
  42746. - err = 0;
  42747. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  42748. + tries= 0;
  42749. +
  42750. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  42751. + {
  42752. + unsigned long delay_at;
  42753. + tries++;
  42754. +
  42755. + err= mmc_app_sd_status(card, ssr);
  42756. + if( !err )
  42757. + break; // sucess!!!
  42758. +
  42759. + touch_nmi_watchdog(); // we are still alive!
  42760. +
  42761. + // delay
  42762. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  42763. + while( time_before( jiffies, delay_at ) )
  42764. + {
  42765. + mdelay( 1 );
  42766. + touch_nmi_watchdog(); // we are still alive!
  42767. + }
  42768. + }
  42769. +
  42770. + if( err)
  42771. + {
  42772. + 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 );
  42773. goto out;
  42774. }
  42775. + if( tries > 1 )
  42776. + {
  42777. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  42778. + }
  42779. +
  42780. for (i = 0; i < 16; i++)
  42781. ssr[i] = be32_to_cpu(ssr[i]);
  42782. @@ -823,14 +911,10 @@
  42783. if (!reinit) {
  42784. /*
  42785. - * Fetch SCR from card.
  42786. + * Fetch and decode SD Configuration register.
  42787. */
  42788. - err = mmc_app_send_scr(card, card->raw_scr);
  42789. - if (err)
  42790. - return err;
  42791. -
  42792. - err = mmc_decode_scr(card);
  42793. - if (err)
  42794. + err = mmc_read_scr(card);
  42795. + if( err )
  42796. return err;
  42797. /*
  42798. diff -Nur linux-3.12.38/drivers/mmc/host/bcm2835-mmc.c linux-rpi/drivers/mmc/host/bcm2835-mmc.c
  42799. --- linux-3.12.38/drivers/mmc/host/bcm2835-mmc.c 1970-01-01 01:00:00.000000000 +0100
  42800. +++ linux-rpi/drivers/mmc/host/bcm2835-mmc.c 2015-03-10 17:26:50.558216692 +0100
  42801. @@ -0,0 +1,1547 @@
  42802. +/*
  42803. + * BCM2835 MMC host driver.
  42804. + *
  42805. + * Author: Gellert Weisz <gellert@raspberrypi.org>
  42806. + * Copyright 2014
  42807. + *
  42808. + * Based on
  42809. + * sdhci-bcm2708.c by Broadcom
  42810. + * sdhci-bcm2835.c by Stephen Warren and Oleksandr Tymoshenko
  42811. + * sdhci.c and sdhci-pci.c by Pierre Ossman
  42812. + *
  42813. + * This program is free software; you can redistribute it and/or modify it
  42814. + * under the terms and conditions of the GNU General Public License,
  42815. + * version 2, as published by the Free Software Foundation.
  42816. + *
  42817. + * This program is distributed in the hope it will be useful, but WITHOUT
  42818. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  42819. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  42820. + * more details.
  42821. + *
  42822. + * You should have received a copy of the GNU General Public License
  42823. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  42824. + */
  42825. +
  42826. +#include <linux/delay.h>
  42827. +#include <linux/module.h>
  42828. +#include <linux/io.h>
  42829. +#include <linux/mmc/mmc.h>
  42830. +#include <linux/mmc/host.h>
  42831. +#include <linux/mmc/sd.h>
  42832. +#include <linux/scatterlist.h>
  42833. +#include <linux/of_address.h>
  42834. +#include <linux/of_irq.h>
  42835. +#include <linux/clk.h>
  42836. +#include <linux/platform_device.h>
  42837. +#include <linux/err.h>
  42838. +#include <linux/blkdev.h>
  42839. +#include <linux/dmaengine.h>
  42840. +#include <linux/dma-mapping.h>
  42841. +#include <linux/of_dma.h>
  42842. +
  42843. +#include "sdhci.h"
  42844. +
  42845. +
  42846. +#ifndef CONFIG_OF
  42847. + #define BCM2835_CLOCK_FREQ 250000000
  42848. +#endif
  42849. +
  42850. +#define DRIVER_NAME "mmc-bcm2835"
  42851. +
  42852. +#define DBG(f, x...) \
  42853. +pr_debug(DRIVER_NAME " [%s()]: " f, __func__, ## x)
  42854. +
  42855. +#ifndef CONFIG_MMC_BCM2835_DMA
  42856. + #define FORCE_PIO
  42857. +#endif
  42858. +
  42859. +
  42860. +/* the inclusive limit in bytes under which PIO will be used instead of DMA */
  42861. +#ifdef CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  42862. +#define PIO_DMA_BARRIER CONFIG_MMC_BCM2835_PIO_DMA_BARRIER
  42863. +#else
  42864. +#define PIO_DMA_BARRIER 00
  42865. +#endif
  42866. +
  42867. +#define MIN_FREQ 400000
  42868. +#define TIMEOUT_VAL 0xE
  42869. +#define BCM2835_SDHCI_WRITE_DELAY(f) (((2 * 1000000) / f) + 1)
  42870. +
  42871. +#ifndef BCM2708_PERI_BASE
  42872. + #define BCM2708_PERI_BASE 0x20000000
  42873. +#endif
  42874. +
  42875. +/* FIXME: Needs IOMMU support */
  42876. +#define BCM2835_VCMMU_SHIFT (0x7E000000 - BCM2708_PERI_BASE)
  42877. +
  42878. +
  42879. +struct bcm2835_host {
  42880. + spinlock_t lock;
  42881. +
  42882. + void __iomem *ioaddr;
  42883. + u32 phys_addr;
  42884. +
  42885. + struct mmc_host *mmc;
  42886. +
  42887. + u32 timeout;
  42888. +
  42889. + int clock; /* Current clock speed */
  42890. + u8 pwr; /* Current voltage */
  42891. +
  42892. + unsigned int max_clk; /* Max possible freq */
  42893. + unsigned int timeout_clk; /* Timeout freq (KHz) */
  42894. + unsigned int clk_mul; /* Clock Muliplier value */
  42895. +
  42896. + struct tasklet_struct finish_tasklet; /* Tasklet structures */
  42897. +
  42898. + struct timer_list timer; /* Timer for timeouts */
  42899. +
  42900. + struct sg_mapping_iter sg_miter; /* SG state for PIO */
  42901. + unsigned int blocks; /* remaining PIO blocks */
  42902. +
  42903. + int irq; /* Device IRQ */
  42904. +
  42905. +
  42906. + u32 ier; /* cached registers */
  42907. +
  42908. + struct mmc_request *mrq; /* Current request */
  42909. + struct mmc_command *cmd; /* Current command */
  42910. + struct mmc_data *data; /* Current data request */
  42911. + unsigned int data_early:1; /* Data finished before cmd */
  42912. +
  42913. + wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
  42914. +
  42915. + u32 thread_isr;
  42916. +
  42917. + u32 shadow;
  42918. +
  42919. + /*DMA part*/
  42920. + struct dma_chan *dma_chan_rx; /* DMA channel for reads */
  42921. + struct dma_chan *dma_chan_tx; /* DMA channel for writes */
  42922. + struct dma_async_tx_descriptor *tx_desc; /* descriptor */
  42923. +
  42924. + bool have_dma;
  42925. + bool use_dma;
  42926. + /*end of DMA part*/
  42927. +
  42928. + int max_delay; /* maximum length of time spent waiting */
  42929. +
  42930. + int flags; /* Host attributes */
  42931. +#define SDHCI_USE_SDMA (1<<0) /* Host is SDMA capable */
  42932. +#define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */
  42933. +#define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */
  42934. +#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
  42935. +#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
  42936. +#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
  42937. +#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
  42938. +#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  42939. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  42940. +};
  42941. +
  42942. +
  42943. +static inline void bcm2835_mmc_writel(struct bcm2835_host *host, u32 val, int reg)
  42944. +{
  42945. + writel(val, host->ioaddr + reg);
  42946. + udelay(BCM2835_SDHCI_WRITE_DELAY(max(host->clock, MIN_FREQ)));
  42947. +}
  42948. +
  42949. +static inline void mmc_raw_writel(struct bcm2835_host *host, u32 val, int reg)
  42950. +{
  42951. + writel(val, host->ioaddr + reg);
  42952. +}
  42953. +
  42954. +static inline u32 bcm2835_mmc_readl(struct bcm2835_host *host, int reg)
  42955. +{
  42956. + return readl(host->ioaddr + reg);
  42957. +}
  42958. +
  42959. +static inline void bcm2835_mmc_writew(struct bcm2835_host *host, u16 val, int reg)
  42960. +{
  42961. + u32 oldval = (reg == SDHCI_COMMAND) ? host->shadow :
  42962. + bcm2835_mmc_readl(host, reg & ~3);
  42963. + u32 word_num = (reg >> 1) & 1;
  42964. + u32 word_shift = word_num * 16;
  42965. + u32 mask = 0xffff << word_shift;
  42966. + u32 newval = (oldval & ~mask) | (val << word_shift);
  42967. +
  42968. + if (reg == SDHCI_TRANSFER_MODE)
  42969. + host->shadow = newval;
  42970. + else
  42971. + bcm2835_mmc_writel(host, newval, reg & ~3);
  42972. +
  42973. +}
  42974. +
  42975. +static inline void bcm2835_mmc_writeb(struct bcm2835_host *host, u8 val, int reg)
  42976. +{
  42977. + u32 oldval = bcm2835_mmc_readl(host, reg & ~3);
  42978. + u32 byte_num = reg & 3;
  42979. + u32 byte_shift = byte_num * 8;
  42980. + u32 mask = 0xff << byte_shift;
  42981. + u32 newval = (oldval & ~mask) | (val << byte_shift);
  42982. +
  42983. + bcm2835_mmc_writel(host, newval, reg & ~3);
  42984. +}
  42985. +
  42986. +
  42987. +static inline u16 bcm2835_mmc_readw(struct bcm2835_host *host, int reg)
  42988. +{
  42989. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  42990. + u32 word_num = (reg >> 1) & 1;
  42991. + u32 word_shift = word_num * 16;
  42992. + u32 word = (val >> word_shift) & 0xffff;
  42993. +
  42994. + return word;
  42995. +}
  42996. +
  42997. +static inline u8 bcm2835_mmc_readb(struct bcm2835_host *host, int reg)
  42998. +{
  42999. + u32 val = bcm2835_mmc_readl(host, (reg & ~3));
  43000. + u32 byte_num = reg & 3;
  43001. + u32 byte_shift = byte_num * 8;
  43002. + u32 byte = (val >> byte_shift) & 0xff;
  43003. +
  43004. + return byte;
  43005. +}
  43006. +
  43007. +static void bcm2835_mmc_unsignal_irqs(struct bcm2835_host *host, u32 clear)
  43008. +{
  43009. + u32 ier;
  43010. +
  43011. + ier = bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE);
  43012. + ier &= ~clear;
  43013. + /* change which requests generate IRQs - makes no difference to
  43014. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  43015. + bcm2835_mmc_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  43016. +}
  43017. +
  43018. +
  43019. +static void bcm2835_mmc_dumpregs(struct bcm2835_host *host)
  43020. +{
  43021. + pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
  43022. + mmc_hostname(host->mmc));
  43023. +
  43024. + pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
  43025. + bcm2835_mmc_readl(host, SDHCI_DMA_ADDRESS),
  43026. + bcm2835_mmc_readw(host, SDHCI_HOST_VERSION));
  43027. + pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
  43028. + bcm2835_mmc_readw(host, SDHCI_BLOCK_SIZE),
  43029. + bcm2835_mmc_readw(host, SDHCI_BLOCK_COUNT));
  43030. + pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
  43031. + bcm2835_mmc_readl(host, SDHCI_ARGUMENT),
  43032. + bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE));
  43033. + pr_debug(DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
  43034. + bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE),
  43035. + bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL));
  43036. + pr_debug(DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
  43037. + bcm2835_mmc_readb(host, SDHCI_POWER_CONTROL),
  43038. + bcm2835_mmc_readb(host, SDHCI_BLOCK_GAP_CONTROL));
  43039. + pr_debug(DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
  43040. + bcm2835_mmc_readb(host, SDHCI_WAKE_UP_CONTROL),
  43041. + bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL));
  43042. + pr_debug(DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
  43043. + bcm2835_mmc_readb(host, SDHCI_TIMEOUT_CONTROL),
  43044. + bcm2835_mmc_readl(host, SDHCI_INT_STATUS));
  43045. + pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
  43046. + bcm2835_mmc_readl(host, SDHCI_INT_ENABLE),
  43047. + bcm2835_mmc_readl(host, SDHCI_SIGNAL_ENABLE));
  43048. + pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
  43049. + bcm2835_mmc_readw(host, SDHCI_ACMD12_ERR),
  43050. + bcm2835_mmc_readw(host, SDHCI_SLOT_INT_STATUS));
  43051. + pr_debug(DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n",
  43052. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES),
  43053. + bcm2835_mmc_readl(host, SDHCI_CAPABILITIES_1));
  43054. + pr_debug(DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n",
  43055. + bcm2835_mmc_readw(host, SDHCI_COMMAND),
  43056. + bcm2835_mmc_readl(host, SDHCI_MAX_CURRENT));
  43057. + pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
  43058. + bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2));
  43059. +
  43060. + pr_debug(DRIVER_NAME ": ===========================================\n");
  43061. +}
  43062. +
  43063. +
  43064. +static void bcm2835_mmc_reset(struct bcm2835_host *host, u8 mask)
  43065. +{
  43066. + unsigned long timeout;
  43067. +
  43068. + bcm2835_mmc_writeb(host, mask, SDHCI_SOFTWARE_RESET);
  43069. +
  43070. + if (mask & SDHCI_RESET_ALL)
  43071. + host->clock = 0;
  43072. +
  43073. + /* Wait max 100 ms */
  43074. + timeout = 100;
  43075. +
  43076. + /* hw clears the bit when it's done */
  43077. + while (bcm2835_mmc_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
  43078. + if (timeout == 0) {
  43079. + pr_err("%s: Reset 0x%x never completed.\n",
  43080. + mmc_hostname(host->mmc), (int)mask);
  43081. + bcm2835_mmc_dumpregs(host);
  43082. + return;
  43083. + }
  43084. + timeout--;
  43085. + mdelay(1);
  43086. + }
  43087. +
  43088. + if (100-timeout > 10 && 100-timeout > host->max_delay) {
  43089. + host->max_delay = 100-timeout;
  43090. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  43091. + }
  43092. +}
  43093. +
  43094. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios);
  43095. +
  43096. +static void bcm2835_mmc_init(struct bcm2835_host *host, int soft)
  43097. +{
  43098. + if (soft)
  43099. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD|SDHCI_RESET_DATA);
  43100. + else
  43101. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  43102. +
  43103. + host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
  43104. + SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT |
  43105. + SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC |
  43106. + SDHCI_INT_TIMEOUT | SDHCI_INT_DATA_END |
  43107. + SDHCI_INT_RESPONSE;
  43108. +
  43109. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  43110. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  43111. +
  43112. + if (soft) {
  43113. + /* force clock reconfiguration */
  43114. + host->clock = 0;
  43115. + bcm2835_mmc_set_ios(host->mmc, &host->mmc->ios);
  43116. + }
  43117. +}
  43118. +
  43119. +
  43120. +
  43121. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host);
  43122. +
  43123. +static void bcm2835_mmc_dma_complete(void *param)
  43124. +{
  43125. + struct bcm2835_host *host = param;
  43126. + struct dma_chan *dma_chan;
  43127. + unsigned long flags;
  43128. + u32 dir_data;
  43129. +
  43130. + spin_lock_irqsave(&host->lock, flags);
  43131. +
  43132. + if (host->data && !(host->data->flags & MMC_DATA_WRITE)) {
  43133. + /* otherwise handled in SDHCI IRQ */
  43134. + dma_chan = host->dma_chan_rx;
  43135. + dir_data = DMA_FROM_DEVICE;
  43136. +
  43137. + dma_unmap_sg(dma_chan->device->dev,
  43138. + host->data->sg, host->data->sg_len,
  43139. + dir_data);
  43140. +
  43141. + bcm2835_mmc_finish_data(host);
  43142. + }
  43143. +
  43144. + spin_unlock_irqrestore(&host->lock, flags);
  43145. +}
  43146. +
  43147. +static void bcm2835_bcm2835_mmc_read_block_pio(struct bcm2835_host *host)
  43148. +{
  43149. + unsigned long flags;
  43150. + size_t blksize, len, chunk;
  43151. +
  43152. + u32 uninitialized_var(scratch);
  43153. + u8 *buf;
  43154. +
  43155. + blksize = host->data->blksz;
  43156. + chunk = 0;
  43157. +
  43158. + local_irq_save(flags);
  43159. +
  43160. + while (blksize) {
  43161. + if (!sg_miter_next(&host->sg_miter))
  43162. + BUG();
  43163. +
  43164. + len = min(host->sg_miter.length, blksize);
  43165. +
  43166. + blksize -= len;
  43167. + host->sg_miter.consumed = len;
  43168. +
  43169. + buf = host->sg_miter.addr;
  43170. +
  43171. + while (len) {
  43172. + if (chunk == 0) {
  43173. + scratch = bcm2835_mmc_readl(host, SDHCI_BUFFER);
  43174. + chunk = 4;
  43175. + }
  43176. +
  43177. + *buf = scratch & 0xFF;
  43178. +
  43179. + buf++;
  43180. + scratch >>= 8;
  43181. + chunk--;
  43182. + len--;
  43183. + }
  43184. + }
  43185. +
  43186. + sg_miter_stop(&host->sg_miter);
  43187. +
  43188. + local_irq_restore(flags);
  43189. +}
  43190. +
  43191. +static void bcm2835_bcm2835_mmc_write_block_pio(struct bcm2835_host *host)
  43192. +{
  43193. + unsigned long flags;
  43194. + size_t blksize, len, chunk;
  43195. + u32 scratch;
  43196. + u8 *buf;
  43197. +
  43198. + blksize = host->data->blksz;
  43199. + chunk = 0;
  43200. + chunk = 0;
  43201. + scratch = 0;
  43202. +
  43203. + local_irq_save(flags);
  43204. +
  43205. + while (blksize) {
  43206. + if (!sg_miter_next(&host->sg_miter))
  43207. + BUG();
  43208. +
  43209. + len = min(host->sg_miter.length, blksize);
  43210. +
  43211. + blksize -= len;
  43212. + host->sg_miter.consumed = len;
  43213. +
  43214. + buf = host->sg_miter.addr;
  43215. +
  43216. + while (len) {
  43217. + scratch |= (u32)*buf << (chunk * 8);
  43218. +
  43219. + buf++;
  43220. + chunk++;
  43221. + len--;
  43222. +
  43223. + if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
  43224. + mmc_raw_writel(host, scratch, SDHCI_BUFFER);
  43225. + chunk = 0;
  43226. + scratch = 0;
  43227. + }
  43228. + }
  43229. + }
  43230. +
  43231. + sg_miter_stop(&host->sg_miter);
  43232. +
  43233. + local_irq_restore(flags);
  43234. +}
  43235. +
  43236. +
  43237. +static void bcm2835_mmc_transfer_pio(struct bcm2835_host *host)
  43238. +{
  43239. + u32 mask;
  43240. +
  43241. + BUG_ON(!host->data);
  43242. +
  43243. + if (host->blocks == 0)
  43244. + return;
  43245. +
  43246. + if (host->data->flags & MMC_DATA_READ)
  43247. + mask = SDHCI_DATA_AVAILABLE;
  43248. + else
  43249. + mask = SDHCI_SPACE_AVAILABLE;
  43250. +
  43251. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  43252. +
  43253. + if (host->data->flags & MMC_DATA_READ)
  43254. + bcm2835_bcm2835_mmc_read_block_pio(host);
  43255. + else
  43256. + bcm2835_bcm2835_mmc_write_block_pio(host);
  43257. +
  43258. + host->blocks--;
  43259. +
  43260. + /* QUIRK used in sdhci.c removes the 'if' */
  43261. + /* but it seems this is unnecessary */
  43262. + if (host->blocks == 0)
  43263. + break;
  43264. +
  43265. +
  43266. + }
  43267. +}
  43268. +
  43269. +
  43270. +static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
  43271. +{
  43272. + u32 len, dir_data, dir_slave;
  43273. + struct dma_async_tx_descriptor *desc = NULL;
  43274. + struct dma_chan *dma_chan;
  43275. +
  43276. +
  43277. + WARN_ON(!host->data);
  43278. +
  43279. + if (!host->data)
  43280. + return;
  43281. +
  43282. + if (host->blocks == 0)
  43283. + return;
  43284. +
  43285. + if (host->data->flags & MMC_DATA_READ) {
  43286. + dma_chan = host->dma_chan_rx;
  43287. + dir_data = DMA_FROM_DEVICE;
  43288. + dir_slave = DMA_DEV_TO_MEM;
  43289. + } else {
  43290. + dma_chan = host->dma_chan_tx;
  43291. + dir_data = DMA_TO_DEVICE;
  43292. + dir_slave = DMA_MEM_TO_DEV;
  43293. + }
  43294. +
  43295. + BUG_ON(!dma_chan->device);
  43296. + BUG_ON(!dma_chan->device->dev);
  43297. + BUG_ON(!host->data->sg);
  43298. +
  43299. + len = dma_map_sg(dma_chan->device->dev, host->data->sg,
  43300. + host->data->sg_len, dir_data);
  43301. + if (len > 0) {
  43302. + desc = dmaengine_prep_slave_sg(dma_chan, host->data->sg,
  43303. + len, dir_slave,
  43304. + DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  43305. + } else {
  43306. + dev_err(mmc_dev(host->mmc), "dma_map_sg returned zero length\n");
  43307. + }
  43308. + if (desc) {
  43309. + bcm2835_mmc_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  43310. + SDHCI_INT_SPACE_AVAIL);
  43311. + host->tx_desc = desc;
  43312. + desc->callback = bcm2835_mmc_dma_complete;
  43313. + desc->callback_param = host;
  43314. + dmaengine_submit(desc);
  43315. + dma_async_issue_pending(dma_chan);
  43316. + }
  43317. +
  43318. +}
  43319. +
  43320. +
  43321. +
  43322. +static void bcm2835_mmc_set_transfer_irqs(struct bcm2835_host *host)
  43323. +{
  43324. + u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  43325. + u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  43326. +
  43327. + if (host->use_dma)
  43328. + host->ier = (host->ier & ~pio_irqs) | dma_irqs;
  43329. + else
  43330. + host->ier = (host->ier & ~dma_irqs) | pio_irqs;
  43331. +
  43332. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  43333. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  43334. +}
  43335. +
  43336. +
  43337. +static void bcm2835_mmc_prepare_data(struct bcm2835_host *host, struct mmc_command *cmd)
  43338. +{
  43339. + u8 count;
  43340. + struct mmc_data *data = cmd->data;
  43341. +
  43342. + WARN_ON(host->data);
  43343. +
  43344. + if (data || (cmd->flags & MMC_RSP_BUSY)) {
  43345. + count = TIMEOUT_VAL;
  43346. + bcm2835_mmc_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
  43347. + }
  43348. +
  43349. + if (!data)
  43350. + return;
  43351. +
  43352. + /* Sanity checks */
  43353. + BUG_ON(data->blksz * data->blocks > 524288);
  43354. + BUG_ON(data->blksz > host->mmc->max_blk_size);
  43355. + BUG_ON(data->blocks > 65535);
  43356. +
  43357. + host->data = data;
  43358. + host->data_early = 0;
  43359. + host->data->bytes_xfered = 0;
  43360. +
  43361. +
  43362. + if (!(host->flags & SDHCI_REQ_USE_DMA)) {
  43363. + int flags;
  43364. +
  43365. + flags = SG_MITER_ATOMIC;
  43366. + if (host->data->flags & MMC_DATA_READ)
  43367. + flags |= SG_MITER_TO_SG;
  43368. + else
  43369. + flags |= SG_MITER_FROM_SG;
  43370. + sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  43371. + host->blocks = data->blocks;
  43372. + }
  43373. +
  43374. + host->use_dma = host->have_dma && data->blocks > PIO_DMA_BARRIER;
  43375. +
  43376. + bcm2835_mmc_set_transfer_irqs(host);
  43377. +
  43378. + /* Set the DMA boundary value and block size */
  43379. + bcm2835_mmc_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
  43380. + data->blksz), SDHCI_BLOCK_SIZE);
  43381. + bcm2835_mmc_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
  43382. +
  43383. + BUG_ON(!host->data);
  43384. +}
  43385. +
  43386. +static void bcm2835_mmc_set_transfer_mode(struct bcm2835_host *host,
  43387. + struct mmc_command *cmd)
  43388. +{
  43389. + u16 mode;
  43390. + struct mmc_data *data = cmd->data;
  43391. +
  43392. + if (data == NULL) {
  43393. + /* clear Auto CMD settings for no data CMDs */
  43394. + mode = bcm2835_mmc_readw(host, SDHCI_TRANSFER_MODE);
  43395. + bcm2835_mmc_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 |
  43396. + SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE);
  43397. + return;
  43398. + }
  43399. +
  43400. + WARN_ON(!host->data);
  43401. +
  43402. + mode = SDHCI_TRNS_BLK_CNT_EN;
  43403. +
  43404. + if ((mmc_op_multi(cmd->opcode) || data->blocks > 1)) {
  43405. + mode |= SDHCI_TRNS_MULTI;
  43406. +
  43407. + /*
  43408. + * If we are sending CMD23, CMD12 never gets sent
  43409. + * on successful completion (so no Auto-CMD12).
  43410. + */
  43411. + if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12))
  43412. + mode |= SDHCI_TRNS_AUTO_CMD12;
  43413. + else if (host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
  43414. + mode |= SDHCI_TRNS_AUTO_CMD23;
  43415. + bcm2835_mmc_writel(host, host->mrq->sbc->arg, SDHCI_ARGUMENT2);
  43416. + }
  43417. + }
  43418. +
  43419. + if (data->flags & MMC_DATA_READ)
  43420. + mode |= SDHCI_TRNS_READ;
  43421. + if (host->flags & SDHCI_REQ_USE_DMA)
  43422. + mode |= SDHCI_TRNS_DMA;
  43423. +
  43424. + bcm2835_mmc_writew(host, mode, SDHCI_TRANSFER_MODE);
  43425. +}
  43426. +
  43427. +void bcm2835_mmc_send_command(struct bcm2835_host *host, struct mmc_command *cmd)
  43428. +{
  43429. + int flags;
  43430. + u32 mask;
  43431. + unsigned long timeout;
  43432. +
  43433. + WARN_ON(host->cmd);
  43434. +
  43435. + /* Wait max 10 ms */
  43436. + timeout = 1000;
  43437. +
  43438. + mask = SDHCI_CMD_INHIBIT;
  43439. + if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  43440. + mask |= SDHCI_DATA_INHIBIT;
  43441. +
  43442. + /* We shouldn't wait for data inihibit for stop commands, even
  43443. + though they might use busy signaling */
  43444. + if (host->mrq->data && (cmd == host->mrq->data->stop))
  43445. + mask &= ~SDHCI_DATA_INHIBIT;
  43446. +
  43447. + while (bcm2835_mmc_readl(host, SDHCI_PRESENT_STATE) & mask) {
  43448. + if (timeout == 0) {
  43449. + pr_err("%s: Controller never released inhibit bit(s).\n",
  43450. + mmc_hostname(host->mmc));
  43451. + bcm2835_mmc_dumpregs(host);
  43452. + cmd->error = -EIO;
  43453. + tasklet_schedule(&host->finish_tasklet);
  43454. + return;
  43455. + }
  43456. + timeout--;
  43457. + udelay(10);
  43458. + }
  43459. +
  43460. + if ((1000-timeout)/100 > 1 && (1000-timeout)/100 > host->max_delay) {
  43461. + host->max_delay = (1000-timeout)/100;
  43462. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  43463. + }
  43464. +
  43465. + timeout = jiffies;
  43466. +#ifdef CONFIG_OF
  43467. + if (!cmd->data && cmd->busy_timeout > 9000)
  43468. + timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
  43469. + else
  43470. +#endif
  43471. + timeout += 10 * HZ;
  43472. + mod_timer(&host->timer, timeout);
  43473. +
  43474. + host->cmd = cmd;
  43475. +
  43476. + bcm2835_mmc_prepare_data(host, cmd);
  43477. +
  43478. + bcm2835_mmc_writel(host, cmd->arg, SDHCI_ARGUMENT);
  43479. +
  43480. + bcm2835_mmc_set_transfer_mode(host, cmd);
  43481. +
  43482. + if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
  43483. + pr_err("%s: Unsupported response type!\n",
  43484. + mmc_hostname(host->mmc));
  43485. + cmd->error = -EINVAL;
  43486. + tasklet_schedule(&host->finish_tasklet);
  43487. + return;
  43488. + }
  43489. +
  43490. + if (!(cmd->flags & MMC_RSP_PRESENT))
  43491. + flags = SDHCI_CMD_RESP_NONE;
  43492. + else if (cmd->flags & MMC_RSP_136)
  43493. + flags = SDHCI_CMD_RESP_LONG;
  43494. + else if (cmd->flags & MMC_RSP_BUSY)
  43495. + flags = SDHCI_CMD_RESP_SHORT_BUSY;
  43496. + else
  43497. + flags = SDHCI_CMD_RESP_SHORT;
  43498. +
  43499. + if (cmd->flags & MMC_RSP_CRC)
  43500. + flags |= SDHCI_CMD_CRC;
  43501. + if (cmd->flags & MMC_RSP_OPCODE)
  43502. + flags |= SDHCI_CMD_INDEX;
  43503. +
  43504. + if (cmd->data)
  43505. + flags |= SDHCI_CMD_DATA;
  43506. +
  43507. + bcm2835_mmc_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
  43508. +}
  43509. +
  43510. +
  43511. +static void bcm2835_mmc_finish_data(struct bcm2835_host *host)
  43512. +{
  43513. + struct mmc_data *data;
  43514. +
  43515. + BUG_ON(!host->data);
  43516. +
  43517. + data = host->data;
  43518. + host->data = NULL;
  43519. +
  43520. + if (data->error)
  43521. + data->bytes_xfered = 0;
  43522. + else
  43523. + data->bytes_xfered = data->blksz * data->blocks;
  43524. +
  43525. + /*
  43526. + * Need to send CMD12 if -
  43527. + * a) open-ended multiblock transfer (no CMD23)
  43528. + * b) error in multiblock transfer
  43529. + */
  43530. + if (data->stop &&
  43531. + (data->error ||
  43532. + !host->mrq->sbc)) {
  43533. +
  43534. + /*
  43535. + * The controller needs a reset of internal state machines
  43536. + * upon error conditions.
  43537. + */
  43538. + if (data->error) {
  43539. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  43540. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  43541. + }
  43542. +
  43543. + bcm2835_mmc_send_command(host, data->stop);
  43544. + } else
  43545. + tasklet_schedule(&host->finish_tasklet);
  43546. +}
  43547. +
  43548. +static void bcm2835_mmc_finish_command(struct bcm2835_host *host)
  43549. +{
  43550. + int i;
  43551. +
  43552. + BUG_ON(host->cmd == NULL);
  43553. +
  43554. + if (host->cmd->flags & MMC_RSP_PRESENT) {
  43555. + if (host->cmd->flags & MMC_RSP_136) {
  43556. + /* CRC is stripped so we need to do some shifting. */
  43557. + for (i = 0; i < 4; i++) {
  43558. + host->cmd->resp[i] = bcm2835_mmc_readl(host,
  43559. + SDHCI_RESPONSE + (3-i)*4) << 8;
  43560. + if (i != 3)
  43561. + host->cmd->resp[i] |=
  43562. + bcm2835_mmc_readb(host,
  43563. + SDHCI_RESPONSE + (3-i)*4-1);
  43564. + }
  43565. + } else {
  43566. + host->cmd->resp[0] = bcm2835_mmc_readl(host, SDHCI_RESPONSE);
  43567. + }
  43568. + }
  43569. +
  43570. + host->cmd->error = 0;
  43571. +
  43572. + /* Finished CMD23, now send actual command. */
  43573. + if (host->cmd == host->mrq->sbc) {
  43574. + host->cmd = NULL;
  43575. + bcm2835_mmc_send_command(host, host->mrq->cmd);
  43576. + } else {
  43577. +
  43578. + /* Processed actual command. */
  43579. + if (host->data && host->data_early)
  43580. + bcm2835_mmc_finish_data(host);
  43581. +
  43582. + if (!host->cmd->data)
  43583. + tasklet_schedule(&host->finish_tasklet);
  43584. +
  43585. + host->cmd = NULL;
  43586. + }
  43587. +}
  43588. +
  43589. +
  43590. +static void bcm2835_mmc_timeout_timer(unsigned long data)
  43591. +{
  43592. + struct bcm2835_host *host;
  43593. + unsigned long flags;
  43594. +
  43595. + host = (struct bcm2835_host *)data;
  43596. +
  43597. + spin_lock_irqsave(&host->lock, flags);
  43598. +
  43599. + if (host->mrq) {
  43600. + pr_err("%s: Timeout waiting for hardware interrupt.\n",
  43601. + mmc_hostname(host->mmc));
  43602. + bcm2835_mmc_dumpregs(host);
  43603. +
  43604. + if (host->data) {
  43605. + host->data->error = -ETIMEDOUT;
  43606. + bcm2835_mmc_finish_data(host);
  43607. + } else {
  43608. + if (host->cmd)
  43609. + host->cmd->error = -ETIMEDOUT;
  43610. + else
  43611. + host->mrq->cmd->error = -ETIMEDOUT;
  43612. +
  43613. + tasklet_schedule(&host->finish_tasklet);
  43614. + }
  43615. + }
  43616. +
  43617. + mmiowb();
  43618. + spin_unlock_irqrestore(&host->lock, flags);
  43619. +}
  43620. +
  43621. +
  43622. +static void bcm2835_mmc_enable_sdio_irq_nolock(struct bcm2835_host *host, int enable)
  43623. +{
  43624. + if (!(host->flags & SDHCI_DEVICE_DEAD)) {
  43625. + if (enable)
  43626. + host->ier |= SDHCI_INT_CARD_INT;
  43627. + else
  43628. + host->ier &= ~SDHCI_INT_CARD_INT;
  43629. +
  43630. + bcm2835_mmc_writel(host, host->ier, SDHCI_INT_ENABLE);
  43631. + bcm2835_mmc_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  43632. + mmiowb();
  43633. + }
  43634. +}
  43635. +
  43636. +static void bcm2835_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
  43637. +{
  43638. + struct bcm2835_host *host = mmc_priv(mmc);
  43639. + unsigned long flags;
  43640. +
  43641. + spin_lock_irqsave(&host->lock, flags);
  43642. + if (enable)
  43643. + host->flags |= SDHCI_SDIO_IRQ_ENABLED;
  43644. + else
  43645. + host->flags &= ~SDHCI_SDIO_IRQ_ENABLED;
  43646. +
  43647. + bcm2835_mmc_enable_sdio_irq_nolock(host, enable);
  43648. + spin_unlock_irqrestore(&host->lock, flags);
  43649. +}
  43650. +
  43651. +static void bcm2835_mmc_cmd_irq(struct bcm2835_host *host, u32 intmask)
  43652. +{
  43653. +
  43654. + BUG_ON(intmask == 0);
  43655. +
  43656. + if (!host->cmd) {
  43657. + pr_err("%s: Got command interrupt 0x%08x even "
  43658. + "though no command operation was in progress.\n",
  43659. + mmc_hostname(host->mmc), (unsigned)intmask);
  43660. + bcm2835_mmc_dumpregs(host);
  43661. + return;
  43662. + }
  43663. +
  43664. + if (intmask & SDHCI_INT_TIMEOUT)
  43665. + host->cmd->error = -ETIMEDOUT;
  43666. + else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
  43667. + SDHCI_INT_INDEX)) {
  43668. + host->cmd->error = -EILSEQ;
  43669. + }
  43670. +
  43671. + if (host->cmd->error) {
  43672. + tasklet_schedule(&host->finish_tasklet);
  43673. + return;
  43674. + }
  43675. +
  43676. + if (intmask & SDHCI_INT_RESPONSE)
  43677. + bcm2835_mmc_finish_command(host);
  43678. +
  43679. +}
  43680. +
  43681. +static void bcm2835_mmc_data_irq(struct bcm2835_host *host, u32 intmask)
  43682. +{
  43683. + struct dma_chan *dma_chan;
  43684. + u32 dir_data;
  43685. +
  43686. + BUG_ON(intmask == 0);
  43687. +
  43688. + if (!host->data) {
  43689. + /*
  43690. + * The "data complete" interrupt is also used to
  43691. + * indicate that a busy state has ended. See comment
  43692. + * above in sdhci_cmd_irq().
  43693. + */
  43694. + if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
  43695. + if (intmask & SDHCI_INT_DATA_END) {
  43696. + bcm2835_mmc_finish_command(host);
  43697. + return;
  43698. + }
  43699. + }
  43700. +
  43701. + pr_debug("%s: Got data interrupt 0x%08x even "
  43702. + "though no data operation was in progress.\n",
  43703. + mmc_hostname(host->mmc), (unsigned)intmask);
  43704. + bcm2835_mmc_dumpregs(host);
  43705. +
  43706. + return;
  43707. + }
  43708. +
  43709. + if (intmask & SDHCI_INT_DATA_TIMEOUT)
  43710. + host->data->error = -ETIMEDOUT;
  43711. + else if (intmask & SDHCI_INT_DATA_END_BIT)
  43712. + host->data->error = -EILSEQ;
  43713. + else if ((intmask & SDHCI_INT_DATA_CRC) &&
  43714. + SDHCI_GET_CMD(bcm2835_mmc_readw(host, SDHCI_COMMAND))
  43715. + != MMC_BUS_TEST_R)
  43716. + host->data->error = -EILSEQ;
  43717. +
  43718. + if (host->use_dma) {
  43719. + if (host->data->flags & MMC_DATA_WRITE) {
  43720. + /* IRQ handled here */
  43721. +
  43722. + dma_chan = host->dma_chan_tx;
  43723. + dir_data = DMA_TO_DEVICE;
  43724. + dma_unmap_sg(dma_chan->device->dev,
  43725. + host->data->sg, host->data->sg_len,
  43726. + dir_data);
  43727. +
  43728. + bcm2835_mmc_finish_data(host);
  43729. + }
  43730. +
  43731. + } else {
  43732. + if (host->data->error)
  43733. + bcm2835_mmc_finish_data(host);
  43734. + else {
  43735. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  43736. + bcm2835_mmc_transfer_pio(host);
  43737. +
  43738. + if (intmask & SDHCI_INT_DATA_END) {
  43739. + if (host->cmd) {
  43740. + /*
  43741. + * Data managed to finish before the
  43742. + * command completed. Make sure we do
  43743. + * things in the proper order.
  43744. + */
  43745. + host->data_early = 1;
  43746. + } else {
  43747. + bcm2835_mmc_finish_data(host);
  43748. + }
  43749. + }
  43750. + }
  43751. + }
  43752. +}
  43753. +
  43754. +
  43755. +static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
  43756. +{
  43757. + irqreturn_t result = IRQ_NONE;
  43758. + struct bcm2835_host *host = dev_id;
  43759. + u32 intmask, mask, unexpected = 0;
  43760. + int max_loops = 16;
  43761. +#ifndef CONFIG_OF
  43762. + int cardint = 0;
  43763. +#endif
  43764. +
  43765. + spin_lock(&host->lock);
  43766. +
  43767. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  43768. +
  43769. + if (!intmask || intmask == 0xffffffff) {
  43770. + result = IRQ_NONE;
  43771. + goto out;
  43772. + }
  43773. +
  43774. + do {
  43775. + /* Clear selected interrupts. */
  43776. + mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  43777. + SDHCI_INT_BUS_POWER);
  43778. + bcm2835_mmc_writel(host, mask, SDHCI_INT_STATUS);
  43779. +
  43780. +
  43781. + if (intmask & SDHCI_INT_CMD_MASK)
  43782. + bcm2835_mmc_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
  43783. +
  43784. + if (intmask & SDHCI_INT_DATA_MASK)
  43785. + bcm2835_mmc_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
  43786. +
  43787. + if (intmask & SDHCI_INT_BUS_POWER)
  43788. + pr_err("%s: Card is consuming too much power!\n",
  43789. + mmc_hostname(host->mmc));
  43790. +
  43791. + if (intmask & SDHCI_INT_CARD_INT) {
  43792. +#ifndef CONFIG_OF
  43793. + cardint = 1;
  43794. +#else
  43795. + bcm2835_mmc_enable_sdio_irq_nolock(host, false);
  43796. + host->thread_isr |= SDHCI_INT_CARD_INT;
  43797. + result = IRQ_WAKE_THREAD;
  43798. +#endif
  43799. + }
  43800. +
  43801. + intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
  43802. + SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
  43803. + SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER |
  43804. + SDHCI_INT_CARD_INT);
  43805. +
  43806. + if (intmask) {
  43807. + unexpected |= intmask;
  43808. + bcm2835_mmc_writel(host, intmask, SDHCI_INT_STATUS);
  43809. + }
  43810. +
  43811. + if (result == IRQ_NONE)
  43812. + result = IRQ_HANDLED;
  43813. +
  43814. + intmask = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  43815. + } while (intmask && --max_loops);
  43816. +out:
  43817. + spin_unlock(&host->lock);
  43818. +
  43819. + if (unexpected) {
  43820. + pr_err("%s: Unexpected interrupt 0x%08x.\n",
  43821. + mmc_hostname(host->mmc), unexpected);
  43822. + bcm2835_mmc_dumpregs(host);
  43823. + }
  43824. +
  43825. +#ifndef CONFIG_OF
  43826. + if (cardint)
  43827. + mmc_signal_sdio_irq(host->mmc);
  43828. +#endif
  43829. +
  43830. + return result;
  43831. +}
  43832. +
  43833. +#ifdef CONFIG_OF
  43834. +static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
  43835. +{
  43836. + struct bcm2835_host *host = dev_id;
  43837. + unsigned long flags;
  43838. + u32 isr;
  43839. +
  43840. + spin_lock_irqsave(&host->lock, flags);
  43841. + isr = host->thread_isr;
  43842. + host->thread_isr = 0;
  43843. + spin_unlock_irqrestore(&host->lock, flags);
  43844. +
  43845. + if (isr & SDHCI_INT_CARD_INT) {
  43846. + sdio_run_irqs(host->mmc);
  43847. +
  43848. + spin_lock_irqsave(&host->lock, flags);
  43849. + if (host->flags & SDHCI_SDIO_IRQ_ENABLED)
  43850. + bcm2835_mmc_enable_sdio_irq_nolock(host, true);
  43851. + spin_unlock_irqrestore(&host->lock, flags);
  43852. + }
  43853. +
  43854. + return isr ? IRQ_HANDLED : IRQ_NONE;
  43855. +}
  43856. +#endif
  43857. +
  43858. +
  43859. +
  43860. +void bcm2835_mmc_set_clock(struct bcm2835_host *host, unsigned int clock)
  43861. +{
  43862. + int div = 0; /* Initialized for compiler warning */
  43863. + int real_div = div, clk_mul = 1;
  43864. + u16 clk = 0;
  43865. + unsigned long timeout;
  43866. +
  43867. +
  43868. + host->mmc->actual_clock = 0;
  43869. +
  43870. + bcm2835_mmc_writew(host, 0, SDHCI_CLOCK_CONTROL);
  43871. +
  43872. + if (clock == 0)
  43873. + return;
  43874. +
  43875. + /* Version 3.00 divisors must be a multiple of 2. */
  43876. + if (host->max_clk <= clock)
  43877. + div = 1;
  43878. + else {
  43879. + for (div = 2; div < SDHCI_MAX_DIV_SPEC_300;
  43880. + div += 2) {
  43881. + if ((host->max_clk / div) <= clock)
  43882. + break;
  43883. + }
  43884. + }
  43885. +
  43886. + real_div = div;
  43887. + div >>= 1;
  43888. +
  43889. + if (real_div)
  43890. + host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div;
  43891. +
  43892. + clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
  43893. + clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
  43894. + << SDHCI_DIVIDER_HI_SHIFT;
  43895. + clk |= SDHCI_CLOCK_INT_EN;
  43896. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  43897. +
  43898. + /* Wait max 20 ms */
  43899. + timeout = 20;
  43900. + while (!((clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL))
  43901. + & SDHCI_CLOCK_INT_STABLE)) {
  43902. + if (timeout == 0) {
  43903. + pr_err("%s: Internal clock never "
  43904. + "stabilised.\n", mmc_hostname(host->mmc));
  43905. + bcm2835_mmc_dumpregs(host);
  43906. + return;
  43907. + }
  43908. + timeout--;
  43909. + mdelay(1);
  43910. + }
  43911. +
  43912. + if (20-timeout > 10 && 20-timeout > host->max_delay) {
  43913. + host->max_delay = 20-timeout;
  43914. + pr_warning("Warning: MMC controller hung for %d ms\n", host->max_delay);
  43915. + }
  43916. +
  43917. + clk |= SDHCI_CLOCK_CARD_EN;
  43918. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  43919. +}
  43920. +
  43921. +static void bcm2835_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
  43922. +{
  43923. + struct bcm2835_host *host;
  43924. + unsigned long flags;
  43925. +
  43926. + host = mmc_priv(mmc);
  43927. +
  43928. + spin_lock_irqsave(&host->lock, flags);
  43929. +
  43930. + WARN_ON(host->mrq != NULL);
  43931. +
  43932. + host->mrq = mrq;
  43933. + bcm2835_mmc_send_command(host, mrq->cmd);
  43934. + mmiowb();
  43935. + spin_unlock_irqrestore(&host->lock, flags);
  43936. +
  43937. + if (mrq->cmd->data && host->use_dma) {
  43938. + /* DMA transfer starts now, PIO starts after interrupt */
  43939. + bcm2835_mmc_transfer_dma(host);
  43940. + }
  43941. +}
  43942. +
  43943. +
  43944. +static void bcm2835_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  43945. +{
  43946. +
  43947. + struct bcm2835_host *host = mmc_priv(mmc);
  43948. + unsigned long flags;
  43949. + u8 ctrl;
  43950. + u16 clk, ctrl_2;
  43951. +
  43952. +
  43953. + spin_lock_irqsave(&host->lock, flags);
  43954. +
  43955. + if (!ios->clock || ios->clock != host->clock) {
  43956. + bcm2835_mmc_set_clock(host, ios->clock);
  43957. + host->clock = ios->clock;
  43958. + }
  43959. +
  43960. + if (host->pwr != SDHCI_POWER_330) {
  43961. + host->pwr = SDHCI_POWER_330;
  43962. + bcm2835_mmc_writeb(host, SDHCI_POWER_330 | SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
  43963. + }
  43964. +
  43965. + ctrl = bcm2835_mmc_readb(host, SDHCI_HOST_CONTROL);
  43966. +
  43967. + /* set bus width */
  43968. + ctrl &= ~SDHCI_CTRL_8BITBUS;
  43969. + if (ios->bus_width == MMC_BUS_WIDTH_4)
  43970. + ctrl |= SDHCI_CTRL_4BITBUS;
  43971. + else
  43972. + ctrl &= ~SDHCI_CTRL_4BITBUS;
  43973. +
  43974. + ctrl &= ~SDHCI_CTRL_HISPD; /* NO_HISPD_BIT */
  43975. +
  43976. +
  43977. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  43978. + /*
  43979. + * We only need to set Driver Strength if the
  43980. + * preset value enable is not set.
  43981. + */
  43982. + ctrl_2 = bcm2835_mmc_readw(host, SDHCI_HOST_CONTROL2);
  43983. + ctrl_2 &= ~SDHCI_CTRL_DRV_TYPE_MASK;
  43984. + if (ios->drv_type == MMC_SET_DRIVER_TYPE_A)
  43985. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_A;
  43986. + else if (ios->drv_type == MMC_SET_DRIVER_TYPE_C)
  43987. + ctrl_2 |= SDHCI_CTRL_DRV_TYPE_C;
  43988. +
  43989. + bcm2835_mmc_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
  43990. +
  43991. + /* Reset SD Clock Enable */
  43992. + clk = bcm2835_mmc_readw(host, SDHCI_CLOCK_CONTROL);
  43993. + clk &= ~SDHCI_CLOCK_CARD_EN;
  43994. + bcm2835_mmc_writew(host, clk, SDHCI_CLOCK_CONTROL);
  43995. +
  43996. + /* Re-enable SD Clock */
  43997. + bcm2835_mmc_set_clock(host, host->clock);
  43998. + bcm2835_mmc_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  43999. +
  44000. + mmiowb();
  44001. +
  44002. + spin_unlock_irqrestore(&host->lock, flags);
  44003. +}
  44004. +
  44005. +
  44006. +static struct mmc_host_ops bcm2835_ops = {
  44007. + .request = bcm2835_mmc_request,
  44008. + .set_ios = bcm2835_mmc_set_ios,
  44009. + .enable_sdio_irq = bcm2835_mmc_enable_sdio_irq,
  44010. +};
  44011. +
  44012. +
  44013. +static void bcm2835_mmc_tasklet_finish(unsigned long param)
  44014. +{
  44015. + struct bcm2835_host *host;
  44016. + unsigned long flags;
  44017. + struct mmc_request *mrq;
  44018. +
  44019. + host = (struct bcm2835_host *)param;
  44020. +
  44021. + spin_lock_irqsave(&host->lock, flags);
  44022. +
  44023. + /*
  44024. + * If this tasklet gets rescheduled while running, it will
  44025. + * be run again afterwards but without any active request.
  44026. + */
  44027. + if (!host->mrq) {
  44028. + spin_unlock_irqrestore(&host->lock, flags);
  44029. + return;
  44030. + }
  44031. +
  44032. + del_timer(&host->timer);
  44033. +
  44034. + mrq = host->mrq;
  44035. +
  44036. + /*
  44037. + * The controller needs a reset of internal state machines
  44038. + * upon error conditions.
  44039. + */
  44040. + if (!(host->flags & SDHCI_DEVICE_DEAD) &&
  44041. + ((mrq->cmd && mrq->cmd->error) ||
  44042. + (mrq->data && (mrq->data->error ||
  44043. + (mrq->data->stop && mrq->data->stop->error))))) {
  44044. +
  44045. + bcm2835_mmc_reset(host, SDHCI_RESET_CMD);
  44046. + bcm2835_mmc_reset(host, SDHCI_RESET_DATA);
  44047. + }
  44048. +
  44049. + host->mrq = NULL;
  44050. + host->cmd = NULL;
  44051. + host->data = NULL;
  44052. +
  44053. + mmiowb();
  44054. +
  44055. + spin_unlock_irqrestore(&host->lock, flags);
  44056. + mmc_request_done(host->mmc, mrq);
  44057. +}
  44058. +
  44059. +
  44060. +
  44061. +int bcm2835_mmc_add_host(struct bcm2835_host *host)
  44062. +{
  44063. + struct mmc_host *mmc;
  44064. +#ifndef FORCE_PIO
  44065. + struct dma_slave_config cfg;
  44066. +#endif
  44067. + int ret;
  44068. +
  44069. + mmc = host->mmc;
  44070. +
  44071. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  44072. +
  44073. + host->clk_mul = 0;
  44074. +
  44075. + mmc->ops = &bcm2835_ops;
  44076. + mmc->f_max = host->max_clk;
  44077. + mmc->f_max = host->max_clk;
  44078. + mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300;
  44079. +
  44080. + /* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
  44081. + host->timeout_clk = mmc->f_max / 1000;
  44082. +#ifdef CONFIG_OF
  44083. + mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
  44084. +#endif
  44085. + /* host controller capabilities */
  44086. + mmc->caps = MMC_CAP_CMD23 | MMC_CAP_ERASE | MMC_CAP_NEEDS_POLL | MMC_CAP_SDIO_IRQ |
  44087. + MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_4_BIT_DATA;
  44088. +
  44089. + host->flags = SDHCI_AUTO_CMD23;
  44090. +
  44091. + spin_lock_init(&host->lock);
  44092. +
  44093. +
  44094. +#ifdef FORCE_PIO
  44095. + pr_info("Forcing PIO mode\n");
  44096. + host->have_dma = false;
  44097. +#else
  44098. + if (!host->dma_chan_tx || !host->dma_chan_rx ||
  44099. + IS_ERR(host->dma_chan_tx) || IS_ERR(host->dma_chan_rx)) {
  44100. + pr_err("%s: Unable to initialise DMA channels. Falling back to PIO\n", DRIVER_NAME);
  44101. + host->have_dma = false;
  44102. + } else {
  44103. + pr_info("DMA channels allocated for the MMC driver");
  44104. + host->have_dma = true;
  44105. +
  44106. + cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  44107. + cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  44108. + cfg.slave_id = 11; /* DREQ channel */
  44109. +
  44110. + cfg.direction = DMA_MEM_TO_DEV;
  44111. + cfg.src_addr = 0;
  44112. + cfg.dst_addr = host->phys_addr + SDHCI_BUFFER;
  44113. + ret = dmaengine_slave_config(host->dma_chan_tx, &cfg);
  44114. +
  44115. + cfg.direction = DMA_DEV_TO_MEM;
  44116. + cfg.src_addr = host->phys_addr + SDHCI_BUFFER;
  44117. + cfg.dst_addr = 0;
  44118. + ret = dmaengine_slave_config(host->dma_chan_rx, &cfg);
  44119. + }
  44120. +#endif
  44121. +
  44122. +
  44123. + mmc->max_segs = 128;
  44124. + mmc->max_req_size = 524288;
  44125. + mmc->max_seg_size = mmc->max_req_size;
  44126. + mmc->max_blk_size = 512;
  44127. + mmc->max_blk_count = 65535;
  44128. +
  44129. + /* report supported voltage ranges */
  44130. + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  44131. +
  44132. + tasklet_init(&host->finish_tasklet,
  44133. + bcm2835_mmc_tasklet_finish, (unsigned long)host);
  44134. +
  44135. + setup_timer(&host->timer, bcm2835_mmc_timeout_timer, (unsigned long)host);
  44136. + init_waitqueue_head(&host->buf_ready_int);
  44137. +
  44138. + bcm2835_mmc_init(host, 0);
  44139. +#ifndef CONFIG_OF
  44140. + ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
  44141. + mmc_hostname(mmc), host);
  44142. +#else
  44143. + ret = request_threaded_irq(host->irq, bcm2835_mmc_irq, bcm2835_mmc_thread_irq,
  44144. + IRQF_SHARED, mmc_hostname(mmc), host);
  44145. +#endif
  44146. + if (ret) {
  44147. + pr_err("%s: Failed to request IRQ %d: %d\n",
  44148. + mmc_hostname(mmc), host->irq, ret);
  44149. + goto untasklet;
  44150. + }
  44151. +
  44152. + mmiowb();
  44153. + mmc_add_host(mmc);
  44154. +
  44155. + pr_info("Load BCM2835 MMC driver\n");
  44156. +
  44157. + return 0;
  44158. +
  44159. +untasklet:
  44160. + tasklet_kill(&host->finish_tasklet);
  44161. +
  44162. + return ret;
  44163. +}
  44164. +
  44165. +static int bcm2835_mmc_probe(struct platform_device *pdev)
  44166. +{
  44167. + struct device *dev = &pdev->dev;
  44168. +#ifdef CONFIG_OF
  44169. + struct device_node *node = dev->of_node;
  44170. + struct clk *clk;
  44171. +#endif
  44172. + struct resource *iomem;
  44173. + struct bcm2835_host *host = NULL;
  44174. +
  44175. + int ret;
  44176. + struct mmc_host *mmc;
  44177. +#if !defined(CONFIG_OF) && !defined(FORCE_PIO)
  44178. + dma_cap_mask_t mask;
  44179. +#endif
  44180. +
  44181. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44182. + if (!iomem) {
  44183. + ret = -ENOMEM;
  44184. + goto err;
  44185. + }
  44186. +
  44187. + if (resource_size(iomem) < 0x100)
  44188. + dev_err(&pdev->dev, "Invalid iomem size!\n");
  44189. +
  44190. + mmc = mmc_alloc_host(sizeof(struct bcm2835_host), dev);
  44191. + host = mmc_priv(mmc);
  44192. + host->mmc = mmc;
  44193. +
  44194. +
  44195. + if (IS_ERR(host)) {
  44196. + ret = PTR_ERR(host);
  44197. + goto err;
  44198. + }
  44199. +
  44200. + host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
  44201. +
  44202. +#ifndef CONFIG_OF
  44203. +#ifndef FORCE_PIO
  44204. + dma_cap_zero(mask);
  44205. + /* we don't care about the channel, any would work */
  44206. + dma_cap_set(DMA_SLAVE, mask);
  44207. +
  44208. + host->dma_chan_tx = dma_request_channel(mask, NULL, NULL);
  44209. + host->dma_chan_rx = dma_request_channel(mask, NULL, NULL);
  44210. +#endif
  44211. + host->max_clk = BCM2835_CLOCK_FREQ;
  44212. +
  44213. +#else
  44214. +#ifndef FORCE_PIO
  44215. + host->dma_chan_tx = of_dma_request_slave_channel(node, "tx");
  44216. + host->dma_chan_rx = of_dma_request_slave_channel(node, "rx");
  44217. +#endif
  44218. + clk = of_clk_get(node, 0);
  44219. + if (IS_ERR(clk)) {
  44220. + dev_err(dev, "get CLOCK failed\n");
  44221. + ret = PTR_ERR(clk);
  44222. + goto out;
  44223. + }
  44224. + host->max_clk = (clk_get_rate(clk));
  44225. +#endif
  44226. + host->irq = platform_get_irq(pdev, 0);
  44227. +
  44228. + if (!request_mem_region(iomem->start, resource_size(iomem),
  44229. + mmc_hostname(host->mmc))) {
  44230. + dev_err(&pdev->dev, "cannot request region\n");
  44231. + ret = -EBUSY;
  44232. + goto err_request;
  44233. + }
  44234. +
  44235. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  44236. + if (!host->ioaddr) {
  44237. + dev_err(&pdev->dev, "failed to remap registers\n");
  44238. + ret = -ENOMEM;
  44239. + goto err_remap;
  44240. + }
  44241. +
  44242. + platform_set_drvdata(pdev, host);
  44243. +
  44244. +
  44245. + if (host->irq <= 0) {
  44246. + dev_err(dev, "get IRQ failed\n");
  44247. + ret = -EINVAL;
  44248. + goto out;
  44249. + }
  44250. +
  44251. +
  44252. +#ifndef CONFIG_OF
  44253. + mmc->caps |= MMC_CAP_4_BIT_DATA;
  44254. +#else
  44255. + mmc_of_parse(mmc);
  44256. +#endif
  44257. + host->timeout = msecs_to_jiffies(1000);
  44258. + spin_lock_init(&host->lock);
  44259. + mmc->ops = &bcm2835_ops;
  44260. + return bcm2835_mmc_add_host(host);
  44261. +
  44262. +
  44263. +err_remap:
  44264. + release_mem_region(iomem->start, resource_size(iomem));
  44265. +err_request:
  44266. + mmc_free_host(host->mmc);
  44267. +err:
  44268. + dev_err(&pdev->dev, "%s failed %d\n", __func__, ret);
  44269. + return ret;
  44270. +out:
  44271. + if (mmc)
  44272. + mmc_free_host(mmc);
  44273. + return ret;
  44274. +}
  44275. +
  44276. +static int bcm2835_mmc_remove(struct platform_device *pdev)
  44277. +{
  44278. + struct bcm2835_host *host = platform_get_drvdata(pdev);
  44279. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44280. + unsigned long flags;
  44281. + int dead;
  44282. + u32 scratch;
  44283. +
  44284. + dead = 0;
  44285. + scratch = bcm2835_mmc_readl(host, SDHCI_INT_STATUS);
  44286. + if (scratch == (u32)-1)
  44287. + dead = 1;
  44288. +
  44289. +
  44290. + if (dead) {
  44291. + spin_lock_irqsave(&host->lock, flags);
  44292. +
  44293. + host->flags |= SDHCI_DEVICE_DEAD;
  44294. +
  44295. + if (host->mrq) {
  44296. + pr_err("%s: Controller removed during "
  44297. + " transfer!\n", mmc_hostname(host->mmc));
  44298. +
  44299. + host->mrq->cmd->error = -ENOMEDIUM;
  44300. + tasklet_schedule(&host->finish_tasklet);
  44301. + }
  44302. +
  44303. + spin_unlock_irqrestore(&host->lock, flags);
  44304. + }
  44305. +
  44306. + mmc_remove_host(host->mmc);
  44307. +
  44308. + if (!dead)
  44309. + bcm2835_mmc_reset(host, SDHCI_RESET_ALL);
  44310. +
  44311. + free_irq(host->irq, host);
  44312. +
  44313. + del_timer_sync(&host->timer);
  44314. +
  44315. + tasklet_kill(&host->finish_tasklet);
  44316. +
  44317. + iounmap(host->ioaddr);
  44318. + release_mem_region(iomem->start, resource_size(iomem));
  44319. + mmc_free_host(host->mmc);
  44320. + platform_set_drvdata(pdev, NULL);
  44321. +
  44322. + return 0;
  44323. +}
  44324. +
  44325. +
  44326. +static const struct of_device_id bcm2835_mmc_match[] = {
  44327. + { .compatible = "brcm,bcm2835-mmc" },
  44328. + { }
  44329. +};
  44330. +MODULE_DEVICE_TABLE(of, bcm2835_mmc_match);
  44331. +
  44332. +
  44333. +
  44334. +static struct platform_driver bcm2835_mmc_driver = {
  44335. + .probe = bcm2835_mmc_probe,
  44336. + .remove = bcm2835_mmc_remove,
  44337. + .driver = {
  44338. + .name = DRIVER_NAME,
  44339. + .owner = THIS_MODULE,
  44340. + .of_match_table = bcm2835_mmc_match,
  44341. + },
  44342. +};
  44343. +module_platform_driver(bcm2835_mmc_driver);
  44344. +
  44345. +MODULE_ALIAS("platform:mmc-bcm2835");
  44346. +MODULE_DESCRIPTION("BCM2835 SDHCI driver");
  44347. +MODULE_LICENSE("GPL v2");
  44348. +MODULE_AUTHOR("Gellert Weisz");
  44349. diff -Nur linux-3.12.38/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  44350. --- linux-3.12.38/drivers/mmc/host/Kconfig 2015-02-16 16:15:42.000000000 +0100
  44351. +++ linux-rpi/drivers/mmc/host/Kconfig 2015-03-10 17:26:50.558216692 +0100
  44352. @@ -260,6 +260,27 @@
  44353. If you have a controller with this interface, say Y or M here.
  44354. +config MMC_SDHCI_BCM2708
  44355. + tristate "SDHCI support on BCM2708"
  44356. + depends on MMC_SDHCI && MACH_BCM2708
  44357. + select MMC_SDHCI_IO_ACCESSORS
  44358. + help
  44359. + This selects the Secure Digital Host Controller Interface (SDHCI)
  44360. + often referrered to as the eMMC block.
  44361. +
  44362. + If you have a controller with this interface, say Y or M here.
  44363. +
  44364. + If unsure, say N.
  44365. +
  44366. +config MMC_SDHCI_BCM2708_DMA
  44367. + bool "DMA support on BCM2708 Arasan controller"
  44368. + depends on MMC_SDHCI_BCM2708
  44369. + help
  44370. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  44371. + based chips.
  44372. +
  44373. + If unsure, say N.
  44374. +
  44375. config MMC_SDHCI_BCM2835
  44376. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  44377. depends on ARCH_BCM2835
  44378. @@ -271,6 +292,35 @@
  44379. If unsure, say N.
  44380. +config MMC_BCM2835
  44381. + tristate "MMC support on BCM2835"
  44382. + depends on MACH_BCM2708
  44383. + help
  44384. + This selects the MMC Interface on BCM2835.
  44385. +
  44386. + If you have a controller with this interface, say Y or M here.
  44387. +
  44388. + If unsure, say N.
  44389. +
  44390. +config MMC_BCM2835_DMA
  44391. + bool "DMA support on BCM2835 Arasan controller"
  44392. + depends on MMC_BCM2835
  44393. + help
  44394. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  44395. + based chips.
  44396. +
  44397. + If unsure, say N.
  44398. +
  44399. +config MMC_BCM2835_PIO_DMA_BARRIER
  44400. + int "Block count limit for PIO transfers"
  44401. + depends on MMC_BCM2835 && MMC_BCM2835_DMA
  44402. + range 0 256
  44403. + default 2
  44404. + help
  44405. + The inclusive limit in bytes under which PIO will be used instead of DMA
  44406. +
  44407. + If unsure, say 2 here.
  44408. +
  44409. config MMC_OMAP
  44410. tristate "TI OMAP Multimedia Card Interface support"
  44411. depends on ARCH_OMAP
  44412. diff -Nur linux-3.12.38/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  44413. --- linux-3.12.38/drivers/mmc/host/Makefile 2015-02-16 16:15:42.000000000 +0100
  44414. +++ linux-rpi/drivers/mmc/host/Makefile 2015-03-10 17:26:50.558216692 +0100
  44415. @@ -15,6 +15,8 @@
  44416. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  44417. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  44418. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  44419. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  44420. +obj-$(CONFIG_MMC_BCM2835) += bcm2835-mmc.o
  44421. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  44422. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  44423. obj-$(CONFIG_MMC_OMAP) += omap.o
  44424. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci-acpi.c linux-rpi/drivers/mmc/host/sdhci-acpi.c
  44425. --- linux-3.12.38/drivers/mmc/host/sdhci-acpi.c 2015-02-16 16:15:42.000000000 +0100
  44426. +++ linux-rpi/drivers/mmc/host/sdhci-acpi.c 2015-03-10 17:26:50.562216692 +0100
  44427. @@ -119,11 +119,9 @@
  44428. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | MMC_CAP_HW_RESET,
  44429. .caps2 = MMC_CAP2_HC_ERASE_SZ,
  44430. .flags = SDHCI_ACPI_RUNTIME_PM,
  44431. - .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  44432. };
  44433. static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
  44434. - .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
  44435. .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
  44436. .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD,
  44437. .flags = SDHCI_ACPI_RUNTIME_PM,
  44438. @@ -144,23 +142,16 @@
  44439. static const struct sdhci_acpi_uid_slot sdhci_acpi_uids[] = {
  44440. { "80860F14" , "1" , &sdhci_acpi_slot_int_emmc },
  44441. { "80860F14" , "3" , &sdhci_acpi_slot_int_sd },
  44442. - { "80860F16" , NULL, &sdhci_acpi_slot_int_sd },
  44443. { "INT33BB" , "2" , &sdhci_acpi_slot_int_sdio },
  44444. - { "INT33BB" , "3" , &sdhci_acpi_slot_int_sd },
  44445. { "INT33C6" , NULL, &sdhci_acpi_slot_int_sdio },
  44446. - { "INT3436" , NULL, &sdhci_acpi_slot_int_sdio },
  44447. - { "INT344D" , NULL, &sdhci_acpi_slot_int_sdio },
  44448. { "PNP0D40" },
  44449. { },
  44450. };
  44451. static const struct acpi_device_id sdhci_acpi_ids[] = {
  44452. { "80860F14" },
  44453. - { "80860F16" },
  44454. { "INT33BB" },
  44455. { "INT33C6" },
  44456. - { "INT3436" },
  44457. - { "INT344D" },
  44458. { "PNP0D40" },
  44459. { },
  44460. };
  44461. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci-bcm2708.c linux-rpi/drivers/mmc/host/sdhci-bcm2708.c
  44462. --- linux-3.12.38/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  44463. +++ linux-rpi/drivers/mmc/host/sdhci-bcm2708.c 2015-03-10 17:26:50.562216692 +0100
  44464. @@ -0,0 +1,1433 @@
  44465. +/*
  44466. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  44467. + * Copyright (c) 2010 Broadcom
  44468. + *
  44469. + * This program is free software; you can redistribute it and/or modify
  44470. + * it under the terms of the GNU General Public License version 2 as
  44471. + * published by the Free Software Foundation.
  44472. + *
  44473. + * This program is distributed in the hope that it will be useful,
  44474. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  44475. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44476. + * GNU General Public License for more details.
  44477. + *
  44478. + * You should have received a copy of the GNU General Public License
  44479. + * along with this program; if not, write to the Free Software
  44480. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  44481. + */
  44482. +
  44483. +/* Supports:
  44484. + * SDHCI platform device - Arasan SD controller in BCM2708
  44485. + *
  44486. + * Inspired by sdhci-pci.c, by Pierre Ossman
  44487. + */
  44488. +
  44489. +#include <linux/delay.h>
  44490. +#include <linux/highmem.h>
  44491. +#include <linux/platform_device.h>
  44492. +#include <linux/module.h>
  44493. +#include <linux/mmc/mmc.h>
  44494. +#include <linux/mmc/host.h>
  44495. +#include <linux/mmc/sd.h>
  44496. +
  44497. +#include <linux/io.h>
  44498. +#include <linux/dma-mapping.h>
  44499. +#include <mach/dma.h>
  44500. +
  44501. +#include "sdhci.h"
  44502. +
  44503. +/*****************************************************************************\
  44504. + * *
  44505. + * Configuration *
  44506. + * *
  44507. +\*****************************************************************************/
  44508. +
  44509. +#define DRIVER_NAME "bcm2708_sdhci"
  44510. +
  44511. +/* for the time being insist on DMA mode - PIO seems not to work */
  44512. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  44513. +#warning Non-DMA (PIO) version of this driver currently unavailable
  44514. +#endif
  44515. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  44516. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  44517. +
  44518. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  44519. +/* #define CHECK_DMA_USE */
  44520. +#endif
  44521. +//#define LOG_REGISTERS
  44522. +
  44523. +#define USE_SCHED_TIME
  44524. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  44525. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  44526. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  44527. +
  44528. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  44529. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  44530. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  44531. +
  44532. +/*! TODO: obtain these from the physical address */
  44533. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  44534. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  44535. +
  44536. +#define MAX_LITE_TRANSFER 32768
  44537. +#define MAX_NORMAL_TRANSFER 1073741824
  44538. +
  44539. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  44540. +
  44541. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  44542. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  44543. +
  44544. +#define REG_EXRDFIFO_EN 0x80
  44545. +#define REG_EXRDFIFO_CFG 0x84
  44546. +
  44547. +int cycle_delay=2;
  44548. +
  44549. +/*****************************************************************************\
  44550. + * *
  44551. + * Debug *
  44552. + * *
  44553. +\*****************************************************************************/
  44554. +
  44555. +
  44556. +
  44557. +#define DBG(f, x...) \
  44558. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  44559. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  44560. +
  44561. +
  44562. +/*****************************************************************************\
  44563. + * *
  44564. + * High Precision Time *
  44565. + * *
  44566. +\*****************************************************************************/
  44567. +
  44568. +#ifdef USE_SCHED_TIME
  44569. +
  44570. +#include <mach/frc.h>
  44571. +
  44572. +typedef unsigned long hptime_t;
  44573. +
  44574. +#define FMT_HPT "lu"
  44575. +
  44576. +static inline hptime_t hptime(void)
  44577. +{
  44578. + return frc_clock_ticks32();
  44579. +}
  44580. +
  44581. +#define HPTIME_CLK_NS 1000ul
  44582. +
  44583. +#else
  44584. +
  44585. +typedef unsigned long hptime_t;
  44586. +
  44587. +#define FMT_HPT "lu"
  44588. +
  44589. +static inline hptime_t hptime(void)
  44590. +{
  44591. + return jiffies;
  44592. +}
  44593. +
  44594. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  44595. +
  44596. +#endif
  44597. +
  44598. +static inline unsigned long int since_ns(hptime_t t)
  44599. +{
  44600. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  44601. +}
  44602. +
  44603. +static bool allow_highspeed = 1;
  44604. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  44605. +static bool sync_after_dma = 1;
  44606. +static bool missing_status = 1;
  44607. +static bool spurious_crc_acmd51 = 0;
  44608. +bool enable_llm = 1;
  44609. +bool extra_messages = 0;
  44610. +
  44611. +#if 0
  44612. +static void hptime_test(void)
  44613. +{
  44614. + hptime_t now;
  44615. + hptime_t later;
  44616. +
  44617. + now = hptime();
  44618. + msleep(10);
  44619. + later = hptime();
  44620. +
  44621. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  44622. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  44623. + later-now, now, later,
  44624. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  44625. +
  44626. + now = hptime();
  44627. + msleep(1000);
  44628. + later = hptime();
  44629. +
  44630. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  44631. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  44632. + later-now, now, later,
  44633. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  44634. +}
  44635. +#endif
  44636. +
  44637. +/*****************************************************************************\
  44638. + * *
  44639. + * SDHCI core callbacks *
  44640. + * *
  44641. +\*****************************************************************************/
  44642. +
  44643. +
  44644. +#ifdef CHECK_DMA_USE
  44645. +/*#define CHECK_DMA_REG_USE*/
  44646. +#endif
  44647. +
  44648. +#ifdef CHECK_DMA_REG_USE
  44649. +/* we don't expect anything to be using these registers during a
  44650. + DMA (except the IRQ status) - so check */
  44651. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  44652. +#else
  44653. +#define check_dma_reg_use(host, reg)
  44654. +#endif
  44655. +
  44656. +
  44657. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  44658. +{
  44659. + return readl(host->ioaddr + reg);
  44660. +}
  44661. +
  44662. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  44663. +{
  44664. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  44665. +
  44666. +#ifdef LOG_REGISTERS
  44667. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  44668. + mmc_hostname(host->mmc), reg, l);
  44669. +#endif
  44670. + check_dma_reg_use(host, reg);
  44671. +
  44672. + return l;
  44673. +}
  44674. +
  44675. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  44676. +{
  44677. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  44678. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  44679. +
  44680. +#ifdef LOG_REGISTERS
  44681. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  44682. + mmc_hostname(host->mmc), reg, w);
  44683. +#endif
  44684. + check_dma_reg_use(host, reg);
  44685. +
  44686. + return (u16)w;
  44687. +}
  44688. +
  44689. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  44690. +{
  44691. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  44692. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  44693. +
  44694. +#ifdef LOG_REGISTERS
  44695. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  44696. + mmc_hostname(host->mmc), reg, b);
  44697. +#endif
  44698. + check_dma_reg_use(host, reg);
  44699. +
  44700. + return (u8)b;
  44701. +}
  44702. +
  44703. +
  44704. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  44705. +{
  44706. + u32 ier;
  44707. +
  44708. +#if USE_SPACED_WRITES_2CLK
  44709. + static bool timeout_disabled = false;
  44710. + unsigned int ns_2clk = 0;
  44711. +
  44712. + /* The Arasan has a bugette whereby it may lose the content of
  44713. + * successive writes to registers that are within two SD-card clock
  44714. + * cycles of each other (a clock domain crossing problem).
  44715. + * It seems, however, that the data register does not have this problem.
  44716. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  44717. + * too)
  44718. + */
  44719. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  44720. + /* host->clock is the clock freq in Hz */
  44721. + static hptime_t last_write_hpt;
  44722. + hptime_t now = hptime();
  44723. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  44724. +
  44725. + if (now == last_write_hpt || now == last_write_hpt+1) {
  44726. + /* we can't guarantee any significant time has
  44727. + * passed - we'll have to wait anyway ! */
  44728. + ndelay(ns_2clk);
  44729. + } else
  44730. + {
  44731. + /* we must have waited at least this many ns: */
  44732. + unsigned int ns_wait = HPTIME_CLK_NS *
  44733. + (now - last_write_hpt - 1);
  44734. + if (ns_wait < ns_2clk)
  44735. + ndelay(ns_2clk - ns_wait);
  44736. + }
  44737. + last_write_hpt = now;
  44738. + }
  44739. +#if USE_SOFTWARE_TIMEOUTS
  44740. + /* The Arasan is clocked for timeouts using the SD clock which is too
  44741. + * fast for ERASE commands and causes issues. So we disable timeouts
  44742. + * for ERASE */
  44743. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  44744. + reg == (SDHCI_COMMAND & ~3)) {
  44745. + mod_timer(&host->timer,
  44746. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  44747. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  44748. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  44749. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  44750. + timeout_disabled = true;
  44751. + ndelay(ns_2clk);
  44752. + } else if (timeout_disabled) {
  44753. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  44754. + ier |= SDHCI_INT_DATA_TIMEOUT;
  44755. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  44756. + timeout_disabled = false;
  44757. + ndelay(ns_2clk);
  44758. + }
  44759. +#endif
  44760. + writel(val, host->ioaddr + reg);
  44761. +#else
  44762. + void __iomem * regaddr = host->ioaddr + reg;
  44763. +
  44764. + writel(val, regaddr);
  44765. +
  44766. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  44767. + {
  44768. + int timeout = 100000;
  44769. + while (val != readl(regaddr) && --timeout > 0)
  44770. + continue;
  44771. +
  44772. + if (timeout <= 0)
  44773. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  44774. + "always gives 0x%X\n",
  44775. + mmc_hostname(host->mmc),
  44776. + val, reg, readl(regaddr));
  44777. + BUG_ON(timeout <= 0);
  44778. + }
  44779. +#endif
  44780. +}
  44781. +
  44782. +
  44783. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  44784. +{
  44785. +#ifdef LOG_REGISTERS
  44786. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  44787. + mmc_hostname(host->mmc), reg, val);
  44788. +#endif
  44789. + check_dma_reg_use(host, reg);
  44790. +
  44791. + sdhci_bcm2708_raw_writel(host, val, reg);
  44792. +}
  44793. +
  44794. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  44795. +{
  44796. + static u32 shadow = 0;
  44797. +
  44798. + u32 p = reg == SDHCI_COMMAND ? shadow :
  44799. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  44800. + u32 s = reg << 3 & 0x18;
  44801. + u32 l = val << s;
  44802. + u32 m = 0xffff << s;
  44803. +
  44804. +#ifdef LOG_REGISTERS
  44805. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  44806. + mmc_hostname(host->mmc), reg, val);
  44807. +#endif
  44808. +
  44809. + if (reg == SDHCI_TRANSFER_MODE)
  44810. + shadow = (p & ~m) | l;
  44811. + else {
  44812. + check_dma_reg_use(host, reg);
  44813. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  44814. + }
  44815. +}
  44816. +
  44817. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  44818. +{
  44819. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  44820. + u32 s = reg << 3 & 0x18;
  44821. + u32 l = val << s;
  44822. + u32 m = 0xff << s;
  44823. +
  44824. +#ifdef LOG_REGISTERS
  44825. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  44826. + mmc_hostname(host->mmc), reg, val);
  44827. +#endif
  44828. +
  44829. + check_dma_reg_use(host, reg);
  44830. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  44831. +}
  44832. +
  44833. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  44834. +{
  44835. + return emmc_clock_freq;
  44836. +}
  44837. +
  44838. +/*****************************************************************************\
  44839. + * *
  44840. + * DMA Operation *
  44841. + * *
  44842. +\*****************************************************************************/
  44843. +
  44844. +struct sdhci_bcm2708_priv {
  44845. + int dma_chan;
  44846. + int dma_irq;
  44847. + void __iomem *dma_chan_base;
  44848. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  44849. + dma_addr_t cb_handle;
  44850. + /* tracking scatter gather progress */
  44851. + unsigned sg_ix; /* scatter gather list index */
  44852. + unsigned sg_done; /* bytes in current sg_ix done */
  44853. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  44854. + unsigned char dma_wanted; /* DMA transfer requested */
  44855. + unsigned char dma_waits; /* wait states in DMAs */
  44856. +#ifdef CHECK_DMA_USE
  44857. + unsigned char dmas_pending; /* no of unfinished DMAs */
  44858. + hptime_t when_started;
  44859. + hptime_t when_reset;
  44860. + hptime_t when_stopped;
  44861. +#endif
  44862. +#endif
  44863. + /* signalling the end of a transfer */
  44864. + void (*complete)(struct sdhci_host *);
  44865. +};
  44866. +
  44867. +#define SDHCI_HOST_PRIV(host) \
  44868. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  44869. +
  44870. +
  44871. +
  44872. +#ifdef CHECK_DMA_REG_USE
  44873. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  44874. +{
  44875. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  44876. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  44877. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  44878. + mmc_hostname(host->mmc), reg);
  44879. + }
  44880. +}
  44881. +#endif
  44882. +
  44883. +
  44884. +
  44885. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  44886. +
  44887. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  44888. +{
  44889. + u32 ier;
  44890. +
  44891. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  44892. + ier &= ~clear;
  44893. + ier |= set;
  44894. + /* change which requests generate IRQs - makes no difference to
  44895. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  44896. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  44897. +}
  44898. +
  44899. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  44900. +{
  44901. + sdhci_clear_set_irqgen(host, 0, irqs);
  44902. +}
  44903. +
  44904. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  44905. +{
  44906. + sdhci_clear_set_irqgen(host, irqs, 0);
  44907. +}
  44908. +
  44909. +
  44910. +
  44911. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  44912. + int ix,
  44913. + dma_addr_t dma_addr, unsigned len,
  44914. + int /*bool*/ is_last)
  44915. +{
  44916. + struct bcm2708_dma_cb *cb;
  44917. + unsigned char dmawaits = host->dma_waits;
  44918. + unsigned i, max_size;
  44919. +
  44920. + if (host->dma_chan >= 8) /* we have a LITE channel */
  44921. + max_size = MAX_LITE_TRANSFER;
  44922. + else
  44923. + max_size = MAX_NORMAL_TRANSFER;
  44924. +
  44925. + for (i = 0; i < len; i += max_size) {
  44926. + cb = &host->cb_base[ix+i/max_size];
  44927. +
  44928. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  44929. + BCM2708_DMA_WAITS(dmawaits) |
  44930. + BCM2708_DMA_WAIT_RESP |
  44931. + BCM2708_DMA_S_DREQ |
  44932. + BCM2708_DMA_D_WIDTH |
  44933. + BCM2708_DMA_D_INC;
  44934. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  44935. + cb->dst = dma_addr + (dma_addr_t)i;
  44936. + cb->length = min(len-i, max_size);
  44937. + cb->stride = 0;
  44938. +
  44939. + if (is_last && len-i <= max_size) {
  44940. + cb->info |= BCM2708_DMA_INT_EN;
  44941. + cb->next = 0;
  44942. + } else
  44943. + cb->next = host->cb_handle +
  44944. + (ix+1 + i/max_size)*sizeof(struct bcm2708_dma_cb);
  44945. +
  44946. + cb->pad[0] = 0;
  44947. + cb->pad[1] = 0;
  44948. + }
  44949. +}
  44950. +
  44951. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  44952. + int ix,
  44953. + dma_addr_t dma_addr, unsigned len,
  44954. + int /*bool*/ is_last)
  44955. +{
  44956. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  44957. + unsigned char dmawaits = host->dma_waits;
  44958. + unsigned i, max_size;
  44959. +
  44960. + if (host->dma_chan >= 8) /* we have a LITE channel */
  44961. + max_size = MAX_LITE_TRANSFER;
  44962. + else
  44963. + max_size = MAX_NORMAL_TRANSFER;
  44964. +
  44965. + /* We can make arbitrarily large writes as long as we specify DREQ to
  44966. + pace the delivery of bytes to the Arasan hardware. However we need
  44967. + to take care when using LITE channels */
  44968. +
  44969. + for (i = 0; i < len; i += max_size) {
  44970. + cb = &host->cb_base[ix+i/max_size];
  44971. +
  44972. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  44973. + BCM2708_DMA_WAITS(dmawaits) |
  44974. + BCM2708_DMA_WAIT_RESP |
  44975. + BCM2708_DMA_D_DREQ |
  44976. + BCM2708_DMA_S_WIDTH |
  44977. + BCM2708_DMA_S_INC;
  44978. + cb->src = dma_addr + (dma_addr_t)i;
  44979. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  44980. + cb->length = min(len-i, max_size);
  44981. + cb->stride = 0;
  44982. +
  44983. + if (is_last && len-i <= max_size) {
  44984. + cb->info |= BCM2708_DMA_INT_EN;
  44985. + cb->next = 0;
  44986. + } else
  44987. + cb->next = host->cb_handle +
  44988. + (ix+1 + i/max_size)*sizeof(struct bcm2708_dma_cb);
  44989. +
  44990. + cb->pad[0] = 0;
  44991. + cb->pad[1] = 0;
  44992. + }
  44993. +}
  44994. +
  44995. +
  44996. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  44997. +{
  44998. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  44999. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  45000. +
  45001. + BUG_ON(host_priv->dma_wanted);
  45002. +#ifdef CHECK_DMA_USE
  45003. + if (host_priv->dma_wanted)
  45004. + printk(KERN_ERR "%s: DMA already in progress - "
  45005. + "now %"FMT_HPT", last started %lu "
  45006. + "reset %lu stopped %lu\n",
  45007. + mmc_hostname(host->mmc),
  45008. + hptime(), since_ns(host_priv->when_started),
  45009. + since_ns(host_priv->when_reset),
  45010. + since_ns(host_priv->when_stopped));
  45011. + else if (host_priv->dmas_pending > 0)
  45012. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  45013. + "already in progress - "
  45014. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  45015. + mmc_hostname(host->mmc),
  45016. + host_priv->dmas_pending,
  45017. + hptime(), since_ns(host_priv->when_started),
  45018. + since_ns(host_priv->when_reset),
  45019. + since_ns(host_priv->when_stopped));
  45020. + host_priv->dmas_pending += 1;
  45021. + host_priv->when_started = hptime();
  45022. +#endif
  45023. + host_priv->dma_wanted = 1;
  45024. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  45025. + host_priv->cb_handle);
  45026. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  45027. +}
  45028. +
  45029. +
  45030. +static void
  45031. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  45032. +{
  45033. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45034. +
  45035. + DBG("PDMA to read %d bytes\n", len);
  45036. + host_priv->sg_done += len;
  45037. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  45038. + schci_bcm2708_dma_go(host);
  45039. +}
  45040. +
  45041. +
  45042. +static void
  45043. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  45044. +{
  45045. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45046. +
  45047. + DBG("PDMA to write %d bytes\n", len);
  45048. + //BUG_ON(0 != (len & 0x1ff));
  45049. +
  45050. + host_priv->sg_done += len;
  45051. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  45052. + schci_bcm2708_dma_go(host);
  45053. +}
  45054. +
  45055. +/*! space is avaiable to receive into or data is available to write
  45056. + Platform DMA exported function
  45057. +*/
  45058. +void
  45059. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  45060. + void(*completion_callback)(struct sdhci_host *host))
  45061. +{
  45062. + struct mmc_data *data = host->data;
  45063. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45064. + int sg_ix;
  45065. + size_t bytes;
  45066. + dma_addr_t addr;
  45067. +
  45068. + BUG_ON(NULL == data);
  45069. + BUG_ON(0 == data->blksz);
  45070. +
  45071. + host_priv->complete = completion_callback;
  45072. +
  45073. + sg_ix = host_priv->sg_ix;
  45074. + BUG_ON(sg_ix >= data->sg_len);
  45075. +
  45076. + /* we can DMA blocks larger than blksz - it may hang the DMA
  45077. + channel but we are its only user */
  45078. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  45079. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  45080. +
  45081. + if (bytes > 0) {
  45082. + /* We're going to poll for read/write available state until
  45083. + we finish this DMA
  45084. + */
  45085. +
  45086. + if (data->flags & MMC_DATA_READ) {
  45087. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  45088. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  45089. + SDHCI_INT_SPACE_AVAIL);
  45090. + sdhci_platdma_read(host, addr, bytes);
  45091. + }
  45092. + } else {
  45093. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  45094. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  45095. + SDHCI_INT_SPACE_AVAIL);
  45096. + sdhci_platdma_write(host, addr, bytes);
  45097. + }
  45098. + }
  45099. + }
  45100. + /* else:
  45101. + we have run out of bytes that need transferring (e.g. we may be in
  45102. + the middle of the last DMA transfer), or
  45103. + it is also possible that we've been called when another IRQ is
  45104. + signalled, even though we've turned off signalling of our own IRQ */
  45105. +
  45106. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  45107. + /* don't let the main sdhci driver act on this .. we'll deal with it
  45108. + when we respond to the DMA - if one is currently in progress */
  45109. +}
  45110. +
  45111. +/* is it possible to DMA the given mmc_data structure?
  45112. + Platform DMA exported function
  45113. +*/
  45114. +int /*bool*/
  45115. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  45116. +{
  45117. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45118. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  45119. +
  45120. + if (!ok)
  45121. + DBG("Reverting to PIO - bad cache alignment\n");
  45122. +
  45123. + else {
  45124. + host_priv->sg_ix = 0; /* first SG index */
  45125. + host_priv->sg_done = 0; /* no bytes done */
  45126. + }
  45127. +
  45128. + return ok;
  45129. +}
  45130. +
  45131. +#include <mach/arm_control.h> //GRAYG
  45132. +/*! the current SD transacton has been abandonned
  45133. + We need to tidy up if we were in the middle of a DMA
  45134. + Platform DMA exported function
  45135. +*/
  45136. +void
  45137. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  45138. +{
  45139. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45140. +// unsigned long flags;
  45141. +
  45142. + BUG_ON(NULL == host);
  45143. +
  45144. +// spin_lock_irqsave(&host->lock, flags);
  45145. +
  45146. + if (host_priv->dma_wanted) {
  45147. + if (NULL == data) {
  45148. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  45149. + mmc_hostname(host->mmc));
  45150. + BUG_ON(NULL == data);
  45151. + } else {
  45152. + struct scatterlist *sg;
  45153. + int sg_len;
  45154. + int sg_todo;
  45155. + int rc;
  45156. + unsigned long cs;
  45157. +
  45158. + sg = data->sg;
  45159. + sg_len = data->sg_len;
  45160. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  45161. +
  45162. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  45163. +
  45164. + if (!(BCM2708_DMA_ACTIVE & cs))
  45165. + {
  45166. + if (extra_messages)
  45167. + printk(KERN_INFO "%s: missed completion of "
  45168. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  45169. + "ignoring it\n",
  45170. + mmc_hostname(host->mmc),
  45171. + host->last_cmdop,
  45172. + host_priv->sg_done, sg_todo,
  45173. + host_priv->sg_ix+1, sg_len);
  45174. + }
  45175. + else
  45176. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  45177. + "DMA before %d/%d [%d]/[%d] complete\n",
  45178. + mmc_hostname(host->mmc),
  45179. + host->last_cmdop,
  45180. + host_priv->sg_done, sg_todo,
  45181. + host_priv->sg_ix+1, sg_len);
  45182. +#ifdef CHECK_DMA_USE
  45183. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  45184. + "last reset %lu last stopped %lu\n",
  45185. + mmc_hostname(host->mmc),
  45186. + hptime(), since_ns(host_priv->when_started),
  45187. + since_ns(host_priv->when_reset),
  45188. + since_ns(host_priv->when_stopped));
  45189. + { unsigned long info, debug;
  45190. + void __iomem *base;
  45191. + unsigned long pend0, pend1, pend2;
  45192. +
  45193. + base = host_priv->dma_chan_base;
  45194. + cs = readl(base + BCM2708_DMA_CS);
  45195. + info = readl(base + BCM2708_DMA_INFO);
  45196. + debug = readl(base + BCM2708_DMA_DEBUG);
  45197. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  45198. + "DEBUG=%08lX\n",
  45199. + mmc_hostname(host->mmc),
  45200. + host_priv->dma_chan,
  45201. + cs, info, debug);
  45202. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  45203. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  45204. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  45205. +
  45206. + printk(KERN_INFO "%s: PEND0=%08lX "
  45207. + "PEND1=%08lX PEND2=%08lX\n",
  45208. + mmc_hostname(host->mmc),
  45209. + pend0, pend1, pend2);
  45210. +
  45211. + //gintsts = readl(__io_address(GINTSTS));
  45212. + //gintmsk = readl(__io_address(GINTMSK));
  45213. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  45214. + // "GINTMSK=%08lX\n",
  45215. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  45216. + }
  45217. +#endif
  45218. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  45219. + BUG_ON(rc != 0);
  45220. + }
  45221. + host_priv->dma_wanted = 0;
  45222. +#ifdef CHECK_DMA_USE
  45223. + host_priv->when_reset = hptime();
  45224. +#endif
  45225. + }
  45226. +
  45227. +// spin_unlock_irqrestore(&host->lock, flags);
  45228. +}
  45229. +
  45230. +
  45231. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  45232. + u32 dma_cs)
  45233. +{
  45234. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45235. + struct mmc_data *data;
  45236. + struct scatterlist *sg;
  45237. + int sg_len;
  45238. + int sg_ix;
  45239. + int sg_todo;
  45240. +// unsigned long flags;
  45241. +
  45242. + BUG_ON(NULL == host);
  45243. +
  45244. +// spin_lock_irqsave(&host->lock, flags);
  45245. + data = host->data;
  45246. +
  45247. +#ifdef CHECK_DMA_USE
  45248. + if (host_priv->dmas_pending <= 0)
  45249. + DBG("on completion no DMA in progress - "
  45250. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  45251. + hptime(), since_ns(host_priv->when_started),
  45252. + since_ns(host_priv->when_reset),
  45253. + since_ns(host_priv->when_stopped));
  45254. + else if (host_priv->dmas_pending > 1)
  45255. + DBG("still %d DMA in progress after completion - "
  45256. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  45257. + host_priv->dmas_pending - 1,
  45258. + hptime(), since_ns(host_priv->when_started),
  45259. + since_ns(host_priv->when_reset),
  45260. + since_ns(host_priv->when_stopped));
  45261. + BUG_ON(host_priv->dmas_pending <= 0);
  45262. + host_priv->dmas_pending -= 1;
  45263. + host_priv->when_stopped = hptime();
  45264. +#endif
  45265. + host_priv->dma_wanted = 0;
  45266. +
  45267. + if (NULL == data) {
  45268. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  45269. +// spin_unlock_irqrestore(&host->lock, flags);
  45270. + return;
  45271. + }
  45272. + sg = data->sg;
  45273. + sg_len = data->sg_len;
  45274. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  45275. +
  45276. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  45277. + host_priv->sg_done, sg_todo,
  45278. + host_priv->sg_ix+1, sg_len);
  45279. +
  45280. + BUG_ON(host_priv->sg_done > sg_todo);
  45281. +
  45282. + if (host_priv->sg_done >= sg_todo) {
  45283. + host_priv->sg_ix++;
  45284. + host_priv->sg_done = 0;
  45285. + }
  45286. +
  45287. + sg_ix = host_priv->sg_ix;
  45288. + if (sg_ix < sg_len) {
  45289. + u32 irq_mask;
  45290. + /* Set off next DMA if we've got the capacity */
  45291. +
  45292. + if (data->flags & MMC_DATA_READ)
  45293. + irq_mask = SDHCI_INT_DATA_AVAIL;
  45294. + else
  45295. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  45296. +
  45297. + /* We have to use the interrupt status register on the BCM2708
  45298. + rather than the SDHCI_PRESENT_STATE register because latency
  45299. + in the glue logic means that the information retrieved from
  45300. + the latter is not always up-to-date w.r.t the DMA engine -
  45301. + it may not indicate that a read or a write is ready yet */
  45302. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  45303. + irq_mask) {
  45304. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  45305. + host_priv->sg_done;
  45306. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  45307. + host_priv->sg_done;
  45308. +
  45309. + /* acknowledge interrupt */
  45310. + sdhci_bcm2708_raw_writel(host, irq_mask,
  45311. + SDHCI_INT_STATUS);
  45312. +
  45313. + BUG_ON(0 == bytes);
  45314. +
  45315. + if (data->flags & MMC_DATA_READ)
  45316. + sdhci_platdma_read(host, addr, bytes);
  45317. + else
  45318. + sdhci_platdma_write(host, addr, bytes);
  45319. + } else {
  45320. + DBG("PDMA - wait avail\n");
  45321. + /* may generate an IRQ if already present */
  45322. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  45323. + SDHCI_INT_SPACE_AVAIL);
  45324. + }
  45325. + } else {
  45326. + if (sync_after_dma) {
  45327. + /* On the Arasan controller the stop command (which will be
  45328. + scheduled after this completes) does not seem to work
  45329. + properly if we allow it to be issued when we are
  45330. + transferring data to/from the SD card.
  45331. + We get CRC and DEND errors unless we wait for
  45332. + the SD controller to finish reading/writing to the card. */
  45333. + u32 state_mask;
  45334. + int timeout=3*1000*1000;
  45335. +
  45336. + DBG("PDMA over - sync card\n");
  45337. + if (data->flags & MMC_DATA_READ)
  45338. + state_mask = SDHCI_DOING_READ;
  45339. + else
  45340. + state_mask = SDHCI_DOING_WRITE;
  45341. +
  45342. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  45343. + & state_mask) && --timeout > 0)
  45344. + {
  45345. + udelay(1);
  45346. + continue;
  45347. + }
  45348. + if (timeout <= 0)
  45349. + printk(KERN_ERR"%s: final %s to SD card still "
  45350. + "running\n",
  45351. + mmc_hostname(host->mmc),
  45352. + data->flags & MMC_DATA_READ? "read": "write");
  45353. + }
  45354. + if (host_priv->complete) {
  45355. + (*host_priv->complete)(host);
  45356. + DBG("PDMA %s complete\n",
  45357. + data->flags & MMC_DATA_READ?"read":"write");
  45358. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  45359. + SDHCI_INT_SPACE_AVAIL);
  45360. + }
  45361. + }
  45362. +// spin_unlock_irqrestore(&host->lock, flags);
  45363. +}
  45364. +
  45365. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  45366. +{
  45367. + irqreturn_t result = IRQ_NONE;
  45368. + struct sdhci_host *host = dev_id;
  45369. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45370. + u32 dma_cs; /* control and status register */
  45371. +
  45372. + BUG_ON(NULL == dev_id);
  45373. + BUG_ON(NULL == host_priv->dma_chan_base);
  45374. +
  45375. + sdhci_spin_lock(host);
  45376. +
  45377. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  45378. +
  45379. + if (dma_cs & BCM2708_DMA_ERR) {
  45380. + unsigned long debug;
  45381. + debug = readl(host_priv->dma_chan_base +
  45382. + BCM2708_DMA_DEBUG);
  45383. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  45384. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  45385. + (unsigned long)debug);
  45386. + /* reset error */
  45387. + writel(debug, host_priv->dma_chan_base +
  45388. + BCM2708_DMA_DEBUG);
  45389. + }
  45390. + if (dma_cs & BCM2708_DMA_INT) {
  45391. + /* acknowledge interrupt */
  45392. + writel(BCM2708_DMA_INT,
  45393. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  45394. +
  45395. + dsb(); /* ARM data synchronization (push) operation */
  45396. +
  45397. + if (!host_priv->dma_wanted) {
  45398. + /* ignore this interrupt - it was reset */
  45399. + if (extra_messages)
  45400. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  45401. + "results were reset\n",
  45402. + mmc_hostname(host->mmc), dma_cs);
  45403. +#ifdef CHECK_DMA_USE
  45404. + printk(KERN_INFO "%s: now %"FMT_HPT
  45405. + " started %lu reset %lu stopped %lu\n",
  45406. + mmc_hostname(host->mmc), hptime(),
  45407. + since_ns(host_priv->when_started),
  45408. + since_ns(host_priv->when_reset),
  45409. + since_ns(host_priv->when_stopped));
  45410. + host_priv->dmas_pending--;
  45411. +#endif
  45412. + } else
  45413. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  45414. +
  45415. + result = IRQ_HANDLED;
  45416. + }
  45417. + sdhci_spin_unlock(host);
  45418. +
  45419. + return result;
  45420. +}
  45421. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  45422. +
  45423. +
  45424. +/***************************************************************************** \
  45425. + * *
  45426. + * Device Attributes *
  45427. + * *
  45428. +\*****************************************************************************/
  45429. +
  45430. +
  45431. +/**
  45432. + * Show the DMA-using status
  45433. + */
  45434. +static ssize_t attr_dma_show(struct device *_dev,
  45435. + struct device_attribute *attr, char *buf)
  45436. +{
  45437. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  45438. +
  45439. + if (host) {
  45440. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  45441. + return sprintf(buf, "%d\n", use_dma);
  45442. + } else
  45443. + return -EINVAL;
  45444. +}
  45445. +
  45446. +/**
  45447. + * Set the DMA-using status
  45448. + */
  45449. +static ssize_t attr_dma_store(struct device *_dev,
  45450. + struct device_attribute *attr,
  45451. + const char *buf, size_t count)
  45452. +{
  45453. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  45454. +
  45455. + if (host) {
  45456. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45457. + int on = simple_strtol(buf, NULL, 0);
  45458. + if (on) {
  45459. + host->flags |= SDHCI_USE_PLATDMA;
  45460. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  45461. + printk(KERN_INFO "%s: DMA enabled\n",
  45462. + mmc_hostname(host->mmc));
  45463. + } else {
  45464. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  45465. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  45466. + printk(KERN_INFO "%s: DMA disabled\n",
  45467. + mmc_hostname(host->mmc));
  45468. + }
  45469. +#endif
  45470. + return count;
  45471. + } else
  45472. + return -EINVAL;
  45473. +}
  45474. +
  45475. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  45476. +
  45477. +
  45478. +/**
  45479. + * Show the DMA wait states used
  45480. + */
  45481. +static ssize_t attr_dmawait_show(struct device *_dev,
  45482. + struct device_attribute *attr, char *buf)
  45483. +{
  45484. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  45485. +
  45486. + if (host) {
  45487. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45488. + int dmawait = host_priv->dma_waits;
  45489. + return sprintf(buf, "%d\n", dmawait);
  45490. + } else
  45491. + return -EINVAL;
  45492. +}
  45493. +
  45494. +/**
  45495. + * Set the DMA wait state used
  45496. + */
  45497. +static ssize_t attr_dmawait_store(struct device *_dev,
  45498. + struct device_attribute *attr,
  45499. + const char *buf, size_t count)
  45500. +{
  45501. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  45502. +
  45503. + if (host) {
  45504. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45505. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45506. + int dma_waits = simple_strtol(buf, NULL, 0);
  45507. + if (dma_waits >= 0 && dma_waits < 32)
  45508. + host_priv->dma_waits = dma_waits;
  45509. + else
  45510. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  45511. + mmc_hostname(host->mmc), dma_waits);
  45512. +#endif
  45513. + return count;
  45514. + } else
  45515. + return -EINVAL;
  45516. +}
  45517. +
  45518. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  45519. + attr_dmawait_show, attr_dmawait_store);
  45520. +
  45521. +
  45522. +/**
  45523. + * Show the DMA-using status
  45524. + */
  45525. +static ssize_t attr_status_show(struct device *_dev,
  45526. + struct device_attribute *attr, char *buf)
  45527. +{
  45528. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  45529. +
  45530. + if (host) {
  45531. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45532. + return sprintf(buf,
  45533. + "present: yes\n"
  45534. + "power: %s\n"
  45535. + "clock: %u Hz\n"
  45536. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45537. + "dma: %s (%d waits)\n",
  45538. +#else
  45539. + "dma: unconfigured\n",
  45540. +#endif
  45541. + "always on",
  45542. + host->clock
  45543. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45544. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  45545. + , host_priv->dma_waits
  45546. +#endif
  45547. + );
  45548. + } else
  45549. + return -EINVAL;
  45550. +}
  45551. +
  45552. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  45553. +
  45554. +/***************************************************************************** \
  45555. + * *
  45556. + * Power Management *
  45557. + * *
  45558. +\*****************************************************************************/
  45559. +
  45560. +
  45561. +#ifdef CONFIG_PM
  45562. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  45563. +{
  45564. + struct sdhci_host *host = (struct sdhci_host *)
  45565. + platform_get_drvdata(dev);
  45566. + int ret = 0;
  45567. +
  45568. + if (host->mmc) {
  45569. + //ret = mmc_suspend_host(host->mmc);
  45570. + }
  45571. +
  45572. + return ret;
  45573. +}
  45574. +
  45575. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  45576. +{
  45577. + struct sdhci_host *host = (struct sdhci_host *)
  45578. + platform_get_drvdata(dev);
  45579. + int ret = 0;
  45580. +
  45581. + if (host->mmc) {
  45582. + //ret = mmc_resume_host(host->mmc);
  45583. + }
  45584. +
  45585. + return ret;
  45586. +}
  45587. +#endif
  45588. +
  45589. +
  45590. +/*****************************************************************************\
  45591. + * *
  45592. + * Device quirk functions. Implemented as local ops because the flags *
  45593. + * field is out of space with newer kernels. This implementation can be *
  45594. + * back ported to older kernels as well. *
  45595. +\****************************************************************************/
  45596. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  45597. +{
  45598. + return 1;
  45599. +}
  45600. +
  45601. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  45602. +{
  45603. + return 1;
  45604. +}
  45605. +
  45606. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  45607. +{
  45608. + return 1;
  45609. +}
  45610. +
  45611. +/***************************************************************************** \
  45612. + * *
  45613. + * Device ops *
  45614. + * *
  45615. +\*****************************************************************************/
  45616. +
  45617. +static struct sdhci_ops sdhci_bcm2708_ops = {
  45618. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  45619. + .read_l = sdhci_bcm2708_readl,
  45620. + .read_w = sdhci_bcm2708_readw,
  45621. + .read_b = sdhci_bcm2708_readb,
  45622. + .write_l = sdhci_bcm2708_writel,
  45623. + .write_w = sdhci_bcm2708_writew,
  45624. + .write_b = sdhci_bcm2708_writeb,
  45625. +#else
  45626. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  45627. +#endif
  45628. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  45629. +
  45630. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45631. + // Platform DMA operations
  45632. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  45633. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  45634. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  45635. +#endif
  45636. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  45637. +};
  45638. +
  45639. +/*****************************************************************************\
  45640. + * *
  45641. + * Device probing/removal *
  45642. + * *
  45643. +\*****************************************************************************/
  45644. +
  45645. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  45646. +{
  45647. + struct sdhci_host *host;
  45648. + struct resource *iomem;
  45649. + struct sdhci_bcm2708_priv *host_priv;
  45650. + int ret;
  45651. +
  45652. + BUG_ON(pdev == NULL);
  45653. +
  45654. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  45655. + if (!iomem) {
  45656. + ret = -ENOMEM;
  45657. + goto err;
  45658. + }
  45659. +
  45660. + if (resource_size(iomem) != 0x100)
  45661. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  45662. + "experience problems.\n");
  45663. +
  45664. + if (pdev->dev.parent)
  45665. + host = sdhci_alloc_host(pdev->dev.parent,
  45666. + sizeof(struct sdhci_bcm2708_priv));
  45667. + else
  45668. + host = sdhci_alloc_host(&pdev->dev,
  45669. + sizeof(struct sdhci_bcm2708_priv));
  45670. +
  45671. + if (IS_ERR(host)) {
  45672. + ret = PTR_ERR(host);
  45673. + goto err;
  45674. + }
  45675. + if (missing_status) {
  45676. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  45677. + }
  45678. +
  45679. + if( spurious_crc_acmd51 ) {
  45680. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  45681. + }
  45682. +
  45683. +
  45684. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  45685. +
  45686. + host->hw_name = "BCM2708_Arasan";
  45687. + host->ops = &sdhci_bcm2708_ops;
  45688. + host->irq = platform_get_irq(pdev, 0);
  45689. + host->second_irq = 0;
  45690. +
  45691. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  45692. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  45693. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  45694. + SDHCI_QUIRK_MISSING_CAPS |
  45695. + SDHCI_QUIRK_NO_HISPD_BIT |
  45696. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  45697. +
  45698. +
  45699. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45700. + host->flags = SDHCI_USE_PLATDMA;
  45701. +#endif
  45702. +
  45703. + if (!request_mem_region(iomem->start, resource_size(iomem),
  45704. + mmc_hostname(host->mmc))) {
  45705. + dev_err(&pdev->dev, "cannot request region\n");
  45706. + ret = -EBUSY;
  45707. + goto err_request;
  45708. + }
  45709. +
  45710. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  45711. + if (!host->ioaddr) {
  45712. + dev_err(&pdev->dev, "failed to remap registers\n");
  45713. + ret = -ENOMEM;
  45714. + goto err_remap;
  45715. + }
  45716. +
  45717. + host_priv = SDHCI_HOST_PRIV(host);
  45718. +
  45719. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45720. + host_priv->dma_wanted = 0;
  45721. +#ifdef CHECK_DMA_USE
  45722. + host_priv->dmas_pending = 0;
  45723. + host_priv->when_started = 0;
  45724. + host_priv->when_reset = 0;
  45725. + host_priv->when_stopped = 0;
  45726. +#endif
  45727. + host_priv->sg_ix = 0;
  45728. + host_priv->sg_done = 0;
  45729. + host_priv->complete = NULL;
  45730. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  45731. +
  45732. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  45733. + &host_priv->cb_handle,
  45734. + GFP_KERNEL);
  45735. + if (!host_priv->cb_base) {
  45736. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  45737. + ret = -ENOMEM;
  45738. + goto err_alloc_cb;
  45739. + }
  45740. +
  45741. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  45742. + &host_priv->dma_chan_base,
  45743. + &host_priv->dma_irq);
  45744. + if (ret < 0) {
  45745. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  45746. + goto err_add_dma;
  45747. + }
  45748. + host_priv->dma_chan = ret;
  45749. +
  45750. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  45751. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  45752. + if (ret) {
  45753. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  45754. + goto err_add_dma_irq;
  45755. + }
  45756. + host->second_irq = host_priv->dma_irq;
  45757. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  45758. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  45759. + host_priv->dma_chan, host_priv->dma_chan_base,
  45760. + host_priv->dma_irq);
  45761. +
  45762. + // we support 3.3V
  45763. + host->caps |= SDHCI_CAN_VDD_330;
  45764. + if (allow_highspeed)
  45765. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  45766. +
  45767. + /* single block writes cause data loss with some SD cards! */
  45768. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  45769. +#endif
  45770. +
  45771. + ret = sdhci_add_host(host);
  45772. + if (ret)
  45773. + goto err_add_host;
  45774. +
  45775. + platform_set_drvdata(pdev, host);
  45776. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  45777. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  45778. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  45779. +
  45780. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45781. + /* enable extension fifo for paced DMA transfers */
  45782. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  45783. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  45784. +#endif
  45785. +
  45786. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  45787. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  45788. + host_priv->dma_chan, host_priv->dma_irq);
  45789. +
  45790. + return 0;
  45791. +
  45792. +err_add_host:
  45793. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45794. + free_irq(host_priv->dma_irq, host);
  45795. +err_add_dma_irq:
  45796. + bcm_dma_chan_free(host_priv->dma_chan);
  45797. +err_add_dma:
  45798. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  45799. + host_priv->cb_handle);
  45800. +err_alloc_cb:
  45801. +#endif
  45802. + iounmap(host->ioaddr);
  45803. +err_remap:
  45804. + release_mem_region(iomem->start, resource_size(iomem));
  45805. +err_request:
  45806. + sdhci_free_host(host);
  45807. +err:
  45808. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  45809. + return ret;
  45810. +}
  45811. +
  45812. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  45813. +{
  45814. + struct sdhci_host *host = platform_get_drvdata(pdev);
  45815. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  45816. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  45817. + int dead;
  45818. + u32 scratch;
  45819. +
  45820. + dead = 0;
  45821. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  45822. + if (scratch == (u32)-1)
  45823. + dead = 1;
  45824. +
  45825. + device_remove_file(&pdev->dev, &dev_attr_status);
  45826. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  45827. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  45828. +
  45829. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  45830. + free_irq(host_priv->dma_irq, host);
  45831. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  45832. + host_priv->cb_handle);
  45833. +#endif
  45834. + sdhci_remove_host(host, dead);
  45835. + iounmap(host->ioaddr);
  45836. + release_mem_region(iomem->start, resource_size(iomem));
  45837. + sdhci_free_host(host);
  45838. + platform_set_drvdata(pdev, NULL);
  45839. +
  45840. + return 0;
  45841. +}
  45842. +
  45843. +static struct platform_driver sdhci_bcm2708_driver = {
  45844. + .driver = {
  45845. + .name = DRIVER_NAME,
  45846. + .owner = THIS_MODULE,
  45847. + },
  45848. + .probe = sdhci_bcm2708_probe,
  45849. + .remove = sdhci_bcm2708_remove,
  45850. +
  45851. +#ifdef CONFIG_PM
  45852. + .suspend = sdhci_bcm2708_suspend,
  45853. + .resume = sdhci_bcm2708_resume,
  45854. +#endif
  45855. +
  45856. +};
  45857. +
  45858. +/*****************************************************************************\
  45859. + * *
  45860. + * Driver init/exit *
  45861. + * *
  45862. +\*****************************************************************************/
  45863. +
  45864. +static int __init sdhci_drv_init(void)
  45865. +{
  45866. + return platform_driver_register(&sdhci_bcm2708_driver);
  45867. +}
  45868. +
  45869. +static void __exit sdhci_drv_exit(void)
  45870. +{
  45871. + platform_driver_unregister(&sdhci_bcm2708_driver);
  45872. +}
  45873. +
  45874. +module_init(sdhci_drv_init);
  45875. +module_exit(sdhci_drv_exit);
  45876. +
  45877. +module_param(allow_highspeed, bool, 0444);
  45878. +module_param(emmc_clock_freq, int, 0444);
  45879. +module_param(sync_after_dma, bool, 0444);
  45880. +module_param(missing_status, bool, 0444);
  45881. +module_param(spurious_crc_acmd51, bool, 0444);
  45882. +module_param(enable_llm, bool, 0444);
  45883. +module_param(cycle_delay, int, 0444);
  45884. +module_param(extra_messages, bool, 0444);
  45885. +
  45886. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  45887. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  45888. +MODULE_LICENSE("GPL v2");
  45889. +MODULE_ALIAS("platform:"DRIVER_NAME);
  45890. +
  45891. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  45892. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  45893. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  45894. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  45895. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  45896. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  45897. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  45898. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci.c linux-rpi/drivers/mmc/host/sdhci.c
  45899. --- linux-3.12.38/drivers/mmc/host/sdhci.c 2015-02-16 16:15:42.000000000 +0100
  45900. +++ linux-rpi/drivers/mmc/host/sdhci.c 2015-03-11 10:46:10.585835779 +0100
  45901. @@ -28,6 +28,7 @@
  45902. #include <linux/mmc/mmc.h>
  45903. #include <linux/mmc/host.h>
  45904. #include <linux/mmc/card.h>
  45905. +#include <linux/mmc/sd.h>
  45906. #include <linux/mmc/slot-gpio.h>
  45907. #include "sdhci.h"
  45908. @@ -131,6 +132,42 @@
  45909. * Low level functions *
  45910. * *
  45911. \*****************************************************************************/
  45912. +static int sdhci_locked=0;
  45913. +void sdhci_spin_lock(struct sdhci_host *host)
  45914. +{
  45915. + spin_lock(&host->lock);
  45916. +}
  45917. +
  45918. +void sdhci_spin_unlock(struct sdhci_host *host)
  45919. +{
  45920. + spin_unlock(&host->lock);
  45921. +}
  45922. +
  45923. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  45924. +{
  45925. + spin_lock_irqsave(&host->lock,*flags);
  45926. +}
  45927. +
  45928. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  45929. +{
  45930. + spin_unlock_irqrestore(&host->lock,flags);
  45931. +}
  45932. +
  45933. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  45934. +{
  45935. +}
  45936. +
  45937. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  45938. +{
  45939. +}
  45940. +
  45941. +
  45942. +#undef spin_lock_irqsave
  45943. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  45944. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  45945. +
  45946. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  45947. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  45948. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  45949. {
  45950. @@ -300,7 +337,7 @@
  45951. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  45952. unsigned long flags;
  45953. - spin_lock_irqsave(&host->lock, flags);
  45954. + sdhci_spin_lock_irqsave(host, &flags);
  45955. if (host->runtime_suspended)
  45956. goto out;
  45957. @@ -310,7 +347,7 @@
  45958. else
  45959. sdhci_activate_led(host);
  45960. out:
  45961. - spin_unlock_irqrestore(&host->lock, flags);
  45962. + sdhci_spin_unlock_irqrestore(host, flags);
  45963. }
  45964. #endif
  45965. @@ -327,7 +364,7 @@
  45966. u32 uninitialized_var(scratch);
  45967. u8 *buf;
  45968. - DBG("PIO reading\n");
  45969. + DBG("PIO reading %db\n", host->data->blksz);
  45970. blksize = host->data->blksz;
  45971. chunk = 0;
  45972. @@ -372,7 +409,7 @@
  45973. u32 scratch;
  45974. u8 *buf;
  45975. - DBG("PIO writing\n");
  45976. + DBG("PIO writing %db\n", host->data->blksz);
  45977. blksize = host->data->blksz;
  45978. chunk = 0;
  45979. @@ -411,19 +448,28 @@
  45980. local_irq_restore(flags);
  45981. }
  45982. -static void sdhci_transfer_pio(struct sdhci_host *host)
  45983. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  45984. {
  45985. u32 mask;
  45986. + u32 state = 0;
  45987. + u32 intmask;
  45988. + int available;
  45989. BUG_ON(!host->data);
  45990. if (host->blocks == 0)
  45991. return;
  45992. - if (host->data->flags & MMC_DATA_READ)
  45993. + if (host->data->flags & MMC_DATA_READ) {
  45994. mask = SDHCI_DATA_AVAILABLE;
  45995. - else
  45996. + intmask = SDHCI_INT_DATA_AVAIL;
  45997. + } else {
  45998. mask = SDHCI_SPACE_AVAILABLE;
  45999. + intmask = SDHCI_INT_SPACE_AVAIL;
  46000. + }
  46001. +
  46002. + /* initially we can see whether we can procede using intstate */
  46003. + available = (intstate & intmask);
  46004. /*
  46005. * Some controllers (JMicron JMB38x) mess up the buffer bits
  46006. @@ -434,7 +480,7 @@
  46007. (host->data->blocks == 1))
  46008. mask = ~0;
  46009. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  46010. + while (available) {
  46011. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  46012. udelay(100);
  46013. @@ -446,9 +492,12 @@
  46014. host->blocks--;
  46015. if (host->blocks == 0)
  46016. break;
  46017. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  46018. + available = state & mask;
  46019. + break;
  46020. }
  46021. - DBG("PIO transfer complete.\n");
  46022. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  46023. }
  46024. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  46025. @@ -721,7 +770,9 @@
  46026. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  46027. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  46028. - if (host->flags & SDHCI_REQ_USE_DMA)
  46029. + /* platform DMA will begin on receipt of PIO irqs */
  46030. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  46031. + !(host->flags & SDHCI_USE_PLATDMA))
  46032. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  46033. else
  46034. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  46035. @@ -753,44 +804,25 @@
  46036. host->data_early = 0;
  46037. host->data->bytes_xfered = 0;
  46038. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  46039. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  46040. host->flags |= SDHCI_REQ_USE_DMA;
  46041. /*
  46042. * FIXME: This doesn't account for merging when mapping the
  46043. * scatterlist.
  46044. */
  46045. - if (host->flags & SDHCI_REQ_USE_DMA) {
  46046. - int broken, i;
  46047. - struct scatterlist *sg;
  46048. -
  46049. - broken = 0;
  46050. - if (host->flags & SDHCI_USE_ADMA) {
  46051. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  46052. - broken = 1;
  46053. - } else {
  46054. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  46055. - broken = 1;
  46056. - }
  46057. -
  46058. - if (unlikely(broken)) {
  46059. - for_each_sg(data->sg, sg, data->sg_len, i) {
  46060. - if (sg->length & 0x3) {
  46061. - DBG("Reverting to PIO because of "
  46062. - "transfer size (%d)\n",
  46063. - sg->length);
  46064. - host->flags &= ~SDHCI_REQ_USE_DMA;
  46065. - break;
  46066. - }
  46067. - }
  46068. - }
  46069. - }
  46070. /*
  46071. * The assumption here being that alignment is the same after
  46072. * translation to device address space.
  46073. */
  46074. - if (host->flags & SDHCI_REQ_USE_DMA) {
  46075. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  46076. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  46077. +
  46078. + if (! sdhci_platdma_dmaable(host, data))
  46079. + host->flags &= ~SDHCI_REQ_USE_DMA;
  46080. +
  46081. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  46082. int broken, i;
  46083. struct scatterlist *sg;
  46084. @@ -849,7 +881,8 @@
  46085. */
  46086. WARN_ON(1);
  46087. host->flags &= ~SDHCI_REQ_USE_DMA;
  46088. - } else {
  46089. + } else
  46090. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  46091. WARN_ON(sg_cnt != 1);
  46092. sdhci_writel(host, sg_dma_address(data->sg),
  46093. SDHCI_DMA_ADDRESS);
  46094. @@ -865,11 +898,13 @@
  46095. if (host->version >= SDHCI_SPEC_200) {
  46096. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  46097. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  46098. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  46099. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  46100. (host->flags & SDHCI_USE_ADMA))
  46101. ctrl |= SDHCI_CTRL_ADMA32;
  46102. else
  46103. ctrl |= SDHCI_CTRL_SDMA;
  46104. + }
  46105. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  46106. }
  46107. @@ -921,7 +956,8 @@
  46108. if (data->flags & MMC_DATA_READ)
  46109. mode |= SDHCI_TRNS_READ;
  46110. - if (host->flags & SDHCI_REQ_USE_DMA)
  46111. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  46112. + !(host->flags & SDHCI_USE_PLATDMA))
  46113. mode |= SDHCI_TRNS_DMA;
  46114. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  46115. @@ -937,13 +973,16 @@
  46116. host->data = NULL;
  46117. if (host->flags & SDHCI_REQ_USE_DMA) {
  46118. - if (host->flags & SDHCI_USE_ADMA)
  46119. - sdhci_adma_table_post(host, data);
  46120. - else {
  46121. + /* we may have to abandon an ongoing platform DMA */
  46122. + if (host->flags & SDHCI_USE_PLATDMA)
  46123. + sdhci_platdma_reset(host, data);
  46124. +
  46125. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  46126. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  46127. data->sg_len, (data->flags & MMC_DATA_READ) ?
  46128. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  46129. - }
  46130. + } else if (host->flags & SDHCI_USE_ADMA)
  46131. + sdhci_adma_table_post(host, data);
  46132. }
  46133. /*
  46134. @@ -996,6 +1035,12 @@
  46135. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  46136. mask |= SDHCI_DATA_INHIBIT;
  46137. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  46138. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  46139. + // which might cause the STATUS command to get stuck when a data operation is in flow
  46140. + mask |= SDHCI_DATA_INHIBIT;
  46141. + }
  46142. +
  46143. /* We shouldn't wait for data inihibit for stop commands, even
  46144. though they might use busy signaling */
  46145. if (host->mrq->data && (cmd == host->mrq->data->stop))
  46146. @@ -1011,12 +1056,20 @@
  46147. return;
  46148. }
  46149. timeout--;
  46150. + sdhci_spin_enable_schedule(host);
  46151. mdelay(1);
  46152. + sdhci_spin_disable_schedule(host);
  46153. }
  46154. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  46155. + sdhci_readl(host, SDHCI_INT_STATUS));
  46156. mod_timer(&host->timer, jiffies + 10 * HZ);
  46157. host->cmd = cmd;
  46158. + if (host->last_cmdop == MMC_APP_CMD)
  46159. + host->last_cmdop = -cmd->opcode;
  46160. + else
  46161. + host->last_cmdop = cmd->opcode;
  46162. sdhci_prepare_data(host, cmd);
  46163. @@ -1232,7 +1285,9 @@
  46164. return;
  46165. }
  46166. timeout--;
  46167. + sdhci_spin_enable_schedule(host);
  46168. mdelay(1);
  46169. + sdhci_spin_disable_schedule(host);
  46170. }
  46171. clk |= SDHCI_CLOCK_CARD_EN;
  46172. @@ -1333,9 +1388,7 @@
  46173. sdhci_runtime_pm_get(host);
  46174. - present = mmc_gpio_get_cd(host->mmc);
  46175. -
  46176. - spin_lock_irqsave(&host->lock, flags);
  46177. + sdhci_spin_lock_irqsave(host, &flags);
  46178. WARN_ON(host->mrq != NULL);
  46179. @@ -1363,6 +1416,7 @@
  46180. * zero: cd-gpio is used, and card is removed
  46181. * one: cd-gpio is used, and card is present
  46182. */
  46183. + present = mmc_gpio_get_cd(host->mmc);
  46184. if (present < 0) {
  46185. /* If polling, assume that the card is always present. */
  46186. if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
  46187. @@ -1392,9 +1446,9 @@
  46188. mmc->card->type == MMC_TYPE_MMC ?
  46189. MMC_SEND_TUNING_BLOCK_HS200 :
  46190. MMC_SEND_TUNING_BLOCK;
  46191. - spin_unlock_irqrestore(&host->lock, flags);
  46192. + sdhci_spin_unlock_irqrestore(host, flags);
  46193. sdhci_execute_tuning(mmc, tuning_opcode);
  46194. - spin_lock_irqsave(&host->lock, flags);
  46195. + sdhci_spin_lock_irqsave(host, &flags);
  46196. /* Restore original mmc_request structure */
  46197. host->mrq = mrq;
  46198. @@ -1408,7 +1462,7 @@
  46199. }
  46200. mmiowb();
  46201. - spin_unlock_irqrestore(&host->lock, flags);
  46202. + sdhci_spin_unlock_irqrestore(host, flags);
  46203. }
  46204. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  46205. @@ -1417,10 +1471,10 @@
  46206. int vdd_bit = -1;
  46207. u8 ctrl;
  46208. - spin_lock_irqsave(&host->lock, flags);
  46209. + sdhci_spin_lock_irqsave(host, &flags);
  46210. if (host->flags & SDHCI_DEVICE_DEAD) {
  46211. - spin_unlock_irqrestore(&host->lock, flags);
  46212. + sdhci_spin_unlock_irqrestore(host, flags);
  46213. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  46214. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  46215. return;
  46216. @@ -1447,9 +1501,9 @@
  46217. vdd_bit = sdhci_set_power(host, ios->vdd);
  46218. if (host->vmmc && vdd_bit != -1) {
  46219. - spin_unlock_irqrestore(&host->lock, flags);
  46220. + sdhci_spin_unlock_irqrestore(host, flags);
  46221. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  46222. - spin_lock_irqsave(&host->lock, flags);
  46223. + sdhci_spin_lock_irqsave(host, &flags);
  46224. }
  46225. if (host->ops->platform_send_init_74_clocks)
  46226. @@ -1586,7 +1640,7 @@
  46227. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  46228. mmiowb();
  46229. - spin_unlock_irqrestore(&host->lock, flags);
  46230. + sdhci_spin_unlock_irqrestore(host, flags);
  46231. }
  46232. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  46233. @@ -1634,7 +1688,7 @@
  46234. unsigned long flags;
  46235. int is_readonly;
  46236. - spin_lock_irqsave(&host->lock, flags);
  46237. + sdhci_spin_lock_irqsave(host, &flags);
  46238. if (host->flags & SDHCI_DEVICE_DEAD)
  46239. is_readonly = 0;
  46240. @@ -1644,7 +1698,7 @@
  46241. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  46242. & SDHCI_WRITE_PROTECT);
  46243. - spin_unlock_irqrestore(&host->lock, flags);
  46244. + sdhci_spin_unlock_irqrestore(host, flags);
  46245. /* This quirk needs to be replaced by a callback-function later */
  46246. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  46247. @@ -1717,9 +1771,9 @@
  46248. struct sdhci_host *host = mmc_priv(mmc);
  46249. unsigned long flags;
  46250. - spin_lock_irqsave(&host->lock, flags);
  46251. + sdhci_spin_lock_irqsave(host, &flags);
  46252. sdhci_enable_sdio_irq_nolock(host, enable);
  46253. - spin_unlock_irqrestore(&host->lock, flags);
  46254. + sdhci_spin_unlock_irqrestore(host, flags);
  46255. }
  46256. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  46257. @@ -2062,18 +2116,15 @@
  46258. {
  46259. struct sdhci_host *host = mmc_priv(mmc);
  46260. unsigned long flags;
  46261. - int present;
  46262. /* First check if client has provided their own card event */
  46263. if (host->ops->card_event)
  46264. host->ops->card_event(host);
  46265. - present = sdhci_do_get_cd(host);
  46266. -
  46267. - spin_lock_irqsave(&host->lock, flags);
  46268. + sdhci_spin_lock_irqsave(host, &flags);
  46269. /* Check host->mrq first in case we are runtime suspended */
  46270. - if (host->mrq && !present) {
  46271. + if (host->mrq && !sdhci_do_get_cd(host)) {
  46272. pr_err("%s: Card removed during transfer!\n",
  46273. mmc_hostname(host->mmc));
  46274. pr_err("%s: Resetting controller.\n",
  46275. @@ -2086,7 +2137,7 @@
  46276. tasklet_schedule(&host->finish_tasklet);
  46277. }
  46278. - spin_unlock_irqrestore(&host->lock, flags);
  46279. + sdhci_spin_unlock_irqrestore(host, flags);
  46280. }
  46281. static const struct mmc_host_ops sdhci_ops = {
  46282. @@ -2125,14 +2176,14 @@
  46283. host = (struct sdhci_host*)param;
  46284. - spin_lock_irqsave(&host->lock, flags);
  46285. + sdhci_spin_lock_irqsave(host, &flags);
  46286. /*
  46287. * If this tasklet gets rescheduled while running, it will
  46288. * be run again afterwards but without any active request.
  46289. */
  46290. if (!host->mrq) {
  46291. - spin_unlock_irqrestore(&host->lock, flags);
  46292. + sdhci_spin_unlock_irqrestore(host, flags);
  46293. return;
  46294. }
  46295. @@ -2170,7 +2221,7 @@
  46296. #endif
  46297. mmiowb();
  46298. - spin_unlock_irqrestore(&host->lock, flags);
  46299. + sdhci_spin_unlock_irqrestore(host, flags);
  46300. mmc_request_done(host->mmc, mrq);
  46301. sdhci_runtime_pm_put(host);
  46302. @@ -2183,11 +2234,11 @@
  46303. host = (struct sdhci_host*)data;
  46304. - spin_lock_irqsave(&host->lock, flags);
  46305. + sdhci_spin_lock_irqsave(host, &flags);
  46306. if (host->mrq) {
  46307. pr_err("%s: Timeout waiting for hardware "
  46308. - "interrupt.\n", mmc_hostname(host->mmc));
  46309. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  46310. sdhci_dumpregs(host);
  46311. if (host->data) {
  46312. @@ -2204,7 +2255,7 @@
  46313. }
  46314. mmiowb();
  46315. - spin_unlock_irqrestore(&host->lock, flags);
  46316. + sdhci_spin_unlock_irqrestore(host, flags);
  46317. }
  46318. static void sdhci_tuning_timer(unsigned long data)
  46319. @@ -2214,11 +2265,11 @@
  46320. host = (struct sdhci_host *)data;
  46321. - spin_lock_irqsave(&host->lock, flags);
  46322. + sdhci_spin_lock_irqsave(host, &flags);
  46323. host->flags |= SDHCI_NEEDS_RETUNING;
  46324. - spin_unlock_irqrestore(&host->lock, flags);
  46325. + sdhci_spin_unlock_irqrestore(host, flags);
  46326. }
  46327. /*****************************************************************************\
  46328. @@ -2232,10 +2283,13 @@
  46329. BUG_ON(intmask == 0);
  46330. if (!host->cmd) {
  46331. + if (!(host->ops->extra_ints)) {
  46332. pr_err("%s: Got command interrupt 0x%08x even "
  46333. "though no command operation was in progress.\n",
  46334. mmc_hostname(host->mmc), (unsigned)intmask);
  46335. sdhci_dumpregs(host);
  46336. + } else
  46337. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  46338. return;
  46339. }
  46340. @@ -2305,6 +2359,19 @@
  46341. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  46342. #endif
  46343. +static void sdhci_data_end(struct sdhci_host *host)
  46344. +{
  46345. + if (host->cmd) {
  46346. + /*
  46347. + * Data managed to finish before the
  46348. + * command completed. Make sure we do
  46349. + * things in the proper order.
  46350. + */
  46351. + host->data_early = 1;
  46352. + } else
  46353. + sdhci_finish_data(host);
  46354. +}
  46355. +
  46356. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  46357. {
  46358. u32 command;
  46359. @@ -2334,23 +2401,39 @@
  46360. }
  46361. }
  46362. + if (!(host->ops->extra_ints)) {
  46363. pr_err("%s: Got data interrupt 0x%08x even "
  46364. "though no data operation was in progress.\n",
  46365. mmc_hostname(host->mmc), (unsigned)intmask);
  46366. sdhci_dumpregs(host);
  46367. + } else
  46368. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  46369. return;
  46370. }
  46371. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  46372. host->data->error = -ETIMEDOUT;
  46373. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  46374. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  46375. + DBG("end error in cmd %d\n", host->last_cmdop);
  46376. + if (host->ops->spurious_crc_acmd51 &&
  46377. + host->last_cmdop == -SD_APP_SEND_SCR) {
  46378. + DBG("ignoring spurious data_end_bit error\n");
  46379. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  46380. + } else
  46381. host->data->error = -EILSEQ;
  46382. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  46383. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  46384. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  46385. - != MMC_BUS_TEST_R)
  46386. + != MMC_BUS_TEST_R) {
  46387. + DBG("crc error in cmd %d\n", host->last_cmdop);
  46388. + if (host->ops->spurious_crc_acmd51 &&
  46389. + host->last_cmdop == -SD_APP_SEND_SCR) {
  46390. + DBG("ignoring spurious data_crc_bit error\n");
  46391. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  46392. + } else {
  46393. host->data->error = -EILSEQ;
  46394. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  46395. + }
  46396. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  46397. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  46398. sdhci_show_adma_error(host);
  46399. host->data->error = -EIO;
  46400. @@ -2358,11 +2441,18 @@
  46401. host->ops->adma_workaround(host, intmask);
  46402. }
  46403. - if (host->data->error)
  46404. + if (host->data->error) {
  46405. + DBG("finish request early on error %d\n", host->data->error);
  46406. sdhci_finish_data(host);
  46407. - else {
  46408. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  46409. - sdhci_transfer_pio(host);
  46410. + } else {
  46411. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  46412. + if (host->flags & SDHCI_REQ_USE_DMA) {
  46413. + /* possible only in PLATDMA mode */
  46414. + sdhci_platdma_avail(host, &intmask,
  46415. + &sdhci_data_end);
  46416. + } else
  46417. + sdhci_transfer_pio(host, intmask);
  46418. + }
  46419. /*
  46420. * We currently don't do anything fancy with DMA
  46421. @@ -2391,18 +2481,8 @@
  46422. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  46423. }
  46424. - if (intmask & SDHCI_INT_DATA_END) {
  46425. - if (host->cmd) {
  46426. - /*
  46427. - * Data managed to finish before the
  46428. - * command completed. Make sure we do
  46429. - * things in the proper order.
  46430. - */
  46431. - host->data_early = 1;
  46432. - } else {
  46433. - sdhci_finish_data(host);
  46434. - }
  46435. - }
  46436. + if (intmask & SDHCI_INT_DATA_END)
  46437. + sdhci_data_end(host);
  46438. }
  46439. }
  46440. @@ -2413,10 +2493,10 @@
  46441. u32 intmask, unexpected = 0;
  46442. int cardint = 0, max_loops = 16;
  46443. - spin_lock(&host->lock);
  46444. + sdhci_spin_lock(host);
  46445. if (host->runtime_suspended) {
  46446. - spin_unlock(&host->lock);
  46447. + sdhci_spin_unlock(host);
  46448. pr_warning("%s: got irq while runtime suspended\n",
  46449. mmc_hostname(host->mmc));
  46450. return IRQ_HANDLED;
  46451. @@ -2458,6 +2538,22 @@
  46452. tasklet_schedule(&host->card_tasklet);
  46453. }
  46454. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  46455. + DBG("controller reports error 0x%x -"
  46456. + "%s%s%s%s%s%s%s%s%s%s",
  46457. + intmask,
  46458. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  46459. + intmask & SDHCI_INT_CRC ? " crc": "",
  46460. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  46461. + intmask & SDHCI_INT_INDEX? " index": "",
  46462. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  46463. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  46464. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  46465. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  46466. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  46467. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  46468. + );
  46469. +
  46470. if (intmask & SDHCI_INT_CMD_MASK) {
  46471. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  46472. SDHCI_INT_STATUS);
  46473. @@ -2472,7 +2568,13 @@
  46474. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  46475. - intmask &= ~SDHCI_INT_ERROR;
  46476. + if (intmask & SDHCI_INT_ERROR_MASK) {
  46477. + /* collect any uncovered errors */
  46478. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  46479. + SDHCI_INT_STATUS);
  46480. + }
  46481. +
  46482. + intmask &= ~SDHCI_INT_ERROR_MASK;
  46483. if (intmask & SDHCI_INT_BUS_POWER) {
  46484. pr_err("%s: Card is consuming too much power!\n",
  46485. @@ -2498,7 +2600,7 @@
  46486. if (intmask && --max_loops)
  46487. goto again;
  46488. out:
  46489. - spin_unlock(&host->lock);
  46490. + sdhci_spin_unlock(host);
  46491. if (unexpected) {
  46492. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  46493. @@ -2508,7 +2610,7 @@
  46494. /*
  46495. * We have to delay this as it calls back into the driver.
  46496. */
  46497. - if (cardint && host->mmc->sdio_irqs)
  46498. + if (cardint)
  46499. mmc_signal_sdio_irq(host->mmc);
  46500. return result;
  46501. @@ -2592,13 +2694,14 @@
  46502. {
  46503. int ret;
  46504. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  46505. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  46506. + SDHCI_USE_PLATDMA)) {
  46507. if (host->ops->enable_dma)
  46508. host->ops->enable_dma(host);
  46509. }
  46510. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  46511. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  46512. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  46513. mmc_hostname(host->mmc), host);
  46514. if (ret)
  46515. return ret;
  46516. @@ -2675,15 +2778,15 @@
  46517. host->flags &= ~SDHCI_NEEDS_RETUNING;
  46518. }
  46519. - spin_lock_irqsave(&host->lock, flags);
  46520. + sdhci_spin_lock_irqsave(host, &flags);
  46521. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  46522. - spin_unlock_irqrestore(&host->lock, flags);
  46523. + sdhci_spin_unlock_irqrestore(host, flags);
  46524. synchronize_irq(host->irq);
  46525. - spin_lock_irqsave(&host->lock, flags);
  46526. + sdhci_spin_lock_irqsave(host, &flags);
  46527. host->runtime_suspended = true;
  46528. - spin_unlock_irqrestore(&host->lock, flags);
  46529. + sdhci_spin_unlock_irqrestore(host, flags);
  46530. return ret;
  46531. }
  46532. @@ -2709,16 +2812,16 @@
  46533. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  46534. if ((host_flags & SDHCI_PV_ENABLED) &&
  46535. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  46536. - spin_lock_irqsave(&host->lock, flags);
  46537. + sdhci_spin_lock_irqsave(host, &flags);
  46538. sdhci_enable_preset_value(host, true);
  46539. - spin_unlock_irqrestore(&host->lock, flags);
  46540. + sdhci_spin_unlock_irqrestore(host, flags);
  46541. }
  46542. /* Set the re-tuning expiration flag */
  46543. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  46544. host->flags |= SDHCI_NEEDS_RETUNING;
  46545. - spin_lock_irqsave(&host->lock, flags);
  46546. + sdhci_spin_lock_irqsave(host, &flags);
  46547. host->runtime_suspended = false;
  46548. @@ -2729,7 +2832,7 @@
  46549. /* Enable Card Detection */
  46550. sdhci_enable_card_detection(host);
  46551. - spin_unlock_irqrestore(&host->lock, flags);
  46552. + sdhci_spin_unlock_irqrestore(host, flags);
  46553. return ret;
  46554. }
  46555. @@ -2824,14 +2927,16 @@
  46556. host->flags &= ~SDHCI_USE_ADMA;
  46557. }
  46558. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  46559. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  46560. + SDHCI_USE_PLATDMA)) {
  46561. if (host->ops->enable_dma) {
  46562. if (host->ops->enable_dma(host)) {
  46563. pr_warning("%s: No suitable DMA "
  46564. "available. Falling back to PIO.\n",
  46565. mmc_hostname(mmc));
  46566. host->flags &=
  46567. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  46568. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  46569. + SDHCI_USE_PLATDMA);
  46570. }
  46571. }
  46572. }
  46573. @@ -3006,13 +3111,11 @@
  46574. /* SD3.0: SDR104 is supported so (for eMMC) the caps2
  46575. * field can be promoted to support HS200.
  46576. */
  46577. - if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200))
  46578. - mmc->caps2 |= MMC_CAP2_HS200;
  46579. + mmc->caps2 |= MMC_CAP2_HS200;
  46580. } else if (caps[1] & SDHCI_SUPPORT_SDR50)
  46581. mmc->caps |= MMC_CAP_UHS_SDR50;
  46582. - if ((caps[1] & SDHCI_SUPPORT_DDR50) &&
  46583. - !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50))
  46584. + if (caps[1] & SDHCI_SUPPORT_DDR50)
  46585. mmc->caps |= MMC_CAP_UHS_DDR50;
  46586. /* Does the host need tuning for SDR50? */
  46587. @@ -3224,8 +3327,8 @@
  46588. sdhci_init(host, 0);
  46589. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  46590. - mmc_hostname(mmc), host);
  46591. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  46592. + mmc_hostname(mmc), host);
  46593. if (ret) {
  46594. pr_err("%s: Failed to request IRQ %d: %d\n",
  46595. mmc_hostname(mmc), host->irq, ret);
  46596. @@ -3258,6 +3361,7 @@
  46597. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  46598. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  46599. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  46600. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  46601. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  46602. @@ -3285,7 +3389,7 @@
  46603. unsigned long flags;
  46604. if (dead) {
  46605. - spin_lock_irqsave(&host->lock, flags);
  46606. + sdhci_spin_lock_irqsave(host, &flags);
  46607. host->flags |= SDHCI_DEVICE_DEAD;
  46608. @@ -3297,7 +3401,7 @@
  46609. tasklet_schedule(&host->finish_tasklet);
  46610. }
  46611. - spin_unlock_irqrestore(&host->lock, flags);
  46612. + sdhci_spin_unlock_irqrestore(host, flags);
  46613. }
  46614. sdhci_disable_card_detection(host);
  46615. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci.h linux-rpi/drivers/mmc/host/sdhci.h
  46616. --- linux-3.12.38/drivers/mmc/host/sdhci.h 2015-02-16 16:15:42.000000000 +0100
  46617. +++ linux-rpi/drivers/mmc/host/sdhci.h 2015-03-10 17:26:50.562216692 +0100
  46618. @@ -289,6 +289,18 @@
  46619. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  46620. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  46621. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  46622. +
  46623. + int (*pdma_able)(struct sdhci_host *host,
  46624. + struct mmc_data *data);
  46625. + void (*pdma_avail)(struct sdhci_host *host,
  46626. + unsigned int *ref_intmask,
  46627. + void(*complete)(struct sdhci_host *));
  46628. + void (*pdma_reset)(struct sdhci_host *host,
  46629. + struct mmc_data *data);
  46630. + unsigned int (*extra_ints)(struct sdhci_host *host);
  46631. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  46632. + unsigned int (*missing_status)(struct sdhci_host *host);
  46633. +
  46634. void (*hw_reset)(struct sdhci_host *host);
  46635. void (*platform_suspend)(struct sdhci_host *host);
  46636. void (*platform_resume)(struct sdhci_host *host);
  46637. @@ -400,9 +412,38 @@
  46638. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  46639. #endif
  46640. +static inline int /*bool*/
  46641. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  46642. +{
  46643. + if (host->ops->pdma_able)
  46644. + return host->ops->pdma_able(host, data);
  46645. + else
  46646. + return 1;
  46647. +}
  46648. +static inline void
  46649. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  46650. + void(*completion_callback)(struct sdhci_host *))
  46651. +{
  46652. + if (host->ops->pdma_avail)
  46653. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  46654. +}
  46655. +
  46656. +static inline void
  46657. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  46658. +{
  46659. + if (host->ops->pdma_reset)
  46660. + host->ops->pdma_reset(host, data);
  46661. +}
  46662. +
  46663. #ifdef CONFIG_PM_RUNTIME
  46664. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  46665. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  46666. #endif
  46667. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  46668. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  46669. +extern void sdhci_spin_lock(struct sdhci_host *host);
  46670. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  46671. +
  46672. +
  46673. #endif /* __SDHCI_HW_H */
  46674. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci-pci.c linux-rpi/drivers/mmc/host/sdhci-pci.c
  46675. --- linux-3.12.38/drivers/mmc/host/sdhci-pci.c 2015-02-16 16:15:42.000000000 +0100
  46676. +++ linux-rpi/drivers/mmc/host/sdhci-pci.c 2015-03-10 17:26:50.562216692 +0100
  46677. @@ -27,7 +27,81 @@
  46678. #include <linux/mmc/sdhci-pci-data.h>
  46679. #include "sdhci.h"
  46680. -#include "sdhci-pci.h"
  46681. +
  46682. +/*
  46683. + * PCI device IDs
  46684. + */
  46685. +#define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809
  46686. +#define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a
  46687. +#define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14
  46688. +#define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15
  46689. +#define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16
  46690. +#define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50
  46691. +#define PCI_DEVICE_ID_INTEL_MRFL_MMC 0x1190
  46692. +#define PCI_DEVICE_ID_INTEL_CLV_SDIO0 0x08f9
  46693. +#define PCI_DEVICE_ID_INTEL_CLV_SDIO1 0x08fa
  46694. +#define PCI_DEVICE_ID_INTEL_CLV_SDIO2 0x08fb
  46695. +#define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5
  46696. +#define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6
  46697. +#define PCI_DEVICE_ID_INTEL_QRK_SD 0x08A7
  46698. +
  46699. +/*
  46700. + * PCI registers
  46701. + */
  46702. +
  46703. +#define PCI_SDHCI_IFPIO 0x00
  46704. +#define PCI_SDHCI_IFDMA 0x01
  46705. +#define PCI_SDHCI_IFVENDOR 0x02
  46706. +
  46707. +#define PCI_SLOT_INFO 0x40 /* 8 bits */
  46708. +#define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
  46709. +#define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
  46710. +
  46711. +#define MAX_SLOTS 8
  46712. +
  46713. +struct sdhci_pci_chip;
  46714. +struct sdhci_pci_slot;
  46715. +
  46716. +struct sdhci_pci_fixes {
  46717. + unsigned int quirks;
  46718. + unsigned int quirks2;
  46719. + bool allow_runtime_pm;
  46720. + bool own_cd_for_runtime_pm;
  46721. +
  46722. + int (*probe) (struct sdhci_pci_chip *);
  46723. +
  46724. + int (*probe_slot) (struct sdhci_pci_slot *);
  46725. + void (*remove_slot) (struct sdhci_pci_slot *, int);
  46726. +
  46727. + int (*suspend) (struct sdhci_pci_chip *);
  46728. + int (*resume) (struct sdhci_pci_chip *);
  46729. +};
  46730. +
  46731. +struct sdhci_pci_slot {
  46732. + struct sdhci_pci_chip *chip;
  46733. + struct sdhci_host *host;
  46734. + struct sdhci_pci_data *data;
  46735. +
  46736. + int pci_bar;
  46737. + int rst_n_gpio;
  46738. + int cd_gpio;
  46739. + int cd_irq;
  46740. +
  46741. + void (*hw_reset)(struct sdhci_host *host);
  46742. +};
  46743. +
  46744. +struct sdhci_pci_chip {
  46745. + struct pci_dev *pdev;
  46746. +
  46747. + unsigned int quirks;
  46748. + unsigned int quirks2;
  46749. + bool allow_runtime_pm;
  46750. + const struct sdhci_pci_fixes *fixes;
  46751. +
  46752. + int num_slots; /* Slots on controller */
  46753. + struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
  46754. +};
  46755. +
  46756. /*****************************************************************************\
  46757. * *
  46758. @@ -270,8 +344,6 @@
  46759. MMC_CAP_HW_RESET;
  46760. slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
  46761. slot->hw_reset = sdhci_pci_int_hw_reset;
  46762. - if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
  46763. - slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
  46764. return 0;
  46765. }
  46766. @@ -284,7 +356,6 @@
  46767. static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
  46768. .allow_runtime_pm = true,
  46769. .probe_slot = byt_emmc_probe_slot,
  46770. - .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  46771. };
  46772. static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
  46773. @@ -318,7 +389,6 @@
  46774. static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
  46775. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  46776. - .quirks2 = SDHCI_QUIRK2_BROKEN_HS200,
  46777. .probe_slot = intel_mrfl_mmc_probe_slot,
  46778. };
  46779. @@ -672,18 +742,6 @@
  46780. .probe = via_probe,
  46781. };
  46782. -static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
  46783. -{
  46784. - slot->host->mmc->caps2 |= MMC_CAP2_HS200;
  46785. - return 0;
  46786. -}
  46787. -
  46788. -static const struct sdhci_pci_fixes sdhci_rtsx = {
  46789. - .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  46790. - SDHCI_QUIRK2_BROKEN_DDR50,
  46791. - .probe_slot = rtsx_probe_slot,
  46792. -};
  46793. -
  46794. static const struct pci_device_id pci_ids[] = {
  46795. {
  46796. .vendor = PCI_VENDOR_ID_RICOH,
  46797. @@ -806,14 +864,6 @@
  46798. },
  46799. {
  46800. - .vendor = PCI_VENDOR_ID_REALTEK,
  46801. - .device = 0x5250,
  46802. - .subvendor = PCI_ANY_ID,
  46803. - .subdevice = PCI_ANY_ID,
  46804. - .driver_data = (kernel_ulong_t)&sdhci_rtsx,
  46805. - },
  46806. -
  46807. - {
  46808. .vendor = PCI_VENDOR_ID_INTEL,
  46809. .device = PCI_DEVICE_ID_INTEL_QRK_SD,
  46810. .subvendor = PCI_ANY_ID,
  46811. @@ -933,29 +983,6 @@
  46812. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  46813. },
  46814. - {
  46815. - .vendor = PCI_VENDOR_ID_INTEL,
  46816. - .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
  46817. - .subvendor = PCI_ANY_ID,
  46818. - .subdevice = PCI_ANY_ID,
  46819. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  46820. - },
  46821. -
  46822. - {
  46823. - .vendor = PCI_VENDOR_ID_INTEL,
  46824. - .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
  46825. - .subvendor = PCI_ANY_ID,
  46826. - .subdevice = PCI_ANY_ID,
  46827. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  46828. - },
  46829. -
  46830. - {
  46831. - .vendor = PCI_VENDOR_ID_INTEL,
  46832. - .device = PCI_DEVICE_ID_INTEL_BSW_SD,
  46833. - .subvendor = PCI_ANY_ID,
  46834. - .subdevice = PCI_ANY_ID,
  46835. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  46836. - },
  46837. {
  46838. .vendor = PCI_VENDOR_ID_INTEL,
  46839. @@ -1004,31 +1031,6 @@
  46840. .subdevice = PCI_ANY_ID,
  46841. .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
  46842. },
  46843. -
  46844. - {
  46845. - .vendor = PCI_VENDOR_ID_INTEL,
  46846. - .device = PCI_DEVICE_ID_INTEL_SPT_EMMC,
  46847. - .subvendor = PCI_ANY_ID,
  46848. - .subdevice = PCI_ANY_ID,
  46849. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  46850. - },
  46851. -
  46852. - {
  46853. - .vendor = PCI_VENDOR_ID_INTEL,
  46854. - .device = PCI_DEVICE_ID_INTEL_SPT_SDIO,
  46855. - .subvendor = PCI_ANY_ID,
  46856. - .subdevice = PCI_ANY_ID,
  46857. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  46858. - },
  46859. -
  46860. - {
  46861. - .vendor = PCI_VENDOR_ID_INTEL,
  46862. - .device = PCI_DEVICE_ID_INTEL_SPT_SD,
  46863. - .subvendor = PCI_ANY_ID,
  46864. - .subdevice = PCI_ANY_ID,
  46865. - .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  46866. - },
  46867. -
  46868. {
  46869. .vendor = PCI_VENDOR_ID_O2,
  46870. .device = PCI_DEVICE_ID_O2_8120,
  46871. diff -Nur linux-3.12.38/drivers/mmc/host/sdhci-pci.h linux-rpi/drivers/mmc/host/sdhci-pci.h
  46872. --- linux-3.12.38/drivers/mmc/host/sdhci-pci.h 2015-02-16 16:15:42.000000000 +0100
  46873. +++ linux-rpi/drivers/mmc/host/sdhci-pci.h 1970-01-01 01:00:00.000000000 +0100
  46874. @@ -1,85 +0,0 @@
  46875. -#ifndef __SDHCI_PCI_H
  46876. -#define __SDHCI_PCI_H
  46877. -
  46878. -/*
  46879. - * PCI device IDs
  46880. - */
  46881. -
  46882. -#define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809
  46883. -#define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a
  46884. -#define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14
  46885. -#define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15
  46886. -#define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16
  46887. -#define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50
  46888. -#define PCI_DEVICE_ID_INTEL_BSW_EMMC 0x2294
  46889. -#define PCI_DEVICE_ID_INTEL_BSW_SDIO 0x2295
  46890. -#define PCI_DEVICE_ID_INTEL_BSW_SD 0x2296
  46891. -#define PCI_DEVICE_ID_INTEL_MRFL_MMC 0x1190
  46892. -#define PCI_DEVICE_ID_INTEL_CLV_SDIO0 0x08f9
  46893. -#define PCI_DEVICE_ID_INTEL_CLV_SDIO1 0x08fa
  46894. -#define PCI_DEVICE_ID_INTEL_CLV_SDIO2 0x08fb
  46895. -#define PCI_DEVICE_ID_INTEL_CLV_EMMC0 0x08e5
  46896. -#define PCI_DEVICE_ID_INTEL_CLV_EMMC1 0x08e6
  46897. -#define PCI_DEVICE_ID_INTEL_QRK_SD 0x08A7
  46898. -#define PCI_DEVICE_ID_INTEL_SPT_EMMC 0x9d2b
  46899. -#define PCI_DEVICE_ID_INTEL_SPT_SDIO 0x9d2c
  46900. -#define PCI_DEVICE_ID_INTEL_SPT_SD 0x9d2d
  46901. -
  46902. -/*
  46903. - * PCI registers
  46904. - */
  46905. -
  46906. -#define PCI_SDHCI_IFPIO 0x00
  46907. -#define PCI_SDHCI_IFDMA 0x01
  46908. -#define PCI_SDHCI_IFVENDOR 0x02
  46909. -
  46910. -#define PCI_SLOT_INFO 0x40 /* 8 bits */
  46911. -#define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
  46912. -#define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
  46913. -
  46914. -#define MAX_SLOTS 8
  46915. -
  46916. -struct sdhci_pci_chip;
  46917. -struct sdhci_pci_slot;
  46918. -
  46919. -struct sdhci_pci_fixes {
  46920. - unsigned int quirks;
  46921. - unsigned int quirks2;
  46922. - bool allow_runtime_pm;
  46923. - bool own_cd_for_runtime_pm;
  46924. -
  46925. - int (*probe) (struct sdhci_pci_chip *);
  46926. -
  46927. - int (*probe_slot) (struct sdhci_pci_slot *);
  46928. - void (*remove_slot) (struct sdhci_pci_slot *, int);
  46929. -
  46930. - int (*suspend) (struct sdhci_pci_chip *);
  46931. - int (*resume) (struct sdhci_pci_chip *);
  46932. -};
  46933. -
  46934. -struct sdhci_pci_slot {
  46935. - struct sdhci_pci_chip *chip;
  46936. - struct sdhci_host *host;
  46937. - struct sdhci_pci_data *data;
  46938. -
  46939. - int pci_bar;
  46940. - int rst_n_gpio;
  46941. - int cd_gpio;
  46942. - int cd_irq;
  46943. -
  46944. - void (*hw_reset)(struct sdhci_host *host);
  46945. -};
  46946. -
  46947. -struct sdhci_pci_chip {
  46948. - struct pci_dev *pdev;
  46949. -
  46950. - unsigned int quirks;
  46951. - unsigned int quirks2;
  46952. - bool allow_runtime_pm;
  46953. - const struct sdhci_pci_fixes *fixes;
  46954. -
  46955. - int num_slots; /* Slots on controller */
  46956. - struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
  46957. -};
  46958. -
  46959. -#endif /* __SDHCI_PCI_H */
  46960. diff -Nur linux-3.12.38/drivers/mtd/tests/torturetest.c linux-rpi/drivers/mtd/tests/torturetest.c
  46961. --- linux-3.12.38/drivers/mtd/tests/torturetest.c 2015-02-16 16:15:42.000000000 +0100
  46962. +++ linux-rpi/drivers/mtd/tests/torturetest.c 2015-03-10 17:26:50.582216692 +0100
  46963. @@ -264,9 +264,7 @@
  46964. int i;
  46965. void *patt;
  46966. - err = mtdtest_erase_good_eraseblocks(mtd, bad_ebs, eb, ebcnt);
  46967. - if (err)
  46968. - goto out;
  46969. + mtdtest_erase_good_eraseblocks(mtd, bad_ebs, eb, ebcnt);
  46970. /* Check if the eraseblocks contain only 0xFF bytes */
  46971. if (check) {
  46972. diff -Nur linux-3.12.38/drivers/mtd/ubi/upd.c linux-rpi/drivers/mtd/ubi/upd.c
  46973. --- linux-3.12.38/drivers/mtd/ubi/upd.c 2015-02-16 16:15:42.000000000 +0100
  46974. +++ linux-rpi/drivers/mtd/ubi/upd.c 2015-03-10 17:26:50.582216692 +0100
  46975. @@ -133,10 +133,6 @@
  46976. ubi_assert(!vol->updating && !vol->changing_leb);
  46977. vol->updating = 1;
  46978. - vol->upd_buf = vmalloc(ubi->leb_size);
  46979. - if (!vol->upd_buf)
  46980. - return -ENOMEM;
  46981. -
  46982. err = set_update_marker(ubi, vol);
  46983. if (err)
  46984. return err;
  46985. @@ -156,12 +152,14 @@
  46986. err = clear_update_marker(ubi, vol, 0);
  46987. if (err)
  46988. return err;
  46989. -
  46990. - vfree(vol->upd_buf);
  46991. vol->updating = 0;
  46992. return 0;
  46993. }
  46994. + vol->upd_buf = vmalloc(ubi->leb_size);
  46995. + if (!vol->upd_buf)
  46996. + return -ENOMEM;
  46997. +
  46998. vol->upd_ebs = div_u64(bytes + vol->usable_leb_size - 1,
  46999. vol->usable_leb_size);
  47000. vol->upd_bytes = bytes;
  47001. diff -Nur linux-3.12.38/drivers/mtd/ubi/wl.c linux-rpi/drivers/mtd/ubi/wl.c
  47002. --- linux-3.12.38/drivers/mtd/ubi/wl.c 2015-02-16 16:15:42.000000000 +0100
  47003. +++ linux-rpi/drivers/mtd/ubi/wl.c 2015-03-10 17:26:50.582216692 +0100
  47004. @@ -1209,6 +1209,7 @@
  47005. err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
  47006. if (err) {
  47007. + kmem_cache_free(ubi_wl_entry_slab, e1);
  47008. if (e2)
  47009. kmem_cache_free(ubi_wl_entry_slab, e2);
  47010. goto out_ro;
  47011. @@ -1222,8 +1223,10 @@
  47012. dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase",
  47013. e2->pnum, vol_id, lnum);
  47014. err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
  47015. - if (err)
  47016. + if (err) {
  47017. + kmem_cache_free(ubi_wl_entry_slab, e2);
  47018. goto out_ro;
  47019. + }
  47020. }
  47021. dbg_wl("done");
  47022. @@ -1259,9 +1262,10 @@
  47023. ubi_free_vid_hdr(ubi, vid_hdr);
  47024. err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
  47025. - if (err)
  47026. + if (err) {
  47027. + kmem_cache_free(ubi_wl_entry_slab, e2);
  47028. goto out_ro;
  47029. -
  47030. + }
  47031. mutex_unlock(&ubi->move_mutex);
  47032. return 0;
  47033. diff -Nur linux-3.12.38/drivers/net/can/dev.c linux-rpi/drivers/net/can/dev.c
  47034. --- linux-3.12.38/drivers/net/can/dev.c 2015-02-16 16:15:42.000000000 +0100
  47035. +++ linux-rpi/drivers/net/can/dev.c 2015-03-10 17:26:50.586216692 +0100
  47036. @@ -643,14 +643,10 @@
  47037. if (dev->flags & IFF_UP)
  47038. return -EBUSY;
  47039. cm = nla_data(data[IFLA_CAN_CTRLMODE]);
  47040. -
  47041. - /* check whether changed bits are allowed to be modified */
  47042. - if (cm->mask & ~priv->ctrlmode_supported)
  47043. + if (cm->flags & ~priv->ctrlmode_supported)
  47044. return -EOPNOTSUPP;
  47045. -
  47046. - /* clear bits to be modified and copy the flag values */
  47047. priv->ctrlmode &= ~cm->mask;
  47048. - priv->ctrlmode |= (cm->flags & cm->mask);
  47049. + priv->ctrlmode |= cm->flags;
  47050. }
  47051. if (data[IFLA_CAN_BITTIMING]) {
  47052. diff -Nur linux-3.12.38/drivers/net/can/usb/kvaser_usb.c linux-rpi/drivers/net/can/usb/kvaser_usb.c
  47053. --- linux-3.12.38/drivers/net/can/usb/kvaser_usb.c 2015-02-16 16:15:42.000000000 +0100
  47054. +++ linux-rpi/drivers/net/can/usb/kvaser_usb.c 2015-03-10 17:26:50.590216692 +0100
  47055. @@ -579,7 +579,7 @@
  47056. usb_sndbulkpipe(dev->udev,
  47057. dev->bulk_out->bEndpointAddress),
  47058. buf, msg->len,
  47059. - kvaser_usb_simple_msg_callback, netdev);
  47060. + kvaser_usb_simple_msg_callback, priv);
  47061. usb_anchor_urb(urb, &priv->tx_submitted);
  47062. err = usb_submit_urb(urb, GFP_ATOMIC);
  47063. @@ -654,6 +654,11 @@
  47064. priv = dev->nets[channel];
  47065. stats = &priv->netdev->stats;
  47066. + if (status & M16C_STATE_BUS_RESET) {
  47067. + kvaser_usb_unlink_tx_urbs(priv);
  47068. + return;
  47069. + }
  47070. +
  47071. skb = alloc_can_err_skb(priv->netdev, &cf);
  47072. if (!skb) {
  47073. stats->rx_dropped++;
  47074. @@ -664,7 +669,7 @@
  47075. netdev_dbg(priv->netdev, "Error status: 0x%02x\n", status);
  47076. - if (status & (M16C_STATE_BUS_OFF | M16C_STATE_BUS_RESET)) {
  47077. + if (status & M16C_STATE_BUS_OFF) {
  47078. cf->can_id |= CAN_ERR_BUSOFF;
  47079. priv->can.can_stats.bus_off++;
  47080. @@ -690,7 +695,9 @@
  47081. }
  47082. new_state = CAN_STATE_ERROR_PASSIVE;
  47083. - } else if (status & M16C_STATE_BUS_ERROR) {
  47084. + }
  47085. +
  47086. + if (status == M16C_STATE_BUS_ERROR) {
  47087. if ((priv->can.state < CAN_STATE_ERROR_WARNING) &&
  47088. ((txerr >= 96) || (rxerr >= 96))) {
  47089. cf->can_id |= CAN_ERR_CRTL;
  47090. @@ -700,8 +707,7 @@
  47091. priv->can.can_stats.error_warning++;
  47092. new_state = CAN_STATE_ERROR_WARNING;
  47093. - } else if ((priv->can.state > CAN_STATE_ERROR_ACTIVE) &&
  47094. - ((txerr < 96) && (rxerr < 96))) {
  47095. + } else if (priv->can.state > CAN_STATE_ERROR_ACTIVE) {
  47096. cf->can_id |= CAN_ERR_PROT;
  47097. cf->data[2] = CAN_ERR_PROT_ACTIVE;
  47098. @@ -1232,9 +1238,6 @@
  47099. if (err)
  47100. netdev_warn(netdev, "Cannot stop device, error %d\n", err);
  47101. - /* reset tx contexts */
  47102. - kvaser_usb_unlink_tx_urbs(priv);
  47103. -
  47104. priv->can.state = CAN_STATE_STOPPED;
  47105. close_candev(priv->netdev);
  47106. @@ -1283,14 +1286,12 @@
  47107. if (!urb) {
  47108. netdev_err(netdev, "No memory left for URBs\n");
  47109. stats->tx_dropped++;
  47110. - dev_kfree_skb(skb);
  47111. - return NETDEV_TX_OK;
  47112. + goto nourbmem;
  47113. }
  47114. buf = kmalloc(sizeof(struct kvaser_msg), GFP_ATOMIC);
  47115. if (!buf) {
  47116. stats->tx_dropped++;
  47117. - dev_kfree_skb(skb);
  47118. goto nobufmem;
  47119. }
  47120. @@ -1325,7 +1326,6 @@
  47121. }
  47122. }
  47123. - /* This should never happen; it implies a flow control bug */
  47124. if (!context) {
  47125. netdev_warn(netdev, "cannot find free context\n");
  47126. ret = NETDEV_TX_BUSY;
  47127. @@ -1356,6 +1356,9 @@
  47128. if (unlikely(err)) {
  47129. can_free_echo_skb(netdev, context->echo_index);
  47130. + skb = NULL; /* set to NULL to avoid double free in
  47131. + * dev_kfree_skb(skb) */
  47132. +
  47133. atomic_dec(&priv->active_tx_urbs);
  47134. usb_unanchor_urb(urb);
  47135. @@ -1377,6 +1380,8 @@
  47136. kfree(buf);
  47137. nobufmem:
  47138. usb_free_urb(urb);
  47139. +nourbmem:
  47140. + dev_kfree_skb(skb);
  47141. return ret;
  47142. }
  47143. @@ -1488,10 +1493,6 @@
  47144. struct kvaser_usb_net_priv *priv;
  47145. int i, err;
  47146. - err = kvaser_usb_send_simple_msg(dev, CMD_RESET_CHIP, channel);
  47147. - if (err)
  47148. - return err;
  47149. -
  47150. netdev = alloc_candev(sizeof(*priv), MAX_TX_URBS);
  47151. if (!netdev) {
  47152. dev_err(&intf->dev, "Cannot alloc candev\n");
  47153. @@ -1577,7 +1578,7 @@
  47154. {
  47155. struct kvaser_usb *dev;
  47156. int err = -ENOMEM;
  47157. - int i, retry = 3;
  47158. + int i;
  47159. dev = devm_kzalloc(&intf->dev, sizeof(*dev), GFP_KERNEL);
  47160. if (!dev)
  47161. @@ -1595,15 +1596,10 @@
  47162. usb_set_intfdata(intf, dev);
  47163. - /* On some x86 laptops, plugging a Kvaser device again after
  47164. - * an unplug makes the firmware always ignore the very first
  47165. - * command. For such a case, provide some room for retries
  47166. - * instead of completely exiting the driver.
  47167. - */
  47168. - do {
  47169. - err = kvaser_usb_get_software_info(dev);
  47170. - } while (--retry && err == -ETIMEDOUT);
  47171. + for (i = 0; i < MAX_NET_DEVICES; i++)
  47172. + kvaser_usb_send_simple_msg(dev, CMD_RESET_CHIP, i);
  47173. + err = kvaser_usb_get_software_info(dev);
  47174. if (err) {
  47175. dev_err(&intf->dev,
  47176. "Cannot get software infos, error %d\n", err);
  47177. diff -Nur linux-3.12.38/drivers/net/can/usb/peak_usb/pcan_usb_core.c linux-rpi/drivers/net/can/usb/peak_usb/pcan_usb_core.c
  47178. --- linux-3.12.38/drivers/net/can/usb/peak_usb/pcan_usb_core.c 2015-02-16 16:15:42.000000000 +0100
  47179. +++ linux-rpi/drivers/net/can/usb/peak_usb/pcan_usb_core.c 2015-03-10 17:26:50.590216692 +0100
  47180. @@ -734,7 +734,7 @@
  47181. dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL);
  47182. if (!dev->cmd_buf) {
  47183. err = -ENOMEM;
  47184. - goto lbl_free_candev;
  47185. + goto lbl_set_intf_data;
  47186. }
  47187. dev->udev = usb_dev;
  47188. @@ -773,7 +773,7 @@
  47189. err = register_candev(netdev);
  47190. if (err) {
  47191. dev_err(&intf->dev, "couldn't register CAN device: %d\n", err);
  47192. - goto lbl_restore_intf_data;
  47193. + goto lbl_free_cmd_buf;
  47194. }
  47195. if (dev->prev_siblings)
  47196. @@ -786,14 +786,14 @@
  47197. if (dev->adapter->dev_init) {
  47198. err = dev->adapter->dev_init(dev);
  47199. if (err)
  47200. - goto lbl_unregister_candev;
  47201. + goto lbl_free_cmd_buf;
  47202. }
  47203. /* set bus off */
  47204. if (dev->adapter->dev_set_bus) {
  47205. err = dev->adapter->dev_set_bus(dev, 0);
  47206. if (err)
  47207. - goto lbl_unregister_candev;
  47208. + goto lbl_free_cmd_buf;
  47209. }
  47210. /* get device number early */
  47211. @@ -805,14 +805,11 @@
  47212. return 0;
  47213. -lbl_unregister_candev:
  47214. - unregister_candev(netdev);
  47215. -
  47216. -lbl_restore_intf_data:
  47217. - usb_set_intfdata(intf, dev->prev_siblings);
  47218. +lbl_free_cmd_buf:
  47219. kfree(dev->cmd_buf);
  47220. -lbl_free_candev:
  47221. +lbl_set_intf_data:
  47222. + usb_set_intfdata(intf, dev->prev_siblings);
  47223. free_candev(netdev);
  47224. return err;
  47225. diff -Nur linux-3.12.38/drivers/net/can/usb/peak_usb/pcan_usb_pro.c linux-rpi/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
  47226. --- linux-3.12.38/drivers/net/can/usb/peak_usb/pcan_usb_pro.c 2015-02-16 16:15:42.000000000 +0100
  47227. +++ linux-rpi/drivers/net/can/usb/peak_usb/pcan_usb_pro.c 2015-03-10 17:26:50.590216692 +0100
  47228. @@ -333,6 +333,8 @@
  47229. if (!(dev->state & PCAN_USB_STATE_CONNECTED))
  47230. return 0;
  47231. + memset(req_addr, '\0', req_size);
  47232. +
  47233. req_type = USB_TYPE_VENDOR | USB_RECIP_OTHER;
  47234. switch (req_id) {
  47235. @@ -343,7 +345,6 @@
  47236. default:
  47237. p = usb_rcvctrlpipe(dev->udev, 0);
  47238. req_type |= USB_DIR_IN;
  47239. - memset(req_addr, '\0', req_size);
  47240. break;
  47241. }
  47242. diff -Nur linux-3.12.38/drivers/net/ethernet/atheros/alx/main.c linux-rpi/drivers/net/ethernet/atheros/alx/main.c
  47243. --- linux-3.12.38/drivers/net/ethernet/atheros/alx/main.c 2015-02-16 16:15:42.000000000 +0100
  47244. +++ linux-rpi/drivers/net/ethernet/atheros/alx/main.c 2015-03-10 17:26:50.602216692 +0100
  47245. @@ -184,16 +184,15 @@
  47246. schedule_work(&alx->reset_wk);
  47247. }
  47248. -static int alx_clean_rx_irq(struct alx_priv *alx, int budget)
  47249. +static bool alx_clean_rx_irq(struct alx_priv *alx, int budget)
  47250. {
  47251. struct alx_rx_queue *rxq = &alx->rxq;
  47252. struct alx_rrd *rrd;
  47253. struct alx_buffer *rxb;
  47254. struct sk_buff *skb;
  47255. u16 length, rfd_cleaned = 0;
  47256. - int work = 0;
  47257. - while (work < budget) {
  47258. + while (budget > 0) {
  47259. rrd = &rxq->rrd[rxq->rrd_read_idx];
  47260. if (!(rrd->word3 & cpu_to_le32(1 << RRD_UPDATED_SHIFT)))
  47261. break;
  47262. @@ -204,7 +203,7 @@
  47263. ALX_GET_FIELD(le32_to_cpu(rrd->word0),
  47264. RRD_NOR) != 1) {
  47265. alx_schedule_reset(alx);
  47266. - return work;
  47267. + return 0;
  47268. }
  47269. rxb = &rxq->bufs[rxq->read_idx];
  47270. @@ -244,7 +243,7 @@
  47271. }
  47272. napi_gro_receive(&alx->napi, skb);
  47273. - work++;
  47274. + budget--;
  47275. next_pkt:
  47276. if (++rxq->read_idx == alx->rx_ringsz)
  47277. @@ -259,22 +258,21 @@
  47278. if (rfd_cleaned)
  47279. alx_refill_rx_ring(alx, GFP_ATOMIC);
  47280. - return work;
  47281. + return budget > 0;
  47282. }
  47283. static int alx_poll(struct napi_struct *napi, int budget)
  47284. {
  47285. struct alx_priv *alx = container_of(napi, struct alx_priv, napi);
  47286. struct alx_hw *hw = &alx->hw;
  47287. + bool complete = true;
  47288. unsigned long flags;
  47289. - bool tx_complete;
  47290. - int work;
  47291. - tx_complete = alx_clean_tx_irq(alx);
  47292. - work = alx_clean_rx_irq(alx, budget);
  47293. + complete = alx_clean_tx_irq(alx) &&
  47294. + alx_clean_rx_irq(alx, budget);
  47295. - if (!tx_complete || work == budget)
  47296. - return budget;
  47297. + if (!complete)
  47298. + return 1;
  47299. napi_complete(&alx->napi);
  47300. @@ -286,7 +284,7 @@
  47301. alx_post_write(hw);
  47302. - return work;
  47303. + return 0;
  47304. }
  47305. static irqreturn_t alx_intr_handle(struct alx_priv *alx, u32 intr)
  47306. diff -Nur linux-3.12.38/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c linux-rpi/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
  47307. --- linux-3.12.38/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 2015-02-16 16:15:42.000000000 +0100
  47308. +++ linux-rpi/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c 2015-03-10 17:26:50.606216692 +0100
  47309. @@ -3087,7 +3087,7 @@
  47310. }
  47311. #endif
  47312. if (!bnx2x_fp_lock_napi(fp))
  47313. - return budget;
  47314. + return work_done;
  47315. for_each_cos_in_tx_queue(fp, cos)
  47316. if (bnx2x_tx_queue_has_work(fp->txdata_ptr[cos]))
  47317. diff -Nur linux-3.12.38/drivers/net/ethernet/broadcom/tg3.c linux-rpi/drivers/net/ethernet/broadcom/tg3.c
  47318. --- linux-3.12.38/drivers/net/ethernet/broadcom/tg3.c 2015-02-16 16:15:42.000000000 +0100
  47319. +++ linux-rpi/drivers/net/ethernet/broadcom/tg3.c 2015-03-10 17:26:50.622216692 +0100
  47320. @@ -17572,6 +17572,23 @@
  47321. goto err_out_apeunmap;
  47322. }
  47323. + /*
  47324. + * Reset chip in case UNDI or EFI driver did not shutdown
  47325. + * DMA self test will enable WDMAC and we'll see (spurious)
  47326. + * pending DMA on the PCI bus at that point.
  47327. + */
  47328. + if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  47329. + (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  47330. + tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  47331. + tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  47332. + }
  47333. +
  47334. + err = tg3_test_dma(tp);
  47335. + if (err) {
  47336. + dev_err(&pdev->dev, "DMA engine test failed, aborting\n");
  47337. + goto err_out_apeunmap;
  47338. + }
  47339. +
  47340. intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW;
  47341. rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW;
  47342. sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW;
  47343. @@ -17616,23 +17633,6 @@
  47344. sndmbx += 0xc;
  47345. }
  47346. - /*
  47347. - * Reset chip in case UNDI or EFI driver did not shutdown
  47348. - * DMA self test will enable WDMAC and we'll see (spurious)
  47349. - * pending DMA on the PCI bus at that point.
  47350. - */
  47351. - if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
  47352. - (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
  47353. - tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
  47354. - tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
  47355. - }
  47356. -
  47357. - err = tg3_test_dma(tp);
  47358. - if (err) {
  47359. - dev_err(&pdev->dev, "DMA engine test failed, aborting\n");
  47360. - goto err_out_apeunmap;
  47361. - }
  47362. -
  47363. tg3_init_coal(tp);
  47364. pci_set_drvdata(pdev, dev);
  47365. diff -Nur linux-3.12.38/drivers/net/ethernet/cisco/enic/enic_main.c linux-rpi/drivers/net/ethernet/cisco/enic/enic_main.c
  47366. --- linux-3.12.38/drivers/net/ethernet/cisco/enic/enic_main.c 2015-02-16 16:15:42.000000000 +0100
  47367. +++ linux-rpi/drivers/net/ethernet/cisco/enic/enic_main.c 2015-03-10 17:26:50.634216691 +0100
  47368. @@ -1043,14 +1043,10 @@
  47369. skb->l4_rxhash = true;
  47370. }
  47371. - /* Hardware does not provide whole packet checksum. It only
  47372. - * provides pseudo checksum. Since hw validates the packet
  47373. - * checksum but not provide us the checksum value. use
  47374. - * CHECSUM_UNNECESSARY.
  47375. - */
  47376. - if ((netdev->features & NETIF_F_RXCSUM) && tcp_udp_csum_ok &&
  47377. - ipv4_csum_ok)
  47378. - skb->ip_summed = CHECKSUM_UNNECESSARY;
  47379. + if ((netdev->features & NETIF_F_RXCSUM) && !csum_not_calc) {
  47380. + skb->csum = htons(checksum);
  47381. + skb->ip_summed = CHECKSUM_COMPLETE;
  47382. + }
  47383. if (vlan_stripped)
  47384. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);
  47385. diff -Nur linux-3.12.38/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c linux-rpi/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
  47386. --- linux-3.12.38/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c 2015-02-16 16:15:42.000000000 +0100
  47387. +++ linux-rpi/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c 2015-03-10 17:26:50.690216691 +0100
  47388. @@ -2366,10 +2366,7 @@
  47389. work_done = netxen_process_rcv_ring(sds_ring, budget);
  47390. - if (!tx_complete)
  47391. - work_done = budget;
  47392. -
  47393. - if (work_done < budget) {
  47394. + if ((work_done < budget) && tx_complete) {
  47395. napi_complete(&sds_ring->napi);
  47396. if (test_bit(__NX_DEV_UP, &adapter->state))
  47397. netxen_nic_enable_int(sds_ring);
  47398. diff -Nur linux-3.12.38/drivers/net/ethernet/ti/cpsw_ale.c linux-rpi/drivers/net/ethernet/ti/cpsw_ale.c
  47399. --- linux-3.12.38/drivers/net/ethernet/ti/cpsw_ale.c 2015-02-16 16:15:42.000000000 +0100
  47400. +++ linux-rpi/drivers/net/ethernet/ti/cpsw_ale.c 2015-03-10 17:26:50.714216691 +0100
  47401. @@ -236,7 +236,7 @@
  47402. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
  47403. }
  47404. -int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
  47405. +int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask)
  47406. {
  47407. u32 ale_entry[ALE_ENTRY_WORDS];
  47408. int ret, idx;
  47409. @@ -247,14 +247,6 @@
  47410. if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR)
  47411. continue;
  47412. - /* if vid passed is -1 then remove all multicast entry from
  47413. - * the table irrespective of vlan id, if a valid vlan id is
  47414. - * passed then remove only multicast added to that vlan id.
  47415. - * if vlan id doesn't match then move on to next entry.
  47416. - */
  47417. - if (vid != -1 && cpsw_ale_get_vlan_id(ale_entry) != vid)
  47418. - continue;
  47419. -
  47420. if (cpsw_ale_get_mcast(ale_entry)) {
  47421. u8 addr[6];
  47422. diff -Nur linux-3.12.38/drivers/net/ethernet/ti/cpsw_ale.h linux-rpi/drivers/net/ethernet/ti/cpsw_ale.h
  47423. --- linux-3.12.38/drivers/net/ethernet/ti/cpsw_ale.h 2015-02-16 16:15:42.000000000 +0100
  47424. +++ linux-rpi/drivers/net/ethernet/ti/cpsw_ale.h 2015-03-10 17:26:50.714216691 +0100
  47425. @@ -86,7 +86,7 @@
  47426. int cpsw_ale_set_ageout(struct cpsw_ale *ale, int ageout);
  47427. int cpsw_ale_flush(struct cpsw_ale *ale, int port_mask);
  47428. -int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid);
  47429. +int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask);
  47430. int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port,
  47431. int flags, u16 vid);
  47432. int cpsw_ale_del_ucast(struct cpsw_ale *ale, u8 *addr, int port,
  47433. diff -Nur linux-3.12.38/drivers/net/ethernet/ti/cpsw.c linux-rpi/drivers/net/ethernet/ti/cpsw.c
  47434. --- linux-3.12.38/drivers/net/ethernet/ti/cpsw.c 2015-02-16 16:15:42.000000000 +0100
  47435. +++ linux-rpi/drivers/net/ethernet/ti/cpsw.c 2015-03-10 17:26:50.714216691 +0100
  47436. @@ -546,12 +546,6 @@
  47437. static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
  47438. {
  47439. struct cpsw_priv *priv = netdev_priv(ndev);
  47440. - int vid;
  47441. -
  47442. - if (priv->data.dual_emac)
  47443. - vid = priv->slaves[priv->emac_port].port_vlan;
  47444. - else
  47445. - vid = priv->data.default_vlan;
  47446. if (ndev->flags & IFF_PROMISC) {
  47447. /* Enable promiscuous mode */
  47448. @@ -560,8 +554,7 @@
  47449. }
  47450. /* Clear all mcast from ALE */
  47451. - cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port,
  47452. - vid);
  47453. + cpsw_ale_flush_multicast(priv->ale, ALE_ALL_PORTS << priv->host_port);
  47454. if (!netdev_mc_empty(ndev)) {
  47455. struct netdev_hw_addr *ha;
  47456. @@ -646,14 +639,6 @@
  47457. static irqreturn_t cpsw_interrupt(int irq, void *dev_id)
  47458. {
  47459. struct cpsw_priv *priv = dev_id;
  47460. - int value = irq - priv->irqs_table[0];
  47461. -
  47462. - /* NOTICE: Ending IRQ here. The trick with the 'value' variable above
  47463. - * is to make sure we will always write the correct value to the EOI
  47464. - * register. Namely 0 for RX_THRESH Interrupt, 1 for RX Interrupt, 2
  47465. - * for TX Interrupt and 3 for MISC Interrupt.
  47466. - */
  47467. - cpdma_ctlr_eoi(priv->dma, value);
  47468. cpsw_intr_disable(priv);
  47469. if (priv->irq_enabled == true) {
  47470. @@ -683,6 +668,8 @@
  47471. int num_tx, num_rx;
  47472. num_tx = cpdma_chan_process(priv->txch, 128);
  47473. + if (num_tx)
  47474. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
  47475. num_rx = cpdma_chan_process(priv->rxch, budget);
  47476. if (num_rx < budget) {
  47477. @@ -690,6 +677,7 @@
  47478. napi_complete(napi);
  47479. cpsw_intr_enable(priv);
  47480. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
  47481. prim_cpsw = cpsw_get_slave_priv(priv, 0);
  47482. if (prim_cpsw->irq_enabled == false) {
  47483. prim_cpsw->irq_enabled = true;
  47484. @@ -1177,6 +1165,8 @@
  47485. napi_enable(&priv->napi);
  47486. cpdma_ctlr_start(priv->dma);
  47487. cpsw_intr_enable(priv);
  47488. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
  47489. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
  47490. if (priv->data.dual_emac)
  47491. priv->slaves[priv->emac_port].open_stat = true;
  47492. @@ -1426,6 +1416,9 @@
  47493. cpdma_chan_start(priv->txch);
  47494. cpdma_ctlr_int_ctrl(priv->dma, true);
  47495. cpsw_intr_enable(priv);
  47496. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
  47497. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
  47498. +
  47499. }
  47500. static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
  47501. @@ -1471,6 +1464,9 @@
  47502. cpsw_interrupt(ndev->irq, priv);
  47503. cpdma_ctlr_int_ctrl(priv->dma, true);
  47504. cpsw_intr_enable(priv);
  47505. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
  47506. + cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
  47507. +
  47508. }
  47509. #endif
  47510. @@ -1514,19 +1510,6 @@
  47511. if (vid == priv->data.default_vlan)
  47512. return 0;
  47513. - if (priv->data.dual_emac) {
  47514. - /* In dual EMAC, reserved VLAN id should not be used for
  47515. - * creating VLAN interfaces as this can break the dual
  47516. - * EMAC port separation
  47517. - */
  47518. - int i;
  47519. -
  47520. - for (i = 0; i < priv->data.slaves; i++) {
  47521. - if (vid == priv->slaves[i].port_vlan)
  47522. - return -EINVAL;
  47523. - }
  47524. - }
  47525. -
  47526. dev_info(priv->dev, "Adding vlanid %d to vlan filter\n", vid);
  47527. return cpsw_add_vlan_ale_entry(priv, vid);
  47528. }
  47529. @@ -1540,15 +1523,6 @@
  47530. if (vid == priv->data.default_vlan)
  47531. return 0;
  47532. - if (priv->data.dual_emac) {
  47533. - int i;
  47534. -
  47535. - for (i = 0; i < priv->data.slaves; i++) {
  47536. - if (vid == priv->slaves[i].port_vlan)
  47537. - return -EINVAL;
  47538. - }
  47539. - }
  47540. -
  47541. dev_info(priv->dev, "removing vlanid %d from vlan filter\n", vid);
  47542. ret = cpsw_ale_del_vlan(priv->ale, vid, 0);
  47543. if (ret != 0)
  47544. diff -Nur linux-3.12.38/drivers/net/ppp/ppp_deflate.c linux-rpi/drivers/net/ppp/ppp_deflate.c
  47545. --- linux-3.12.38/drivers/net/ppp/ppp_deflate.c 2015-02-16 16:15:42.000000000 +0100
  47546. +++ linux-rpi/drivers/net/ppp/ppp_deflate.c 2015-03-10 17:26:50.734216691 +0100
  47547. @@ -246,7 +246,7 @@
  47548. /*
  47549. * See if we managed to reduce the size of the packet.
  47550. */
  47551. - if (olen < isize && olen <= osize) {
  47552. + if (olen < isize) {
  47553. state->stats.comp_bytes += olen;
  47554. state->stats.comp_packets++;
  47555. } else {
  47556. diff -Nur linux-3.12.38/drivers/net/team/team.c linux-rpi/drivers/net/team/team.c
  47557. --- linux-3.12.38/drivers/net/team/team.c 2015-02-16 16:15:42.000000000 +0100
  47558. +++ linux-rpi/drivers/net/team/team.c 2015-03-10 17:26:50.734216691 +0100
  47559. @@ -629,7 +629,6 @@
  47560. static void team_notify_peers_work(struct work_struct *work)
  47561. {
  47562. struct team *team;
  47563. - int val;
  47564. team = container_of(work, struct team, notify_peers.dw.work);
  47565. @@ -637,14 +636,9 @@
  47566. schedule_delayed_work(&team->notify_peers.dw, 0);
  47567. return;
  47568. }
  47569. - val = atomic_dec_if_positive(&team->notify_peers.count_pending);
  47570. - if (val < 0) {
  47571. - rtnl_unlock();
  47572. - return;
  47573. - }
  47574. call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev);
  47575. rtnl_unlock();
  47576. - if (val)
  47577. + if (!atomic_dec_and_test(&team->notify_peers.count_pending))
  47578. schedule_delayed_work(&team->notify_peers.dw,
  47579. msecs_to_jiffies(team->notify_peers.interval));
  47580. }
  47581. @@ -675,7 +669,6 @@
  47582. static void team_mcast_rejoin_work(struct work_struct *work)
  47583. {
  47584. struct team *team;
  47585. - int val;
  47586. team = container_of(work, struct team, mcast_rejoin.dw.work);
  47587. @@ -683,14 +676,9 @@
  47588. schedule_delayed_work(&team->mcast_rejoin.dw, 0);
  47589. return;
  47590. }
  47591. - val = atomic_dec_if_positive(&team->mcast_rejoin.count_pending);
  47592. - if (val < 0) {
  47593. - rtnl_unlock();
  47594. - return;
  47595. - }
  47596. call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev);
  47597. rtnl_unlock();
  47598. - if (val)
  47599. + if (!atomic_dec_and_test(&team->mcast_rejoin.count_pending))
  47600. schedule_delayed_work(&team->mcast_rejoin.dw,
  47601. msecs_to_jiffies(team->mcast_rejoin.interval));
  47602. }
  47603. diff -Nur linux-3.12.38/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  47604. --- linux-3.12.38/drivers/net/usb/smsc95xx.c 2015-02-16 16:15:42.000000000 +0100
  47605. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2015-03-10 17:26:50.738216691 +0100
  47606. @@ -61,6 +61,7 @@
  47607. #define SUSPEND_SUSPEND3 (0x08)
  47608. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  47609. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  47610. +#define MAC_ADDR_LEN (6)
  47611. struct smsc95xx_priv {
  47612. u32 mac_cr;
  47613. @@ -76,6 +77,10 @@
  47614. module_param(turbo_mode, bool, 0644);
  47615. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  47616. +static char *macaddr = ":";
  47617. +module_param(macaddr, charp, 0);
  47618. +MODULE_PARM_DESC(macaddr, "MAC address");
  47619. +
  47620. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  47621. u32 *data, int in_pm)
  47622. {
  47623. @@ -765,8 +770,59 @@
  47624. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  47625. }
  47626. +/* Check the macaddr module parameter for a MAC address */
  47627. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  47628. +{
  47629. + int i, j, got_num, num;
  47630. + u8 mtbl[MAC_ADDR_LEN];
  47631. +
  47632. + if (macaddr[0] == ':')
  47633. + return 0;
  47634. +
  47635. + i = 0;
  47636. + j = 0;
  47637. + num = 0;
  47638. + got_num = 0;
  47639. + while (j < MAC_ADDR_LEN) {
  47640. + if (macaddr[i] && macaddr[i] != ':') {
  47641. + got_num++;
  47642. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  47643. + num = num * 16 + macaddr[i] - '0';
  47644. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  47645. + num = num * 16 + 10 + macaddr[i] - 'A';
  47646. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  47647. + num = num * 16 + 10 + macaddr[i] - 'a';
  47648. + else
  47649. + break;
  47650. + i++;
  47651. + } else if (got_num == 2) {
  47652. + mtbl[j++] = (u8) num;
  47653. + num = 0;
  47654. + got_num = 0;
  47655. + i++;
  47656. + } else {
  47657. + break;
  47658. + }
  47659. + }
  47660. +
  47661. + if (j == MAC_ADDR_LEN) {
  47662. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  47663. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  47664. + mtbl[3], mtbl[4], mtbl[5]);
  47665. + for (i = 0; i < MAC_ADDR_LEN; i++)
  47666. + dev_mac[i] = mtbl[i];
  47667. + return 1;
  47668. + } else {
  47669. + return 0;
  47670. + }
  47671. +}
  47672. +
  47673. static void smsc95xx_init_mac_address(struct usbnet *dev)
  47674. {
  47675. + /* Check module parameters */
  47676. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  47677. + return;
  47678. +
  47679. /* try reading mac address from EEPROM */
  47680. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  47681. dev->net->dev_addr) == 0) {
  47682. diff -Nur linux-3.12.38/drivers/net/wireless/ath/ath5k/qcu.c linux-rpi/drivers/net/wireless/ath/ath5k/qcu.c
  47683. --- linux-3.12.38/drivers/net/wireless/ath/ath5k/qcu.c 2015-02-16 16:15:42.000000000 +0100
  47684. +++ linux-rpi/drivers/net/wireless/ath/ath5k/qcu.c 2015-03-10 17:26:50.754216691 +0100
  47685. @@ -225,7 +225,13 @@
  47686. } else {
  47687. switch (queue_type) {
  47688. case AR5K_TX_QUEUE_DATA:
  47689. - queue = queue_info->tqi_subtype;
  47690. + for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
  47691. + ah->ah_txq[queue].tqi_type !=
  47692. + AR5K_TX_QUEUE_INACTIVE; queue++) {
  47693. +
  47694. + if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
  47695. + return -EINVAL;
  47696. + }
  47697. break;
  47698. case AR5K_TX_QUEUE_UAPSD:
  47699. queue = AR5K_TX_QUEUE_ID_UAPSD;
  47700. diff -Nur linux-3.12.38/drivers/net/wireless/ath/ath9k/hw.h linux-rpi/drivers/net/wireless/ath/ath9k/hw.h
  47701. --- linux-3.12.38/drivers/net/wireless/ath/ath9k/hw.h 2015-02-16 16:15:42.000000000 +0100
  47702. +++ linux-rpi/drivers/net/wireless/ath/ath9k/hw.h 2015-03-10 17:26:50.766216691 +0100
  47703. @@ -215,8 +215,8 @@
  47704. #define AH_WOW_BEACON_MISS BIT(3)
  47705. enum ath_hw_txq_subtype {
  47706. - ATH_TXQ_AC_BK = 0,
  47707. - ATH_TXQ_AC_BE = 1,
  47708. + ATH_TXQ_AC_BE = 0,
  47709. + ATH_TXQ_AC_BK = 1,
  47710. ATH_TXQ_AC_VI = 2,
  47711. ATH_TXQ_AC_VO = 3,
  47712. };
  47713. diff -Nur linux-3.12.38/drivers/net/wireless/ath/ath9k/mac.c linux-rpi/drivers/net/wireless/ath/ath9k/mac.c
  47714. --- linux-3.12.38/drivers/net/wireless/ath/ath9k/mac.c 2015-02-16 16:15:42.000000000 +0100
  47715. +++ linux-rpi/drivers/net/wireless/ath/ath9k/mac.c 2015-03-10 17:26:50.766216691 +0100
  47716. @@ -311,7 +311,14 @@
  47717. q = ATH9K_NUM_TX_QUEUES - 3;
  47718. break;
  47719. case ATH9K_TX_QUEUE_DATA:
  47720. - q = qinfo->tqi_subtype;
  47721. + for (q = 0; q < ATH9K_NUM_TX_QUEUES; q++)
  47722. + if (ah->txq[q].tqi_type ==
  47723. + ATH9K_TX_QUEUE_INACTIVE)
  47724. + break;
  47725. + if (q == ATH9K_NUM_TX_QUEUES) {
  47726. + ath_err(common, "No available TX queue\n");
  47727. + return -1;
  47728. + }
  47729. break;
  47730. default:
  47731. ath_err(common, "Invalid TX queue type: %u\n", type);
  47732. diff -Nur linux-3.12.38/drivers/parport/parport_pc.c linux-rpi/drivers/parport/parport_pc.c
  47733. --- linux-3.12.38/drivers/parport/parport_pc.c 2015-02-16 16:15:42.000000000 +0100
  47734. +++ linux-rpi/drivers/parport/parport_pc.c 2015-03-10 17:26:50.866216690 +0100
  47735. @@ -3312,14 +3312,13 @@
  47736. while (!list_empty(&ports_list)) {
  47737. struct parport_pc_private *priv;
  47738. struct parport *port;
  47739. - struct device *dev;
  47740. priv = list_entry(ports_list.next,
  47741. struct parport_pc_private, list);
  47742. port = priv->port;
  47743. - dev = port->dev;
  47744. + if (port->dev && port->dev->bus == &platform_bus_type)
  47745. + platform_device_unregister(
  47746. + to_platform_device(port->dev));
  47747. parport_pc_unregister_port(port);
  47748. - if (dev && dev->bus == &platform_bus_type)
  47749. - platform_device_unregister(to_platform_device(dev));
  47750. }
  47751. }
  47752. diff -Nur linux-3.12.38/drivers/pci/probe.c linux-rpi/drivers/pci/probe.c
  47753. --- linux-3.12.38/drivers/pci/probe.c 2015-02-16 16:15:42.000000000 +0100
  47754. +++ linux-rpi/drivers/pci/probe.c 2015-03-10 17:26:50.878216690 +0100
  47755. @@ -214,17 +214,14 @@
  47756. res->flags |= IORESOURCE_SIZEALIGN;
  47757. if (res->flags & IORESOURCE_IO) {
  47758. l &= PCI_BASE_ADDRESS_IO_MASK;
  47759. - sz &= PCI_BASE_ADDRESS_IO_MASK;
  47760. mask = PCI_BASE_ADDRESS_IO_MASK & (u32) IO_SPACE_LIMIT;
  47761. } else {
  47762. l &= PCI_BASE_ADDRESS_MEM_MASK;
  47763. - sz &= PCI_BASE_ADDRESS_MEM_MASK;
  47764. mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
  47765. }
  47766. } else {
  47767. res->flags |= (l & IORESOURCE_ROM_ENABLE);
  47768. l &= PCI_ROM_ADDRESS_MASK;
  47769. - sz &= PCI_ROM_ADDRESS_MASK;
  47770. mask = (u32)PCI_ROM_ADDRESS_MASK;
  47771. }
  47772. diff -Nur linux-3.12.38/drivers/pinctrl/core.c linux-rpi/drivers/pinctrl/core.c
  47773. --- linux-3.12.38/drivers/pinctrl/core.c 2015-02-16 16:15:42.000000000 +0100
  47774. +++ linux-rpi/drivers/pinctrl/core.c 2015-03-10 17:26:50.878216690 +0100
  47775. @@ -1796,15 +1796,14 @@
  47776. if (pctldev == NULL)
  47777. return;
  47778. + mutex_lock(&pinctrldev_list_mutex);
  47779. mutex_lock(&pctldev->mutex);
  47780. +
  47781. pinctrl_remove_device_debugfs(pctldev);
  47782. - mutex_unlock(&pctldev->mutex);
  47783. if (!IS_ERR(pctldev->p))
  47784. pinctrl_put(pctldev->p);
  47785. - mutex_lock(&pinctrldev_list_mutex);
  47786. - mutex_lock(&pctldev->mutex);
  47787. /* TODO: check that no pinmuxes are still active? */
  47788. list_del(&pctldev->node);
  47789. /* Destroy descriptor tree */
  47790. diff -Nur linux-3.12.38/drivers/platform/x86/asus-nb-wmi.c linux-rpi/drivers/platform/x86/asus-nb-wmi.c
  47791. --- linux-3.12.38/drivers/platform/x86/asus-nb-wmi.c 2015-02-16 16:15:42.000000000 +0100
  47792. +++ linux-rpi/drivers/platform/x86/asus-nb-wmi.c 2015-03-10 17:26:50.898216690 +0100
  47793. @@ -70,14 +70,10 @@
  47794. .no_display_toggle = true,
  47795. };
  47796. -static struct quirk_entry quirk_asus_wapf4 = {
  47797. +static struct quirk_entry quirk_asus_x401u = {
  47798. .wapf = 4,
  47799. };
  47800. -static struct quirk_entry quirk_asus_x200ca = {
  47801. - .wapf = 2,
  47802. -};
  47803. -
  47804. static int dmi_matched(const struct dmi_system_id *dmi)
  47805. {
  47806. quirks = dmi->driver_data;
  47807. @@ -87,20 +83,6 @@
  47808. static struct dmi_system_id asus_quirks[] = {
  47809. {
  47810. .callback = dmi_matched,
  47811. - .ident = "ASUSTeK COMPUTER INC. U32U",
  47812. - .matches = {
  47813. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  47814. - DMI_MATCH(DMI_PRODUCT_NAME, "U32U"),
  47815. - },
  47816. - /*
  47817. - * Note this machine has a Brazos APU, and most Brazos Asus
  47818. - * machines need quirk_asus_x55u / wmi_backlight_power but
  47819. - * here acpi-video seems to work fine for backlight control.
  47820. - */
  47821. - .driver_data = &quirk_asus_wapf4,
  47822. - },
  47823. - {
  47824. - .callback = dmi_matched,
  47825. .ident = "ASUSTeK COMPUTER INC. X401U",
  47826. .matches = {
  47827. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47828. @@ -115,7 +97,7 @@
  47829. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47830. DMI_MATCH(DMI_PRODUCT_NAME, "X401A"),
  47831. },
  47832. - .driver_data = &quirk_asus_wapf4,
  47833. + .driver_data = &quirk_asus_x401u,
  47834. },
  47835. {
  47836. .callback = dmi_matched,
  47837. @@ -124,7 +106,7 @@
  47838. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47839. DMI_MATCH(DMI_PRODUCT_NAME, "X401A1"),
  47840. },
  47841. - .driver_data = &quirk_asus_wapf4,
  47842. + .driver_data = &quirk_asus_x401u,
  47843. },
  47844. {
  47845. .callback = dmi_matched,
  47846. @@ -142,7 +124,7 @@
  47847. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47848. DMI_MATCH(DMI_PRODUCT_NAME, "X501A"),
  47849. },
  47850. - .driver_data = &quirk_asus_wapf4,
  47851. + .driver_data = &quirk_asus_x401u,
  47852. },
  47853. {
  47854. .callback = dmi_matched,
  47855. @@ -151,52 +133,7 @@
  47856. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47857. DMI_MATCH(DMI_PRODUCT_NAME, "X501A1"),
  47858. },
  47859. - .driver_data = &quirk_asus_wapf4,
  47860. - },
  47861. - {
  47862. - .callback = dmi_matched,
  47863. - .ident = "ASUSTeK COMPUTER INC. X550CA",
  47864. - .matches = {
  47865. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47866. - DMI_MATCH(DMI_PRODUCT_NAME, "X550CA"),
  47867. - },
  47868. - .driver_data = &quirk_asus_wapf4,
  47869. - },
  47870. - {
  47871. - .callback = dmi_matched,
  47872. - .ident = "ASUSTeK COMPUTER INC. X550CC",
  47873. - .matches = {
  47874. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47875. - DMI_MATCH(DMI_PRODUCT_NAME, "X550CC"),
  47876. - },
  47877. - .driver_data = &quirk_asus_wapf4,
  47878. - },
  47879. - {
  47880. - .callback = dmi_matched,
  47881. - .ident = "ASUSTeK COMPUTER INC. X550CL",
  47882. - .matches = {
  47883. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47884. - DMI_MATCH(DMI_PRODUCT_NAME, "X550CL"),
  47885. - },
  47886. - .driver_data = &quirk_asus_wapf4,
  47887. - },
  47888. - {
  47889. - .callback = dmi_matched,
  47890. - .ident = "ASUSTeK COMPUTER INC. X550VB",
  47891. - .matches = {
  47892. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47893. - DMI_MATCH(DMI_PRODUCT_NAME, "X550VB"),
  47894. - },
  47895. - .driver_data = &quirk_asus_wapf4,
  47896. - },
  47897. - {
  47898. - .callback = dmi_matched,
  47899. - .ident = "ASUSTeK COMPUTER INC. X551CA",
  47900. - .matches = {
  47901. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47902. - DMI_MATCH(DMI_PRODUCT_NAME, "X551CA"),
  47903. - },
  47904. - .driver_data = &quirk_asus_wapf4,
  47905. + .driver_data = &quirk_asus_x401u,
  47906. },
  47907. {
  47908. .callback = dmi_matched,
  47909. @@ -205,7 +142,7 @@
  47910. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47911. DMI_MATCH(DMI_PRODUCT_NAME, "X55A"),
  47912. },
  47913. - .driver_data = &quirk_asus_wapf4,
  47914. + .driver_data = &quirk_asus_x401u,
  47915. },
  47916. {
  47917. .callback = dmi_matched,
  47918. @@ -214,7 +151,7 @@
  47919. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47920. DMI_MATCH(DMI_PRODUCT_NAME, "X55C"),
  47921. },
  47922. - .driver_data = &quirk_asus_wapf4,
  47923. + .driver_data = &quirk_asus_x401u,
  47924. },
  47925. {
  47926. .callback = dmi_matched,
  47927. @@ -232,7 +169,7 @@
  47928. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47929. DMI_MATCH(DMI_PRODUCT_NAME, "X55VD"),
  47930. },
  47931. - .driver_data = &quirk_asus_wapf4,
  47932. + .driver_data = &quirk_asus_x401u,
  47933. },
  47934. {
  47935. .callback = dmi_matched,
  47936. @@ -241,16 +178,7 @@
  47937. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47938. DMI_MATCH(DMI_PRODUCT_NAME, "X75A"),
  47939. },
  47940. - .driver_data = &quirk_asus_wapf4,
  47941. - },
  47942. - {
  47943. - .callback = dmi_matched,
  47944. - .ident = "ASUSTeK COMPUTER INC. X75VBP",
  47945. - .matches = {
  47946. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47947. - DMI_MATCH(DMI_PRODUCT_NAME, "X75VBP"),
  47948. - },
  47949. - .driver_data = &quirk_asus_wapf4,
  47950. + .driver_data = &quirk_asus_x401u,
  47951. },
  47952. {
  47953. .callback = dmi_matched,
  47954. @@ -259,7 +187,7 @@
  47955. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47956. DMI_MATCH(DMI_PRODUCT_NAME, "1015E"),
  47957. },
  47958. - .driver_data = &quirk_asus_wapf4,
  47959. + .driver_data = &quirk_asus_x401u,
  47960. },
  47961. {
  47962. .callback = dmi_matched,
  47963. @@ -268,16 +196,7 @@
  47964. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47965. DMI_MATCH(DMI_PRODUCT_NAME, "1015U"),
  47966. },
  47967. - .driver_data = &quirk_asus_wapf4,
  47968. - },
  47969. - {
  47970. - .callback = dmi_matched,
  47971. - .ident = "ASUSTeK COMPUTER INC. X200CA",
  47972. - .matches = {
  47973. - DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  47974. - DMI_MATCH(DMI_PRODUCT_NAME, "X200CA"),
  47975. - },
  47976. - .driver_data = &quirk_asus_x200ca,
  47977. + .driver_data = &quirk_asus_x401u,
  47978. },
  47979. {},
  47980. };
  47981. diff -Nur linux-3.12.38/drivers/platform/x86/hp_accel.c linux-rpi/drivers/platform/x86/hp_accel.c
  47982. --- linux-3.12.38/drivers/platform/x86/hp_accel.c 2015-02-16 16:15:42.000000000 +0100
  47983. +++ linux-rpi/drivers/platform/x86/hp_accel.c 2015-03-10 17:26:50.898216690 +0100
  47984. @@ -237,7 +237,6 @@
  47985. AXIS_DMI_MATCH("HPB64xx", "HP ProBook 64", xy_swap),
  47986. AXIS_DMI_MATCH("HPB64xx", "HP EliteBook 84", xy_swap),
  47987. AXIS_DMI_MATCH("HPB65xx", "HP ProBook 65", x_inverted),
  47988. - AXIS_DMI_MATCH("HPZBook15", "HP ZBook 15", x_inverted),
  47989. { NULL, }
  47990. /* Laptop models without axis info (yet):
  47991. * "NC6910" "HP Compaq 6910"
  47992. diff -Nur linux-3.12.38/drivers/regulator/core.c linux-rpi/drivers/regulator/core.c
  47993. --- linux-3.12.38/drivers/regulator/core.c 2015-02-16 16:15:42.000000000 +0100
  47994. +++ linux-rpi/drivers/regulator/core.c 2015-03-10 17:26:50.910216690 +0100
  47995. @@ -1474,7 +1474,7 @@
  47996. }
  47997. EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
  47998. -/* regulator_list_mutex lock held by regulator_put() */
  47999. +/* Locks held by regulator_put() */
  48000. static void _regulator_put(struct regulator *regulator)
  48001. {
  48002. struct regulator_dev *rdev;
  48003. @@ -1489,14 +1489,12 @@
  48004. /* remove any sysfs entries */
  48005. if (regulator->dev)
  48006. sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
  48007. - mutex_lock(&rdev->mutex);
  48008. kfree(regulator->supply_name);
  48009. list_del(&regulator->list);
  48010. kfree(regulator);
  48011. rdev->open_count--;
  48012. rdev->exclusive = 0;
  48013. - mutex_unlock(&rdev->mutex);
  48014. module_put(rdev->owner);
  48015. }
  48016. diff -Nur linux-3.12.38/drivers/rtc/rtc-sirfsoc.c linux-rpi/drivers/rtc/rtc-sirfsoc.c
  48017. --- linux-3.12.38/drivers/rtc/rtc-sirfsoc.c 2015-02-16 16:15:42.000000000 +0100
  48018. +++ linux-rpi/drivers/rtc/rtc-sirfsoc.c 2015-03-10 17:26:50.922216690 +0100
  48019. @@ -290,6 +290,14 @@
  48020. rtc_div = ((32768 / RTC_HZ) / 2) - 1;
  48021. sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
  48022. + rtcdrv->rtc = rtc_device_register(pdev->name, &(pdev->dev),
  48023. + &sirfsoc_rtc_ops, THIS_MODULE);
  48024. + if (IS_ERR(rtcdrv->rtc)) {
  48025. + err = PTR_ERR(rtcdrv->rtc);
  48026. + dev_err(&pdev->dev, "can't register RTC device\n");
  48027. + return err;
  48028. + }
  48029. +
  48030. /* 0x3 -> RTC_CLK */
  48031. sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK,
  48032. rtcdrv->rtc_base + RTC_CLOCK_SWITCH);
  48033. @@ -304,14 +312,6 @@
  48034. rtcdrv->overflow_rtc =
  48035. sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE);
  48036. - rtcdrv->rtc = rtc_device_register(pdev->name, &(pdev->dev),
  48037. - &sirfsoc_rtc_ops, THIS_MODULE);
  48038. - if (IS_ERR(rtcdrv->rtc)) {
  48039. - err = PTR_ERR(rtcdrv->rtc);
  48040. - dev_err(&pdev->dev, "can't register RTC device\n");
  48041. - return err;
  48042. - }
  48043. -
  48044. rtcdrv->irq = platform_get_irq(pdev, 0);
  48045. err = devm_request_irq(
  48046. &pdev->dev,
  48047. diff -Nur linux-3.12.38/drivers/s390/crypto/ap_bus.c linux-rpi/drivers/s390/crypto/ap_bus.c
  48048. --- linux-3.12.38/drivers/s390/crypto/ap_bus.c 2015-02-16 16:15:42.000000000 +0100
  48049. +++ linux-rpi/drivers/s390/crypto/ap_bus.c 2015-03-10 17:26:50.930216690 +0100
  48050. @@ -44,7 +44,6 @@
  48051. #include <linux/hrtimer.h>
  48052. #include <linux/ktime.h>
  48053. #include <asm/facility.h>
  48054. -#include <linux/crypto.h>
  48055. #include "ap_bus.h"
  48056. @@ -72,7 +71,7 @@
  48057. MODULE_DESCRIPTION("Adjunct Processor Bus driver, " \
  48058. "Copyright IBM Corp. 2006, 2012");
  48059. MODULE_LICENSE("GPL");
  48060. -MODULE_ALIAS_CRYPTO("z90crypt");
  48061. +MODULE_ALIAS("z90crypt");
  48062. /*
  48063. * Module parameter
  48064. diff -Nur linux-3.12.38/drivers/scsi/ipr.c linux-rpi/drivers/scsi/ipr.c
  48065. --- linux-3.12.38/drivers/scsi/ipr.c 2015-02-16 16:15:42.000000000 +0100
  48066. +++ linux-rpi/drivers/scsi/ipr.c 2015-03-10 17:26:50.974216689 +0100
  48067. @@ -683,7 +683,6 @@
  48068. ipr_reinit_ipr_cmnd(ipr_cmd);
  48069. ipr_cmd->u.scratch = 0;
  48070. ipr_cmd->sibling = NULL;
  48071. - ipr_cmd->eh_comp = NULL;
  48072. ipr_cmd->fast_done = fast_done;
  48073. init_timer(&ipr_cmd->timer);
  48074. }
  48075. @@ -849,8 +848,6 @@
  48076. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  48077. scsi_cmd->scsi_done(scsi_cmd);
  48078. - if (ipr_cmd->eh_comp)
  48079. - complete(ipr_cmd->eh_comp);
  48080. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  48081. }
  48082. @@ -4808,84 +4805,6 @@
  48083. return rc;
  48084. }
  48085. -/**
  48086. - * ipr_match_lun - Match function for specified LUN
  48087. - * @ipr_cmd: ipr command struct
  48088. - * @device: device to match (sdev)
  48089. - *
  48090. - * Returns:
  48091. - * 1 if command matches sdev / 0 if command does not match sdev
  48092. - **/
  48093. -static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
  48094. -{
  48095. - if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
  48096. - return 1;
  48097. - return 0;
  48098. -}
  48099. -
  48100. -/**
  48101. - * ipr_wait_for_ops - Wait for matching commands to complete
  48102. - * @ipr_cmd: ipr command struct
  48103. - * @device: device to match (sdev)
  48104. - * @match: match function to use
  48105. - *
  48106. - * Returns:
  48107. - * SUCCESS / FAILED
  48108. - **/
  48109. -static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
  48110. - int (*match)(struct ipr_cmnd *, void *))
  48111. -{
  48112. - struct ipr_cmnd *ipr_cmd;
  48113. - int wait;
  48114. - unsigned long flags;
  48115. - struct ipr_hrr_queue *hrrq;
  48116. - signed long timeout = IPR_ABORT_TASK_TIMEOUT;
  48117. - DECLARE_COMPLETION_ONSTACK(comp);
  48118. -
  48119. - ENTER;
  48120. - do {
  48121. - wait = 0;
  48122. -
  48123. - for_each_hrrq(hrrq, ioa_cfg) {
  48124. - spin_lock_irqsave(hrrq->lock, flags);
  48125. - list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
  48126. - if (match(ipr_cmd, device)) {
  48127. - ipr_cmd->eh_comp = &comp;
  48128. - wait++;
  48129. - }
  48130. - }
  48131. - spin_unlock_irqrestore(hrrq->lock, flags);
  48132. - }
  48133. -
  48134. - if (wait) {
  48135. - timeout = wait_for_completion_timeout(&comp, timeout);
  48136. -
  48137. - if (!timeout) {
  48138. - wait = 0;
  48139. -
  48140. - for_each_hrrq(hrrq, ioa_cfg) {
  48141. - spin_lock_irqsave(hrrq->lock, flags);
  48142. - list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
  48143. - if (match(ipr_cmd, device)) {
  48144. - ipr_cmd->eh_comp = NULL;
  48145. - wait++;
  48146. - }
  48147. - }
  48148. - spin_unlock_irqrestore(hrrq->lock, flags);
  48149. - }
  48150. -
  48151. - if (wait)
  48152. - dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
  48153. - LEAVE;
  48154. - return wait ? FAILED : SUCCESS;
  48155. - }
  48156. - }
  48157. - } while (wait);
  48158. -
  48159. - LEAVE;
  48160. - return SUCCESS;
  48161. -}
  48162. -
  48163. static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
  48164. {
  48165. struct ipr_ioa_cfg *ioa_cfg;
  48166. @@ -5104,17 +5023,11 @@
  48167. static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
  48168. {
  48169. int rc;
  48170. - struct ipr_ioa_cfg *ioa_cfg;
  48171. -
  48172. - ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
  48173. spin_lock_irq(cmd->device->host->host_lock);
  48174. rc = __ipr_eh_dev_reset(cmd);
  48175. spin_unlock_irq(cmd->device->host->host_lock);
  48176. - if (rc == SUCCESS)
  48177. - rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
  48178. -
  48179. return rc;
  48180. }
  48181. @@ -5292,18 +5205,13 @@
  48182. {
  48183. unsigned long flags;
  48184. int rc;
  48185. - struct ipr_ioa_cfg *ioa_cfg;
  48186. ENTER;
  48187. - ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  48188. -
  48189. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  48190. rc = ipr_cancel_op(scsi_cmd);
  48191. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  48192. - if (rc == SUCCESS)
  48193. - rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
  48194. LEAVE;
  48195. return rc;
  48196. }
  48197. diff -Nur linux-3.12.38/drivers/scsi/ipr.h linux-rpi/drivers/scsi/ipr.h
  48198. --- linux-3.12.38/drivers/scsi/ipr.h 2015-02-16 16:15:42.000000000 +0100
  48199. +++ linux-rpi/drivers/scsi/ipr.h 2015-03-10 17:26:50.974216689 +0100
  48200. @@ -1588,7 +1588,6 @@
  48201. struct scsi_device *sdev;
  48202. } u;
  48203. - struct completion *eh_comp;
  48204. struct ipr_hrr_queue *hrrq;
  48205. struct ipr_ioa_cfg *ioa_cfg;
  48206. };
  48207. diff -Nur linux-3.12.38/drivers/scsi/mpt2sas/mpt2sas_transport.c linux-rpi/drivers/scsi/mpt2sas/mpt2sas_transport.c
  48208. --- linux-3.12.38/drivers/scsi/mpt2sas/mpt2sas_transport.c 2015-02-16 16:15:42.000000000 +0100
  48209. +++ linux-rpi/drivers/scsi/mpt2sas/mpt2sas_transport.c 2015-03-10 17:26:50.994216689 +0100
  48210. @@ -1006,9 +1006,12 @@
  48211. &mpt2sas_phy->remote_identify);
  48212. _transport_add_phy_to_an_existing_port(ioc, sas_node,
  48213. mpt2sas_phy, mpt2sas_phy->remote_identify.sas_address);
  48214. - } else
  48215. + } else {
  48216. memset(&mpt2sas_phy->remote_identify, 0 , sizeof(struct
  48217. sas_identify));
  48218. + _transport_del_phy_from_an_existing_port(ioc, sas_node,
  48219. + mpt2sas_phy);
  48220. + }
  48221. if (mpt2sas_phy->phy)
  48222. mpt2sas_phy->phy->negotiated_linkrate =
  48223. diff -Nur linux-3.12.38/drivers/scsi/mpt3sas/mpt3sas_transport.c linux-rpi/drivers/scsi/mpt3sas/mpt3sas_transport.c
  48224. --- linux-3.12.38/drivers/scsi/mpt3sas/mpt3sas_transport.c 2015-02-16 16:15:42.000000000 +0100
  48225. +++ linux-rpi/drivers/scsi/mpt3sas/mpt3sas_transport.c 2015-03-10 17:26:50.998216689 +0100
  48226. @@ -1003,9 +1003,12 @@
  48227. &mpt3sas_phy->remote_identify);
  48228. _transport_add_phy_to_an_existing_port(ioc, sas_node,
  48229. mpt3sas_phy, mpt3sas_phy->remote_identify.sas_address);
  48230. - } else
  48231. + } else {
  48232. memset(&mpt3sas_phy->remote_identify, 0 , sizeof(struct
  48233. sas_identify));
  48234. + _transport_del_phy_from_an_existing_port(ioc, sas_node,
  48235. + mpt3sas_phy);
  48236. + }
  48237. if (mpt3sas_phy->phy)
  48238. mpt3sas_phy->phy->negotiated_linkrate =
  48239. diff -Nur linux-3.12.38/drivers/scsi/scsi_devinfo.c linux-rpi/drivers/scsi/scsi_devinfo.c
  48240. --- linux-3.12.38/drivers/scsi/scsi_devinfo.c 2015-02-16 16:15:42.000000000 +0100
  48241. +++ linux-rpi/drivers/scsi/scsi_devinfo.c 2015-03-10 17:26:51.018216689 +0100
  48242. @@ -211,7 +211,6 @@
  48243. {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN},
  48244. {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
  48245. {"MICROP", "4110", NULL, BLIST_NOTQ},
  48246. - {"MSFT", "Virtual HD", NULL, BLIST_NO_RSOC},
  48247. {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
  48248. {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
  48249. {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  48250. diff -Nur linux-3.12.38/drivers/scsi/scsi_lib.c linux-rpi/drivers/scsi/scsi_lib.c
  48251. --- linux-3.12.38/drivers/scsi/scsi_lib.c 2015-02-16 16:15:42.000000000 +0100
  48252. +++ linux-rpi/drivers/scsi/scsi_lib.c 2015-03-10 17:26:51.018216689 +0100
  48253. @@ -831,14 +831,6 @@
  48254. scsi_next_command(cmd);
  48255. return;
  48256. }
  48257. - } else if (blk_rq_bytes(req) == 0 && result && !sense_deferred) {
  48258. - /*
  48259. - * Certain non BLOCK_PC requests are commands that don't
  48260. - * actually transfer anything (FLUSH), so cannot use
  48261. - * good_bytes != blk_rq_bytes(req) as the signal for an error.
  48262. - * This sets the error explicitly for the problem case.
  48263. - */
  48264. - error = __scsi_error_from_host_byte(cmd, result);
  48265. }
  48266. /* no bidi support for !REQ_TYPE_BLOCK_PC yet */
  48267. diff -Nur linux-3.12.38/drivers/scsi/storvsc_drv.c linux-rpi/drivers/scsi/storvsc_drv.c
  48268. --- linux-3.12.38/drivers/scsi/storvsc_drv.c 2015-02-16 16:15:42.000000000 +0100
  48269. +++ linux-rpi/drivers/scsi/storvsc_drv.c 2015-03-10 17:26:51.022216689 +0100
  48270. @@ -1690,12 +1690,13 @@
  48271. if (ret == -EAGAIN) {
  48272. /* no more space */
  48273. - if (cmd_request->bounce_sgl_count)
  48274. + if (cmd_request->bounce_sgl_count) {
  48275. destroy_bounce_buffer(cmd_request->bounce_sgl,
  48276. cmd_request->bounce_sgl_count);
  48277. - ret = SCSI_MLQUEUE_DEVICE_BUSY;
  48278. - goto queue_error;
  48279. + ret = SCSI_MLQUEUE_DEVICE_BUSY;
  48280. + goto queue_error;
  48281. + }
  48282. }
  48283. return 0;
  48284. diff -Nur linux-3.12.38/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  48285. --- linux-3.12.38/drivers/spi/Kconfig 2015-02-16 16:15:42.000000000 +0100
  48286. +++ linux-rpi/drivers/spi/Kconfig 2015-03-10 17:26:51.030216689 +0100
  48287. @@ -85,6 +85,14 @@
  48288. is for the regular SPI controller. Slave mode operation is not also
  48289. not supported.
  48290. +config SPI_BCM2708
  48291. + tristate "BCM2708 SPI controller driver (SPI0)"
  48292. + depends on MACH_BCM2708
  48293. + help
  48294. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  48295. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  48296. + device.
  48297. +
  48298. config SPI_BFIN5XX
  48299. tristate "SPI controller driver for ADI Blackfin5xx"
  48300. depends on BLACKFIN && !BF60x
  48301. diff -Nur linux-3.12.38/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  48302. --- linux-3.12.38/drivers/spi/Makefile 2015-02-16 16:15:42.000000000 +0100
  48303. +++ linux-rpi/drivers/spi/Makefile 2015-03-10 17:26:51.030216689 +0100
  48304. @@ -18,6 +18,7 @@
  48305. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  48306. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  48307. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  48308. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  48309. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  48310. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  48311. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  48312. diff -Nur linux-3.12.38/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  48313. --- linux-3.12.38/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  48314. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2015-03-10 17:26:51.030216689 +0100
  48315. @@ -0,0 +1,626 @@
  48316. +/*
  48317. + * Driver for Broadcom BCM2708 SPI Controllers
  48318. + *
  48319. + * Copyright (C) 2012 Chris Boot
  48320. + *
  48321. + * This driver is inspired by:
  48322. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  48323. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  48324. + *
  48325. + * This program is free software; you can redistribute it and/or modify
  48326. + * it under the terms of the GNU General Public License as published by
  48327. + * the Free Software Foundation; either version 2 of the License, or
  48328. + * (at your option) any later version.
  48329. + *
  48330. + * This program is distributed in the hope that it will be useful,
  48331. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48332. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48333. + * GNU General Public License for more details.
  48334. + *
  48335. + * You should have received a copy of the GNU General Public License
  48336. + * along with this program; if not, write to the Free Software
  48337. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  48338. + */
  48339. +
  48340. +#include <linux/kernel.h>
  48341. +#include <linux/module.h>
  48342. +#include <linux/spinlock.h>
  48343. +#include <linux/clk.h>
  48344. +#include <linux/err.h>
  48345. +#include <linux/platform_device.h>
  48346. +#include <linux/io.h>
  48347. +#include <linux/spi/spi.h>
  48348. +#include <linux/interrupt.h>
  48349. +#include <linux/delay.h>
  48350. +#include <linux/log2.h>
  48351. +#include <linux/sched.h>
  48352. +#include <linux/wait.h>
  48353. +
  48354. +/* SPI register offsets */
  48355. +#define SPI_CS 0x00
  48356. +#define SPI_FIFO 0x04
  48357. +#define SPI_CLK 0x08
  48358. +#define SPI_DLEN 0x0c
  48359. +#define SPI_LTOH 0x10
  48360. +#define SPI_DC 0x14
  48361. +
  48362. +/* Bitfields in CS */
  48363. +#define SPI_CS_LEN_LONG 0x02000000
  48364. +#define SPI_CS_DMA_LEN 0x01000000
  48365. +#define SPI_CS_CSPOL2 0x00800000
  48366. +#define SPI_CS_CSPOL1 0x00400000
  48367. +#define SPI_CS_CSPOL0 0x00200000
  48368. +#define SPI_CS_RXF 0x00100000
  48369. +#define SPI_CS_RXR 0x00080000
  48370. +#define SPI_CS_TXD 0x00040000
  48371. +#define SPI_CS_RXD 0x00020000
  48372. +#define SPI_CS_DONE 0x00010000
  48373. +#define SPI_CS_LEN 0x00002000
  48374. +#define SPI_CS_REN 0x00001000
  48375. +#define SPI_CS_ADCS 0x00000800
  48376. +#define SPI_CS_INTR 0x00000400
  48377. +#define SPI_CS_INTD 0x00000200
  48378. +#define SPI_CS_DMAEN 0x00000100
  48379. +#define SPI_CS_TA 0x00000080
  48380. +#define SPI_CS_CSPOL 0x00000040
  48381. +#define SPI_CS_CLEAR_RX 0x00000020
  48382. +#define SPI_CS_CLEAR_TX 0x00000010
  48383. +#define SPI_CS_CPOL 0x00000008
  48384. +#define SPI_CS_CPHA 0x00000004
  48385. +#define SPI_CS_CS_10 0x00000002
  48386. +#define SPI_CS_CS_01 0x00000001
  48387. +
  48388. +#define SPI_TIMEOUT_MS 150
  48389. +
  48390. +#define DRV_NAME "bcm2708_spi"
  48391. +
  48392. +struct bcm2708_spi {
  48393. + spinlock_t lock;
  48394. + void __iomem *base;
  48395. + int irq;
  48396. + struct clk *clk;
  48397. + bool stopping;
  48398. +
  48399. + struct list_head queue;
  48400. + struct workqueue_struct *workq;
  48401. + struct work_struct work;
  48402. + struct completion done;
  48403. +
  48404. + const u8 *tx_buf;
  48405. + u8 *rx_buf;
  48406. + int len;
  48407. +};
  48408. +
  48409. +struct bcm2708_spi_state {
  48410. + u32 cs;
  48411. + u16 cdiv;
  48412. +};
  48413. +
  48414. +/*
  48415. + * This function sets the ALT mode on the SPI pins so that we can use them with
  48416. + * the SPI hardware.
  48417. + *
  48418. + * FIXME: This is a hack. Use pinmux / pinctrl.
  48419. + */
  48420. +static void bcm2708_init_pinmode(void)
  48421. +{
  48422. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  48423. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  48424. +
  48425. + int pin;
  48426. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  48427. +
  48428. + /* SPI is on GPIO 7..11 */
  48429. + for (pin = 7; pin <= 11; pin++) {
  48430. + INP_GPIO(pin); /* set mode to GPIO input first */
  48431. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  48432. + }
  48433. +
  48434. + iounmap(gpio);
  48435. +
  48436. +#undef INP_GPIO
  48437. +#undef SET_GPIO_ALT
  48438. +}
  48439. +
  48440. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  48441. +{
  48442. + return readl(bs->base + reg);
  48443. +}
  48444. +
  48445. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  48446. +{
  48447. + writel(val, bs->base + reg);
  48448. +}
  48449. +
  48450. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  48451. +{
  48452. + u8 byte;
  48453. +
  48454. + while (len--) {
  48455. + byte = bcm2708_rd(bs, SPI_FIFO);
  48456. + if (bs->rx_buf)
  48457. + *bs->rx_buf++ = byte;
  48458. + }
  48459. +}
  48460. +
  48461. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  48462. +{
  48463. + u8 byte;
  48464. + u16 val;
  48465. +
  48466. + if (len > bs->len)
  48467. + len = bs->len;
  48468. +
  48469. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  48470. + /* LoSSI mode */
  48471. + if (unlikely(len % 2)) {
  48472. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  48473. + bs->len = 0;
  48474. + return;
  48475. + }
  48476. + while (len) {
  48477. + if (bs->tx_buf) {
  48478. + val = *(const u16 *)bs->tx_buf;
  48479. + bs->tx_buf += 2;
  48480. + } else
  48481. + val = 0;
  48482. + bcm2708_wr(bs, SPI_FIFO, val);
  48483. + bs->len -= 2;
  48484. + len -= 2;
  48485. + }
  48486. + return;
  48487. + }
  48488. +
  48489. + while (len--) {
  48490. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  48491. + bcm2708_wr(bs, SPI_FIFO, byte);
  48492. + bs->len--;
  48493. + }
  48494. +}
  48495. +
  48496. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  48497. +{
  48498. + struct spi_master *master = dev_id;
  48499. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48500. + u32 cs;
  48501. +
  48502. + spin_lock(&bs->lock);
  48503. +
  48504. + cs = bcm2708_rd(bs, SPI_CS);
  48505. +
  48506. + if (cs & SPI_CS_DONE) {
  48507. + if (bs->len) { /* first interrupt in a transfer */
  48508. + /* fill the TX fifo with up to 16 bytes */
  48509. + bcm2708_wr_fifo(bs, 16);
  48510. + } else { /* transfer complete */
  48511. + /* disable interrupts */
  48512. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  48513. + bcm2708_wr(bs, SPI_CS, cs);
  48514. +
  48515. + /* drain RX FIFO */
  48516. + while (cs & SPI_CS_RXD) {
  48517. + bcm2708_rd_fifo(bs, 1);
  48518. + cs = bcm2708_rd(bs, SPI_CS);
  48519. + }
  48520. +
  48521. + /* wake up our bh */
  48522. + complete(&bs->done);
  48523. + }
  48524. + } else if (cs & SPI_CS_RXR) {
  48525. + /* read 12 bytes of data */
  48526. + bcm2708_rd_fifo(bs, 12);
  48527. +
  48528. + /* write up to 12 bytes */
  48529. + bcm2708_wr_fifo(bs, 12);
  48530. + }
  48531. +
  48532. + spin_unlock(&bs->lock);
  48533. +
  48534. + return IRQ_HANDLED;
  48535. +}
  48536. +
  48537. +static int bcm2708_setup_state(struct spi_master *master,
  48538. + struct device *dev, struct bcm2708_spi_state *state,
  48539. + u32 hz, u8 csel, u8 mode, u8 bpw)
  48540. +{
  48541. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48542. + int cdiv;
  48543. + unsigned long bus_hz;
  48544. + u32 cs = 0;
  48545. +
  48546. + bus_hz = clk_get_rate(bs->clk);
  48547. +
  48548. + if (hz >= bus_hz) {
  48549. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  48550. + } else if (hz) {
  48551. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  48552. +
  48553. + /* CDIV must be a power of 2, so round up */
  48554. + cdiv = roundup_pow_of_two(cdiv);
  48555. +
  48556. + if (cdiv > 65536) {
  48557. + dev_dbg(dev,
  48558. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  48559. + hz, cdiv, bus_hz / 65536);
  48560. + return -EINVAL;
  48561. + } else if (cdiv == 65536) {
  48562. + cdiv = 0;
  48563. + } else if (cdiv == 1) {
  48564. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  48565. + }
  48566. + } else {
  48567. + cdiv = 0;
  48568. + }
  48569. +
  48570. + switch (bpw) {
  48571. + case 8:
  48572. + break;
  48573. + case 9:
  48574. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  48575. + cs |= SPI_CS_LEN;
  48576. + break;
  48577. + default:
  48578. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  48579. + bpw);
  48580. + return -EINVAL;
  48581. + }
  48582. +
  48583. + if (mode & SPI_CPOL)
  48584. + cs |= SPI_CS_CPOL;
  48585. + if (mode & SPI_CPHA)
  48586. + cs |= SPI_CS_CPHA;
  48587. +
  48588. + if (!(mode & SPI_NO_CS)) {
  48589. + if (mode & SPI_CS_HIGH) {
  48590. + cs |= SPI_CS_CSPOL;
  48591. + cs |= SPI_CS_CSPOL0 << csel;
  48592. + }
  48593. +
  48594. + cs |= csel;
  48595. + } else {
  48596. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  48597. + }
  48598. +
  48599. + if (state) {
  48600. + state->cs = cs;
  48601. + state->cdiv = cdiv;
  48602. + dev_dbg(dev, "setup: want %d Hz; "
  48603. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  48604. + "mode %u: cs 0x%08X\n",
  48605. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  48606. + }
  48607. +
  48608. + return 0;
  48609. +}
  48610. +
  48611. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  48612. + struct spi_message *msg, struct spi_transfer *xfer)
  48613. +{
  48614. + struct spi_device *spi = msg->spi;
  48615. + struct bcm2708_spi_state state, *stp;
  48616. + int ret;
  48617. + u32 cs;
  48618. +
  48619. + if (bs->stopping)
  48620. + return -ESHUTDOWN;
  48621. +
  48622. + if (xfer->bits_per_word || xfer->speed_hz) {
  48623. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  48624. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48625. + spi->chip_select, spi->mode,
  48626. + xfer->bits_per_word ? xfer->bits_per_word :
  48627. + spi->bits_per_word);
  48628. + if (ret)
  48629. + return ret;
  48630. +
  48631. + stp = &state;
  48632. + } else {
  48633. + stp = spi->controller_state;
  48634. + }
  48635. +
  48636. + INIT_COMPLETION(bs->done);
  48637. + bs->tx_buf = xfer->tx_buf;
  48638. + bs->rx_buf = xfer->rx_buf;
  48639. + bs->len = xfer->len;
  48640. +
  48641. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  48642. +
  48643. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  48644. + bcm2708_wr(bs, SPI_CS, cs);
  48645. +
  48646. + ret = wait_for_completion_timeout(&bs->done,
  48647. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  48648. + if (ret == 0) {
  48649. + dev_err(&spi->dev, "transfer timed out\n");
  48650. + return -ETIMEDOUT;
  48651. + }
  48652. +
  48653. + if (xfer->delay_usecs)
  48654. + udelay(xfer->delay_usecs);
  48655. +
  48656. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  48657. + xfer->cs_change) {
  48658. + /* clear TA and interrupt flags */
  48659. + bcm2708_wr(bs, SPI_CS, stp->cs);
  48660. + }
  48661. +
  48662. + msg->actual_length += (xfer->len - bs->len);
  48663. +
  48664. + return 0;
  48665. +}
  48666. +
  48667. +static void bcm2708_work(struct work_struct *work)
  48668. +{
  48669. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  48670. + unsigned long flags;
  48671. + struct spi_message *msg;
  48672. + struct spi_transfer *xfer;
  48673. + int status = 0;
  48674. +
  48675. + spin_lock_irqsave(&bs->lock, flags);
  48676. + while (!list_empty(&bs->queue)) {
  48677. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  48678. + list_del_init(&msg->queue);
  48679. + spin_unlock_irqrestore(&bs->lock, flags);
  48680. +
  48681. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48682. + status = bcm2708_process_transfer(bs, msg, xfer);
  48683. + if (status)
  48684. + break;
  48685. + }
  48686. +
  48687. + msg->status = status;
  48688. + msg->complete(msg->context);
  48689. +
  48690. + spin_lock_irqsave(&bs->lock, flags);
  48691. + }
  48692. + spin_unlock_irqrestore(&bs->lock, flags);
  48693. +}
  48694. +
  48695. +static int bcm2708_spi_setup(struct spi_device *spi)
  48696. +{
  48697. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48698. + struct bcm2708_spi_state *state;
  48699. + int ret;
  48700. +
  48701. + if (bs->stopping)
  48702. + return -ESHUTDOWN;
  48703. +
  48704. + if (!(spi->mode & SPI_NO_CS) &&
  48705. + (spi->chip_select > spi->master->num_chipselect)) {
  48706. + dev_dbg(&spi->dev,
  48707. + "setup: invalid chipselect %u (%u defined)\n",
  48708. + spi->chip_select, spi->master->num_chipselect);
  48709. + return -EINVAL;
  48710. + }
  48711. +
  48712. + state = spi->controller_state;
  48713. + if (!state) {
  48714. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  48715. + if (!state)
  48716. + return -ENOMEM;
  48717. +
  48718. + spi->controller_state = state;
  48719. + }
  48720. +
  48721. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  48722. + spi->max_speed_hz, spi->chip_select, spi->mode,
  48723. + spi->bits_per_word);
  48724. + if (ret < 0) {
  48725. + kfree(state);
  48726. + spi->controller_state = NULL;
  48727. + return ret;
  48728. + }
  48729. +
  48730. + dev_dbg(&spi->dev,
  48731. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  48732. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  48733. + spi->mode, state->cs, state->cdiv);
  48734. +
  48735. + return 0;
  48736. +}
  48737. +
  48738. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  48739. +{
  48740. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  48741. + struct spi_transfer *xfer;
  48742. + int ret;
  48743. + unsigned long flags;
  48744. +
  48745. + if (unlikely(list_empty(&msg->transfers)))
  48746. + return -EINVAL;
  48747. +
  48748. + if (bs->stopping)
  48749. + return -ESHUTDOWN;
  48750. +
  48751. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  48752. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  48753. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  48754. + return -EINVAL;
  48755. + }
  48756. +
  48757. + if (!xfer->bits_per_word || xfer->speed_hz)
  48758. + continue;
  48759. +
  48760. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  48761. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  48762. + spi->chip_select, spi->mode,
  48763. + xfer->bits_per_word ? xfer->bits_per_word :
  48764. + spi->bits_per_word);
  48765. + if (ret)
  48766. + return ret;
  48767. + }
  48768. +
  48769. + msg->status = -EINPROGRESS;
  48770. + msg->actual_length = 0;
  48771. +
  48772. + spin_lock_irqsave(&bs->lock, flags);
  48773. + list_add_tail(&msg->queue, &bs->queue);
  48774. + queue_work(bs->workq, &bs->work);
  48775. + spin_unlock_irqrestore(&bs->lock, flags);
  48776. +
  48777. + return 0;
  48778. +}
  48779. +
  48780. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  48781. +{
  48782. + if (spi->controller_state) {
  48783. + kfree(spi->controller_state);
  48784. + spi->controller_state = NULL;
  48785. + }
  48786. +}
  48787. +
  48788. +static int bcm2708_spi_probe(struct platform_device *pdev)
  48789. +{
  48790. + struct resource *regs;
  48791. + int irq, err = -ENOMEM;
  48792. + struct clk *clk;
  48793. + struct spi_master *master;
  48794. + struct bcm2708_spi *bs;
  48795. +
  48796. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  48797. + if (!regs) {
  48798. + dev_err(&pdev->dev, "could not get IO memory\n");
  48799. + return -ENXIO;
  48800. + }
  48801. +
  48802. + irq = platform_get_irq(pdev, 0);
  48803. + if (irq < 0) {
  48804. + dev_err(&pdev->dev, "could not get IRQ\n");
  48805. + return irq;
  48806. + }
  48807. +
  48808. + clk = clk_get(&pdev->dev, NULL);
  48809. + if (IS_ERR(clk)) {
  48810. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  48811. + return PTR_ERR(clk);
  48812. + }
  48813. +
  48814. + bcm2708_init_pinmode();
  48815. +
  48816. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  48817. + if (!master) {
  48818. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  48819. + goto out_clk_put;
  48820. + }
  48821. +
  48822. + /* the spi->mode bits understood by this driver: */
  48823. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  48824. +
  48825. + master->bus_num = pdev->id;
  48826. + master->num_chipselect = 3;
  48827. + master->setup = bcm2708_spi_setup;
  48828. + master->transfer = bcm2708_spi_transfer;
  48829. + master->cleanup = bcm2708_spi_cleanup;
  48830. + platform_set_drvdata(pdev, master);
  48831. +
  48832. + bs = spi_master_get_devdata(master);
  48833. +
  48834. + spin_lock_init(&bs->lock);
  48835. + INIT_LIST_HEAD(&bs->queue);
  48836. + init_completion(&bs->done);
  48837. + INIT_WORK(&bs->work, bcm2708_work);
  48838. +
  48839. + bs->base = ioremap(regs->start, resource_size(regs));
  48840. + if (!bs->base) {
  48841. + dev_err(&pdev->dev, "could not remap memory\n");
  48842. + goto out_master_put;
  48843. + }
  48844. +
  48845. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  48846. + if (!bs->workq) {
  48847. + dev_err(&pdev->dev, "could not create workqueue\n");
  48848. + goto out_iounmap;
  48849. + }
  48850. +
  48851. + bs->irq = irq;
  48852. + bs->clk = clk;
  48853. + bs->stopping = false;
  48854. +
  48855. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  48856. + master);
  48857. + if (err) {
  48858. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  48859. + goto out_workqueue;
  48860. + }
  48861. +
  48862. + /* initialise the hardware */
  48863. + clk_enable(clk);
  48864. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48865. +
  48866. + err = spi_register_master(master);
  48867. + if (err) {
  48868. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  48869. + goto out_free_irq;
  48870. + }
  48871. +
  48872. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  48873. + (unsigned long)regs->start, irq);
  48874. +
  48875. + return 0;
  48876. +
  48877. +out_free_irq:
  48878. + free_irq(bs->irq, master);
  48879. +out_workqueue:
  48880. + destroy_workqueue(bs->workq);
  48881. +out_iounmap:
  48882. + iounmap(bs->base);
  48883. +out_master_put:
  48884. + spi_master_put(master);
  48885. +out_clk_put:
  48886. + clk_put(clk);
  48887. + return err;
  48888. +}
  48889. +
  48890. +static int bcm2708_spi_remove(struct platform_device *pdev)
  48891. +{
  48892. + struct spi_master *master = platform_get_drvdata(pdev);
  48893. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  48894. +
  48895. + /* reset the hardware and block queue progress */
  48896. + spin_lock_irq(&bs->lock);
  48897. + bs->stopping = true;
  48898. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  48899. + spin_unlock_irq(&bs->lock);
  48900. +
  48901. + flush_work_sync(&bs->work);
  48902. +
  48903. + clk_disable(bs->clk);
  48904. + clk_put(bs->clk);
  48905. + free_irq(bs->irq, master);
  48906. + iounmap(bs->base);
  48907. +
  48908. + spi_unregister_master(master);
  48909. +
  48910. + return 0;
  48911. +}
  48912. +
  48913. +static struct platform_driver bcm2708_spi_driver = {
  48914. + .driver = {
  48915. + .name = DRV_NAME,
  48916. + .owner = THIS_MODULE,
  48917. + },
  48918. + .probe = bcm2708_spi_probe,
  48919. + .remove = bcm2708_spi_remove,
  48920. +};
  48921. +
  48922. +
  48923. +static int __init bcm2708_spi_init(void)
  48924. +{
  48925. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  48926. +}
  48927. +module_init(bcm2708_spi_init);
  48928. +
  48929. +static void __exit bcm2708_spi_exit(void)
  48930. +{
  48931. + platform_driver_unregister(&bcm2708_spi_driver);
  48932. +}
  48933. +module_exit(bcm2708_spi_exit);
  48934. +
  48935. +
  48936. +//module_platform_driver(bcm2708_spi_driver);
  48937. +
  48938. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  48939. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  48940. +MODULE_LICENSE("GPL v2");
  48941. +MODULE_ALIAS("platform:" DRV_NAME);
  48942. diff -Nur linux-3.12.38/drivers/spi/spi-dw-mid.c linux-rpi/drivers/spi/spi-dw-mid.c
  48943. --- linux-3.12.38/drivers/spi/spi-dw-mid.c 2015-02-16 16:15:42.000000000 +0100
  48944. +++ linux-rpi/drivers/spi/spi-dw-mid.c 2015-03-10 17:26:51.030216689 +0100
  48945. @@ -222,6 +222,7 @@
  48946. iounmap(clk_reg);
  48947. dws->num_cs = 16;
  48948. + dws->fifo_len = 40; /* FIFO has 40 words buffer */
  48949. #ifdef CONFIG_SPI_DW_MID_DMA
  48950. dws->dma_priv = kzalloc(sizeof(struct mid_dma), GFP_KERNEL);
  48951. diff -Nur linux-3.12.38/drivers/spi/spi-fsl-spi.c linux-rpi/drivers/spi/spi-fsl-spi.c
  48952. --- linux-3.12.38/drivers/spi/spi-fsl-spi.c 2015-02-16 16:15:42.000000000 +0100
  48953. +++ linux-rpi/drivers/spi/spi-fsl-spi.c 2015-03-10 17:26:51.030216689 +0100
  48954. @@ -362,28 +362,18 @@
  48955. static void fsl_spi_do_one_msg(struct spi_message *m)
  48956. {
  48957. struct spi_device *spi = m->spi;
  48958. - struct spi_transfer *t, *first;
  48959. + struct spi_transfer *t;
  48960. unsigned int cs_change;
  48961. const int nsecs = 50;
  48962. int status;
  48963. - /* Don't allow changes if CS is active */
  48964. - first = list_first_entry(&m->transfers, struct spi_transfer,
  48965. - transfer_list);
  48966. - list_for_each_entry(t, &m->transfers, transfer_list) {
  48967. - if ((first->bits_per_word != t->bits_per_word) ||
  48968. - (first->speed_hz != t->speed_hz)) {
  48969. - status = -EINVAL;
  48970. - dev_err(&spi->dev,
  48971. - "bits_per_word/speed_hz should be same for the same SPI transfer\n");
  48972. - return;
  48973. - }
  48974. - }
  48975. -
  48976. cs_change = 1;
  48977. - status = -EINVAL;
  48978. + status = 0;
  48979. list_for_each_entry(t, &m->transfers, transfer_list) {
  48980. if (t->bits_per_word || t->speed_hz) {
  48981. + /* Don't allow changes if CS is active */
  48982. + status = -EINVAL;
  48983. +
  48984. if (cs_change)
  48985. status = fsl_spi_setup_transfer(spi, t);
  48986. if (status < 0)
  48987. diff -Nur linux-3.12.38/drivers/spi/spi-pxa2xx.c linux-rpi/drivers/spi/spi-pxa2xx.c
  48988. --- linux-3.12.38/drivers/spi/spi-pxa2xx.c 2015-02-16 16:15:42.000000000 +0100
  48989. +++ linux-rpi/drivers/spi/spi-pxa2xx.c 2015-03-10 17:26:51.034216689 +0100
  48990. @@ -400,8 +400,8 @@
  48991. cs_deassert(drv_data);
  48992. }
  48993. - drv_data->cur_chip = NULL;
  48994. spi_finalize_current_message(drv_data->master);
  48995. + drv_data->cur_chip = NULL;
  48996. }
  48997. static void reset_sccr1(struct driver_data *drv_data)
  48998. diff -Nur linux-3.12.38/drivers/staging/lustre/lustre/llite/dcache.c linux-rpi/drivers/staging/lustre/lustre/llite/dcache.c
  48999. --- linux-3.12.38/drivers/staging/lustre/lustre/llite/dcache.c 2015-02-16 16:15:42.000000000 +0100
  49000. +++ linux-rpi/drivers/staging/lustre/lustre/llite/dcache.c 2015-03-10 17:26:51.118216689 +0100
  49001. @@ -278,7 +278,7 @@
  49002. inode->i_ino, inode->i_generation, inode);
  49003. ll_lock_dcache(inode);
  49004. - ll_d_hlist_for_each_entry(dentry, p, &inode->i_dentry, d_u.d_alias) {
  49005. + ll_d_hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) {
  49006. CDEBUG(D_DENTRY, "dentry in drop %.*s (%p) parent %p "
  49007. "inode %p flags %d\n", dentry->d_name.len,
  49008. dentry->d_name.name, dentry, dentry->d_parent,
  49009. diff -Nur linux-3.12.38/drivers/staging/lustre/lustre/llite/llite_lib.c linux-rpi/drivers/staging/lustre/lustre/llite/llite_lib.c
  49010. --- linux-3.12.38/drivers/staging/lustre/lustre/llite/llite_lib.c 2015-02-16 16:15:42.000000000 +0100
  49011. +++ linux-rpi/drivers/staging/lustre/lustre/llite/llite_lib.c 2015-03-10 17:26:51.118216689 +0100
  49012. @@ -665,7 +665,7 @@
  49013. return;
  49014. list_for_each(tmp, &dentry->d_subdirs) {
  49015. - struct dentry *d = list_entry(tmp, struct dentry, d_child);
  49016. + struct dentry *d = list_entry(tmp, struct dentry, d_u.d_child);
  49017. lustre_dump_dentry(d, recur - 1);
  49018. }
  49019. }
  49020. diff -Nur linux-3.12.38/drivers/staging/lustre/lustre/llite/namei.c linux-rpi/drivers/staging/lustre/lustre/llite/namei.c
  49021. --- linux-3.12.38/drivers/staging/lustre/lustre/llite/namei.c 2015-02-16 16:15:42.000000000 +0100
  49022. +++ linux-rpi/drivers/staging/lustre/lustre/llite/namei.c 2015-03-10 17:26:51.122216688 +0100
  49023. @@ -175,14 +175,14 @@
  49024. struct ll_d_hlist_node *p;
  49025. ll_lock_dcache(dir);
  49026. - ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry, d_u.d_alias) {
  49027. + ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry, d_alias) {
  49028. spin_lock(&dentry->d_lock);
  49029. if (!list_empty(&dentry->d_subdirs)) {
  49030. struct dentry *child;
  49031. list_for_each_entry_safe(child, tmp_subdir,
  49032. &dentry->d_subdirs,
  49033. - d_child) {
  49034. + d_u.d_child) {
  49035. if (child->d_inode == NULL)
  49036. d_lustre_invalidate(child, 1);
  49037. }
  49038. @@ -363,7 +363,7 @@
  49039. discon_alias = invalid_alias = NULL;
  49040. ll_lock_dcache(inode);
  49041. - ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry, d_u.d_alias) {
  49042. + ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry, d_alias) {
  49043. LASSERT(alias != dentry);
  49044. spin_lock(&alias->d_lock);
  49045. @@ -953,7 +953,7 @@
  49046. {
  49047. struct dentry *parent, *child;
  49048. - parent = ll_d_hlist_entry(dir->i_dentry, struct dentry, d_u.d_alias);
  49049. + parent = ll_d_hlist_entry(dir->i_dentry, struct dentry, d_alias);
  49050. child = d_lookup(parent, name);
  49051. if (child) {
  49052. if (child->d_inode)
  49053. diff -Nur linux-3.12.38/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  49054. --- linux-3.12.38/drivers/staging/media/lirc/Kconfig 2015-02-16 16:15:42.000000000 +0100
  49055. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2015-03-09 10:39:32.818893720 +0100
  49056. @@ -38,6 +38,12 @@
  49057. help
  49058. Driver for Homebrew Parallel Port Receivers
  49059. +config LIRC_RPI
  49060. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  49061. + depends on LIRC
  49062. + help
  49063. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  49064. +
  49065. config LIRC_SASEM
  49066. tristate "Sasem USB IR Remote"
  49067. depends on LIRC && USB
  49068. diff -Nur linux-3.12.38/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  49069. --- linux-3.12.38/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  49070. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2015-03-10 17:26:51.146216688 +0100
  49071. @@ -0,0 +1,689 @@
  49072. +/*
  49073. + * lirc_rpi.c
  49074. + *
  49075. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  49076. + * (space-lengths) (just like the lirc_serial driver does)
  49077. + * between GPIO interrupt events on the Raspberry Pi.
  49078. + * Lots of code has been taken from the lirc_serial module,
  49079. + * so I would like say thanks to the authors.
  49080. + *
  49081. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  49082. + * Michael Bishop <cleverca22@gmail.com>
  49083. + * This program is free software; you can redistribute it and/or modify
  49084. + * it under the terms of the GNU General Public License as published by
  49085. + * the Free Software Foundation; either version 2 of the License, or
  49086. + * (at your option) any later version.
  49087. + *
  49088. + * This program is distributed in the hope that it will be useful,
  49089. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  49090. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49091. + * GNU General Public License for more details.
  49092. + *
  49093. + * You should have received a copy of the GNU General Public License
  49094. + * along with this program; if not, write to the Free Software
  49095. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  49096. + */
  49097. +
  49098. +#include <linux/module.h>
  49099. +#include <linux/errno.h>
  49100. +#include <linux/interrupt.h>
  49101. +#include <linux/sched.h>
  49102. +#include <linux/kernel.h>
  49103. +#include <linux/time.h>
  49104. +#include <linux/timex.h>
  49105. +#include <linux/string.h>
  49106. +#include <linux/delay.h>
  49107. +#include <linux/platform_device.h>
  49108. +#include <linux/irq.h>
  49109. +#include <linux/spinlock.h>
  49110. +#include <media/lirc.h>
  49111. +#include <media/lirc_dev.h>
  49112. +#include <mach/gpio.h>
  49113. +#include <linux/gpio.h>
  49114. +
  49115. +#include <linux/platform_data/bcm2708.h>
  49116. +
  49117. +#define LIRC_DRIVER_NAME "lirc_rpi"
  49118. +#define RBUF_LEN 256
  49119. +#define LIRC_TRANSMITTER_LATENCY 50
  49120. +
  49121. +#ifndef MAX_UDELAY_MS
  49122. +#define MAX_UDELAY_US 5000
  49123. +#else
  49124. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  49125. +#endif
  49126. +
  49127. +#define dprintk(fmt, args...) \
  49128. + do { \
  49129. + if (debug) \
  49130. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  49131. + fmt, ## args); \
  49132. + } while (0)
  49133. +
  49134. +/* module parameters */
  49135. +
  49136. +/* set the default GPIO input pin */
  49137. +static int gpio_in_pin = 18;
  49138. +/* set the default pull behaviour for input pin */
  49139. +static int gpio_in_pull = BCM2708_PULL_DOWN;
  49140. +/* set the default GPIO output pin */
  49141. +static int gpio_out_pin = 17;
  49142. +/* enable debugging messages */
  49143. +static bool debug;
  49144. +/* -1 = auto, 0 = active high, 1 = active low */
  49145. +static int sense = -1;
  49146. +/* use softcarrier by default */
  49147. +static bool softcarrier = 1;
  49148. +/* 0 = do not invert output, 1 = invert output */
  49149. +static bool invert = 0;
  49150. +
  49151. +struct gpio_chip *gpiochip;
  49152. +struct irq_chip *irqchip;
  49153. +struct irq_data *irqdata;
  49154. +
  49155. +/* forward declarations */
  49156. +static long send_pulse(unsigned long length);
  49157. +static void send_space(long length);
  49158. +static void lirc_rpi_exit(void);
  49159. +
  49160. +static struct platform_device *lirc_rpi_dev;
  49161. +static struct timeval lasttv = { 0, 0 };
  49162. +static struct lirc_buffer rbuf;
  49163. +static spinlock_t lock;
  49164. +
  49165. +/* initialized/set in init_timing_params() */
  49166. +static unsigned int freq = 38000;
  49167. +static unsigned int duty_cycle = 50;
  49168. +static unsigned long period;
  49169. +static unsigned long pulse_width;
  49170. +static unsigned long space_width;
  49171. +
  49172. +static void safe_udelay(unsigned long usecs)
  49173. +{
  49174. + while (usecs > MAX_UDELAY_US) {
  49175. + udelay(MAX_UDELAY_US);
  49176. + usecs -= MAX_UDELAY_US;
  49177. + }
  49178. + udelay(usecs);
  49179. +}
  49180. +
  49181. +static int init_timing_params(unsigned int new_duty_cycle,
  49182. + unsigned int new_freq)
  49183. +{
  49184. + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
  49185. + LIRC_TRANSMITTER_LATENCY)
  49186. + return -EINVAL;
  49187. + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  49188. + LIRC_TRANSMITTER_LATENCY)
  49189. + return -EINVAL;
  49190. + duty_cycle = new_duty_cycle;
  49191. + freq = new_freq;
  49192. + period = 1000 * 1000000L / freq;
  49193. + pulse_width = period * duty_cycle / 100;
  49194. + space_width = period - pulse_width;
  49195. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  49196. + "space=%ld\n", freq, pulse_width, space_width);
  49197. + return 0;
  49198. +}
  49199. +
  49200. +static long send_pulse_softcarrier(unsigned long length)
  49201. +{
  49202. + int flag;
  49203. + unsigned long actual, target;
  49204. + unsigned long actual_us, initial_us, target_us;
  49205. +
  49206. + length *= 1000;
  49207. +
  49208. + actual = 0; target = 0; flag = 0;
  49209. + read_current_timer(&actual_us);
  49210. +
  49211. + while (actual < length) {
  49212. + if (flag) {
  49213. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49214. + target += space_width;
  49215. + } else {
  49216. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  49217. + target += pulse_width;
  49218. + }
  49219. + initial_us = actual_us;
  49220. + target_us = actual_us + (target - actual) / 1000;
  49221. + /*
  49222. + * Note - we've checked in ioctl that the pulse/space
  49223. + * widths are big enough so that d is > 0
  49224. + */
  49225. + if ((int)(target_us - actual_us) > 0)
  49226. + udelay(target_us - actual_us);
  49227. + read_current_timer(&actual_us);
  49228. + actual += (actual_us - initial_us) * 1000;
  49229. + flag = !flag;
  49230. + }
  49231. + return (actual-length) / 1000;
  49232. +}
  49233. +
  49234. +static long send_pulse(unsigned long length)
  49235. +{
  49236. + if (length <= 0)
  49237. + return 0;
  49238. +
  49239. + if (softcarrier) {
  49240. + return send_pulse_softcarrier(length);
  49241. + } else {
  49242. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  49243. + safe_udelay(length);
  49244. + return 0;
  49245. + }
  49246. +}
  49247. +
  49248. +static void send_space(long length)
  49249. +{
  49250. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49251. + if (length <= 0)
  49252. + return;
  49253. + safe_udelay(length);
  49254. +}
  49255. +
  49256. +static void rbwrite(int l)
  49257. +{
  49258. + if (lirc_buffer_full(&rbuf)) {
  49259. + /* no new signals will be accepted */
  49260. + dprintk("Buffer overrun\n");
  49261. + return;
  49262. + }
  49263. + lirc_buffer_write(&rbuf, (void *)&l);
  49264. +}
  49265. +
  49266. +static void frbwrite(int l)
  49267. +{
  49268. + /* simple noise filter */
  49269. + static int pulse, space;
  49270. + static unsigned int ptr;
  49271. +
  49272. + if (ptr > 0 && (l & PULSE_BIT)) {
  49273. + pulse += l & PULSE_MASK;
  49274. + if (pulse > 250) {
  49275. + rbwrite(space);
  49276. + rbwrite(pulse | PULSE_BIT);
  49277. + ptr = 0;
  49278. + pulse = 0;
  49279. + }
  49280. + return;
  49281. + }
  49282. + if (!(l & PULSE_BIT)) {
  49283. + if (ptr == 0) {
  49284. + if (l > 20000) {
  49285. + space = l;
  49286. + ptr++;
  49287. + return;
  49288. + }
  49289. + } else {
  49290. + if (l > 20000) {
  49291. + space += pulse;
  49292. + if (space > PULSE_MASK)
  49293. + space = PULSE_MASK;
  49294. + space += l;
  49295. + if (space > PULSE_MASK)
  49296. + space = PULSE_MASK;
  49297. + pulse = 0;
  49298. + return;
  49299. + }
  49300. + rbwrite(space);
  49301. + rbwrite(pulse | PULSE_BIT);
  49302. + ptr = 0;
  49303. + pulse = 0;
  49304. + }
  49305. + }
  49306. + rbwrite(l);
  49307. +}
  49308. +
  49309. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  49310. +{
  49311. + struct timeval tv;
  49312. + long deltv;
  49313. + int data;
  49314. + int signal;
  49315. +
  49316. + /* use the GPIO signal level */
  49317. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  49318. +
  49319. + /* unmask the irq */
  49320. + irqchip->irq_unmask(irqdata);
  49321. +
  49322. + if (sense != -1) {
  49323. + /* get current time */
  49324. + do_gettimeofday(&tv);
  49325. +
  49326. + /* calc time since last interrupt in microseconds */
  49327. + deltv = tv.tv_sec-lasttv.tv_sec;
  49328. + if (tv.tv_sec < lasttv.tv_sec ||
  49329. + (tv.tv_sec == lasttv.tv_sec &&
  49330. + tv.tv_usec < lasttv.tv_usec)) {
  49331. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49332. + ": AIEEEE: your clock just jumped backwards\n");
  49333. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49334. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  49335. + tv.tv_sec, lasttv.tv_sec,
  49336. + tv.tv_usec, lasttv.tv_usec);
  49337. + data = PULSE_MASK;
  49338. + } else if (deltv > 15) {
  49339. + data = PULSE_MASK; /* really long time */
  49340. + if (!(signal^sense)) {
  49341. + /* sanity check */
  49342. + printk(KERN_WARNING LIRC_DRIVER_NAME
  49343. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  49344. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  49345. + tv.tv_usec, lasttv.tv_usec);
  49346. + /*
  49347. + * detecting pulse while this
  49348. + * MUST be a space!
  49349. + */
  49350. + sense = sense ? 0 : 1;
  49351. + }
  49352. + } else {
  49353. + data = (int) (deltv*1000000 +
  49354. + (tv.tv_usec - lasttv.tv_usec));
  49355. + }
  49356. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  49357. + lasttv = tv;
  49358. + wake_up_interruptible(&rbuf.wait_poll);
  49359. + }
  49360. +
  49361. + return IRQ_HANDLED;
  49362. +}
  49363. +
  49364. +static int is_right_chip(struct gpio_chip *chip, void *data)
  49365. +{
  49366. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  49367. +
  49368. + if (strcmp(data, chip->label) == 0)
  49369. + return 1;
  49370. + return 0;
  49371. +}
  49372. +
  49373. +static int init_port(void)
  49374. +{
  49375. + int i, nlow, nhigh, ret, irq;
  49376. +
  49377. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  49378. +
  49379. + if (!gpiochip)
  49380. + return -ENODEV;
  49381. +
  49382. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  49383. + printk(KERN_ALERT LIRC_DRIVER_NAME
  49384. + ": cant claim gpio pin %d\n", gpio_out_pin);
  49385. + ret = -ENODEV;
  49386. + goto exit_init_port;
  49387. + }
  49388. +
  49389. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  49390. + printk(KERN_ALERT LIRC_DRIVER_NAME
  49391. + ": cant claim gpio pin %d\n", gpio_in_pin);
  49392. + ret = -ENODEV;
  49393. + goto exit_gpio_free_out_pin;
  49394. + }
  49395. +
  49396. + bcm2708_gpio_setpull(gpiochip, gpio_in_pin, gpio_in_pull);
  49397. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  49398. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  49399. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49400. +
  49401. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  49402. + dprintk("to_irq %d\n", irq);
  49403. + irqdata = irq_get_irq_data(irq);
  49404. +
  49405. + if (irqdata && irqdata->chip) {
  49406. + irqchip = irqdata->chip;
  49407. + } else {
  49408. + ret = -ENODEV;
  49409. + goto exit_gpio_free_in_pin;
  49410. + }
  49411. +
  49412. + /* if pin is high, then this must be an active low receiver. */
  49413. + if (sense == -1) {
  49414. + /* wait 1/2 sec for the power supply */
  49415. + msleep(500);
  49416. +
  49417. + /*
  49418. + * probe 9 times every 0.04s, collect "votes" for
  49419. + * active high/low
  49420. + */
  49421. + nlow = 0;
  49422. + nhigh = 0;
  49423. + for (i = 0; i < 9; i++) {
  49424. + if (gpiochip->get(gpiochip, gpio_in_pin))
  49425. + nlow++;
  49426. + else
  49427. + nhigh++;
  49428. + msleep(40);
  49429. + }
  49430. + sense = (nlow >= nhigh ? 1 : 0);
  49431. + printk(KERN_INFO LIRC_DRIVER_NAME
  49432. + ": auto-detected active %s receiver on GPIO pin %d\n",
  49433. + sense ? "low" : "high", gpio_in_pin);
  49434. + } else {
  49435. + printk(KERN_INFO LIRC_DRIVER_NAME
  49436. + ": manually using active %s receiver on GPIO pin %d\n",
  49437. + sense ? "low" : "high", gpio_in_pin);
  49438. + }
  49439. +
  49440. + return 0;
  49441. +
  49442. + exit_gpio_free_in_pin:
  49443. + gpio_free(gpio_in_pin);
  49444. +
  49445. + exit_gpio_free_out_pin:
  49446. + gpio_free(gpio_out_pin);
  49447. +
  49448. + exit_init_port:
  49449. + return ret;
  49450. +}
  49451. +
  49452. +// called when the character device is opened
  49453. +static int set_use_inc(void *data)
  49454. +{
  49455. + int result;
  49456. + unsigned long flags;
  49457. +
  49458. + /* initialize timestamp */
  49459. + do_gettimeofday(&lasttv);
  49460. +
  49461. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  49462. + (irq_handler_t) irq_handler, 0,
  49463. + LIRC_DRIVER_NAME, (void*) 0);
  49464. +
  49465. + switch (result) {
  49466. + case -EBUSY:
  49467. + printk(KERN_ERR LIRC_DRIVER_NAME
  49468. + ": IRQ %d is busy\n",
  49469. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  49470. + return -EBUSY;
  49471. + case -EINVAL:
  49472. + printk(KERN_ERR LIRC_DRIVER_NAME
  49473. + ": Bad irq number or handler\n");
  49474. + return -EINVAL;
  49475. + default:
  49476. + dprintk("Interrupt %d obtained\n",
  49477. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  49478. + break;
  49479. + };
  49480. +
  49481. + /* initialize pulse/space widths */
  49482. + init_timing_params(duty_cycle, freq);
  49483. +
  49484. + spin_lock_irqsave(&lock, flags);
  49485. +
  49486. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  49487. + irqchip->irq_set_type(irqdata,
  49488. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  49489. +
  49490. + /* unmask the irq */
  49491. + irqchip->irq_unmask(irqdata);
  49492. +
  49493. + spin_unlock_irqrestore(&lock, flags);
  49494. +
  49495. + return 0;
  49496. +}
  49497. +
  49498. +static void set_use_dec(void *data)
  49499. +{
  49500. + unsigned long flags;
  49501. +
  49502. + spin_lock_irqsave(&lock, flags);
  49503. +
  49504. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  49505. + irqchip->irq_set_type(irqdata, 0);
  49506. + irqchip->irq_mask(irqdata);
  49507. +
  49508. + spin_unlock_irqrestore(&lock, flags);
  49509. +
  49510. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  49511. +
  49512. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  49513. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  49514. +}
  49515. +
  49516. +static ssize_t lirc_write(struct file *file, const char *buf,
  49517. + size_t n, loff_t *ppos)
  49518. +{
  49519. + int i, count;
  49520. + unsigned long flags;
  49521. + long delta = 0;
  49522. + int *wbuf;
  49523. +
  49524. + count = n / sizeof(int);
  49525. + if (n % sizeof(int) || count % 2 == 0)
  49526. + return -EINVAL;
  49527. + wbuf = memdup_user(buf, n);
  49528. + if (IS_ERR(wbuf))
  49529. + return PTR_ERR(wbuf);
  49530. + spin_lock_irqsave(&lock, flags);
  49531. +
  49532. + for (i = 0; i < count; i++) {
  49533. + if (i%2)
  49534. + send_space(wbuf[i] - delta);
  49535. + else
  49536. + delta = send_pulse(wbuf[i]);
  49537. + }
  49538. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  49539. +
  49540. + spin_unlock_irqrestore(&lock, flags);
  49541. + kfree(wbuf);
  49542. + return n;
  49543. +}
  49544. +
  49545. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  49546. +{
  49547. + int result;
  49548. + __u32 value;
  49549. +
  49550. + switch (cmd) {
  49551. + case LIRC_GET_SEND_MODE:
  49552. + return -ENOIOCTLCMD;
  49553. + break;
  49554. +
  49555. + case LIRC_SET_SEND_MODE:
  49556. + result = get_user(value, (__u32 *) arg);
  49557. + if (result)
  49558. + return result;
  49559. + /* only LIRC_MODE_PULSE supported */
  49560. + if (value != LIRC_MODE_PULSE)
  49561. + return -ENOSYS;
  49562. + break;
  49563. +
  49564. + case LIRC_GET_LENGTH:
  49565. + return -ENOSYS;
  49566. + break;
  49567. +
  49568. + case LIRC_SET_SEND_DUTY_CYCLE:
  49569. + dprintk("SET_SEND_DUTY_CYCLE\n");
  49570. + result = get_user(value, (__u32 *) arg);
  49571. + if (result)
  49572. + return result;
  49573. + if (value <= 0 || value > 100)
  49574. + return -EINVAL;
  49575. + return init_timing_params(value, freq);
  49576. + break;
  49577. +
  49578. + case LIRC_SET_SEND_CARRIER:
  49579. + dprintk("SET_SEND_CARRIER\n");
  49580. + result = get_user(value, (__u32 *) arg);
  49581. + if (result)
  49582. + return result;
  49583. + if (value > 500000 || value < 20000)
  49584. + return -EINVAL;
  49585. + return init_timing_params(duty_cycle, value);
  49586. + break;
  49587. +
  49588. + default:
  49589. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  49590. + }
  49591. + return 0;
  49592. +}
  49593. +
  49594. +static const struct file_operations lirc_fops = {
  49595. + .owner = THIS_MODULE,
  49596. + .write = lirc_write,
  49597. + .unlocked_ioctl = lirc_ioctl,
  49598. + .read = lirc_dev_fop_read,
  49599. + .poll = lirc_dev_fop_poll,
  49600. + .open = lirc_dev_fop_open,
  49601. + .release = lirc_dev_fop_close,
  49602. + .llseek = no_llseek,
  49603. +};
  49604. +
  49605. +static struct lirc_driver driver = {
  49606. + .name = LIRC_DRIVER_NAME,
  49607. + .minor = -1,
  49608. + .code_length = 1,
  49609. + .sample_rate = 0,
  49610. + .data = NULL,
  49611. + .add_to_buf = NULL,
  49612. + .rbuf = &rbuf,
  49613. + .set_use_inc = set_use_inc,
  49614. + .set_use_dec = set_use_dec,
  49615. + .fops = &lirc_fops,
  49616. + .dev = NULL,
  49617. + .owner = THIS_MODULE,
  49618. +};
  49619. +
  49620. +static struct platform_driver lirc_rpi_driver = {
  49621. + .driver = {
  49622. + .name = LIRC_DRIVER_NAME,
  49623. + .owner = THIS_MODULE,
  49624. + },
  49625. +};
  49626. +
  49627. +static int __init lirc_rpi_init(void)
  49628. +{
  49629. + int result;
  49630. +
  49631. + /* Init read buffer. */
  49632. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  49633. + if (result < 0)
  49634. + return -ENOMEM;
  49635. +
  49636. + result = platform_driver_register(&lirc_rpi_driver);
  49637. + if (result) {
  49638. + printk(KERN_ERR LIRC_DRIVER_NAME
  49639. + ": lirc register returned %d\n", result);
  49640. + goto exit_buffer_free;
  49641. + }
  49642. +
  49643. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  49644. + if (!lirc_rpi_dev) {
  49645. + result = -ENOMEM;
  49646. + goto exit_driver_unregister;
  49647. + }
  49648. +
  49649. + result = platform_device_add(lirc_rpi_dev);
  49650. + if (result)
  49651. + goto exit_device_put;
  49652. +
  49653. + return 0;
  49654. +
  49655. + exit_device_put:
  49656. + platform_device_put(lirc_rpi_dev);
  49657. +
  49658. + exit_driver_unregister:
  49659. + platform_driver_unregister(&lirc_rpi_driver);
  49660. +
  49661. + exit_buffer_free:
  49662. + lirc_buffer_free(&rbuf);
  49663. +
  49664. + return result;
  49665. +}
  49666. +
  49667. +static void lirc_rpi_exit(void)
  49668. +{
  49669. + platform_device_unregister(lirc_rpi_dev);
  49670. + platform_driver_unregister(&lirc_rpi_driver);
  49671. + lirc_buffer_free(&rbuf);
  49672. +}
  49673. +
  49674. +static int __init lirc_rpi_init_module(void)
  49675. +{
  49676. + int result;
  49677. +
  49678. + result = lirc_rpi_init();
  49679. + if (result)
  49680. + return result;
  49681. +
  49682. + if (gpio_in_pin >= BCM2708_NR_GPIOS || gpio_out_pin >= BCM2708_NR_GPIOS) {
  49683. + result = -EINVAL;
  49684. + printk(KERN_ERR LIRC_DRIVER_NAME
  49685. + ": invalid GPIO pin(s) specified!\n");
  49686. + goto exit_rpi;
  49687. + }
  49688. +
  49689. + result = init_port();
  49690. + if (result < 0)
  49691. + goto exit_rpi;
  49692. +
  49693. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  49694. + LIRC_CAN_SET_SEND_CARRIER |
  49695. + LIRC_CAN_SEND_PULSE |
  49696. + LIRC_CAN_REC_MODE2;
  49697. +
  49698. + driver.dev = &lirc_rpi_dev->dev;
  49699. + driver.minor = lirc_register_driver(&driver);
  49700. +
  49701. + if (driver.minor < 0) {
  49702. + printk(KERN_ERR LIRC_DRIVER_NAME
  49703. + ": device registration failed with %d\n", result);
  49704. + result = -EIO;
  49705. + goto exit_rpi;
  49706. + }
  49707. +
  49708. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  49709. +
  49710. + return 0;
  49711. +
  49712. + exit_rpi:
  49713. + lirc_rpi_exit();
  49714. +
  49715. + return result;
  49716. +}
  49717. +
  49718. +static void __exit lirc_rpi_exit_module(void)
  49719. +{
  49720. + gpio_free(gpio_out_pin);
  49721. + gpio_free(gpio_in_pin);
  49722. +
  49723. + lirc_rpi_exit();
  49724. +
  49725. + lirc_unregister_driver(driver.minor);
  49726. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  49727. +}
  49728. +
  49729. +module_init(lirc_rpi_init_module);
  49730. +module_exit(lirc_rpi_exit_module);
  49731. +
  49732. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  49733. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  49734. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  49735. +MODULE_LICENSE("GPL");
  49736. +
  49737. +module_param(gpio_out_pin, int, S_IRUGO);
  49738. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  49739. + " processor. (default 17");
  49740. +
  49741. +module_param(gpio_in_pin, int, S_IRUGO);
  49742. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  49743. + " (default 18");
  49744. +
  49745. +module_param(gpio_in_pull, int, S_IRUGO);
  49746. +MODULE_PARM_DESC(gpio_in_pull, "GPIO input pin pull configuration."
  49747. + " (0 = off, 1 = up, 2 = down, default down)");
  49748. +
  49749. +module_param(sense, int, S_IRUGO);
  49750. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  49751. + " (0 = active high, 1 = active low )");
  49752. +
  49753. +module_param(softcarrier, bool, S_IRUGO);
  49754. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  49755. +
  49756. +module_param(invert, bool, S_IRUGO);
  49757. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  49758. +
  49759. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  49760. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  49761. diff -Nur linux-3.12.38/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  49762. --- linux-3.12.38/drivers/staging/media/lirc/Makefile 2015-02-16 16:15:42.000000000 +0100
  49763. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2015-03-09 10:39:32.818893720 +0100
  49764. @@ -7,6 +7,7 @@
  49765. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  49766. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  49767. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  49768. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  49769. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  49770. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  49771. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  49772. diff -Nur linux-3.12.38/drivers/target/iscsi/iscsi_target_login.c linux-rpi/drivers/target/iscsi/iscsi_target_login.c
  49773. --- linux-3.12.38/drivers/target/iscsi/iscsi_target_login.c 2015-02-16 16:15:42.000000000 +0100
  49774. +++ linux-rpi/drivers/target/iscsi/iscsi_target_login.c 2015-03-10 17:26:51.246216688 +0100
  49775. @@ -1188,9 +1188,6 @@
  49776. conn->sock = NULL;
  49777. }
  49778. - if (conn->conn_transport->iscsit_wait_conn)
  49779. - conn->conn_transport->iscsit_wait_conn(conn);
  49780. -
  49781. if (conn->conn_transport->iscsit_free_conn)
  49782. conn->conn_transport->iscsit_free_conn(conn);
  49783. diff -Nur linux-3.12.38/drivers/target/iscsi/iscsi_target_util.c linux-rpi/drivers/target/iscsi/iscsi_target_util.c
  49784. --- linux-3.12.38/drivers/target/iscsi/iscsi_target_util.c 2015-02-16 16:15:42.000000000 +0100
  49785. +++ linux-rpi/drivers/target/iscsi/iscsi_target_util.c 2015-03-10 17:26:51.246216688 +0100
  49786. @@ -1355,15 +1355,15 @@
  49787. struct iscsi_conn *conn,
  49788. struct iscsi_data_count *count)
  49789. {
  49790. - int ret, iov_len;
  49791. + int data = count->data_length, total_tx = 0, tx_loop = 0, iov_len;
  49792. struct kvec *iov_p;
  49793. struct msghdr msg;
  49794. if (!conn || !conn->sock || !conn->conn_ops)
  49795. return -1;
  49796. - if (count->data_length <= 0) {
  49797. - pr_err("Data length is: %d\n", count->data_length);
  49798. + if (data <= 0) {
  49799. + pr_err("Data length is: %d\n", data);
  49800. return -1;
  49801. }
  49802. @@ -1372,16 +1372,20 @@
  49803. iov_p = count->iov;
  49804. iov_len = count->iov_count;
  49805. - ret = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len,
  49806. - count->data_length);
  49807. - if (ret != count->data_length) {
  49808. - pr_err("Unexpected ret: %d send data %d\n",
  49809. - ret, count->data_length);
  49810. - return -EPIPE;
  49811. + while (total_tx < data) {
  49812. + tx_loop = kernel_sendmsg(conn->sock, &msg, iov_p, iov_len,
  49813. + (data - total_tx));
  49814. + if (tx_loop <= 0) {
  49815. + pr_debug("tx_loop: %d total_tx %d\n",
  49816. + tx_loop, total_tx);
  49817. + return tx_loop;
  49818. + }
  49819. + total_tx += tx_loop;
  49820. + pr_debug("tx_loop: %d, total_tx: %d, data: %d\n",
  49821. + tx_loop, total_tx, data);
  49822. }
  49823. - pr_debug("ret: %d, sent data: %d\n", ret, count->data_length);
  49824. - return ret;
  49825. + return total_tx;
  49826. }
  49827. int rx_data(
  49828. diff -Nur linux-3.12.38/drivers/target/loopback/tcm_loop.c linux-rpi/drivers/target/loopback/tcm_loop.c
  49829. --- linux-3.12.38/drivers/target/loopback/tcm_loop.c 2015-02-16 16:15:42.000000000 +0100
  49830. +++ linux-rpi/drivers/target/loopback/tcm_loop.c 2015-03-10 17:26:51.246216688 +0100
  49831. @@ -179,7 +179,7 @@
  49832. goto out_done;
  49833. }
  49834. - tl_nexus = tl_tpg->tl_nexus;
  49835. + tl_nexus = tl_hba->tl_nexus;
  49836. if (!tl_nexus) {
  49837. scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus"
  49838. " does not exist\n");
  49839. @@ -258,20 +258,20 @@
  49840. */
  49841. tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
  49842. /*
  49843. - * Locate the tl_tpg and se_tpg pointers from TargetID in sc->device->id
  49844. - */
  49845. - tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  49846. - se_tpg = &tl_tpg->tl_se_tpg;
  49847. - /*
  49848. * Locate the tl_nexus and se_sess pointers
  49849. */
  49850. - tl_nexus = tl_tpg->tl_nexus;
  49851. + tl_nexus = tl_hba->tl_nexus;
  49852. if (!tl_nexus) {
  49853. pr_err("Unable to perform device reset without"
  49854. " active I_T Nexus\n");
  49855. return FAILED;
  49856. }
  49857. se_sess = tl_nexus->se_sess;
  49858. + /*
  49859. + * Locate the tl_tpg and se_tpg pointers from TargetID in sc->device->id
  49860. + */
  49861. + tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
  49862. + se_tpg = &tl_tpg->tl_se_tpg;
  49863. tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL);
  49864. if (!tl_cmd) {
  49865. @@ -878,8 +878,8 @@
  49866. struct tcm_loop_nexus *tl_nexus;
  49867. int ret = -ENOMEM;
  49868. - if (tl_tpg->tl_nexus) {
  49869. - pr_debug("tl_tpg->tl_nexus already exists\n");
  49870. + if (tl_tpg->tl_hba->tl_nexus) {
  49871. + pr_debug("tl_tpg->tl_hba->tl_nexus already exists\n");
  49872. return -EEXIST;
  49873. }
  49874. se_tpg = &tl_tpg->tl_se_tpg;
  49875. @@ -914,7 +914,7 @@
  49876. */
  49877. __transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
  49878. tl_nexus->se_sess, tl_nexus);
  49879. - tl_tpg->tl_nexus = tl_nexus;
  49880. + tl_tpg->tl_hba->tl_nexus = tl_nexus;
  49881. pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
  49882. " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
  49883. name);
  49884. @@ -930,8 +930,9 @@
  49885. {
  49886. struct se_session *se_sess;
  49887. struct tcm_loop_nexus *tl_nexus;
  49888. + struct tcm_loop_hba *tl_hba = tpg->tl_hba;
  49889. - tl_nexus = tpg->tl_nexus;
  49890. + tl_nexus = tpg->tl_hba->tl_nexus;
  49891. if (!tl_nexus)
  49892. return -ENODEV;
  49893. @@ -947,13 +948,13 @@
  49894. }
  49895. pr_debug("TCM_Loop_ConfigFS: Removing I_T Nexus to emulated"
  49896. - " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tpg->tl_hba),
  49897. + " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
  49898. tl_nexus->se_sess->se_node_acl->initiatorname);
  49899. /*
  49900. * Release the SCSI I_T Nexus to the emulated SAS Target Port
  49901. */
  49902. transport_deregister_session(tl_nexus->se_sess);
  49903. - tpg->tl_nexus = NULL;
  49904. + tpg->tl_hba->tl_nexus = NULL;
  49905. kfree(tl_nexus);
  49906. return 0;
  49907. }
  49908. @@ -969,7 +970,7 @@
  49909. struct tcm_loop_nexus *tl_nexus;
  49910. ssize_t ret;
  49911. - tl_nexus = tl_tpg->tl_nexus;
  49912. + tl_nexus = tl_tpg->tl_hba->tl_nexus;
  49913. if (!tl_nexus)
  49914. return -ENODEV;
  49915. diff -Nur linux-3.12.38/drivers/target/loopback/tcm_loop.h linux-rpi/drivers/target/loopback/tcm_loop.h
  49916. --- linux-3.12.38/drivers/target/loopback/tcm_loop.h 2015-02-16 16:15:42.000000000 +0100
  49917. +++ linux-rpi/drivers/target/loopback/tcm_loop.h 2015-03-10 17:26:51.250216688 +0100
  49918. @@ -25,6 +25,11 @@
  49919. };
  49920. struct tcm_loop_nexus {
  49921. + int it_nexus_active;
  49922. + /*
  49923. + * Pointer to Linux/SCSI HBA from linux/include/scsi_host.h
  49924. + */
  49925. + struct scsi_host *sh;
  49926. /*
  49927. * Pointer to TCM session for I_T Nexus
  49928. */
  49929. @@ -40,7 +45,6 @@
  49930. atomic_t tl_tpg_port_count;
  49931. struct se_portal_group tl_se_tpg;
  49932. struct tcm_loop_hba *tl_hba;
  49933. - struct tcm_loop_nexus *tl_nexus;
  49934. };
  49935. struct tcm_loop_hba {
  49936. @@ -49,6 +53,7 @@
  49937. struct se_hba_s *se_hba;
  49938. struct se_lun *tl_hba_lun;
  49939. struct se_port *tl_hba_lun_sep;
  49940. + struct tcm_loop_nexus *tl_nexus;
  49941. struct device dev;
  49942. struct Scsi_Host *sh;
  49943. struct tcm_loop_tpg tl_hba_tpgs[TL_TPGS_PER_HBA];
  49944. diff -Nur linux-3.12.38/drivers/target/target_core_device.c linux-rpi/drivers/target/target_core_device.c
  49945. --- linux-3.12.38/drivers/target/target_core_device.c 2015-02-16 16:15:42.000000000 +0100
  49946. +++ linux-rpi/drivers/target/target_core_device.c 2015-03-10 17:26:51.250216688 +0100
  49947. @@ -1066,10 +1066,10 @@
  49948. " changed for TCM/pSCSI\n", dev);
  49949. return -EINVAL;
  49950. }
  49951. - if (optimal_sectors > dev->dev_attrib.hw_max_sectors) {
  49952. + if (optimal_sectors > dev->dev_attrib.fabric_max_sectors) {
  49953. pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
  49954. - " greater than hw_max_sectors: %u\n", dev,
  49955. - optimal_sectors, dev->dev_attrib.hw_max_sectors);
  49956. + " greater than fabric_max_sectors: %u\n", dev,
  49957. + optimal_sectors, dev->dev_attrib.fabric_max_sectors);
  49958. return -EINVAL;
  49959. }
  49960. @@ -1474,6 +1474,7 @@
  49961. DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT;
  49962. dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN;
  49963. dev->dev_attrib.fabric_max_sectors = DA_FABRIC_MAX_SECTORS;
  49964. + dev->dev_attrib.optimal_sectors = DA_FABRIC_MAX_SECTORS;
  49965. return dev;
  49966. }
  49967. @@ -1506,7 +1507,6 @@
  49968. dev->dev_attrib.hw_max_sectors =
  49969. se_dev_align_max_sectors(dev->dev_attrib.hw_max_sectors,
  49970. dev->dev_attrib.hw_block_size);
  49971. - dev->dev_attrib.optimal_sectors = dev->dev_attrib.hw_max_sectors;
  49972. dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX);
  49973. dev->creation_time = get_jiffies_64();
  49974. diff -Nur linux-3.12.38/drivers/target/target_core_file.c linux-rpi/drivers/target/target_core_file.c
  49975. --- linux-3.12.38/drivers/target/target_core_file.c 2015-02-16 16:15:42.000000000 +0100
  49976. +++ linux-rpi/drivers/target/target_core_file.c 2015-03-10 17:26:51.250216688 +0100
  49977. @@ -552,16 +552,7 @@
  49978. {
  49979. struct se_device *dev = cmd->se_dev;
  49980. int ret = 0;
  49981. - /*
  49982. - * We are currently limited by the number of iovecs (2048) per
  49983. - * single vfs_[writev,readv] call.
  49984. - */
  49985. - if (cmd->data_length > FD_MAX_BYTES) {
  49986. - pr_err("FILEIO: Not able to process I/O of %u bytes due to"
  49987. - "FD_MAX_BYTES: %u iovec count limitiation\n",
  49988. - cmd->data_length, FD_MAX_BYTES);
  49989. - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  49990. - }
  49991. +
  49992. /*
  49993. * Call vectorized fileio functions to map struct scatterlist
  49994. * physical memory addresses to struct iovec virtual memory.
  49995. diff -Nur linux-3.12.38/drivers/target/target_core_iblock.c linux-rpi/drivers/target/target_core_iblock.c
  49996. --- linux-3.12.38/drivers/target/target_core_iblock.c 2015-02-16 16:15:42.000000000 +0100
  49997. +++ linux-rpi/drivers/target/target_core_iblock.c 2015-03-10 17:26:51.250216688 +0100
  49998. @@ -122,7 +122,7 @@
  49999. q = bdev_get_queue(bd);
  50000. dev->dev_attrib.hw_block_size = bdev_logical_block_size(bd);
  50001. - dev->dev_attrib.hw_max_sectors = queue_max_hw_sectors(q);
  50002. + dev->dev_attrib.hw_max_sectors = UINT_MAX;
  50003. dev->dev_attrib.hw_queue_depth = q->nr_requests;
  50004. /*
  50005. diff -Nur linux-3.12.38/drivers/target/target_core_sbc.c linux-rpi/drivers/target/target_core_sbc.c
  50006. --- linux-3.12.38/drivers/target/target_core_sbc.c 2015-02-16 16:15:42.000000000 +0100
  50007. +++ linux-rpi/drivers/target/target_core_sbc.c 2015-03-10 17:26:51.250216688 +0100
  50008. @@ -829,6 +829,21 @@
  50009. if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
  50010. unsigned long long end_lba;
  50011. + if (sectors > dev->dev_attrib.fabric_max_sectors) {
  50012. + printk_ratelimited(KERN_ERR "SCSI OP %02xh with too"
  50013. + " big sectors %u exceeds fabric_max_sectors:"
  50014. + " %u\n", cdb[0], sectors,
  50015. + dev->dev_attrib.fabric_max_sectors);
  50016. + return TCM_INVALID_CDB_FIELD;
  50017. + }
  50018. + if (sectors > dev->dev_attrib.hw_max_sectors) {
  50019. + printk_ratelimited(KERN_ERR "SCSI OP %02xh with too"
  50020. + " big sectors %u exceeds backend hw_max_sectors:"
  50021. + " %u\n", cdb[0], sectors,
  50022. + dev->dev_attrib.hw_max_sectors);
  50023. + return TCM_INVALID_CDB_FIELD;
  50024. + }
  50025. +
  50026. end_lba = dev->transport->get_blocks(dev) + 1;
  50027. if (cmd->t_task_lba + sectors > end_lba) {
  50028. pr_err("cmd exceeds last lba %llu "
  50029. diff -Nur linux-3.12.38/drivers/target/target_core_spc.c linux-rpi/drivers/target/target_core_spc.c
  50030. --- linux-3.12.38/drivers/target/target_core_spc.c 2015-02-16 16:15:42.000000000 +0100
  50031. +++ linux-rpi/drivers/target/target_core_spc.c 2015-03-10 17:26:51.250216688 +0100
  50032. @@ -450,6 +450,7 @@
  50033. spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
  50034. {
  50035. struct se_device *dev = cmd->se_dev;
  50036. + u32 max_sectors;
  50037. int have_tp = 0;
  50038. /*
  50039. @@ -479,7 +480,9 @@
  50040. /*
  50041. * Set MAXIMUM TRANSFER LENGTH
  50042. */
  50043. - put_unaligned_be32(dev->dev_attrib.hw_max_sectors, &buf[8]);
  50044. + max_sectors = min(dev->dev_attrib.fabric_max_sectors,
  50045. + dev->dev_attrib.hw_max_sectors);
  50046. + put_unaligned_be32(max_sectors, &buf[8]);
  50047. /*
  50048. * Set OPTIMAL TRANSFER LENGTH
  50049. diff -Nur linux-3.12.38/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  50050. --- linux-3.12.38/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  50051. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2015-03-09 10:39:33.042893719 +0100
  50052. @@ -0,0 +1,184 @@
  50053. +/*****************************************************************************
  50054. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  50055. +*
  50056. +* Unless you and Broadcom execute a separate written software license
  50057. +* agreement governing use of this software, this software is licensed to you
  50058. +* under the terms of the GNU General Public License version 2, available at
  50059. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  50060. +*
  50061. +* Notwithstanding the above, under no circumstances may you combine this
  50062. +* software in any way with any other Broadcom software provided under a
  50063. +* license other than the GPL, without Broadcom's express prior written
  50064. +* consent.
  50065. +*****************************************************************************/
  50066. +
  50067. +#include <linux/kernel.h>
  50068. +#include <linux/module.h>
  50069. +#include <linux/init.h>
  50070. +#include <linux/platform_device.h>
  50071. +#include <linux/slab.h>
  50072. +#include <linux/sysfs.h>
  50073. +#include <mach/vcio.h>
  50074. +#include <linux/thermal.h>
  50075. +
  50076. +
  50077. +/* --- DEFINITIONS --- */
  50078. +#define MODULE_NAME "bcm2835_thermal"
  50079. +
  50080. +/*#define THERMAL_DEBUG_ENABLE*/
  50081. +
  50082. +#ifdef THERMAL_DEBUG_ENABLE
  50083. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  50084. +#else
  50085. +#define print_debug(fmt,...)
  50086. +#endif
  50087. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  50088. +
  50089. +#define VC_TAG_GET_TEMP 0x00030006
  50090. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  50091. +
  50092. +typedef enum {
  50093. + TEMP,
  50094. + MAX_TEMP,
  50095. +} temp_type;
  50096. +
  50097. +/* --- STRUCTS --- */
  50098. +/* tag part of the message */
  50099. +struct vc_msg_tag {
  50100. + uint32_t tag_id; /* the tag ID for the temperature */
  50101. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  50102. + uint32_t request_code; /* identifies message as a request (should be 0) */
  50103. + uint32_t id; /* extra ID field (should be 0) */
  50104. + uint32_t val; /* returned value of the temperature */
  50105. +};
  50106. +
  50107. +/* message structure to be sent to videocore */
  50108. +struct vc_msg {
  50109. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  50110. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  50111. + struct vc_msg_tag tag; /* the tag structure above to make */
  50112. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  50113. +};
  50114. +
  50115. +struct bcm2835_thermal_data {
  50116. + struct thermal_zone_device *thermal_dev;
  50117. + struct vc_msg msg;
  50118. +};
  50119. +
  50120. +/* --- GLOBALS --- */
  50121. +static struct bcm2835_thermal_data bcm2835_data;
  50122. +
  50123. +/* Thermal Device Operations */
  50124. +static struct thermal_zone_device_ops ops;
  50125. +
  50126. +/* --- FUNCTIONS --- */
  50127. +
  50128. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  50129. +{
  50130. + int result = -1, retry = 3;
  50131. + print_debug("IN");
  50132. +
  50133. + *temp = 0;
  50134. + while (result != 0 && retry-- > 0) {
  50135. + /* wipe all previous message data */
  50136. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  50137. +
  50138. + /* prepare message */
  50139. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  50140. + bcm2835_data.msg.tag.buffer_size = 8;
  50141. + bcm2835_data.msg.tag.tag_id = tag_id;
  50142. +
  50143. + /* send the message */
  50144. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  50145. + 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);
  50146. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  50147. + result = -1;
  50148. + }
  50149. +
  50150. + /* check if it was all ok and return the rate in milli degrees C */
  50151. + if (result == 0)
  50152. + *temp = (uint)bcm2835_data.msg.tag.val;
  50153. + else
  50154. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  50155. + print_debug("OUT");
  50156. + return result;
  50157. +}
  50158. +
  50159. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  50160. +{
  50161. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  50162. +}
  50163. +
  50164. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  50165. +{
  50166. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  50167. +}
  50168. +
  50169. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  50170. +{
  50171. + *trip_type = THERMAL_TRIP_HOT;
  50172. + return 0;
  50173. +}
  50174. +
  50175. +
  50176. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  50177. +{
  50178. + *dev_mode = THERMAL_DEVICE_ENABLED;
  50179. + return 0;
  50180. +}
  50181. +
  50182. +
  50183. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  50184. +{
  50185. + print_debug("IN");
  50186. + print_debug("THERMAL Driver has been probed!");
  50187. +
  50188. + /* check that the device isn't null!*/
  50189. + if(pdev == NULL)
  50190. + {
  50191. + print_debug("Platform device is empty!");
  50192. + return -ENODEV;
  50193. + }
  50194. +
  50195. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  50196. + {
  50197. + print_debug("Unable to register the thermal device!");
  50198. + return -EFAULT;
  50199. + }
  50200. + return 0;
  50201. +}
  50202. +
  50203. +
  50204. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  50205. +{
  50206. + print_debug("IN");
  50207. +
  50208. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  50209. +
  50210. + print_debug("OUT");
  50211. +
  50212. + return 0;
  50213. +}
  50214. +
  50215. +static struct thermal_zone_device_ops ops = {
  50216. + .get_temp = bcm2835_get_temp,
  50217. + .get_trip_temp = bcm2835_get_max_temp,
  50218. + .get_trip_type = bcm2835_get_trip_type,
  50219. + .get_mode = bcm2835_get_mode,
  50220. +};
  50221. +
  50222. +/* Thermal Driver */
  50223. +static struct platform_driver bcm2835_thermal_driver = {
  50224. + .probe = bcm2835_thermal_probe,
  50225. + .remove = bcm2835_thermal_remove,
  50226. + .driver = {
  50227. + .name = "bcm2835_thermal",
  50228. + .owner = THIS_MODULE,
  50229. + },
  50230. +};
  50231. +
  50232. +MODULE_LICENSE("GPL");
  50233. +MODULE_AUTHOR("Dorian Peake");
  50234. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  50235. +
  50236. +module_platform_driver(bcm2835_thermal_driver);
  50237. diff -Nur linux-3.12.38/drivers/thermal/intel_powerclamp.c linux-rpi/drivers/thermal/intel_powerclamp.c
  50238. --- linux-3.12.38/drivers/thermal/intel_powerclamp.c 2015-02-16 16:15:42.000000000 +0100
  50239. +++ linux-rpi/drivers/thermal/intel_powerclamp.c 2015-03-10 17:26:51.254216688 +0100
  50240. @@ -426,6 +426,7 @@
  50241. * allowed. thus jiffies are updated properly.
  50242. */
  50243. preempt_disable();
  50244. + tick_nohz_idle_enter();
  50245. /* mwait until target jiffies is reached */
  50246. while (time_before(jiffies, target_jiffies)) {
  50247. unsigned long ecx = 1;
  50248. @@ -443,6 +444,7 @@
  50249. start_critical_timings();
  50250. atomic_inc(&idle_wakeup_counter);
  50251. }
  50252. + tick_nohz_idle_exit();
  50253. preempt_enable_no_resched();
  50254. }
  50255. del_timer_sync(&wakeup_timer);
  50256. diff -Nur linux-3.12.38/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  50257. --- linux-3.12.38/drivers/thermal/Kconfig 2015-02-16 16:15:42.000000000 +0100
  50258. +++ linux-rpi/drivers/thermal/Kconfig 2015-03-10 17:26:51.254216688 +0100
  50259. @@ -181,6 +181,12 @@
  50260. enforce idle time which results in more package C-state residency. The
  50261. user interface is exposed via generic thermal framework.
  50262. +config THERMAL_BCM2835
  50263. + tristate "BCM2835 Thermal Driver"
  50264. + help
  50265. + This will enable temperature monitoring for the Broadcom BCM2835
  50266. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  50267. +
  50268. config X86_PKG_TEMP_THERMAL
  50269. tristate "X86 package temperature thermal driver"
  50270. depends on X86_THERMAL_VECTOR
  50271. diff -Nur linux-3.12.38/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  50272. --- linux-3.12.38/drivers/thermal/Makefile 2015-02-16 16:15:42.000000000 +0100
  50273. +++ linux-rpi/drivers/thermal/Makefile 2015-03-10 17:26:51.254216688 +0100
  50274. @@ -27,5 +27,6 @@
  50275. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  50276. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  50277. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  50278. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  50279. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  50280. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  50281. diff -Nur linux-3.12.38/drivers/tty/n_tty.c linux-rpi/drivers/tty/n_tty.c
  50282. --- linux-3.12.38/drivers/tty/n_tty.c 2015-02-16 16:15:42.000000000 +0100
  50283. +++ linux-rpi/drivers/tty/n_tty.c 2015-03-10 17:26:51.258216688 +0100
  50284. @@ -319,8 +319,7 @@
  50285. static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
  50286. {
  50287. - *read_buf_addr(ldata, ldata->read_head) = c;
  50288. - ldata->read_head++;
  50289. + *read_buf_addr(ldata, ldata->read_head++) = c;
  50290. }
  50291. /**
  50292. diff -Nur linux-3.12.38/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  50293. --- linux-3.12.38/drivers/tty/serial/amba-pl011.c 2015-02-16 16:15:42.000000000 +0100
  50294. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2015-03-10 17:26:51.262216688 +0100
  50295. @@ -84,7 +84,7 @@
  50296. static unsigned int get_fifosize_arm(struct amba_device *dev)
  50297. {
  50298. - return amba_rev(dev) < 3 ? 16 : 32;
  50299. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  50300. }
  50301. static struct vendor_data vendor_arm = {
  50302. diff -Nur linux-3.12.38/drivers/tty/serial/samsung.c linux-rpi/drivers/tty/serial/samsung.c
  50303. --- linux-3.12.38/drivers/tty/serial/samsung.c 2015-02-16 16:15:42.000000000 +0100
  50304. +++ linux-rpi/drivers/tty/serial/samsung.c 2015-03-10 17:26:51.270216688 +0100
  50305. @@ -537,15 +537,11 @@
  50306. unsigned int old)
  50307. {
  50308. struct s3c24xx_uart_port *ourport = to_ourport(port);
  50309. - int timeout = 10000;
  50310. ourport->pm_level = level;
  50311. switch (level) {
  50312. case 3:
  50313. - while (--timeout && !s3c24xx_serial_txempty_nofifo(port))
  50314. - udelay(100);
  50315. -
  50316. if (!IS_ERR(ourport->baudclk))
  50317. clk_disable_unprepare(ourport->baudclk);
  50318. diff -Nur linux-3.12.38/drivers/usb/class/cdc-acm.c linux-rpi/drivers/usb/class/cdc-acm.c
  50319. --- linux-3.12.38/drivers/usb/class/cdc-acm.c 2015-02-16 16:15:42.000000000 +0100
  50320. +++ linux-rpi/drivers/usb/class/cdc-acm.c 2015-03-10 17:26:51.282216688 +0100
  50321. @@ -1079,11 +1079,10 @@
  50322. } else {
  50323. control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
  50324. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
  50325. - }
  50326. -
  50327. - if (!control_interface || !data_interface) {
  50328. - dev_dbg(&intf->dev, "no interfaces\n");
  50329. - return -ENODEV;
  50330. + if (!control_interface || !data_interface) {
  50331. + dev_dbg(&intf->dev, "no interfaces\n");
  50332. + return -ENODEV;
  50333. + }
  50334. }
  50335. if (data_interface_num != call_interface_num)
  50336. @@ -1358,7 +1357,6 @@
  50337. &dev_attr_wCountryCodes);
  50338. device_remove_file(&acm->control->dev,
  50339. &dev_attr_iCountryCodeRelDate);
  50340. - kfree(acm->country_codes);
  50341. }
  50342. device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
  50343. alloc_fail7:
  50344. diff -Nur linux-3.12.38/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  50345. --- linux-3.12.38/drivers/usb/core/generic.c 2015-02-16 16:15:42.000000000 +0100
  50346. +++ linux-rpi/drivers/usb/core/generic.c 2015-03-10 17:26:51.282216688 +0100
  50347. @@ -152,6 +152,7 @@
  50348. dev_warn(&udev->dev,
  50349. "no configuration chosen from %d choice%s\n",
  50350. num_configs, plural(num_configs));
  50351. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  50352. }
  50353. return i;
  50354. }
  50355. diff -Nur linux-3.12.38/drivers/usb/core/hub.c linux-rpi/drivers/usb/core/hub.c
  50356. --- linux-3.12.38/drivers/usb/core/hub.c 2015-02-16 16:15:42.000000000 +0100
  50357. +++ linux-rpi/drivers/usb/core/hub.c 2015-03-10 17:26:51.282216688 +0100
  50358. @@ -4845,7 +4845,7 @@
  50359. u16 status = 0;
  50360. u16 unused;
  50361. - dev_dbg(hub_dev, "over-current change on port "
  50362. + dev_notice(hub_dev, "over-current change on port "
  50363. "%d\n", i);
  50364. usb_clear_port_feature(hdev, i,
  50365. USB_PORT_FEAT_C_OVER_CURRENT);
  50366. diff -Nur linux-3.12.38/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  50367. --- linux-3.12.38/drivers/usb/core/message.c 2015-02-16 16:15:42.000000000 +0100
  50368. +++ linux-rpi/drivers/usb/core/message.c 2015-03-10 17:26:51.282216688 +0100
  50369. @@ -1885,6 +1885,85 @@
  50370. if (cp->string == NULL &&
  50371. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  50372. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  50373. +/* Uncomment this define to enable the HS Electrical Test support */
  50374. +#define DWC_HS_ELECT_TST 1
  50375. +#ifdef DWC_HS_ELECT_TST
  50376. + /* Here we implement the HS Electrical Test support. The
  50377. + * tester uses a vendor ID of 0x1A0A to indicate we should
  50378. + * run a special test sequence. The product ID tells us
  50379. + * which sequence to run. We invoke the test sequence by
  50380. + * sending a non-standard SetFeature command to our root
  50381. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  50382. + * recognize the command and perform the desired test
  50383. + * sequence.
  50384. + */
  50385. + if (dev->descriptor.idVendor == 0x1A0A) {
  50386. + /* HSOTG Electrical Test */
  50387. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  50388. +
  50389. + if (dev->bus && dev->bus->root_hub) {
  50390. + struct usb_device *hdev = dev->bus->root_hub;
  50391. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  50392. +
  50393. + switch (dev->descriptor.idProduct) {
  50394. + case 0x0101: /* TEST_SE0_NAK */
  50395. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  50396. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50397. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50398. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  50399. + break;
  50400. +
  50401. + case 0x0102: /* TEST_J */
  50402. + dev_warn(&dev->dev, "TEST_J\n");
  50403. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50404. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50405. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  50406. + break;
  50407. +
  50408. + case 0x0103: /* TEST_K */
  50409. + dev_warn(&dev->dev, "TEST_K\n");
  50410. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50411. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50412. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  50413. + break;
  50414. +
  50415. + case 0x0104: /* TEST_PACKET */
  50416. + dev_warn(&dev->dev, "TEST_PACKET\n");
  50417. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50418. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50419. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  50420. + break;
  50421. +
  50422. + case 0x0105: /* TEST_FORCE_ENABLE */
  50423. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  50424. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50425. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50426. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  50427. + break;
  50428. +
  50429. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  50430. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  50431. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50432. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50433. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  50434. + break;
  50435. +
  50436. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  50437. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  50438. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50439. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50440. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  50441. + break;
  50442. +
  50443. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  50444. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  50445. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  50446. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  50447. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  50448. + }
  50449. + }
  50450. + }
  50451. +#endif /* DWC_HS_ELECT_TST */
  50452. /* Now that the interfaces are installed, re-enable LPM. */
  50453. usb_unlocked_enable_lpm(dev);
  50454. diff -Nur linux-3.12.38/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  50455. --- linux-3.12.38/drivers/usb/core/otg_whitelist.h 2015-02-16 16:15:42.000000000 +0100
  50456. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2015-03-10 17:26:51.282216688 +0100
  50457. @@ -19,33 +19,82 @@
  50458. static struct usb_device_id whitelist_table [] = {
  50459. /* hubs are optional in OTG, but very handy ... */
  50460. +#define CERT_WITHOUT_HUBS
  50461. +#if defined(CERT_WITHOUT_HUBS)
  50462. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  50463. +#else
  50464. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  50465. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  50466. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  50467. +#endif
  50468. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  50469. /* FIXME actually, printers are NOT supposed to use device classes;
  50470. * they're supposed to use interface classes...
  50471. */
  50472. -{ USB_DEVICE_INFO(7, 1, 1) },
  50473. -{ USB_DEVICE_INFO(7, 1, 2) },
  50474. -{ USB_DEVICE_INFO(7, 1, 3) },
  50475. +//{ USB_DEVICE_INFO(7, 1, 1) },
  50476. +//{ USB_DEVICE_INFO(7, 1, 2) },
  50477. +//{ USB_DEVICE_INFO(7, 1, 3) },
  50478. #endif
  50479. #ifdef CONFIG_USB_NET_CDCETHER
  50480. /* Linux-USB CDC Ethernet gadget */
  50481. -{ USB_DEVICE(0x0525, 0xa4a1), },
  50482. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  50483. /* Linux-USB CDC Ethernet + RNDIS gadget */
  50484. -{ USB_DEVICE(0x0525, 0xa4a2), },
  50485. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  50486. #endif
  50487. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  50488. /* gadget zero, for testing */
  50489. -{ USB_DEVICE(0x0525, 0xa4a0), },
  50490. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  50491. #endif
  50492. +/* OPT Tester */
  50493. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  50494. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  50495. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  50496. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  50497. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  50498. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  50499. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  50500. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  50501. +
  50502. +/* Sony cameras */
  50503. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  50504. +
  50505. +/* Memory Devices */
  50506. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  50507. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  50508. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  50509. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  50510. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  50511. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  50512. +
  50513. +/* HP Printers */
  50514. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  50515. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  50516. +
  50517. +/* Speakers */
  50518. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  50519. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  50520. +
  50521. { } /* Terminating entry */
  50522. };
  50523. +static inline void report_errors(struct usb_device *dev)
  50524. +{
  50525. + /* OTG MESSAGE: report errors here, customize to match your product */
  50526. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  50527. + le16_to_cpu(dev->descriptor.idVendor),
  50528. + le16_to_cpu(dev->descriptor.idProduct));
  50529. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  50530. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  50531. + } else {
  50532. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  50533. + }
  50534. +}
  50535. +
  50536. +
  50537. static int is_targeted(struct usb_device *dev)
  50538. {
  50539. struct usb_device_id *id = whitelist_table;
  50540. @@ -55,58 +104,83 @@
  50541. return 1;
  50542. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  50543. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  50544. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  50545. - return 0;
  50546. + if (dev->descriptor.idVendor == 0x1a0a &&
  50547. + dev->descriptor.idProduct == 0xbadd) {
  50548. + return 0;
  50549. + } else if (!enable_whitelist) {
  50550. + return 1;
  50551. + } else {
  50552. - /* NOTE: can't use usb_match_id() since interface caches
  50553. - * aren't set up yet. this is cut/paste from that code.
  50554. - */
  50555. - for (id = whitelist_table; id->match_flags; id++) {
  50556. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  50557. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  50558. - continue;
  50559. -
  50560. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  50561. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  50562. - continue;
  50563. -
  50564. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  50565. - greater than any unsigned number. */
  50566. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  50567. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  50568. - continue;
  50569. -
  50570. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  50571. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  50572. - continue;
  50573. -
  50574. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  50575. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  50576. - continue;
  50577. -
  50578. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  50579. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  50580. - continue;
  50581. -
  50582. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  50583. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  50584. - continue;
  50585. +#ifdef DEBUG
  50586. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  50587. + dev->descriptor.idVendor,
  50588. + dev->descriptor.idProduct,
  50589. + dev->descriptor.bDeviceClass,
  50590. + dev->descriptor.bDeviceSubClass,
  50591. + dev->descriptor.bDeviceProtocol);
  50592. +#endif
  50593. return 1;
  50594. + /* NOTE: can't use usb_match_id() since interface caches
  50595. + * aren't set up yet. this is cut/paste from that code.
  50596. + */
  50597. + for (id = whitelist_table; id->match_flags; id++) {
  50598. +#ifdef DEBUG
  50599. + dev_dbg(&dev->dev,
  50600. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  50601. + id->idVendor,
  50602. + id->idProduct,
  50603. + id->bDeviceClass,
  50604. + id->bDeviceSubClass,
  50605. + id->bDeviceProtocol);
  50606. +#endif
  50607. +
  50608. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  50609. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  50610. + continue;
  50611. +
  50612. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  50613. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  50614. + continue;
  50615. +
  50616. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  50617. + greater than any unsigned number. */
  50618. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  50619. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  50620. + continue;
  50621. +
  50622. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  50623. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  50624. + continue;
  50625. +
  50626. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  50627. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  50628. + continue;
  50629. +
  50630. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  50631. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  50632. + continue;
  50633. +
  50634. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  50635. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  50636. + continue;
  50637. +
  50638. + return 1;
  50639. + }
  50640. }
  50641. /* add other match criteria here ... */
  50642. -
  50643. - /* OTG MESSAGE: report errors here, customize to match your product */
  50644. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  50645. - le16_to_cpu(dev->descriptor.idVendor),
  50646. - le16_to_cpu(dev->descriptor.idProduct));
  50647. #ifdef CONFIG_USB_OTG_WHITELIST
  50648. + report_errors(dev);
  50649. return 0;
  50650. #else
  50651. - return 1;
  50652. + if (enable_whitelist) {
  50653. + report_errors(dev);
  50654. + return 0;
  50655. + } else {
  50656. + return 1;
  50657. + }
  50658. #endif
  50659. }
  50660. diff -Nur linux-3.12.38/drivers/usb/dwc3/gadget.c linux-rpi/drivers/usb/dwc3/gadget.c
  50661. --- linux-3.12.38/drivers/usb/dwc3/gadget.c 2015-02-16 16:15:42.000000000 +0100
  50662. +++ linux-rpi/drivers/usb/dwc3/gadget.c 2015-03-10 17:26:51.286216687 +0100
  50663. @@ -887,7 +887,8 @@
  50664. if (i == (request->num_mapped_sgs - 1) ||
  50665. sg_is_last(s)) {
  50666. - if (list_empty(&dep->request_list))
  50667. + if (list_is_last(&req->list,
  50668. + &dep->request_list))
  50669. last_one = true;
  50670. chain = false;
  50671. }
  50672. @@ -905,9 +906,6 @@
  50673. if (last_one)
  50674. break;
  50675. }
  50676. -
  50677. - if (last_one)
  50678. - break;
  50679. } else {
  50680. dma = req->request.dma;
  50681. length = req->request.length;
  50682. diff -Nur linux-3.12.38/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  50683. --- linux-3.12.38/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  50684. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2015-03-09 10:39:33.198893718 +0100
  50685. @@ -0,0 +1,3676 @@
  50686. +/*
  50687. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  50688. + *
  50689. + * Copyright (C) 2003-2008 Alan Stern
  50690. + * All rights reserved.
  50691. + *
  50692. + * Redistribution and use in source and binary forms, with or without
  50693. + * modification, are permitted provided that the following conditions
  50694. + * are met:
  50695. + * 1. Redistributions of source code must retain the above copyright
  50696. + * notice, this list of conditions, and the following disclaimer,
  50697. + * without modification.
  50698. + * 2. Redistributions in binary form must reproduce the above copyright
  50699. + * notice, this list of conditions and the following disclaimer in the
  50700. + * documentation and/or other materials provided with the distribution.
  50701. + * 3. The names of the above-listed copyright holders may not be used
  50702. + * to endorse or promote products derived from this software without
  50703. + * specific prior written permission.
  50704. + *
  50705. + * ALTERNATIVELY, this software may be distributed under the terms of the
  50706. + * GNU General Public License ("GPL") as published by the Free Software
  50707. + * Foundation, either version 2 of that License or (at your option) any
  50708. + * later version.
  50709. + *
  50710. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  50711. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  50712. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50713. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  50714. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  50715. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  50716. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  50717. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  50718. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  50719. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  50720. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50721. + */
  50722. +
  50723. +
  50724. +/*
  50725. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  50726. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  50727. + * to providing an example of a genuinely useful gadget driver for a USB
  50728. + * device, it also illustrates a technique of double-buffering for increased
  50729. + * throughput. Last but not least, it gives an easy way to probe the
  50730. + * behavior of the Mass Storage drivers in a USB host.
  50731. + *
  50732. + * Backing storage is provided by a regular file or a block device, specified
  50733. + * by the "file" module parameter. Access can be limited to read-only by
  50734. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  50735. + * access is always read-only.) The gadget will indicate that it has
  50736. + * removable media if the optional "removable" module parameter is set.
  50737. + *
  50738. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  50739. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  50740. + * by the optional "transport" module parameter. It also supports the
  50741. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  50742. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  50743. + * the optional "protocol" module parameter. In addition, the default
  50744. + * Vendor ID, Product ID, release number and serial number can be overridden.
  50745. + *
  50746. + * There is support for multiple logical units (LUNs), each of which has
  50747. + * its own backing file. The number of LUNs can be set using the optional
  50748. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  50749. + * files are specified using comma-separated lists for "file" and "ro".
  50750. + * The default number of LUNs is taken from the number of "file" elements;
  50751. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  50752. + * file must be specified for each LUN. If it is set, then an unspecified
  50753. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  50754. + * each LUN would be settable independently as a disk drive or a CD-ROM
  50755. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  50756. + * emulation includes a single data track and no audio tracks; hence there
  50757. + * need be only one backing file per LUN.
  50758. + *
  50759. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  50760. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  50761. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  50762. + * Support is included for both full-speed and high-speed operation.
  50763. + *
  50764. + * Note that the driver is slightly non-portable in that it assumes a
  50765. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  50766. + * interrupt-in endpoints. With most device controllers this isn't an
  50767. + * issue, but there may be some with hardware restrictions that prevent
  50768. + * a buffer from being used by more than one endpoint.
  50769. + *
  50770. + * Module options:
  50771. + *
  50772. + * file=filename[,filename...]
  50773. + * Required if "removable" is not set, names of
  50774. + * the files or block devices used for
  50775. + * backing storage
  50776. + * serial=HHHH... Required serial number (string of hex chars)
  50777. + * ro=b[,b...] Default false, booleans for read-only access
  50778. + * removable Default false, boolean for removable media
  50779. + * luns=N Default N = number of filenames, number of
  50780. + * LUNs to support
  50781. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  50782. + * in SCSI WRITE(10,12) commands
  50783. + * stall Default determined according to the type of
  50784. + * USB device controller (usually true),
  50785. + * boolean to permit the driver to halt
  50786. + * bulk endpoints
  50787. + * cdrom Default false, boolean for whether to emulate
  50788. + * a CD-ROM drive
  50789. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  50790. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  50791. + * ATAPI, QIC, UFI, 8070, or SCSI;
  50792. + * also 1 - 6)
  50793. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  50794. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  50795. + * release=0xRRRR Override the USB release number (bcdDevice)
  50796. + * buflen=N Default N=16384, buffer size used (will be
  50797. + * rounded down to a multiple of
  50798. + * PAGE_CACHE_SIZE)
  50799. + *
  50800. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  50801. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  50802. + * default values are used for everything else.
  50803. + *
  50804. + * The pathnames of the backing files and the ro settings are available in
  50805. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  50806. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  50807. + * these files will simulate ejecting/loading the medium (writing an empty
  50808. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  50809. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  50810. + * is being used.
  50811. + *
  50812. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  50813. + * The driver's SCSI command interface was based on the "Information
  50814. + * technology - Small Computer System Interface - 2" document from
  50815. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  50816. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  50817. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  50818. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  50819. + * document, Revision 1.0, December 14, 1998, available at
  50820. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  50821. + */
  50822. +
  50823. +
  50824. +/*
  50825. + * Driver Design
  50826. + *
  50827. + * The FSG driver is fairly straightforward. There is a main kernel
  50828. + * thread that handles most of the work. Interrupt routines field
  50829. + * callbacks from the controller driver: bulk- and interrupt-request
  50830. + * completion notifications, endpoint-0 events, and disconnect events.
  50831. + * Completion events are passed to the main thread by wakeup calls. Many
  50832. + * ep0 requests are handled at interrupt time, but SetInterface,
  50833. + * SetConfiguration, and device reset requests are forwarded to the
  50834. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  50835. + * should interrupt any ongoing file I/O operations).
  50836. + *
  50837. + * The thread's main routine implements the standard command/data/status
  50838. + * parts of a SCSI interaction. It and its subroutines are full of tests
  50839. + * for pending signals/exceptions -- all this polling is necessary since
  50840. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  50841. + * indication that the driver really wants to be running in userspace.)
  50842. + * An important point is that so long as the thread is alive it keeps an
  50843. + * open reference to the backing file. This will prevent unmounting
  50844. + * the backing file's underlying filesystem and could cause problems
  50845. + * during system shutdown, for example. To prevent such problems, the
  50846. + * thread catches INT, TERM, and KILL signals and converts them into
  50847. + * an EXIT exception.
  50848. + *
  50849. + * In normal operation the main thread is started during the gadget's
  50850. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  50851. + * exit when it receives a signal, and there's no point leaving the
  50852. + * gadget running when the thread is dead. So just before the thread
  50853. + * exits, it deregisters the gadget driver. This makes things a little
  50854. + * tricky: The driver is deregistered at two places, and the exiting
  50855. + * thread can indirectly call fsg_unbind() which in turn can tell the
  50856. + * thread to exit. The first problem is resolved through the use of the
  50857. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  50858. + * The second problem is resolved by having fsg_unbind() check
  50859. + * fsg->state; it won't try to stop the thread if the state is already
  50860. + * FSG_STATE_TERMINATED.
  50861. + *
  50862. + * To provide maximum throughput, the driver uses a circular pipeline of
  50863. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  50864. + * arbitrarily long; in practice the benefits don't justify having more
  50865. + * than 2 stages (i.e., double buffering). But it helps to think of the
  50866. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  50867. + * a bulk-out request pointer (since the buffer can be used for both
  50868. + * output and input -- directions always are given from the host's
  50869. + * point of view) as well as a pointer to the buffer and various state
  50870. + * variables.
  50871. + *
  50872. + * Use of the pipeline follows a simple protocol. There is a variable
  50873. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  50874. + * At any time that buffer head may still be in use from an earlier
  50875. + * request, so each buffer head has a state variable indicating whether
  50876. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  50877. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  50878. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  50879. + * head FULL when the I/O is complete. Then the buffer will be emptied
  50880. + * (again possibly by USB I/O, during which it is marked BUSY) and
  50881. + * finally marked EMPTY again (possibly by a completion routine).
  50882. + *
  50883. + * A module parameter tells the driver to avoid stalling the bulk
  50884. + * endpoints wherever the transport specification allows. This is
  50885. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  50886. + * halt on a bulk endpoint. However, under certain circumstances the
  50887. + * Bulk-only specification requires a stall. In such cases the driver
  50888. + * will halt the endpoint and set a flag indicating that it should clear
  50889. + * the halt in software during the next device reset. Hopefully this
  50890. + * will permit everything to work correctly. Furthermore, although the
  50891. + * specification allows the bulk-out endpoint to halt when the host sends
  50892. + * too much data, implementing this would cause an unavoidable race.
  50893. + * The driver will always use the "no-stall" approach for OUT transfers.
  50894. + *
  50895. + * One subtle point concerns sending status-stage responses for ep0
  50896. + * requests. Some of these requests, such as device reset, can involve
  50897. + * interrupting an ongoing file I/O operation, which might take an
  50898. + * arbitrarily long time. During that delay the host might give up on
  50899. + * the original ep0 request and issue a new one. When that happens the
  50900. + * driver should not notify the host about completion of the original
  50901. + * request, as the host will no longer be waiting for it. So the driver
  50902. + * assigns to each ep0 request a unique tag, and it keeps track of the
  50903. + * tag value of the request associated with a long-running exception
  50904. + * (device-reset, interface-change, or configuration-change). When the
  50905. + * exception handler is finished, the status-stage response is submitted
  50906. + * only if the current ep0 request tag is equal to the exception request
  50907. + * tag. Thus only the most recently received ep0 request will get a
  50908. + * status-stage response.
  50909. + *
  50910. + * Warning: This driver source file is too long. It ought to be split up
  50911. + * into a header file plus about 3 separate .c files, to handle the details
  50912. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  50913. + */
  50914. +
  50915. +
  50916. +/* #define VERBOSE_DEBUG */
  50917. +/* #define DUMP_MSGS */
  50918. +
  50919. +
  50920. +#include <linux/blkdev.h>
  50921. +#include <linux/completion.h>
  50922. +#include <linux/dcache.h>
  50923. +#include <linux/delay.h>
  50924. +#include <linux/device.h>
  50925. +#include <linux/fcntl.h>
  50926. +#include <linux/file.h>
  50927. +#include <linux/fs.h>
  50928. +#include <linux/kref.h>
  50929. +#include <linux/kthread.h>
  50930. +#include <linux/limits.h>
  50931. +#include <linux/module.h>
  50932. +#include <linux/rwsem.h>
  50933. +#include <linux/slab.h>
  50934. +#include <linux/spinlock.h>
  50935. +#include <linux/string.h>
  50936. +#include <linux/freezer.h>
  50937. +#include <linux/utsname.h>
  50938. +
  50939. +#include <linux/usb/ch9.h>
  50940. +#include <linux/usb/gadget.h>
  50941. +
  50942. +#include "gadget_chips.h"
  50943. +
  50944. +
  50945. +
  50946. +/*
  50947. + * Kbuild is not very cooperative with respect to linking separately
  50948. + * compiled library objects into one module. So for now we won't use
  50949. + * separate compilation ... ensuring init/exit sections work to shrink
  50950. + * the runtime footprint, and giving us at least some parts of what
  50951. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  50952. + */
  50953. +#include "usbstring.c"
  50954. +#include "config.c"
  50955. +#include "epautoconf.c"
  50956. +
  50957. +/*-------------------------------------------------------------------------*/
  50958. +
  50959. +#define DRIVER_DESC "File-backed Storage Gadget"
  50960. +#define DRIVER_NAME "g_file_storage"
  50961. +#define DRIVER_VERSION "1 September 2010"
  50962. +
  50963. +static char fsg_string_manufacturer[64];
  50964. +static const char fsg_string_product[] = DRIVER_DESC;
  50965. +static const char fsg_string_config[] = "Self-powered";
  50966. +static const char fsg_string_interface[] = "Mass Storage";
  50967. +
  50968. +
  50969. +#include "storage_common.c"
  50970. +
  50971. +
  50972. +MODULE_DESCRIPTION(DRIVER_DESC);
  50973. +MODULE_AUTHOR("Alan Stern");
  50974. +MODULE_LICENSE("Dual BSD/GPL");
  50975. +
  50976. +/*
  50977. + * This driver assumes self-powered hardware and has no way for users to
  50978. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  50979. + * and endpoint addresses.
  50980. + */
  50981. +
  50982. +
  50983. +/*-------------------------------------------------------------------------*/
  50984. +
  50985. +
  50986. +/* Encapsulate the module parameter settings */
  50987. +
  50988. +static struct {
  50989. + char *file[FSG_MAX_LUNS];
  50990. + char *serial;
  50991. + bool ro[FSG_MAX_LUNS];
  50992. + bool nofua[FSG_MAX_LUNS];
  50993. + unsigned int num_filenames;
  50994. + unsigned int num_ros;
  50995. + unsigned int num_nofuas;
  50996. + unsigned int nluns;
  50997. +
  50998. + bool removable;
  50999. + bool can_stall;
  51000. + bool cdrom;
  51001. +
  51002. + char *transport_parm;
  51003. + char *protocol_parm;
  51004. + unsigned short vendor;
  51005. + unsigned short product;
  51006. + unsigned short release;
  51007. + unsigned int buflen;
  51008. +
  51009. + int transport_type;
  51010. + char *transport_name;
  51011. + int protocol_type;
  51012. + char *protocol_name;
  51013. +
  51014. +} mod_data = { // Default values
  51015. + .transport_parm = "BBB",
  51016. + .protocol_parm = "SCSI",
  51017. + .removable = 0,
  51018. + .can_stall = 1,
  51019. + .cdrom = 0,
  51020. + .vendor = FSG_VENDOR_ID,
  51021. + .product = FSG_PRODUCT_ID,
  51022. + .release = 0xffff, // Use controller chip type
  51023. + .buflen = 16384,
  51024. + };
  51025. +
  51026. +
  51027. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  51028. + S_IRUGO);
  51029. +MODULE_PARM_DESC(file, "names of backing files or devices");
  51030. +
  51031. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  51032. +MODULE_PARM_DESC(serial, "USB serial number");
  51033. +
  51034. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  51035. +MODULE_PARM_DESC(ro, "true to force read-only");
  51036. +
  51037. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  51038. + S_IRUGO);
  51039. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  51040. +
  51041. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  51042. +MODULE_PARM_DESC(luns, "number of LUNs");
  51043. +
  51044. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  51045. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  51046. +
  51047. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  51048. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  51049. +
  51050. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  51051. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  51052. +
  51053. +/* In the non-TEST version, only the module parameters listed above
  51054. + * are available. */
  51055. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  51056. +
  51057. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  51058. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  51059. +
  51060. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  51061. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  51062. + "8070, or SCSI)");
  51063. +
  51064. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  51065. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  51066. +
  51067. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  51068. +MODULE_PARM_DESC(product, "USB Product ID");
  51069. +
  51070. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  51071. +MODULE_PARM_DESC(release, "USB release number");
  51072. +
  51073. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  51074. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  51075. +
  51076. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  51077. +
  51078. +
  51079. +/*
  51080. + * These definitions will permit the compiler to avoid generating code for
  51081. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  51082. + * can recognize when a test of a constant expression yields a dead code
  51083. + * path.
  51084. + */
  51085. +
  51086. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  51087. +
  51088. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  51089. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  51090. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  51091. +
  51092. +#else
  51093. +
  51094. +#define transport_is_bbb() 1
  51095. +#define transport_is_cbi() 0
  51096. +#define protocol_is_scsi() 1
  51097. +
  51098. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  51099. +
  51100. +
  51101. +/*-------------------------------------------------------------------------*/
  51102. +
  51103. +
  51104. +struct fsg_dev {
  51105. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  51106. + spinlock_t lock;
  51107. + struct usb_gadget *gadget;
  51108. +
  51109. + /* filesem protects: backing files in use */
  51110. + struct rw_semaphore filesem;
  51111. +
  51112. + /* reference counting: wait until all LUNs are released */
  51113. + struct kref ref;
  51114. +
  51115. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  51116. + struct usb_request *ep0req; // For control responses
  51117. + unsigned int ep0_req_tag;
  51118. + const char *ep0req_name;
  51119. +
  51120. + struct usb_request *intreq; // For interrupt responses
  51121. + int intreq_busy;
  51122. + struct fsg_buffhd *intr_buffhd;
  51123. +
  51124. + unsigned int bulk_out_maxpacket;
  51125. + enum fsg_state state; // For exception handling
  51126. + unsigned int exception_req_tag;
  51127. +
  51128. + u8 config, new_config;
  51129. +
  51130. + unsigned int running : 1;
  51131. + unsigned int bulk_in_enabled : 1;
  51132. + unsigned int bulk_out_enabled : 1;
  51133. + unsigned int intr_in_enabled : 1;
  51134. + unsigned int phase_error : 1;
  51135. + unsigned int short_packet_received : 1;
  51136. + unsigned int bad_lun_okay : 1;
  51137. +
  51138. + unsigned long atomic_bitflags;
  51139. +#define REGISTERED 0
  51140. +#define IGNORE_BULK_OUT 1
  51141. +#define SUSPENDED 2
  51142. +
  51143. + struct usb_ep *bulk_in;
  51144. + struct usb_ep *bulk_out;
  51145. + struct usb_ep *intr_in;
  51146. +
  51147. + struct fsg_buffhd *next_buffhd_to_fill;
  51148. + struct fsg_buffhd *next_buffhd_to_drain;
  51149. +
  51150. + int thread_wakeup_needed;
  51151. + struct completion thread_notifier;
  51152. + struct task_struct *thread_task;
  51153. +
  51154. + int cmnd_size;
  51155. + u8 cmnd[MAX_COMMAND_SIZE];
  51156. + enum data_direction data_dir;
  51157. + u32 data_size;
  51158. + u32 data_size_from_cmnd;
  51159. + u32 tag;
  51160. + unsigned int lun;
  51161. + u32 residue;
  51162. + u32 usb_amount_left;
  51163. +
  51164. + /* The CB protocol offers no way for a host to know when a command
  51165. + * has completed. As a result the next command may arrive early,
  51166. + * and we will still have to handle it. For that reason we need
  51167. + * a buffer to store new commands when using CB (or CBI, which
  51168. + * does not oblige a host to wait for command completion either). */
  51169. + int cbbuf_cmnd_size;
  51170. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  51171. +
  51172. + unsigned int nluns;
  51173. + struct fsg_lun *luns;
  51174. + struct fsg_lun *curlun;
  51175. + /* Must be the last entry */
  51176. + struct fsg_buffhd buffhds[];
  51177. +};
  51178. +
  51179. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  51180. +
  51181. +static int exception_in_progress(struct fsg_dev *fsg)
  51182. +{
  51183. + return (fsg->state > FSG_STATE_IDLE);
  51184. +}
  51185. +
  51186. +/* Make bulk-out requests be divisible by the maxpacket size */
  51187. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  51188. + struct fsg_buffhd *bh, unsigned int length)
  51189. +{
  51190. + unsigned int rem;
  51191. +
  51192. + bh->bulk_out_intended_length = length;
  51193. + rem = length % fsg->bulk_out_maxpacket;
  51194. + if (rem > 0)
  51195. + length += fsg->bulk_out_maxpacket - rem;
  51196. + bh->outreq->length = length;
  51197. +}
  51198. +
  51199. +static struct fsg_dev *the_fsg;
  51200. +static struct usb_gadget_driver fsg_driver;
  51201. +
  51202. +
  51203. +/*-------------------------------------------------------------------------*/
  51204. +
  51205. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  51206. +{
  51207. + const char *name;
  51208. +
  51209. + if (ep == fsg->bulk_in)
  51210. + name = "bulk-in";
  51211. + else if (ep == fsg->bulk_out)
  51212. + name = "bulk-out";
  51213. + else
  51214. + name = ep->name;
  51215. + DBG(fsg, "%s set halt\n", name);
  51216. + return usb_ep_set_halt(ep);
  51217. +}
  51218. +
  51219. +
  51220. +/*-------------------------------------------------------------------------*/
  51221. +
  51222. +/*
  51223. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  51224. + * descriptors are built on demand. Also the (static) config and interface
  51225. + * descriptors are adjusted during fsg_bind().
  51226. + */
  51227. +
  51228. +/* There is only one configuration. */
  51229. +#define CONFIG_VALUE 1
  51230. +
  51231. +static struct usb_device_descriptor
  51232. +device_desc = {
  51233. + .bLength = sizeof device_desc,
  51234. + .bDescriptorType = USB_DT_DEVICE,
  51235. +
  51236. + .bcdUSB = cpu_to_le16(0x0200),
  51237. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  51238. +
  51239. + /* The next three values can be overridden by module parameters */
  51240. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  51241. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  51242. + .bcdDevice = cpu_to_le16(0xffff),
  51243. +
  51244. + .iManufacturer = FSG_STRING_MANUFACTURER,
  51245. + .iProduct = FSG_STRING_PRODUCT,
  51246. + .iSerialNumber = FSG_STRING_SERIAL,
  51247. + .bNumConfigurations = 1,
  51248. +};
  51249. +
  51250. +static struct usb_config_descriptor
  51251. +config_desc = {
  51252. + .bLength = sizeof config_desc,
  51253. + .bDescriptorType = USB_DT_CONFIG,
  51254. +
  51255. + /* wTotalLength computed by usb_gadget_config_buf() */
  51256. + .bNumInterfaces = 1,
  51257. + .bConfigurationValue = CONFIG_VALUE,
  51258. + .iConfiguration = FSG_STRING_CONFIG,
  51259. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  51260. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  51261. +};
  51262. +
  51263. +
  51264. +static struct usb_qualifier_descriptor
  51265. +dev_qualifier = {
  51266. + .bLength = sizeof dev_qualifier,
  51267. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  51268. +
  51269. + .bcdUSB = cpu_to_le16(0x0200),
  51270. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  51271. +
  51272. + .bNumConfigurations = 1,
  51273. +};
  51274. +
  51275. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  51276. +{
  51277. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  51278. + buf += USB_DT_BOS_SIZE;
  51279. +
  51280. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  51281. + buf += USB_DT_USB_EXT_CAP_SIZE;
  51282. +
  51283. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  51284. +
  51285. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  51286. + + USB_DT_USB_EXT_CAP_SIZE;
  51287. +}
  51288. +
  51289. +/*
  51290. + * Config descriptors must agree with the code that sets configurations
  51291. + * and with code managing interfaces and their altsettings. They must
  51292. + * also handle different speeds and other-speed requests.
  51293. + */
  51294. +static int populate_config_buf(struct usb_gadget *gadget,
  51295. + u8 *buf, u8 type, unsigned index)
  51296. +{
  51297. + enum usb_device_speed speed = gadget->speed;
  51298. + int len;
  51299. + const struct usb_descriptor_header **function;
  51300. +
  51301. + if (index > 0)
  51302. + return -EINVAL;
  51303. +
  51304. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  51305. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  51306. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  51307. + ? (const struct usb_descriptor_header **)fsg_hs_function
  51308. + : (const struct usb_descriptor_header **)fsg_fs_function;
  51309. +
  51310. + /* for now, don't advertise srp-only devices */
  51311. + if (!gadget_is_otg(gadget))
  51312. + function++;
  51313. +
  51314. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  51315. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  51316. + return len;
  51317. +}
  51318. +
  51319. +
  51320. +/*-------------------------------------------------------------------------*/
  51321. +
  51322. +/* These routines may be called in process context or in_irq */
  51323. +
  51324. +/* Caller must hold fsg->lock */
  51325. +static void wakeup_thread(struct fsg_dev *fsg)
  51326. +{
  51327. + /* Tell the main thread that something has happened */
  51328. + fsg->thread_wakeup_needed = 1;
  51329. + if (fsg->thread_task)
  51330. + wake_up_process(fsg->thread_task);
  51331. +}
  51332. +
  51333. +
  51334. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  51335. +{
  51336. + unsigned long flags;
  51337. +
  51338. + /* Do nothing if a higher-priority exception is already in progress.
  51339. + * If a lower-or-equal priority exception is in progress, preempt it
  51340. + * and notify the main thread by sending it a signal. */
  51341. + spin_lock_irqsave(&fsg->lock, flags);
  51342. + if (fsg->state <= new_state) {
  51343. + fsg->exception_req_tag = fsg->ep0_req_tag;
  51344. + fsg->state = new_state;
  51345. + if (fsg->thread_task)
  51346. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  51347. + fsg->thread_task);
  51348. + }
  51349. + spin_unlock_irqrestore(&fsg->lock, flags);
  51350. +}
  51351. +
  51352. +
  51353. +/*-------------------------------------------------------------------------*/
  51354. +
  51355. +/* The disconnect callback and ep0 routines. These always run in_irq,
  51356. + * except that ep0_queue() is called in the main thread to acknowledge
  51357. + * completion of various requests: set config, set interface, and
  51358. + * Bulk-only device reset. */
  51359. +
  51360. +static void fsg_disconnect(struct usb_gadget *gadget)
  51361. +{
  51362. + struct fsg_dev *fsg = get_gadget_data(gadget);
  51363. +
  51364. + DBG(fsg, "disconnect or port reset\n");
  51365. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  51366. +}
  51367. +
  51368. +
  51369. +static int ep0_queue(struct fsg_dev *fsg)
  51370. +{
  51371. + int rc;
  51372. +
  51373. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  51374. + if (rc != 0 && rc != -ESHUTDOWN) {
  51375. +
  51376. + /* We can't do much more than wait for a reset */
  51377. + WARNING(fsg, "error in submission: %s --> %d\n",
  51378. + fsg->ep0->name, rc);
  51379. + }
  51380. + return rc;
  51381. +}
  51382. +
  51383. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  51384. +{
  51385. + struct fsg_dev *fsg = ep->driver_data;
  51386. +
  51387. + if (req->actual > 0)
  51388. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  51389. + if (req->status || req->actual != req->length)
  51390. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  51391. + req->status, req->actual, req->length);
  51392. + if (req->status == -ECONNRESET) // Request was cancelled
  51393. + usb_ep_fifo_flush(ep);
  51394. +
  51395. + if (req->status == 0 && req->context)
  51396. + ((fsg_routine_t) (req->context))(fsg);
  51397. +}
  51398. +
  51399. +
  51400. +/*-------------------------------------------------------------------------*/
  51401. +
  51402. +/* Bulk and interrupt endpoint completion handlers.
  51403. + * These always run in_irq. */
  51404. +
  51405. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  51406. +{
  51407. + struct fsg_dev *fsg = ep->driver_data;
  51408. + struct fsg_buffhd *bh = req->context;
  51409. +
  51410. + if (req->status || req->actual != req->length)
  51411. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  51412. + req->status, req->actual, req->length);
  51413. + if (req->status == -ECONNRESET) // Request was cancelled
  51414. + usb_ep_fifo_flush(ep);
  51415. +
  51416. + /* Hold the lock while we update the request and buffer states */
  51417. + smp_wmb();
  51418. + spin_lock(&fsg->lock);
  51419. + bh->inreq_busy = 0;
  51420. + bh->state = BUF_STATE_EMPTY;
  51421. + wakeup_thread(fsg);
  51422. + spin_unlock(&fsg->lock);
  51423. +}
  51424. +
  51425. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  51426. +{
  51427. + struct fsg_dev *fsg = ep->driver_data;
  51428. + struct fsg_buffhd *bh = req->context;
  51429. +
  51430. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  51431. + if (req->status || req->actual != bh->bulk_out_intended_length)
  51432. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  51433. + req->status, req->actual,
  51434. + bh->bulk_out_intended_length);
  51435. + if (req->status == -ECONNRESET) // Request was cancelled
  51436. + usb_ep_fifo_flush(ep);
  51437. +
  51438. + /* Hold the lock while we update the request and buffer states */
  51439. + smp_wmb();
  51440. + spin_lock(&fsg->lock);
  51441. + bh->outreq_busy = 0;
  51442. + bh->state = BUF_STATE_FULL;
  51443. + wakeup_thread(fsg);
  51444. + spin_unlock(&fsg->lock);
  51445. +}
  51446. +
  51447. +
  51448. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  51449. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  51450. +{
  51451. + struct fsg_dev *fsg = ep->driver_data;
  51452. + struct fsg_buffhd *bh = req->context;
  51453. +
  51454. + if (req->status || req->actual != req->length)
  51455. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  51456. + req->status, req->actual, req->length);
  51457. + if (req->status == -ECONNRESET) // Request was cancelled
  51458. + usb_ep_fifo_flush(ep);
  51459. +
  51460. + /* Hold the lock while we update the request and buffer states */
  51461. + smp_wmb();
  51462. + spin_lock(&fsg->lock);
  51463. + fsg->intreq_busy = 0;
  51464. + bh->state = BUF_STATE_EMPTY;
  51465. + wakeup_thread(fsg);
  51466. + spin_unlock(&fsg->lock);
  51467. +}
  51468. +
  51469. +#else
  51470. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  51471. +{}
  51472. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  51473. +
  51474. +
  51475. +/*-------------------------------------------------------------------------*/
  51476. +
  51477. +/* Ep0 class-specific handlers. These always run in_irq. */
  51478. +
  51479. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  51480. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51481. +{
  51482. + struct usb_request *req = fsg->ep0req;
  51483. + static u8 cbi_reset_cmnd[6] = {
  51484. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  51485. +
  51486. + /* Error in command transfer? */
  51487. + if (req->status || req->length != req->actual ||
  51488. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  51489. +
  51490. + /* Not all controllers allow a protocol stall after
  51491. + * receiving control-out data, but we'll try anyway. */
  51492. + fsg_set_halt(fsg, fsg->ep0);
  51493. + return; // Wait for reset
  51494. + }
  51495. +
  51496. + /* Is it the special reset command? */
  51497. + if (req->actual >= sizeof cbi_reset_cmnd &&
  51498. + memcmp(req->buf, cbi_reset_cmnd,
  51499. + sizeof cbi_reset_cmnd) == 0) {
  51500. +
  51501. + /* Raise an exception to stop the current operation
  51502. + * and reinitialize our state. */
  51503. + DBG(fsg, "cbi reset request\n");
  51504. + raise_exception(fsg, FSG_STATE_RESET);
  51505. + return;
  51506. + }
  51507. +
  51508. + VDBG(fsg, "CB[I] accept device-specific command\n");
  51509. + spin_lock(&fsg->lock);
  51510. +
  51511. + /* Save the command for later */
  51512. + if (fsg->cbbuf_cmnd_size)
  51513. + WARNING(fsg, "CB[I] overwriting previous command\n");
  51514. + fsg->cbbuf_cmnd_size = req->actual;
  51515. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  51516. +
  51517. + wakeup_thread(fsg);
  51518. + spin_unlock(&fsg->lock);
  51519. +}
  51520. +
  51521. +#else
  51522. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  51523. +{}
  51524. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  51525. +
  51526. +
  51527. +static int class_setup_req(struct fsg_dev *fsg,
  51528. + const struct usb_ctrlrequest *ctrl)
  51529. +{
  51530. + struct usb_request *req = fsg->ep0req;
  51531. + int value = -EOPNOTSUPP;
  51532. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  51533. + u16 w_value = le16_to_cpu(ctrl->wValue);
  51534. + u16 w_length = le16_to_cpu(ctrl->wLength);
  51535. +
  51536. + if (!fsg->config)
  51537. + return value;
  51538. +
  51539. + /* Handle Bulk-only class-specific requests */
  51540. + if (transport_is_bbb()) {
  51541. + switch (ctrl->bRequest) {
  51542. +
  51543. + case US_BULK_RESET_REQUEST:
  51544. + if (ctrl->bRequestType != (USB_DIR_OUT |
  51545. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  51546. + break;
  51547. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  51548. + value = -EDOM;
  51549. + break;
  51550. + }
  51551. +
  51552. + /* Raise an exception to stop the current operation
  51553. + * and reinitialize our state. */
  51554. + DBG(fsg, "bulk reset request\n");
  51555. + raise_exception(fsg, FSG_STATE_RESET);
  51556. + value = DELAYED_STATUS;
  51557. + break;
  51558. +
  51559. + case US_BULK_GET_MAX_LUN:
  51560. + if (ctrl->bRequestType != (USB_DIR_IN |
  51561. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  51562. + break;
  51563. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  51564. + value = -EDOM;
  51565. + break;
  51566. + }
  51567. + VDBG(fsg, "get max LUN\n");
  51568. + *(u8 *) req->buf = fsg->nluns - 1;
  51569. + value = 1;
  51570. + break;
  51571. + }
  51572. + }
  51573. +
  51574. + /* Handle CBI class-specific requests */
  51575. + else {
  51576. + switch (ctrl->bRequest) {
  51577. +
  51578. + case USB_CBI_ADSC_REQUEST:
  51579. + if (ctrl->bRequestType != (USB_DIR_OUT |
  51580. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  51581. + break;
  51582. + if (w_index != 0 || w_value != 0) {
  51583. + value = -EDOM;
  51584. + break;
  51585. + }
  51586. + if (w_length > MAX_COMMAND_SIZE) {
  51587. + value = -EOVERFLOW;
  51588. + break;
  51589. + }
  51590. + value = w_length;
  51591. + fsg->ep0req->context = received_cbi_adsc;
  51592. + break;
  51593. + }
  51594. + }
  51595. +
  51596. + if (value == -EOPNOTSUPP)
  51597. + VDBG(fsg,
  51598. + "unknown class-specific control req "
  51599. + "%02x.%02x v%04x i%04x l%u\n",
  51600. + ctrl->bRequestType, ctrl->bRequest,
  51601. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  51602. + return value;
  51603. +}
  51604. +
  51605. +
  51606. +/*-------------------------------------------------------------------------*/
  51607. +
  51608. +/* Ep0 standard request handlers. These always run in_irq. */
  51609. +
  51610. +static int standard_setup_req(struct fsg_dev *fsg,
  51611. + const struct usb_ctrlrequest *ctrl)
  51612. +{
  51613. + struct usb_request *req = fsg->ep0req;
  51614. + int value = -EOPNOTSUPP;
  51615. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  51616. + u16 w_value = le16_to_cpu(ctrl->wValue);
  51617. +
  51618. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  51619. + * but config change events will also reconfigure hardware. */
  51620. + switch (ctrl->bRequest) {
  51621. +
  51622. + case USB_REQ_GET_DESCRIPTOR:
  51623. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51624. + USB_RECIP_DEVICE))
  51625. + break;
  51626. + switch (w_value >> 8) {
  51627. +
  51628. + case USB_DT_DEVICE:
  51629. + VDBG(fsg, "get device descriptor\n");
  51630. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  51631. + value = sizeof device_desc;
  51632. + memcpy(req->buf, &device_desc, value);
  51633. + break;
  51634. + case USB_DT_DEVICE_QUALIFIER:
  51635. + VDBG(fsg, "get device qualifier\n");
  51636. + if (!gadget_is_dualspeed(fsg->gadget) ||
  51637. + fsg->gadget->speed == USB_SPEED_SUPER)
  51638. + break;
  51639. + /*
  51640. + * Assume ep0 uses the same maxpacket value for both
  51641. + * speeds
  51642. + */
  51643. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  51644. + value = sizeof dev_qualifier;
  51645. + memcpy(req->buf, &dev_qualifier, value);
  51646. + break;
  51647. +
  51648. + case USB_DT_OTHER_SPEED_CONFIG:
  51649. + VDBG(fsg, "get other-speed config descriptor\n");
  51650. + if (!gadget_is_dualspeed(fsg->gadget) ||
  51651. + fsg->gadget->speed == USB_SPEED_SUPER)
  51652. + break;
  51653. + goto get_config;
  51654. + case USB_DT_CONFIG:
  51655. + VDBG(fsg, "get configuration descriptor\n");
  51656. +get_config:
  51657. + value = populate_config_buf(fsg->gadget,
  51658. + req->buf,
  51659. + w_value >> 8,
  51660. + w_value & 0xff);
  51661. + break;
  51662. +
  51663. + case USB_DT_STRING:
  51664. + VDBG(fsg, "get string descriptor\n");
  51665. +
  51666. + /* wIndex == language code */
  51667. + value = usb_gadget_get_string(&fsg_stringtab,
  51668. + w_value & 0xff, req->buf);
  51669. + break;
  51670. +
  51671. + case USB_DT_BOS:
  51672. + VDBG(fsg, "get bos descriptor\n");
  51673. +
  51674. + if (gadget_is_superspeed(fsg->gadget))
  51675. + value = populate_bos(fsg, req->buf);
  51676. + break;
  51677. + }
  51678. +
  51679. + break;
  51680. +
  51681. + /* One config, two speeds */
  51682. + case USB_REQ_SET_CONFIGURATION:
  51683. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  51684. + USB_RECIP_DEVICE))
  51685. + break;
  51686. + VDBG(fsg, "set configuration\n");
  51687. + if (w_value == CONFIG_VALUE || w_value == 0) {
  51688. + fsg->new_config = w_value;
  51689. +
  51690. + /* Raise an exception to wipe out previous transaction
  51691. + * state (queued bufs, etc) and set the new config. */
  51692. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  51693. + value = DELAYED_STATUS;
  51694. + }
  51695. + break;
  51696. + case USB_REQ_GET_CONFIGURATION:
  51697. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51698. + USB_RECIP_DEVICE))
  51699. + break;
  51700. + VDBG(fsg, "get configuration\n");
  51701. + *(u8 *) req->buf = fsg->config;
  51702. + value = 1;
  51703. + break;
  51704. +
  51705. + case USB_REQ_SET_INTERFACE:
  51706. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  51707. + USB_RECIP_INTERFACE))
  51708. + break;
  51709. + if (fsg->config && w_index == 0) {
  51710. +
  51711. + /* Raise an exception to wipe out previous transaction
  51712. + * state (queued bufs, etc) and install the new
  51713. + * interface altsetting. */
  51714. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  51715. + value = DELAYED_STATUS;
  51716. + }
  51717. + break;
  51718. + case USB_REQ_GET_INTERFACE:
  51719. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  51720. + USB_RECIP_INTERFACE))
  51721. + break;
  51722. + if (!fsg->config)
  51723. + break;
  51724. + if (w_index != 0) {
  51725. + value = -EDOM;
  51726. + break;
  51727. + }
  51728. + VDBG(fsg, "get interface\n");
  51729. + *(u8 *) req->buf = 0;
  51730. + value = 1;
  51731. + break;
  51732. +
  51733. + default:
  51734. + VDBG(fsg,
  51735. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  51736. + ctrl->bRequestType, ctrl->bRequest,
  51737. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  51738. + }
  51739. +
  51740. + return value;
  51741. +}
  51742. +
  51743. +
  51744. +static int fsg_setup(struct usb_gadget *gadget,
  51745. + const struct usb_ctrlrequest *ctrl)
  51746. +{
  51747. + struct fsg_dev *fsg = get_gadget_data(gadget);
  51748. + int rc;
  51749. + int w_length = le16_to_cpu(ctrl->wLength);
  51750. +
  51751. + ++fsg->ep0_req_tag; // Record arrival of a new request
  51752. + fsg->ep0req->context = NULL;
  51753. + fsg->ep0req->length = 0;
  51754. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  51755. +
  51756. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  51757. + rc = class_setup_req(fsg, ctrl);
  51758. + else
  51759. + rc = standard_setup_req(fsg, ctrl);
  51760. +
  51761. + /* Respond with data/status or defer until later? */
  51762. + if (rc >= 0 && rc != DELAYED_STATUS) {
  51763. + rc = min(rc, w_length);
  51764. + fsg->ep0req->length = rc;
  51765. + fsg->ep0req->zero = rc < w_length;
  51766. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  51767. + "ep0-in" : "ep0-out");
  51768. + rc = ep0_queue(fsg);
  51769. + }
  51770. +
  51771. + /* Device either stalls (rc < 0) or reports success */
  51772. + return rc;
  51773. +}
  51774. +
  51775. +
  51776. +/*-------------------------------------------------------------------------*/
  51777. +
  51778. +/* All the following routines run in process context */
  51779. +
  51780. +
  51781. +/* Use this for bulk or interrupt transfers, not ep0 */
  51782. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  51783. + struct usb_request *req, int *pbusy,
  51784. + enum fsg_buffer_state *state)
  51785. +{
  51786. + int rc;
  51787. +
  51788. + if (ep == fsg->bulk_in)
  51789. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  51790. + else if (ep == fsg->intr_in)
  51791. + dump_msg(fsg, "intr-in", req->buf, req->length);
  51792. +
  51793. + spin_lock_irq(&fsg->lock);
  51794. + *pbusy = 1;
  51795. + *state = BUF_STATE_BUSY;
  51796. + spin_unlock_irq(&fsg->lock);
  51797. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  51798. + if (rc != 0) {
  51799. + *pbusy = 0;
  51800. + *state = BUF_STATE_EMPTY;
  51801. +
  51802. + /* We can't do much more than wait for a reset */
  51803. +
  51804. + /* Note: currently the net2280 driver fails zero-length
  51805. + * submissions if DMA is enabled. */
  51806. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  51807. + req->length == 0))
  51808. + WARNING(fsg, "error in submission: %s --> %d\n",
  51809. + ep->name, rc);
  51810. + }
  51811. +}
  51812. +
  51813. +
  51814. +static int sleep_thread(struct fsg_dev *fsg)
  51815. +{
  51816. + int rc = 0;
  51817. +
  51818. + /* Wait until a signal arrives or we are woken up */
  51819. + for (;;) {
  51820. + try_to_freeze();
  51821. + set_current_state(TASK_INTERRUPTIBLE);
  51822. + if (signal_pending(current)) {
  51823. + rc = -EINTR;
  51824. + break;
  51825. + }
  51826. + if (fsg->thread_wakeup_needed)
  51827. + break;
  51828. + schedule();
  51829. + }
  51830. + __set_current_state(TASK_RUNNING);
  51831. + fsg->thread_wakeup_needed = 0;
  51832. + return rc;
  51833. +}
  51834. +
  51835. +
  51836. +/*-------------------------------------------------------------------------*/
  51837. +
  51838. +static int do_read(struct fsg_dev *fsg)
  51839. +{
  51840. + struct fsg_lun *curlun = fsg->curlun;
  51841. + u32 lba;
  51842. + struct fsg_buffhd *bh;
  51843. + int rc;
  51844. + u32 amount_left;
  51845. + loff_t file_offset, file_offset_tmp;
  51846. + unsigned int amount;
  51847. + ssize_t nread;
  51848. +
  51849. + /* Get the starting Logical Block Address and check that it's
  51850. + * not too big */
  51851. + if (fsg->cmnd[0] == READ_6)
  51852. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  51853. + else {
  51854. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  51855. +
  51856. + /* We allow DPO (Disable Page Out = don't save data in the
  51857. + * cache) and FUA (Force Unit Access = don't read from the
  51858. + * cache), but we don't implement them. */
  51859. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  51860. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51861. + return -EINVAL;
  51862. + }
  51863. + }
  51864. + if (lba >= curlun->num_sectors) {
  51865. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51866. + return -EINVAL;
  51867. + }
  51868. + file_offset = ((loff_t) lba) << curlun->blkbits;
  51869. +
  51870. + /* Carry out the file reads */
  51871. + amount_left = fsg->data_size_from_cmnd;
  51872. + if (unlikely(amount_left == 0))
  51873. + return -EIO; // No default reply
  51874. +
  51875. + for (;;) {
  51876. +
  51877. + /* Figure out how much we need to read:
  51878. + * Try to read the remaining amount.
  51879. + * But don't read more than the buffer size.
  51880. + * And don't try to read past the end of the file.
  51881. + */
  51882. + amount = min((unsigned int) amount_left, mod_data.buflen);
  51883. + amount = min((loff_t) amount,
  51884. + curlun->file_length - file_offset);
  51885. +
  51886. + /* Wait for the next buffer to become available */
  51887. + bh = fsg->next_buffhd_to_fill;
  51888. + while (bh->state != BUF_STATE_EMPTY) {
  51889. + rc = sleep_thread(fsg);
  51890. + if (rc)
  51891. + return rc;
  51892. + }
  51893. +
  51894. + /* If we were asked to read past the end of file,
  51895. + * end with an empty buffer. */
  51896. + if (amount == 0) {
  51897. + curlun->sense_data =
  51898. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  51899. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51900. + curlun->info_valid = 1;
  51901. + bh->inreq->length = 0;
  51902. + bh->state = BUF_STATE_FULL;
  51903. + break;
  51904. + }
  51905. +
  51906. + /* Perform the read */
  51907. + file_offset_tmp = file_offset;
  51908. + nread = vfs_read(curlun->filp,
  51909. + (char __user *) bh->buf,
  51910. + amount, &file_offset_tmp);
  51911. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  51912. + (unsigned long long) file_offset,
  51913. + (int) nread);
  51914. + if (signal_pending(current))
  51915. + return -EINTR;
  51916. +
  51917. + if (nread < 0) {
  51918. + LDBG(curlun, "error in file read: %d\n",
  51919. + (int) nread);
  51920. + nread = 0;
  51921. + } else if (nread < amount) {
  51922. + LDBG(curlun, "partial file read: %d/%u\n",
  51923. + (int) nread, amount);
  51924. + nread = round_down(nread, curlun->blksize);
  51925. + }
  51926. + file_offset += nread;
  51927. + amount_left -= nread;
  51928. + fsg->residue -= nread;
  51929. +
  51930. + /* Except at the end of the transfer, nread will be
  51931. + * equal to the buffer size, which is divisible by the
  51932. + * bulk-in maxpacket size.
  51933. + */
  51934. + bh->inreq->length = nread;
  51935. + bh->state = BUF_STATE_FULL;
  51936. +
  51937. + /* If an error occurred, report it and its position */
  51938. + if (nread < amount) {
  51939. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  51940. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  51941. + curlun->info_valid = 1;
  51942. + break;
  51943. + }
  51944. +
  51945. + if (amount_left == 0)
  51946. + break; // No more left to read
  51947. +
  51948. + /* Send this buffer and go read some more */
  51949. + bh->inreq->zero = 0;
  51950. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  51951. + &bh->inreq_busy, &bh->state);
  51952. + fsg->next_buffhd_to_fill = bh->next;
  51953. + }
  51954. +
  51955. + return -EIO; // No default reply
  51956. +}
  51957. +
  51958. +
  51959. +/*-------------------------------------------------------------------------*/
  51960. +
  51961. +static int do_write(struct fsg_dev *fsg)
  51962. +{
  51963. + struct fsg_lun *curlun = fsg->curlun;
  51964. + u32 lba;
  51965. + struct fsg_buffhd *bh;
  51966. + int get_some_more;
  51967. + u32 amount_left_to_req, amount_left_to_write;
  51968. + loff_t usb_offset, file_offset, file_offset_tmp;
  51969. + unsigned int amount;
  51970. + ssize_t nwritten;
  51971. + int rc;
  51972. +
  51973. + if (curlun->ro) {
  51974. + curlun->sense_data = SS_WRITE_PROTECTED;
  51975. + return -EINVAL;
  51976. + }
  51977. + spin_lock(&curlun->filp->f_lock);
  51978. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  51979. + spin_unlock(&curlun->filp->f_lock);
  51980. +
  51981. + /* Get the starting Logical Block Address and check that it's
  51982. + * not too big */
  51983. + if (fsg->cmnd[0] == WRITE_6)
  51984. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  51985. + else {
  51986. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  51987. +
  51988. + /* We allow DPO (Disable Page Out = don't save data in the
  51989. + * cache) and FUA (Force Unit Access = write directly to the
  51990. + * medium). We don't implement DPO; we implement FUA by
  51991. + * performing synchronous output. */
  51992. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  51993. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  51994. + return -EINVAL;
  51995. + }
  51996. + /* FUA */
  51997. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  51998. + spin_lock(&curlun->filp->f_lock);
  51999. + curlun->filp->f_flags |= O_DSYNC;
  52000. + spin_unlock(&curlun->filp->f_lock);
  52001. + }
  52002. + }
  52003. + if (lba >= curlun->num_sectors) {
  52004. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  52005. + return -EINVAL;
  52006. + }
  52007. +
  52008. + /* Carry out the file writes */
  52009. + get_some_more = 1;
  52010. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  52011. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  52012. +
  52013. + while (amount_left_to_write > 0) {
  52014. +
  52015. + /* Queue a request for more data from the host */
  52016. + bh = fsg->next_buffhd_to_fill;
  52017. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  52018. +
  52019. + /* Figure out how much we want to get:
  52020. + * Try to get the remaining amount,
  52021. + * but not more than the buffer size.
  52022. + */
  52023. + amount = min(amount_left_to_req, mod_data.buflen);
  52024. +
  52025. + /* Beyond the end of the backing file? */
  52026. + if (usb_offset >= curlun->file_length) {
  52027. + get_some_more = 0;
  52028. + curlun->sense_data =
  52029. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  52030. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  52031. + curlun->info_valid = 1;
  52032. + continue;
  52033. + }
  52034. +
  52035. + /* Get the next buffer */
  52036. + usb_offset += amount;
  52037. + fsg->usb_amount_left -= amount;
  52038. + amount_left_to_req -= amount;
  52039. + if (amount_left_to_req == 0)
  52040. + get_some_more = 0;
  52041. +
  52042. + /* Except at the end of the transfer, amount will be
  52043. + * equal to the buffer size, which is divisible by
  52044. + * the bulk-out maxpacket size.
  52045. + */
  52046. + set_bulk_out_req_length(fsg, bh, amount);
  52047. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  52048. + &bh->outreq_busy, &bh->state);
  52049. + fsg->next_buffhd_to_fill = bh->next;
  52050. + continue;
  52051. + }
  52052. +
  52053. + /* Write the received data to the backing file */
  52054. + bh = fsg->next_buffhd_to_drain;
  52055. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  52056. + break; // We stopped early
  52057. + if (bh->state == BUF_STATE_FULL) {
  52058. + smp_rmb();
  52059. + fsg->next_buffhd_to_drain = bh->next;
  52060. + bh->state = BUF_STATE_EMPTY;
  52061. +
  52062. + /* Did something go wrong with the transfer? */
  52063. + if (bh->outreq->status != 0) {
  52064. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  52065. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  52066. + curlun->info_valid = 1;
  52067. + break;
  52068. + }
  52069. +
  52070. + amount = bh->outreq->actual;
  52071. + if (curlun->file_length - file_offset < amount) {
  52072. + LERROR(curlun,
  52073. + "write %u @ %llu beyond end %llu\n",
  52074. + amount, (unsigned long long) file_offset,
  52075. + (unsigned long long) curlun->file_length);
  52076. + amount = curlun->file_length - file_offset;
  52077. + }
  52078. +
  52079. + /* Don't accept excess data. The spec doesn't say
  52080. + * what to do in this case. We'll ignore the error.
  52081. + */
  52082. + amount = min(amount, bh->bulk_out_intended_length);
  52083. +
  52084. + /* Don't write a partial block */
  52085. + amount = round_down(amount, curlun->blksize);
  52086. + if (amount == 0)
  52087. + goto empty_write;
  52088. +
  52089. + /* Perform the write */
  52090. + file_offset_tmp = file_offset;
  52091. + nwritten = vfs_write(curlun->filp,
  52092. + (char __user *) bh->buf,
  52093. + amount, &file_offset_tmp);
  52094. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  52095. + (unsigned long long) file_offset,
  52096. + (int) nwritten);
  52097. + if (signal_pending(current))
  52098. + return -EINTR; // Interrupted!
  52099. +
  52100. + if (nwritten < 0) {
  52101. + LDBG(curlun, "error in file write: %d\n",
  52102. + (int) nwritten);
  52103. + nwritten = 0;
  52104. + } else if (nwritten < amount) {
  52105. + LDBG(curlun, "partial file write: %d/%u\n",
  52106. + (int) nwritten, amount);
  52107. + nwritten = round_down(nwritten, curlun->blksize);
  52108. + }
  52109. + file_offset += nwritten;
  52110. + amount_left_to_write -= nwritten;
  52111. + fsg->residue -= nwritten;
  52112. +
  52113. + /* If an error occurred, report it and its position */
  52114. + if (nwritten < amount) {
  52115. + curlun->sense_data = SS_WRITE_ERROR;
  52116. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  52117. + curlun->info_valid = 1;
  52118. + break;
  52119. + }
  52120. +
  52121. + empty_write:
  52122. + /* Did the host decide to stop early? */
  52123. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  52124. + fsg->short_packet_received = 1;
  52125. + break;
  52126. + }
  52127. + continue;
  52128. + }
  52129. +
  52130. + /* Wait for something to happen */
  52131. + rc = sleep_thread(fsg);
  52132. + if (rc)
  52133. + return rc;
  52134. + }
  52135. +
  52136. + return -EIO; // No default reply
  52137. +}
  52138. +
  52139. +
  52140. +/*-------------------------------------------------------------------------*/
  52141. +
  52142. +static int do_synchronize_cache(struct fsg_dev *fsg)
  52143. +{
  52144. + struct fsg_lun *curlun = fsg->curlun;
  52145. + int rc;
  52146. +
  52147. + /* We ignore the requested LBA and write out all file's
  52148. + * dirty data buffers. */
  52149. + rc = fsg_lun_fsync_sub(curlun);
  52150. + if (rc)
  52151. + curlun->sense_data = SS_WRITE_ERROR;
  52152. + return 0;
  52153. +}
  52154. +
  52155. +
  52156. +/*-------------------------------------------------------------------------*/
  52157. +
  52158. +static void invalidate_sub(struct fsg_lun *curlun)
  52159. +{
  52160. + struct file *filp = curlun->filp;
  52161. + struct inode *inode = filp->f_path.dentry->d_inode;
  52162. + unsigned long rc;
  52163. +
  52164. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  52165. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  52166. +}
  52167. +
  52168. +static int do_verify(struct fsg_dev *fsg)
  52169. +{
  52170. + struct fsg_lun *curlun = fsg->curlun;
  52171. + u32 lba;
  52172. + u32 verification_length;
  52173. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  52174. + loff_t file_offset, file_offset_tmp;
  52175. + u32 amount_left;
  52176. + unsigned int amount;
  52177. + ssize_t nread;
  52178. +
  52179. + /* Get the starting Logical Block Address and check that it's
  52180. + * not too big */
  52181. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  52182. + if (lba >= curlun->num_sectors) {
  52183. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  52184. + return -EINVAL;
  52185. + }
  52186. +
  52187. + /* We allow DPO (Disable Page Out = don't save data in the
  52188. + * cache) but we don't implement it. */
  52189. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  52190. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52191. + return -EINVAL;
  52192. + }
  52193. +
  52194. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  52195. + if (unlikely(verification_length == 0))
  52196. + return -EIO; // No default reply
  52197. +
  52198. + /* Prepare to carry out the file verify */
  52199. + amount_left = verification_length << curlun->blkbits;
  52200. + file_offset = ((loff_t) lba) << curlun->blkbits;
  52201. +
  52202. + /* Write out all the dirty buffers before invalidating them */
  52203. + fsg_lun_fsync_sub(curlun);
  52204. + if (signal_pending(current))
  52205. + return -EINTR;
  52206. +
  52207. + invalidate_sub(curlun);
  52208. + if (signal_pending(current))
  52209. + return -EINTR;
  52210. +
  52211. + /* Just try to read the requested blocks */
  52212. + while (amount_left > 0) {
  52213. +
  52214. + /* Figure out how much we need to read:
  52215. + * Try to read the remaining amount, but not more than
  52216. + * the buffer size.
  52217. + * And don't try to read past the end of the file.
  52218. + */
  52219. + amount = min((unsigned int) amount_left, mod_data.buflen);
  52220. + amount = min((loff_t) amount,
  52221. + curlun->file_length - file_offset);
  52222. + if (amount == 0) {
  52223. + curlun->sense_data =
  52224. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  52225. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  52226. + curlun->info_valid = 1;
  52227. + break;
  52228. + }
  52229. +
  52230. + /* Perform the read */
  52231. + file_offset_tmp = file_offset;
  52232. + nread = vfs_read(curlun->filp,
  52233. + (char __user *) bh->buf,
  52234. + amount, &file_offset_tmp);
  52235. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  52236. + (unsigned long long) file_offset,
  52237. + (int) nread);
  52238. + if (signal_pending(current))
  52239. + return -EINTR;
  52240. +
  52241. + if (nread < 0) {
  52242. + LDBG(curlun, "error in file verify: %d\n",
  52243. + (int) nread);
  52244. + nread = 0;
  52245. + } else if (nread < amount) {
  52246. + LDBG(curlun, "partial file verify: %d/%u\n",
  52247. + (int) nread, amount);
  52248. + nread = round_down(nread, curlun->blksize);
  52249. + }
  52250. + if (nread == 0) {
  52251. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  52252. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  52253. + curlun->info_valid = 1;
  52254. + break;
  52255. + }
  52256. + file_offset += nread;
  52257. + amount_left -= nread;
  52258. + }
  52259. + return 0;
  52260. +}
  52261. +
  52262. +
  52263. +/*-------------------------------------------------------------------------*/
  52264. +
  52265. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52266. +{
  52267. + u8 *buf = (u8 *) bh->buf;
  52268. +
  52269. + static char vendor_id[] = "Linux ";
  52270. + static char product_disk_id[] = "File-Stor Gadget";
  52271. + static char product_cdrom_id[] = "File-CD Gadget ";
  52272. +
  52273. + if (!fsg->curlun) { // Unsupported LUNs are okay
  52274. + fsg->bad_lun_okay = 1;
  52275. + memset(buf, 0, 36);
  52276. + buf[0] = 0x7f; // Unsupported, no device-type
  52277. + buf[4] = 31; // Additional length
  52278. + return 36;
  52279. + }
  52280. +
  52281. + memset(buf, 0, 8);
  52282. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  52283. + if (mod_data.removable)
  52284. + buf[1] = 0x80;
  52285. + buf[2] = 2; // ANSI SCSI level 2
  52286. + buf[3] = 2; // SCSI-2 INQUIRY data format
  52287. + buf[4] = 31; // Additional length
  52288. + // No special options
  52289. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  52290. + (mod_data.cdrom ? product_cdrom_id :
  52291. + product_disk_id),
  52292. + mod_data.release);
  52293. + return 36;
  52294. +}
  52295. +
  52296. +
  52297. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52298. +{
  52299. + struct fsg_lun *curlun = fsg->curlun;
  52300. + u8 *buf = (u8 *) bh->buf;
  52301. + u32 sd, sdinfo;
  52302. + int valid;
  52303. +
  52304. + /*
  52305. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  52306. + *
  52307. + * If a REQUEST SENSE command is received from an initiator
  52308. + * with a pending unit attention condition (before the target
  52309. + * generates the contingent allegiance condition), then the
  52310. + * target shall either:
  52311. + * a) report any pending sense data and preserve the unit
  52312. + * attention condition on the logical unit, or,
  52313. + * b) report the unit attention condition, may discard any
  52314. + * pending sense data, and clear the unit attention
  52315. + * condition on the logical unit for that initiator.
  52316. + *
  52317. + * FSG normally uses option a); enable this code to use option b).
  52318. + */
  52319. +#if 0
  52320. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  52321. + curlun->sense_data = curlun->unit_attention_data;
  52322. + curlun->unit_attention_data = SS_NO_SENSE;
  52323. + }
  52324. +#endif
  52325. +
  52326. + if (!curlun) { // Unsupported LUNs are okay
  52327. + fsg->bad_lun_okay = 1;
  52328. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  52329. + sdinfo = 0;
  52330. + valid = 0;
  52331. + } else {
  52332. + sd = curlun->sense_data;
  52333. + sdinfo = curlun->sense_data_info;
  52334. + valid = curlun->info_valid << 7;
  52335. + curlun->sense_data = SS_NO_SENSE;
  52336. + curlun->sense_data_info = 0;
  52337. + curlun->info_valid = 0;
  52338. + }
  52339. +
  52340. + memset(buf, 0, 18);
  52341. + buf[0] = valid | 0x70; // Valid, current error
  52342. + buf[2] = SK(sd);
  52343. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  52344. + buf[7] = 18 - 8; // Additional sense length
  52345. + buf[12] = ASC(sd);
  52346. + buf[13] = ASCQ(sd);
  52347. + return 18;
  52348. +}
  52349. +
  52350. +
  52351. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52352. +{
  52353. + struct fsg_lun *curlun = fsg->curlun;
  52354. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  52355. + int pmi = fsg->cmnd[8];
  52356. + u8 *buf = (u8 *) bh->buf;
  52357. +
  52358. + /* Check the PMI and LBA fields */
  52359. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  52360. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52361. + return -EINVAL;
  52362. + }
  52363. +
  52364. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  52365. + /* Max logical block */
  52366. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  52367. + return 8;
  52368. +}
  52369. +
  52370. +
  52371. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52372. +{
  52373. + struct fsg_lun *curlun = fsg->curlun;
  52374. + int msf = fsg->cmnd[1] & 0x02;
  52375. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  52376. + u8 *buf = (u8 *) bh->buf;
  52377. +
  52378. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  52379. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52380. + return -EINVAL;
  52381. + }
  52382. + if (lba >= curlun->num_sectors) {
  52383. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  52384. + return -EINVAL;
  52385. + }
  52386. +
  52387. + memset(buf, 0, 8);
  52388. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  52389. + store_cdrom_address(&buf[4], msf, lba);
  52390. + return 8;
  52391. +}
  52392. +
  52393. +
  52394. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52395. +{
  52396. + struct fsg_lun *curlun = fsg->curlun;
  52397. + int msf = fsg->cmnd[1] & 0x02;
  52398. + int start_track = fsg->cmnd[6];
  52399. + u8 *buf = (u8 *) bh->buf;
  52400. +
  52401. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  52402. + start_track > 1) {
  52403. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52404. + return -EINVAL;
  52405. + }
  52406. +
  52407. + memset(buf, 0, 20);
  52408. + buf[1] = (20-2); /* TOC data length */
  52409. + buf[2] = 1; /* First track number */
  52410. + buf[3] = 1; /* Last track number */
  52411. + buf[5] = 0x16; /* Data track, copying allowed */
  52412. + buf[6] = 0x01; /* Only track is number 1 */
  52413. + store_cdrom_address(&buf[8], msf, 0);
  52414. +
  52415. + buf[13] = 0x16; /* Lead-out track is data */
  52416. + buf[14] = 0xAA; /* Lead-out track number */
  52417. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  52418. + return 20;
  52419. +}
  52420. +
  52421. +
  52422. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52423. +{
  52424. + struct fsg_lun *curlun = fsg->curlun;
  52425. + int mscmnd = fsg->cmnd[0];
  52426. + u8 *buf = (u8 *) bh->buf;
  52427. + u8 *buf0 = buf;
  52428. + int pc, page_code;
  52429. + int changeable_values, all_pages;
  52430. + int valid_page = 0;
  52431. + int len, limit;
  52432. +
  52433. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  52434. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52435. + return -EINVAL;
  52436. + }
  52437. + pc = fsg->cmnd[2] >> 6;
  52438. + page_code = fsg->cmnd[2] & 0x3f;
  52439. + if (pc == 3) {
  52440. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  52441. + return -EINVAL;
  52442. + }
  52443. + changeable_values = (pc == 1);
  52444. + all_pages = (page_code == 0x3f);
  52445. +
  52446. + /* Write the mode parameter header. Fixed values are: default
  52447. + * medium type, no cache control (DPOFUA), and no block descriptors.
  52448. + * The only variable value is the WriteProtect bit. We will fill in
  52449. + * the mode data length later. */
  52450. + memset(buf, 0, 8);
  52451. + if (mscmnd == MODE_SENSE) {
  52452. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  52453. + buf += 4;
  52454. + limit = 255;
  52455. + } else { // MODE_SENSE_10
  52456. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  52457. + buf += 8;
  52458. + limit = 65535; // Should really be mod_data.buflen
  52459. + }
  52460. +
  52461. + /* No block descriptors */
  52462. +
  52463. + /* The mode pages, in numerical order. The only page we support
  52464. + * is the Caching page. */
  52465. + if (page_code == 0x08 || all_pages) {
  52466. + valid_page = 1;
  52467. + buf[0] = 0x08; // Page code
  52468. + buf[1] = 10; // Page length
  52469. + memset(buf+2, 0, 10); // None of the fields are changeable
  52470. +
  52471. + if (!changeable_values) {
  52472. + buf[2] = 0x04; // Write cache enable,
  52473. + // Read cache not disabled
  52474. + // No cache retention priorities
  52475. + put_unaligned_be16(0xffff, &buf[4]);
  52476. + /* Don't disable prefetch */
  52477. + /* Minimum prefetch = 0 */
  52478. + put_unaligned_be16(0xffff, &buf[8]);
  52479. + /* Maximum prefetch */
  52480. + put_unaligned_be16(0xffff, &buf[10]);
  52481. + /* Maximum prefetch ceiling */
  52482. + }
  52483. + buf += 12;
  52484. + }
  52485. +
  52486. + /* Check that a valid page was requested and the mode data length
  52487. + * isn't too long. */
  52488. + len = buf - buf0;
  52489. + if (!valid_page || len > limit) {
  52490. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52491. + return -EINVAL;
  52492. + }
  52493. +
  52494. + /* Store the mode data length */
  52495. + if (mscmnd == MODE_SENSE)
  52496. + buf0[0] = len - 1;
  52497. + else
  52498. + put_unaligned_be16(len - 2, buf0);
  52499. + return len;
  52500. +}
  52501. +
  52502. +
  52503. +static int do_start_stop(struct fsg_dev *fsg)
  52504. +{
  52505. + struct fsg_lun *curlun = fsg->curlun;
  52506. + int loej, start;
  52507. +
  52508. + if (!mod_data.removable) {
  52509. + curlun->sense_data = SS_INVALID_COMMAND;
  52510. + return -EINVAL;
  52511. + }
  52512. +
  52513. + // int immed = fsg->cmnd[1] & 0x01;
  52514. + loej = fsg->cmnd[4] & 0x02;
  52515. + start = fsg->cmnd[4] & 0x01;
  52516. +
  52517. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  52518. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  52519. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  52520. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52521. + return -EINVAL;
  52522. + }
  52523. +
  52524. + if (!start) {
  52525. +
  52526. + /* Are we allowed to unload the media? */
  52527. + if (curlun->prevent_medium_removal) {
  52528. + LDBG(curlun, "unload attempt prevented\n");
  52529. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  52530. + return -EINVAL;
  52531. + }
  52532. + if (loej) { // Simulate an unload/eject
  52533. + up_read(&fsg->filesem);
  52534. + down_write(&fsg->filesem);
  52535. + fsg_lun_close(curlun);
  52536. + up_write(&fsg->filesem);
  52537. + down_read(&fsg->filesem);
  52538. + }
  52539. + } else {
  52540. +
  52541. + /* Our emulation doesn't support mounting; the medium is
  52542. + * available for use as soon as it is loaded. */
  52543. + if (!fsg_lun_is_open(curlun)) {
  52544. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  52545. + return -EINVAL;
  52546. + }
  52547. + }
  52548. +#endif
  52549. + return 0;
  52550. +}
  52551. +
  52552. +
  52553. +static int do_prevent_allow(struct fsg_dev *fsg)
  52554. +{
  52555. + struct fsg_lun *curlun = fsg->curlun;
  52556. + int prevent;
  52557. +
  52558. + if (!mod_data.removable) {
  52559. + curlun->sense_data = SS_INVALID_COMMAND;
  52560. + return -EINVAL;
  52561. + }
  52562. +
  52563. + prevent = fsg->cmnd[4] & 0x01;
  52564. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  52565. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  52566. + return -EINVAL;
  52567. + }
  52568. +
  52569. + if (curlun->prevent_medium_removal && !prevent)
  52570. + fsg_lun_fsync_sub(curlun);
  52571. + curlun->prevent_medium_removal = prevent;
  52572. + return 0;
  52573. +}
  52574. +
  52575. +
  52576. +static int do_read_format_capacities(struct fsg_dev *fsg,
  52577. + struct fsg_buffhd *bh)
  52578. +{
  52579. + struct fsg_lun *curlun = fsg->curlun;
  52580. + u8 *buf = (u8 *) bh->buf;
  52581. +
  52582. + buf[0] = buf[1] = buf[2] = 0;
  52583. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  52584. + buf += 4;
  52585. +
  52586. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  52587. + /* Number of blocks */
  52588. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  52589. + buf[4] = 0x02; /* Current capacity */
  52590. + return 12;
  52591. +}
  52592. +
  52593. +
  52594. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  52595. +{
  52596. + struct fsg_lun *curlun = fsg->curlun;
  52597. +
  52598. + /* We don't support MODE SELECT */
  52599. + curlun->sense_data = SS_INVALID_COMMAND;
  52600. + return -EINVAL;
  52601. +}
  52602. +
  52603. +
  52604. +/*-------------------------------------------------------------------------*/
  52605. +
  52606. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  52607. +{
  52608. + int rc;
  52609. +
  52610. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  52611. + if (rc == -EAGAIN)
  52612. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  52613. + while (rc != 0) {
  52614. + if (rc != -EAGAIN) {
  52615. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  52616. + rc = 0;
  52617. + break;
  52618. + }
  52619. +
  52620. + /* Wait for a short time and then try again */
  52621. + if (msleep_interruptible(100) != 0)
  52622. + return -EINTR;
  52623. + rc = usb_ep_set_halt(fsg->bulk_in);
  52624. + }
  52625. + return rc;
  52626. +}
  52627. +
  52628. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  52629. +{
  52630. + int rc;
  52631. +
  52632. + DBG(fsg, "bulk-in set wedge\n");
  52633. + rc = usb_ep_set_wedge(fsg->bulk_in);
  52634. + if (rc == -EAGAIN)
  52635. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  52636. + while (rc != 0) {
  52637. + if (rc != -EAGAIN) {
  52638. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  52639. + rc = 0;
  52640. + break;
  52641. + }
  52642. +
  52643. + /* Wait for a short time and then try again */
  52644. + if (msleep_interruptible(100) != 0)
  52645. + return -EINTR;
  52646. + rc = usb_ep_set_wedge(fsg->bulk_in);
  52647. + }
  52648. + return rc;
  52649. +}
  52650. +
  52651. +static int throw_away_data(struct fsg_dev *fsg)
  52652. +{
  52653. + struct fsg_buffhd *bh;
  52654. + u32 amount;
  52655. + int rc;
  52656. +
  52657. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  52658. + fsg->usb_amount_left > 0) {
  52659. +
  52660. + /* Throw away the data in a filled buffer */
  52661. + if (bh->state == BUF_STATE_FULL) {
  52662. + smp_rmb();
  52663. + bh->state = BUF_STATE_EMPTY;
  52664. + fsg->next_buffhd_to_drain = bh->next;
  52665. +
  52666. + /* A short packet or an error ends everything */
  52667. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  52668. + bh->outreq->status != 0) {
  52669. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52670. + return -EINTR;
  52671. + }
  52672. + continue;
  52673. + }
  52674. +
  52675. + /* Try to submit another request if we need one */
  52676. + bh = fsg->next_buffhd_to_fill;
  52677. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  52678. + amount = min(fsg->usb_amount_left,
  52679. + (u32) mod_data.buflen);
  52680. +
  52681. + /* Except at the end of the transfer, amount will be
  52682. + * equal to the buffer size, which is divisible by
  52683. + * the bulk-out maxpacket size.
  52684. + */
  52685. + set_bulk_out_req_length(fsg, bh, amount);
  52686. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  52687. + &bh->outreq_busy, &bh->state);
  52688. + fsg->next_buffhd_to_fill = bh->next;
  52689. + fsg->usb_amount_left -= amount;
  52690. + continue;
  52691. + }
  52692. +
  52693. + /* Otherwise wait for something to happen */
  52694. + rc = sleep_thread(fsg);
  52695. + if (rc)
  52696. + return rc;
  52697. + }
  52698. + return 0;
  52699. +}
  52700. +
  52701. +
  52702. +static int finish_reply(struct fsg_dev *fsg)
  52703. +{
  52704. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  52705. + int rc = 0;
  52706. +
  52707. + switch (fsg->data_dir) {
  52708. + case DATA_DIR_NONE:
  52709. + break; // Nothing to send
  52710. +
  52711. + /* If we don't know whether the host wants to read or write,
  52712. + * this must be CB or CBI with an unknown command. We mustn't
  52713. + * try to send or receive any data. So stall both bulk pipes
  52714. + * if we can and wait for a reset. */
  52715. + case DATA_DIR_UNKNOWN:
  52716. + if (mod_data.can_stall) {
  52717. + fsg_set_halt(fsg, fsg->bulk_out);
  52718. + rc = halt_bulk_in_endpoint(fsg);
  52719. + }
  52720. + break;
  52721. +
  52722. + /* All but the last buffer of data must have already been sent */
  52723. + case DATA_DIR_TO_HOST:
  52724. + if (fsg->data_size == 0)
  52725. + ; // Nothing to send
  52726. +
  52727. + /* If there's no residue, simply send the last buffer */
  52728. + else if (fsg->residue == 0) {
  52729. + bh->inreq->zero = 0;
  52730. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52731. + &bh->inreq_busy, &bh->state);
  52732. + fsg->next_buffhd_to_fill = bh->next;
  52733. + }
  52734. +
  52735. + /* There is a residue. For CB and CBI, simply mark the end
  52736. + * of the data with a short packet. However, if we are
  52737. + * allowed to stall, there was no data at all (residue ==
  52738. + * data_size), and the command failed (invalid LUN or
  52739. + * sense data is set), then halt the bulk-in endpoint
  52740. + * instead. */
  52741. + else if (!transport_is_bbb()) {
  52742. + if (mod_data.can_stall &&
  52743. + fsg->residue == fsg->data_size &&
  52744. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  52745. + bh->state = BUF_STATE_EMPTY;
  52746. + rc = halt_bulk_in_endpoint(fsg);
  52747. + } else {
  52748. + bh->inreq->zero = 1;
  52749. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52750. + &bh->inreq_busy, &bh->state);
  52751. + fsg->next_buffhd_to_fill = bh->next;
  52752. + }
  52753. + }
  52754. +
  52755. + /*
  52756. + * For Bulk-only, mark the end of the data with a short
  52757. + * packet. If we are allowed to stall, halt the bulk-in
  52758. + * endpoint. (Note: This violates the Bulk-Only Transport
  52759. + * specification, which requires us to pad the data if we
  52760. + * don't halt the endpoint. Presumably nobody will mind.)
  52761. + */
  52762. + else {
  52763. + bh->inreq->zero = 1;
  52764. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52765. + &bh->inreq_busy, &bh->state);
  52766. + fsg->next_buffhd_to_fill = bh->next;
  52767. + if (mod_data.can_stall)
  52768. + rc = halt_bulk_in_endpoint(fsg);
  52769. + }
  52770. + break;
  52771. +
  52772. + /* We have processed all we want from the data the host has sent.
  52773. + * There may still be outstanding bulk-out requests. */
  52774. + case DATA_DIR_FROM_HOST:
  52775. + if (fsg->residue == 0)
  52776. + ; // Nothing to receive
  52777. +
  52778. + /* Did the host stop sending unexpectedly early? */
  52779. + else if (fsg->short_packet_received) {
  52780. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52781. + rc = -EINTR;
  52782. + }
  52783. +
  52784. + /* We haven't processed all the incoming data. Even though
  52785. + * we may be allowed to stall, doing so would cause a race.
  52786. + * The controller may already have ACK'ed all the remaining
  52787. + * bulk-out packets, in which case the host wouldn't see a
  52788. + * STALL. Not realizing the endpoint was halted, it wouldn't
  52789. + * clear the halt -- leading to problems later on. */
  52790. +#if 0
  52791. + else if (mod_data.can_stall) {
  52792. + fsg_set_halt(fsg, fsg->bulk_out);
  52793. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  52794. + rc = -EINTR;
  52795. + }
  52796. +#endif
  52797. +
  52798. + /* We can't stall. Read in the excess data and throw it
  52799. + * all away. */
  52800. + else
  52801. + rc = throw_away_data(fsg);
  52802. + break;
  52803. + }
  52804. + return rc;
  52805. +}
  52806. +
  52807. +
  52808. +static int send_status(struct fsg_dev *fsg)
  52809. +{
  52810. + struct fsg_lun *curlun = fsg->curlun;
  52811. + struct fsg_buffhd *bh;
  52812. + int rc;
  52813. + u8 status = US_BULK_STAT_OK;
  52814. + u32 sd, sdinfo = 0;
  52815. +
  52816. + /* Wait for the next buffer to become available */
  52817. + bh = fsg->next_buffhd_to_fill;
  52818. + while (bh->state != BUF_STATE_EMPTY) {
  52819. + rc = sleep_thread(fsg);
  52820. + if (rc)
  52821. + return rc;
  52822. + }
  52823. +
  52824. + if (curlun) {
  52825. + sd = curlun->sense_data;
  52826. + sdinfo = curlun->sense_data_info;
  52827. + } else if (fsg->bad_lun_okay)
  52828. + sd = SS_NO_SENSE;
  52829. + else
  52830. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  52831. +
  52832. + if (fsg->phase_error) {
  52833. + DBG(fsg, "sending phase-error status\n");
  52834. + status = US_BULK_STAT_PHASE;
  52835. + sd = SS_INVALID_COMMAND;
  52836. + } else if (sd != SS_NO_SENSE) {
  52837. + DBG(fsg, "sending command-failure status\n");
  52838. + status = US_BULK_STAT_FAIL;
  52839. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  52840. + " info x%x\n",
  52841. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  52842. + }
  52843. +
  52844. + if (transport_is_bbb()) {
  52845. + struct bulk_cs_wrap *csw = bh->buf;
  52846. +
  52847. + /* Store and send the Bulk-only CSW */
  52848. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  52849. + csw->Tag = fsg->tag;
  52850. + csw->Residue = cpu_to_le32(fsg->residue);
  52851. + csw->Status = status;
  52852. +
  52853. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  52854. + bh->inreq->zero = 0;
  52855. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  52856. + &bh->inreq_busy, &bh->state);
  52857. +
  52858. + } else if (mod_data.transport_type == USB_PR_CB) {
  52859. +
  52860. + /* Control-Bulk transport has no status phase! */
  52861. + return 0;
  52862. +
  52863. + } else { // USB_PR_CBI
  52864. + struct interrupt_data *buf = bh->buf;
  52865. +
  52866. + /* Store and send the Interrupt data. UFI sends the ASC
  52867. + * and ASCQ bytes. Everything else sends a Type (which
  52868. + * is always 0) and the status Value. */
  52869. + if (mod_data.protocol_type == USB_SC_UFI) {
  52870. + buf->bType = ASC(sd);
  52871. + buf->bValue = ASCQ(sd);
  52872. + } else {
  52873. + buf->bType = 0;
  52874. + buf->bValue = status;
  52875. + }
  52876. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  52877. +
  52878. + fsg->intr_buffhd = bh; // Point to the right buffhd
  52879. + fsg->intreq->buf = bh->inreq->buf;
  52880. + fsg->intreq->context = bh;
  52881. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  52882. + &fsg->intreq_busy, &bh->state);
  52883. + }
  52884. +
  52885. + fsg->next_buffhd_to_fill = bh->next;
  52886. + return 0;
  52887. +}
  52888. +
  52889. +
  52890. +/*-------------------------------------------------------------------------*/
  52891. +
  52892. +/* Check whether the command is properly formed and whether its data size
  52893. + * and direction agree with the values we already have. */
  52894. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  52895. + enum data_direction data_dir, unsigned int mask,
  52896. + int needs_medium, const char *name)
  52897. +{
  52898. + int i;
  52899. + int lun = fsg->cmnd[1] >> 5;
  52900. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  52901. + char hdlen[20];
  52902. + struct fsg_lun *curlun;
  52903. +
  52904. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  52905. + * Transparent SCSI doesn't pad. */
  52906. + if (protocol_is_scsi())
  52907. + ;
  52908. +
  52909. + /* There's some disagreement as to whether RBC pads commands or not.
  52910. + * We'll play it safe and accept either form. */
  52911. + else if (mod_data.protocol_type == USB_SC_RBC) {
  52912. + if (fsg->cmnd_size == 12)
  52913. + cmnd_size = 12;
  52914. +
  52915. + /* All the other protocols pad to 12 bytes */
  52916. + } else
  52917. + cmnd_size = 12;
  52918. +
  52919. + hdlen[0] = 0;
  52920. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  52921. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  52922. + fsg->data_size);
  52923. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  52924. + name, cmnd_size, dirletter[(int) data_dir],
  52925. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  52926. +
  52927. + /* We can't reply at all until we know the correct data direction
  52928. + * and size. */
  52929. + if (fsg->data_size_from_cmnd == 0)
  52930. + data_dir = DATA_DIR_NONE;
  52931. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  52932. + fsg->data_dir = data_dir;
  52933. + fsg->data_size = fsg->data_size_from_cmnd;
  52934. +
  52935. + } else { // Bulk-only
  52936. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  52937. +
  52938. + /* Host data size < Device data size is a phase error.
  52939. + * Carry out the command, but only transfer as much
  52940. + * as we are allowed. */
  52941. + fsg->data_size_from_cmnd = fsg->data_size;
  52942. + fsg->phase_error = 1;
  52943. + }
  52944. + }
  52945. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  52946. +
  52947. + /* Conflicting data directions is a phase error */
  52948. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  52949. + fsg->phase_error = 1;
  52950. + return -EINVAL;
  52951. + }
  52952. +
  52953. + /* Verify the length of the command itself */
  52954. + if (cmnd_size != fsg->cmnd_size) {
  52955. +
  52956. + /* Special case workaround: There are plenty of buggy SCSI
  52957. + * implementations. Many have issues with cbw->Length
  52958. + * field passing a wrong command size. For those cases we
  52959. + * always try to work around the problem by using the length
  52960. + * sent by the host side provided it is at least as large
  52961. + * as the correct command length.
  52962. + * Examples of such cases would be MS-Windows, which issues
  52963. + * REQUEST SENSE with cbw->Length == 12 where it should
  52964. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  52965. + * REQUEST SENSE with cbw->Length == 10 where it should
  52966. + * be 6 as well.
  52967. + */
  52968. + if (cmnd_size <= fsg->cmnd_size) {
  52969. + DBG(fsg, "%s is buggy! Expected length %d "
  52970. + "but we got %d\n", name,
  52971. + cmnd_size, fsg->cmnd_size);
  52972. + cmnd_size = fsg->cmnd_size;
  52973. + } else {
  52974. + fsg->phase_error = 1;
  52975. + return -EINVAL;
  52976. + }
  52977. + }
  52978. +
  52979. + /* Check that the LUN values are consistent */
  52980. + if (transport_is_bbb()) {
  52981. + if (fsg->lun != lun)
  52982. + DBG(fsg, "using LUN %d from CBW, "
  52983. + "not LUN %d from CDB\n",
  52984. + fsg->lun, lun);
  52985. + }
  52986. +
  52987. + /* Check the LUN */
  52988. + curlun = fsg->curlun;
  52989. + if (curlun) {
  52990. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  52991. + curlun->sense_data = SS_NO_SENSE;
  52992. + curlun->sense_data_info = 0;
  52993. + curlun->info_valid = 0;
  52994. + }
  52995. + } else {
  52996. + fsg->bad_lun_okay = 0;
  52997. +
  52998. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  52999. + * to use unsupported LUNs; all others may not. */
  53000. + if (fsg->cmnd[0] != INQUIRY &&
  53001. + fsg->cmnd[0] != REQUEST_SENSE) {
  53002. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  53003. + return -EINVAL;
  53004. + }
  53005. + }
  53006. +
  53007. + /* If a unit attention condition exists, only INQUIRY and
  53008. + * REQUEST SENSE commands are allowed; anything else must fail. */
  53009. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  53010. + fsg->cmnd[0] != INQUIRY &&
  53011. + fsg->cmnd[0] != REQUEST_SENSE) {
  53012. + curlun->sense_data = curlun->unit_attention_data;
  53013. + curlun->unit_attention_data = SS_NO_SENSE;
  53014. + return -EINVAL;
  53015. + }
  53016. +
  53017. + /* Check that only command bytes listed in the mask are non-zero */
  53018. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  53019. + for (i = 1; i < cmnd_size; ++i) {
  53020. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  53021. + if (curlun)
  53022. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  53023. + return -EINVAL;
  53024. + }
  53025. + }
  53026. +
  53027. + /* If the medium isn't mounted and the command needs to access
  53028. + * it, return an error. */
  53029. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  53030. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  53031. + return -EINVAL;
  53032. + }
  53033. +
  53034. + return 0;
  53035. +}
  53036. +
  53037. +/* wrapper of check_command for data size in blocks handling */
  53038. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  53039. + enum data_direction data_dir, unsigned int mask,
  53040. + int needs_medium, const char *name)
  53041. +{
  53042. + if (fsg->curlun)
  53043. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  53044. + return check_command(fsg, cmnd_size, data_dir,
  53045. + mask, needs_medium, name);
  53046. +}
  53047. +
  53048. +static int do_scsi_command(struct fsg_dev *fsg)
  53049. +{
  53050. + struct fsg_buffhd *bh;
  53051. + int rc;
  53052. + int reply = -EINVAL;
  53053. + int i;
  53054. + static char unknown[16];
  53055. +
  53056. + dump_cdb(fsg);
  53057. +
  53058. + /* Wait for the next buffer to become available for data or status */
  53059. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  53060. + while (bh->state != BUF_STATE_EMPTY) {
  53061. + rc = sleep_thread(fsg);
  53062. + if (rc)
  53063. + return rc;
  53064. + }
  53065. + fsg->phase_error = 0;
  53066. + fsg->short_packet_received = 0;
  53067. +
  53068. + down_read(&fsg->filesem); // We're using the backing file
  53069. + switch (fsg->cmnd[0]) {
  53070. +
  53071. + case INQUIRY:
  53072. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  53073. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  53074. + (1<<4), 0,
  53075. + "INQUIRY")) == 0)
  53076. + reply = do_inquiry(fsg, bh);
  53077. + break;
  53078. +
  53079. + case MODE_SELECT:
  53080. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  53081. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  53082. + (1<<1) | (1<<4), 0,
  53083. + "MODE SELECT(6)")) == 0)
  53084. + reply = do_mode_select(fsg, bh);
  53085. + break;
  53086. +
  53087. + case MODE_SELECT_10:
  53088. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53089. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  53090. + (1<<1) | (3<<7), 0,
  53091. + "MODE SELECT(10)")) == 0)
  53092. + reply = do_mode_select(fsg, bh);
  53093. + break;
  53094. +
  53095. + case MODE_SENSE:
  53096. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  53097. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  53098. + (1<<1) | (1<<2) | (1<<4), 0,
  53099. + "MODE SENSE(6)")) == 0)
  53100. + reply = do_mode_sense(fsg, bh);
  53101. + break;
  53102. +
  53103. + case MODE_SENSE_10:
  53104. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53105. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  53106. + (1<<1) | (1<<2) | (3<<7), 0,
  53107. + "MODE SENSE(10)")) == 0)
  53108. + reply = do_mode_sense(fsg, bh);
  53109. + break;
  53110. +
  53111. + case ALLOW_MEDIUM_REMOVAL:
  53112. + fsg->data_size_from_cmnd = 0;
  53113. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  53114. + (1<<4), 0,
  53115. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  53116. + reply = do_prevent_allow(fsg);
  53117. + break;
  53118. +
  53119. + case READ_6:
  53120. + i = fsg->cmnd[4];
  53121. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  53122. + if ((reply = check_command_size_in_blocks(fsg, 6,
  53123. + DATA_DIR_TO_HOST,
  53124. + (7<<1) | (1<<4), 1,
  53125. + "READ(6)")) == 0)
  53126. + reply = do_read(fsg);
  53127. + break;
  53128. +
  53129. + case READ_10:
  53130. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53131. + if ((reply = check_command_size_in_blocks(fsg, 10,
  53132. + DATA_DIR_TO_HOST,
  53133. + (1<<1) | (0xf<<2) | (3<<7), 1,
  53134. + "READ(10)")) == 0)
  53135. + reply = do_read(fsg);
  53136. + break;
  53137. +
  53138. + case READ_12:
  53139. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  53140. + if ((reply = check_command_size_in_blocks(fsg, 12,
  53141. + DATA_DIR_TO_HOST,
  53142. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  53143. + "READ(12)")) == 0)
  53144. + reply = do_read(fsg);
  53145. + break;
  53146. +
  53147. + case READ_CAPACITY:
  53148. + fsg->data_size_from_cmnd = 8;
  53149. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  53150. + (0xf<<2) | (1<<8), 1,
  53151. + "READ CAPACITY")) == 0)
  53152. + reply = do_read_capacity(fsg, bh);
  53153. + break;
  53154. +
  53155. + case READ_HEADER:
  53156. + if (!mod_data.cdrom)
  53157. + goto unknown_cmnd;
  53158. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53159. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  53160. + (3<<7) | (0x1f<<1), 1,
  53161. + "READ HEADER")) == 0)
  53162. + reply = do_read_header(fsg, bh);
  53163. + break;
  53164. +
  53165. + case READ_TOC:
  53166. + if (!mod_data.cdrom)
  53167. + goto unknown_cmnd;
  53168. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53169. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  53170. + (7<<6) | (1<<1), 1,
  53171. + "READ TOC")) == 0)
  53172. + reply = do_read_toc(fsg, bh);
  53173. + break;
  53174. +
  53175. + case READ_FORMAT_CAPACITIES:
  53176. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53177. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  53178. + (3<<7), 1,
  53179. + "READ FORMAT CAPACITIES")) == 0)
  53180. + reply = do_read_format_capacities(fsg, bh);
  53181. + break;
  53182. +
  53183. + case REQUEST_SENSE:
  53184. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  53185. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  53186. + (1<<4), 0,
  53187. + "REQUEST SENSE")) == 0)
  53188. + reply = do_request_sense(fsg, bh);
  53189. + break;
  53190. +
  53191. + case START_STOP:
  53192. + fsg->data_size_from_cmnd = 0;
  53193. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  53194. + (1<<1) | (1<<4), 0,
  53195. + "START-STOP UNIT")) == 0)
  53196. + reply = do_start_stop(fsg);
  53197. + break;
  53198. +
  53199. + case SYNCHRONIZE_CACHE:
  53200. + fsg->data_size_from_cmnd = 0;
  53201. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  53202. + (0xf<<2) | (3<<7), 1,
  53203. + "SYNCHRONIZE CACHE")) == 0)
  53204. + reply = do_synchronize_cache(fsg);
  53205. + break;
  53206. +
  53207. + case TEST_UNIT_READY:
  53208. + fsg->data_size_from_cmnd = 0;
  53209. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  53210. + 0, 1,
  53211. + "TEST UNIT READY");
  53212. + break;
  53213. +
  53214. + /* Although optional, this command is used by MS-Windows. We
  53215. + * support a minimal version: BytChk must be 0. */
  53216. + case VERIFY:
  53217. + fsg->data_size_from_cmnd = 0;
  53218. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  53219. + (1<<1) | (0xf<<2) | (3<<7), 1,
  53220. + "VERIFY")) == 0)
  53221. + reply = do_verify(fsg);
  53222. + break;
  53223. +
  53224. + case WRITE_6:
  53225. + i = fsg->cmnd[4];
  53226. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  53227. + if ((reply = check_command_size_in_blocks(fsg, 6,
  53228. + DATA_DIR_FROM_HOST,
  53229. + (7<<1) | (1<<4), 1,
  53230. + "WRITE(6)")) == 0)
  53231. + reply = do_write(fsg);
  53232. + break;
  53233. +
  53234. + case WRITE_10:
  53235. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  53236. + if ((reply = check_command_size_in_blocks(fsg, 10,
  53237. + DATA_DIR_FROM_HOST,
  53238. + (1<<1) | (0xf<<2) | (3<<7), 1,
  53239. + "WRITE(10)")) == 0)
  53240. + reply = do_write(fsg);
  53241. + break;
  53242. +
  53243. + case WRITE_12:
  53244. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  53245. + if ((reply = check_command_size_in_blocks(fsg, 12,
  53246. + DATA_DIR_FROM_HOST,
  53247. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  53248. + "WRITE(12)")) == 0)
  53249. + reply = do_write(fsg);
  53250. + break;
  53251. +
  53252. + /* Some mandatory commands that we recognize but don't implement.
  53253. + * They don't mean much in this setting. It's left as an exercise
  53254. + * for anyone interested to implement RESERVE and RELEASE in terms
  53255. + * of Posix locks. */
  53256. + case FORMAT_UNIT:
  53257. + case RELEASE:
  53258. + case RESERVE:
  53259. + case SEND_DIAGNOSTIC:
  53260. + // Fall through
  53261. +
  53262. + default:
  53263. + unknown_cmnd:
  53264. + fsg->data_size_from_cmnd = 0;
  53265. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  53266. + if ((reply = check_command(fsg, fsg->cmnd_size,
  53267. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  53268. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  53269. + reply = -EINVAL;
  53270. + }
  53271. + break;
  53272. + }
  53273. + up_read(&fsg->filesem);
  53274. +
  53275. + if (reply == -EINTR || signal_pending(current))
  53276. + return -EINTR;
  53277. +
  53278. + /* Set up the single reply buffer for finish_reply() */
  53279. + if (reply == -EINVAL)
  53280. + reply = 0; // Error reply length
  53281. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  53282. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  53283. + bh->inreq->length = reply;
  53284. + bh->state = BUF_STATE_FULL;
  53285. + fsg->residue -= reply;
  53286. + } // Otherwise it's already set
  53287. +
  53288. + return 0;
  53289. +}
  53290. +
  53291. +
  53292. +/*-------------------------------------------------------------------------*/
  53293. +
  53294. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  53295. +{
  53296. + struct usb_request *req = bh->outreq;
  53297. + struct bulk_cb_wrap *cbw = req->buf;
  53298. +
  53299. + /* Was this a real packet? Should it be ignored? */
  53300. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  53301. + return -EINVAL;
  53302. +
  53303. + /* Is the CBW valid? */
  53304. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  53305. + cbw->Signature != cpu_to_le32(
  53306. + US_BULK_CB_SIGN)) {
  53307. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  53308. + req->actual,
  53309. + le32_to_cpu(cbw->Signature));
  53310. +
  53311. + /* The Bulk-only spec says we MUST stall the IN endpoint
  53312. + * (6.6.1), so it's unavoidable. It also says we must
  53313. + * retain this state until the next reset, but there's
  53314. + * no way to tell the controller driver it should ignore
  53315. + * Clear-Feature(HALT) requests.
  53316. + *
  53317. + * We aren't required to halt the OUT endpoint; instead
  53318. + * we can simply accept and discard any data received
  53319. + * until the next reset. */
  53320. + wedge_bulk_in_endpoint(fsg);
  53321. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  53322. + return -EINVAL;
  53323. + }
  53324. +
  53325. + /* Is the CBW meaningful? */
  53326. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  53327. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  53328. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  53329. + "cmdlen %u\n",
  53330. + cbw->Lun, cbw->Flags, cbw->Length);
  53331. +
  53332. + /* We can do anything we want here, so let's stall the
  53333. + * bulk pipes if we are allowed to. */
  53334. + if (mod_data.can_stall) {
  53335. + fsg_set_halt(fsg, fsg->bulk_out);
  53336. + halt_bulk_in_endpoint(fsg);
  53337. + }
  53338. + return -EINVAL;
  53339. + }
  53340. +
  53341. + /* Save the command for later */
  53342. + fsg->cmnd_size = cbw->Length;
  53343. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  53344. + if (cbw->Flags & US_BULK_FLAG_IN)
  53345. + fsg->data_dir = DATA_DIR_TO_HOST;
  53346. + else
  53347. + fsg->data_dir = DATA_DIR_FROM_HOST;
  53348. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  53349. + if (fsg->data_size == 0)
  53350. + fsg->data_dir = DATA_DIR_NONE;
  53351. + fsg->lun = cbw->Lun;
  53352. + fsg->tag = cbw->Tag;
  53353. + return 0;
  53354. +}
  53355. +
  53356. +
  53357. +static int get_next_command(struct fsg_dev *fsg)
  53358. +{
  53359. + struct fsg_buffhd *bh;
  53360. + int rc = 0;
  53361. +
  53362. + if (transport_is_bbb()) {
  53363. +
  53364. + /* Wait for the next buffer to become available */
  53365. + bh = fsg->next_buffhd_to_fill;
  53366. + while (bh->state != BUF_STATE_EMPTY) {
  53367. + rc = sleep_thread(fsg);
  53368. + if (rc)
  53369. + return rc;
  53370. + }
  53371. +
  53372. + /* Queue a request to read a Bulk-only CBW */
  53373. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  53374. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  53375. + &bh->outreq_busy, &bh->state);
  53376. +
  53377. + /* We will drain the buffer in software, which means we
  53378. + * can reuse it for the next filling. No need to advance
  53379. + * next_buffhd_to_fill. */
  53380. +
  53381. + /* Wait for the CBW to arrive */
  53382. + while (bh->state != BUF_STATE_FULL) {
  53383. + rc = sleep_thread(fsg);
  53384. + if (rc)
  53385. + return rc;
  53386. + }
  53387. + smp_rmb();
  53388. + rc = received_cbw(fsg, bh);
  53389. + bh->state = BUF_STATE_EMPTY;
  53390. +
  53391. + } else { // USB_PR_CB or USB_PR_CBI
  53392. +
  53393. + /* Wait for the next command to arrive */
  53394. + while (fsg->cbbuf_cmnd_size == 0) {
  53395. + rc = sleep_thread(fsg);
  53396. + if (rc)
  53397. + return rc;
  53398. + }
  53399. +
  53400. + /* Is the previous status interrupt request still busy?
  53401. + * The host is allowed to skip reading the status,
  53402. + * so we must cancel it. */
  53403. + if (fsg->intreq_busy)
  53404. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  53405. +
  53406. + /* Copy the command and mark the buffer empty */
  53407. + fsg->data_dir = DATA_DIR_UNKNOWN;
  53408. + spin_lock_irq(&fsg->lock);
  53409. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  53410. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  53411. + fsg->cbbuf_cmnd_size = 0;
  53412. + spin_unlock_irq(&fsg->lock);
  53413. +
  53414. + /* Use LUN from the command */
  53415. + fsg->lun = fsg->cmnd[1] >> 5;
  53416. + }
  53417. +
  53418. + /* Update current lun */
  53419. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  53420. + fsg->curlun = &fsg->luns[fsg->lun];
  53421. + else
  53422. + fsg->curlun = NULL;
  53423. +
  53424. + return rc;
  53425. +}
  53426. +
  53427. +
  53428. +/*-------------------------------------------------------------------------*/
  53429. +
  53430. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  53431. + const struct usb_endpoint_descriptor *d)
  53432. +{
  53433. + int rc;
  53434. +
  53435. + ep->driver_data = fsg;
  53436. + ep->desc = d;
  53437. + rc = usb_ep_enable(ep);
  53438. + if (rc)
  53439. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  53440. + return rc;
  53441. +}
  53442. +
  53443. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  53444. + struct usb_request **preq)
  53445. +{
  53446. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  53447. + if (*preq)
  53448. + return 0;
  53449. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  53450. + return -ENOMEM;
  53451. +}
  53452. +
  53453. +/*
  53454. + * Reset interface setting and re-init endpoint state (toggle etc).
  53455. + * Call with altsetting < 0 to disable the interface. The only other
  53456. + * available altsetting is 0, which enables the interface.
  53457. + */
  53458. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  53459. +{
  53460. + int rc = 0;
  53461. + int i;
  53462. + const struct usb_endpoint_descriptor *d;
  53463. +
  53464. + if (fsg->running)
  53465. + DBG(fsg, "reset interface\n");
  53466. +
  53467. +reset:
  53468. + /* Deallocate the requests */
  53469. + for (i = 0; i < fsg_num_buffers; ++i) {
  53470. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  53471. +
  53472. + if (bh->inreq) {
  53473. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  53474. + bh->inreq = NULL;
  53475. + }
  53476. + if (bh->outreq) {
  53477. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  53478. + bh->outreq = NULL;
  53479. + }
  53480. + }
  53481. + if (fsg->intreq) {
  53482. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  53483. + fsg->intreq = NULL;
  53484. + }
  53485. +
  53486. + /* Disable the endpoints */
  53487. + if (fsg->bulk_in_enabled) {
  53488. + usb_ep_disable(fsg->bulk_in);
  53489. + fsg->bulk_in_enabled = 0;
  53490. + }
  53491. + if (fsg->bulk_out_enabled) {
  53492. + usb_ep_disable(fsg->bulk_out);
  53493. + fsg->bulk_out_enabled = 0;
  53494. + }
  53495. + if (fsg->intr_in_enabled) {
  53496. + usb_ep_disable(fsg->intr_in);
  53497. + fsg->intr_in_enabled = 0;
  53498. + }
  53499. +
  53500. + fsg->running = 0;
  53501. + if (altsetting < 0 || rc != 0)
  53502. + return rc;
  53503. +
  53504. + DBG(fsg, "set interface %d\n", altsetting);
  53505. +
  53506. + /* Enable the endpoints */
  53507. + d = fsg_ep_desc(fsg->gadget,
  53508. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  53509. + &fsg_ss_bulk_in_desc);
  53510. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  53511. + goto reset;
  53512. + fsg->bulk_in_enabled = 1;
  53513. +
  53514. + d = fsg_ep_desc(fsg->gadget,
  53515. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  53516. + &fsg_ss_bulk_out_desc);
  53517. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  53518. + goto reset;
  53519. + fsg->bulk_out_enabled = 1;
  53520. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  53521. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  53522. +
  53523. + if (transport_is_cbi()) {
  53524. + d = fsg_ep_desc(fsg->gadget,
  53525. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  53526. + &fsg_ss_intr_in_desc);
  53527. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  53528. + goto reset;
  53529. + fsg->intr_in_enabled = 1;
  53530. + }
  53531. +
  53532. + /* Allocate the requests */
  53533. + for (i = 0; i < fsg_num_buffers; ++i) {
  53534. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  53535. +
  53536. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  53537. + goto reset;
  53538. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  53539. + goto reset;
  53540. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  53541. + bh->inreq->context = bh->outreq->context = bh;
  53542. + bh->inreq->complete = bulk_in_complete;
  53543. + bh->outreq->complete = bulk_out_complete;
  53544. + }
  53545. + if (transport_is_cbi()) {
  53546. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  53547. + goto reset;
  53548. + fsg->intreq->complete = intr_in_complete;
  53549. + }
  53550. +
  53551. + fsg->running = 1;
  53552. + for (i = 0; i < fsg->nluns; ++i)
  53553. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  53554. + return rc;
  53555. +}
  53556. +
  53557. +
  53558. +/*
  53559. + * Change our operational configuration. This code must agree with the code
  53560. + * that returns config descriptors, and with interface altsetting code.
  53561. + *
  53562. + * It's also responsible for power management interactions. Some
  53563. + * configurations might not work with our current power sources.
  53564. + * For now we just assume the gadget is always self-powered.
  53565. + */
  53566. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  53567. +{
  53568. + int rc = 0;
  53569. +
  53570. + /* Disable the single interface */
  53571. + if (fsg->config != 0) {
  53572. + DBG(fsg, "reset config\n");
  53573. + fsg->config = 0;
  53574. + rc = do_set_interface(fsg, -1);
  53575. + }
  53576. +
  53577. + /* Enable the interface */
  53578. + if (new_config != 0) {
  53579. + fsg->config = new_config;
  53580. + if ((rc = do_set_interface(fsg, 0)) != 0)
  53581. + fsg->config = 0; // Reset on errors
  53582. + else
  53583. + INFO(fsg, "%s config #%d\n",
  53584. + usb_speed_string(fsg->gadget->speed),
  53585. + fsg->config);
  53586. + }
  53587. + return rc;
  53588. +}
  53589. +
  53590. +
  53591. +/*-------------------------------------------------------------------------*/
  53592. +
  53593. +static void handle_exception(struct fsg_dev *fsg)
  53594. +{
  53595. + siginfo_t info;
  53596. + int sig;
  53597. + int i;
  53598. + int num_active;
  53599. + struct fsg_buffhd *bh;
  53600. + enum fsg_state old_state;
  53601. + u8 new_config;
  53602. + struct fsg_lun *curlun;
  53603. + unsigned int exception_req_tag;
  53604. + int rc;
  53605. +
  53606. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  53607. + * into a high-priority EXIT exception. */
  53608. + for (;;) {
  53609. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  53610. + if (!sig)
  53611. + break;
  53612. + if (sig != SIGUSR1) {
  53613. + if (fsg->state < FSG_STATE_EXIT)
  53614. + DBG(fsg, "Main thread exiting on signal\n");
  53615. + raise_exception(fsg, FSG_STATE_EXIT);
  53616. + }
  53617. + }
  53618. +
  53619. + /* Cancel all the pending transfers */
  53620. + if (fsg->intreq_busy)
  53621. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  53622. + for (i = 0; i < fsg_num_buffers; ++i) {
  53623. + bh = &fsg->buffhds[i];
  53624. + if (bh->inreq_busy)
  53625. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  53626. + if (bh->outreq_busy)
  53627. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  53628. + }
  53629. +
  53630. + /* Wait until everything is idle */
  53631. + for (;;) {
  53632. + num_active = fsg->intreq_busy;
  53633. + for (i = 0; i < fsg_num_buffers; ++i) {
  53634. + bh = &fsg->buffhds[i];
  53635. + num_active += bh->inreq_busy + bh->outreq_busy;
  53636. + }
  53637. + if (num_active == 0)
  53638. + break;
  53639. + if (sleep_thread(fsg))
  53640. + return;
  53641. + }
  53642. +
  53643. + /* Clear out the controller's fifos */
  53644. + if (fsg->bulk_in_enabled)
  53645. + usb_ep_fifo_flush(fsg->bulk_in);
  53646. + if (fsg->bulk_out_enabled)
  53647. + usb_ep_fifo_flush(fsg->bulk_out);
  53648. + if (fsg->intr_in_enabled)
  53649. + usb_ep_fifo_flush(fsg->intr_in);
  53650. +
  53651. + /* Reset the I/O buffer states and pointers, the SCSI
  53652. + * state, and the exception. Then invoke the handler. */
  53653. + spin_lock_irq(&fsg->lock);
  53654. +
  53655. + for (i = 0; i < fsg_num_buffers; ++i) {
  53656. + bh = &fsg->buffhds[i];
  53657. + bh->state = BUF_STATE_EMPTY;
  53658. + }
  53659. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  53660. + &fsg->buffhds[0];
  53661. +
  53662. + exception_req_tag = fsg->exception_req_tag;
  53663. + new_config = fsg->new_config;
  53664. + old_state = fsg->state;
  53665. +
  53666. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  53667. + fsg->state = FSG_STATE_STATUS_PHASE;
  53668. + else {
  53669. + for (i = 0; i < fsg->nluns; ++i) {
  53670. + curlun = &fsg->luns[i];
  53671. + curlun->prevent_medium_removal = 0;
  53672. + curlun->sense_data = curlun->unit_attention_data =
  53673. + SS_NO_SENSE;
  53674. + curlun->sense_data_info = 0;
  53675. + curlun->info_valid = 0;
  53676. + }
  53677. + fsg->state = FSG_STATE_IDLE;
  53678. + }
  53679. + spin_unlock_irq(&fsg->lock);
  53680. +
  53681. + /* Carry out any extra actions required for the exception */
  53682. + switch (old_state) {
  53683. + default:
  53684. + break;
  53685. +
  53686. + case FSG_STATE_ABORT_BULK_OUT:
  53687. + send_status(fsg);
  53688. + spin_lock_irq(&fsg->lock);
  53689. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  53690. + fsg->state = FSG_STATE_IDLE;
  53691. + spin_unlock_irq(&fsg->lock);
  53692. + break;
  53693. +
  53694. + case FSG_STATE_RESET:
  53695. + /* In case we were forced against our will to halt a
  53696. + * bulk endpoint, clear the halt now. (The SuperH UDC
  53697. + * requires this.) */
  53698. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  53699. + usb_ep_clear_halt(fsg->bulk_in);
  53700. +
  53701. + if (transport_is_bbb()) {
  53702. + if (fsg->ep0_req_tag == exception_req_tag)
  53703. + ep0_queue(fsg); // Complete the status stage
  53704. +
  53705. + } else if (transport_is_cbi())
  53706. + send_status(fsg); // Status by interrupt pipe
  53707. +
  53708. + /* Technically this should go here, but it would only be
  53709. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  53710. + * CONFIG_CHANGE cases. */
  53711. + // for (i = 0; i < fsg->nluns; ++i)
  53712. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  53713. + break;
  53714. +
  53715. + case FSG_STATE_INTERFACE_CHANGE:
  53716. + rc = do_set_interface(fsg, 0);
  53717. + if (fsg->ep0_req_tag != exception_req_tag)
  53718. + break;
  53719. + if (rc != 0) // STALL on errors
  53720. + fsg_set_halt(fsg, fsg->ep0);
  53721. + else // Complete the status stage
  53722. + ep0_queue(fsg);
  53723. + break;
  53724. +
  53725. + case FSG_STATE_CONFIG_CHANGE:
  53726. + rc = do_set_config(fsg, new_config);
  53727. + if (fsg->ep0_req_tag != exception_req_tag)
  53728. + break;
  53729. + if (rc != 0) // STALL on errors
  53730. + fsg_set_halt(fsg, fsg->ep0);
  53731. + else // Complete the status stage
  53732. + ep0_queue(fsg);
  53733. + break;
  53734. +
  53735. + case FSG_STATE_DISCONNECT:
  53736. + for (i = 0; i < fsg->nluns; ++i)
  53737. + fsg_lun_fsync_sub(fsg->luns + i);
  53738. + do_set_config(fsg, 0); // Unconfigured state
  53739. + break;
  53740. +
  53741. + case FSG_STATE_EXIT:
  53742. + case FSG_STATE_TERMINATED:
  53743. + do_set_config(fsg, 0); // Free resources
  53744. + spin_lock_irq(&fsg->lock);
  53745. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  53746. + spin_unlock_irq(&fsg->lock);
  53747. + break;
  53748. + }
  53749. +}
  53750. +
  53751. +
  53752. +/*-------------------------------------------------------------------------*/
  53753. +
  53754. +static int fsg_main_thread(void *fsg_)
  53755. +{
  53756. + struct fsg_dev *fsg = fsg_;
  53757. +
  53758. + /* Allow the thread to be killed by a signal, but set the signal mask
  53759. + * to block everything but INT, TERM, KILL, and USR1. */
  53760. + allow_signal(SIGINT);
  53761. + allow_signal(SIGTERM);
  53762. + allow_signal(SIGKILL);
  53763. + allow_signal(SIGUSR1);
  53764. +
  53765. + /* Allow the thread to be frozen */
  53766. + set_freezable();
  53767. +
  53768. + /* Arrange for userspace references to be interpreted as kernel
  53769. + * pointers. That way we can pass a kernel pointer to a routine
  53770. + * that expects a __user pointer and it will work okay. */
  53771. + set_fs(get_ds());
  53772. +
  53773. + /* The main loop */
  53774. + while (fsg->state != FSG_STATE_TERMINATED) {
  53775. + if (exception_in_progress(fsg) || signal_pending(current)) {
  53776. + handle_exception(fsg);
  53777. + continue;
  53778. + }
  53779. +
  53780. + if (!fsg->running) {
  53781. + sleep_thread(fsg);
  53782. + continue;
  53783. + }
  53784. +
  53785. + if (get_next_command(fsg))
  53786. + continue;
  53787. +
  53788. + spin_lock_irq(&fsg->lock);
  53789. + if (!exception_in_progress(fsg))
  53790. + fsg->state = FSG_STATE_DATA_PHASE;
  53791. + spin_unlock_irq(&fsg->lock);
  53792. +
  53793. + if (do_scsi_command(fsg) || finish_reply(fsg))
  53794. + continue;
  53795. +
  53796. + spin_lock_irq(&fsg->lock);
  53797. + if (!exception_in_progress(fsg))
  53798. + fsg->state = FSG_STATE_STATUS_PHASE;
  53799. + spin_unlock_irq(&fsg->lock);
  53800. +
  53801. + if (send_status(fsg))
  53802. + continue;
  53803. +
  53804. + spin_lock_irq(&fsg->lock);
  53805. + if (!exception_in_progress(fsg))
  53806. + fsg->state = FSG_STATE_IDLE;
  53807. + spin_unlock_irq(&fsg->lock);
  53808. + }
  53809. +
  53810. + spin_lock_irq(&fsg->lock);
  53811. + fsg->thread_task = NULL;
  53812. + spin_unlock_irq(&fsg->lock);
  53813. +
  53814. + /* If we are exiting because of a signal, unregister the
  53815. + * gadget driver. */
  53816. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  53817. + usb_gadget_unregister_driver(&fsg_driver);
  53818. +
  53819. + /* Let the unbind and cleanup routines know the thread has exited */
  53820. + complete_and_exit(&fsg->thread_notifier, 0);
  53821. +}
  53822. +
  53823. +
  53824. +/*-------------------------------------------------------------------------*/
  53825. +
  53826. +
  53827. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  53828. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  53829. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  53830. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  53831. +
  53832. +
  53833. +/*-------------------------------------------------------------------------*/
  53834. +
  53835. +static void fsg_release(struct kref *ref)
  53836. +{
  53837. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  53838. +
  53839. + kfree(fsg->luns);
  53840. + kfree(fsg);
  53841. +}
  53842. +
  53843. +static void lun_release(struct device *dev)
  53844. +{
  53845. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  53846. + struct fsg_dev *fsg =
  53847. + container_of(filesem, struct fsg_dev, filesem);
  53848. +
  53849. + kref_put(&fsg->ref, fsg_release);
  53850. +}
  53851. +
  53852. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  53853. +{
  53854. + struct fsg_dev *fsg = get_gadget_data(gadget);
  53855. + int i;
  53856. + struct fsg_lun *curlun;
  53857. + struct usb_request *req = fsg->ep0req;
  53858. +
  53859. + DBG(fsg, "unbind\n");
  53860. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  53861. +
  53862. + /* If the thread isn't already dead, tell it to exit now */
  53863. + if (fsg->state != FSG_STATE_TERMINATED) {
  53864. + raise_exception(fsg, FSG_STATE_EXIT);
  53865. + wait_for_completion(&fsg->thread_notifier);
  53866. +
  53867. + /* The cleanup routine waits for this completion also */
  53868. + complete(&fsg->thread_notifier);
  53869. + }
  53870. +
  53871. + /* Unregister the sysfs attribute files and the LUNs */
  53872. + for (i = 0; i < fsg->nluns; ++i) {
  53873. + curlun = &fsg->luns[i];
  53874. + if (curlun->registered) {
  53875. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  53876. + device_remove_file(&curlun->dev, &dev_attr_ro);
  53877. + device_remove_file(&curlun->dev, &dev_attr_file);
  53878. + fsg_lun_close(curlun);
  53879. + device_unregister(&curlun->dev);
  53880. + curlun->registered = 0;
  53881. + }
  53882. + }
  53883. +
  53884. + /* Free the data buffers */
  53885. + for (i = 0; i < fsg_num_buffers; ++i)
  53886. + kfree(fsg->buffhds[i].buf);
  53887. +
  53888. + /* Free the request and buffer for endpoint 0 */
  53889. + if (req) {
  53890. + kfree(req->buf);
  53891. + usb_ep_free_request(fsg->ep0, req);
  53892. + }
  53893. +
  53894. + set_gadget_data(gadget, NULL);
  53895. +}
  53896. +
  53897. +
  53898. +static int __init check_parameters(struct fsg_dev *fsg)
  53899. +{
  53900. + int prot;
  53901. + int gcnum;
  53902. +
  53903. + /* Store the default values */
  53904. + mod_data.transport_type = USB_PR_BULK;
  53905. + mod_data.transport_name = "Bulk-only";
  53906. + mod_data.protocol_type = USB_SC_SCSI;
  53907. + mod_data.protocol_name = "Transparent SCSI";
  53908. +
  53909. + /* Some peripheral controllers are known not to be able to
  53910. + * halt bulk endpoints correctly. If one of them is present,
  53911. + * disable stalls.
  53912. + */
  53913. + if (gadget_is_at91(fsg->gadget))
  53914. + mod_data.can_stall = 0;
  53915. +
  53916. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  53917. + gcnum = usb_gadget_controller_number(fsg->gadget);
  53918. + if (gcnum >= 0)
  53919. + mod_data.release = 0x0300 + gcnum;
  53920. + else {
  53921. + WARNING(fsg, "controller '%s' not recognized\n",
  53922. + fsg->gadget->name);
  53923. + mod_data.release = 0x0399;
  53924. + }
  53925. + }
  53926. +
  53927. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  53928. +
  53929. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  53930. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  53931. + ; // Use default setting
  53932. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  53933. + mod_data.transport_type = USB_PR_CB;
  53934. + mod_data.transport_name = "Control-Bulk";
  53935. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  53936. + mod_data.transport_type = USB_PR_CBI;
  53937. + mod_data.transport_name = "Control-Bulk-Interrupt";
  53938. + } else {
  53939. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  53940. + return -EINVAL;
  53941. + }
  53942. +
  53943. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  53944. + prot == USB_SC_SCSI) {
  53945. + ; // Use default setting
  53946. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  53947. + prot == USB_SC_RBC) {
  53948. + mod_data.protocol_type = USB_SC_RBC;
  53949. + mod_data.protocol_name = "RBC";
  53950. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  53951. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  53952. + prot == USB_SC_8020) {
  53953. + mod_data.protocol_type = USB_SC_8020;
  53954. + mod_data.protocol_name = "8020i (ATAPI)";
  53955. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  53956. + prot == USB_SC_QIC) {
  53957. + mod_data.protocol_type = USB_SC_QIC;
  53958. + mod_data.protocol_name = "QIC-157";
  53959. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  53960. + prot == USB_SC_UFI) {
  53961. + mod_data.protocol_type = USB_SC_UFI;
  53962. + mod_data.protocol_name = "UFI";
  53963. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  53964. + prot == USB_SC_8070) {
  53965. + mod_data.protocol_type = USB_SC_8070;
  53966. + mod_data.protocol_name = "8070i";
  53967. + } else {
  53968. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  53969. + return -EINVAL;
  53970. + }
  53971. +
  53972. + mod_data.buflen &= PAGE_CACHE_MASK;
  53973. + if (mod_data.buflen <= 0) {
  53974. + ERROR(fsg, "invalid buflen\n");
  53975. + return -ETOOSMALL;
  53976. + }
  53977. +
  53978. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  53979. +
  53980. + /* Serial string handling.
  53981. + * On a real device, the serial string would be loaded
  53982. + * from permanent storage. */
  53983. + if (mod_data.serial) {
  53984. + const char *ch;
  53985. + unsigned len = 0;
  53986. +
  53987. + /* Sanity check :
  53988. + * The CB[I] specification limits the serial string to
  53989. + * 12 uppercase hexadecimal characters.
  53990. + * BBB need at least 12 uppercase hexadecimal characters,
  53991. + * with a maximum of 126. */
  53992. + for (ch = mod_data.serial; *ch; ++ch) {
  53993. + ++len;
  53994. + if ((*ch < '0' || *ch > '9') &&
  53995. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  53996. + WARNING(fsg,
  53997. + "Invalid serial string character: %c\n",
  53998. + *ch);
  53999. + goto no_serial;
  54000. + }
  54001. + }
  54002. + if (len > 126 ||
  54003. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  54004. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  54005. + WARNING(fsg, "Invalid serial string length!\n");
  54006. + goto no_serial;
  54007. + }
  54008. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  54009. + } else {
  54010. + WARNING(fsg, "No serial-number string provided!\n");
  54011. + no_serial:
  54012. + device_desc.iSerialNumber = 0;
  54013. + }
  54014. +
  54015. + return 0;
  54016. +}
  54017. +
  54018. +
  54019. +static int __init fsg_bind(struct usb_gadget *gadget)
  54020. +{
  54021. + struct fsg_dev *fsg = the_fsg;
  54022. + int rc;
  54023. + int i;
  54024. + struct fsg_lun *curlun;
  54025. + struct usb_ep *ep;
  54026. + struct usb_request *req;
  54027. + char *pathbuf, *p;
  54028. +
  54029. + fsg->gadget = gadget;
  54030. + set_gadget_data(gadget, fsg);
  54031. + fsg->ep0 = gadget->ep0;
  54032. + fsg->ep0->driver_data = fsg;
  54033. +
  54034. + if ((rc = check_parameters(fsg)) != 0)
  54035. + goto out;
  54036. +
  54037. + if (mod_data.removable) { // Enable the store_xxx attributes
  54038. + dev_attr_file.attr.mode = 0644;
  54039. + dev_attr_file.store = fsg_store_file;
  54040. + if (!mod_data.cdrom) {
  54041. + dev_attr_ro.attr.mode = 0644;
  54042. + dev_attr_ro.store = fsg_store_ro;
  54043. + }
  54044. + }
  54045. +
  54046. + /* Only for removable media? */
  54047. + dev_attr_nofua.attr.mode = 0644;
  54048. + dev_attr_nofua.store = fsg_store_nofua;
  54049. +
  54050. + /* Find out how many LUNs there should be */
  54051. + i = mod_data.nluns;
  54052. + if (i == 0)
  54053. + i = max(mod_data.num_filenames, 1u);
  54054. + if (i > FSG_MAX_LUNS) {
  54055. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  54056. + rc = -EINVAL;
  54057. + goto out;
  54058. + }
  54059. +
  54060. + /* Create the LUNs, open their backing files, and register the
  54061. + * LUN devices in sysfs. */
  54062. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  54063. + if (!fsg->luns) {
  54064. + rc = -ENOMEM;
  54065. + goto out;
  54066. + }
  54067. + fsg->nluns = i;
  54068. +
  54069. + for (i = 0; i < fsg->nluns; ++i) {
  54070. + curlun = &fsg->luns[i];
  54071. + curlun->cdrom = !!mod_data.cdrom;
  54072. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  54073. + curlun->initially_ro = curlun->ro;
  54074. + curlun->removable = mod_data.removable;
  54075. + curlun->nofua = mod_data.nofua[i];
  54076. + curlun->dev.release = lun_release;
  54077. + curlun->dev.parent = &gadget->dev;
  54078. + curlun->dev.driver = &fsg_driver.driver;
  54079. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  54080. + dev_set_name(&curlun->dev,"%s-lun%d",
  54081. + dev_name(&gadget->dev), i);
  54082. +
  54083. + kref_get(&fsg->ref);
  54084. + rc = device_register(&curlun->dev);
  54085. + if (rc) {
  54086. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  54087. + put_device(&curlun->dev);
  54088. + goto out;
  54089. + }
  54090. + curlun->registered = 1;
  54091. +
  54092. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  54093. + if (rc)
  54094. + goto out;
  54095. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  54096. + if (rc)
  54097. + goto out;
  54098. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  54099. + if (rc)
  54100. + goto out;
  54101. +
  54102. + if (mod_data.file[i] && *mod_data.file[i]) {
  54103. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  54104. + if (rc)
  54105. + goto out;
  54106. + } else if (!mod_data.removable) {
  54107. + ERROR(fsg, "no file given for LUN%d\n", i);
  54108. + rc = -EINVAL;
  54109. + goto out;
  54110. + }
  54111. + }
  54112. +
  54113. + /* Find all the endpoints we will use */
  54114. + usb_ep_autoconfig_reset(gadget);
  54115. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  54116. + if (!ep)
  54117. + goto autoconf_fail;
  54118. + ep->driver_data = fsg; // claim the endpoint
  54119. + fsg->bulk_in = ep;
  54120. +
  54121. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  54122. + if (!ep)
  54123. + goto autoconf_fail;
  54124. + ep->driver_data = fsg; // claim the endpoint
  54125. + fsg->bulk_out = ep;
  54126. +
  54127. + if (transport_is_cbi()) {
  54128. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  54129. + if (!ep)
  54130. + goto autoconf_fail;
  54131. + ep->driver_data = fsg; // claim the endpoint
  54132. + fsg->intr_in = ep;
  54133. + }
  54134. +
  54135. + /* Fix up the descriptors */
  54136. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  54137. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  54138. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  54139. +
  54140. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  54141. + fsg_intf_desc.bNumEndpoints = i;
  54142. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  54143. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  54144. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  54145. +
  54146. + if (gadget_is_dualspeed(gadget)) {
  54147. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  54148. +
  54149. + /* Assume endpoint addresses are the same for both speeds */
  54150. + fsg_hs_bulk_in_desc.bEndpointAddress =
  54151. + fsg_fs_bulk_in_desc.bEndpointAddress;
  54152. + fsg_hs_bulk_out_desc.bEndpointAddress =
  54153. + fsg_fs_bulk_out_desc.bEndpointAddress;
  54154. + fsg_hs_intr_in_desc.bEndpointAddress =
  54155. + fsg_fs_intr_in_desc.bEndpointAddress;
  54156. + }
  54157. +
  54158. + if (gadget_is_superspeed(gadget)) {
  54159. + unsigned max_burst;
  54160. +
  54161. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  54162. +
  54163. + /* Calculate bMaxBurst, we know packet size is 1024 */
  54164. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  54165. +
  54166. + /* Assume endpoint addresses are the same for both speeds */
  54167. + fsg_ss_bulk_in_desc.bEndpointAddress =
  54168. + fsg_fs_bulk_in_desc.bEndpointAddress;
  54169. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  54170. +
  54171. + fsg_ss_bulk_out_desc.bEndpointAddress =
  54172. + fsg_fs_bulk_out_desc.bEndpointAddress;
  54173. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  54174. + }
  54175. +
  54176. + if (gadget_is_otg(gadget))
  54177. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  54178. +
  54179. + rc = -ENOMEM;
  54180. +
  54181. + /* Allocate the request and buffer for endpoint 0 */
  54182. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  54183. + if (!req)
  54184. + goto out;
  54185. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  54186. + if (!req->buf)
  54187. + goto out;
  54188. + req->complete = ep0_complete;
  54189. +
  54190. + /* Allocate the data buffers */
  54191. + for (i = 0; i < fsg_num_buffers; ++i) {
  54192. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  54193. +
  54194. + /* Allocate for the bulk-in endpoint. We assume that
  54195. + * the buffer will also work with the bulk-out (and
  54196. + * interrupt-in) endpoint. */
  54197. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  54198. + if (!bh->buf)
  54199. + goto out;
  54200. + bh->next = bh + 1;
  54201. + }
  54202. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  54203. +
  54204. + /* This should reflect the actual gadget power source */
  54205. + usb_gadget_set_selfpowered(gadget);
  54206. +
  54207. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  54208. + "%s %s with %s",
  54209. + init_utsname()->sysname, init_utsname()->release,
  54210. + gadget->name);
  54211. +
  54212. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  54213. + "file-storage-gadget");
  54214. + if (IS_ERR(fsg->thread_task)) {
  54215. + rc = PTR_ERR(fsg->thread_task);
  54216. + goto out;
  54217. + }
  54218. +
  54219. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  54220. + INFO(fsg, "NOTE: This driver is deprecated. "
  54221. + "Consider using g_mass_storage instead.\n");
  54222. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  54223. +
  54224. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  54225. + for (i = 0; i < fsg->nluns; ++i) {
  54226. + curlun = &fsg->luns[i];
  54227. + if (fsg_lun_is_open(curlun)) {
  54228. + p = NULL;
  54229. + if (pathbuf) {
  54230. + p = d_path(&curlun->filp->f_path,
  54231. + pathbuf, PATH_MAX);
  54232. + if (IS_ERR(p))
  54233. + p = NULL;
  54234. + }
  54235. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  54236. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  54237. + }
  54238. + }
  54239. + kfree(pathbuf);
  54240. +
  54241. + DBG(fsg, "transport=%s (x%02x)\n",
  54242. + mod_data.transport_name, mod_data.transport_type);
  54243. + DBG(fsg, "protocol=%s (x%02x)\n",
  54244. + mod_data.protocol_name, mod_data.protocol_type);
  54245. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  54246. + mod_data.vendor, mod_data.product, mod_data.release);
  54247. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  54248. + mod_data.removable, mod_data.can_stall,
  54249. + mod_data.cdrom, mod_data.buflen);
  54250. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  54251. +
  54252. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  54253. +
  54254. + /* Tell the thread to start working */
  54255. + wake_up_process(fsg->thread_task);
  54256. + return 0;
  54257. +
  54258. +autoconf_fail:
  54259. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  54260. + rc = -ENOTSUPP;
  54261. +
  54262. +out:
  54263. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  54264. + fsg_unbind(gadget);
  54265. + complete(&fsg->thread_notifier);
  54266. + return rc;
  54267. +}
  54268. +
  54269. +
  54270. +/*-------------------------------------------------------------------------*/
  54271. +
  54272. +static void fsg_suspend(struct usb_gadget *gadget)
  54273. +{
  54274. + struct fsg_dev *fsg = get_gadget_data(gadget);
  54275. +
  54276. + DBG(fsg, "suspend\n");
  54277. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  54278. +}
  54279. +
  54280. +static void fsg_resume(struct usb_gadget *gadget)
  54281. +{
  54282. + struct fsg_dev *fsg = get_gadget_data(gadget);
  54283. +
  54284. + DBG(fsg, "resume\n");
  54285. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  54286. +}
  54287. +
  54288. +
  54289. +/*-------------------------------------------------------------------------*/
  54290. +
  54291. +static struct usb_gadget_driver fsg_driver = {
  54292. + .max_speed = USB_SPEED_SUPER,
  54293. + .function = (char *) fsg_string_product,
  54294. + .unbind = fsg_unbind,
  54295. + .disconnect = fsg_disconnect,
  54296. + .setup = fsg_setup,
  54297. + .suspend = fsg_suspend,
  54298. + .resume = fsg_resume,
  54299. +
  54300. + .driver = {
  54301. + .name = DRIVER_NAME,
  54302. + .owner = THIS_MODULE,
  54303. + // .release = ...
  54304. + // .suspend = ...
  54305. + // .resume = ...
  54306. + },
  54307. +};
  54308. +
  54309. +
  54310. +static int __init fsg_alloc(void)
  54311. +{
  54312. + struct fsg_dev *fsg;
  54313. +
  54314. + fsg = kzalloc(sizeof *fsg +
  54315. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  54316. +
  54317. + if (!fsg)
  54318. + return -ENOMEM;
  54319. + spin_lock_init(&fsg->lock);
  54320. + init_rwsem(&fsg->filesem);
  54321. + kref_init(&fsg->ref);
  54322. + init_completion(&fsg->thread_notifier);
  54323. +
  54324. + the_fsg = fsg;
  54325. + return 0;
  54326. +}
  54327. +
  54328. +
  54329. +static int __init fsg_init(void)
  54330. +{
  54331. + int rc;
  54332. + struct fsg_dev *fsg;
  54333. +
  54334. + rc = fsg_num_buffers_validate();
  54335. + if (rc != 0)
  54336. + return rc;
  54337. +
  54338. + if ((rc = fsg_alloc()) != 0)
  54339. + return rc;
  54340. + fsg = the_fsg;
  54341. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  54342. + kref_put(&fsg->ref, fsg_release);
  54343. + return rc;
  54344. +}
  54345. +module_init(fsg_init);
  54346. +
  54347. +
  54348. +static void __exit fsg_cleanup(void)
  54349. +{
  54350. + struct fsg_dev *fsg = the_fsg;
  54351. +
  54352. + /* Unregister the driver iff the thread hasn't already done so */
  54353. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  54354. + usb_gadget_unregister_driver(&fsg_driver);
  54355. +
  54356. + /* Wait for the thread to finish up */
  54357. + wait_for_completion(&fsg->thread_notifier);
  54358. +
  54359. + kref_put(&fsg->ref, fsg_release);
  54360. +}
  54361. +module_exit(fsg_cleanup);
  54362. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  54363. --- linux-3.12.38/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  54364. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2015-03-09 10:39:33.214893718 +0100
  54365. @@ -0,0 +1,174 @@
  54366. +
  54367. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  54368. +IO context struct. The IO context struct should live in an os-dependent struct
  54369. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  54370. +named 'os_dep' embedded in the main device struct. So there these calls look
  54371. +like this:
  54372. +
  54373. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  54374. +
  54375. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  54376. + &pcd->dev_global_regs->dcfg, 0);
  54377. +
  54378. +Note that for the existing Linux driver ports, it is not necessary to actually
  54379. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  54380. +require an IO context, its macros for dwc_read_reg32() and friends do not
  54381. +use the context pointer, so it is optimized away by the compiler. But it is
  54382. +necessary to add the pointer parameter to all of the call sites, to be ready
  54383. +for any future ports (such as FreeBSD) which do require an IO context.
  54384. +
  54385. +
  54386. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  54387. +take an additional parameter, a pointer to a memory context. Examples:
  54388. +
  54389. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  54390. +
  54391. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  54392. +
  54393. +Again, for the Linux ports, it is not necessary to actually define the memctx
  54394. +member, but it is necessary to add the pointer parameter to all of the call
  54395. +sites.
  54396. +
  54397. +
  54398. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  54399. +
  54400. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  54401. +
  54402. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  54403. +
  54404. +
  54405. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  54406. +
  54407. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  54408. +
  54409. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  54410. +
  54411. +
  54412. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  54413. +
  54414. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  54415. +
  54416. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  54417. +
  54418. +
  54419. +Same for dwc_timer_alloc(). Example:
  54420. +
  54421. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  54422. + cb_func, cb_data);
  54423. +
  54424. +
  54425. +Same for dwc_waitq_alloc(). Example:
  54426. +
  54427. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  54428. +
  54429. +
  54430. +Same for dwc_thread_run(). Example:
  54431. +
  54432. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  54433. + "dwc_usb3_thd1", data);
  54434. +
  54435. +
  54436. +Same for dwc_workq_alloc(). Example:
  54437. +
  54438. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  54439. +
  54440. +
  54441. +Same for dwc_task_alloc(). Example:
  54442. +
  54443. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  54444. + cb_func, cb_data);
  54445. +
  54446. +
  54447. +In addition to the context pointer additions, a few core functions have had
  54448. +other changes made to their parameters:
  54449. +
  54450. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  54451. +has been changed from a uint64_t to a dwc_irqflags_t.
  54452. +
  54453. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  54454. +FreeBSD equivalent of that function requires it.
  54455. +
  54456. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  54457. +'char *name' parameter, to be consistent with dwc_thread_run() and
  54458. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  54459. +requires a unique name.
  54460. +
  54461. +
  54462. +Here is a complete list of the core functions that now take a pointer to a
  54463. +context as their first parameter:
  54464. +
  54465. + dwc_read_reg32
  54466. + dwc_read_reg64
  54467. + dwc_write_reg32
  54468. + dwc_write_reg64
  54469. + dwc_modify_reg32
  54470. + dwc_modify_reg64
  54471. + dwc_alloc
  54472. + dwc_alloc_atomic
  54473. + dwc_strdup
  54474. + dwc_free
  54475. + dwc_dma_alloc
  54476. + dwc_dma_free
  54477. + dwc_mutex_alloc
  54478. + dwc_mutex_free
  54479. + dwc_spinlock_alloc
  54480. + dwc_spinlock_free
  54481. + dwc_timer_alloc
  54482. + dwc_waitq_alloc
  54483. + dwc_thread_run
  54484. + dwc_workq_alloc
  54485. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  54486. +
  54487. +And here are the core functions that have other changes to their parameters:
  54488. +
  54489. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  54490. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  54491. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  54492. +
  54493. +
  54494. +
  54495. +The changes to the core functions also require some of the other library
  54496. +functions to change:
  54497. +
  54498. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  54499. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  54500. + (for mutex allocation) as the 2nd param.
  54501. +
  54502. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  54503. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  54504. + 'void *memctx' as the 1st param.
  54505. +
  54506. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  54507. + 'void *memctx' as the 1st param.
  54508. +
  54509. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  54510. +
  54511. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  54512. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  54513. + param, and also now returns an integer value that is non-zero if
  54514. + allocation of its data structures or work queue fails.
  54515. +
  54516. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  54517. +
  54518. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  54519. + param, and also now returns an integer value that is non-zero if
  54520. + allocation of its data structures fails.
  54521. +
  54522. +
  54523. +
  54524. +Other miscellaneous changes:
  54525. +
  54526. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  54527. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  54528. +
  54529. +The following #define's have been added to allow selectively compiling library
  54530. +features:
  54531. +
  54532. + DWC_CCLIB
  54533. + DWC_CRYPTOLIB
  54534. + DWC_NOTIFYLIB
  54535. + DWC_UTFLIB
  54536. +
  54537. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  54538. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  54539. +library code directly into a driver module, instead of as a standalone module.
  54540. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  54541. --- linux-3.12.38/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  54542. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2015-03-09 10:39:33.214893718 +0100
  54543. @@ -0,0 +1,270 @@
  54544. +# Doxyfile 1.4.5
  54545. +
  54546. +#---------------------------------------------------------------------------
  54547. +# Project related configuration options
  54548. +#---------------------------------------------------------------------------
  54549. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  54550. +PROJECT_NUMBER =
  54551. +OUTPUT_DIRECTORY = doc
  54552. +CREATE_SUBDIRS = NO
  54553. +OUTPUT_LANGUAGE = English
  54554. +BRIEF_MEMBER_DESC = YES
  54555. +REPEAT_BRIEF = YES
  54556. +ABBREVIATE_BRIEF = "The $name class" \
  54557. + "The $name widget" \
  54558. + "The $name file" \
  54559. + is \
  54560. + provides \
  54561. + specifies \
  54562. + contains \
  54563. + represents \
  54564. + a \
  54565. + an \
  54566. + the
  54567. +ALWAYS_DETAILED_SEC = YES
  54568. +INLINE_INHERITED_MEMB = NO
  54569. +FULL_PATH_NAMES = NO
  54570. +STRIP_FROM_PATH = ..
  54571. +STRIP_FROM_INC_PATH =
  54572. +SHORT_NAMES = NO
  54573. +JAVADOC_AUTOBRIEF = YES
  54574. +MULTILINE_CPP_IS_BRIEF = NO
  54575. +DETAILS_AT_TOP = YES
  54576. +INHERIT_DOCS = YES
  54577. +SEPARATE_MEMBER_PAGES = NO
  54578. +TAB_SIZE = 8
  54579. +ALIASES =
  54580. +OPTIMIZE_OUTPUT_FOR_C = YES
  54581. +OPTIMIZE_OUTPUT_JAVA = NO
  54582. +BUILTIN_STL_SUPPORT = NO
  54583. +DISTRIBUTE_GROUP_DOC = NO
  54584. +SUBGROUPING = NO
  54585. +#---------------------------------------------------------------------------
  54586. +# Build related configuration options
  54587. +#---------------------------------------------------------------------------
  54588. +EXTRACT_ALL = NO
  54589. +EXTRACT_PRIVATE = NO
  54590. +EXTRACT_STATIC = YES
  54591. +EXTRACT_LOCAL_CLASSES = NO
  54592. +EXTRACT_LOCAL_METHODS = NO
  54593. +HIDE_UNDOC_MEMBERS = NO
  54594. +HIDE_UNDOC_CLASSES = NO
  54595. +HIDE_FRIEND_COMPOUNDS = NO
  54596. +HIDE_IN_BODY_DOCS = NO
  54597. +INTERNAL_DOCS = NO
  54598. +CASE_SENSE_NAMES = YES
  54599. +HIDE_SCOPE_NAMES = NO
  54600. +SHOW_INCLUDE_FILES = NO
  54601. +INLINE_INFO = YES
  54602. +SORT_MEMBER_DOCS = NO
  54603. +SORT_BRIEF_DOCS = NO
  54604. +SORT_BY_SCOPE_NAME = NO
  54605. +GENERATE_TODOLIST = YES
  54606. +GENERATE_TESTLIST = YES
  54607. +GENERATE_BUGLIST = YES
  54608. +GENERATE_DEPRECATEDLIST= YES
  54609. +ENABLED_SECTIONS =
  54610. +MAX_INITIALIZER_LINES = 30
  54611. +SHOW_USED_FILES = YES
  54612. +SHOW_DIRECTORIES = YES
  54613. +FILE_VERSION_FILTER =
  54614. +#---------------------------------------------------------------------------
  54615. +# configuration options related to warning and progress messages
  54616. +#---------------------------------------------------------------------------
  54617. +QUIET = YES
  54618. +WARNINGS = YES
  54619. +WARN_IF_UNDOCUMENTED = NO
  54620. +WARN_IF_DOC_ERROR = YES
  54621. +WARN_NO_PARAMDOC = YES
  54622. +WARN_FORMAT = "$file:$line: $text"
  54623. +WARN_LOGFILE =
  54624. +#---------------------------------------------------------------------------
  54625. +# configuration options related to the input files
  54626. +#---------------------------------------------------------------------------
  54627. +INPUT = .
  54628. +FILE_PATTERNS = *.c \
  54629. + *.cc \
  54630. + *.cxx \
  54631. + *.cpp \
  54632. + *.c++ \
  54633. + *.d \
  54634. + *.java \
  54635. + *.ii \
  54636. + *.ixx \
  54637. + *.ipp \
  54638. + *.i++ \
  54639. + *.inl \
  54640. + *.h \
  54641. + *.hh \
  54642. + *.hxx \
  54643. + *.hpp \
  54644. + *.h++ \
  54645. + *.idl \
  54646. + *.odl \
  54647. + *.cs \
  54648. + *.php \
  54649. + *.php3 \
  54650. + *.inc \
  54651. + *.m \
  54652. + *.mm \
  54653. + *.dox \
  54654. + *.py \
  54655. + *.C \
  54656. + *.CC \
  54657. + *.C++ \
  54658. + *.II \
  54659. + *.I++ \
  54660. + *.H \
  54661. + *.HH \
  54662. + *.H++ \
  54663. + *.CS \
  54664. + *.PHP \
  54665. + *.PHP3 \
  54666. + *.M \
  54667. + *.MM \
  54668. + *.PY
  54669. +RECURSIVE = NO
  54670. +EXCLUDE =
  54671. +EXCLUDE_SYMLINKS = NO
  54672. +EXCLUDE_PATTERNS =
  54673. +EXAMPLE_PATH =
  54674. +EXAMPLE_PATTERNS = *
  54675. +EXAMPLE_RECURSIVE = NO
  54676. +IMAGE_PATH =
  54677. +INPUT_FILTER =
  54678. +FILTER_PATTERNS =
  54679. +FILTER_SOURCE_FILES = NO
  54680. +#---------------------------------------------------------------------------
  54681. +# configuration options related to source browsing
  54682. +#---------------------------------------------------------------------------
  54683. +SOURCE_BROWSER = NO
  54684. +INLINE_SOURCES = NO
  54685. +STRIP_CODE_COMMENTS = YES
  54686. +REFERENCED_BY_RELATION = YES
  54687. +REFERENCES_RELATION = YES
  54688. +USE_HTAGS = NO
  54689. +VERBATIM_HEADERS = NO
  54690. +#---------------------------------------------------------------------------
  54691. +# configuration options related to the alphabetical class index
  54692. +#---------------------------------------------------------------------------
  54693. +ALPHABETICAL_INDEX = NO
  54694. +COLS_IN_ALPHA_INDEX = 5
  54695. +IGNORE_PREFIX =
  54696. +#---------------------------------------------------------------------------
  54697. +# configuration options related to the HTML output
  54698. +#---------------------------------------------------------------------------
  54699. +GENERATE_HTML = YES
  54700. +HTML_OUTPUT = html
  54701. +HTML_FILE_EXTENSION = .html
  54702. +HTML_HEADER =
  54703. +HTML_FOOTER =
  54704. +HTML_STYLESHEET =
  54705. +HTML_ALIGN_MEMBERS = YES
  54706. +GENERATE_HTMLHELP = NO
  54707. +CHM_FILE =
  54708. +HHC_LOCATION =
  54709. +GENERATE_CHI = NO
  54710. +BINARY_TOC = NO
  54711. +TOC_EXPAND = NO
  54712. +DISABLE_INDEX = NO
  54713. +ENUM_VALUES_PER_LINE = 4
  54714. +GENERATE_TREEVIEW = YES
  54715. +TREEVIEW_WIDTH = 250
  54716. +#---------------------------------------------------------------------------
  54717. +# configuration options related to the LaTeX output
  54718. +#---------------------------------------------------------------------------
  54719. +GENERATE_LATEX = NO
  54720. +LATEX_OUTPUT = latex
  54721. +LATEX_CMD_NAME = latex
  54722. +MAKEINDEX_CMD_NAME = makeindex
  54723. +COMPACT_LATEX = NO
  54724. +PAPER_TYPE = a4wide
  54725. +EXTRA_PACKAGES =
  54726. +LATEX_HEADER =
  54727. +PDF_HYPERLINKS = NO
  54728. +USE_PDFLATEX = NO
  54729. +LATEX_BATCHMODE = NO
  54730. +LATEX_HIDE_INDICES = NO
  54731. +#---------------------------------------------------------------------------
  54732. +# configuration options related to the RTF output
  54733. +#---------------------------------------------------------------------------
  54734. +GENERATE_RTF = NO
  54735. +RTF_OUTPUT = rtf
  54736. +COMPACT_RTF = NO
  54737. +RTF_HYPERLINKS = NO
  54738. +RTF_STYLESHEET_FILE =
  54739. +RTF_EXTENSIONS_FILE =
  54740. +#---------------------------------------------------------------------------
  54741. +# configuration options related to the man page output
  54742. +#---------------------------------------------------------------------------
  54743. +GENERATE_MAN = NO
  54744. +MAN_OUTPUT = man
  54745. +MAN_EXTENSION = .3
  54746. +MAN_LINKS = NO
  54747. +#---------------------------------------------------------------------------
  54748. +# configuration options related to the XML output
  54749. +#---------------------------------------------------------------------------
  54750. +GENERATE_XML = NO
  54751. +XML_OUTPUT = xml
  54752. +XML_SCHEMA =
  54753. +XML_DTD =
  54754. +XML_PROGRAMLISTING = YES
  54755. +#---------------------------------------------------------------------------
  54756. +# configuration options for the AutoGen Definitions output
  54757. +#---------------------------------------------------------------------------
  54758. +GENERATE_AUTOGEN_DEF = NO
  54759. +#---------------------------------------------------------------------------
  54760. +# configuration options related to the Perl module output
  54761. +#---------------------------------------------------------------------------
  54762. +GENERATE_PERLMOD = NO
  54763. +PERLMOD_LATEX = NO
  54764. +PERLMOD_PRETTY = YES
  54765. +PERLMOD_MAKEVAR_PREFIX =
  54766. +#---------------------------------------------------------------------------
  54767. +# Configuration options related to the preprocessor
  54768. +#---------------------------------------------------------------------------
  54769. +ENABLE_PREPROCESSING = YES
  54770. +MACRO_EXPANSION = NO
  54771. +EXPAND_ONLY_PREDEF = NO
  54772. +SEARCH_INCLUDES = YES
  54773. +INCLUDE_PATH =
  54774. +INCLUDE_FILE_PATTERNS =
  54775. +PREDEFINED = DEBUG DEBUG_MEMORY
  54776. +EXPAND_AS_DEFINED =
  54777. +SKIP_FUNCTION_MACROS = YES
  54778. +#---------------------------------------------------------------------------
  54779. +# Configuration::additions related to external references
  54780. +#---------------------------------------------------------------------------
  54781. +TAGFILES =
  54782. +GENERATE_TAGFILE =
  54783. +ALLEXTERNALS = NO
  54784. +EXTERNAL_GROUPS = YES
  54785. +PERL_PATH = /usr/bin/perl
  54786. +#---------------------------------------------------------------------------
  54787. +# Configuration options related to the dot tool
  54788. +#---------------------------------------------------------------------------
  54789. +CLASS_DIAGRAMS = YES
  54790. +HIDE_UNDOC_RELATIONS = YES
  54791. +HAVE_DOT = NO
  54792. +CLASS_GRAPH = YES
  54793. +COLLABORATION_GRAPH = YES
  54794. +GROUP_GRAPHS = YES
  54795. +UML_LOOK = NO
  54796. +TEMPLATE_RELATIONS = NO
  54797. +INCLUDE_GRAPH = NO
  54798. +INCLUDED_BY_GRAPH = YES
  54799. +CALL_GRAPH = NO
  54800. +GRAPHICAL_HIERARCHY = YES
  54801. +DIRECTORY_GRAPH = YES
  54802. +DOT_IMAGE_FORMAT = png
  54803. +DOT_PATH =
  54804. +DOTFILE_DIRS =
  54805. +MAX_DOT_GRAPH_DEPTH = 1000
  54806. +DOT_TRANSPARENT = NO
  54807. +DOT_MULTI_TARGETS = NO
  54808. +GENERATE_LEGEND = YES
  54809. +DOT_CLEANUP = YES
  54810. +#---------------------------------------------------------------------------
  54811. +# Configuration::additions related to the search engine
  54812. +#---------------------------------------------------------------------------
  54813. +SEARCHENGINE = NO
  54814. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  54815. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  54816. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2015-03-09 10:39:33.214893718 +0100
  54817. @@ -0,0 +1,532 @@
  54818. +/* =========================================================================
  54819. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  54820. + * $Revision: #4 $
  54821. + * $Date: 2010/11/04 $
  54822. + * $Change: 1621692 $
  54823. + *
  54824. + * Synopsys Portability Library Software and documentation
  54825. + * (hereinafter, "Software") is an Unsupported proprietary work of
  54826. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  54827. + * between Synopsys and you.
  54828. + *
  54829. + * The Software IS NOT an item of Licensed Software or Licensed Product
  54830. + * under any End User Software License Agreement or Agreement for
  54831. + * Licensed Product with Synopsys or any supplement thereto. You are
  54832. + * permitted to use and redistribute this Software in source and binary
  54833. + * forms, with or without modification, provided that redistributions
  54834. + * of source code must retain this notice. You may not view, use,
  54835. + * disclose, copy or distribute this file or any information contained
  54836. + * herein except pursuant to this license grant from Synopsys. If you
  54837. + * do not agree with this notice, including the disclaimer below, then
  54838. + * you are not authorized to use the Software.
  54839. + *
  54840. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  54841. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  54842. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  54843. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  54844. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54845. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54846. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  54847. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  54848. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54849. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  54850. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54851. + * DAMAGE.
  54852. + * ========================================================================= */
  54853. +#ifdef DWC_CCLIB
  54854. +
  54855. +#include "dwc_cc.h"
  54856. +
  54857. +typedef struct dwc_cc
  54858. +{
  54859. + uint32_t uid;
  54860. + uint8_t chid[16];
  54861. + uint8_t cdid[16];
  54862. + uint8_t ck[16];
  54863. + uint8_t *name;
  54864. + uint8_t length;
  54865. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  54866. +} dwc_cc_t;
  54867. +
  54868. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  54869. +
  54870. +/** The main structure for CC management. */
  54871. +struct dwc_cc_if
  54872. +{
  54873. + dwc_mutex_t *mutex;
  54874. + char *filename;
  54875. +
  54876. + unsigned is_host:1;
  54877. +
  54878. + dwc_notifier_t *notifier;
  54879. +
  54880. + struct context_list list;
  54881. +};
  54882. +
  54883. +#ifdef DEBUG
  54884. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  54885. +{
  54886. + int i;
  54887. + DWC_PRINTF("%s: ", name);
  54888. + for (i=0; i<len; i++) {
  54889. + DWC_PRINTF("%02x ", bytes[i]);
  54890. + }
  54891. + DWC_PRINTF("\n");
  54892. +}
  54893. +#else
  54894. +#define dump_bytes(x...)
  54895. +#endif
  54896. +
  54897. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  54898. +{
  54899. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  54900. + if (!cc) {
  54901. + return NULL;
  54902. + }
  54903. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  54904. +
  54905. + if (name) {
  54906. + cc->length = length;
  54907. + cc->name = dwc_alloc(mem_ctx, length);
  54908. + if (!cc->name) {
  54909. + dwc_free(mem_ctx, cc);
  54910. + return NULL;
  54911. + }
  54912. +
  54913. + DWC_MEMCPY(cc->name, name, length);
  54914. + }
  54915. +
  54916. + return cc;
  54917. +}
  54918. +
  54919. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  54920. +{
  54921. + if (cc->name) {
  54922. + dwc_free(mem_ctx, cc->name);
  54923. + }
  54924. + dwc_free(mem_ctx, cc);
  54925. +}
  54926. +
  54927. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  54928. +{
  54929. + uint32_t uid = 0;
  54930. + dwc_cc_t *cc;
  54931. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54932. + if (cc->uid > uid) {
  54933. + uid = cc->uid;
  54934. + }
  54935. + }
  54936. +
  54937. + if (uid == 0) {
  54938. + uid = 255;
  54939. + }
  54940. +
  54941. + return uid + 1;
  54942. +}
  54943. +
  54944. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  54945. +{
  54946. + dwc_cc_t *cc;
  54947. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54948. + if (cc->uid == uid) {
  54949. + return cc;
  54950. + }
  54951. + }
  54952. + return NULL;
  54953. +}
  54954. +
  54955. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  54956. +{
  54957. + unsigned int size = 0;
  54958. + dwc_cc_t *cc;
  54959. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54960. + size += (48 + 1);
  54961. + if (cc->name) {
  54962. + size += cc->length;
  54963. + }
  54964. + }
  54965. + return size;
  54966. +}
  54967. +
  54968. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  54969. +{
  54970. + uint32_t uid = 0;
  54971. + dwc_cc_t *cc;
  54972. +
  54973. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54974. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  54975. + uid = cc->uid;
  54976. + break;
  54977. + }
  54978. + }
  54979. + return uid;
  54980. +}
  54981. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  54982. +{
  54983. + uint32_t uid = 0;
  54984. + dwc_cc_t *cc;
  54985. +
  54986. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  54987. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  54988. + uid = cc->uid;
  54989. + break;
  54990. + }
  54991. + }
  54992. + return uid;
  54993. +}
  54994. +
  54995. +/* Internal cc_add */
  54996. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  54997. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  54998. +{
  54999. + dwc_cc_t *cc;
  55000. + uint32_t uid;
  55001. +
  55002. + if (cc_if->is_host) {
  55003. + uid = cc_match_cdid(cc_if, cdid);
  55004. + }
  55005. + else {
  55006. + uid = cc_match_chid(cc_if, chid);
  55007. + }
  55008. +
  55009. + if (uid) {
  55010. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  55011. + cc = cc_find(cc_if, uid);
  55012. + }
  55013. + else {
  55014. + cc = alloc_cc(mem_ctx, name, length);
  55015. + cc->uid = next_uid(cc_if);
  55016. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  55017. + }
  55018. +
  55019. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  55020. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  55021. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  55022. +
  55023. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  55024. + dump_bytes("CHID", cc->chid, 16);
  55025. + dump_bytes("CDID", cc->cdid, 16);
  55026. + dump_bytes("CK", cc->ck, 16);
  55027. + return cc->uid;
  55028. +}
  55029. +
  55030. +/* Internal cc_clear */
  55031. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  55032. +{
  55033. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  55034. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  55035. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  55036. + free_cc(mem_ctx, cc);
  55037. + }
  55038. +}
  55039. +
  55040. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  55041. + dwc_notifier_t *notifier, unsigned is_host)
  55042. +{
  55043. + dwc_cc_if_t *cc_if = NULL;
  55044. +
  55045. + /* Allocate a common_cc_if structure */
  55046. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  55047. +
  55048. + if (!cc_if)
  55049. + return NULL;
  55050. +
  55051. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  55052. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  55053. +#else
  55054. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  55055. +#endif
  55056. + if (!cc_if->mutex) {
  55057. + dwc_free(mem_ctx, cc_if);
  55058. + return NULL;
  55059. + }
  55060. +
  55061. + DWC_CIRCLEQ_INIT(&cc_if->list);
  55062. + cc_if->is_host = is_host;
  55063. + cc_if->notifier = notifier;
  55064. + return cc_if;
  55065. +}
  55066. +
  55067. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  55068. +{
  55069. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  55070. + DWC_MUTEX_FREE(cc_if->mutex);
  55071. +#else
  55072. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  55073. +#endif
  55074. + cc_clear(mem_ctx, cc_if);
  55075. + dwc_free(mem_ctx, cc_if);
  55076. +}
  55077. +
  55078. +static void cc_changed(dwc_cc_if_t *cc_if)
  55079. +{
  55080. + if (cc_if->notifier) {
  55081. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  55082. + }
  55083. +}
  55084. +
  55085. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  55086. +{
  55087. + DWC_MUTEX_LOCK(cc_if->mutex);
  55088. + cc_clear(mem_ctx, cc_if);
  55089. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55090. + cc_changed(cc_if);
  55091. +}
  55092. +
  55093. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  55094. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  55095. +{
  55096. + uint32_t uid;
  55097. +
  55098. + DWC_MUTEX_LOCK(cc_if->mutex);
  55099. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  55100. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55101. + cc_changed(cc_if);
  55102. +
  55103. + return uid;
  55104. +}
  55105. +
  55106. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  55107. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  55108. +{
  55109. + dwc_cc_t* cc;
  55110. +
  55111. + DWC_DEBUGC("Change connection context %d", id);
  55112. +
  55113. + DWC_MUTEX_LOCK(cc_if->mutex);
  55114. + cc = cc_find(cc_if, id);
  55115. + if (!cc) {
  55116. + DWC_ERROR("Uid %d not found in cc list\n", id);
  55117. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55118. + return;
  55119. + }
  55120. +
  55121. + if (chid) {
  55122. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  55123. + }
  55124. + if (cdid) {
  55125. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  55126. + }
  55127. + if (ck) {
  55128. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  55129. + }
  55130. +
  55131. + if (name) {
  55132. + if (cc->name) {
  55133. + dwc_free(mem_ctx, cc->name);
  55134. + }
  55135. + cc->name = dwc_alloc(mem_ctx, length);
  55136. + if (!cc->name) {
  55137. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  55138. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55139. + return;
  55140. + }
  55141. + cc->length = length;
  55142. + DWC_MEMCPY(cc->name, name, length);
  55143. + }
  55144. +
  55145. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55146. +
  55147. + cc_changed(cc_if);
  55148. +
  55149. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  55150. + dump_bytes("New CHID", cc->chid, 16);
  55151. + dump_bytes("New CDID", cc->cdid, 16);
  55152. + dump_bytes("New CK", cc->ck, 16);
  55153. +}
  55154. +
  55155. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  55156. +{
  55157. + dwc_cc_t *cc;
  55158. +
  55159. + DWC_DEBUGC("Removing connection context %d", id);
  55160. +
  55161. + DWC_MUTEX_LOCK(cc_if->mutex);
  55162. + cc = cc_find(cc_if, id);
  55163. + if (!cc) {
  55164. + DWC_ERROR("Uid %d not found in cc list\n", id);
  55165. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55166. + return;
  55167. + }
  55168. +
  55169. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  55170. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55171. + free_cc(mem_ctx, cc);
  55172. +
  55173. + cc_changed(cc_if);
  55174. +}
  55175. +
  55176. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  55177. +{
  55178. + uint8_t *buf, *x;
  55179. + uint8_t zero = 0;
  55180. + dwc_cc_t *cc;
  55181. +
  55182. + DWC_MUTEX_LOCK(cc_if->mutex);
  55183. + *length = cc_data_size(cc_if);
  55184. + if (!(*length)) {
  55185. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55186. + return NULL;
  55187. + }
  55188. +
  55189. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  55190. +
  55191. + buf = dwc_alloc(mem_ctx, *length);
  55192. + if (!buf) {
  55193. + *length = 0;
  55194. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55195. + return NULL;
  55196. + }
  55197. +
  55198. + x = buf;
  55199. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  55200. + DWC_MEMCPY(x, cc->chid, 16);
  55201. + x += 16;
  55202. + DWC_MEMCPY(x, cc->cdid, 16);
  55203. + x += 16;
  55204. + DWC_MEMCPY(x, cc->ck, 16);
  55205. + x += 16;
  55206. + if (cc->name) {
  55207. + DWC_MEMCPY(x, &cc->length, 1);
  55208. + x += 1;
  55209. + DWC_MEMCPY(x, cc->name, cc->length);
  55210. + x += cc->length;
  55211. + }
  55212. + else {
  55213. + DWC_MEMCPY(x, &zero, 1);
  55214. + x += 1;
  55215. + }
  55216. + }
  55217. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55218. +
  55219. + return buf;
  55220. +}
  55221. +
  55222. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  55223. +{
  55224. + uint8_t name_length;
  55225. + uint8_t *name;
  55226. + uint8_t *chid;
  55227. + uint8_t *cdid;
  55228. + uint8_t *ck;
  55229. + uint32_t i = 0;
  55230. +
  55231. + DWC_MUTEX_LOCK(cc_if->mutex);
  55232. + cc_clear(mem_ctx, cc_if);
  55233. +
  55234. + while (i < length) {
  55235. + chid = &data[i];
  55236. + i += 16;
  55237. + cdid = &data[i];
  55238. + i += 16;
  55239. + ck = &data[i];
  55240. + i += 16;
  55241. +
  55242. + name_length = data[i];
  55243. + i ++;
  55244. +
  55245. + if (name_length) {
  55246. + name = &data[i];
  55247. + i += name_length;
  55248. + }
  55249. + else {
  55250. + name = NULL;
  55251. + }
  55252. +
  55253. + /* check to see if we haven't overflown the buffer */
  55254. + if (i > length) {
  55255. + DWC_ERROR("Data format error while attempting to load CCs "
  55256. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  55257. + break;
  55258. + }
  55259. +
  55260. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  55261. + }
  55262. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55263. +
  55264. + cc_changed(cc_if);
  55265. +}
  55266. +
  55267. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  55268. +{
  55269. + uint32_t uid = 0;
  55270. +
  55271. + DWC_MUTEX_LOCK(cc_if->mutex);
  55272. + uid = cc_match_chid(cc_if, chid);
  55273. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55274. + return uid;
  55275. +}
  55276. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  55277. +{
  55278. + uint32_t uid = 0;
  55279. +
  55280. + DWC_MUTEX_LOCK(cc_if->mutex);
  55281. + uid = cc_match_cdid(cc_if, cdid);
  55282. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55283. + return uid;
  55284. +}
  55285. +
  55286. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  55287. +{
  55288. + uint8_t *ck = NULL;
  55289. + dwc_cc_t *cc;
  55290. +
  55291. + DWC_MUTEX_LOCK(cc_if->mutex);
  55292. + cc = cc_find(cc_if, id);
  55293. + if (cc) {
  55294. + ck = cc->ck;
  55295. + }
  55296. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55297. +
  55298. + return ck;
  55299. +
  55300. +}
  55301. +
  55302. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  55303. +{
  55304. + uint8_t *retval = NULL;
  55305. + dwc_cc_t *cc;
  55306. +
  55307. + DWC_MUTEX_LOCK(cc_if->mutex);
  55308. + cc = cc_find(cc_if, id);
  55309. + if (cc) {
  55310. + retval = cc->chid;
  55311. + }
  55312. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55313. +
  55314. + return retval;
  55315. +}
  55316. +
  55317. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  55318. +{
  55319. + uint8_t *retval = NULL;
  55320. + dwc_cc_t *cc;
  55321. +
  55322. + DWC_MUTEX_LOCK(cc_if->mutex);
  55323. + cc = cc_find(cc_if, id);
  55324. + if (cc) {
  55325. + retval = cc->cdid;
  55326. + }
  55327. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55328. +
  55329. + return retval;
  55330. +}
  55331. +
  55332. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  55333. +{
  55334. + uint8_t *retval = NULL;
  55335. + dwc_cc_t *cc;
  55336. +
  55337. + DWC_MUTEX_LOCK(cc_if->mutex);
  55338. + *length = 0;
  55339. + cc = cc_find(cc_if, id);
  55340. + if (cc) {
  55341. + *length = cc->length;
  55342. + retval = cc->name;
  55343. + }
  55344. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  55345. +
  55346. + return retval;
  55347. +}
  55348. +
  55349. +#endif /* DWC_CCLIB */
  55350. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  55351. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  55352. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2015-03-09 10:39:33.214893718 +0100
  55353. @@ -0,0 +1,224 @@
  55354. +/* =========================================================================
  55355. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  55356. + * $Revision: #4 $
  55357. + * $Date: 2010/09/28 $
  55358. + * $Change: 1596182 $
  55359. + *
  55360. + * Synopsys Portability Library Software and documentation
  55361. + * (hereinafter, "Software") is an Unsupported proprietary work of
  55362. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  55363. + * between Synopsys and you.
  55364. + *
  55365. + * The Software IS NOT an item of Licensed Software or Licensed Product
  55366. + * under any End User Software License Agreement or Agreement for
  55367. + * Licensed Product with Synopsys or any supplement thereto. You are
  55368. + * permitted to use and redistribute this Software in source and binary
  55369. + * forms, with or without modification, provided that redistributions
  55370. + * of source code must retain this notice. You may not view, use,
  55371. + * disclose, copy or distribute this file or any information contained
  55372. + * herein except pursuant to this license grant from Synopsys. If you
  55373. + * do not agree with this notice, including the disclaimer below, then
  55374. + * you are not authorized to use the Software.
  55375. + *
  55376. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  55377. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  55378. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  55379. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  55380. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  55381. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  55382. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55383. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  55384. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  55385. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  55386. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55387. + * DAMAGE.
  55388. + * ========================================================================= */
  55389. +#ifndef _DWC_CC_H_
  55390. +#define _DWC_CC_H_
  55391. +
  55392. +#ifdef __cplusplus
  55393. +extern "C" {
  55394. +#endif
  55395. +
  55396. +/** @file
  55397. + *
  55398. + * This file defines the Context Context library.
  55399. + *
  55400. + * The main data structure is dwc_cc_if_t which is returned by either the
  55401. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  55402. + * function. The data structure is opaque and should only be manipulated via the
  55403. + * functions provied in this API.
  55404. + *
  55405. + * It manages a list of connection contexts and operations can be performed to
  55406. + * add, remove, query, search, and change, those contexts. Additionally,
  55407. + * a dwc_notifier_t object can be requested from the manager so that
  55408. + * the user can be notified whenever the context list has changed.
  55409. + */
  55410. +
  55411. +#include "dwc_os.h"
  55412. +#include "dwc_list.h"
  55413. +#include "dwc_notifier.h"
  55414. +
  55415. +
  55416. +/* Notifications */
  55417. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  55418. +
  55419. +struct dwc_cc_if;
  55420. +typedef struct dwc_cc_if dwc_cc_if_t;
  55421. +
  55422. +
  55423. +/** @name Connection Context Operations */
  55424. +/** @{ */
  55425. +
  55426. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  55427. + * fields to default values, and returns a pointer to the structure or NULL on
  55428. + * error. */
  55429. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  55430. + dwc_notifier_t *notifier, unsigned is_host);
  55431. +
  55432. +/** Frees the memory for the specified CC structure allocated from
  55433. + * dwc_cc_if_alloc(). */
  55434. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  55435. +
  55436. +/** Removes all contexts from the connection context list */
  55437. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  55438. +
  55439. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  55440. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  55441. + * not overwritten.
  55442. + *
  55443. + * @param cc_if The cc_if structure.
  55444. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  55445. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  55446. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  55447. + * @param name An optional host friendly name as defined in the association model
  55448. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  55449. + * @param length The length othe unicode string.
  55450. + * @return A unique identifier used to refer to this context that is valid for
  55451. + * as long as this context is still in the list. */
  55452. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  55453. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  55454. + uint8_t length);
  55455. +
  55456. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  55457. + * list, preserving any accumulated statistics. This would typically be called
  55458. + * if the host decideds to change the context with a SET_CONNECTION request.
  55459. + *
  55460. + * @param cc_if The cc_if structure.
  55461. + * @param id The identifier of the connection context.
  55462. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  55463. + * indicates no change.
  55464. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  55465. + * indicates no change.
  55466. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  55467. + * indicates no change.
  55468. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  55469. + * @param length Length of name. */
  55470. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  55471. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  55472. + uint8_t *name, uint8_t length);
  55473. +
  55474. +/** Remove the specified connection context.
  55475. + * @param cc_if The cc_if structure.
  55476. + * @param id The identifier of the connection context to remove. */
  55477. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  55478. +
  55479. +/** Get a binary block of data for the connection context list and attributes.
  55480. + * This data can be used by the OS specific driver to save the connection
  55481. + * context list into non-volatile memory.
  55482. + *
  55483. + * @param cc_if The cc_if structure.
  55484. + * @param length Return the length of the data buffer.
  55485. + * @return A pointer to the data buffer. The memory for this buffer should be
  55486. + * freed with DWC_FREE() after use. */
  55487. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  55488. + unsigned int *length);
  55489. +
  55490. +/** Restore the connection context list from the binary data that was previously
  55491. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  55492. + * driver to load a connection context list from non-volatile memory.
  55493. + *
  55494. + * @param cc_if The cc_if structure.
  55495. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  55496. + * @param length The length of the data. */
  55497. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  55498. + uint8_t *data, unsigned int length);
  55499. +
  55500. +/** Find the connection context from the specified CHID.
  55501. + *
  55502. + * @param cc_if The cc_if structure.
  55503. + * @param chid A pointer to the CHID data.
  55504. + * @return A non-zero identifier of the connection context if the CHID matches.
  55505. + * Otherwise returns 0. */
  55506. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  55507. +
  55508. +/** Find the connection context from the specified CDID.
  55509. + *
  55510. + * @param cc_if The cc_if structure.
  55511. + * @param cdid A pointer to the CDID data.
  55512. + * @return A non-zero identifier of the connection context if the CHID matches.
  55513. + * Otherwise returns 0. */
  55514. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  55515. +
  55516. +/** Retrieve the CK from the specified connection context.
  55517. + *
  55518. + * @param cc_if The cc_if structure.
  55519. + * @param id The identifier of the connection context.
  55520. + * @return A pointer to the CK data. The memory does not need to be freed. */
  55521. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  55522. +
  55523. +/** Retrieve the CHID from the specified connection context.
  55524. + *
  55525. + * @param cc_if The cc_if structure.
  55526. + * @param id The identifier of the connection context.
  55527. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  55528. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  55529. +
  55530. +/** Retrieve the CDID from the specified connection context.
  55531. + *
  55532. + * @param cc_if The cc_if structure.
  55533. + * @param id The identifier of the connection context.
  55534. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  55535. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  55536. +
  55537. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  55538. +
  55539. +/** Checks a buffer for non-zero.
  55540. + * @param id A pointer to a 16 byte buffer.
  55541. + * @return true if the 16 byte value is non-zero. */
  55542. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  55543. + int i;
  55544. + for (i=0; i<16; i++) {
  55545. + if (id[i]) return 1;
  55546. + }
  55547. + return 0;
  55548. +}
  55549. +
  55550. +/** Checks a buffer for zero.
  55551. + * @param id A pointer to a 16 byte buffer.
  55552. + * @return true if the 16 byte value is zero. */
  55553. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  55554. + return !dwc_assoc_is_not_zero_id(id);
  55555. +}
  55556. +
  55557. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  55558. + * buffer. */
  55559. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  55560. + char *ptr = buffer;
  55561. + int i;
  55562. + for (i=0; i<16; i++) {
  55563. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  55564. + if (i < 15) {
  55565. + ptr += DWC_SPRINTF(ptr, " ");
  55566. + }
  55567. + }
  55568. + return ptr - buffer;
  55569. +}
  55570. +
  55571. +/** @} */
  55572. +
  55573. +#ifdef __cplusplus
  55574. +}
  55575. +#endif
  55576. +
  55577. +#endif /* _DWC_CC_H_ */
  55578. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  55579. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  55580. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2015-03-09 10:39:33.214893718 +0100
  55581. @@ -0,0 +1,1308 @@
  55582. +#include "dwc_os.h"
  55583. +#include "dwc_list.h"
  55584. +
  55585. +#ifdef DWC_CCLIB
  55586. +# include "dwc_cc.h"
  55587. +#endif
  55588. +
  55589. +#ifdef DWC_CRYPTOLIB
  55590. +# include "dwc_modpow.h"
  55591. +# include "dwc_dh.h"
  55592. +# include "dwc_crypto.h"
  55593. +#endif
  55594. +
  55595. +#ifdef DWC_NOTIFYLIB
  55596. +# include "dwc_notifier.h"
  55597. +#endif
  55598. +
  55599. +/* OS-Level Implementations */
  55600. +
  55601. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  55602. +
  55603. +
  55604. +/* MISC */
  55605. +
  55606. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  55607. +{
  55608. + return memset(dest, byte, size);
  55609. +}
  55610. +
  55611. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  55612. +{
  55613. + return memcpy(dest, src, size);
  55614. +}
  55615. +
  55616. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  55617. +{
  55618. + bcopy(src, dest, size);
  55619. + return dest;
  55620. +}
  55621. +
  55622. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  55623. +{
  55624. + return memcmp(m1, m2, size);
  55625. +}
  55626. +
  55627. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  55628. +{
  55629. + return strncmp(s1, s2, size);
  55630. +}
  55631. +
  55632. +int DWC_STRCMP(void *s1, void *s2)
  55633. +{
  55634. + return strcmp(s1, s2);
  55635. +}
  55636. +
  55637. +int DWC_STRLEN(char const *str)
  55638. +{
  55639. + return strlen(str);
  55640. +}
  55641. +
  55642. +char *DWC_STRCPY(char *to, char const *from)
  55643. +{
  55644. + return strcpy(to, from);
  55645. +}
  55646. +
  55647. +char *DWC_STRDUP(char const *str)
  55648. +{
  55649. + int len = DWC_STRLEN(str) + 1;
  55650. + char *new = DWC_ALLOC_ATOMIC(len);
  55651. +
  55652. + if (!new) {
  55653. + return NULL;
  55654. + }
  55655. +
  55656. + DWC_MEMCPY(new, str, len);
  55657. + return new;
  55658. +}
  55659. +
  55660. +int DWC_ATOI(char *str, int32_t *value)
  55661. +{
  55662. + char *end = NULL;
  55663. +
  55664. + *value = strtol(str, &end, 0);
  55665. + if (*end == '\0') {
  55666. + return 0;
  55667. + }
  55668. +
  55669. + return -1;
  55670. +}
  55671. +
  55672. +int DWC_ATOUI(char *str, uint32_t *value)
  55673. +{
  55674. + char *end = NULL;
  55675. +
  55676. + *value = strtoul(str, &end, 0);
  55677. + if (*end == '\0') {
  55678. + return 0;
  55679. + }
  55680. +
  55681. + return -1;
  55682. +}
  55683. +
  55684. +
  55685. +#ifdef DWC_UTFLIB
  55686. +/* From usbstring.c */
  55687. +
  55688. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  55689. +{
  55690. + int count = 0;
  55691. + u8 c;
  55692. + u16 uchar;
  55693. +
  55694. + /* this insists on correct encodings, though not minimal ones.
  55695. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  55696. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  55697. + */
  55698. + while (len != 0 && (c = (u8) *s++) != 0) {
  55699. + if (unlikely(c & 0x80)) {
  55700. + // 2-byte sequence:
  55701. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  55702. + if ((c & 0xe0) == 0xc0) {
  55703. + uchar = (c & 0x1f) << 6;
  55704. +
  55705. + c = (u8) *s++;
  55706. + if ((c & 0xc0) != 0xc0)
  55707. + goto fail;
  55708. + c &= 0x3f;
  55709. + uchar |= c;
  55710. +
  55711. + // 3-byte sequence (most CJKV characters):
  55712. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  55713. + } else if ((c & 0xf0) == 0xe0) {
  55714. + uchar = (c & 0x0f) << 12;
  55715. +
  55716. + c = (u8) *s++;
  55717. + if ((c & 0xc0) != 0xc0)
  55718. + goto fail;
  55719. + c &= 0x3f;
  55720. + uchar |= c << 6;
  55721. +
  55722. + c = (u8) *s++;
  55723. + if ((c & 0xc0) != 0xc0)
  55724. + goto fail;
  55725. + c &= 0x3f;
  55726. + uchar |= c;
  55727. +
  55728. + /* no bogus surrogates */
  55729. + if (0xd800 <= uchar && uchar <= 0xdfff)
  55730. + goto fail;
  55731. +
  55732. + // 4-byte sequence (surrogate pairs, currently rare):
  55733. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  55734. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  55735. + // (uuuuu = wwww + 1)
  55736. + // FIXME accept the surrogate code points (only)
  55737. + } else
  55738. + goto fail;
  55739. + } else
  55740. + uchar = c;
  55741. + put_unaligned (cpu_to_le16 (uchar), cp++);
  55742. + count++;
  55743. + len--;
  55744. + }
  55745. + return count;
  55746. +fail:
  55747. + return -1;
  55748. +}
  55749. +
  55750. +#endif /* DWC_UTFLIB */
  55751. +
  55752. +
  55753. +/* dwc_debug.h */
  55754. +
  55755. +dwc_bool_t DWC_IN_IRQ(void)
  55756. +{
  55757. +// return in_irq();
  55758. + return 0;
  55759. +}
  55760. +
  55761. +dwc_bool_t DWC_IN_BH(void)
  55762. +{
  55763. +// return in_softirq();
  55764. + return 0;
  55765. +}
  55766. +
  55767. +void DWC_VPRINTF(char *format, va_list args)
  55768. +{
  55769. + vprintf(format, args);
  55770. +}
  55771. +
  55772. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  55773. +{
  55774. + return vsnprintf(str, size, format, args);
  55775. +}
  55776. +
  55777. +void DWC_PRINTF(char *format, ...)
  55778. +{
  55779. + va_list args;
  55780. +
  55781. + va_start(args, format);
  55782. + DWC_VPRINTF(format, args);
  55783. + va_end(args);
  55784. +}
  55785. +
  55786. +int DWC_SPRINTF(char *buffer, char *format, ...)
  55787. +{
  55788. + int retval;
  55789. + va_list args;
  55790. +
  55791. + va_start(args, format);
  55792. + retval = vsprintf(buffer, format, args);
  55793. + va_end(args);
  55794. + return retval;
  55795. +}
  55796. +
  55797. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  55798. +{
  55799. + int retval;
  55800. + va_list args;
  55801. +
  55802. + va_start(args, format);
  55803. + retval = vsnprintf(buffer, size, format, args);
  55804. + va_end(args);
  55805. + return retval;
  55806. +}
  55807. +
  55808. +void __DWC_WARN(char *format, ...)
  55809. +{
  55810. + va_list args;
  55811. +
  55812. + va_start(args, format);
  55813. + DWC_VPRINTF(format, args);
  55814. + va_end(args);
  55815. +}
  55816. +
  55817. +void __DWC_ERROR(char *format, ...)
  55818. +{
  55819. + va_list args;
  55820. +
  55821. + va_start(args, format);
  55822. + DWC_VPRINTF(format, args);
  55823. + va_end(args);
  55824. +}
  55825. +
  55826. +void DWC_EXCEPTION(char *format, ...)
  55827. +{
  55828. + va_list args;
  55829. +
  55830. + va_start(args, format);
  55831. + DWC_VPRINTF(format, args);
  55832. + va_end(args);
  55833. +// BUG_ON(1); ???
  55834. +}
  55835. +
  55836. +#ifdef DEBUG
  55837. +void __DWC_DEBUG(char *format, ...)
  55838. +{
  55839. + va_list args;
  55840. +
  55841. + va_start(args, format);
  55842. + DWC_VPRINTF(format, args);
  55843. + va_end(args);
  55844. +}
  55845. +#endif
  55846. +
  55847. +
  55848. +/* dwc_mem.h */
  55849. +
  55850. +#if 0
  55851. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  55852. + uint32_t align,
  55853. + uint32_t alloc)
  55854. +{
  55855. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  55856. + size, align, alloc);
  55857. + return (dwc_pool_t *)pool;
  55858. +}
  55859. +
  55860. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  55861. +{
  55862. + dma_pool_destroy((struct dma_pool *)pool);
  55863. +}
  55864. +
  55865. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  55866. +{
  55867. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  55868. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  55869. +}
  55870. +
  55871. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  55872. +{
  55873. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  55874. + memset(..);
  55875. +}
  55876. +
  55877. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  55878. +{
  55879. + dma_pool_free(pool, vaddr, daddr);
  55880. +}
  55881. +#endif
  55882. +
  55883. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  55884. +{
  55885. + if (error)
  55886. + return;
  55887. + *(bus_addr_t *)arg = segs[0].ds_addr;
  55888. +}
  55889. +
  55890. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  55891. +{
  55892. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  55893. + int error;
  55894. +
  55895. + error = bus_dma_tag_create(
  55896. +#if __FreeBSD_version >= 700000
  55897. + bus_get_dma_tag(dma->dev), /* parent */
  55898. +#else
  55899. + NULL, /* parent */
  55900. +#endif
  55901. + 4, 0, /* alignment, bounds */
  55902. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  55903. + BUS_SPACE_MAXADDR, /* highaddr */
  55904. + NULL, NULL, /* filter, filterarg */
  55905. + size, /* maxsize */
  55906. + 1, /* nsegments */
  55907. + size, /* maxsegsize */
  55908. + 0, /* flags */
  55909. + NULL, /* lockfunc */
  55910. + NULL, /* lockarg */
  55911. + &dma->dma_tag);
  55912. + if (error) {
  55913. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  55914. + __func__, error);
  55915. + goto fail_0;
  55916. + }
  55917. +
  55918. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  55919. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  55920. + if (error) {
  55921. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  55922. + __func__, (uintmax_t)size, error);
  55923. + goto fail_1;
  55924. + }
  55925. +
  55926. + dma->dma_paddr = 0;
  55927. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  55928. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  55929. + if (error || dma->dma_paddr == 0) {
  55930. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  55931. + __func__, error);
  55932. + goto fail_2;
  55933. + }
  55934. +
  55935. + *dma_addr = dma->dma_paddr;
  55936. + return dma->dma_vaddr;
  55937. +
  55938. +fail_2:
  55939. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  55940. +fail_1:
  55941. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  55942. + bus_dma_tag_destroy(dma->dma_tag);
  55943. +fail_0:
  55944. + dma->dma_map = NULL;
  55945. + dma->dma_tag = NULL;
  55946. +
  55947. + return NULL;
  55948. +}
  55949. +
  55950. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  55951. +{
  55952. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  55953. +
  55954. + if (dma->dma_tag == NULL)
  55955. + return;
  55956. + if (dma->dma_map != NULL) {
  55957. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  55958. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  55959. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  55960. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  55961. + dma->dma_map = NULL;
  55962. + }
  55963. +
  55964. + bus_dma_tag_destroy(dma->dma_tag);
  55965. + dma->dma_tag = NULL;
  55966. +}
  55967. +
  55968. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  55969. +{
  55970. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  55971. +}
  55972. +
  55973. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  55974. +{
  55975. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  55976. +}
  55977. +
  55978. +void __DWC_FREE(void *mem_ctx, void *addr)
  55979. +{
  55980. + free(addr, M_DEVBUF);
  55981. +}
  55982. +
  55983. +
  55984. +#ifdef DWC_CRYPTOLIB
  55985. +/* dwc_crypto.h */
  55986. +
  55987. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  55988. +{
  55989. + get_random_bytes(buffer, length);
  55990. +}
  55991. +
  55992. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  55993. +{
  55994. + struct crypto_blkcipher *tfm;
  55995. + struct blkcipher_desc desc;
  55996. + struct scatterlist sgd;
  55997. + struct scatterlist sgs;
  55998. +
  55999. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  56000. + if (tfm == NULL) {
  56001. + printk("failed to load transform for aes CBC\n");
  56002. + return -1;
  56003. + }
  56004. +
  56005. + crypto_blkcipher_setkey(tfm, key, keylen);
  56006. + crypto_blkcipher_set_iv(tfm, iv, 16);
  56007. +
  56008. + sg_init_one(&sgd, out, messagelen);
  56009. + sg_init_one(&sgs, message, messagelen);
  56010. +
  56011. + desc.tfm = tfm;
  56012. + desc.flags = 0;
  56013. +
  56014. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  56015. + crypto_free_blkcipher(tfm);
  56016. + DWC_ERROR("AES CBC encryption failed");
  56017. + return -1;
  56018. + }
  56019. +
  56020. + crypto_free_blkcipher(tfm);
  56021. + return 0;
  56022. +}
  56023. +
  56024. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  56025. +{
  56026. + struct crypto_hash *tfm;
  56027. + struct hash_desc desc;
  56028. + struct scatterlist sg;
  56029. +
  56030. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  56031. + if (IS_ERR(tfm)) {
  56032. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  56033. + return 0;
  56034. + }
  56035. + desc.tfm = tfm;
  56036. + desc.flags = 0;
  56037. +
  56038. + sg_init_one(&sg, message, len);
  56039. + crypto_hash_digest(&desc, &sg, len, out);
  56040. + crypto_free_hash(tfm);
  56041. +
  56042. + return 1;
  56043. +}
  56044. +
  56045. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  56046. + uint8_t *key, uint32_t keylen, uint8_t *out)
  56047. +{
  56048. + struct crypto_hash *tfm;
  56049. + struct hash_desc desc;
  56050. + struct scatterlist sg;
  56051. +
  56052. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  56053. + if (IS_ERR(tfm)) {
  56054. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  56055. + return 0;
  56056. + }
  56057. + desc.tfm = tfm;
  56058. + desc.flags = 0;
  56059. +
  56060. + sg_init_one(&sg, message, messagelen);
  56061. + crypto_hash_setkey(tfm, key, keylen);
  56062. + crypto_hash_digest(&desc, &sg, messagelen, out);
  56063. + crypto_free_hash(tfm);
  56064. +
  56065. + return 1;
  56066. +}
  56067. +
  56068. +#endif /* DWC_CRYPTOLIB */
  56069. +
  56070. +
  56071. +/* Byte Ordering Conversions */
  56072. +
  56073. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  56074. +{
  56075. +#ifdef __LITTLE_ENDIAN
  56076. + return *p;
  56077. +#else
  56078. + uint8_t *u_p = (uint8_t *)p;
  56079. +
  56080. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56081. +#endif
  56082. +}
  56083. +
  56084. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  56085. +{
  56086. +#ifdef __BIG_ENDIAN
  56087. + return *p;
  56088. +#else
  56089. + uint8_t *u_p = (uint8_t *)p;
  56090. +
  56091. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56092. +#endif
  56093. +}
  56094. +
  56095. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  56096. +{
  56097. +#ifdef __LITTLE_ENDIAN
  56098. + return *p;
  56099. +#else
  56100. + uint8_t *u_p = (uint8_t *)p;
  56101. +
  56102. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56103. +#endif
  56104. +}
  56105. +
  56106. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  56107. +{
  56108. +#ifdef __BIG_ENDIAN
  56109. + return *p;
  56110. +#else
  56111. + uint8_t *u_p = (uint8_t *)p;
  56112. +
  56113. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  56114. +#endif
  56115. +}
  56116. +
  56117. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  56118. +{
  56119. +#ifdef __LITTLE_ENDIAN
  56120. + return *p;
  56121. +#else
  56122. + uint8_t *u_p = (uint8_t *)p;
  56123. + return (u_p[1] | (u_p[0] << 8));
  56124. +#endif
  56125. +}
  56126. +
  56127. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  56128. +{
  56129. +#ifdef __BIG_ENDIAN
  56130. + return *p;
  56131. +#else
  56132. + uint8_t *u_p = (uint8_t *)p;
  56133. + return (u_p[1] | (u_p[0] << 8));
  56134. +#endif
  56135. +}
  56136. +
  56137. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  56138. +{
  56139. +#ifdef __LITTLE_ENDIAN
  56140. + return *p;
  56141. +#else
  56142. + uint8_t *u_p = (uint8_t *)p;
  56143. + return (u_p[1] | (u_p[0] << 8));
  56144. +#endif
  56145. +}
  56146. +
  56147. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  56148. +{
  56149. +#ifdef __BIG_ENDIAN
  56150. + return *p;
  56151. +#else
  56152. + uint8_t *u_p = (uint8_t *)p;
  56153. + return (u_p[1] | (u_p[0] << 8));
  56154. +#endif
  56155. +}
  56156. +
  56157. +
  56158. +/* Registers */
  56159. +
  56160. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  56161. +{
  56162. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56163. + bus_size_t ior = (bus_size_t)reg;
  56164. +
  56165. + return bus_space_read_4(io->iot, io->ioh, ior);
  56166. +}
  56167. +
  56168. +#if 0
  56169. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  56170. +{
  56171. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56172. + bus_size_t ior = (bus_size_t)reg;
  56173. +
  56174. + return bus_space_read_8(io->iot, io->ioh, ior);
  56175. +}
  56176. +#endif
  56177. +
  56178. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  56179. +{
  56180. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56181. + bus_size_t ior = (bus_size_t)reg;
  56182. +
  56183. + bus_space_write_4(io->iot, io->ioh, ior, value);
  56184. +}
  56185. +
  56186. +#if 0
  56187. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  56188. +{
  56189. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56190. + bus_size_t ior = (bus_size_t)reg;
  56191. +
  56192. + bus_space_write_8(io->iot, io->ioh, ior, value);
  56193. +}
  56194. +#endif
  56195. +
  56196. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  56197. + uint32_t set_mask)
  56198. +{
  56199. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56200. + bus_size_t ior = (bus_size_t)reg;
  56201. +
  56202. + bus_space_write_4(io->iot, io->ioh, ior,
  56203. + (bus_space_read_4(io->iot, io->ioh, ior) &
  56204. + ~clear_mask) | set_mask);
  56205. +}
  56206. +
  56207. +#if 0
  56208. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  56209. + uint64_t set_mask)
  56210. +{
  56211. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  56212. + bus_size_t ior = (bus_size_t)reg;
  56213. +
  56214. + bus_space_write_8(io->iot, io->ioh, ior,
  56215. + (bus_space_read_8(io->iot, io->ioh, ior) &
  56216. + ~clear_mask) | set_mask);
  56217. +}
  56218. +#endif
  56219. +
  56220. +
  56221. +/* Locking */
  56222. +
  56223. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  56224. +{
  56225. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  56226. +
  56227. + if (!sl) {
  56228. + DWC_ERROR("Cannot allocate memory for spinlock");
  56229. + return NULL;
  56230. + }
  56231. +
  56232. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  56233. + return (dwc_spinlock_t *)sl;
  56234. +}
  56235. +
  56236. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  56237. +{
  56238. + struct mtx *sl = (struct mtx *)lock;
  56239. +
  56240. + mtx_destroy(sl);
  56241. + DWC_FREE(sl);
  56242. +}
  56243. +
  56244. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  56245. +{
  56246. + mtx_lock_spin((struct mtx *)lock); // ???
  56247. +}
  56248. +
  56249. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  56250. +{
  56251. + mtx_unlock_spin((struct mtx *)lock); // ???
  56252. +}
  56253. +
  56254. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  56255. +{
  56256. + mtx_lock_spin((struct mtx *)lock);
  56257. +}
  56258. +
  56259. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  56260. +{
  56261. + mtx_unlock_spin((struct mtx *)lock);
  56262. +}
  56263. +
  56264. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  56265. +{
  56266. + struct mtx *m;
  56267. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  56268. +
  56269. + if (!mutex) {
  56270. + DWC_ERROR("Cannot allocate memory for mutex");
  56271. + return NULL;
  56272. + }
  56273. +
  56274. + m = (struct mtx *)mutex;
  56275. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  56276. + return mutex;
  56277. +}
  56278. +
  56279. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  56280. +#else
  56281. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  56282. +{
  56283. + mtx_destroy((struct mtx *)mutex);
  56284. + DWC_FREE(mutex);
  56285. +}
  56286. +#endif
  56287. +
  56288. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  56289. +{
  56290. + struct mtx *m = (struct mtx *)mutex;
  56291. +
  56292. + mtx_lock(m);
  56293. +}
  56294. +
  56295. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  56296. +{
  56297. + struct mtx *m = (struct mtx *)mutex;
  56298. +
  56299. + return mtx_trylock(m);
  56300. +}
  56301. +
  56302. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  56303. +{
  56304. + struct mtx *m = (struct mtx *)mutex;
  56305. +
  56306. + mtx_unlock(m);
  56307. +}
  56308. +
  56309. +
  56310. +/* Timing */
  56311. +
  56312. +void DWC_UDELAY(uint32_t usecs)
  56313. +{
  56314. + DELAY(usecs);
  56315. +}
  56316. +
  56317. +void DWC_MDELAY(uint32_t msecs)
  56318. +{
  56319. + do {
  56320. + DELAY(1000);
  56321. + } while (--msecs);
  56322. +}
  56323. +
  56324. +void DWC_MSLEEP(uint32_t msecs)
  56325. +{
  56326. + struct timeval tv;
  56327. +
  56328. + tv.tv_sec = msecs / 1000;
  56329. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  56330. + pause("dw3slp", tvtohz(&tv));
  56331. +}
  56332. +
  56333. +uint32_t DWC_TIME(void)
  56334. +{
  56335. + struct timeval tv;
  56336. +
  56337. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  56338. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  56339. +}
  56340. +
  56341. +
  56342. +/* Timers */
  56343. +
  56344. +struct dwc_timer {
  56345. + struct callout t;
  56346. + char *name;
  56347. + dwc_spinlock_t *lock;
  56348. + dwc_timer_callback_t cb;
  56349. + void *data;
  56350. +};
  56351. +
  56352. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  56353. +{
  56354. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  56355. +
  56356. + if (!t) {
  56357. + DWC_ERROR("Cannot allocate memory for timer");
  56358. + return NULL;
  56359. + }
  56360. +
  56361. + callout_init(&t->t, 1);
  56362. +
  56363. + t->name = DWC_STRDUP(name);
  56364. + if (!t->name) {
  56365. + DWC_ERROR("Cannot allocate memory for timer->name");
  56366. + goto no_name;
  56367. + }
  56368. +
  56369. + t->lock = DWC_SPINLOCK_ALLOC();
  56370. + if (!t->lock) {
  56371. + DWC_ERROR("Cannot allocate memory for lock");
  56372. + goto no_lock;
  56373. + }
  56374. +
  56375. + t->cb = cb;
  56376. + t->data = data;
  56377. +
  56378. + return t;
  56379. +
  56380. + no_lock:
  56381. + DWC_FREE(t->name);
  56382. + no_name:
  56383. + DWC_FREE(t);
  56384. +
  56385. + return NULL;
  56386. +}
  56387. +
  56388. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  56389. +{
  56390. + callout_stop(&timer->t);
  56391. + DWC_SPINLOCK_FREE(timer->lock);
  56392. + DWC_FREE(timer->name);
  56393. + DWC_FREE(timer);
  56394. +}
  56395. +
  56396. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  56397. +{
  56398. + struct timeval tv;
  56399. +
  56400. + tv.tv_sec = time / 1000;
  56401. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  56402. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  56403. +}
  56404. +
  56405. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  56406. +{
  56407. + callout_stop(&timer->t);
  56408. +}
  56409. +
  56410. +
  56411. +/* Wait Queues */
  56412. +
  56413. +struct dwc_waitq {
  56414. + struct mtx lock;
  56415. + int abort;
  56416. +};
  56417. +
  56418. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  56419. +{
  56420. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  56421. +
  56422. + if (!wq) {
  56423. + DWC_ERROR("Cannot allocate memory for waitqueue");
  56424. + return NULL;
  56425. + }
  56426. +
  56427. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  56428. + wq->abort = 0;
  56429. +
  56430. + return wq;
  56431. +}
  56432. +
  56433. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  56434. +{
  56435. + mtx_destroy(&wq->lock);
  56436. + DWC_FREE(wq);
  56437. +}
  56438. +
  56439. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  56440. +{
  56441. +// intrmask_t ipl;
  56442. + int result = 0;
  56443. +
  56444. + mtx_lock(&wq->lock);
  56445. +// ipl = splbio();
  56446. +
  56447. + /* Skip the sleep if already aborted or triggered */
  56448. + if (!wq->abort && !cond(data)) {
  56449. +// splx(ipl);
  56450. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  56451. +// ipl = splbio();
  56452. + }
  56453. +
  56454. + if (result == ERESTART) { // signaled - restart
  56455. + result = -DWC_E_RESTART;
  56456. +
  56457. + } else if (result == EINTR) { // signaled - interrupt
  56458. + result = -DWC_E_ABORT;
  56459. +
  56460. + } else if (wq->abort) {
  56461. + result = -DWC_E_ABORT;
  56462. +
  56463. + } else {
  56464. + result = 0;
  56465. + }
  56466. +
  56467. + wq->abort = 0;
  56468. +// splx(ipl);
  56469. + mtx_unlock(&wq->lock);
  56470. + return result;
  56471. +}
  56472. +
  56473. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  56474. + void *data, int32_t msecs)
  56475. +{
  56476. + struct timeval tv, tv1, tv2;
  56477. +// intrmask_t ipl;
  56478. + int result = 0;
  56479. +
  56480. + tv.tv_sec = msecs / 1000;
  56481. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  56482. +
  56483. + mtx_lock(&wq->lock);
  56484. +// ipl = splbio();
  56485. +
  56486. + /* Skip the sleep if already aborted or triggered */
  56487. + if (!wq->abort && !cond(data)) {
  56488. +// splx(ipl);
  56489. + getmicrouptime(&tv1);
  56490. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  56491. + getmicrouptime(&tv2);
  56492. +// ipl = splbio();
  56493. + }
  56494. +
  56495. + if (result == 0) { // awoken
  56496. + if (wq->abort) {
  56497. + result = -DWC_E_ABORT;
  56498. + } else {
  56499. + tv2.tv_usec -= tv1.tv_usec;
  56500. + if (tv2.tv_usec < 0) {
  56501. + tv2.tv_usec += 1000000;
  56502. + tv2.tv_sec--;
  56503. + }
  56504. +
  56505. + tv2.tv_sec -= tv1.tv_sec;
  56506. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  56507. + result = msecs - result;
  56508. + if (result <= 0)
  56509. + result = 1;
  56510. + }
  56511. + } else if (result == ERESTART) { // signaled - restart
  56512. + result = -DWC_E_RESTART;
  56513. +
  56514. + } else if (result == EINTR) { // signaled - interrupt
  56515. + result = -DWC_E_ABORT;
  56516. +
  56517. + } else { // timed out
  56518. + result = -DWC_E_TIMEOUT;
  56519. + }
  56520. +
  56521. + wq->abort = 0;
  56522. +// splx(ipl);
  56523. + mtx_unlock(&wq->lock);
  56524. + return result;
  56525. +}
  56526. +
  56527. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  56528. +{
  56529. + wakeup(wq);
  56530. +}
  56531. +
  56532. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  56533. +{
  56534. +// intrmask_t ipl;
  56535. +
  56536. + mtx_lock(&wq->lock);
  56537. +// ipl = splbio();
  56538. + wq->abort = 1;
  56539. + wakeup(wq);
  56540. +// splx(ipl);
  56541. + mtx_unlock(&wq->lock);
  56542. +}
  56543. +
  56544. +
  56545. +/* Threading */
  56546. +
  56547. +struct dwc_thread {
  56548. + struct proc *proc;
  56549. + int abort;
  56550. +};
  56551. +
  56552. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  56553. +{
  56554. + int retval;
  56555. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  56556. +
  56557. + if (!thread) {
  56558. + return NULL;
  56559. + }
  56560. +
  56561. + thread->abort = 0;
  56562. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  56563. + RFPROC | RFNOWAIT, 0, "%s", name);
  56564. + if (retval) {
  56565. + DWC_FREE(thread);
  56566. + return NULL;
  56567. + }
  56568. +
  56569. + return thread;
  56570. +}
  56571. +
  56572. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  56573. +{
  56574. + int retval;
  56575. +
  56576. + thread->abort = 1;
  56577. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  56578. +
  56579. + if (retval == 0) {
  56580. + /* DWC_THREAD_EXIT() will free the thread struct */
  56581. + return 0;
  56582. + }
  56583. +
  56584. + /* NOTE: We leak the thread struct if thread doesn't die */
  56585. +
  56586. + if (retval == EWOULDBLOCK) {
  56587. + return -DWC_E_TIMEOUT;
  56588. + }
  56589. +
  56590. + return -DWC_E_UNKNOWN;
  56591. +}
  56592. +
  56593. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  56594. +{
  56595. + return thread->abort;
  56596. +}
  56597. +
  56598. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  56599. +{
  56600. + wakeup(&thread->abort);
  56601. + DWC_FREE(thread);
  56602. + kthread_exit(0);
  56603. +}
  56604. +
  56605. +
  56606. +/* tasklets
  56607. + - Runs in interrupt context (cannot sleep)
  56608. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  56609. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  56610. + */
  56611. +struct dwc_tasklet {
  56612. + struct task t;
  56613. + dwc_tasklet_callback_t cb;
  56614. + void *data;
  56615. +};
  56616. +
  56617. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  56618. +{
  56619. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  56620. +
  56621. + task->cb(task->data);
  56622. +}
  56623. +
  56624. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  56625. +{
  56626. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  56627. +
  56628. + if (task) {
  56629. + task->cb = cb;
  56630. + task->data = data;
  56631. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  56632. + } else {
  56633. + DWC_ERROR("Cannot allocate memory for tasklet");
  56634. + }
  56635. +
  56636. + return task;
  56637. +}
  56638. +
  56639. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  56640. +{
  56641. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  56642. + DWC_FREE(task);
  56643. +}
  56644. +
  56645. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  56646. +{
  56647. + /* Uses predefined system queue */
  56648. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  56649. +}
  56650. +
  56651. +
  56652. +/* workqueues
  56653. + - Runs in process context (can sleep)
  56654. + */
  56655. +typedef struct work_container {
  56656. + dwc_work_callback_t cb;
  56657. + void *data;
  56658. + dwc_workq_t *wq;
  56659. + char *name;
  56660. + int hz;
  56661. +
  56662. +#ifdef DEBUG
  56663. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  56664. +#endif
  56665. + struct task task;
  56666. +} work_container_t;
  56667. +
  56668. +#ifdef DEBUG
  56669. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  56670. +#endif
  56671. +
  56672. +struct dwc_workq {
  56673. + struct taskqueue *taskq;
  56674. + dwc_spinlock_t *lock;
  56675. + dwc_waitq_t *waitq;
  56676. + int pending;
  56677. +
  56678. +#ifdef DEBUG
  56679. + struct work_container_queue entries;
  56680. +#endif
  56681. +};
  56682. +
  56683. +static void do_work(void *data, int pending) // what to do with pending ???
  56684. +{
  56685. + work_container_t *container = (work_container_t *)data;
  56686. + dwc_workq_t *wq = container->wq;
  56687. + dwc_irqflags_t flags;
  56688. +
  56689. + if (container->hz) {
  56690. + pause("dw3wrk", container->hz);
  56691. + }
  56692. +
  56693. + container->cb(container->data);
  56694. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  56695. +
  56696. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56697. +
  56698. +#ifdef DEBUG
  56699. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  56700. +#endif
  56701. + if (container->name)
  56702. + DWC_FREE(container->name);
  56703. + DWC_FREE(container);
  56704. + wq->pending--;
  56705. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56706. + DWC_WAITQ_TRIGGER(wq->waitq);
  56707. +}
  56708. +
  56709. +static int work_done(void *data)
  56710. +{
  56711. + dwc_workq_t *workq = (dwc_workq_t *)data;
  56712. +
  56713. + return workq->pending == 0;
  56714. +}
  56715. +
  56716. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  56717. +{
  56718. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  56719. +}
  56720. +
  56721. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  56722. +{
  56723. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  56724. +
  56725. + if (!wq) {
  56726. + DWC_ERROR("Cannot allocate memory for workqueue");
  56727. + return NULL;
  56728. + }
  56729. +
  56730. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  56731. + if (!wq->taskq) {
  56732. + DWC_ERROR("Cannot allocate memory for taskqueue");
  56733. + goto no_taskq;
  56734. + }
  56735. +
  56736. + wq->pending = 0;
  56737. +
  56738. + wq->lock = DWC_SPINLOCK_ALLOC();
  56739. + if (!wq->lock) {
  56740. + DWC_ERROR("Cannot allocate memory for spinlock");
  56741. + goto no_lock;
  56742. + }
  56743. +
  56744. + wq->waitq = DWC_WAITQ_ALLOC();
  56745. + if (!wq->waitq) {
  56746. + DWC_ERROR("Cannot allocate memory for waitqueue");
  56747. + goto no_waitq;
  56748. + }
  56749. +
  56750. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  56751. +
  56752. +#ifdef DEBUG
  56753. + DWC_CIRCLEQ_INIT(&wq->entries);
  56754. +#endif
  56755. + return wq;
  56756. +
  56757. + no_waitq:
  56758. + DWC_SPINLOCK_FREE(wq->lock);
  56759. + no_lock:
  56760. + taskqueue_free(wq->taskq);
  56761. + no_taskq:
  56762. + DWC_FREE(wq);
  56763. +
  56764. + return NULL;
  56765. +}
  56766. +
  56767. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  56768. +{
  56769. +#ifdef DEBUG
  56770. + dwc_irqflags_t flags;
  56771. +
  56772. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56773. +
  56774. + if (wq->pending != 0) {
  56775. + struct work_container *container;
  56776. +
  56777. + DWC_ERROR("Destroying work queue with pending work");
  56778. +
  56779. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  56780. + DWC_ERROR("Work %s still pending", container->name);
  56781. + }
  56782. + }
  56783. +
  56784. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56785. +#endif
  56786. + DWC_WAITQ_FREE(wq->waitq);
  56787. + DWC_SPINLOCK_FREE(wq->lock);
  56788. + taskqueue_free(wq->taskq);
  56789. + DWC_FREE(wq);
  56790. +}
  56791. +
  56792. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  56793. + char *format, ...)
  56794. +{
  56795. + dwc_irqflags_t flags;
  56796. + work_container_t *container;
  56797. + static char name[128];
  56798. + va_list args;
  56799. +
  56800. + va_start(args, format);
  56801. + DWC_VSNPRINTF(name, 128, format, args);
  56802. + va_end(args);
  56803. +
  56804. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56805. + wq->pending++;
  56806. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56807. + DWC_WAITQ_TRIGGER(wq->waitq);
  56808. +
  56809. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  56810. + if (!container) {
  56811. + DWC_ERROR("Cannot allocate memory for container");
  56812. + return;
  56813. + }
  56814. +
  56815. + container->name = DWC_STRDUP(name);
  56816. + if (!container->name) {
  56817. + DWC_ERROR("Cannot allocate memory for container->name");
  56818. + DWC_FREE(container);
  56819. + return;
  56820. + }
  56821. +
  56822. + container->cb = cb;
  56823. + container->data = data;
  56824. + container->wq = wq;
  56825. + container->hz = 0;
  56826. +
  56827. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  56828. +
  56829. + TASK_INIT(&container->task, 0, do_work, container);
  56830. +
  56831. +#ifdef DEBUG
  56832. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  56833. +#endif
  56834. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  56835. +}
  56836. +
  56837. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  56838. + void *data, uint32_t time, char *format, ...)
  56839. +{
  56840. + dwc_irqflags_t flags;
  56841. + work_container_t *container;
  56842. + static char name[128];
  56843. + struct timeval tv;
  56844. + va_list args;
  56845. +
  56846. + va_start(args, format);
  56847. + DWC_VSNPRINTF(name, 128, format, args);
  56848. + va_end(args);
  56849. +
  56850. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  56851. + wq->pending++;
  56852. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  56853. + DWC_WAITQ_TRIGGER(wq->waitq);
  56854. +
  56855. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  56856. + if (!container) {
  56857. + DWC_ERROR("Cannot allocate memory for container");
  56858. + return;
  56859. + }
  56860. +
  56861. + container->name = DWC_STRDUP(name);
  56862. + if (!container->name) {
  56863. + DWC_ERROR("Cannot allocate memory for container->name");
  56864. + DWC_FREE(container);
  56865. + return;
  56866. + }
  56867. +
  56868. + container->cb = cb;
  56869. + container->data = data;
  56870. + container->wq = wq;
  56871. +
  56872. + tv.tv_sec = time / 1000;
  56873. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  56874. + container->hz = tvtohz(&tv);
  56875. +
  56876. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  56877. +
  56878. + TASK_INIT(&container->task, 0, do_work, container);
  56879. +
  56880. +#ifdef DEBUG
  56881. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  56882. +#endif
  56883. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  56884. +}
  56885. +
  56886. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  56887. +{
  56888. + return wq->pending;
  56889. +}
  56890. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  56891. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  56892. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2015-03-10 17:26:51.302216687 +0100
  56893. @@ -0,0 +1,1432 @@
  56894. +#include <linux/kernel.h>
  56895. +#include <linux/init.h>
  56896. +#include <linux/module.h>
  56897. +#include <linux/kthread.h>
  56898. +
  56899. +#ifdef DWC_CCLIB
  56900. +# include "dwc_cc.h"
  56901. +#endif
  56902. +
  56903. +#ifdef DWC_CRYPTOLIB
  56904. +# include "dwc_modpow.h"
  56905. +# include "dwc_dh.h"
  56906. +# include "dwc_crypto.h"
  56907. +#endif
  56908. +
  56909. +#ifdef DWC_NOTIFYLIB
  56910. +# include "dwc_notifier.h"
  56911. +#endif
  56912. +
  56913. +/* OS-Level Implementations */
  56914. +
  56915. +/* This is the Linux kernel implementation of the DWC platform library. */
  56916. +#include <linux/moduleparam.h>
  56917. +#include <linux/ctype.h>
  56918. +#include <linux/crypto.h>
  56919. +#include <linux/delay.h>
  56920. +#include <linux/device.h>
  56921. +#include <linux/dma-mapping.h>
  56922. +#include <linux/cdev.h>
  56923. +#include <linux/errno.h>
  56924. +#include <linux/interrupt.h>
  56925. +#include <linux/jiffies.h>
  56926. +#include <linux/list.h>
  56927. +#include <linux/pci.h>
  56928. +#include <linux/random.h>
  56929. +#include <linux/scatterlist.h>
  56930. +#include <linux/slab.h>
  56931. +#include <linux/stat.h>
  56932. +#include <linux/string.h>
  56933. +#include <linux/timer.h>
  56934. +#include <linux/usb.h>
  56935. +
  56936. +#include <linux/version.h>
  56937. +
  56938. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  56939. +# include <linux/usb/gadget.h>
  56940. +#else
  56941. +# include <linux/usb_gadget.h>
  56942. +#endif
  56943. +
  56944. +#include <asm/io.h>
  56945. +#include <asm/page.h>
  56946. +#include <asm/uaccess.h>
  56947. +#include <asm/unaligned.h>
  56948. +
  56949. +#include "dwc_os.h"
  56950. +#include "dwc_list.h"
  56951. +
  56952. +
  56953. +/* MISC */
  56954. +
  56955. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  56956. +{
  56957. + return memset(dest, byte, size);
  56958. +}
  56959. +
  56960. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  56961. +{
  56962. + return memcpy(dest, src, size);
  56963. +}
  56964. +
  56965. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  56966. +{
  56967. + return memmove(dest, src, size);
  56968. +}
  56969. +
  56970. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  56971. +{
  56972. + return memcmp(m1, m2, size);
  56973. +}
  56974. +
  56975. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  56976. +{
  56977. + return strncmp(s1, s2, size);
  56978. +}
  56979. +
  56980. +int DWC_STRCMP(void *s1, void *s2)
  56981. +{
  56982. + return strcmp(s1, s2);
  56983. +}
  56984. +
  56985. +int DWC_STRLEN(char const *str)
  56986. +{
  56987. + return strlen(str);
  56988. +}
  56989. +
  56990. +char *DWC_STRCPY(char *to, char const *from)
  56991. +{
  56992. + return strcpy(to, from);
  56993. +}
  56994. +
  56995. +char *DWC_STRDUP(char const *str)
  56996. +{
  56997. + int len = DWC_STRLEN(str) + 1;
  56998. + char *new = DWC_ALLOC_ATOMIC(len);
  56999. +
  57000. + if (!new) {
  57001. + return NULL;
  57002. + }
  57003. +
  57004. + DWC_MEMCPY(new, str, len);
  57005. + return new;
  57006. +}
  57007. +
  57008. +int DWC_ATOI(const char *str, int32_t *value)
  57009. +{
  57010. + char *end = NULL;
  57011. +
  57012. + *value = simple_strtol(str, &end, 0);
  57013. + if (*end == '\0') {
  57014. + return 0;
  57015. + }
  57016. +
  57017. + return -1;
  57018. +}
  57019. +
  57020. +int DWC_ATOUI(const char *str, uint32_t *value)
  57021. +{
  57022. + char *end = NULL;
  57023. +
  57024. + *value = simple_strtoul(str, &end, 0);
  57025. + if (*end == '\0') {
  57026. + return 0;
  57027. + }
  57028. +
  57029. + return -1;
  57030. +}
  57031. +
  57032. +
  57033. +#ifdef DWC_UTFLIB
  57034. +/* From usbstring.c */
  57035. +
  57036. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  57037. +{
  57038. + int count = 0;
  57039. + u8 c;
  57040. + u16 uchar;
  57041. +
  57042. + /* this insists on correct encodings, though not minimal ones.
  57043. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  57044. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  57045. + */
  57046. + while (len != 0 && (c = (u8) *s++) != 0) {
  57047. + if (unlikely(c & 0x80)) {
  57048. + // 2-byte sequence:
  57049. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  57050. + if ((c & 0xe0) == 0xc0) {
  57051. + uchar = (c & 0x1f) << 6;
  57052. +
  57053. + c = (u8) *s++;
  57054. + if ((c & 0xc0) != 0xc0)
  57055. + goto fail;
  57056. + c &= 0x3f;
  57057. + uchar |= c;
  57058. +
  57059. + // 3-byte sequence (most CJKV characters):
  57060. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  57061. + } else if ((c & 0xf0) == 0xe0) {
  57062. + uchar = (c & 0x0f) << 12;
  57063. +
  57064. + c = (u8) *s++;
  57065. + if ((c & 0xc0) != 0xc0)
  57066. + goto fail;
  57067. + c &= 0x3f;
  57068. + uchar |= c << 6;
  57069. +
  57070. + c = (u8) *s++;
  57071. + if ((c & 0xc0) != 0xc0)
  57072. + goto fail;
  57073. + c &= 0x3f;
  57074. + uchar |= c;
  57075. +
  57076. + /* no bogus surrogates */
  57077. + if (0xd800 <= uchar && uchar <= 0xdfff)
  57078. + goto fail;
  57079. +
  57080. + // 4-byte sequence (surrogate pairs, currently rare):
  57081. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  57082. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  57083. + // (uuuuu = wwww + 1)
  57084. + // FIXME accept the surrogate code points (only)
  57085. + } else
  57086. + goto fail;
  57087. + } else
  57088. + uchar = c;
  57089. + put_unaligned (cpu_to_le16 (uchar), cp++);
  57090. + count++;
  57091. + len--;
  57092. + }
  57093. + return count;
  57094. +fail:
  57095. + return -1;
  57096. +}
  57097. +#endif /* DWC_UTFLIB */
  57098. +
  57099. +
  57100. +/* dwc_debug.h */
  57101. +
  57102. +dwc_bool_t DWC_IN_IRQ(void)
  57103. +{
  57104. + return in_irq();
  57105. +}
  57106. +
  57107. +dwc_bool_t DWC_IN_BH(void)
  57108. +{
  57109. + return in_softirq();
  57110. +}
  57111. +
  57112. +void DWC_VPRINTF(char *format, va_list args)
  57113. +{
  57114. + vprintk(format, args);
  57115. +}
  57116. +
  57117. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  57118. +{
  57119. + return vsnprintf(str, size, format, args);
  57120. +}
  57121. +
  57122. +void DWC_PRINTF(char *format, ...)
  57123. +{
  57124. + va_list args;
  57125. +
  57126. + va_start(args, format);
  57127. + DWC_VPRINTF(format, args);
  57128. + va_end(args);
  57129. +}
  57130. +
  57131. +int DWC_SPRINTF(char *buffer, char *format, ...)
  57132. +{
  57133. + int retval;
  57134. + va_list args;
  57135. +
  57136. + va_start(args, format);
  57137. + retval = vsprintf(buffer, format, args);
  57138. + va_end(args);
  57139. + return retval;
  57140. +}
  57141. +
  57142. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  57143. +{
  57144. + int retval;
  57145. + va_list args;
  57146. +
  57147. + va_start(args, format);
  57148. + retval = vsnprintf(buffer, size, format, args);
  57149. + va_end(args);
  57150. + return retval;
  57151. +}
  57152. +
  57153. +void __DWC_WARN(char *format, ...)
  57154. +{
  57155. + va_list args;
  57156. +
  57157. + va_start(args, format);
  57158. + DWC_PRINTF(KERN_WARNING);
  57159. + DWC_VPRINTF(format, args);
  57160. + va_end(args);
  57161. +}
  57162. +
  57163. +void __DWC_ERROR(char *format, ...)
  57164. +{
  57165. + va_list args;
  57166. +
  57167. + va_start(args, format);
  57168. + DWC_PRINTF(KERN_ERR);
  57169. + DWC_VPRINTF(format, args);
  57170. + va_end(args);
  57171. +}
  57172. +
  57173. +void DWC_EXCEPTION(char *format, ...)
  57174. +{
  57175. + va_list args;
  57176. +
  57177. + va_start(args, format);
  57178. + DWC_PRINTF(KERN_ERR);
  57179. + DWC_VPRINTF(format, args);
  57180. + va_end(args);
  57181. + BUG_ON(1);
  57182. +}
  57183. +
  57184. +#ifdef DEBUG
  57185. +void __DWC_DEBUG(char *format, ...)
  57186. +{
  57187. + va_list args;
  57188. +
  57189. + va_start(args, format);
  57190. + DWC_PRINTF(KERN_DEBUG);
  57191. + DWC_VPRINTF(format, args);
  57192. + va_end(args);
  57193. +}
  57194. +#endif
  57195. +
  57196. +
  57197. +/* dwc_mem.h */
  57198. +
  57199. +#if 0
  57200. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  57201. + uint32_t align,
  57202. + uint32_t alloc)
  57203. +{
  57204. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  57205. + size, align, alloc);
  57206. + return (dwc_pool_t *)pool;
  57207. +}
  57208. +
  57209. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  57210. +{
  57211. + dma_pool_destroy((struct dma_pool *)pool);
  57212. +}
  57213. +
  57214. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  57215. +{
  57216. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  57217. +}
  57218. +
  57219. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  57220. +{
  57221. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  57222. + memset(..);
  57223. +}
  57224. +
  57225. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  57226. +{
  57227. + dma_pool_free(pool, vaddr, daddr);
  57228. +}
  57229. +#endif
  57230. +
  57231. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  57232. +{
  57233. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  57234. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  57235. +#else
  57236. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  57237. +#endif
  57238. + if (!buf) {
  57239. + return NULL;
  57240. + }
  57241. +
  57242. + memset(buf, 0, (size_t)size);
  57243. + return buf;
  57244. +}
  57245. +
  57246. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  57247. +{
  57248. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  57249. + if (!buf) {
  57250. + return NULL;
  57251. + }
  57252. + memset(buf, 0, (size_t)size);
  57253. + return buf;
  57254. +}
  57255. +
  57256. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  57257. +{
  57258. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  57259. +}
  57260. +
  57261. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  57262. +{
  57263. + return kzalloc(size, GFP_KERNEL);
  57264. +}
  57265. +
  57266. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  57267. +{
  57268. + return kzalloc(size, GFP_ATOMIC);
  57269. +}
  57270. +
  57271. +void __DWC_FREE(void *mem_ctx, void *addr)
  57272. +{
  57273. + kfree(addr);
  57274. +}
  57275. +
  57276. +
  57277. +#ifdef DWC_CRYPTOLIB
  57278. +/* dwc_crypto.h */
  57279. +
  57280. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  57281. +{
  57282. + get_random_bytes(buffer, length);
  57283. +}
  57284. +
  57285. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  57286. +{
  57287. + struct crypto_blkcipher *tfm;
  57288. + struct blkcipher_desc desc;
  57289. + struct scatterlist sgd;
  57290. + struct scatterlist sgs;
  57291. +
  57292. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  57293. + if (tfm == NULL) {
  57294. + printk("failed to load transform for aes CBC\n");
  57295. + return -1;
  57296. + }
  57297. +
  57298. + crypto_blkcipher_setkey(tfm, key, keylen);
  57299. + crypto_blkcipher_set_iv(tfm, iv, 16);
  57300. +
  57301. + sg_init_one(&sgd, out, messagelen);
  57302. + sg_init_one(&sgs, message, messagelen);
  57303. +
  57304. + desc.tfm = tfm;
  57305. + desc.flags = 0;
  57306. +
  57307. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  57308. + crypto_free_blkcipher(tfm);
  57309. + DWC_ERROR("AES CBC encryption failed");
  57310. + return -1;
  57311. + }
  57312. +
  57313. + crypto_free_blkcipher(tfm);
  57314. + return 0;
  57315. +}
  57316. +
  57317. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  57318. +{
  57319. + struct crypto_hash *tfm;
  57320. + struct hash_desc desc;
  57321. + struct scatterlist sg;
  57322. +
  57323. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  57324. + if (IS_ERR(tfm)) {
  57325. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  57326. + return 0;
  57327. + }
  57328. + desc.tfm = tfm;
  57329. + desc.flags = 0;
  57330. +
  57331. + sg_init_one(&sg, message, len);
  57332. + crypto_hash_digest(&desc, &sg, len, out);
  57333. + crypto_free_hash(tfm);
  57334. +
  57335. + return 1;
  57336. +}
  57337. +
  57338. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  57339. + uint8_t *key, uint32_t keylen, uint8_t *out)
  57340. +{
  57341. + struct crypto_hash *tfm;
  57342. + struct hash_desc desc;
  57343. + struct scatterlist sg;
  57344. +
  57345. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  57346. + if (IS_ERR(tfm)) {
  57347. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  57348. + return 0;
  57349. + }
  57350. + desc.tfm = tfm;
  57351. + desc.flags = 0;
  57352. +
  57353. + sg_init_one(&sg, message, messagelen);
  57354. + crypto_hash_setkey(tfm, key, keylen);
  57355. + crypto_hash_digest(&desc, &sg, messagelen, out);
  57356. + crypto_free_hash(tfm);
  57357. +
  57358. + return 1;
  57359. +}
  57360. +#endif /* DWC_CRYPTOLIB */
  57361. +
  57362. +
  57363. +/* Byte Ordering Conversions */
  57364. +
  57365. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  57366. +{
  57367. +#ifdef __LITTLE_ENDIAN
  57368. + return *p;
  57369. +#else
  57370. + uint8_t *u_p = (uint8_t *)p;
  57371. +
  57372. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  57373. +#endif
  57374. +}
  57375. +
  57376. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  57377. +{
  57378. +#ifdef __BIG_ENDIAN
  57379. + return *p;
  57380. +#else
  57381. + uint8_t *u_p = (uint8_t *)p;
  57382. +
  57383. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  57384. +#endif
  57385. +}
  57386. +
  57387. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  57388. +{
  57389. +#ifdef __LITTLE_ENDIAN
  57390. + return *p;
  57391. +#else
  57392. + uint8_t *u_p = (uint8_t *)p;
  57393. +
  57394. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  57395. +#endif
  57396. +}
  57397. +
  57398. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  57399. +{
  57400. +#ifdef __BIG_ENDIAN
  57401. + return *p;
  57402. +#else
  57403. + uint8_t *u_p = (uint8_t *)p;
  57404. +
  57405. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  57406. +#endif
  57407. +}
  57408. +
  57409. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  57410. +{
  57411. +#ifdef __LITTLE_ENDIAN
  57412. + return *p;
  57413. +#else
  57414. + uint8_t *u_p = (uint8_t *)p;
  57415. + return (u_p[1] | (u_p[0] << 8));
  57416. +#endif
  57417. +}
  57418. +
  57419. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  57420. +{
  57421. +#ifdef __BIG_ENDIAN
  57422. + return *p;
  57423. +#else
  57424. + uint8_t *u_p = (uint8_t *)p;
  57425. + return (u_p[1] | (u_p[0] << 8));
  57426. +#endif
  57427. +}
  57428. +
  57429. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  57430. +{
  57431. +#ifdef __LITTLE_ENDIAN
  57432. + return *p;
  57433. +#else
  57434. + uint8_t *u_p = (uint8_t *)p;
  57435. + return (u_p[1] | (u_p[0] << 8));
  57436. +#endif
  57437. +}
  57438. +
  57439. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  57440. +{
  57441. +#ifdef __BIG_ENDIAN
  57442. + return *p;
  57443. +#else
  57444. + uint8_t *u_p = (uint8_t *)p;
  57445. + return (u_p[1] | (u_p[0] << 8));
  57446. +#endif
  57447. +}
  57448. +
  57449. +
  57450. +/* Registers */
  57451. +
  57452. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  57453. +{
  57454. + return readl(reg);
  57455. +}
  57456. +
  57457. +#if 0
  57458. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  57459. +{
  57460. +}
  57461. +#endif
  57462. +
  57463. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  57464. +{
  57465. + writel(value, reg);
  57466. +}
  57467. +
  57468. +#if 0
  57469. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  57470. +{
  57471. +}
  57472. +#endif
  57473. +
  57474. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  57475. +{
  57476. + unsigned long flags;
  57477. +
  57478. + local_irq_save(flags);
  57479. + local_fiq_disable();
  57480. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  57481. + local_fiq_enable();
  57482. + local_irq_restore(flags);
  57483. +}
  57484. +
  57485. +#if 0
  57486. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  57487. +{
  57488. +}
  57489. +#endif
  57490. +
  57491. +
  57492. +/* Locking */
  57493. +
  57494. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  57495. +{
  57496. + spinlock_t *sl = (spinlock_t *)1;
  57497. +
  57498. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57499. + sl = DWC_ALLOC(sizeof(*sl));
  57500. + if (!sl) {
  57501. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  57502. + return NULL;
  57503. + }
  57504. +
  57505. + spin_lock_init(sl);
  57506. +#endif
  57507. + return (dwc_spinlock_t *)sl;
  57508. +}
  57509. +
  57510. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  57511. +{
  57512. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57513. + DWC_FREE(lock);
  57514. +#endif
  57515. +}
  57516. +
  57517. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  57518. +{
  57519. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57520. + spin_lock((spinlock_t *)lock);
  57521. +#endif
  57522. +}
  57523. +
  57524. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  57525. +{
  57526. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57527. + spin_unlock((spinlock_t *)lock);
  57528. +#endif
  57529. +}
  57530. +
  57531. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  57532. +{
  57533. + dwc_irqflags_t f;
  57534. +
  57535. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57536. + spin_lock_irqsave((spinlock_t *)lock, f);
  57537. +#else
  57538. + local_irq_save(f);
  57539. +#endif
  57540. + *flags = f;
  57541. +}
  57542. +
  57543. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  57544. +{
  57545. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  57546. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  57547. +#else
  57548. + local_irq_restore(flags);
  57549. +#endif
  57550. +}
  57551. +
  57552. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  57553. +{
  57554. + struct mutex *m;
  57555. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  57556. +
  57557. + if (!mutex) {
  57558. + DWC_ERROR("Cannot allocate memory for mutex\n");
  57559. + return NULL;
  57560. + }
  57561. +
  57562. + m = (struct mutex *)mutex;
  57563. + mutex_init(m);
  57564. + return mutex;
  57565. +}
  57566. +
  57567. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  57568. +#else
  57569. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  57570. +{
  57571. + mutex_destroy((struct mutex *)mutex);
  57572. + DWC_FREE(mutex);
  57573. +}
  57574. +#endif
  57575. +
  57576. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  57577. +{
  57578. + struct mutex *m = (struct mutex *)mutex;
  57579. + mutex_lock(m);
  57580. +}
  57581. +
  57582. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  57583. +{
  57584. + struct mutex *m = (struct mutex *)mutex;
  57585. + return mutex_trylock(m);
  57586. +}
  57587. +
  57588. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  57589. +{
  57590. + struct mutex *m = (struct mutex *)mutex;
  57591. + mutex_unlock(m);
  57592. +}
  57593. +
  57594. +
  57595. +/* Timing */
  57596. +
  57597. +void DWC_UDELAY(uint32_t usecs)
  57598. +{
  57599. + udelay(usecs);
  57600. +}
  57601. +
  57602. +void DWC_MDELAY(uint32_t msecs)
  57603. +{
  57604. + mdelay(msecs);
  57605. +}
  57606. +
  57607. +void DWC_MSLEEP(uint32_t msecs)
  57608. +{
  57609. + msleep(msecs);
  57610. +}
  57611. +
  57612. +uint32_t DWC_TIME(void)
  57613. +{
  57614. + return jiffies_to_msecs(jiffies);
  57615. +}
  57616. +
  57617. +
  57618. +/* Timers */
  57619. +
  57620. +struct dwc_timer {
  57621. + struct timer_list *t;
  57622. + char *name;
  57623. + dwc_timer_callback_t cb;
  57624. + void *data;
  57625. + uint8_t scheduled;
  57626. + dwc_spinlock_t *lock;
  57627. +};
  57628. +
  57629. +static void timer_callback(unsigned long data)
  57630. +{
  57631. + dwc_timer_t *timer = (dwc_timer_t *)data;
  57632. + dwc_irqflags_t flags;
  57633. +
  57634. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57635. + timer->scheduled = 0;
  57636. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57637. + DWC_DEBUGC("Timer %s callback", timer->name);
  57638. + timer->cb(timer->data);
  57639. +}
  57640. +
  57641. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  57642. +{
  57643. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  57644. +
  57645. + if (!t) {
  57646. + DWC_ERROR("Cannot allocate memory for timer");
  57647. + return NULL;
  57648. + }
  57649. +
  57650. + t->t = DWC_ALLOC(sizeof(*t->t));
  57651. + if (!t->t) {
  57652. + DWC_ERROR("Cannot allocate memory for timer->t");
  57653. + goto no_timer;
  57654. + }
  57655. +
  57656. + t->name = DWC_STRDUP(name);
  57657. + if (!t->name) {
  57658. + DWC_ERROR("Cannot allocate memory for timer->name");
  57659. + goto no_name;
  57660. + }
  57661. +
  57662. + t->lock = DWC_SPINLOCK_ALLOC();
  57663. + if (!t->lock) {
  57664. + DWC_ERROR("Cannot allocate memory for lock");
  57665. + goto no_lock;
  57666. + }
  57667. +
  57668. + t->scheduled = 0;
  57669. + t->t->base = &boot_tvec_bases;
  57670. + t->t->expires = jiffies;
  57671. + setup_timer(t->t, timer_callback, (unsigned long)t);
  57672. +
  57673. + t->cb = cb;
  57674. + t->data = data;
  57675. +
  57676. + return t;
  57677. +
  57678. + no_lock:
  57679. + DWC_FREE(t->name);
  57680. + no_name:
  57681. + DWC_FREE(t->t);
  57682. + no_timer:
  57683. + DWC_FREE(t);
  57684. + return NULL;
  57685. +}
  57686. +
  57687. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  57688. +{
  57689. + dwc_irqflags_t flags;
  57690. +
  57691. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57692. +
  57693. + if (timer->scheduled) {
  57694. + del_timer(timer->t);
  57695. + timer->scheduled = 0;
  57696. + }
  57697. +
  57698. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57699. + DWC_SPINLOCK_FREE(timer->lock);
  57700. + DWC_FREE(timer->t);
  57701. + DWC_FREE(timer->name);
  57702. + DWC_FREE(timer);
  57703. +}
  57704. +
  57705. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  57706. +{
  57707. + dwc_irqflags_t flags;
  57708. +
  57709. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  57710. +
  57711. + if (!timer->scheduled) {
  57712. + timer->scheduled = 1;
  57713. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  57714. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  57715. + add_timer(timer->t);
  57716. + } else {
  57717. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  57718. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  57719. + }
  57720. +
  57721. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  57722. +}
  57723. +
  57724. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  57725. +{
  57726. + del_timer(timer->t);
  57727. +}
  57728. +
  57729. +
  57730. +/* Wait Queues */
  57731. +
  57732. +struct dwc_waitq {
  57733. + wait_queue_head_t queue;
  57734. + int abort;
  57735. +};
  57736. +
  57737. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  57738. +{
  57739. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  57740. +
  57741. + if (!wq) {
  57742. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  57743. + return NULL;
  57744. + }
  57745. +
  57746. + init_waitqueue_head(&wq->queue);
  57747. + wq->abort = 0;
  57748. + return wq;
  57749. +}
  57750. +
  57751. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  57752. +{
  57753. + DWC_FREE(wq);
  57754. +}
  57755. +
  57756. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  57757. +{
  57758. + int result = wait_event_interruptible(wq->queue,
  57759. + cond(data) || wq->abort);
  57760. + if (result == -ERESTARTSYS) {
  57761. + wq->abort = 0;
  57762. + return -DWC_E_RESTART;
  57763. + }
  57764. +
  57765. + if (wq->abort == 1) {
  57766. + wq->abort = 0;
  57767. + return -DWC_E_ABORT;
  57768. + }
  57769. +
  57770. + wq->abort = 0;
  57771. +
  57772. + if (result == 0) {
  57773. + return 0;
  57774. + }
  57775. +
  57776. + return -DWC_E_UNKNOWN;
  57777. +}
  57778. +
  57779. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  57780. + void *data, int32_t msecs)
  57781. +{
  57782. + int32_t tmsecs;
  57783. + int result = wait_event_interruptible_timeout(wq->queue,
  57784. + cond(data) || wq->abort,
  57785. + msecs_to_jiffies(msecs));
  57786. + if (result == -ERESTARTSYS) {
  57787. + wq->abort = 0;
  57788. + return -DWC_E_RESTART;
  57789. + }
  57790. +
  57791. + if (wq->abort == 1) {
  57792. + wq->abort = 0;
  57793. + return -DWC_E_ABORT;
  57794. + }
  57795. +
  57796. + wq->abort = 0;
  57797. +
  57798. + if (result > 0) {
  57799. + tmsecs = jiffies_to_msecs(result);
  57800. + if (!tmsecs) {
  57801. + return 1;
  57802. + }
  57803. +
  57804. + return tmsecs;
  57805. + }
  57806. +
  57807. + if (result == 0) {
  57808. + return -DWC_E_TIMEOUT;
  57809. + }
  57810. +
  57811. + return -DWC_E_UNKNOWN;
  57812. +}
  57813. +
  57814. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  57815. +{
  57816. + wq->abort = 0;
  57817. + wake_up_interruptible(&wq->queue);
  57818. +}
  57819. +
  57820. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  57821. +{
  57822. + wq->abort = 1;
  57823. + wake_up_interruptible(&wq->queue);
  57824. +}
  57825. +
  57826. +
  57827. +/* Threading */
  57828. +
  57829. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  57830. +{
  57831. + struct task_struct *thread = kthread_run(func, data, name);
  57832. +
  57833. + if (thread == ERR_PTR(-ENOMEM)) {
  57834. + return NULL;
  57835. + }
  57836. +
  57837. + return (dwc_thread_t *)thread;
  57838. +}
  57839. +
  57840. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  57841. +{
  57842. + return kthread_stop((struct task_struct *)thread);
  57843. +}
  57844. +
  57845. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  57846. +{
  57847. + return kthread_should_stop();
  57848. +}
  57849. +
  57850. +
  57851. +/* tasklets
  57852. + - run in interrupt context (cannot sleep)
  57853. + - each tasklet runs on a single CPU
  57854. + - different tasklets can be running simultaneously on different CPUs
  57855. + */
  57856. +struct dwc_tasklet {
  57857. + struct tasklet_struct t;
  57858. + dwc_tasklet_callback_t cb;
  57859. + void *data;
  57860. +};
  57861. +
  57862. +static void tasklet_callback(unsigned long data)
  57863. +{
  57864. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  57865. + t->cb(t->data);
  57866. +}
  57867. +
  57868. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  57869. +{
  57870. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  57871. +
  57872. + if (t) {
  57873. + t->cb = cb;
  57874. + t->data = data;
  57875. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  57876. + } else {
  57877. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  57878. + }
  57879. +
  57880. + return t;
  57881. +}
  57882. +
  57883. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  57884. +{
  57885. + DWC_FREE(task);
  57886. +}
  57887. +
  57888. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  57889. +{
  57890. + tasklet_schedule(&task->t);
  57891. +}
  57892. +
  57893. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  57894. +{
  57895. + tasklet_hi_schedule(&task->t);
  57896. +}
  57897. +
  57898. +
  57899. +/* workqueues
  57900. + - run in process context (can sleep)
  57901. + */
  57902. +typedef struct work_container {
  57903. + dwc_work_callback_t cb;
  57904. + void *data;
  57905. + dwc_workq_t *wq;
  57906. + char *name;
  57907. +
  57908. +#ifdef DEBUG
  57909. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  57910. +#endif
  57911. + struct delayed_work work;
  57912. +} work_container_t;
  57913. +
  57914. +#ifdef DEBUG
  57915. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  57916. +#endif
  57917. +
  57918. +struct dwc_workq {
  57919. + struct workqueue_struct *wq;
  57920. + dwc_spinlock_t *lock;
  57921. + dwc_waitq_t *waitq;
  57922. + int pending;
  57923. +
  57924. +#ifdef DEBUG
  57925. + struct work_container_queue entries;
  57926. +#endif
  57927. +};
  57928. +
  57929. +static void do_work(struct work_struct *work)
  57930. +{
  57931. + dwc_irqflags_t flags;
  57932. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  57933. + work_container_t *container = container_of(dw, struct work_container, work);
  57934. + dwc_workq_t *wq = container->wq;
  57935. +
  57936. + container->cb(container->data);
  57937. +
  57938. +#ifdef DEBUG
  57939. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  57940. +#endif
  57941. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  57942. + if (container->name) {
  57943. + DWC_FREE(container->name);
  57944. + }
  57945. + DWC_FREE(container);
  57946. +
  57947. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  57948. + wq->pending--;
  57949. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  57950. + DWC_WAITQ_TRIGGER(wq->waitq);
  57951. +}
  57952. +
  57953. +static int work_done(void *data)
  57954. +{
  57955. + dwc_workq_t *workq = (dwc_workq_t *)data;
  57956. + return workq->pending == 0;
  57957. +}
  57958. +
  57959. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  57960. +{
  57961. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  57962. +}
  57963. +
  57964. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  57965. +{
  57966. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  57967. +
  57968. + if (!wq) {
  57969. + return NULL;
  57970. + }
  57971. +
  57972. + wq->wq = create_singlethread_workqueue(name);
  57973. + if (!wq->wq) {
  57974. + goto no_wq;
  57975. + }
  57976. +
  57977. + wq->pending = 0;
  57978. +
  57979. + wq->lock = DWC_SPINLOCK_ALLOC();
  57980. + if (!wq->lock) {
  57981. + goto no_lock;
  57982. + }
  57983. +
  57984. + wq->waitq = DWC_WAITQ_ALLOC();
  57985. + if (!wq->waitq) {
  57986. + goto no_waitq;
  57987. + }
  57988. +
  57989. +#ifdef DEBUG
  57990. + DWC_CIRCLEQ_INIT(&wq->entries);
  57991. +#endif
  57992. + return wq;
  57993. +
  57994. + no_waitq:
  57995. + DWC_SPINLOCK_FREE(wq->lock);
  57996. + no_lock:
  57997. + destroy_workqueue(wq->wq);
  57998. + no_wq:
  57999. + DWC_FREE(wq);
  58000. +
  58001. + return NULL;
  58002. +}
  58003. +
  58004. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  58005. +{
  58006. +#ifdef DEBUG
  58007. + if (wq->pending != 0) {
  58008. + struct work_container *wc;
  58009. + DWC_ERROR("Destroying work queue with pending work");
  58010. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  58011. + DWC_ERROR("Work %s still pending", wc->name);
  58012. + }
  58013. + }
  58014. +#endif
  58015. + destroy_workqueue(wq->wq);
  58016. + DWC_SPINLOCK_FREE(wq->lock);
  58017. + DWC_WAITQ_FREE(wq->waitq);
  58018. + DWC_FREE(wq);
  58019. +}
  58020. +
  58021. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  58022. + char *format, ...)
  58023. +{
  58024. + dwc_irqflags_t flags;
  58025. + work_container_t *container;
  58026. + static char name[128];
  58027. + va_list args;
  58028. +
  58029. + va_start(args, format);
  58030. + DWC_VSNPRINTF(name, 128, format, args);
  58031. + va_end(args);
  58032. +
  58033. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58034. + wq->pending++;
  58035. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58036. + DWC_WAITQ_TRIGGER(wq->waitq);
  58037. +
  58038. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  58039. + if (!container) {
  58040. + DWC_ERROR("Cannot allocate memory for container\n");
  58041. + return;
  58042. + }
  58043. +
  58044. + container->name = DWC_STRDUP(name);
  58045. + if (!container->name) {
  58046. + DWC_ERROR("Cannot allocate memory for container->name\n");
  58047. + DWC_FREE(container);
  58048. + return;
  58049. + }
  58050. +
  58051. + container->cb = cb;
  58052. + container->data = data;
  58053. + container->wq = wq;
  58054. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  58055. + INIT_WORK(&container->work.work, do_work);
  58056. +
  58057. +#ifdef DEBUG
  58058. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  58059. +#endif
  58060. + queue_work(wq->wq, &container->work.work);
  58061. +}
  58062. +
  58063. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  58064. + void *data, uint32_t time, char *format, ...)
  58065. +{
  58066. + dwc_irqflags_t flags;
  58067. + work_container_t *container;
  58068. + static char name[128];
  58069. + va_list args;
  58070. +
  58071. + va_start(args, format);
  58072. + DWC_VSNPRINTF(name, 128, format, args);
  58073. + va_end(args);
  58074. +
  58075. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  58076. + wq->pending++;
  58077. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  58078. + DWC_WAITQ_TRIGGER(wq->waitq);
  58079. +
  58080. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  58081. + if (!container) {
  58082. + DWC_ERROR("Cannot allocate memory for container\n");
  58083. + return;
  58084. + }
  58085. +
  58086. + container->name = DWC_STRDUP(name);
  58087. + if (!container->name) {
  58088. + DWC_ERROR("Cannot allocate memory for container->name\n");
  58089. + DWC_FREE(container);
  58090. + return;
  58091. + }
  58092. +
  58093. + container->cb = cb;
  58094. + container->data = data;
  58095. + container->wq = wq;
  58096. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  58097. + INIT_DELAYED_WORK(&container->work, do_work);
  58098. +
  58099. +#ifdef DEBUG
  58100. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  58101. +#endif
  58102. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  58103. +}
  58104. +
  58105. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  58106. +{
  58107. + return wq->pending;
  58108. +}
  58109. +
  58110. +
  58111. +#ifdef DWC_LIBMODULE
  58112. +
  58113. +#ifdef DWC_CCLIB
  58114. +/* CC */
  58115. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  58116. +EXPORT_SYMBOL(dwc_cc_if_free);
  58117. +EXPORT_SYMBOL(dwc_cc_clear);
  58118. +EXPORT_SYMBOL(dwc_cc_add);
  58119. +EXPORT_SYMBOL(dwc_cc_remove);
  58120. +EXPORT_SYMBOL(dwc_cc_change);
  58121. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  58122. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  58123. +EXPORT_SYMBOL(dwc_cc_match_chid);
  58124. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  58125. +EXPORT_SYMBOL(dwc_cc_ck);
  58126. +EXPORT_SYMBOL(dwc_cc_chid);
  58127. +EXPORT_SYMBOL(dwc_cc_cdid);
  58128. +EXPORT_SYMBOL(dwc_cc_name);
  58129. +#endif /* DWC_CCLIB */
  58130. +
  58131. +#ifdef DWC_CRYPTOLIB
  58132. +# ifndef CONFIG_MACH_IPMATE
  58133. +/* Modpow */
  58134. +EXPORT_SYMBOL(dwc_modpow);
  58135. +
  58136. +/* DH */
  58137. +EXPORT_SYMBOL(dwc_dh_modpow);
  58138. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  58139. +EXPORT_SYMBOL(dwc_dh_pk);
  58140. +# endif /* CONFIG_MACH_IPMATE */
  58141. +
  58142. +/* Crypto */
  58143. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  58144. +EXPORT_SYMBOL(dwc_wusb_cmf);
  58145. +EXPORT_SYMBOL(dwc_wusb_prf);
  58146. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  58147. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  58148. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  58149. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  58150. +#endif /* DWC_CRYPTOLIB */
  58151. +
  58152. +/* Notification */
  58153. +#ifdef DWC_NOTIFYLIB
  58154. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  58155. +EXPORT_SYMBOL(dwc_free_notification_manager);
  58156. +EXPORT_SYMBOL(dwc_register_notifier);
  58157. +EXPORT_SYMBOL(dwc_unregister_notifier);
  58158. +EXPORT_SYMBOL(dwc_add_observer);
  58159. +EXPORT_SYMBOL(dwc_remove_observer);
  58160. +EXPORT_SYMBOL(dwc_notify);
  58161. +#endif
  58162. +
  58163. +/* Memory Debugging Routines */
  58164. +#ifdef DWC_DEBUG_MEMORY
  58165. +EXPORT_SYMBOL(dwc_alloc_debug);
  58166. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  58167. +EXPORT_SYMBOL(dwc_free_debug);
  58168. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  58169. +EXPORT_SYMBOL(dwc_dma_free_debug);
  58170. +#endif
  58171. +
  58172. +EXPORT_SYMBOL(DWC_MEMSET);
  58173. +EXPORT_SYMBOL(DWC_MEMCPY);
  58174. +EXPORT_SYMBOL(DWC_MEMMOVE);
  58175. +EXPORT_SYMBOL(DWC_MEMCMP);
  58176. +EXPORT_SYMBOL(DWC_STRNCMP);
  58177. +EXPORT_SYMBOL(DWC_STRCMP);
  58178. +EXPORT_SYMBOL(DWC_STRLEN);
  58179. +EXPORT_SYMBOL(DWC_STRCPY);
  58180. +EXPORT_SYMBOL(DWC_STRDUP);
  58181. +EXPORT_SYMBOL(DWC_ATOI);
  58182. +EXPORT_SYMBOL(DWC_ATOUI);
  58183. +
  58184. +#ifdef DWC_UTFLIB
  58185. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  58186. +#endif /* DWC_UTFLIB */
  58187. +
  58188. +EXPORT_SYMBOL(DWC_IN_IRQ);
  58189. +EXPORT_SYMBOL(DWC_IN_BH);
  58190. +EXPORT_SYMBOL(DWC_VPRINTF);
  58191. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  58192. +EXPORT_SYMBOL(DWC_PRINTF);
  58193. +EXPORT_SYMBOL(DWC_SPRINTF);
  58194. +EXPORT_SYMBOL(DWC_SNPRINTF);
  58195. +EXPORT_SYMBOL(__DWC_WARN);
  58196. +EXPORT_SYMBOL(__DWC_ERROR);
  58197. +EXPORT_SYMBOL(DWC_EXCEPTION);
  58198. +
  58199. +#ifdef DEBUG
  58200. +EXPORT_SYMBOL(__DWC_DEBUG);
  58201. +#endif
  58202. +
  58203. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  58204. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  58205. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  58206. +EXPORT_SYMBOL(__DWC_ALLOC);
  58207. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  58208. +EXPORT_SYMBOL(__DWC_FREE);
  58209. +
  58210. +#ifdef DWC_CRYPTOLIB
  58211. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  58212. +EXPORT_SYMBOL(DWC_AES_CBC);
  58213. +EXPORT_SYMBOL(DWC_SHA256);
  58214. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  58215. +#endif
  58216. +
  58217. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  58218. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  58219. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  58220. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  58221. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  58222. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  58223. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  58224. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  58225. +EXPORT_SYMBOL(DWC_READ_REG32);
  58226. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  58227. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  58228. +
  58229. +#if 0
  58230. +EXPORT_SYMBOL(DWC_READ_REG64);
  58231. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  58232. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  58233. +#endif
  58234. +
  58235. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  58236. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  58237. +EXPORT_SYMBOL(DWC_SPINLOCK);
  58238. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  58239. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  58240. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  58241. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  58242. +
  58243. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  58244. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  58245. +#endif
  58246. +
  58247. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  58248. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  58249. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  58250. +EXPORT_SYMBOL(DWC_UDELAY);
  58251. +EXPORT_SYMBOL(DWC_MDELAY);
  58252. +EXPORT_SYMBOL(DWC_MSLEEP);
  58253. +EXPORT_SYMBOL(DWC_TIME);
  58254. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  58255. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  58256. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  58257. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  58258. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  58259. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  58260. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  58261. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  58262. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  58263. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  58264. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  58265. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  58266. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  58267. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  58268. +EXPORT_SYMBOL(DWC_TASK_FREE);
  58269. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  58270. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  58271. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  58272. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  58273. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  58274. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  58275. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  58276. +
  58277. +static int dwc_common_port_init_module(void)
  58278. +{
  58279. + int result = 0;
  58280. +
  58281. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  58282. +
  58283. +#ifdef DWC_DEBUG_MEMORY
  58284. + result = dwc_memory_debug_start(NULL);
  58285. + if (result) {
  58286. + printk(KERN_ERR
  58287. + "dwc_memory_debug_start() failed with error %d\n",
  58288. + result);
  58289. + return result;
  58290. + }
  58291. +#endif
  58292. +
  58293. +#ifdef DWC_NOTIFYLIB
  58294. + result = dwc_alloc_notification_manager(NULL, NULL);
  58295. + if (result) {
  58296. + printk(KERN_ERR
  58297. + "dwc_alloc_notification_manager() failed with error %d\n",
  58298. + result);
  58299. + return result;
  58300. + }
  58301. +#endif
  58302. + return result;
  58303. +}
  58304. +
  58305. +static void dwc_common_port_exit_module(void)
  58306. +{
  58307. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  58308. +
  58309. +#ifdef DWC_NOTIFYLIB
  58310. + dwc_free_notification_manager();
  58311. +#endif
  58312. +
  58313. +#ifdef DWC_DEBUG_MEMORY
  58314. + dwc_memory_debug_stop();
  58315. +#endif
  58316. +}
  58317. +
  58318. +module_init(dwc_common_port_init_module);
  58319. +module_exit(dwc_common_port_exit_module);
  58320. +
  58321. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  58322. +MODULE_AUTHOR("Synopsys Inc.");
  58323. +MODULE_LICENSE ("GPL");
  58324. +
  58325. +#endif /* DWC_LIBMODULE */
  58326. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  58327. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  58328. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2015-03-09 10:39:33.214893718 +0100
  58329. @@ -0,0 +1,1275 @@
  58330. +#include "dwc_os.h"
  58331. +#include "dwc_list.h"
  58332. +
  58333. +#ifdef DWC_CCLIB
  58334. +# include "dwc_cc.h"
  58335. +#endif
  58336. +
  58337. +#ifdef DWC_CRYPTOLIB
  58338. +# include "dwc_modpow.h"
  58339. +# include "dwc_dh.h"
  58340. +# include "dwc_crypto.h"
  58341. +#endif
  58342. +
  58343. +#ifdef DWC_NOTIFYLIB
  58344. +# include "dwc_notifier.h"
  58345. +#endif
  58346. +
  58347. +/* OS-Level Implementations */
  58348. +
  58349. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  58350. +
  58351. +
  58352. +/* MISC */
  58353. +
  58354. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  58355. +{
  58356. + return memset(dest, byte, size);
  58357. +}
  58358. +
  58359. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  58360. +{
  58361. + return memcpy(dest, src, size);
  58362. +}
  58363. +
  58364. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  58365. +{
  58366. + bcopy(src, dest, size);
  58367. + return dest;
  58368. +}
  58369. +
  58370. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  58371. +{
  58372. + return memcmp(m1, m2, size);
  58373. +}
  58374. +
  58375. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  58376. +{
  58377. + return strncmp(s1, s2, size);
  58378. +}
  58379. +
  58380. +int DWC_STRCMP(void *s1, void *s2)
  58381. +{
  58382. + return strcmp(s1, s2);
  58383. +}
  58384. +
  58385. +int DWC_STRLEN(char const *str)
  58386. +{
  58387. + return strlen(str);
  58388. +}
  58389. +
  58390. +char *DWC_STRCPY(char *to, char const *from)
  58391. +{
  58392. + return strcpy(to, from);
  58393. +}
  58394. +
  58395. +char *DWC_STRDUP(char const *str)
  58396. +{
  58397. + int len = DWC_STRLEN(str) + 1;
  58398. + char *new = DWC_ALLOC_ATOMIC(len);
  58399. +
  58400. + if (!new) {
  58401. + return NULL;
  58402. + }
  58403. +
  58404. + DWC_MEMCPY(new, str, len);
  58405. + return new;
  58406. +}
  58407. +
  58408. +int DWC_ATOI(char *str, int32_t *value)
  58409. +{
  58410. + char *end = NULL;
  58411. +
  58412. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  58413. + * should be equivalent on 2's complement machines
  58414. + */
  58415. + *value = strtoul(str, &end, 0);
  58416. + if (*end == '\0') {
  58417. + return 0;
  58418. + }
  58419. +
  58420. + return -1;
  58421. +}
  58422. +
  58423. +int DWC_ATOUI(char *str, uint32_t *value)
  58424. +{
  58425. + char *end = NULL;
  58426. +
  58427. + *value = strtoul(str, &end, 0);
  58428. + if (*end == '\0') {
  58429. + return 0;
  58430. + }
  58431. +
  58432. + return -1;
  58433. +}
  58434. +
  58435. +
  58436. +#ifdef DWC_UTFLIB
  58437. +/* From usbstring.c */
  58438. +
  58439. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  58440. +{
  58441. + int count = 0;
  58442. + u8 c;
  58443. + u16 uchar;
  58444. +
  58445. + /* this insists on correct encodings, though not minimal ones.
  58446. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  58447. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  58448. + */
  58449. + while (len != 0 && (c = (u8) *s++) != 0) {
  58450. + if (unlikely(c & 0x80)) {
  58451. + // 2-byte sequence:
  58452. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  58453. + if ((c & 0xe0) == 0xc0) {
  58454. + uchar = (c & 0x1f) << 6;
  58455. +
  58456. + c = (u8) *s++;
  58457. + if ((c & 0xc0) != 0xc0)
  58458. + goto fail;
  58459. + c &= 0x3f;
  58460. + uchar |= c;
  58461. +
  58462. + // 3-byte sequence (most CJKV characters):
  58463. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  58464. + } else if ((c & 0xf0) == 0xe0) {
  58465. + uchar = (c & 0x0f) << 12;
  58466. +
  58467. + c = (u8) *s++;
  58468. + if ((c & 0xc0) != 0xc0)
  58469. + goto fail;
  58470. + c &= 0x3f;
  58471. + uchar |= c << 6;
  58472. +
  58473. + c = (u8) *s++;
  58474. + if ((c & 0xc0) != 0xc0)
  58475. + goto fail;
  58476. + c &= 0x3f;
  58477. + uchar |= c;
  58478. +
  58479. + /* no bogus surrogates */
  58480. + if (0xd800 <= uchar && uchar <= 0xdfff)
  58481. + goto fail;
  58482. +
  58483. + // 4-byte sequence (surrogate pairs, currently rare):
  58484. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  58485. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  58486. + // (uuuuu = wwww + 1)
  58487. + // FIXME accept the surrogate code points (only)
  58488. + } else
  58489. + goto fail;
  58490. + } else
  58491. + uchar = c;
  58492. + put_unaligned (cpu_to_le16 (uchar), cp++);
  58493. + count++;
  58494. + len--;
  58495. + }
  58496. + return count;
  58497. +fail:
  58498. + return -1;
  58499. +}
  58500. +
  58501. +#endif /* DWC_UTFLIB */
  58502. +
  58503. +
  58504. +/* dwc_debug.h */
  58505. +
  58506. +dwc_bool_t DWC_IN_IRQ(void)
  58507. +{
  58508. +// return in_irq();
  58509. + return 0;
  58510. +}
  58511. +
  58512. +dwc_bool_t DWC_IN_BH(void)
  58513. +{
  58514. +// return in_softirq();
  58515. + return 0;
  58516. +}
  58517. +
  58518. +void DWC_VPRINTF(char *format, va_list args)
  58519. +{
  58520. + vprintf(format, args);
  58521. +}
  58522. +
  58523. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  58524. +{
  58525. + return vsnprintf(str, size, format, args);
  58526. +}
  58527. +
  58528. +void DWC_PRINTF(char *format, ...)
  58529. +{
  58530. + va_list args;
  58531. +
  58532. + va_start(args, format);
  58533. + DWC_VPRINTF(format, args);
  58534. + va_end(args);
  58535. +}
  58536. +
  58537. +int DWC_SPRINTF(char *buffer, char *format, ...)
  58538. +{
  58539. + int retval;
  58540. + va_list args;
  58541. +
  58542. + va_start(args, format);
  58543. + retval = vsprintf(buffer, format, args);
  58544. + va_end(args);
  58545. + return retval;
  58546. +}
  58547. +
  58548. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  58549. +{
  58550. + int retval;
  58551. + va_list args;
  58552. +
  58553. + va_start(args, format);
  58554. + retval = vsnprintf(buffer, size, format, args);
  58555. + va_end(args);
  58556. + return retval;
  58557. +}
  58558. +
  58559. +void __DWC_WARN(char *format, ...)
  58560. +{
  58561. + va_list args;
  58562. +
  58563. + va_start(args, format);
  58564. + DWC_VPRINTF(format, args);
  58565. + va_end(args);
  58566. +}
  58567. +
  58568. +void __DWC_ERROR(char *format, ...)
  58569. +{
  58570. + va_list args;
  58571. +
  58572. + va_start(args, format);
  58573. + DWC_VPRINTF(format, args);
  58574. + va_end(args);
  58575. +}
  58576. +
  58577. +void DWC_EXCEPTION(char *format, ...)
  58578. +{
  58579. + va_list args;
  58580. +
  58581. + va_start(args, format);
  58582. + DWC_VPRINTF(format, args);
  58583. + va_end(args);
  58584. +// BUG_ON(1); ???
  58585. +}
  58586. +
  58587. +#ifdef DEBUG
  58588. +void __DWC_DEBUG(char *format, ...)
  58589. +{
  58590. + va_list args;
  58591. +
  58592. + va_start(args, format);
  58593. + DWC_VPRINTF(format, args);
  58594. + va_end(args);
  58595. +}
  58596. +#endif
  58597. +
  58598. +
  58599. +/* dwc_mem.h */
  58600. +
  58601. +#if 0
  58602. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  58603. + uint32_t align,
  58604. + uint32_t alloc)
  58605. +{
  58606. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  58607. + size, align, alloc);
  58608. + return (dwc_pool_t *)pool;
  58609. +}
  58610. +
  58611. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  58612. +{
  58613. + dma_pool_destroy((struct dma_pool *)pool);
  58614. +}
  58615. +
  58616. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  58617. +{
  58618. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  58619. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  58620. +}
  58621. +
  58622. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  58623. +{
  58624. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  58625. + memset(..);
  58626. +}
  58627. +
  58628. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  58629. +{
  58630. + dma_pool_free(pool, vaddr, daddr);
  58631. +}
  58632. +#endif
  58633. +
  58634. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  58635. +{
  58636. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  58637. + int error;
  58638. +
  58639. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  58640. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  58641. + &dma->nsegs, BUS_DMA_NOWAIT);
  58642. + if (error) {
  58643. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  58644. + (uintmax_t)size, error);
  58645. + goto fail_0;
  58646. + }
  58647. +
  58648. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  58649. + (caddr_t *)&dma->dma_vaddr,
  58650. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  58651. + if (error) {
  58652. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  58653. + goto fail_1;
  58654. + }
  58655. +
  58656. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  58657. + BUS_DMA_NOWAIT, &dma->dma_map);
  58658. + if (error) {
  58659. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  58660. + goto fail_2;
  58661. + }
  58662. +
  58663. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  58664. + size, NULL, BUS_DMA_NOWAIT);
  58665. + if (error) {
  58666. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  58667. + goto fail_3;
  58668. + }
  58669. +
  58670. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  58671. + *dma_addr = dma->dma_paddr;
  58672. + return dma->dma_vaddr;
  58673. +
  58674. +fail_3:
  58675. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  58676. +fail_2:
  58677. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  58678. +fail_1:
  58679. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  58680. +fail_0:
  58681. + dma->dma_map = NULL;
  58682. + dma->dma_vaddr = NULL;
  58683. + dma->nsegs = 0;
  58684. +
  58685. + return NULL;
  58686. +}
  58687. +
  58688. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  58689. +{
  58690. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  58691. +
  58692. + if (dma->dma_map != NULL) {
  58693. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  58694. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  58695. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  58696. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  58697. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  58698. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  58699. + dma->dma_paddr = 0;
  58700. + dma->dma_map = NULL;
  58701. + dma->dma_vaddr = NULL;
  58702. + dma->nsegs = 0;
  58703. + }
  58704. +}
  58705. +
  58706. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  58707. +{
  58708. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  58709. +}
  58710. +
  58711. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  58712. +{
  58713. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  58714. +}
  58715. +
  58716. +void __DWC_FREE(void *mem_ctx, void *addr)
  58717. +{
  58718. + free(addr, M_DEVBUF);
  58719. +}
  58720. +
  58721. +
  58722. +#ifdef DWC_CRYPTOLIB
  58723. +/* dwc_crypto.h */
  58724. +
  58725. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  58726. +{
  58727. + get_random_bytes(buffer, length);
  58728. +}
  58729. +
  58730. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  58731. +{
  58732. + struct crypto_blkcipher *tfm;
  58733. + struct blkcipher_desc desc;
  58734. + struct scatterlist sgd;
  58735. + struct scatterlist sgs;
  58736. +
  58737. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  58738. + if (tfm == NULL) {
  58739. + printk("failed to load transform for aes CBC\n");
  58740. + return -1;
  58741. + }
  58742. +
  58743. + crypto_blkcipher_setkey(tfm, key, keylen);
  58744. + crypto_blkcipher_set_iv(tfm, iv, 16);
  58745. +
  58746. + sg_init_one(&sgd, out, messagelen);
  58747. + sg_init_one(&sgs, message, messagelen);
  58748. +
  58749. + desc.tfm = tfm;
  58750. + desc.flags = 0;
  58751. +
  58752. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  58753. + crypto_free_blkcipher(tfm);
  58754. + DWC_ERROR("AES CBC encryption failed");
  58755. + return -1;
  58756. + }
  58757. +
  58758. + crypto_free_blkcipher(tfm);
  58759. + return 0;
  58760. +}
  58761. +
  58762. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  58763. +{
  58764. + struct crypto_hash *tfm;
  58765. + struct hash_desc desc;
  58766. + struct scatterlist sg;
  58767. +
  58768. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  58769. + if (IS_ERR(tfm)) {
  58770. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  58771. + return 0;
  58772. + }
  58773. + desc.tfm = tfm;
  58774. + desc.flags = 0;
  58775. +
  58776. + sg_init_one(&sg, message, len);
  58777. + crypto_hash_digest(&desc, &sg, len, out);
  58778. + crypto_free_hash(tfm);
  58779. +
  58780. + return 1;
  58781. +}
  58782. +
  58783. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  58784. + uint8_t *key, uint32_t keylen, uint8_t *out)
  58785. +{
  58786. + struct crypto_hash *tfm;
  58787. + struct hash_desc desc;
  58788. + struct scatterlist sg;
  58789. +
  58790. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  58791. + if (IS_ERR(tfm)) {
  58792. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  58793. + return 0;
  58794. + }
  58795. + desc.tfm = tfm;
  58796. + desc.flags = 0;
  58797. +
  58798. + sg_init_one(&sg, message, messagelen);
  58799. + crypto_hash_setkey(tfm, key, keylen);
  58800. + crypto_hash_digest(&desc, &sg, messagelen, out);
  58801. + crypto_free_hash(tfm);
  58802. +
  58803. + return 1;
  58804. +}
  58805. +
  58806. +#endif /* DWC_CRYPTOLIB */
  58807. +
  58808. +
  58809. +/* Byte Ordering Conversions */
  58810. +
  58811. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  58812. +{
  58813. +#ifdef __LITTLE_ENDIAN
  58814. + return *p;
  58815. +#else
  58816. + uint8_t *u_p = (uint8_t *)p;
  58817. +
  58818. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58819. +#endif
  58820. +}
  58821. +
  58822. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  58823. +{
  58824. +#ifdef __BIG_ENDIAN
  58825. + return *p;
  58826. +#else
  58827. + uint8_t *u_p = (uint8_t *)p;
  58828. +
  58829. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58830. +#endif
  58831. +}
  58832. +
  58833. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  58834. +{
  58835. +#ifdef __LITTLE_ENDIAN
  58836. + return *p;
  58837. +#else
  58838. + uint8_t *u_p = (uint8_t *)p;
  58839. +
  58840. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58841. +#endif
  58842. +}
  58843. +
  58844. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  58845. +{
  58846. +#ifdef __BIG_ENDIAN
  58847. + return *p;
  58848. +#else
  58849. + uint8_t *u_p = (uint8_t *)p;
  58850. +
  58851. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  58852. +#endif
  58853. +}
  58854. +
  58855. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  58856. +{
  58857. +#ifdef __LITTLE_ENDIAN
  58858. + return *p;
  58859. +#else
  58860. + uint8_t *u_p = (uint8_t *)p;
  58861. + return (u_p[1] | (u_p[0] << 8));
  58862. +#endif
  58863. +}
  58864. +
  58865. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  58866. +{
  58867. +#ifdef __BIG_ENDIAN
  58868. + return *p;
  58869. +#else
  58870. + uint8_t *u_p = (uint8_t *)p;
  58871. + return (u_p[1] | (u_p[0] << 8));
  58872. +#endif
  58873. +}
  58874. +
  58875. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  58876. +{
  58877. +#ifdef __LITTLE_ENDIAN
  58878. + return *p;
  58879. +#else
  58880. + uint8_t *u_p = (uint8_t *)p;
  58881. + return (u_p[1] | (u_p[0] << 8));
  58882. +#endif
  58883. +}
  58884. +
  58885. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  58886. +{
  58887. +#ifdef __BIG_ENDIAN
  58888. + return *p;
  58889. +#else
  58890. + uint8_t *u_p = (uint8_t *)p;
  58891. + return (u_p[1] | (u_p[0] << 8));
  58892. +#endif
  58893. +}
  58894. +
  58895. +
  58896. +/* Registers */
  58897. +
  58898. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  58899. +{
  58900. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58901. + bus_size_t ior = (bus_size_t)reg;
  58902. +
  58903. + return bus_space_read_4(io->iot, io->ioh, ior);
  58904. +}
  58905. +
  58906. +#if 0
  58907. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  58908. +{
  58909. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58910. + bus_size_t ior = (bus_size_t)reg;
  58911. +
  58912. + return bus_space_read_8(io->iot, io->ioh, ior);
  58913. +}
  58914. +#endif
  58915. +
  58916. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  58917. +{
  58918. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58919. + bus_size_t ior = (bus_size_t)reg;
  58920. +
  58921. + bus_space_write_4(io->iot, io->ioh, ior, value);
  58922. +}
  58923. +
  58924. +#if 0
  58925. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  58926. +{
  58927. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58928. + bus_size_t ior = (bus_size_t)reg;
  58929. +
  58930. + bus_space_write_8(io->iot, io->ioh, ior, value);
  58931. +}
  58932. +#endif
  58933. +
  58934. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  58935. + uint32_t set_mask)
  58936. +{
  58937. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58938. + bus_size_t ior = (bus_size_t)reg;
  58939. +
  58940. + bus_space_write_4(io->iot, io->ioh, ior,
  58941. + (bus_space_read_4(io->iot, io->ioh, ior) &
  58942. + ~clear_mask) | set_mask);
  58943. +}
  58944. +
  58945. +#if 0
  58946. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  58947. + uint64_t set_mask)
  58948. +{
  58949. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  58950. + bus_size_t ior = (bus_size_t)reg;
  58951. +
  58952. + bus_space_write_8(io->iot, io->ioh, ior,
  58953. + (bus_space_read_8(io->iot, io->ioh, ior) &
  58954. + ~clear_mask) | set_mask);
  58955. +}
  58956. +#endif
  58957. +
  58958. +
  58959. +/* Locking */
  58960. +
  58961. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  58962. +{
  58963. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  58964. +
  58965. + if (!sl) {
  58966. + DWC_ERROR("Cannot allocate memory for spinlock");
  58967. + return NULL;
  58968. + }
  58969. +
  58970. + simple_lock_init(sl);
  58971. + return (dwc_spinlock_t *)sl;
  58972. +}
  58973. +
  58974. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  58975. +{
  58976. + struct simplelock *sl = (struct simplelock *)lock;
  58977. +
  58978. + DWC_FREE(sl);
  58979. +}
  58980. +
  58981. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  58982. +{
  58983. + simple_lock((struct simplelock *)lock);
  58984. +}
  58985. +
  58986. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  58987. +{
  58988. + simple_unlock((struct simplelock *)lock);
  58989. +}
  58990. +
  58991. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  58992. +{
  58993. + simple_lock((struct simplelock *)lock);
  58994. + *flags = splbio();
  58995. +}
  58996. +
  58997. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  58998. +{
  58999. + splx(flags);
  59000. + simple_unlock((struct simplelock *)lock);
  59001. +}
  59002. +
  59003. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  59004. +{
  59005. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  59006. +
  59007. + if (!mutex) {
  59008. + DWC_ERROR("Cannot allocate memory for mutex");
  59009. + return NULL;
  59010. + }
  59011. +
  59012. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  59013. + return mutex;
  59014. +}
  59015. +
  59016. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  59017. +#else
  59018. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  59019. +{
  59020. + DWC_FREE(mutex);
  59021. +}
  59022. +#endif
  59023. +
  59024. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  59025. +{
  59026. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  59027. +}
  59028. +
  59029. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  59030. +{
  59031. + int status;
  59032. +
  59033. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  59034. + return status == 0;
  59035. +}
  59036. +
  59037. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  59038. +{
  59039. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  59040. +}
  59041. +
  59042. +
  59043. +/* Timing */
  59044. +
  59045. +void DWC_UDELAY(uint32_t usecs)
  59046. +{
  59047. + DELAY(usecs);
  59048. +}
  59049. +
  59050. +void DWC_MDELAY(uint32_t msecs)
  59051. +{
  59052. + do {
  59053. + DELAY(1000);
  59054. + } while (--msecs);
  59055. +}
  59056. +
  59057. +void DWC_MSLEEP(uint32_t msecs)
  59058. +{
  59059. + struct timeval tv;
  59060. +
  59061. + tv.tv_sec = msecs / 1000;
  59062. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  59063. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  59064. +}
  59065. +
  59066. +uint32_t DWC_TIME(void)
  59067. +{
  59068. + struct timeval tv;
  59069. +
  59070. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  59071. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  59072. +}
  59073. +
  59074. +
  59075. +/* Timers */
  59076. +
  59077. +struct dwc_timer {
  59078. + struct callout t;
  59079. + char *name;
  59080. + dwc_spinlock_t *lock;
  59081. + dwc_timer_callback_t cb;
  59082. + void *data;
  59083. +};
  59084. +
  59085. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  59086. +{
  59087. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  59088. +
  59089. + if (!t) {
  59090. + DWC_ERROR("Cannot allocate memory for timer");
  59091. + return NULL;
  59092. + }
  59093. +
  59094. + callout_init(&t->t);
  59095. +
  59096. + t->name = DWC_STRDUP(name);
  59097. + if (!t->name) {
  59098. + DWC_ERROR("Cannot allocate memory for timer->name");
  59099. + goto no_name;
  59100. + }
  59101. +
  59102. + t->lock = DWC_SPINLOCK_ALLOC();
  59103. + if (!t->lock) {
  59104. + DWC_ERROR("Cannot allocate memory for timer->lock");
  59105. + goto no_lock;
  59106. + }
  59107. +
  59108. + t->cb = cb;
  59109. + t->data = data;
  59110. +
  59111. + return t;
  59112. +
  59113. + no_lock:
  59114. + DWC_FREE(t->name);
  59115. + no_name:
  59116. + DWC_FREE(t);
  59117. +
  59118. + return NULL;
  59119. +}
  59120. +
  59121. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  59122. +{
  59123. + callout_stop(&timer->t);
  59124. + DWC_SPINLOCK_FREE(timer->lock);
  59125. + DWC_FREE(timer->name);
  59126. + DWC_FREE(timer);
  59127. +}
  59128. +
  59129. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  59130. +{
  59131. + struct timeval tv;
  59132. +
  59133. + tv.tv_sec = time / 1000;
  59134. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  59135. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  59136. +}
  59137. +
  59138. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  59139. +{
  59140. + callout_stop(&timer->t);
  59141. +}
  59142. +
  59143. +
  59144. +/* Wait Queues */
  59145. +
  59146. +struct dwc_waitq {
  59147. + struct simplelock lock;
  59148. + int abort;
  59149. +};
  59150. +
  59151. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  59152. +{
  59153. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  59154. +
  59155. + if (!wq) {
  59156. + DWC_ERROR("Cannot allocate memory for waitqueue");
  59157. + return NULL;
  59158. + }
  59159. +
  59160. + simple_lock_init(&wq->lock);
  59161. + wq->abort = 0;
  59162. +
  59163. + return wq;
  59164. +}
  59165. +
  59166. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  59167. +{
  59168. + DWC_FREE(wq);
  59169. +}
  59170. +
  59171. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  59172. +{
  59173. + int ipl;
  59174. + int result = 0;
  59175. +
  59176. + simple_lock(&wq->lock);
  59177. + ipl = splbio();
  59178. +
  59179. + /* Skip the sleep if already aborted or triggered */
  59180. + if (!wq->abort && !cond(data)) {
  59181. + splx(ipl);
  59182. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  59183. + ipl = splbio();
  59184. + }
  59185. +
  59186. + if (result == 0) { // awoken
  59187. + if (wq->abort) {
  59188. + wq->abort = 0;
  59189. + result = -DWC_E_ABORT;
  59190. + } else {
  59191. + result = 0;
  59192. + }
  59193. +
  59194. + splx(ipl);
  59195. + simple_unlock(&wq->lock);
  59196. + } else {
  59197. + wq->abort = 0;
  59198. + splx(ipl);
  59199. + simple_unlock(&wq->lock);
  59200. +
  59201. + if (result == ERESTART) { // signaled - restart
  59202. + result = -DWC_E_RESTART;
  59203. + } else { // signaled - must be EINTR
  59204. + result = -DWC_E_ABORT;
  59205. + }
  59206. + }
  59207. +
  59208. + return result;
  59209. +}
  59210. +
  59211. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  59212. + void *data, int32_t msecs)
  59213. +{
  59214. + struct timeval tv, tv1, tv2;
  59215. + int ipl;
  59216. + int result = 0;
  59217. +
  59218. + tv.tv_sec = msecs / 1000;
  59219. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  59220. +
  59221. + simple_lock(&wq->lock);
  59222. + ipl = splbio();
  59223. +
  59224. + /* Skip the sleep if already aborted or triggered */
  59225. + if (!wq->abort && !cond(data)) {
  59226. + splx(ipl);
  59227. + getmicrouptime(&tv1);
  59228. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  59229. + getmicrouptime(&tv2);
  59230. + ipl = splbio();
  59231. + }
  59232. +
  59233. + if (result == 0) { // awoken
  59234. + if (wq->abort) {
  59235. + wq->abort = 0;
  59236. + splx(ipl);
  59237. + simple_unlock(&wq->lock);
  59238. + result = -DWC_E_ABORT;
  59239. + } else {
  59240. + splx(ipl);
  59241. + simple_unlock(&wq->lock);
  59242. +
  59243. + tv2.tv_usec -= tv1.tv_usec;
  59244. + if (tv2.tv_usec < 0) {
  59245. + tv2.tv_usec += 1000000;
  59246. + tv2.tv_sec--;
  59247. + }
  59248. +
  59249. + tv2.tv_sec -= tv1.tv_sec;
  59250. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  59251. + result = msecs - result;
  59252. + if (result <= 0)
  59253. + result = 1;
  59254. + }
  59255. + } else {
  59256. + wq->abort = 0;
  59257. + splx(ipl);
  59258. + simple_unlock(&wq->lock);
  59259. +
  59260. + if (result == ERESTART) { // signaled - restart
  59261. + result = -DWC_E_RESTART;
  59262. +
  59263. + } else if (result == EINTR) { // signaled - interrupt
  59264. + result = -DWC_E_ABORT;
  59265. +
  59266. + } else { // timed out
  59267. + result = -DWC_E_TIMEOUT;
  59268. + }
  59269. + }
  59270. +
  59271. + return result;
  59272. +}
  59273. +
  59274. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  59275. +{
  59276. + wakeup(wq);
  59277. +}
  59278. +
  59279. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  59280. +{
  59281. + int ipl;
  59282. +
  59283. + simple_lock(&wq->lock);
  59284. + ipl = splbio();
  59285. + wq->abort = 1;
  59286. + wakeup(wq);
  59287. + splx(ipl);
  59288. + simple_unlock(&wq->lock);
  59289. +}
  59290. +
  59291. +
  59292. +/* Threading */
  59293. +
  59294. +struct dwc_thread {
  59295. + struct proc *proc;
  59296. + int abort;
  59297. +};
  59298. +
  59299. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  59300. +{
  59301. + int retval;
  59302. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  59303. +
  59304. + if (!thread) {
  59305. + return NULL;
  59306. + }
  59307. +
  59308. + thread->abort = 0;
  59309. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  59310. + "%s", name);
  59311. + if (retval) {
  59312. + DWC_FREE(thread);
  59313. + return NULL;
  59314. + }
  59315. +
  59316. + return thread;
  59317. +}
  59318. +
  59319. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  59320. +{
  59321. + int retval;
  59322. +
  59323. + thread->abort = 1;
  59324. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  59325. +
  59326. + if (retval == 0) {
  59327. + /* DWC_THREAD_EXIT() will free the thread struct */
  59328. + return 0;
  59329. + }
  59330. +
  59331. + /* NOTE: We leak the thread struct if thread doesn't die */
  59332. +
  59333. + if (retval == EWOULDBLOCK) {
  59334. + return -DWC_E_TIMEOUT;
  59335. + }
  59336. +
  59337. + return -DWC_E_UNKNOWN;
  59338. +}
  59339. +
  59340. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  59341. +{
  59342. + return thread->abort;
  59343. +}
  59344. +
  59345. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  59346. +{
  59347. + wakeup(&thread->abort);
  59348. + DWC_FREE(thread);
  59349. + kthread_exit(0);
  59350. +}
  59351. +
  59352. +/* tasklets
  59353. + - Runs in interrupt context (cannot sleep)
  59354. + - Each tasklet runs on a single CPU
  59355. + - Different tasklets can be running simultaneously on different CPUs
  59356. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  59357. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  59358. + */
  59359. +struct dwc_tasklet {
  59360. + dwc_tasklet_callback_t cb;
  59361. + void *data;
  59362. +};
  59363. +
  59364. +static void tasklet_callback(void *data)
  59365. +{
  59366. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  59367. +
  59368. + task->cb(task->data);
  59369. +}
  59370. +
  59371. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  59372. +{
  59373. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  59374. +
  59375. + if (task) {
  59376. + task->cb = cb;
  59377. + task->data = data;
  59378. + } else {
  59379. + DWC_ERROR("Cannot allocate memory for tasklet");
  59380. + }
  59381. +
  59382. + return task;
  59383. +}
  59384. +
  59385. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  59386. +{
  59387. + DWC_FREE(task);
  59388. +}
  59389. +
  59390. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  59391. +{
  59392. + tasklet_callback(task);
  59393. +}
  59394. +
  59395. +
  59396. +/* workqueues
  59397. + - Runs in process context (can sleep)
  59398. + */
  59399. +typedef struct work_container {
  59400. + dwc_work_callback_t cb;
  59401. + void *data;
  59402. + dwc_workq_t *wq;
  59403. + char *name;
  59404. + int hz;
  59405. + struct work task;
  59406. +} work_container_t;
  59407. +
  59408. +struct dwc_workq {
  59409. + struct workqueue *taskq;
  59410. + dwc_spinlock_t *lock;
  59411. + dwc_waitq_t *waitq;
  59412. + int pending;
  59413. + struct work_container *container;
  59414. +};
  59415. +
  59416. +static void do_work(struct work *task, void *data)
  59417. +{
  59418. + dwc_workq_t *wq = (dwc_workq_t *)data;
  59419. + work_container_t *container = wq->container;
  59420. + dwc_irqflags_t flags;
  59421. +
  59422. + if (container->hz) {
  59423. + tsleep(container, 0, "dw3wrk", container->hz);
  59424. + }
  59425. +
  59426. + container->cb(container->data);
  59427. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  59428. +
  59429. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  59430. + if (container->name)
  59431. + DWC_FREE(container->name);
  59432. + DWC_FREE(container);
  59433. + wq->pending--;
  59434. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  59435. + DWC_WAITQ_TRIGGER(wq->waitq);
  59436. +}
  59437. +
  59438. +static int work_done(void *data)
  59439. +{
  59440. + dwc_workq_t *workq = (dwc_workq_t *)data;
  59441. +
  59442. + return workq->pending == 0;
  59443. +}
  59444. +
  59445. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  59446. +{
  59447. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  59448. +}
  59449. +
  59450. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  59451. +{
  59452. + int result;
  59453. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  59454. +
  59455. + if (!wq) {
  59456. + DWC_ERROR("Cannot allocate memory for workqueue");
  59457. + return NULL;
  59458. + }
  59459. +
  59460. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  59461. + IPL_BIO, 0);
  59462. + if (result) {
  59463. + DWC_ERROR("Cannot create workqueue");
  59464. + goto no_taskq;
  59465. + }
  59466. +
  59467. + wq->pending = 0;
  59468. +
  59469. + wq->lock = DWC_SPINLOCK_ALLOC();
  59470. + if (!wq->lock) {
  59471. + DWC_ERROR("Cannot allocate memory for spinlock");
  59472. + goto no_lock;
  59473. + }
  59474. +
  59475. + wq->waitq = DWC_WAITQ_ALLOC();
  59476. + if (!wq->waitq) {
  59477. + DWC_ERROR("Cannot allocate memory for waitqueue");
  59478. + goto no_waitq;
  59479. + }
  59480. +
  59481. + return wq;
  59482. +
  59483. + no_waitq:
  59484. + DWC_SPINLOCK_FREE(wq->lock);
  59485. + no_lock:
  59486. + workqueue_destroy(wq->taskq);
  59487. + no_taskq:
  59488. + DWC_FREE(wq);
  59489. +
  59490. + return NULL;
  59491. +}
  59492. +
  59493. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  59494. +{
  59495. +#ifdef DEBUG
  59496. + dwc_irqflags_t flags;
  59497. +
  59498. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  59499. +
  59500. + if (wq->pending != 0) {
  59501. + struct work_container *container = wq->container;
  59502. +
  59503. + DWC_ERROR("Destroying work queue with pending work");
  59504. +
  59505. + if (container && container->name) {
  59506. + DWC_ERROR("Work %s still pending", container->name);
  59507. + }
  59508. + }
  59509. +
  59510. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  59511. +#endif
  59512. + DWC_WAITQ_FREE(wq->waitq);
  59513. + DWC_SPINLOCK_FREE(wq->lock);
  59514. + workqueue_destroy(wq->taskq);
  59515. + DWC_FREE(wq);
  59516. +}
  59517. +
  59518. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  59519. + char *format, ...)
  59520. +{
  59521. + dwc_irqflags_t flags;
  59522. + work_container_t *container;
  59523. + static char name[128];
  59524. + va_list args;
  59525. +
  59526. + va_start(args, format);
  59527. + DWC_VSNPRINTF(name, 128, format, args);
  59528. + va_end(args);
  59529. +
  59530. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  59531. + wq->pending++;
  59532. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  59533. + DWC_WAITQ_TRIGGER(wq->waitq);
  59534. +
  59535. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  59536. + if (!container) {
  59537. + DWC_ERROR("Cannot allocate memory for container");
  59538. + return;
  59539. + }
  59540. +
  59541. + container->name = DWC_STRDUP(name);
  59542. + if (!container->name) {
  59543. + DWC_ERROR("Cannot allocate memory for container->name");
  59544. + DWC_FREE(container);
  59545. + return;
  59546. + }
  59547. +
  59548. + container->cb = cb;
  59549. + container->data = data;
  59550. + container->wq = wq;
  59551. + container->hz = 0;
  59552. + wq->container = container;
  59553. +
  59554. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  59555. + workqueue_enqueue(wq->taskq, &container->task);
  59556. +}
  59557. +
  59558. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  59559. + void *data, uint32_t time, char *format, ...)
  59560. +{
  59561. + dwc_irqflags_t flags;
  59562. + work_container_t *container;
  59563. + static char name[128];
  59564. + struct timeval tv;
  59565. + va_list args;
  59566. +
  59567. + va_start(args, format);
  59568. + DWC_VSNPRINTF(name, 128, format, args);
  59569. + va_end(args);
  59570. +
  59571. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  59572. + wq->pending++;
  59573. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  59574. + DWC_WAITQ_TRIGGER(wq->waitq);
  59575. +
  59576. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  59577. + if (!container) {
  59578. + DWC_ERROR("Cannot allocate memory for container");
  59579. + return;
  59580. + }
  59581. +
  59582. + container->name = DWC_STRDUP(name);
  59583. + if (!container->name) {
  59584. + DWC_ERROR("Cannot allocate memory for container->name");
  59585. + DWC_FREE(container);
  59586. + return;
  59587. + }
  59588. +
  59589. + container->cb = cb;
  59590. + container->data = data;
  59591. + container->wq = wq;
  59592. + tv.tv_sec = time / 1000;
  59593. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  59594. + container->hz = tvtohz(&tv);
  59595. + wq->container = container;
  59596. +
  59597. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  59598. + workqueue_enqueue(wq->taskq, &container->task);
  59599. +}
  59600. +
  59601. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  59602. +{
  59603. + return wq->pending;
  59604. +}
  59605. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  59606. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  59607. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2015-03-09 10:39:33.214893718 +0100
  59608. @@ -0,0 +1,308 @@
  59609. +/* =========================================================================
  59610. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  59611. + * $Revision: #5 $
  59612. + * $Date: 2010/09/28 $
  59613. + * $Change: 1596182 $
  59614. + *
  59615. + * Synopsys Portability Library Software and documentation
  59616. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59617. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59618. + * between Synopsys and you.
  59619. + *
  59620. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59621. + * under any End User Software License Agreement or Agreement for
  59622. + * Licensed Product with Synopsys or any supplement thereto. You are
  59623. + * permitted to use and redistribute this Software in source and binary
  59624. + * forms, with or without modification, provided that redistributions
  59625. + * of source code must retain this notice. You may not view, use,
  59626. + * disclose, copy or distribute this file or any information contained
  59627. + * herein except pursuant to this license grant from Synopsys. If you
  59628. + * do not agree with this notice, including the disclaimer below, then
  59629. + * you are not authorized to use the Software.
  59630. + *
  59631. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59632. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59633. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59634. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59635. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59636. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59637. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59638. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59639. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59640. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59641. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59642. + * DAMAGE.
  59643. + * ========================================================================= */
  59644. +
  59645. +/** @file
  59646. + * This file contains the WUSB cryptographic routines.
  59647. + */
  59648. +
  59649. +#ifdef DWC_CRYPTOLIB
  59650. +
  59651. +#include "dwc_crypto.h"
  59652. +#include "usb.h"
  59653. +
  59654. +#ifdef DEBUG
  59655. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  59656. +{
  59657. + int i;
  59658. + DWC_PRINTF("%s: ", name);
  59659. + for (i=0; i<len; i++) {
  59660. + DWC_PRINTF("%02x ", bytes[i]);
  59661. + }
  59662. + DWC_PRINTF("\n");
  59663. +}
  59664. +#else
  59665. +#define dump_bytes(x...)
  59666. +#endif
  59667. +
  59668. +/* Display a block */
  59669. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  59670. +{
  59671. +#ifdef DWC_DEBUG_CRYPTO
  59672. + int i, blksize = 16;
  59673. +
  59674. + DWC_DEBUG("%s", prefix);
  59675. +
  59676. + if (suffix == NULL) {
  59677. + suffix = "\n";
  59678. + blksize = a;
  59679. + }
  59680. +
  59681. + for (i = 0; i < blksize; i++)
  59682. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  59683. + DWC_PRINT(suffix);
  59684. +#endif
  59685. +}
  59686. +
  59687. +/**
  59688. + * Encrypts an array of bytes using the AES encryption engine.
  59689. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  59690. + * in-place.
  59691. + *
  59692. + * @return 0 on success, negative error code on error.
  59693. + */
  59694. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  59695. +{
  59696. + u8 block_t[16];
  59697. + DWC_MEMSET(block_t, 0, 16);
  59698. +
  59699. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  59700. +}
  59701. +
  59702. +/**
  59703. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  59704. + * This function takes a data string and returns the encrypted CBC
  59705. + * Counter-mode MIC.
  59706. + *
  59707. + * @param key The 128-bit symmetric key.
  59708. + * @param nonce The CCM nonce.
  59709. + * @param label The unique 14-byte ASCII text label.
  59710. + * @param bytes The byte array to be encrypted.
  59711. + * @param len Length of the byte array.
  59712. + * @param result Byte array to receive the 8-byte encrypted MIC.
  59713. + */
  59714. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  59715. + char *label, u8 *bytes, int len, u8 *result)
  59716. +{
  59717. + u8 block_m[16];
  59718. + u8 block_x[16];
  59719. + u8 block_t[8];
  59720. + int idx, blkNum;
  59721. + u16 la = (u16)(len + 14);
  59722. +
  59723. + /* Set the AES-128 key */
  59724. + //dwc_aes_setkey(tfm, key, 16);
  59725. +
  59726. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  59727. + block_m[0] = 0x59;
  59728. + for (idx = 0; idx < 13; idx++)
  59729. + block_m[idx + 1] = nonce[idx];
  59730. + block_m[14] = 0;
  59731. + block_m[15] = 0;
  59732. +
  59733. + /* Produce the CBC IV */
  59734. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  59735. + show_block(block_m, "CBC IV in: ", "\n", 0);
  59736. + show_block(block_x, "CBC IV out:", "\n", 0);
  59737. +
  59738. + /* Fill block B1 from l(a) = Blen + 14, and A */
  59739. + block_x[0] ^= (u8)(la >> 8);
  59740. + block_x[1] ^= (u8)la;
  59741. + for (idx = 0; idx < 14; idx++)
  59742. + block_x[idx + 2] ^= label[idx];
  59743. + show_block(block_x, "After xor: ", "b1\n", 16);
  59744. +
  59745. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59746. + show_block(block_x, "After AES: ", "b1\n", 16);
  59747. +
  59748. + idx = 0;
  59749. + blkNum = 0;
  59750. +
  59751. + /* Fill remaining blocks with B */
  59752. + while (len-- > 0) {
  59753. + block_x[idx] ^= *bytes++;
  59754. + if (++idx >= 16) {
  59755. + idx = 0;
  59756. + show_block(block_x, "After xor: ", "\n", blkNum);
  59757. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59758. + show_block(block_x, "After AES: ", "\n", blkNum);
  59759. + blkNum++;
  59760. + }
  59761. + }
  59762. +
  59763. + /* Handle partial last block */
  59764. + if (idx > 0) {
  59765. + show_block(block_x, "After xor: ", "\n", blkNum);
  59766. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  59767. + show_block(block_x, "After AES: ", "\n", blkNum);
  59768. + }
  59769. +
  59770. + /* Save the MIC tag */
  59771. + DWC_MEMCPY(block_t, block_x, 8);
  59772. + show_block(block_t, "MIC tag : ", NULL, 8);
  59773. +
  59774. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  59775. + block_m[0] = 0x01;
  59776. + block_m[14] = 0;
  59777. + block_m[15] = 0;
  59778. +
  59779. + /* Encrypt the counter */
  59780. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  59781. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  59782. +
  59783. + /* XOR with MIC tag */
  59784. + for (idx = 0; idx < 8; idx++) {
  59785. + block_t[idx] ^= block_x[idx];
  59786. + }
  59787. +
  59788. + /* Return result to caller */
  59789. + DWC_MEMCPY(result, block_t, 8);
  59790. + show_block(result, "CCM-MIC : ", NULL, 8);
  59791. +
  59792. +}
  59793. +
  59794. +/**
  59795. + * The PRF function described in section 6.5 of the WUSB spec. This function
  59796. + * concatenates MIC values returned from dwc_cmf() to create a value of
  59797. + * the requested length.
  59798. + *
  59799. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  59800. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  59801. + * @param result Byte array to receive the result.
  59802. + */
  59803. +void dwc_wusb_prf(int prf_len, u8 *key,
  59804. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  59805. +{
  59806. + int i;
  59807. +
  59808. + nonce[0] = 0;
  59809. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  59810. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  59811. + result += 8;
  59812. + }
  59813. +}
  59814. +
  59815. +/**
  59816. + * Fills in CCM Nonce per the WUSB spec.
  59817. + *
  59818. + * @param[in] haddr Host address.
  59819. + * @param[in] daddr Device address.
  59820. + * @param[in] tkid Session Key(PTK) identifier.
  59821. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  59822. + */
  59823. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  59824. + uint8_t *nonce)
  59825. +{
  59826. +
  59827. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  59828. +
  59829. + DWC_MEMSET(&nonce[0], 0, 16);
  59830. +
  59831. + DWC_MEMCPY(&nonce[6], tkid, 3);
  59832. + nonce[9] = daddr & 0xFF;
  59833. + nonce[10] = (daddr >> 8) & 0xFF;
  59834. + nonce[11] = haddr & 0xFF;
  59835. + nonce[12] = (haddr >> 8) & 0xFF;
  59836. +
  59837. + dump_bytes("CCM nonce", nonce, 16);
  59838. +}
  59839. +
  59840. +/**
  59841. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  59842. + * Nonce.
  59843. + */
  59844. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  59845. +{
  59846. + uint8_t inonce[16];
  59847. + uint32_t temp[4];
  59848. +
  59849. + /* Fill in the Nonce */
  59850. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  59851. + inonce[9] = addr & 0xFF;
  59852. + inonce[10] = (addr >> 8) & 0xFF;
  59853. + inonce[11] = inonce[9];
  59854. + inonce[12] = inonce[10];
  59855. +
  59856. + /* Collect "randomness samples" */
  59857. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  59858. +
  59859. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  59860. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  59861. + nonce);
  59862. +}
  59863. +
  59864. +/**
  59865. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  59866. + * WUSB spec.
  59867. + *
  59868. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  59869. + * @param[in] mk Master Key to derive the session from
  59870. + * @param[in] hnonce Pointer to Host Nonce.
  59871. + * @param[in] dnonce Pointer to Device Nonce.
  59872. + * @param[out] kck Pointer to where the KCK output is to be written.
  59873. + * @param[out] ptk Pointer to where the PTK output is to be written.
  59874. + */
  59875. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  59876. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  59877. +{
  59878. + uint8_t idata[32];
  59879. + uint8_t odata[32];
  59880. +
  59881. + dump_bytes("ck", mk, 16);
  59882. + dump_bytes("hnonce", hnonce, 16);
  59883. + dump_bytes("dnonce", dnonce, 16);
  59884. +
  59885. + /* The data is the HNonce and DNonce concatenated */
  59886. + DWC_MEMCPY(&idata[0], hnonce, 16);
  59887. + DWC_MEMCPY(&idata[16], dnonce, 16);
  59888. +
  59889. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  59890. +
  59891. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  59892. + DWC_MEMCPY(kck, &odata[0], 16);
  59893. + DWC_MEMCPY(ptk, &odata[16], 16);
  59894. +
  59895. + dump_bytes("kck", kck, 16);
  59896. + dump_bytes("ptk", ptk, 16);
  59897. +}
  59898. +
  59899. +/**
  59900. + * Generates the Message Integrity Code over the Handshake data per the
  59901. + * WUSB spec.
  59902. + *
  59903. + * @param ccm_nonce Pointer to CCM Nonce.
  59904. + * @param kck Pointer to Key Confirmation Key.
  59905. + * @param data Pointer to Handshake data to be checked.
  59906. + * @param mic Pointer to where the MIC output is to be written.
  59907. + */
  59908. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  59909. + uint8_t *data, uint8_t *mic)
  59910. +{
  59911. +
  59912. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  59913. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  59914. +}
  59915. +
  59916. +#endif /* DWC_CRYPTOLIB */
  59917. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  59918. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  59919. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2015-03-09 10:39:33.214893718 +0100
  59920. @@ -0,0 +1,111 @@
  59921. +/* =========================================================================
  59922. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  59923. + * $Revision: #3 $
  59924. + * $Date: 2010/09/28 $
  59925. + * $Change: 1596182 $
  59926. + *
  59927. + * Synopsys Portability Library Software and documentation
  59928. + * (hereinafter, "Software") is an Unsupported proprietary work of
  59929. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  59930. + * between Synopsys and you.
  59931. + *
  59932. + * The Software IS NOT an item of Licensed Software or Licensed Product
  59933. + * under any End User Software License Agreement or Agreement for
  59934. + * Licensed Product with Synopsys or any supplement thereto. You are
  59935. + * permitted to use and redistribute this Software in source and binary
  59936. + * forms, with or without modification, provided that redistributions
  59937. + * of source code must retain this notice. You may not view, use,
  59938. + * disclose, copy or distribute this file or any information contained
  59939. + * herein except pursuant to this license grant from Synopsys. If you
  59940. + * do not agree with this notice, including the disclaimer below, then
  59941. + * you are not authorized to use the Software.
  59942. + *
  59943. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  59944. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  59945. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  59946. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  59947. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  59948. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  59949. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  59950. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  59951. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59952. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  59953. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  59954. + * DAMAGE.
  59955. + * ========================================================================= */
  59956. +
  59957. +#ifndef _DWC_CRYPTO_H_
  59958. +#define _DWC_CRYPTO_H_
  59959. +
  59960. +#ifdef __cplusplus
  59961. +extern "C" {
  59962. +#endif
  59963. +
  59964. +/** @file
  59965. + *
  59966. + * This file contains declarations for the WUSB Cryptographic routines as
  59967. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  59968. + * modules.
  59969. + */
  59970. +
  59971. +#include "dwc_os.h"
  59972. +
  59973. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  59974. +
  59975. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  59976. + char *label, u8 *bytes, int len, u8 *result);
  59977. +void dwc_wusb_prf(int prf_len, u8 *key,
  59978. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  59979. +
  59980. +/**
  59981. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  59982. + *
  59983. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  59984. + */
  59985. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  59986. + char *label, u8 *bytes, int len, u8 *result)
  59987. +{
  59988. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  59989. +}
  59990. +
  59991. +/**
  59992. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  59993. + *
  59994. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  59995. + */
  59996. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  59997. + char *label, u8 *bytes, int len, u8 *result)
  59998. +{
  59999. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  60000. +}
  60001. +
  60002. +/**
  60003. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  60004. + *
  60005. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  60006. + */
  60007. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  60008. + char *label, u8 *bytes, int len, u8 *result)
  60009. +{
  60010. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  60011. +}
  60012. +
  60013. +
  60014. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  60015. + uint8_t *nonce);
  60016. +void dwc_wusb_gen_nonce(uint16_t addr,
  60017. + uint8_t *nonce);
  60018. +
  60019. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  60020. + uint8_t *hnonce, uint8_t *dnonce,
  60021. + uint8_t *kck, uint8_t *ptk);
  60022. +
  60023. +
  60024. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  60025. + *kck, uint8_t *data, uint8_t *mic);
  60026. +
  60027. +#ifdef __cplusplus
  60028. +}
  60029. +#endif
  60030. +
  60031. +#endif /* _DWC_CRYPTO_H_ */
  60032. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  60033. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  60034. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2015-03-09 10:39:33.214893718 +0100
  60035. @@ -0,0 +1,291 @@
  60036. +/* =========================================================================
  60037. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  60038. + * $Revision: #3 $
  60039. + * $Date: 2010/09/28 $
  60040. + * $Change: 1596182 $
  60041. + *
  60042. + * Synopsys Portability Library Software and documentation
  60043. + * (hereinafter, "Software") is an Unsupported proprietary work of
  60044. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  60045. + * between Synopsys and you.
  60046. + *
  60047. + * The Software IS NOT an item of Licensed Software or Licensed Product
  60048. + * under any End User Software License Agreement or Agreement for
  60049. + * Licensed Product with Synopsys or any supplement thereto. You are
  60050. + * permitted to use and redistribute this Software in source and binary
  60051. + * forms, with or without modification, provided that redistributions
  60052. + * of source code must retain this notice. You may not view, use,
  60053. + * disclose, copy or distribute this file or any information contained
  60054. + * herein except pursuant to this license grant from Synopsys. If you
  60055. + * do not agree with this notice, including the disclaimer below, then
  60056. + * you are not authorized to use the Software.
  60057. + *
  60058. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  60059. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  60060. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  60061. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  60062. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  60063. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  60064. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  60065. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  60066. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  60067. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  60068. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  60069. + * DAMAGE.
  60070. + * ========================================================================= */
  60071. +#ifdef DWC_CRYPTOLIB
  60072. +
  60073. +#ifndef CONFIG_MACH_IPMATE
  60074. +
  60075. +#include "dwc_dh.h"
  60076. +#include "dwc_modpow.h"
  60077. +
  60078. +#ifdef DEBUG
  60079. +/* This function prints out a buffer in the format described in the Association
  60080. + * Model specification. */
  60081. +static void dh_dump(char *str, void *_num, int len)
  60082. +{
  60083. + uint8_t *num = _num;
  60084. + int i;
  60085. + DWC_PRINTF("%s\n", str);
  60086. + for (i = 0; i < len; i ++) {
  60087. + DWC_PRINTF("%02x", num[i]);
  60088. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  60089. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  60090. + }
  60091. +
  60092. + DWC_PRINTF("\n");
  60093. +}
  60094. +#else
  60095. +#define dh_dump(_x...) do {; } while(0)
  60096. +#endif
  60097. +
  60098. +/* Constant g value */
  60099. +static __u32 dh_g[] = {
  60100. + 0x02000000,
  60101. +};
  60102. +
  60103. +/* Constant p value */
  60104. +static __u32 dh_p[] = {
  60105. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  60106. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  60107. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  60108. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  60109. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  60110. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  60111. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  60112. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  60113. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  60114. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  60115. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  60116. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  60117. +};
  60118. +
  60119. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  60120. +{
  60121. + uint8_t *in = _in;
  60122. + uint8_t *out = _out;
  60123. + int i;
  60124. + for (i=0; i<len; i++) {
  60125. + out[i] = in[len-1-i];
  60126. + }
  60127. +}
  60128. +
  60129. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  60130. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  60131. + * of 4. */
  60132. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  60133. + void *exp, uint32_t exp_len,
  60134. + void *mod, uint32_t mod_len,
  60135. + void *out)
  60136. +{
  60137. + /* modpow() takes little endian numbers. AM uses big-endian. This
  60138. + * function swaps bytes of numbers before passing onto modpow. */
  60139. +
  60140. + int retval = 0;
  60141. + uint32_t *result;
  60142. +
  60143. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  60144. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  60145. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  60146. +
  60147. + dh_swap_bytes(num, &bignum_num[1], num_len);
  60148. + bignum_num[0] = num_len / 4;
  60149. +
  60150. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  60151. + bignum_exp[0] = exp_len / 4;
  60152. +
  60153. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  60154. + bignum_mod[0] = mod_len / 4;
  60155. +
  60156. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  60157. + if (!result) {
  60158. + retval = -1;
  60159. + goto dh_modpow_nomem;
  60160. + }
  60161. +
  60162. + dh_swap_bytes(&result[1], out, result[0] * 4);
  60163. + dwc_free(mem_ctx, result);
  60164. +
  60165. + dh_modpow_nomem:
  60166. + dwc_free(mem_ctx, bignum_num);
  60167. + dwc_free(mem_ctx, bignum_exp);
  60168. + dwc_free(mem_ctx, bignum_mod);
  60169. + return retval;
  60170. +}
  60171. +
  60172. +
  60173. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  60174. +{
  60175. + int retval;
  60176. + uint8_t m3[385];
  60177. +
  60178. +#ifndef DH_TEST_VECTORS
  60179. + DWC_RANDOM_BYTES(exp, 32);
  60180. +#endif
  60181. +
  60182. + /* Compute the pkd */
  60183. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  60184. + exp, 32,
  60185. + dh_p, 384, pk))) {
  60186. + return retval;
  60187. + }
  60188. +
  60189. + m3[384] = nd;
  60190. + DWC_MEMCPY(&m3[0], pk, 384);
  60191. + DWC_SHA256(m3, 385, hash);
  60192. +
  60193. + dh_dump("PK", pk, 384);
  60194. + dh_dump("SHA-256(M3)", hash, 32);
  60195. + return 0;
  60196. +}
  60197. +
  60198. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  60199. + uint8_t *exp, int is_host,
  60200. + char *dd, uint8_t *ck, uint8_t *kdk)
  60201. +{
  60202. + int retval;
  60203. + uint8_t mv[784];
  60204. + uint8_t sha_result[32];
  60205. + uint8_t dhkey[384];
  60206. + uint8_t shared_secret[384];
  60207. + char *message;
  60208. + uint32_t vd;
  60209. +
  60210. + uint8_t *pk;
  60211. +
  60212. + if (is_host) {
  60213. + pk = pkd;
  60214. + }
  60215. + else {
  60216. + pk = pkh;
  60217. + }
  60218. +
  60219. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  60220. + exp, 32,
  60221. + dh_p, 384, shared_secret))) {
  60222. + return retval;
  60223. + }
  60224. + dh_dump("Shared Secret", shared_secret, 384);
  60225. +
  60226. + DWC_SHA256(shared_secret, 384, dhkey);
  60227. + dh_dump("DHKEY", dhkey, 384);
  60228. +
  60229. + DWC_MEMCPY(&mv[0], pkd, 384);
  60230. + DWC_MEMCPY(&mv[384], pkh, 384);
  60231. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  60232. + dh_dump("MV", mv, 784);
  60233. +
  60234. + DWC_SHA256(mv, 784, sha_result);
  60235. + dh_dump("SHA-256(MV)", sha_result, 32);
  60236. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  60237. +
  60238. + dh_swap_bytes(sha_result, &vd, 4);
  60239. +#ifdef DEBUG
  60240. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  60241. +#endif
  60242. +
  60243. + switch (nd) {
  60244. + case 2:
  60245. + vd = vd % 100;
  60246. + DWC_SPRINTF(dd, "%02d", vd);
  60247. + break;
  60248. + case 3:
  60249. + vd = vd % 1000;
  60250. + DWC_SPRINTF(dd, "%03d", vd);
  60251. + break;
  60252. + case 4:
  60253. + vd = vd % 10000;
  60254. + DWC_SPRINTF(dd, "%04d", vd);
  60255. + break;
  60256. + }
  60257. +#ifdef DEBUG
  60258. + DWC_PRINTF("Display Digits: %s\n", dd);
  60259. +#endif
  60260. +
  60261. + message = "connection key";
  60262. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  60263. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  60264. + DWC_MEMCPY(ck, sha_result, 16);
  60265. +
  60266. + message = "key derivation key";
  60267. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  60268. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  60269. + DWC_MEMCPY(kdk, sha_result, 32);
  60270. +
  60271. + return 0;
  60272. +}
  60273. +
  60274. +
  60275. +#ifdef DH_TEST_VECTORS
  60276. +
  60277. +static __u8 dh_a[] = {
  60278. + 0x44, 0x00, 0x51, 0xd6,
  60279. + 0xf0, 0xb5, 0x5e, 0xa9,
  60280. + 0x67, 0xab, 0x31, 0xc6,
  60281. + 0x8a, 0x8b, 0x5e, 0x37,
  60282. + 0xd9, 0x10, 0xda, 0xe0,
  60283. + 0xe2, 0xd4, 0x59, 0xa4,
  60284. + 0x86, 0x45, 0x9c, 0xaa,
  60285. + 0xdf, 0x36, 0x75, 0x16,
  60286. +};
  60287. +
  60288. +static __u8 dh_b[] = {
  60289. + 0x5d, 0xae, 0xc7, 0x86,
  60290. + 0x79, 0x80, 0xa3, 0x24,
  60291. + 0x8c, 0xe3, 0x57, 0x8f,
  60292. + 0xc7, 0x5f, 0x1b, 0x0f,
  60293. + 0x2d, 0xf8, 0x9d, 0x30,
  60294. + 0x6f, 0xa4, 0x52, 0xcd,
  60295. + 0xe0, 0x7a, 0x04, 0x8a,
  60296. + 0xde, 0xd9, 0x26, 0x56,
  60297. +};
  60298. +
  60299. +void dwc_run_dh_test_vectors(void *mem_ctx)
  60300. +{
  60301. + uint8_t pkd[384];
  60302. + uint8_t pkh[384];
  60303. + uint8_t hashd[32];
  60304. + uint8_t hashh[32];
  60305. + uint8_t ck[16];
  60306. + uint8_t kdk[32];
  60307. + char dd[5];
  60308. +
  60309. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  60310. +
  60311. + /* compute the PKd and SHA-256(PKd || Nd) */
  60312. + DWC_PRINTF("Computing PKd\n");
  60313. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  60314. +
  60315. + /* compute the PKd and SHA-256(PKh || Nd) */
  60316. + DWC_PRINTF("Computing PKh\n");
  60317. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  60318. +
  60319. + /* compute the dhkey */
  60320. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  60321. +}
  60322. +#endif /* DH_TEST_VECTORS */
  60323. +
  60324. +#endif /* !CONFIG_MACH_IPMATE */
  60325. +
  60326. +#endif /* DWC_CRYPTOLIB */
  60327. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  60328. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  60329. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2015-03-09 10:39:33.214893718 +0100
  60330. @@ -0,0 +1,106 @@
  60331. +/* =========================================================================
  60332. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  60333. + * $Revision: #4 $
  60334. + * $Date: 2010/09/28 $
  60335. + * $Change: 1596182 $
  60336. + *
  60337. + * Synopsys Portability Library Software and documentation
  60338. + * (hereinafter, "Software") is an Unsupported proprietary work of
  60339. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  60340. + * between Synopsys and you.
  60341. + *
  60342. + * The Software IS NOT an item of Licensed Software or Licensed Product
  60343. + * under any End User Software License Agreement or Agreement for
  60344. + * Licensed Product with Synopsys or any supplement thereto. You are
  60345. + * permitted to use and redistribute this Software in source and binary
  60346. + * forms, with or without modification, provided that redistributions
  60347. + * of source code must retain this notice. You may not view, use,
  60348. + * disclose, copy or distribute this file or any information contained
  60349. + * herein except pursuant to this license grant from Synopsys. If you
  60350. + * do not agree with this notice, including the disclaimer below, then
  60351. + * you are not authorized to use the Software.
  60352. + *
  60353. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  60354. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  60355. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  60356. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  60357. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  60358. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  60359. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  60360. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  60361. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  60362. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  60363. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  60364. + * DAMAGE.
  60365. + * ========================================================================= */
  60366. +#ifndef _DWC_DH_H_
  60367. +#define _DWC_DH_H_
  60368. +
  60369. +#ifdef __cplusplus
  60370. +extern "C" {
  60371. +#endif
  60372. +
  60373. +#include "dwc_os.h"
  60374. +
  60375. +/** @file
  60376. + *
  60377. + * This file defines the common functions on device and host for performing
  60378. + * numeric association as defined in the WUSB spec. They are only to be
  60379. + * used internally by the DWC UWB modules. */
  60380. +
  60381. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  60382. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  60383. + uint8_t *key, uint32_t keylen,
  60384. + uint8_t *out);
  60385. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  60386. + void *exp, uint32_t exp_len,
  60387. + void *mod, uint32_t mod_len,
  60388. + void *out);
  60389. +
  60390. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  60391. + *
  60392. + * PK = g^exp mod p.
  60393. + *
  60394. + * Input:
  60395. + * Nd = Number of digits on the device.
  60396. + *
  60397. + * Output:
  60398. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  60399. + * used as either A or B.
  60400. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  60401. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  60402. + */
  60403. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  60404. +
  60405. +/** Computes the DHKEY, and VD.
  60406. + *
  60407. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  60408. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  60409. + *
  60410. + * Input:
  60411. + * pkd = The PKD value.
  60412. + * pkh = The PKH value.
  60413. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  60414. + * is_host = Set to non zero if a WUSB host is calling this function.
  60415. + *
  60416. + * Output:
  60417. +
  60418. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  60419. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  60420. + * null termination character. This buffer can be used directly for display.
  60421. + * ck = A 16-byte buffer to be filled with the CK.
  60422. + * kdk = A 32-byte buffer to be filled with the KDK.
  60423. + */
  60424. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  60425. + uint8_t *exp, int is_host,
  60426. + char *dd, uint8_t *ck, uint8_t *kdk);
  60427. +
  60428. +#ifdef DH_TEST_VECTORS
  60429. +extern void dwc_run_dh_test_vectors(void);
  60430. +#endif
  60431. +
  60432. +#ifdef __cplusplus
  60433. +}
  60434. +#endif
  60435. +
  60436. +#endif /* _DWC_DH_H_ */
  60437. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  60438. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  60439. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2015-03-09 10:39:33.214893718 +0100
  60440. @@ -0,0 +1,594 @@
  60441. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  60442. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  60443. +
  60444. +/*
  60445. + * Copyright (c) 1991, 1993
  60446. + * The Regents of the University of California. All rights reserved.
  60447. + *
  60448. + * Redistribution and use in source and binary forms, with or without
  60449. + * modification, are permitted provided that the following conditions
  60450. + * are met:
  60451. + * 1. Redistributions of source code must retain the above copyright
  60452. + * notice, this list of conditions and the following disclaimer.
  60453. + * 2. Redistributions in binary form must reproduce the above copyright
  60454. + * notice, this list of conditions and the following disclaimer in the
  60455. + * documentation and/or other materials provided with the distribution.
  60456. + * 3. Neither the name of the University nor the names of its contributors
  60457. + * may be used to endorse or promote products derived from this software
  60458. + * without specific prior written permission.
  60459. + *
  60460. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  60461. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  60462. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  60463. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  60464. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  60465. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  60466. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60467. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  60468. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  60469. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  60470. + * SUCH DAMAGE.
  60471. + *
  60472. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  60473. + */
  60474. +
  60475. +#ifndef _DWC_LIST_H_
  60476. +#define _DWC_LIST_H_
  60477. +
  60478. +#ifdef __cplusplus
  60479. +extern "C" {
  60480. +#endif
  60481. +
  60482. +/** @file
  60483. + *
  60484. + * This file defines linked list operations. It is derived from BSD with
  60485. + * only the MACRO names being prefixed with DWC_. This is because a few of
  60486. + * these names conflict with those on Linux. For documentation on use, see the
  60487. + * inline comments in the source code. The original license for this source
  60488. + * code applies and is preserved in the dwc_list.h source file.
  60489. + */
  60490. +
  60491. +/*
  60492. + * This file defines five types of data structures: singly-linked lists,
  60493. + * lists, simple queues, tail queues, and circular queues.
  60494. + *
  60495. + *
  60496. + * A singly-linked list is headed by a single forward pointer. The elements
  60497. + * are singly linked for minimum space and pointer manipulation overhead at
  60498. + * the expense of O(n) removal for arbitrary elements. New elements can be
  60499. + * added to the list after an existing element or at the head of the list.
  60500. + * Elements being removed from the head of the list should use the explicit
  60501. + * macro for this purpose for optimum efficiency. A singly-linked list may
  60502. + * only be traversed in the forward direction. Singly-linked lists are ideal
  60503. + * for applications with large datasets and few or no removals or for
  60504. + * implementing a LIFO queue.
  60505. + *
  60506. + * A list is headed by a single forward pointer (or an array of forward
  60507. + * pointers for a hash table header). The elements are doubly linked
  60508. + * so that an arbitrary element can be removed without a need to
  60509. + * traverse the list. New elements can be added to the list before
  60510. + * or after an existing element or at the head of the list. A list
  60511. + * may only be traversed in the forward direction.
  60512. + *
  60513. + * A simple queue is headed by a pair of pointers, one the head of the
  60514. + * list and the other to the tail of the list. The elements are singly
  60515. + * linked to save space, so elements can only be removed from the
  60516. + * head of the list. New elements can be added to the list before or after
  60517. + * an existing element, at the head of the list, or at the end of the
  60518. + * list. A simple queue may only be traversed in the forward direction.
  60519. + *
  60520. + * A tail queue is headed by a pair of pointers, one to the head of the
  60521. + * list and the other to the tail of the list. The elements are doubly
  60522. + * linked so that an arbitrary element can be removed without a need to
  60523. + * traverse the list. New elements can be added to the list before or
  60524. + * after an existing element, at the head of the list, or at the end of
  60525. + * the list. A tail queue may be traversed in either direction.
  60526. + *
  60527. + * A circle queue is headed by a pair of pointers, one to the head of the
  60528. + * list and the other to the tail of the list. The elements are doubly
  60529. + * linked so that an arbitrary element can be removed without a need to
  60530. + * traverse the list. New elements can be added to the list before or after
  60531. + * an existing element, at the head of the list, or at the end of the list.
  60532. + * A circle queue may be traversed in either direction, but has a more
  60533. + * complex end of list detection.
  60534. + *
  60535. + * For details on the use of these macros, see the queue(3) manual page.
  60536. + */
  60537. +
  60538. +/*
  60539. + * Double-linked List.
  60540. + */
  60541. +
  60542. +typedef struct dwc_list_link {
  60543. + struct dwc_list_link *next;
  60544. + struct dwc_list_link *prev;
  60545. +} dwc_list_link_t;
  60546. +
  60547. +#define DWC_LIST_INIT(link) do { \
  60548. + (link)->next = (link); \
  60549. + (link)->prev = (link); \
  60550. +} while (0)
  60551. +
  60552. +#define DWC_LIST_FIRST(link) ((link)->next)
  60553. +#define DWC_LIST_LAST(link) ((link)->prev)
  60554. +#define DWC_LIST_END(link) (link)
  60555. +#define DWC_LIST_NEXT(link) ((link)->next)
  60556. +#define DWC_LIST_PREV(link) ((link)->prev)
  60557. +#define DWC_LIST_EMPTY(link) \
  60558. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  60559. +#define DWC_LIST_ENTRY(link, type, field) \
  60560. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  60561. +
  60562. +#if 0
  60563. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  60564. + (link)->next = (list)->next; \
  60565. + (link)->prev = (list); \
  60566. + (list)->next->prev = (link); \
  60567. + (list)->next = (link); \
  60568. +} while (0)
  60569. +
  60570. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  60571. + (link)->next = (list); \
  60572. + (link)->prev = (list)->prev; \
  60573. + (list)->prev->next = (link); \
  60574. + (list)->prev = (link); \
  60575. +} while (0)
  60576. +#else
  60577. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  60578. + dwc_list_link_t *__next__ = (list)->next; \
  60579. + __next__->prev = (link); \
  60580. + (link)->next = __next__; \
  60581. + (link)->prev = (list); \
  60582. + (list)->next = (link); \
  60583. +} while (0)
  60584. +
  60585. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  60586. + dwc_list_link_t *__prev__ = (list)->prev; \
  60587. + (list)->prev = (link); \
  60588. + (link)->next = (list); \
  60589. + (link)->prev = __prev__; \
  60590. + __prev__->next = (link); \
  60591. +} while (0)
  60592. +#endif
  60593. +
  60594. +#if 0
  60595. +static inline void __list_add(struct list_head *new,
  60596. + struct list_head *prev,
  60597. + struct list_head *next)
  60598. +{
  60599. + next->prev = new;
  60600. + new->next = next;
  60601. + new->prev = prev;
  60602. + prev->next = new;
  60603. +}
  60604. +
  60605. +static inline void list_add(struct list_head *new, struct list_head *head)
  60606. +{
  60607. + __list_add(new, head, head->next);
  60608. +}
  60609. +
  60610. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  60611. +{
  60612. + __list_add(new, head->prev, head);
  60613. +}
  60614. +
  60615. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  60616. +{
  60617. + next->prev = prev;
  60618. + prev->next = next;
  60619. +}
  60620. +
  60621. +static inline void list_del(struct list_head *entry)
  60622. +{
  60623. + __list_del(entry->prev, entry->next);
  60624. + entry->next = LIST_POISON1;
  60625. + entry->prev = LIST_POISON2;
  60626. +}
  60627. +#endif
  60628. +
  60629. +#define DWC_LIST_REMOVE(link) do { \
  60630. + (link)->next->prev = (link)->prev; \
  60631. + (link)->prev->next = (link)->next; \
  60632. +} while (0)
  60633. +
  60634. +#define DWC_LIST_REMOVE_INIT(link) do { \
  60635. + DWC_LIST_REMOVE(link); \
  60636. + DWC_LIST_INIT(link); \
  60637. +} while (0)
  60638. +
  60639. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  60640. + DWC_LIST_REMOVE(link); \
  60641. + DWC_LIST_INSERT_HEAD(list, link); \
  60642. +} while (0)
  60643. +
  60644. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  60645. + DWC_LIST_REMOVE(link); \
  60646. + DWC_LIST_INSERT_TAIL(list, link); \
  60647. +} while (0)
  60648. +
  60649. +#define DWC_LIST_FOREACH(var, list) \
  60650. + for((var) = DWC_LIST_FIRST(list); \
  60651. + (var) != DWC_LIST_END(list); \
  60652. + (var) = DWC_LIST_NEXT(var))
  60653. +
  60654. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  60655. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  60656. + (var) != DWC_LIST_END(list); \
  60657. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  60658. +
  60659. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  60660. + for((var) = DWC_LIST_LAST(list); \
  60661. + (var) != DWC_LIST_END(list); \
  60662. + (var) = DWC_LIST_PREV(var))
  60663. +
  60664. +/*
  60665. + * Singly-linked List definitions.
  60666. + */
  60667. +#define DWC_SLIST_HEAD(name, type) \
  60668. +struct name { \
  60669. + struct type *slh_first; /* first element */ \
  60670. +}
  60671. +
  60672. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  60673. + { NULL }
  60674. +
  60675. +#define DWC_SLIST_ENTRY(type) \
  60676. +struct { \
  60677. + struct type *sle_next; /* next element */ \
  60678. +}
  60679. +
  60680. +/*
  60681. + * Singly-linked List access methods.
  60682. + */
  60683. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  60684. +#define DWC_SLIST_END(head) NULL
  60685. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  60686. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  60687. +
  60688. +#define DWC_SLIST_FOREACH(var, head, field) \
  60689. + for((var) = SLIST_FIRST(head); \
  60690. + (var) != SLIST_END(head); \
  60691. + (var) = SLIST_NEXT(var, field))
  60692. +
  60693. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  60694. + for((varp) = &SLIST_FIRST((head)); \
  60695. + ((var) = *(varp)) != SLIST_END(head); \
  60696. + (varp) = &SLIST_NEXT((var), field))
  60697. +
  60698. +/*
  60699. + * Singly-linked List functions.
  60700. + */
  60701. +#define DWC_SLIST_INIT(head) { \
  60702. + SLIST_FIRST(head) = SLIST_END(head); \
  60703. +}
  60704. +
  60705. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  60706. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  60707. + (slistelm)->field.sle_next = (elm); \
  60708. +} while (0)
  60709. +
  60710. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  60711. + (elm)->field.sle_next = (head)->slh_first; \
  60712. + (head)->slh_first = (elm); \
  60713. +} while (0)
  60714. +
  60715. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  60716. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  60717. +} while (0)
  60718. +
  60719. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  60720. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  60721. +} while (0)
  60722. +
  60723. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  60724. + if ((head)->slh_first == (elm)) { \
  60725. + SLIST_REMOVE_HEAD((head), field); \
  60726. + } \
  60727. + else { \
  60728. + struct type *curelm = (head)->slh_first; \
  60729. + while( curelm->field.sle_next != (elm) ) \
  60730. + curelm = curelm->field.sle_next; \
  60731. + curelm->field.sle_next = \
  60732. + curelm->field.sle_next->field.sle_next; \
  60733. + } \
  60734. +} while (0)
  60735. +
  60736. +/*
  60737. + * Simple queue definitions.
  60738. + */
  60739. +#define DWC_SIMPLEQ_HEAD(name, type) \
  60740. +struct name { \
  60741. + struct type *sqh_first; /* first element */ \
  60742. + struct type **sqh_last; /* addr of last next element */ \
  60743. +}
  60744. +
  60745. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  60746. + { NULL, &(head).sqh_first }
  60747. +
  60748. +#define DWC_SIMPLEQ_ENTRY(type) \
  60749. +struct { \
  60750. + struct type *sqe_next; /* next element */ \
  60751. +}
  60752. +
  60753. +/*
  60754. + * Simple queue access methods.
  60755. + */
  60756. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  60757. +#define DWC_SIMPLEQ_END(head) NULL
  60758. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  60759. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  60760. +
  60761. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  60762. + for((var) = SIMPLEQ_FIRST(head); \
  60763. + (var) != SIMPLEQ_END(head); \
  60764. + (var) = SIMPLEQ_NEXT(var, field))
  60765. +
  60766. +/*
  60767. + * Simple queue functions.
  60768. + */
  60769. +#define DWC_SIMPLEQ_INIT(head) do { \
  60770. + (head)->sqh_first = NULL; \
  60771. + (head)->sqh_last = &(head)->sqh_first; \
  60772. +} while (0)
  60773. +
  60774. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  60775. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  60776. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60777. + (head)->sqh_first = (elm); \
  60778. +} while (0)
  60779. +
  60780. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  60781. + (elm)->field.sqe_next = NULL; \
  60782. + *(head)->sqh_last = (elm); \
  60783. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60784. +} while (0)
  60785. +
  60786. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60787. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  60788. + (head)->sqh_last = &(elm)->field.sqe_next; \
  60789. + (listelm)->field.sqe_next = (elm); \
  60790. +} while (0)
  60791. +
  60792. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  60793. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  60794. + (head)->sqh_last = &(head)->sqh_first; \
  60795. +} while (0)
  60796. +
  60797. +/*
  60798. + * Tail queue definitions.
  60799. + */
  60800. +#define DWC_TAILQ_HEAD(name, type) \
  60801. +struct name { \
  60802. + struct type *tqh_first; /* first element */ \
  60803. + struct type **tqh_last; /* addr of last next element */ \
  60804. +}
  60805. +
  60806. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  60807. + { NULL, &(head).tqh_first }
  60808. +
  60809. +#define DWC_TAILQ_ENTRY(type) \
  60810. +struct { \
  60811. + struct type *tqe_next; /* next element */ \
  60812. + struct type **tqe_prev; /* address of previous next element */ \
  60813. +}
  60814. +
  60815. +/*
  60816. + * tail queue access methods
  60817. + */
  60818. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  60819. +#define DWC_TAILQ_END(head) NULL
  60820. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  60821. +#define DWC_TAILQ_LAST(head, headname) \
  60822. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  60823. +/* XXX */
  60824. +#define DWC_TAILQ_PREV(elm, headname, field) \
  60825. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  60826. +#define DWC_TAILQ_EMPTY(head) \
  60827. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  60828. +
  60829. +#define DWC_TAILQ_FOREACH(var, head, field) \
  60830. + for ((var) = DWC_TAILQ_FIRST(head); \
  60831. + (var) != DWC_TAILQ_END(head); \
  60832. + (var) = DWC_TAILQ_NEXT(var, field))
  60833. +
  60834. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  60835. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  60836. + (var) != DWC_TAILQ_END(head); \
  60837. + (var) = DWC_TAILQ_PREV(var, headname, field))
  60838. +
  60839. +/*
  60840. + * Tail queue functions.
  60841. + */
  60842. +#define DWC_TAILQ_INIT(head) do { \
  60843. + (head)->tqh_first = NULL; \
  60844. + (head)->tqh_last = &(head)->tqh_first; \
  60845. +} while (0)
  60846. +
  60847. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  60848. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  60849. + (head)->tqh_first->field.tqe_prev = \
  60850. + &(elm)->field.tqe_next; \
  60851. + else \
  60852. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60853. + (head)->tqh_first = (elm); \
  60854. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  60855. +} while (0)
  60856. +
  60857. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  60858. + (elm)->field.tqe_next = NULL; \
  60859. + (elm)->field.tqe_prev = (head)->tqh_last; \
  60860. + *(head)->tqh_last = (elm); \
  60861. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60862. +} while (0)
  60863. +
  60864. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60865. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  60866. + (elm)->field.tqe_next->field.tqe_prev = \
  60867. + &(elm)->field.tqe_next; \
  60868. + else \
  60869. + (head)->tqh_last = &(elm)->field.tqe_next; \
  60870. + (listelm)->field.tqe_next = (elm); \
  60871. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  60872. +} while (0)
  60873. +
  60874. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  60875. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  60876. + (elm)->field.tqe_next = (listelm); \
  60877. + *(listelm)->field.tqe_prev = (elm); \
  60878. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  60879. +} while (0)
  60880. +
  60881. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  60882. + if (((elm)->field.tqe_next) != NULL) \
  60883. + (elm)->field.tqe_next->field.tqe_prev = \
  60884. + (elm)->field.tqe_prev; \
  60885. + else \
  60886. + (head)->tqh_last = (elm)->field.tqe_prev; \
  60887. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  60888. +} while (0)
  60889. +
  60890. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  60891. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  60892. + (elm2)->field.tqe_next->field.tqe_prev = \
  60893. + &(elm2)->field.tqe_next; \
  60894. + else \
  60895. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  60896. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  60897. + *(elm2)->field.tqe_prev = (elm2); \
  60898. +} while (0)
  60899. +
  60900. +/*
  60901. + * Circular queue definitions.
  60902. + */
  60903. +#define DWC_CIRCLEQ_HEAD(name, type) \
  60904. +struct name { \
  60905. + struct type *cqh_first; /* first element */ \
  60906. + struct type *cqh_last; /* last element */ \
  60907. +}
  60908. +
  60909. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  60910. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  60911. +
  60912. +#define DWC_CIRCLEQ_ENTRY(type) \
  60913. +struct { \
  60914. + struct type *cqe_next; /* next element */ \
  60915. + struct type *cqe_prev; /* previous element */ \
  60916. +}
  60917. +
  60918. +/*
  60919. + * Circular queue access methods
  60920. + */
  60921. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  60922. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  60923. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  60924. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  60925. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  60926. +#define DWC_CIRCLEQ_EMPTY(head) \
  60927. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  60928. +
  60929. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  60930. +
  60931. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  60932. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  60933. + (var) != DWC_CIRCLEQ_END(head); \
  60934. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  60935. +
  60936. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  60937. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  60938. + (var) != DWC_CIRCLEQ_END(head); \
  60939. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  60940. +
  60941. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  60942. + for((var) = DWC_CIRCLEQ_LAST(head); \
  60943. + (var) != DWC_CIRCLEQ_END(head); \
  60944. + (var) = DWC_CIRCLEQ_PREV(var, field))
  60945. +
  60946. +/*
  60947. + * Circular queue functions.
  60948. + */
  60949. +#define DWC_CIRCLEQ_INIT(head) do { \
  60950. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  60951. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  60952. +} while (0)
  60953. +
  60954. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  60955. + (elm)->field.cqe_next = NULL; \
  60956. + (elm)->field.cqe_prev = NULL; \
  60957. +} while (0)
  60958. +
  60959. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  60960. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  60961. + (elm)->field.cqe_prev = (listelm); \
  60962. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  60963. + (head)->cqh_last = (elm); \
  60964. + else \
  60965. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  60966. + (listelm)->field.cqe_next = (elm); \
  60967. +} while (0)
  60968. +
  60969. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  60970. + (elm)->field.cqe_next = (listelm); \
  60971. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  60972. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  60973. + (head)->cqh_first = (elm); \
  60974. + else \
  60975. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  60976. + (listelm)->field.cqe_prev = (elm); \
  60977. +} while (0)
  60978. +
  60979. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  60980. + (elm)->field.cqe_next = (head)->cqh_first; \
  60981. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  60982. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  60983. + (head)->cqh_last = (elm); \
  60984. + else \
  60985. + (head)->cqh_first->field.cqe_prev = (elm); \
  60986. + (head)->cqh_first = (elm); \
  60987. +} while (0)
  60988. +
  60989. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  60990. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  60991. + (elm)->field.cqe_prev = (head)->cqh_last; \
  60992. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  60993. + (head)->cqh_first = (elm); \
  60994. + else \
  60995. + (head)->cqh_last->field.cqe_next = (elm); \
  60996. + (head)->cqh_last = (elm); \
  60997. +} while (0)
  60998. +
  60999. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  61000. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  61001. + (head)->cqh_last = (elm)->field.cqe_prev; \
  61002. + else \
  61003. + (elm)->field.cqe_next->field.cqe_prev = \
  61004. + (elm)->field.cqe_prev; \
  61005. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  61006. + (head)->cqh_first = (elm)->field.cqe_next; \
  61007. + else \
  61008. + (elm)->field.cqe_prev->field.cqe_next = \
  61009. + (elm)->field.cqe_next; \
  61010. +} while (0)
  61011. +
  61012. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  61013. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  61014. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  61015. +} while (0)
  61016. +
  61017. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  61018. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  61019. + DWC_CIRCLEQ_END(head)) \
  61020. + (head).cqh_last = (elm2); \
  61021. + else \
  61022. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  61023. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  61024. + DWC_CIRCLEQ_END(head)) \
  61025. + (head).cqh_first = (elm2); \
  61026. + else \
  61027. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  61028. +} while (0)
  61029. +
  61030. +#ifdef __cplusplus
  61031. +}
  61032. +#endif
  61033. +
  61034. +#endif /* _DWC_LIST_H_ */
  61035. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  61036. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  61037. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2015-03-09 10:39:33.214893718 +0100
  61038. @@ -0,0 +1,245 @@
  61039. +/* Memory Debugging */
  61040. +#ifdef DWC_DEBUG_MEMORY
  61041. +
  61042. +#include "dwc_os.h"
  61043. +#include "dwc_list.h"
  61044. +
  61045. +struct allocation {
  61046. + void *addr;
  61047. + void *ctx;
  61048. + char *func;
  61049. + int line;
  61050. + uint32_t size;
  61051. + int dma;
  61052. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  61053. +};
  61054. +
  61055. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  61056. +
  61057. +struct allocation_manager {
  61058. + void *mem_ctx;
  61059. + struct allocation_queue allocations;
  61060. +
  61061. + /* statistics */
  61062. + int num;
  61063. + int num_freed;
  61064. + int num_active;
  61065. + uint32_t total;
  61066. + uint32_t cur;
  61067. + uint32_t max;
  61068. +};
  61069. +
  61070. +static struct allocation_manager *manager = NULL;
  61071. +
  61072. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  61073. + int dma)
  61074. +{
  61075. + struct allocation *a;
  61076. +
  61077. + DWC_ASSERT(manager != NULL, "manager not allocated");
  61078. +
  61079. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  61080. + if (!a) {
  61081. + return -DWC_E_NO_MEMORY;
  61082. + }
  61083. +
  61084. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  61085. + if (!a->func) {
  61086. + __DWC_FREE(manager->mem_ctx, a);
  61087. + return -DWC_E_NO_MEMORY;
  61088. + }
  61089. +
  61090. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  61091. + a->addr = addr;
  61092. + a->ctx = ctx;
  61093. + a->line = line;
  61094. + a->size = size;
  61095. + a->dma = dma;
  61096. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  61097. +
  61098. + /* Update stats */
  61099. + manager->num++;
  61100. + manager->num_active++;
  61101. + manager->total += size;
  61102. + manager->cur += size;
  61103. +
  61104. + if (manager->max < manager->cur) {
  61105. + manager->max = manager->cur;
  61106. + }
  61107. +
  61108. + return 0;
  61109. +}
  61110. +
  61111. +static struct allocation *find_allocation(void *ctx, void *addr)
  61112. +{
  61113. + struct allocation *a;
  61114. +
  61115. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  61116. + if (a->ctx == ctx && a->addr == addr) {
  61117. + return a;
  61118. + }
  61119. + }
  61120. +
  61121. + return NULL;
  61122. +}
  61123. +
  61124. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  61125. +{
  61126. + struct allocation *a = find_allocation(ctx, addr);
  61127. +
  61128. + if (!a) {
  61129. + DWC_ASSERT(0,
  61130. + "Free of address %p that was never allocated or already freed %s:%d",
  61131. + addr, func, line);
  61132. + return;
  61133. + }
  61134. +
  61135. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  61136. +
  61137. + manager->num_active--;
  61138. + manager->num_freed++;
  61139. + manager->cur -= a->size;
  61140. + __DWC_FREE(manager->mem_ctx, a->func);
  61141. + __DWC_FREE(manager->mem_ctx, a);
  61142. +}
  61143. +
  61144. +int dwc_memory_debug_start(void *mem_ctx)
  61145. +{
  61146. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  61147. +
  61148. + if (manager) {
  61149. + return -DWC_E_BUSY;
  61150. + }
  61151. +
  61152. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  61153. + if (!manager) {
  61154. + return -DWC_E_NO_MEMORY;
  61155. + }
  61156. +
  61157. + DWC_CIRCLEQ_INIT(&manager->allocations);
  61158. + manager->mem_ctx = mem_ctx;
  61159. + manager->num = 0;
  61160. + manager->num_freed = 0;
  61161. + manager->num_active = 0;
  61162. + manager->total = 0;
  61163. + manager->cur = 0;
  61164. + manager->max = 0;
  61165. +
  61166. + return 0;
  61167. +}
  61168. +
  61169. +void dwc_memory_debug_stop(void)
  61170. +{
  61171. + struct allocation *a;
  61172. +
  61173. + dwc_memory_debug_report();
  61174. +
  61175. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  61176. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  61177. + free_allocation(a->ctx, a->addr, NULL, -1);
  61178. + }
  61179. +
  61180. + __DWC_FREE(manager->mem_ctx, manager);
  61181. +}
  61182. +
  61183. +void dwc_memory_debug_report(void)
  61184. +{
  61185. + struct allocation *a;
  61186. +
  61187. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  61188. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  61189. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  61190. + DWC_PRINTF("Active = %d\n", manager->num_active);
  61191. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  61192. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  61193. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  61194. + DWC_PRINTF("Unfreed allocations:\n");
  61195. +
  61196. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  61197. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  61198. + a->addr, a->size, a->func, a->line, a->dma);
  61199. + }
  61200. +}
  61201. +
  61202. +/* The replacement functions */
  61203. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  61204. +{
  61205. + void *addr = __DWC_ALLOC(mem_ctx, size);
  61206. +
  61207. + if (!addr) {
  61208. + return NULL;
  61209. + }
  61210. +
  61211. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  61212. + __DWC_FREE(mem_ctx, addr);
  61213. + return NULL;
  61214. + }
  61215. +
  61216. + return addr;
  61217. +}
  61218. +
  61219. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  61220. + int line)
  61221. +{
  61222. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  61223. +
  61224. + if (!addr) {
  61225. + return NULL;
  61226. + }
  61227. +
  61228. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  61229. + __DWC_FREE(mem_ctx, addr);
  61230. + return NULL;
  61231. + }
  61232. +
  61233. + return addr;
  61234. +}
  61235. +
  61236. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  61237. +{
  61238. + free_allocation(mem_ctx, addr, func, line);
  61239. + __DWC_FREE(mem_ctx, addr);
  61240. +}
  61241. +
  61242. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  61243. + char const *func, int line)
  61244. +{
  61245. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  61246. +
  61247. + if (!addr) {
  61248. + return NULL;
  61249. + }
  61250. +
  61251. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  61252. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  61253. + return NULL;
  61254. + }
  61255. +
  61256. + return addr;
  61257. +}
  61258. +
  61259. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  61260. + dwc_dma_t *dma_addr, char const *func, int line)
  61261. +{
  61262. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  61263. +
  61264. + if (!addr) {
  61265. + return NULL;
  61266. + }
  61267. +
  61268. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  61269. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  61270. + return NULL;
  61271. + }
  61272. +
  61273. + return addr;
  61274. +}
  61275. +
  61276. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  61277. + dwc_dma_t dma_addr, char const *func, int line)
  61278. +{
  61279. + free_allocation(dma_ctx, virt_addr, func, line);
  61280. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  61281. +}
  61282. +
  61283. +#endif /* DWC_DEBUG_MEMORY */
  61284. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  61285. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  61286. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2015-03-09 10:39:33.214893718 +0100
  61287. @@ -0,0 +1,636 @@
  61288. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  61289. + *
  61290. + * PuTTY is copyright 1997-2007 Simon Tatham.
  61291. + *
  61292. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  61293. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  61294. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  61295. + * Kuhn, and CORE SDI S.A.
  61296. + *
  61297. + * Permission is hereby granted, free of charge, to any person
  61298. + * obtaining a copy of this software and associated documentation files
  61299. + * (the "Software"), to deal in the Software without restriction,
  61300. + * including without limitation the rights to use, copy, modify, merge,
  61301. + * publish, distribute, sublicense, and/or sell copies of the Software,
  61302. + * and to permit persons to whom the Software is furnished to do so,
  61303. + * subject to the following conditions:
  61304. + *
  61305. + * The above copyright notice and this permission notice shall be
  61306. + * included in all copies or substantial portions of the Software.
  61307. +
  61308. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  61309. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  61310. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  61311. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  61312. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  61313. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  61314. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  61315. + *
  61316. + */
  61317. +#ifdef DWC_CRYPTOLIB
  61318. +
  61319. +#ifndef CONFIG_MACH_IPMATE
  61320. +
  61321. +#include "dwc_modpow.h"
  61322. +
  61323. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  61324. +#define BIGNUM_TOP_BIT 0x80000000UL
  61325. +#define BIGNUM_INT_BITS 32
  61326. +
  61327. +
  61328. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  61329. +{
  61330. + void *p;
  61331. + size *= n;
  61332. + if (size == 0) size = 1;
  61333. + p = dwc_alloc(mem_ctx, size);
  61334. + return p;
  61335. +}
  61336. +
  61337. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  61338. +#define sfree dwc_free
  61339. +
  61340. +/*
  61341. + * Usage notes:
  61342. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  61343. + * subscripts, as some implementations object to this (see below).
  61344. + * * Note that none of the division methods below will cope if the
  61345. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  61346. + * to avoid this case.
  61347. + * If this condition occurs, in the case of the x86 DIV instruction,
  61348. + * an overflow exception will occur, which (according to a correspondent)
  61349. + * will manifest on Windows as something like
  61350. + * 0xC0000095: Integer overflow
  61351. + * The C variant won't give the right answer, either.
  61352. + */
  61353. +
  61354. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  61355. +
  61356. +#if defined __GNUC__ && defined __i386__
  61357. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  61358. + __asm__("div %2" : \
  61359. + "=d" (r), "=a" (q) : \
  61360. + "r" (w), "d" (hi), "a" (lo))
  61361. +#else
  61362. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  61363. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  61364. + q = n / w; \
  61365. + r = n % w; \
  61366. +} while (0)
  61367. +#endif
  61368. +
  61369. +// q = n / w;
  61370. +// r = n % w;
  61371. +
  61372. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  61373. +
  61374. +#define BIGNUM_INTERNAL
  61375. +
  61376. +static Bignum newbn(void *mem_ctx, int length)
  61377. +{
  61378. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  61379. + //if (!b)
  61380. + //abort(); /* FIXME */
  61381. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  61382. + b[0] = length;
  61383. + return b;
  61384. +}
  61385. +
  61386. +void freebn(void *mem_ctx, Bignum b)
  61387. +{
  61388. + /*
  61389. + * Burn the evidence, just in case.
  61390. + */
  61391. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  61392. + sfree(mem_ctx, b);
  61393. +}
  61394. +
  61395. +/*
  61396. + * Compute c = a * b.
  61397. + * Input is in the first len words of a and b.
  61398. + * Result is returned in the first 2*len words of c.
  61399. + */
  61400. +static void internal_mul(BignumInt *a, BignumInt *b,
  61401. + BignumInt *c, int len)
  61402. +{
  61403. + int i, j;
  61404. + BignumDblInt t;
  61405. +
  61406. + for (j = 0; j < 2 * len; j++)
  61407. + c[j] = 0;
  61408. +
  61409. + for (i = len - 1; i >= 0; i--) {
  61410. + t = 0;
  61411. + for (j = len - 1; j >= 0; j--) {
  61412. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  61413. + t += (BignumDblInt) c[i + j + 1];
  61414. + c[i + j + 1] = (BignumInt) t;
  61415. + t = t >> BIGNUM_INT_BITS;
  61416. + }
  61417. + c[i] = (BignumInt) t;
  61418. + }
  61419. +}
  61420. +
  61421. +static void internal_add_shifted(BignumInt *number,
  61422. + unsigned n, int shift)
  61423. +{
  61424. + int word = 1 + (shift / BIGNUM_INT_BITS);
  61425. + int bshift = shift % BIGNUM_INT_BITS;
  61426. + BignumDblInt addend;
  61427. +
  61428. + addend = (BignumDblInt)n << bshift;
  61429. +
  61430. + while (addend) {
  61431. + addend += number[word];
  61432. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  61433. + addend >>= BIGNUM_INT_BITS;
  61434. + word++;
  61435. + }
  61436. +}
  61437. +
  61438. +/*
  61439. + * Compute a = a % m.
  61440. + * Input in first alen words of a and first mlen words of m.
  61441. + * Output in first alen words of a
  61442. + * (of which first alen-mlen words will be zero).
  61443. + * The MSW of m MUST have its high bit set.
  61444. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  61445. + * rather than the internal bigendian format. Quotient parts are shifted
  61446. + * left by `qshift' before adding into quot.
  61447. + */
  61448. +static void internal_mod(BignumInt *a, int alen,
  61449. + BignumInt *m, int mlen,
  61450. + BignumInt *quot, int qshift)
  61451. +{
  61452. + BignumInt m0, m1;
  61453. + unsigned int h;
  61454. + int i, k;
  61455. +
  61456. + m0 = m[0];
  61457. + if (mlen > 1)
  61458. + m1 = m[1];
  61459. + else
  61460. + m1 = 0;
  61461. +
  61462. + for (i = 0; i <= alen - mlen; i++) {
  61463. + BignumDblInt t;
  61464. + unsigned int q, r, c, ai1;
  61465. +
  61466. + if (i == 0) {
  61467. + h = 0;
  61468. + } else {
  61469. + h = a[i - 1];
  61470. + a[i - 1] = 0;
  61471. + }
  61472. +
  61473. + if (i == alen - 1)
  61474. + ai1 = 0;
  61475. + else
  61476. + ai1 = a[i + 1];
  61477. +
  61478. + /* Find q = h:a[i] / m0 */
  61479. + if (h >= m0) {
  61480. + /*
  61481. + * Special case.
  61482. + *
  61483. + * To illustrate it, suppose a BignumInt is 8 bits, and
  61484. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  61485. + * our initial division will be 0xA123 / 0xA1, which
  61486. + * will give a quotient of 0x100 and a divide overflow.
  61487. + * However, the invariants in this division algorithm
  61488. + * are not violated, since the full number A1:23:... is
  61489. + * _less_ than the quotient prefix A1:B2:... and so the
  61490. + * following correction loop would have sorted it out.
  61491. + *
  61492. + * In this situation we set q to be the largest
  61493. + * quotient we _can_ stomach (0xFF, of course).
  61494. + */
  61495. + q = BIGNUM_INT_MASK;
  61496. + } else {
  61497. + /* Macro doesn't want an array subscript expression passed
  61498. + * into it (see definition), so use a temporary. */
  61499. + BignumInt tmplo = a[i];
  61500. + DIVMOD_WORD(q, r, h, tmplo, m0);
  61501. +
  61502. + /* Refine our estimate of q by looking at
  61503. + h:a[i]:a[i+1] / m0:m1 */
  61504. + t = MUL_WORD(m1, q);
  61505. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  61506. + q--;
  61507. + t -= m1;
  61508. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  61509. + if (r >= (BignumDblInt) m0 &&
  61510. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  61511. + }
  61512. + }
  61513. +
  61514. + /* Subtract q * m from a[i...] */
  61515. + c = 0;
  61516. + for (k = mlen - 1; k >= 0; k--) {
  61517. + t = MUL_WORD(q, m[k]);
  61518. + t += c;
  61519. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  61520. + if ((BignumInt) t > a[i + k])
  61521. + c++;
  61522. + a[i + k] -= (BignumInt) t;
  61523. + }
  61524. +
  61525. + /* Add back m in case of borrow */
  61526. + if (c != h) {
  61527. + t = 0;
  61528. + for (k = mlen - 1; k >= 0; k--) {
  61529. + t += m[k];
  61530. + t += a[i + k];
  61531. + a[i + k] = (BignumInt) t;
  61532. + t = t >> BIGNUM_INT_BITS;
  61533. + }
  61534. + q--;
  61535. + }
  61536. + if (quot)
  61537. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  61538. + }
  61539. +}
  61540. +
  61541. +/*
  61542. + * Compute p % mod.
  61543. + * The most significant word of mod MUST be non-zero.
  61544. + * We assume that the result array is the same size as the mod array.
  61545. + * We optionally write out a quotient if `quotient' is non-NULL.
  61546. + * We can avoid writing out the result if `result' is NULL.
  61547. + */
  61548. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  61549. +{
  61550. + BignumInt *n, *m;
  61551. + int mshift;
  61552. + int plen, mlen, i, j;
  61553. +
  61554. + /* Allocate m of size mlen, copy mod to m */
  61555. + /* We use big endian internally */
  61556. + mlen = mod[0];
  61557. + m = snewn(mem_ctx, mlen, BignumInt);
  61558. + //if (!m)
  61559. + //abort(); /* FIXME */
  61560. + for (j = 0; j < mlen; j++)
  61561. + m[j] = mod[mod[0] - j];
  61562. +
  61563. + /* Shift m left to make msb bit set */
  61564. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  61565. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  61566. + break;
  61567. + if (mshift) {
  61568. + for (i = 0; i < mlen - 1; i++)
  61569. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  61570. + m[mlen - 1] = m[mlen - 1] << mshift;
  61571. + }
  61572. +
  61573. + plen = p[0];
  61574. + /* Ensure plen > mlen */
  61575. + if (plen <= mlen)
  61576. + plen = mlen + 1;
  61577. +
  61578. + /* Allocate n of size plen, copy p to n */
  61579. + n = snewn(mem_ctx, plen, BignumInt);
  61580. + //if (!n)
  61581. + //abort(); /* FIXME */
  61582. + for (j = 0; j < plen; j++)
  61583. + n[j] = 0;
  61584. + for (j = 1; j <= (int)p[0]; j++)
  61585. + n[plen - j] = p[j];
  61586. +
  61587. + /* Main computation */
  61588. + internal_mod(n, plen, m, mlen, quotient, mshift);
  61589. +
  61590. + /* Fixup result in case the modulus was shifted */
  61591. + if (mshift) {
  61592. + for (i = plen - mlen - 1; i < plen - 1; i++)
  61593. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  61594. + n[plen - 1] = n[plen - 1] << mshift;
  61595. + internal_mod(n, plen, m, mlen, quotient, 0);
  61596. + for (i = plen - 1; i >= plen - mlen; i--)
  61597. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  61598. + }
  61599. +
  61600. + /* Copy result to buffer */
  61601. + if (result) {
  61602. + for (i = 1; i <= (int)result[0]; i++) {
  61603. + int j = plen - i;
  61604. + result[i] = j >= 0 ? n[j] : 0;
  61605. + }
  61606. + }
  61607. +
  61608. + /* Free temporary arrays */
  61609. + for (i = 0; i < mlen; i++)
  61610. + m[i] = 0;
  61611. + sfree(mem_ctx, m);
  61612. + for (i = 0; i < plen; i++)
  61613. + n[i] = 0;
  61614. + sfree(mem_ctx, n);
  61615. +}
  61616. +
  61617. +/*
  61618. + * Simple remainder.
  61619. + */
  61620. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  61621. +{
  61622. + Bignum r = newbn(mem_ctx, b[0]);
  61623. + bigdivmod(mem_ctx, a, b, r, NULL);
  61624. + return r;
  61625. +}
  61626. +
  61627. +/*
  61628. + * Compute (base ^ exp) % mod.
  61629. + */
  61630. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  61631. +{
  61632. + BignumInt *a, *b, *n, *m;
  61633. + int mshift;
  61634. + int mlen, i, j;
  61635. + Bignum base, result;
  61636. +
  61637. + /*
  61638. + * The most significant word of mod needs to be non-zero. It
  61639. + * should already be, but let's make sure.
  61640. + */
  61641. + //assert(mod[mod[0]] != 0);
  61642. +
  61643. + /*
  61644. + * Make sure the base is smaller than the modulus, by reducing
  61645. + * it modulo the modulus if not.
  61646. + */
  61647. + base = bigmod(mem_ctx, base_in, mod);
  61648. +
  61649. + /* Allocate m of size mlen, copy mod to m */
  61650. + /* We use big endian internally */
  61651. + mlen = mod[0];
  61652. + m = snewn(mem_ctx, mlen, BignumInt);
  61653. + //if (!m)
  61654. + //abort(); /* FIXME */
  61655. + for (j = 0; j < mlen; j++)
  61656. + m[j] = mod[mod[0] - j];
  61657. +
  61658. + /* Shift m left to make msb bit set */
  61659. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  61660. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  61661. + break;
  61662. + if (mshift) {
  61663. + for (i = 0; i < mlen - 1; i++)
  61664. + m[i] =
  61665. + (m[i] << mshift) | (m[i + 1] >>
  61666. + (BIGNUM_INT_BITS - mshift));
  61667. + m[mlen - 1] = m[mlen - 1] << mshift;
  61668. + }
  61669. +
  61670. + /* Allocate n of size mlen, copy base to n */
  61671. + n = snewn(mem_ctx, mlen, BignumInt);
  61672. + //if (!n)
  61673. + //abort(); /* FIXME */
  61674. + i = mlen - base[0];
  61675. + for (j = 0; j < i; j++)
  61676. + n[j] = 0;
  61677. + for (j = 0; j < base[0]; j++)
  61678. + n[i + j] = base[base[0] - j];
  61679. +
  61680. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  61681. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  61682. + //if (!a)
  61683. + //abort(); /* FIXME */
  61684. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  61685. + //if (!b)
  61686. + //abort(); /* FIXME */
  61687. + for (i = 0; i < 2 * mlen; i++)
  61688. + a[i] = 0;
  61689. + a[2 * mlen - 1] = 1;
  61690. +
  61691. + /* Skip leading zero bits of exp. */
  61692. + i = 0;
  61693. + j = BIGNUM_INT_BITS - 1;
  61694. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  61695. + j--;
  61696. + if (j < 0) {
  61697. + i++;
  61698. + j = BIGNUM_INT_BITS - 1;
  61699. + }
  61700. + }
  61701. +
  61702. + /* Main computation */
  61703. + while (i < exp[0]) {
  61704. + while (j >= 0) {
  61705. + internal_mul(a + mlen, a + mlen, b, mlen);
  61706. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  61707. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  61708. + internal_mul(b + mlen, n, a, mlen);
  61709. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  61710. + } else {
  61711. + BignumInt *t;
  61712. + t = a;
  61713. + a = b;
  61714. + b = t;
  61715. + }
  61716. + j--;
  61717. + }
  61718. + i++;
  61719. + j = BIGNUM_INT_BITS - 1;
  61720. + }
  61721. +
  61722. + /* Fixup result in case the modulus was shifted */
  61723. + if (mshift) {
  61724. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  61725. + a[i] =
  61726. + (a[i] << mshift) | (a[i + 1] >>
  61727. + (BIGNUM_INT_BITS - mshift));
  61728. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  61729. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  61730. + for (i = 2 * mlen - 1; i >= mlen; i--)
  61731. + a[i] =
  61732. + (a[i] >> mshift) | (a[i - 1] <<
  61733. + (BIGNUM_INT_BITS - mshift));
  61734. + }
  61735. +
  61736. + /* Copy result to buffer */
  61737. + result = newbn(mem_ctx, mod[0]);
  61738. + for (i = 0; i < mlen; i++)
  61739. + result[result[0] - i] = a[i + mlen];
  61740. + while (result[0] > 1 && result[result[0]] == 0)
  61741. + result[0]--;
  61742. +
  61743. + /* Free temporary arrays */
  61744. + for (i = 0; i < 2 * mlen; i++)
  61745. + a[i] = 0;
  61746. + sfree(mem_ctx, a);
  61747. + for (i = 0; i < 2 * mlen; i++)
  61748. + b[i] = 0;
  61749. + sfree(mem_ctx, b);
  61750. + for (i = 0; i < mlen; i++)
  61751. + m[i] = 0;
  61752. + sfree(mem_ctx, m);
  61753. + for (i = 0; i < mlen; i++)
  61754. + n[i] = 0;
  61755. + sfree(mem_ctx, n);
  61756. +
  61757. + freebn(mem_ctx, base);
  61758. +
  61759. + return result;
  61760. +}
  61761. +
  61762. +
  61763. +#ifdef UNITTEST
  61764. +
  61765. +static __u32 dh_p[] = {
  61766. + 96,
  61767. + 0xFFFFFFFF,
  61768. + 0xFFFFFFFF,
  61769. + 0xA93AD2CA,
  61770. + 0x4B82D120,
  61771. + 0xE0FD108E,
  61772. + 0x43DB5BFC,
  61773. + 0x74E5AB31,
  61774. + 0x08E24FA0,
  61775. + 0xBAD946E2,
  61776. + 0x770988C0,
  61777. + 0x7A615D6C,
  61778. + 0xBBE11757,
  61779. + 0x177B200C,
  61780. + 0x521F2B18,
  61781. + 0x3EC86A64,
  61782. + 0xD8760273,
  61783. + 0xD98A0864,
  61784. + 0xF12FFA06,
  61785. + 0x1AD2EE6B,
  61786. + 0xCEE3D226,
  61787. + 0x4A25619D,
  61788. + 0x1E8C94E0,
  61789. + 0xDB0933D7,
  61790. + 0xABF5AE8C,
  61791. + 0xA6E1E4C7,
  61792. + 0xB3970F85,
  61793. + 0x5D060C7D,
  61794. + 0x8AEA7157,
  61795. + 0x58DBEF0A,
  61796. + 0xECFB8504,
  61797. + 0xDF1CBA64,
  61798. + 0xA85521AB,
  61799. + 0x04507A33,
  61800. + 0xAD33170D,
  61801. + 0x8AAAC42D,
  61802. + 0x15728E5A,
  61803. + 0x98FA0510,
  61804. + 0x15D22618,
  61805. + 0xEA956AE5,
  61806. + 0x3995497C,
  61807. + 0x95581718,
  61808. + 0xDE2BCBF6,
  61809. + 0x6F4C52C9,
  61810. + 0xB5C55DF0,
  61811. + 0xEC07A28F,
  61812. + 0x9B2783A2,
  61813. + 0x180E8603,
  61814. + 0xE39E772C,
  61815. + 0x2E36CE3B,
  61816. + 0x32905E46,
  61817. + 0xCA18217C,
  61818. + 0xF1746C08,
  61819. + 0x4ABC9804,
  61820. + 0x670C354E,
  61821. + 0x7096966D,
  61822. + 0x9ED52907,
  61823. + 0x208552BB,
  61824. + 0x1C62F356,
  61825. + 0xDCA3AD96,
  61826. + 0x83655D23,
  61827. + 0xFD24CF5F,
  61828. + 0x69163FA8,
  61829. + 0x1C55D39A,
  61830. + 0x98DA4836,
  61831. + 0xA163BF05,
  61832. + 0xC2007CB8,
  61833. + 0xECE45B3D,
  61834. + 0x49286651,
  61835. + 0x7C4B1FE6,
  61836. + 0xAE9F2411,
  61837. + 0x5A899FA5,
  61838. + 0xEE386BFB,
  61839. + 0xF406B7ED,
  61840. + 0x0BFF5CB6,
  61841. + 0xA637ED6B,
  61842. + 0xF44C42E9,
  61843. + 0x625E7EC6,
  61844. + 0xE485B576,
  61845. + 0x6D51C245,
  61846. + 0x4FE1356D,
  61847. + 0xF25F1437,
  61848. + 0x302B0A6D,
  61849. + 0xCD3A431B,
  61850. + 0xEF9519B3,
  61851. + 0x8E3404DD,
  61852. + 0x514A0879,
  61853. + 0x3B139B22,
  61854. + 0x020BBEA6,
  61855. + 0x8A67CC74,
  61856. + 0x29024E08,
  61857. + 0x80DC1CD1,
  61858. + 0xC4C6628B,
  61859. + 0x2168C234,
  61860. + 0xC90FDAA2,
  61861. + 0xFFFFFFFF,
  61862. + 0xFFFFFFFF,
  61863. +};
  61864. +
  61865. +static __u32 dh_a[] = {
  61866. + 8,
  61867. + 0xdf367516,
  61868. + 0x86459caa,
  61869. + 0xe2d459a4,
  61870. + 0xd910dae0,
  61871. + 0x8a8b5e37,
  61872. + 0x67ab31c6,
  61873. + 0xf0b55ea9,
  61874. + 0x440051d6,
  61875. +};
  61876. +
  61877. +static __u32 dh_b[] = {
  61878. + 8,
  61879. + 0xded92656,
  61880. + 0xe07a048a,
  61881. + 0x6fa452cd,
  61882. + 0x2df89d30,
  61883. + 0xc75f1b0f,
  61884. + 0x8ce3578f,
  61885. + 0x7980a324,
  61886. + 0x5daec786,
  61887. +};
  61888. +
  61889. +static __u32 dh_g[] = {
  61890. + 1,
  61891. + 2,
  61892. +};
  61893. +
  61894. +int main(void)
  61895. +{
  61896. + int i;
  61897. + __u32 *k;
  61898. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  61899. +
  61900. + printf("\n\n");
  61901. + for (i=0; i<k[0]; i++) {
  61902. + __u32 word32 = k[k[0] - i];
  61903. + __u16 l = word32 & 0xffff;
  61904. + __u16 m = (word32 & 0xffff0000) >> 16;
  61905. + printf("%04x %04x ", m, l);
  61906. + if (!((i + 1)%13)) printf("\n");
  61907. + }
  61908. + printf("\n\n");
  61909. +
  61910. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  61911. + printf("PASS\n\n");
  61912. + }
  61913. + else {
  61914. + printf("FAIL\n\n");
  61915. + }
  61916. +
  61917. +}
  61918. +
  61919. +#endif /* UNITTEST */
  61920. +
  61921. +#endif /* CONFIG_MACH_IPMATE */
  61922. +
  61923. +#endif /*DWC_CRYPTOLIB */
  61924. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  61925. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  61926. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2015-03-09 10:39:33.214893718 +0100
  61927. @@ -0,0 +1,34 @@
  61928. +/*
  61929. + * dwc_modpow.h
  61930. + * See dwc_modpow.c for license and changes
  61931. + */
  61932. +#ifndef _DWC_MODPOW_H
  61933. +#define _DWC_MODPOW_H
  61934. +
  61935. +#ifdef __cplusplus
  61936. +extern "C" {
  61937. +#endif
  61938. +
  61939. +#include "dwc_os.h"
  61940. +
  61941. +/** @file
  61942. + *
  61943. + * This file defines the module exponentiation function which is only used
  61944. + * internally by the DWC UWB modules for calculation of PKs during numeric
  61945. + * association. The routine is taken from the PUTTY, an open source terminal
  61946. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  61947. + *
  61948. + */
  61949. +
  61950. +typedef uint32_t BignumInt;
  61951. +typedef uint64_t BignumDblInt;
  61952. +typedef BignumInt *Bignum;
  61953. +
  61954. +/* Compute modular exponentiaion */
  61955. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  61956. +
  61957. +#ifdef __cplusplus
  61958. +}
  61959. +#endif
  61960. +
  61961. +#endif /* _LINUX_BIGNUM_H */
  61962. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  61963. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  61964. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2015-03-09 10:39:33.214893718 +0100
  61965. @@ -0,0 +1,319 @@
  61966. +#ifdef DWC_NOTIFYLIB
  61967. +
  61968. +#include "dwc_notifier.h"
  61969. +#include "dwc_list.h"
  61970. +
  61971. +typedef struct dwc_observer {
  61972. + void *observer;
  61973. + dwc_notifier_callback_t callback;
  61974. + void *data;
  61975. + char *notification;
  61976. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  61977. +} observer_t;
  61978. +
  61979. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  61980. +
  61981. +typedef struct dwc_notifier {
  61982. + void *mem_ctx;
  61983. + void *object;
  61984. + struct observer_queue observers;
  61985. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  61986. +} notifier_t;
  61987. +
  61988. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  61989. +
  61990. +typedef struct manager {
  61991. + void *mem_ctx;
  61992. + void *wkq_ctx;
  61993. + dwc_workq_t *wq;
  61994. +// dwc_mutex_t *mutex;
  61995. + struct notifier_queue notifiers;
  61996. +} manager_t;
  61997. +
  61998. +static manager_t *manager = NULL;
  61999. +
  62000. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  62001. +{
  62002. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  62003. + if (!manager) {
  62004. + return -DWC_E_NO_MEMORY;
  62005. + }
  62006. +
  62007. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  62008. +
  62009. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  62010. + if (!manager->wq) {
  62011. + return -DWC_E_NO_MEMORY;
  62012. + }
  62013. +
  62014. + return 0;
  62015. +}
  62016. +
  62017. +static void free_manager(void)
  62018. +{
  62019. + dwc_workq_free(manager->wq);
  62020. +
  62021. + /* All notifiers must have unregistered themselves before this module
  62022. + * can be removed. Hitting this assertion indicates a programmer
  62023. + * error. */
  62024. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  62025. + "Notification manager being freed before all notifiers have been removed");
  62026. + dwc_free(manager->mem_ctx, manager);
  62027. +}
  62028. +
  62029. +#ifdef DEBUG
  62030. +static void dump_manager(void)
  62031. +{
  62032. + notifier_t *n;
  62033. + observer_t *o;
  62034. +
  62035. + DWC_ASSERT(manager, "Notification manager not found");
  62036. +
  62037. + DWC_DEBUG("List of all notifiers and observers:\n");
  62038. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  62039. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  62040. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  62041. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  62042. + }
  62043. + }
  62044. +}
  62045. +#else
  62046. +#define dump_manager(...)
  62047. +#endif
  62048. +
  62049. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  62050. + dwc_notifier_callback_t callback, void *data)
  62051. +{
  62052. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  62053. +
  62054. + if (!new_observer) {
  62055. + return NULL;
  62056. + }
  62057. +
  62058. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  62059. + new_observer->observer = observer;
  62060. + new_observer->notification = notification;
  62061. + new_observer->callback = callback;
  62062. + new_observer->data = data;
  62063. + return new_observer;
  62064. +}
  62065. +
  62066. +static void free_observer(void *mem_ctx, observer_t *observer)
  62067. +{
  62068. + dwc_free(mem_ctx, observer);
  62069. +}
  62070. +
  62071. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  62072. +{
  62073. + notifier_t *notifier;
  62074. +
  62075. + if (!object) {
  62076. + return NULL;
  62077. + }
  62078. +
  62079. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  62080. + if (!notifier) {
  62081. + return NULL;
  62082. + }
  62083. +
  62084. + DWC_CIRCLEQ_INIT(&notifier->observers);
  62085. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  62086. +
  62087. + notifier->mem_ctx = mem_ctx;
  62088. + notifier->object = object;
  62089. + return notifier;
  62090. +}
  62091. +
  62092. +static void free_notifier(notifier_t *notifier)
  62093. +{
  62094. + observer_t *observer;
  62095. +
  62096. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  62097. + free_observer(notifier->mem_ctx, observer);
  62098. + }
  62099. +
  62100. + dwc_free(notifier->mem_ctx, notifier);
  62101. +}
  62102. +
  62103. +static notifier_t *find_notifier(void *object)
  62104. +{
  62105. + notifier_t *notifier;
  62106. +
  62107. + DWC_ASSERT(manager, "Notification manager not found");
  62108. +
  62109. + if (!object) {
  62110. + return NULL;
  62111. + }
  62112. +
  62113. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  62114. + if (notifier->object == object) {
  62115. + return notifier;
  62116. + }
  62117. + }
  62118. +
  62119. + return NULL;
  62120. +}
  62121. +
  62122. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  62123. +{
  62124. + return create_manager(mem_ctx, wkq_ctx);
  62125. +}
  62126. +
  62127. +void dwc_free_notification_manager(void)
  62128. +{
  62129. + free_manager();
  62130. +}
  62131. +
  62132. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  62133. +{
  62134. + notifier_t *notifier;
  62135. +
  62136. + DWC_ASSERT(manager, "Notification manager not found");
  62137. +
  62138. + notifier = find_notifier(object);
  62139. + if (notifier) {
  62140. + DWC_ERROR("Notifier %p is already registered\n", object);
  62141. + return NULL;
  62142. + }
  62143. +
  62144. + notifier = alloc_notifier(mem_ctx, object);
  62145. + if (!notifier) {
  62146. + return NULL;
  62147. + }
  62148. +
  62149. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  62150. +
  62151. + DWC_INFO("Notifier %p registered", object);
  62152. + dump_manager();
  62153. +
  62154. + return notifier;
  62155. +}
  62156. +
  62157. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  62158. +{
  62159. + DWC_ASSERT(manager, "Notification manager not found");
  62160. +
  62161. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  62162. + observer_t *o;
  62163. +
  62164. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  62165. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  62166. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  62167. + }
  62168. +
  62169. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  62170. + "Notifier %p has active observers when removing", notifier);
  62171. + }
  62172. +
  62173. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  62174. + free_notifier(notifier);
  62175. +
  62176. + DWC_INFO("Notifier unregistered");
  62177. + dump_manager();
  62178. +}
  62179. +
  62180. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  62181. +int dwc_add_observer(void *observer, void *object, char *notification,
  62182. + dwc_notifier_callback_t callback, void *data)
  62183. +{
  62184. + notifier_t *notifier = find_notifier(object);
  62185. + observer_t *new_observer;
  62186. +
  62187. + if (!notifier) {
  62188. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  62189. + return -DWC_E_INVALID;
  62190. + }
  62191. +
  62192. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  62193. + if (!new_observer) {
  62194. + return -DWC_E_NO_MEMORY;
  62195. + }
  62196. +
  62197. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  62198. +
  62199. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  62200. + observer, object, notification, callback, data);
  62201. +
  62202. + dump_manager();
  62203. + return 0;
  62204. +}
  62205. +
  62206. +int dwc_remove_observer(void *observer)
  62207. +{
  62208. + notifier_t *n;
  62209. +
  62210. + DWC_ASSERT(manager, "Notification manager not found");
  62211. +
  62212. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  62213. + observer_t *o;
  62214. + observer_t *o2;
  62215. +
  62216. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  62217. + if (o->observer == observer) {
  62218. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  62219. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  62220. + o->observer, n->object, o->notification);
  62221. + free_observer(n->mem_ctx, o);
  62222. + }
  62223. + }
  62224. + }
  62225. +
  62226. + dump_manager();
  62227. + return 0;
  62228. +}
  62229. +
  62230. +typedef struct callback_data {
  62231. + void *mem_ctx;
  62232. + dwc_notifier_callback_t cb;
  62233. + void *observer;
  62234. + void *data;
  62235. + void *object;
  62236. + char *notification;
  62237. + void *notification_data;
  62238. +} cb_data_t;
  62239. +
  62240. +static void cb_task(void *data)
  62241. +{
  62242. + cb_data_t *cb = (cb_data_t *)data;
  62243. +
  62244. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  62245. + dwc_free(cb->mem_ctx, cb);
  62246. +}
  62247. +
  62248. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  62249. +{
  62250. + observer_t *o;
  62251. +
  62252. + DWC_ASSERT(manager, "Notification manager not found");
  62253. +
  62254. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  62255. + int len = DWC_STRLEN(notification);
  62256. +
  62257. + if (DWC_STRLEN(o->notification) != len) {
  62258. + continue;
  62259. + }
  62260. +
  62261. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  62262. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  62263. +
  62264. + if (!cb_data) {
  62265. + DWC_ERROR("Failed to allocate callback data\n");
  62266. + return;
  62267. + }
  62268. +
  62269. + cb_data->mem_ctx = notifier->mem_ctx;
  62270. + cb_data->cb = o->callback;
  62271. + cb_data->observer = o->observer;
  62272. + cb_data->data = o->data;
  62273. + cb_data->object = notifier->object;
  62274. + cb_data->notification = notification;
  62275. + cb_data->notification_data = notification_data;
  62276. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  62277. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  62278. + "Notify callback from %p for Notification %s, to observer %p",
  62279. + cb_data->object, notification, cb_data->observer);
  62280. + }
  62281. + }
  62282. +}
  62283. +
  62284. +#endif /* DWC_NOTIFYLIB */
  62285. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  62286. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  62287. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2015-03-09 10:39:33.214893718 +0100
  62288. @@ -0,0 +1,122 @@
  62289. +
  62290. +#ifndef __DWC_NOTIFIER_H__
  62291. +#define __DWC_NOTIFIER_H__
  62292. +
  62293. +#ifdef __cplusplus
  62294. +extern "C" {
  62295. +#endif
  62296. +
  62297. +#include "dwc_os.h"
  62298. +
  62299. +/** @file
  62300. + *
  62301. + * A simple implementation of the Observer pattern. Any "module" can
  62302. + * register as an observer or notifier. The notion of "module" is abstract and
  62303. + * can mean anything used to identify either an observer or notifier. Usually
  62304. + * it will be a pointer to a data structure which contains some state, ie an
  62305. + * object.
  62306. + *
  62307. + * Before any notifiers can be added, the global notification manager must be
  62308. + * brought up with dwc_alloc_notification_manager().
  62309. + * dwc_free_notification_manager() will bring it down and free all resources.
  62310. + * These would typically be called upon module load and unload. The
  62311. + * notification manager is a single global instance that handles all registered
  62312. + * observable modules and observers so this should be done only once.
  62313. + *
  62314. + * A module can be observable by using Notifications to publicize some general
  62315. + * information about it's state or operation. It does not care who listens, or
  62316. + * even if anyone listens, or what they do with the information. The observable
  62317. + * modules do not need to know any information about it's observers or their
  62318. + * interface, or their state or data.
  62319. + *
  62320. + * Any module can register to emit Notifications. It should publish a list of
  62321. + * notifications that it can emit and their behavior, such as when they will get
  62322. + * triggered, and what information will be provided to the observer. Then it
  62323. + * should register itself as an observable module. See dwc_register_notifier().
  62324. + *
  62325. + * Any module can observe any observable, registered module, provided it has a
  62326. + * handle to the other module and knows what notifications to observe. See
  62327. + * dwc_add_observer().
  62328. + *
  62329. + * A function of type dwc_notifier_callback_t is called whenever a notification
  62330. + * is triggered with one or more observers observing it. This function is
  62331. + * called in it's own process so it may sleep or block if needed. It is
  62332. + * guaranteed to be called sometime after the notification has occurred and will
  62333. + * be called once per each time the notification is triggered. It will NOT be
  62334. + * called in the same process context used to trigger the notification.
  62335. + *
  62336. + * @section Limitiations
  62337. + *
  62338. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  62339. + * schedule too many processes too handle. Be aware of this limitation when
  62340. + * designing to use notifications, and only add notifications for appropriate
  62341. + * observable information.
  62342. + *
  62343. + * Also Notification callbacks are not synchronous. If you need to synchronize
  62344. + * the behavior between module/observer you must use other means. And perhaps
  62345. + * that will mean Notifications are not the proper solution.
  62346. + */
  62347. +
  62348. +struct dwc_notifier;
  62349. +typedef struct dwc_notifier dwc_notifier_t;
  62350. +
  62351. +/** The callback function must be of this type.
  62352. + *
  62353. + * @param object This is the object that is being observed.
  62354. + * @param notification This is the notification that was triggered.
  62355. + * @param observer This is the observer
  62356. + * @param notification_data This is notification-specific data that the notifier
  62357. + * has included in this notification. The value of this should be published in
  62358. + * the documentation of the observable module with the notifications.
  62359. + * @param user_data This is any custom data that the observer provided when
  62360. + * adding itself as an observer to the notification. */
  62361. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  62362. + void *notification_data, void *user_data);
  62363. +
  62364. +/** Brings up the notification manager. */
  62365. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  62366. +/** Brings down the notification manager. */
  62367. +extern void dwc_free_notification_manager(void);
  62368. +
  62369. +/** This function registers an observable module. A dwc_notifier_t object is
  62370. + * returned to the observable module. This is an opaque object that is used by
  62371. + * the observable module to trigger notifications. This object should only be
  62372. + * accessible to functions that are authorized to trigger notifications for this
  62373. + * module. Observers do not need this object. */
  62374. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  62375. +
  62376. +/** This function unregisters an observable module. All observers have to be
  62377. + * removed prior to unregistration. */
  62378. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  62379. +
  62380. +/** Add a module as an observer to the observable module. The observable module
  62381. + * needs to have previously registered with the notification manager.
  62382. + *
  62383. + * @param observer The observer module
  62384. + * @param object The module to observe
  62385. + * @param notification The notification to observe
  62386. + * @param callback The callback function to call
  62387. + * @param user_data Any additional user data to pass into the callback function */
  62388. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  62389. + dwc_notifier_callback_t callback, void *user_data);
  62390. +
  62391. +/** Removes the specified observer from all notifications that it is currently
  62392. + * observing. */
  62393. +extern int dwc_remove_observer(void *observer);
  62394. +
  62395. +/** This function triggers a Notification. It should be called by the
  62396. + * observable module, or any module or library which the observable module
  62397. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  62398. + *
  62399. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  62400. + * their own process context for each trigger. Callbacks can be blocking.
  62401. + * dwc_notify can be called from interrupt context if needed.
  62402. + *
  62403. + */
  62404. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  62405. +
  62406. +#ifdef __cplusplus
  62407. +}
  62408. +#endif
  62409. +
  62410. +#endif /* __DWC_NOTIFIER_H__ */
  62411. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  62412. --- linux-3.12.38/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  62413. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2015-03-10 17:26:51.302216687 +0100
  62414. @@ -0,0 +1,1262 @@
  62415. +/* =========================================================================
  62416. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  62417. + * $Revision: #14 $
  62418. + * $Date: 2010/11/04 $
  62419. + * $Change: 1621695 $
  62420. + *
  62421. + * Synopsys Portability Library Software and documentation
  62422. + * (hereinafter, "Software") is an Unsupported proprietary work of
  62423. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  62424. + * between Synopsys and you.
  62425. + *
  62426. + * The Software IS NOT an item of Licensed Software or Licensed Product
  62427. + * under any End User Software License Agreement or Agreement for
  62428. + * Licensed Product with Synopsys or any supplement thereto. You are
  62429. + * permitted to use and redistribute this Software in source and binary
  62430. + * forms, with or without modification, provided that redistributions
  62431. + * of source code must retain this notice. You may not view, use,
  62432. + * disclose, copy or distribute this file or any information contained
  62433. + * herein except pursuant to this license grant from Synopsys. If you
  62434. + * do not agree with this notice, including the disclaimer below, then
  62435. + * you are not authorized to use the Software.
  62436. + *
  62437. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  62438. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  62439. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  62440. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  62441. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  62442. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  62443. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  62444. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  62445. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  62446. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  62447. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62448. + * DAMAGE.
  62449. + * ========================================================================= */
  62450. +#ifndef _DWC_OS_H_
  62451. +#define _DWC_OS_H_
  62452. +
  62453. +#ifdef __cplusplus
  62454. +extern "C" {
  62455. +#endif
  62456. +
  62457. +/** @file
  62458. + *
  62459. + * DWC portability library, low level os-wrapper functions
  62460. + *
  62461. + */
  62462. +
  62463. +/* These basic types need to be defined by some OS header file or custom header
  62464. + * file for your specific target architecture.
  62465. + *
  62466. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  62467. + *
  62468. + * Any custom or alternate header file must be added and enabled here.
  62469. + */
  62470. +
  62471. +#ifdef DWC_LINUX
  62472. +# include <linux/types.h>
  62473. +# ifdef CONFIG_DEBUG_MUTEXES
  62474. +# include <linux/mutex.h>
  62475. +# endif
  62476. +# include <linux/errno.h>
  62477. +# include <stdarg.h>
  62478. +#endif
  62479. +
  62480. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62481. +# include <os_dep.h>
  62482. +#endif
  62483. +
  62484. +
  62485. +/** @name Primitive Types and Values */
  62486. +
  62487. +/** We define a boolean type for consistency. Can be either YES or NO */
  62488. +typedef uint8_t dwc_bool_t;
  62489. +#define YES 1
  62490. +#define NO 0
  62491. +
  62492. +#ifdef DWC_LINUX
  62493. +
  62494. +/** @name Error Codes */
  62495. +#define DWC_E_INVALID EINVAL
  62496. +#define DWC_E_NO_MEMORY ENOMEM
  62497. +#define DWC_E_NO_DEVICE ENODEV
  62498. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  62499. +#define DWC_E_TIMEOUT ETIMEDOUT
  62500. +#define DWC_E_BUSY EBUSY
  62501. +#define DWC_E_AGAIN EAGAIN
  62502. +#define DWC_E_RESTART ERESTART
  62503. +#define DWC_E_ABORT ECONNABORTED
  62504. +#define DWC_E_SHUTDOWN ESHUTDOWN
  62505. +#define DWC_E_NO_DATA ENODATA
  62506. +#define DWC_E_DISCONNECT ECONNRESET
  62507. +#define DWC_E_UNKNOWN EINVAL
  62508. +#define DWC_E_NO_STREAM_RES ENOSR
  62509. +#define DWC_E_COMMUNICATION ECOMM
  62510. +#define DWC_E_OVERFLOW EOVERFLOW
  62511. +#define DWC_E_PROTOCOL EPROTO
  62512. +#define DWC_E_IN_PROGRESS EINPROGRESS
  62513. +#define DWC_E_PIPE EPIPE
  62514. +#define DWC_E_IO EIO
  62515. +#define DWC_E_NO_SPACE ENOSPC
  62516. +
  62517. +#else
  62518. +
  62519. +/** @name Error Codes */
  62520. +#define DWC_E_INVALID 1001
  62521. +#define DWC_E_NO_MEMORY 1002
  62522. +#define DWC_E_NO_DEVICE 1003
  62523. +#define DWC_E_NOT_SUPPORTED 1004
  62524. +#define DWC_E_TIMEOUT 1005
  62525. +#define DWC_E_BUSY 1006
  62526. +#define DWC_E_AGAIN 1007
  62527. +#define DWC_E_RESTART 1008
  62528. +#define DWC_E_ABORT 1009
  62529. +#define DWC_E_SHUTDOWN 1010
  62530. +#define DWC_E_NO_DATA 1011
  62531. +#define DWC_E_DISCONNECT 2000
  62532. +#define DWC_E_UNKNOWN 3000
  62533. +#define DWC_E_NO_STREAM_RES 4001
  62534. +#define DWC_E_COMMUNICATION 4002
  62535. +#define DWC_E_OVERFLOW 4003
  62536. +#define DWC_E_PROTOCOL 4004
  62537. +#define DWC_E_IN_PROGRESS 4005
  62538. +#define DWC_E_PIPE 4006
  62539. +#define DWC_E_IO 4007
  62540. +#define DWC_E_NO_SPACE 4008
  62541. +
  62542. +#endif
  62543. +
  62544. +
  62545. +/** @name Tracing/Logging Functions
  62546. + *
  62547. + * These function provide the capability to add tracing, debugging, and error
  62548. + * messages, as well exceptions as assertions. The WUDEV uses these
  62549. + * extensively. These could be logged to the main console, the serial port, an
  62550. + * internal buffer, etc. These functions could also be no-op if they are too
  62551. + * expensive on your system. By default undefining the DEBUG macro already
  62552. + * no-ops some of these functions. */
  62553. +
  62554. +/** Returns non-zero if in interrupt context. */
  62555. +extern dwc_bool_t DWC_IN_IRQ(void);
  62556. +#define dwc_in_irq DWC_IN_IRQ
  62557. +
  62558. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  62559. +static inline char *dwc_irq(void) {
  62560. + return DWC_IN_IRQ() ? "IRQ" : "";
  62561. +}
  62562. +
  62563. +/** Returns non-zero if in bottom-half context. */
  62564. +extern dwc_bool_t DWC_IN_BH(void);
  62565. +#define dwc_in_bh DWC_IN_BH
  62566. +
  62567. +/** Returns "BH" if DWC_IN_BH is true. */
  62568. +static inline char *dwc_bh(void) {
  62569. + return DWC_IN_BH() ? "BH" : "";
  62570. +}
  62571. +
  62572. +/**
  62573. + * A vprintf() clone. Just call vprintf if you've got it.
  62574. + */
  62575. +extern void DWC_VPRINTF(char *format, va_list args);
  62576. +#define dwc_vprintf DWC_VPRINTF
  62577. +
  62578. +/**
  62579. + * A vsnprintf() clone. Just call vprintf if you've got it.
  62580. + */
  62581. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  62582. +#define dwc_vsnprintf DWC_VSNPRINTF
  62583. +
  62584. +/**
  62585. + * printf() clone. Just call printf if you've go it.
  62586. + */
  62587. +extern void DWC_PRINTF(char *format, ...)
  62588. +/* This provides compiler level static checking of the parameters if you're
  62589. + * using GCC. */
  62590. +#ifdef __GNUC__
  62591. + __attribute__ ((format(printf, 1, 2)));
  62592. +#else
  62593. + ;
  62594. +#endif
  62595. +#define dwc_printf DWC_PRINTF
  62596. +
  62597. +/**
  62598. + * sprintf() clone. Just call sprintf if you've got it.
  62599. + */
  62600. +extern int DWC_SPRINTF(char *string, char *format, ...)
  62601. +#ifdef __GNUC__
  62602. + __attribute__ ((format(printf, 2, 3)));
  62603. +#else
  62604. + ;
  62605. +#endif
  62606. +#define dwc_sprintf DWC_SPRINTF
  62607. +
  62608. +/**
  62609. + * snprintf() clone. Just call snprintf if you've got it.
  62610. + */
  62611. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  62612. +#ifdef __GNUC__
  62613. + __attribute__ ((format(printf, 3, 4)));
  62614. +#else
  62615. + ;
  62616. +#endif
  62617. +#define dwc_snprintf DWC_SNPRINTF
  62618. +
  62619. +/**
  62620. + * Prints a WARNING message. On systems that don't differentiate between
  62621. + * warnings and regular log messages, just print it. Indicates that something
  62622. + * may be wrong with the driver. Works like printf().
  62623. + *
  62624. + * Use the DWC_WARN macro to call this function.
  62625. + */
  62626. +extern void __DWC_WARN(char *format, ...)
  62627. +#ifdef __GNUC__
  62628. + __attribute__ ((format(printf, 1, 2)));
  62629. +#else
  62630. + ;
  62631. +#endif
  62632. +
  62633. +/**
  62634. + * Prints an error message. On systems that don't differentiate between errors
  62635. + * and regular log messages, just print it. Indicates that something went wrong
  62636. + * with the driver. Works like printf().
  62637. + *
  62638. + * Use the DWC_ERROR macro to call this function.
  62639. + */
  62640. +extern void __DWC_ERROR(char *format, ...)
  62641. +#ifdef __GNUC__
  62642. + __attribute__ ((format(printf, 1, 2)));
  62643. +#else
  62644. + ;
  62645. +#endif
  62646. +
  62647. +/**
  62648. + * Prints an exception error message and takes some user-defined action such as
  62649. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  62650. + * abnormally wrong with the driver such as programmer error, or other
  62651. + * exceptional condition. It should not be ignored so even on systems without
  62652. + * printing capability, some action should be taken to notify the developer of
  62653. + * it. Works like printf().
  62654. + */
  62655. +extern void DWC_EXCEPTION(char *format, ...)
  62656. +#ifdef __GNUC__
  62657. + __attribute__ ((format(printf, 1, 2)));
  62658. +#else
  62659. + ;
  62660. +#endif
  62661. +#define dwc_exception DWC_EXCEPTION
  62662. +
  62663. +#ifndef DWC_OTG_DEBUG_LEV
  62664. +#define DWC_OTG_DEBUG_LEV 0
  62665. +#endif
  62666. +
  62667. +#ifdef DEBUG
  62668. +/**
  62669. + * Prints out a debug message. Used for logging/trace messages.
  62670. + *
  62671. + * Use the DWC_DEBUG macro to call this function
  62672. + */
  62673. +extern void __DWC_DEBUG(char *format, ...)
  62674. +#ifdef __GNUC__
  62675. + __attribute__ ((format(printf, 1, 2)));
  62676. +#else
  62677. + ;
  62678. +#endif
  62679. +#else
  62680. +#define __DWC_DEBUG printk
  62681. +#endif
  62682. +
  62683. +/**
  62684. + * Prints out a Debug message.
  62685. + */
  62686. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  62687. + __func__, dwc_irq(), ## _args)
  62688. +#define dwc_debug DWC_DEBUG
  62689. +/**
  62690. + * Prints out a Debug message if enabled at compile time.
  62691. + */
  62692. +#if DWC_OTG_DEBUG_LEV > 0
  62693. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  62694. +#else
  62695. +#define DWC_DEBUGC(_format, _args...)
  62696. +#endif
  62697. +#define dwc_debugc DWC_DEBUGC
  62698. +/**
  62699. + * Prints out an informative message.
  62700. + */
  62701. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  62702. + dwc_irq(), ## _args)
  62703. +#define dwc_info DWC_INFO
  62704. +/**
  62705. + * Prints out an informative message if enabled at compile time.
  62706. + */
  62707. +#if DWC_OTG_DEBUG_LEV > 1
  62708. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  62709. +#else
  62710. +#define DWC_INFOC(_format, _args...)
  62711. +#endif
  62712. +#define dwc_infoc DWC_INFOC
  62713. +/**
  62714. + * Prints out a warning message.
  62715. + */
  62716. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  62717. + dwc_irq(), __func__, __LINE__, ## _args)
  62718. +#define dwc_warn DWC_WARN
  62719. +/**
  62720. + * Prints out an error message.
  62721. + */
  62722. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  62723. + dwc_irq(), __func__, __LINE__, ## _args)
  62724. +#define dwc_error DWC_ERROR
  62725. +
  62726. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  62727. + dwc_irq(), __func__, __LINE__, ## _args)
  62728. +#define dwc_proto_error DWC_PROTO_ERROR
  62729. +
  62730. +#ifdef DEBUG
  62731. +/** Prints out a exception error message if the _expr expression fails. Disabled
  62732. + * if DEBUG is not enabled. */
  62733. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  62734. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  62735. + __FILE__, __LINE__, ## _args); } \
  62736. + } while (0)
  62737. +#else
  62738. +#define DWC_ASSERT(_x...)
  62739. +#endif
  62740. +#define dwc_assert DWC_ASSERT
  62741. +
  62742. +
  62743. +/** @name Byte Ordering
  62744. + * The following functions are for conversions between processor's byte ordering
  62745. + * and specific ordering you want.
  62746. + */
  62747. +
  62748. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  62749. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  62750. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  62751. +
  62752. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  62753. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  62754. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  62755. +
  62756. +/** Converts 32 bit little endian data to CPU byte ordering. */
  62757. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  62758. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  62759. +
  62760. +/** Converts 32 bit big endian data to CPU byte ordering. */
  62761. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  62762. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  62763. +
  62764. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  62765. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  62766. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  62767. +
  62768. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  62769. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  62770. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  62771. +
  62772. +/** Converts 16 bit little endian data to CPU byte ordering. */
  62773. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  62774. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  62775. +
  62776. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  62777. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  62778. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  62779. +
  62780. +
  62781. +/** @name Register Read/Write
  62782. + *
  62783. + * The following six functions should be implemented to read/write registers of
  62784. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  62785. + * The reg value is a pointer to the register calculated from the void *base
  62786. + * variable passed into the driver when it is started. */
  62787. +
  62788. +#ifdef DWC_LINUX
  62789. +/* Linux doesn't need any extra parameters for register read/write, so we
  62790. + * just throw away the IO context parameter.
  62791. + */
  62792. +/** Reads the content of a 32-bit register. */
  62793. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  62794. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  62795. +
  62796. +/** Reads the content of a 64-bit register. */
  62797. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  62798. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  62799. +
  62800. +/** Writes to a 32-bit register. */
  62801. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  62802. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  62803. +
  62804. +/** Writes to a 64-bit register. */
  62805. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  62806. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  62807. +
  62808. +/**
  62809. + * Modify bit values in a register. Using the
  62810. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  62811. + */
  62812. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  62813. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  62814. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  62815. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  62816. +
  62817. +#endif /* DWC_LINUX */
  62818. +
  62819. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62820. +typedef struct dwc_ioctx {
  62821. + struct device *dev;
  62822. + bus_space_tag_t iot;
  62823. + bus_space_handle_t ioh;
  62824. +} dwc_ioctx_t;
  62825. +
  62826. +/** BSD needs two extra parameters for register read/write, so we pass
  62827. + * them in using the IO context parameter.
  62828. + */
  62829. +/** Reads the content of a 32-bit register. */
  62830. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  62831. +#define dwc_read_reg32 DWC_READ_REG32
  62832. +
  62833. +/** Reads the content of a 64-bit register. */
  62834. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  62835. +#define dwc_read_reg64 DWC_READ_REG64
  62836. +
  62837. +/** Writes to a 32-bit register. */
  62838. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  62839. +#define dwc_write_reg32 DWC_WRITE_REG32
  62840. +
  62841. +/** Writes to a 64-bit register. */
  62842. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  62843. +#define dwc_write_reg64 DWC_WRITE_REG64
  62844. +
  62845. +/**
  62846. + * Modify bit values in a register. Using the
  62847. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  62848. + */
  62849. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  62850. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  62851. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  62852. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  62853. +
  62854. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  62855. +
  62856. +/** @cond */
  62857. +
  62858. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  62859. + * register writes. */
  62860. +
  62861. +#ifdef DWC_LINUX
  62862. +
  62863. +# ifdef DWC_DEBUG_REGS
  62864. +
  62865. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62866. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  62867. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  62868. +} \
  62869. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  62870. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  62871. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  62872. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  62873. +}
  62874. +
  62875. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62876. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  62877. + return DWC_READ_REG32(&container->regs->_reg); \
  62878. +} \
  62879. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  62880. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  62881. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  62882. +}
  62883. +
  62884. +# else /* DWC_DEBUG_REGS */
  62885. +
  62886. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62887. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  62888. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  62889. +} \
  62890. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  62891. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  62892. +}
  62893. +
  62894. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62895. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  62896. + return DWC_READ_REG32(&container->regs->_reg); \
  62897. +} \
  62898. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  62899. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  62900. +}
  62901. +
  62902. +# endif /* DWC_DEBUG_REGS */
  62903. +
  62904. +#endif /* DWC_LINUX */
  62905. +
  62906. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  62907. +
  62908. +# ifdef DWC_DEBUG_REGS
  62909. +
  62910. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62911. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  62912. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  62913. +} \
  62914. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  62915. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  62916. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  62917. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  62918. +}
  62919. +
  62920. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62921. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  62922. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  62923. +} \
  62924. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  62925. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  62926. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  62927. +}
  62928. +
  62929. +# else /* DWC_DEBUG_REGS */
  62930. +
  62931. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  62932. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  62933. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  62934. +} \
  62935. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  62936. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  62937. +}
  62938. +
  62939. +#define dwc_define_read_write_reg(_reg,_container_type) \
  62940. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  62941. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  62942. +} \
  62943. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  62944. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  62945. +}
  62946. +
  62947. +# endif /* DWC_DEBUG_REGS */
  62948. +
  62949. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  62950. +
  62951. +/** @endcond */
  62952. +
  62953. +
  62954. +#ifdef DWC_CRYPTOLIB
  62955. +/** @name Crypto Functions
  62956. + *
  62957. + * These are the low-level cryptographic functions used by the driver. */
  62958. +
  62959. +/** Perform AES CBC */
  62960. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  62961. +#define dwc_aes_cbc DWC_AES_CBC
  62962. +
  62963. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  62964. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  62965. +#define dwc_random_bytes DWC_RANDOM_BYTES
  62966. +
  62967. +/** Perform the SHA-256 hash function */
  62968. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  62969. +#define dwc_sha256 DWC_SHA256
  62970. +
  62971. +/** Calculated the HMAC-SHA256 */
  62972. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  62973. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  62974. +
  62975. +#endif /* DWC_CRYPTOLIB */
  62976. +
  62977. +
  62978. +/** @name Memory Allocation
  62979. + *
  62980. + * These function provide access to memory allocation. There are only 2 DMA
  62981. + * functions and 3 Regular memory functions that need to be implemented. None
  62982. + * of the memory debugging routines need to be implemented. The allocation
  62983. + * routines all ZERO the contents of the memory.
  62984. + *
  62985. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  62986. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  62987. + * keeps track of how much memory the driver is using at any given time. */
  62988. +
  62989. +#define DWC_PAGE_SIZE 4096
  62990. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  62991. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  62992. +
  62993. +#define DWC_INVALID_DMA_ADDR 0x0
  62994. +
  62995. +#ifdef DWC_LINUX
  62996. +/** Type for a DMA address */
  62997. +typedef dma_addr_t dwc_dma_t;
  62998. +#endif
  62999. +
  63000. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  63001. +typedef bus_addr_t dwc_dma_t;
  63002. +#endif
  63003. +
  63004. +#ifdef DWC_FREEBSD
  63005. +typedef struct dwc_dmactx {
  63006. + struct device *dev;
  63007. + bus_dma_tag_t dma_tag;
  63008. + bus_dmamap_t dma_map;
  63009. + bus_addr_t dma_paddr;
  63010. + void *dma_vaddr;
  63011. +} dwc_dmactx_t;
  63012. +#endif
  63013. +
  63014. +#ifdef DWC_NETBSD
  63015. +typedef struct dwc_dmactx {
  63016. + struct device *dev;
  63017. + bus_dma_tag_t dma_tag;
  63018. + bus_dmamap_t dma_map;
  63019. + bus_dma_segment_t segs[1];
  63020. + int nsegs;
  63021. + bus_addr_t dma_paddr;
  63022. + void *dma_vaddr;
  63023. +} dwc_dmactx_t;
  63024. +#endif
  63025. +
  63026. +/* @todo these functions will be added in the future */
  63027. +#if 0
  63028. +/**
  63029. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  63030. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  63031. + * boundary requirements specified.
  63032. + *
  63033. + * @param[in] size Specifies the size of the buffers that will be allocated from
  63034. + * this pool.
  63035. + * @param[in] align Specifies the byte alignment requirements of the buffers
  63036. + * allocated from this pool. Must be a power of 2.
  63037. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  63038. + * this pool must not cross.
  63039. + *
  63040. + * @returns A pointer to an internal opaque structure which is not to be
  63041. + * accessed outside of these library functions. Use this handle to specify
  63042. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  63043. + * when you are done with it.
  63044. + */
  63045. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  63046. +
  63047. +/**
  63048. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  63049. + */
  63050. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  63051. +
  63052. +/**
  63053. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  63054. + */
  63055. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  63056. +
  63057. +/**
  63058. + * Free a previously allocated buffer from the DMA pool.
  63059. + */
  63060. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  63061. +#endif
  63062. +
  63063. +/** Allocates a DMA capable buffer and zeroes its contents. */
  63064. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  63065. +
  63066. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  63067. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  63068. +
  63069. +/** Frees a previously allocated buffer. */
  63070. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  63071. +
  63072. +/** Allocates a block of memory and zeroes its contents. */
  63073. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  63074. +
  63075. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  63076. + * which can be used inside interrupt context. The size should be sufficiently
  63077. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  63078. + * __DWC_ALLOC if it is atomic. */
  63079. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  63080. +
  63081. +/** Frees a previously allocated buffer. */
  63082. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  63083. +
  63084. +#ifndef DWC_DEBUG_MEMORY
  63085. +
  63086. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  63087. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  63088. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  63089. +
  63090. +# ifdef DWC_LINUX
  63091. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  63092. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  63093. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  63094. +# endif
  63095. +
  63096. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  63097. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  63098. +#define DWC_DMA_FREE __DWC_DMA_FREE
  63099. +# endif
  63100. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  63101. +
  63102. +#else /* DWC_DEBUG_MEMORY */
  63103. +
  63104. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  63105. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  63106. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  63107. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  63108. + char const *func, int line);
  63109. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  63110. + char const *func, int line);
  63111. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  63112. + dwc_dma_t dma_addr, char const *func, int line);
  63113. +
  63114. +extern int dwc_memory_debug_start(void *mem_ctx);
  63115. +extern void dwc_memory_debug_stop(void);
  63116. +extern void dwc_memory_debug_report(void);
  63117. +
  63118. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  63119. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  63120. + __func__, __LINE__)
  63121. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  63122. +
  63123. +# ifdef DWC_LINUX
  63124. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  63125. + _dma_, __func__, __LINE__)
  63126. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  63127. + _dma_, __func__, __LINE__)
  63128. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  63129. + _virt_, _dma_, __func__, __LINE__)
  63130. +# endif
  63131. +
  63132. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  63133. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  63134. + _dma_, __func__, __LINE__)
  63135. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  63136. + _virt_, _dma_, __func__, __LINE__)
  63137. +# endif
  63138. +
  63139. +#endif /* DWC_DEBUG_MEMORY */
  63140. +
  63141. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  63142. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  63143. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  63144. +
  63145. +#ifdef DWC_LINUX
  63146. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  63147. + * just throw away the DMA context parameter.
  63148. + */
  63149. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  63150. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  63151. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  63152. +#endif
  63153. +
  63154. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  63155. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  63156. + * them in using the DMA context parameter.
  63157. + */
  63158. +#define dwc_dma_alloc DWC_DMA_ALLOC
  63159. +#define dwc_dma_free DWC_DMA_FREE
  63160. +#endif
  63161. +
  63162. +
  63163. +/** @name Memory and String Processing */
  63164. +
  63165. +/** memset() clone */
  63166. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  63167. +#define dwc_memset DWC_MEMSET
  63168. +
  63169. +/** memcpy() clone */
  63170. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  63171. +#define dwc_memcpy DWC_MEMCPY
  63172. +
  63173. +/** memmove() clone */
  63174. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  63175. +#define dwc_memmove DWC_MEMMOVE
  63176. +
  63177. +/** memcmp() clone */
  63178. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  63179. +#define dwc_memcmp DWC_MEMCMP
  63180. +
  63181. +/** strcmp() clone */
  63182. +extern int DWC_STRCMP(void *s1, void *s2);
  63183. +#define dwc_strcmp DWC_STRCMP
  63184. +
  63185. +/** strncmp() clone */
  63186. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  63187. +#define dwc_strncmp DWC_STRNCMP
  63188. +
  63189. +/** strlen() clone, for NULL terminated ASCII strings */
  63190. +extern int DWC_STRLEN(char const *str);
  63191. +#define dwc_strlen DWC_STRLEN
  63192. +
  63193. +/** strcpy() clone, for NULL terminated ASCII strings */
  63194. +extern char *DWC_STRCPY(char *to, const char *from);
  63195. +#define dwc_strcpy DWC_STRCPY
  63196. +
  63197. +/** strdup() clone. If you wish to use memory allocation debugging, this
  63198. + * implementation of strdup should use the DWC_* memory routines instead of
  63199. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  63200. + * will not be seen by the debugging routines. */
  63201. +extern char *DWC_STRDUP(char const *str);
  63202. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  63203. +
  63204. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  63205. + * converted from the string str in base 10 unless the string begins with a "0x"
  63206. + * in which case it is base 16. String must be a NULL terminated sequence of
  63207. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  63208. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  63209. + * the number and end with a NULL character. If any invalid characters are
  63210. + * encountered or it returns with a negative error code and the results of the
  63211. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  63212. + * undefined. An example implementation using atoi() can be referenced from the
  63213. + * Linux implementation. */
  63214. +extern int DWC_ATOI(const char *str, int32_t *value);
  63215. +#define dwc_atoi DWC_ATOI
  63216. +
  63217. +/** Same as above but for unsigned. */
  63218. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  63219. +#define dwc_atoui DWC_ATOUI
  63220. +
  63221. +#ifdef DWC_UTFLIB
  63222. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  63223. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  63224. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  63225. +#endif
  63226. +
  63227. +
  63228. +/** @name Wait queues
  63229. + *
  63230. + * Wait queues provide a means of synchronizing between threads or processes. A
  63231. + * process can block on a waitq if some condition is not true, waiting for it to
  63232. + * become true. When the waitq is triggered all waiting process will get
  63233. + * unblocked and the condition will be check again. Waitqs should be triggered
  63234. + * every time a condition can potentially change.*/
  63235. +struct dwc_waitq;
  63236. +
  63237. +/** Type for a waitq */
  63238. +typedef struct dwc_waitq dwc_waitq_t;
  63239. +
  63240. +/** The type of waitq condition callback function. This is called every time
  63241. + * condition is evaluated. */
  63242. +typedef int (*dwc_waitq_condition_t)(void *data);
  63243. +
  63244. +/** Allocate a waitq */
  63245. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  63246. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  63247. +
  63248. +/** Free a waitq */
  63249. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  63250. +#define dwc_waitq_free DWC_WAITQ_FREE
  63251. +
  63252. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  63253. + * condition again. The function returns when the condition becomes true. The return value
  63254. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  63255. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  63256. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  63257. +
  63258. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  63259. + * check the condition again. The function returns when the condition become
  63260. + * true or the timeout has passed. The return value is 0 on condition true or
  63261. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  63262. + * error. */
  63263. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  63264. + void *data, int32_t msecs);
  63265. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  63266. +
  63267. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  63268. + * has potentially changed. */
  63269. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  63270. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  63271. +
  63272. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  63273. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  63274. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  63275. +
  63276. +
  63277. +/** @name Threads
  63278. + *
  63279. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  63280. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  63281. + * returns the value from the thread.
  63282. + */
  63283. +
  63284. +struct dwc_thread;
  63285. +
  63286. +/** Type for a thread */
  63287. +typedef struct dwc_thread dwc_thread_t;
  63288. +
  63289. +/** The thread function */
  63290. +typedef int (*dwc_thread_function_t)(void *data);
  63291. +
  63292. +/** Create a thread and start it running the thread_function. Returns a handle
  63293. + * to the thread */
  63294. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  63295. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  63296. +
  63297. +/** Stops a thread. Return the value returned by the thread. Or will return
  63298. + * DWC_ABORT if the thread never started. */
  63299. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  63300. +#define dwc_thread_stop DWC_THREAD_STOP
  63301. +
  63302. +/** Signifies to the thread that it must stop. */
  63303. +#ifdef DWC_LINUX
  63304. +/* Linux doesn't need any parameters for kthread_should_stop() */
  63305. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  63306. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  63307. +
  63308. +/* No thread_exit function in Linux */
  63309. +#define dwc_thread_exit(_thrd_)
  63310. +#endif
  63311. +
  63312. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  63313. +/** BSD needs the thread pointer for kthread_suspend_check() */
  63314. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  63315. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  63316. +
  63317. +/** The thread must call this to exit. */
  63318. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  63319. +#define dwc_thread_exit DWC_THREAD_EXIT
  63320. +#endif
  63321. +
  63322. +
  63323. +/** @name Work queues
  63324. + *
  63325. + * Workqs are used to queue a callback function to be called at some later time,
  63326. + * in another thread. */
  63327. +struct dwc_workq;
  63328. +
  63329. +/** Type for a workq */
  63330. +typedef struct dwc_workq dwc_workq_t;
  63331. +
  63332. +/** The type of the callback function to be called. */
  63333. +typedef void (*dwc_work_callback_t)(void *data);
  63334. +
  63335. +/** Allocate a workq */
  63336. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  63337. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  63338. +
  63339. +/** Free a workq. All work must be completed before being freed. */
  63340. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  63341. +#define dwc_workq_free DWC_WORKQ_FREE
  63342. +
  63343. +/** Schedule a callback on the workq, passing in data. The function will be
  63344. + * scheduled at some later time. */
  63345. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  63346. + void *data, char *format, ...)
  63347. +#ifdef __GNUC__
  63348. + __attribute__ ((format(printf, 4, 5)));
  63349. +#else
  63350. + ;
  63351. +#endif
  63352. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  63353. +
  63354. +/** Schedule a callback on the workq, that will be called until at least
  63355. + * given number miliseconds have passed. */
  63356. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  63357. + void *data, uint32_t time, char *format, ...)
  63358. +#ifdef __GNUC__
  63359. + __attribute__ ((format(printf, 5, 6)));
  63360. +#else
  63361. + ;
  63362. +#endif
  63363. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  63364. +
  63365. +/** The number of processes in the workq */
  63366. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  63367. +#define dwc_workq_pending DWC_WORKQ_PENDING
  63368. +
  63369. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  63370. + * 0 on timeout. */
  63371. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  63372. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  63373. +
  63374. +
  63375. +/** @name Tasklets
  63376. + *
  63377. + */
  63378. +struct dwc_tasklet;
  63379. +
  63380. +/** Type for a tasklet */
  63381. +typedef struct dwc_tasklet dwc_tasklet_t;
  63382. +
  63383. +/** The type of the callback function to be called */
  63384. +typedef void (*dwc_tasklet_callback_t)(void *data);
  63385. +
  63386. +/** Allocates a tasklet */
  63387. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  63388. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  63389. +
  63390. +/** Frees a tasklet */
  63391. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  63392. +#define dwc_task_free DWC_TASK_FREE
  63393. +
  63394. +/** Schedules a tasklet to run */
  63395. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  63396. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  63397. +
  63398. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  63399. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  63400. +
  63401. +/** @name Timer
  63402. + *
  63403. + * Callbacks must be small and atomic.
  63404. + */
  63405. +struct dwc_timer;
  63406. +
  63407. +/** Type for a timer */
  63408. +typedef struct dwc_timer dwc_timer_t;
  63409. +
  63410. +/** The type of the callback function to be called */
  63411. +typedef void (*dwc_timer_callback_t)(void *data);
  63412. +
  63413. +/** Allocates a timer */
  63414. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  63415. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  63416. +
  63417. +/** Frees a timer */
  63418. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  63419. +#define dwc_timer_free DWC_TIMER_FREE
  63420. +
  63421. +/** Schedules the timer to run at time ms from now. And will repeat at every
  63422. + * repeat_interval msec therafter
  63423. + *
  63424. + * Modifies a timer that is still awaiting execution to a new expiration time.
  63425. + * The mod_time is added to the old time. */
  63426. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  63427. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  63428. +
  63429. +/** Disables the timer from execution. */
  63430. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  63431. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  63432. +
  63433. +
  63434. +/** @name Spinlocks
  63435. + *
  63436. + * These locks are used when the work between the lock/unlock is atomic and
  63437. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  63438. + * suitable to lock between interrupt/non-interrupt context. They also lock
  63439. + * between processes if you have multiple CPUs or Preemption. If you don't have
  63440. + * multiple CPUS or Preemption, then the you can simply implement the
  63441. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  63442. + * the work between the lock/unlock is atomic, the process context will never
  63443. + * change, and so you never have to lock between processes. */
  63444. +
  63445. +struct dwc_spinlock;
  63446. +
  63447. +/** Type for a spinlock */
  63448. +typedef struct dwc_spinlock dwc_spinlock_t;
  63449. +
  63450. +/** Type for the 'flags' argument to spinlock funtions */
  63451. +typedef unsigned long dwc_irqflags_t;
  63452. +
  63453. +/** Returns an initialized lock variable. This function should allocate and
  63454. + * initialize the OS-specific data structure used for locking. This data
  63455. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  63456. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  63457. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  63458. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  63459. +
  63460. +/** Frees an initialized lock variable. */
  63461. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  63462. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  63463. +
  63464. +/** Disables interrupts and blocks until it acquires the lock.
  63465. + *
  63466. + * @param lock Pointer to the spinlock.
  63467. + * @param flags Unsigned long for irq flags storage.
  63468. + */
  63469. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  63470. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  63471. +
  63472. +/** Re-enables the interrupt and releases the lock.
  63473. + *
  63474. + * @param lock Pointer to the spinlock.
  63475. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  63476. + * passed into DWC_LOCK.
  63477. + */
  63478. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  63479. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  63480. +
  63481. +/** Blocks until it acquires the lock.
  63482. + *
  63483. + * @param lock Pointer to the spinlock.
  63484. + */
  63485. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  63486. +#define dwc_spinlock DWC_SPINLOCK
  63487. +
  63488. +/** Releases the lock.
  63489. + *
  63490. + * @param lock Pointer to the spinlock.
  63491. + */
  63492. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  63493. +#define dwc_spinunlock DWC_SPINUNLOCK
  63494. +
  63495. +
  63496. +/** @name Mutexes
  63497. + *
  63498. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  63499. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  63500. + */
  63501. +
  63502. +struct dwc_mutex;
  63503. +
  63504. +/** Type for a mutex */
  63505. +typedef struct dwc_mutex dwc_mutex_t;
  63506. +
  63507. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  63508. + * the symbol to determine recursive locking. This makes it falsely think
  63509. + * recursive locking occurs. */
  63510. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  63511. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  63512. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  63513. + mutex_init((struct mutex *)__mutexp); \
  63514. +})
  63515. +#endif
  63516. +
  63517. +/** Allocate a mutex */
  63518. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  63519. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  63520. +
  63521. +/* For memory leak debugging when using Linux Mutex Debugging */
  63522. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  63523. +#define DWC_MUTEX_FREE(__mutexp) do { \
  63524. + mutex_destroy((struct mutex *)__mutexp); \
  63525. + DWC_FREE(__mutexp); \
  63526. +} while(0)
  63527. +#else
  63528. +/** Free a mutex */
  63529. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  63530. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  63531. +#endif
  63532. +
  63533. +/** Lock a mutex */
  63534. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  63535. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  63536. +
  63537. +/** Non-blocking lock returns 1 on successful lock. */
  63538. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  63539. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  63540. +
  63541. +/** Unlock a mutex */
  63542. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  63543. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  63544. +
  63545. +
  63546. +/** @name Time */
  63547. +
  63548. +/** Microsecond delay.
  63549. + *
  63550. + * @param usecs Microseconds to delay.
  63551. + */
  63552. +extern void DWC_UDELAY(uint32_t usecs);
  63553. +#define dwc_udelay DWC_UDELAY
  63554. +
  63555. +/** Millisecond delay.
  63556. + *
  63557. + * @param msecs Milliseconds to delay.
  63558. + */
  63559. +extern void DWC_MDELAY(uint32_t msecs);
  63560. +#define dwc_mdelay DWC_MDELAY
  63561. +
  63562. +/** Non-busy waiting.
  63563. + * Sleeps for specified number of milliseconds.
  63564. + *
  63565. + * @param msecs Milliseconds to sleep.
  63566. + */
  63567. +extern void DWC_MSLEEP(uint32_t msecs);
  63568. +#define dwc_msleep DWC_MSLEEP
  63569. +
  63570. +/**
  63571. + * Returns number of milliseconds since boot.
  63572. + */
  63573. +extern uint32_t DWC_TIME(void);
  63574. +#define dwc_time DWC_TIME
  63575. +
  63576. +
  63577. +
  63578. +
  63579. +/* @mainpage DWC Portability and Common Library
  63580. + *
  63581. + * This is the documentation for the DWC Portability and Common Library.
  63582. + *
  63583. + * @section intro Introduction
  63584. + *
  63585. + * The DWC Portability library consists of wrapper calls and data structures to
  63586. + * all low-level functions which are typically provided by the OS. The WUDEV
  63587. + * driver uses only these functions. In order to port the WUDEV driver, only
  63588. + * the functions in this library need to be re-implemented, with the same
  63589. + * behavior as documented here.
  63590. + *
  63591. + * The Common library consists of higher level functions, which rely only on
  63592. + * calling the functions from the DWC Portability library. These common
  63593. + * routines are shared across modules. Some of the common libraries need to be
  63594. + * used directly by the driver programmer when porting WUDEV. Such as the
  63595. + * parameter and notification libraries.
  63596. + *
  63597. + * @section low Portability Library OS Wrapper Functions
  63598. + *
  63599. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  63600. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  63601. + * these functions are included in the dwc_os.h file.
  63602. + *
  63603. + * There are many functions here covering a wide array of OS services. Please
  63604. + * see dwc_os.h for details, and implementation notes for each function.
  63605. + *
  63606. + * @section common Common Library Functions
  63607. + *
  63608. + * Any function starting with dwc and in all lowercase is a common library
  63609. + * routine. These functions have a portable implementation and do not need to
  63610. + * be reimplemented when porting. The common routines can be used by any
  63611. + * driver, and some must be used by the end user to control the drivers. For
  63612. + * example, you must use the Parameter common library in order to set the
  63613. + * parameters in the WUDEV module.
  63614. + *
  63615. + * The common libraries consist of the following:
  63616. + *
  63617. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  63618. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  63619. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  63620. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  63621. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  63622. + * - Modpow - Used internally only. See dwc_modpow.h
  63623. + * - DH - Used internally only. See dwc_dh.h
  63624. + * - Crypto - Used internally only. See dwc_crypto.h
  63625. + *
  63626. + *
  63627. + * @section prereq Prerequistes For dwc_os.h
  63628. + * @subsection types Data Types
  63629. + *
  63630. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  63631. + * compilation environment. These data types are:
  63632. + *
  63633. + * - uint8_t - unsigned 8-bit data type
  63634. + * - int8_t - signed 8-bit data type
  63635. + * - uint16_t - unsigned 16-bit data type
  63636. + * - int16_t - signed 16-bit data type
  63637. + * - uint32_t - unsigned 32-bit data type
  63638. + * - int32_t - signed 32-bit data type
  63639. + * - uint64_t - unsigned 64-bit data type
  63640. + * - int64_t - signed 64-bit data type
  63641. + *
  63642. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  63643. + * that is to modify the top of the file to include the appropriate header.
  63644. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  63645. + * defined, the correct header will be added. A standard header <stdint.h> is
  63646. + * also used for environments where standard C headers are available.
  63647. + *
  63648. + * @subsection stdarg Variable Arguments
  63649. + *
  63650. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  63651. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  63652. + * provided in your enviornment in order to use dwc_os.h with the debug and
  63653. + * tracing message functionality.
  63654. + *
  63655. + * @subsection thread Threading
  63656. + *
  63657. + * WUDEV Core must be run on an operating system that provides for multiple
  63658. + * threads/processes. Threading can be implemented in many ways, even in
  63659. + * embedded systems without an operating system. At the bare minimum, the
  63660. + * system should be able to start any number of processes at any time to handle
  63661. + * special work. It need not be a pre-emptive system. Process context can
  63662. + * change upon a call to a blocking function. The hardware interrupt context
  63663. + * that calls the module's ISR() function must be differentiable from process
  63664. + * context, even if your processes are impemented via a hardware interrupt.
  63665. + * Further locking mechanism between process must exist (or be implemented), and
  63666. + * process context must have a way to disable interrupts for a period of time to
  63667. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  63668. + * threading should be able to be implemented with the defined behavior.
  63669. + *
  63670. + */
  63671. +
  63672. +#ifdef __cplusplus
  63673. +}
  63674. +#endif
  63675. +
  63676. +#endif /* _DWC_OS_H_ */
  63677. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  63678. --- linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  63679. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2015-03-09 10:39:33.214893718 +0100
  63680. @@ -0,0 +1,58 @@
  63681. +#
  63682. +# Makefile for DWC_common library
  63683. +#
  63684. +
  63685. +ifneq ($(KERNELRELEASE),)
  63686. +
  63687. +ccflags-y += -DDWC_LINUX
  63688. +#ccflags-y += -DDEBUG
  63689. +#ccflags-y += -DDWC_DEBUG_REGS
  63690. +#ccflags-y += -DDWC_DEBUG_MEMORY
  63691. +
  63692. +ccflags-y += -DDWC_LIBMODULE
  63693. +ccflags-y += -DDWC_CCLIB
  63694. +#ccflags-y += -DDWC_CRYPTOLIB
  63695. +ccflags-y += -DDWC_NOTIFYLIB
  63696. +ccflags-y += -DDWC_UTFLIB
  63697. +
  63698. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  63699. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  63700. + dwc_crypto.o dwc_notifier.o \
  63701. + dwc_common_linux.o dwc_mem.o
  63702. +
  63703. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  63704. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  63705. +
  63706. +ifneq ($(kernrel3),2.6.20)
  63707. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  63708. +ccflags-y += $(CPPFLAGS)
  63709. +endif
  63710. +
  63711. +else
  63712. +
  63713. +#ifeq ($(KDIR),)
  63714. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  63715. +#endif
  63716. +
  63717. +ifeq ($(ARCH),)
  63718. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  63719. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  63720. +endif
  63721. +
  63722. +ifeq ($(DOXYGEN),)
  63723. +DOXYGEN := doxygen
  63724. +endif
  63725. +
  63726. +default:
  63727. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  63728. +
  63729. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  63730. + $(DOXYGEN) doc/doxygen.cfg
  63731. +
  63732. +tags: $(wildcard *.[hc])
  63733. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  63734. +
  63735. +endif
  63736. +
  63737. +clean:
  63738. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  63739. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  63740. --- linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  63741. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2015-03-09 10:39:33.214893718 +0100
  63742. @@ -0,0 +1,17 @@
  63743. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  63744. +CFLAGS += -DDWC_FREEBSD
  63745. +CFLAGS += -DDEBUG
  63746. +#CFLAGS += -DDWC_DEBUG_REGS
  63747. +#CFLAGS += -DDWC_DEBUG_MEMORY
  63748. +
  63749. +#CFLAGS += -DDWC_LIBMODULE
  63750. +#CFLAGS += -DDWC_CCLIB
  63751. +#CFLAGS += -DDWC_CRYPTOLIB
  63752. +#CFLAGS += -DDWC_NOTIFYLIB
  63753. +#CFLAGS += -DDWC_UTFLIB
  63754. +
  63755. +KMOD = dwc_common_port_lib
  63756. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  63757. + dwc_common_fbsd.c dwc_mem.c
  63758. +
  63759. +.include <bsd.kmod.mk>
  63760. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  63761. --- linux-3.12.38/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  63762. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2015-03-09 10:39:33.214893718 +0100
  63763. @@ -0,0 +1,49 @@
  63764. +#
  63765. +# Makefile for DWC_common library
  63766. +#
  63767. +ifneq ($(KERNELRELEASE),)
  63768. +
  63769. +ccflags-y += -DDWC_LINUX
  63770. +#ccflags-y += -DDEBUG
  63771. +#ccflags-y += -DDWC_DEBUG_REGS
  63772. +#ccflags-y += -DDWC_DEBUG_MEMORY
  63773. +
  63774. +ccflags-y += -DDWC_LIBMODULE
  63775. +ccflags-y += -DDWC_CCLIB
  63776. +ccflags-y += -DDWC_CRYPTOLIB
  63777. +ccflags-y += -DDWC_NOTIFYLIB
  63778. +ccflags-y += -DDWC_UTFLIB
  63779. +
  63780. +obj-m := dwc_common_port_lib.o
  63781. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  63782. + dwc_crypto.o dwc_notifier.o \
  63783. + dwc_common_linux.o dwc_mem.o
  63784. +
  63785. +else
  63786. +
  63787. +ifeq ($(KDIR),)
  63788. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  63789. +endif
  63790. +
  63791. +ifeq ($(ARCH),)
  63792. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  63793. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  63794. +endif
  63795. +
  63796. +ifeq ($(DOXYGEN),)
  63797. +DOXYGEN := doxygen
  63798. +endif
  63799. +
  63800. +default:
  63801. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  63802. +
  63803. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  63804. + $(DOXYGEN) doc/doxygen.cfg
  63805. +
  63806. +tags: $(wildcard *.[hc])
  63807. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  63808. +
  63809. +endif
  63810. +
  63811. +clean:
  63812. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  63813. diff -Nur linux-3.12.38/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  63814. --- linux-3.12.38/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  63815. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2015-03-09 10:39:33.214893718 +0100
  63816. @@ -0,0 +1,946 @@
  63817. +/*
  63818. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  63819. + * All rights reserved.
  63820. + *
  63821. + * This code is derived from software contributed to The NetBSD Foundation
  63822. + * by Lennart Augustsson (lennart@augustsson.net) at
  63823. + * Carlstedt Research & Technology.
  63824. + *
  63825. + * Redistribution and use in source and binary forms, with or without
  63826. + * modification, are permitted provided that the following conditions
  63827. + * are met:
  63828. + * 1. Redistributions of source code must retain the above copyright
  63829. + * notice, this list of conditions and the following disclaimer.
  63830. + * 2. Redistributions in binary form must reproduce the above copyright
  63831. + * notice, this list of conditions and the following disclaimer in the
  63832. + * documentation and/or other materials provided with the distribution.
  63833. + * 3. All advertising materials mentioning features or use of this software
  63834. + * must display the following acknowledgement:
  63835. + * This product includes software developed by the NetBSD
  63836. + * Foundation, Inc. and its contributors.
  63837. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  63838. + * contributors may be used to endorse or promote products derived
  63839. + * from this software without specific prior written permission.
  63840. + *
  63841. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  63842. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  63843. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  63844. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  63845. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  63846. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  63847. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  63848. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  63849. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  63850. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  63851. + * POSSIBILITY OF SUCH DAMAGE.
  63852. + */
  63853. +
  63854. +/* Modified by Synopsys, Inc, 12/12/2007 */
  63855. +
  63856. +
  63857. +#ifndef _USB_H_
  63858. +#define _USB_H_
  63859. +
  63860. +#ifdef __cplusplus
  63861. +extern "C" {
  63862. +#endif
  63863. +
  63864. +/*
  63865. + * The USB records contain some unaligned little-endian word
  63866. + * components. The U[SG]ETW macros take care of both the alignment
  63867. + * and endian problem and should always be used to access non-byte
  63868. + * values.
  63869. + */
  63870. +typedef u_int8_t uByte;
  63871. +typedef u_int8_t uWord[2];
  63872. +typedef u_int8_t uDWord[4];
  63873. +
  63874. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  63875. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  63876. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  63877. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  63878. +
  63879. +#if 1
  63880. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  63881. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  63882. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  63883. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  63884. + (w)[1] = (u_int8_t)((v) >> 8), \
  63885. + (w)[2] = (u_int8_t)((v) >> 16), \
  63886. + (w)[3] = (u_int8_t)((v) >> 24))
  63887. +#else
  63888. +/*
  63889. + * On little-endian machines that can handle unanliged accesses
  63890. + * (e.g. i386) these macros can be replaced by the following.
  63891. + */
  63892. +#define UGETW(w) (*(u_int16_t *)(w))
  63893. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  63894. +#define UGETDW(w) (*(u_int32_t *)(w))
  63895. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  63896. +#endif
  63897. +
  63898. +/*
  63899. + * Macros for accessing UAS IU fields, which are big-endian
  63900. + */
  63901. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  63902. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  63903. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  63904. + ((x) >> 8) & 0xff, (x) & 0xff }
  63905. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  63906. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  63907. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  63908. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  63909. + (w)[1] = (u_int8_t)((v) >> 16), \
  63910. + (w)[2] = (u_int8_t)((v) >> 8), \
  63911. + (w)[3] = (u_int8_t)(v))
  63912. +
  63913. +#define UPACKED __attribute__((__packed__))
  63914. +
  63915. +typedef struct {
  63916. + uByte bmRequestType;
  63917. + uByte bRequest;
  63918. + uWord wValue;
  63919. + uWord wIndex;
  63920. + uWord wLength;
  63921. +} UPACKED usb_device_request_t;
  63922. +
  63923. +#define UT_GET_DIR(a) ((a) & 0x80)
  63924. +#define UT_WRITE 0x00
  63925. +#define UT_READ 0x80
  63926. +
  63927. +#define UT_GET_TYPE(a) ((a) & 0x60)
  63928. +#define UT_STANDARD 0x00
  63929. +#define UT_CLASS 0x20
  63930. +#define UT_VENDOR 0x40
  63931. +
  63932. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  63933. +#define UT_DEVICE 0x00
  63934. +#define UT_INTERFACE 0x01
  63935. +#define UT_ENDPOINT 0x02
  63936. +#define UT_OTHER 0x03
  63937. +
  63938. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  63939. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  63940. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  63941. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  63942. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  63943. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  63944. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  63945. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  63946. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  63947. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  63948. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  63949. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  63950. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  63951. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  63952. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  63953. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  63954. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  63955. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  63956. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  63957. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  63958. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  63959. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  63960. +
  63961. +/* Requests */
  63962. +#define UR_GET_STATUS 0x00
  63963. +#define USTAT_STANDARD_STATUS 0x00
  63964. +#define WUSTAT_WUSB_FEATURE 0x01
  63965. +#define WUSTAT_CHANNEL_INFO 0x02
  63966. +#define WUSTAT_RECEIVED_DATA 0x03
  63967. +#define WUSTAT_MAS_AVAILABILITY 0x04
  63968. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  63969. +#define UR_CLEAR_FEATURE 0x01
  63970. +#define UR_SET_FEATURE 0x03
  63971. +#define UR_SET_AND_TEST_FEATURE 0x0c
  63972. +#define UR_SET_ADDRESS 0x05
  63973. +#define UR_GET_DESCRIPTOR 0x06
  63974. +#define UDESC_DEVICE 0x01
  63975. +#define UDESC_CONFIG 0x02
  63976. +#define UDESC_STRING 0x03
  63977. +#define UDESC_INTERFACE 0x04
  63978. +#define UDESC_ENDPOINT 0x05
  63979. +#define UDESC_SS_USB_COMPANION 0x30
  63980. +#define UDESC_DEVICE_QUALIFIER 0x06
  63981. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  63982. +#define UDESC_INTERFACE_POWER 0x08
  63983. +#define UDESC_OTG 0x09
  63984. +#define WUDESC_SECURITY 0x0c
  63985. +#define WUDESC_KEY 0x0d
  63986. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  63987. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  63988. +#define WUD_KEY_TYPE_ASSOC 0x01
  63989. +#define WUD_KEY_TYPE_GTK 0x02
  63990. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  63991. +#define WUD_KEY_ORIGIN_HOST 0x00
  63992. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  63993. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  63994. +#define WUDESC_BOS 0x0f
  63995. +#define WUDESC_DEVICE_CAPABILITY 0x10
  63996. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  63997. +#define UDESC_BOS 0x0f
  63998. +#define UDESC_DEVICE_CAPABILITY 0x10
  63999. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  64000. +#define UDESC_CS_CONFIG 0x22
  64001. +#define UDESC_CS_STRING 0x23
  64002. +#define UDESC_CS_INTERFACE 0x24
  64003. +#define UDESC_CS_ENDPOINT 0x25
  64004. +#define UDESC_HUB 0x29
  64005. +#define UR_SET_DESCRIPTOR 0x07
  64006. +#define UR_GET_CONFIG 0x08
  64007. +#define UR_SET_CONFIG 0x09
  64008. +#define UR_GET_INTERFACE 0x0a
  64009. +#define UR_SET_INTERFACE 0x0b
  64010. +#define UR_SYNCH_FRAME 0x0c
  64011. +#define WUR_SET_ENCRYPTION 0x0d
  64012. +#define WUR_GET_ENCRYPTION 0x0e
  64013. +#define WUR_SET_HANDSHAKE 0x0f
  64014. +#define WUR_GET_HANDSHAKE 0x10
  64015. +#define WUR_SET_CONNECTION 0x11
  64016. +#define WUR_SET_SECURITY_DATA 0x12
  64017. +#define WUR_GET_SECURITY_DATA 0x13
  64018. +#define WUR_SET_WUSB_DATA 0x14
  64019. +#define WUDATA_DRPIE_INFO 0x01
  64020. +#define WUDATA_TRANSMIT_DATA 0x02
  64021. +#define WUDATA_TRANSMIT_PARAMS 0x03
  64022. +#define WUDATA_RECEIVE_PARAMS 0x04
  64023. +#define WUDATA_TRANSMIT_POWER 0x05
  64024. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  64025. +#define WUR_LOOPBACK_DATA_READ 0x16
  64026. +#define WUR_SET_INTERFACE_DS 0x17
  64027. +
  64028. +/* Feature numbers */
  64029. +#define UF_ENDPOINT_HALT 0
  64030. +#define UF_DEVICE_REMOTE_WAKEUP 1
  64031. +#define UF_TEST_MODE 2
  64032. +#define UF_DEVICE_B_HNP_ENABLE 3
  64033. +#define UF_DEVICE_A_HNP_SUPPORT 4
  64034. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  64035. +#define WUF_WUSB 3
  64036. +#define WUF_TX_DRPIE 0x0
  64037. +#define WUF_DEV_XMIT_PACKET 0x1
  64038. +#define WUF_COUNT_PACKETS 0x2
  64039. +#define WUF_CAPTURE_PACKETS 0x3
  64040. +#define UF_FUNCTION_SUSPEND 0
  64041. +#define UF_U1_ENABLE 48
  64042. +#define UF_U2_ENABLE 49
  64043. +#define UF_LTM_ENABLE 50
  64044. +
  64045. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  64046. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  64047. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  64048. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  64049. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  64050. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  64051. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  64052. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  64053. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  64054. +
  64055. +#ifdef _MSC_VER
  64056. +#include <pshpack1.h>
  64057. +#endif
  64058. +
  64059. +typedef struct {
  64060. + uByte bLength;
  64061. + uByte bDescriptorType;
  64062. + uByte bDescriptorSubtype;
  64063. +} UPACKED usb_descriptor_t;
  64064. +
  64065. +typedef struct {
  64066. + uByte bLength;
  64067. + uByte bDescriptorType;
  64068. +} UPACKED usb_descriptor_header_t;
  64069. +
  64070. +typedef struct {
  64071. + uByte bLength;
  64072. + uByte bDescriptorType;
  64073. + uWord bcdUSB;
  64074. +#define UD_USB_2_0 0x0200
  64075. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  64076. + uByte bDeviceClass;
  64077. + uByte bDeviceSubClass;
  64078. + uByte bDeviceProtocol;
  64079. + uByte bMaxPacketSize;
  64080. + /* The fields below are not part of the initial descriptor. */
  64081. + uWord idVendor;
  64082. + uWord idProduct;
  64083. + uWord bcdDevice;
  64084. + uByte iManufacturer;
  64085. + uByte iProduct;
  64086. + uByte iSerialNumber;
  64087. + uByte bNumConfigurations;
  64088. +} UPACKED usb_device_descriptor_t;
  64089. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  64090. +
  64091. +typedef struct {
  64092. + uByte bLength;
  64093. + uByte bDescriptorType;
  64094. + uWord wTotalLength;
  64095. + uByte bNumInterface;
  64096. + uByte bConfigurationValue;
  64097. + uByte iConfiguration;
  64098. +#define UC_ATT_ONE (1 << 7) /* must be set */
  64099. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  64100. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  64101. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  64102. + uByte bmAttributes;
  64103. +#define UC_BUS_POWERED 0x80
  64104. +#define UC_SELF_POWERED 0x40
  64105. +#define UC_REMOTE_WAKEUP 0x20
  64106. + uByte bMaxPower; /* max current in 2 mA units */
  64107. +#define UC_POWER_FACTOR 2
  64108. +} UPACKED usb_config_descriptor_t;
  64109. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  64110. +
  64111. +typedef struct {
  64112. + uByte bLength;
  64113. + uByte bDescriptorType;
  64114. + uByte bInterfaceNumber;
  64115. + uByte bAlternateSetting;
  64116. + uByte bNumEndpoints;
  64117. + uByte bInterfaceClass;
  64118. + uByte bInterfaceSubClass;
  64119. + uByte bInterfaceProtocol;
  64120. + uByte iInterface;
  64121. +} UPACKED usb_interface_descriptor_t;
  64122. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  64123. +
  64124. +typedef struct {
  64125. + uByte bLength;
  64126. + uByte bDescriptorType;
  64127. + uByte bEndpointAddress;
  64128. +#define UE_GET_DIR(a) ((a) & 0x80)
  64129. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  64130. +#define UE_DIR_IN 0x80
  64131. +#define UE_DIR_OUT 0x00
  64132. +#define UE_ADDR 0x0f
  64133. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  64134. + uByte bmAttributes;
  64135. +#define UE_XFERTYPE 0x03
  64136. +#define UE_CONTROL 0x00
  64137. +#define UE_ISOCHRONOUS 0x01
  64138. +#define UE_BULK 0x02
  64139. +#define UE_INTERRUPT 0x03
  64140. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  64141. +#define UE_ISO_TYPE 0x0c
  64142. +#define UE_ISO_ASYNC 0x04
  64143. +#define UE_ISO_ADAPT 0x08
  64144. +#define UE_ISO_SYNC 0x0c
  64145. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  64146. + uWord wMaxPacketSize;
  64147. + uByte bInterval;
  64148. +} UPACKED usb_endpoint_descriptor_t;
  64149. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  64150. +
  64151. +typedef struct ss_endpoint_companion_descriptor {
  64152. + uByte bLength;
  64153. + uByte bDescriptorType;
  64154. + uByte bMaxBurst;
  64155. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  64156. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  64157. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  64158. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  64159. + uByte bmAttributes;
  64160. + uWord wBytesPerInterval;
  64161. +} UPACKED ss_endpoint_companion_descriptor_t;
  64162. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  64163. +
  64164. +typedef struct {
  64165. + uByte bLength;
  64166. + uByte bDescriptorType;
  64167. + uWord bString[127];
  64168. +} UPACKED usb_string_descriptor_t;
  64169. +#define USB_MAX_STRING_LEN 128
  64170. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  64171. +
  64172. +/* Hub specific request */
  64173. +#define UR_GET_BUS_STATE 0x02
  64174. +#define UR_CLEAR_TT_BUFFER 0x08
  64175. +#define UR_RESET_TT 0x09
  64176. +#define UR_GET_TT_STATE 0x0a
  64177. +#define UR_STOP_TT 0x0b
  64178. +
  64179. +/* Hub features */
  64180. +#define UHF_C_HUB_LOCAL_POWER 0
  64181. +#define UHF_C_HUB_OVER_CURRENT 1
  64182. +#define UHF_PORT_CONNECTION 0
  64183. +#define UHF_PORT_ENABLE 1
  64184. +#define UHF_PORT_SUSPEND 2
  64185. +#define UHF_PORT_OVER_CURRENT 3
  64186. +#define UHF_PORT_RESET 4
  64187. +#define UHF_PORT_L1 5
  64188. +#define UHF_PORT_POWER 8
  64189. +#define UHF_PORT_LOW_SPEED 9
  64190. +#define UHF_PORT_HIGH_SPEED 10
  64191. +#define UHF_C_PORT_CONNECTION 16
  64192. +#define UHF_C_PORT_ENABLE 17
  64193. +#define UHF_C_PORT_SUSPEND 18
  64194. +#define UHF_C_PORT_OVER_CURRENT 19
  64195. +#define UHF_C_PORT_RESET 20
  64196. +#define UHF_C_PORT_L1 23
  64197. +#define UHF_PORT_TEST 21
  64198. +#define UHF_PORT_INDICATOR 22
  64199. +
  64200. +typedef struct {
  64201. + uByte bDescLength;
  64202. + uByte bDescriptorType;
  64203. + uByte bNbrPorts;
  64204. + uWord wHubCharacteristics;
  64205. +#define UHD_PWR 0x0003
  64206. +#define UHD_PWR_GANGED 0x0000
  64207. +#define UHD_PWR_INDIVIDUAL 0x0001
  64208. +#define UHD_PWR_NO_SWITCH 0x0002
  64209. +#define UHD_COMPOUND 0x0004
  64210. +#define UHD_OC 0x0018
  64211. +#define UHD_OC_GLOBAL 0x0000
  64212. +#define UHD_OC_INDIVIDUAL 0x0008
  64213. +#define UHD_OC_NONE 0x0010
  64214. +#define UHD_TT_THINK 0x0060
  64215. +#define UHD_TT_THINK_8 0x0000
  64216. +#define UHD_TT_THINK_16 0x0020
  64217. +#define UHD_TT_THINK_24 0x0040
  64218. +#define UHD_TT_THINK_32 0x0060
  64219. +#define UHD_PORT_IND 0x0080
  64220. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  64221. +#define UHD_PWRON_FACTOR 2
  64222. + uByte bHubContrCurrent;
  64223. + uByte DeviceRemovable[32]; /* max 255 ports */
  64224. +#define UHD_NOT_REMOV(desc, i) \
  64225. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  64226. + /* deprecated */ uByte PortPowerCtrlMask[1];
  64227. +} UPACKED usb_hub_descriptor_t;
  64228. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  64229. +
  64230. +typedef struct {
  64231. + uByte bLength;
  64232. + uByte bDescriptorType;
  64233. + uWord bcdUSB;
  64234. + uByte bDeviceClass;
  64235. + uByte bDeviceSubClass;
  64236. + uByte bDeviceProtocol;
  64237. + uByte bMaxPacketSize0;
  64238. + uByte bNumConfigurations;
  64239. + uByte bReserved;
  64240. +} UPACKED usb_device_qualifier_t;
  64241. +#define USB_DEVICE_QUALIFIER_SIZE 10
  64242. +
  64243. +typedef struct {
  64244. + uByte bLength;
  64245. + uByte bDescriptorType;
  64246. + uByte bmAttributes;
  64247. +#define UOTG_SRP 0x01
  64248. +#define UOTG_HNP 0x02
  64249. +} UPACKED usb_otg_descriptor_t;
  64250. +
  64251. +/* OTG feature selectors */
  64252. +#define UOTG_B_HNP_ENABLE 3
  64253. +#define UOTG_A_HNP_SUPPORT 4
  64254. +#define UOTG_A_ALT_HNP_SUPPORT 5
  64255. +
  64256. +typedef struct {
  64257. + uWord wStatus;
  64258. +/* Device status flags */
  64259. +#define UDS_SELF_POWERED 0x0001
  64260. +#define UDS_REMOTE_WAKEUP 0x0002
  64261. +/* Endpoint status flags */
  64262. +#define UES_HALT 0x0001
  64263. +} UPACKED usb_status_t;
  64264. +
  64265. +typedef struct {
  64266. + uWord wHubStatus;
  64267. +#define UHS_LOCAL_POWER 0x0001
  64268. +#define UHS_OVER_CURRENT 0x0002
  64269. + uWord wHubChange;
  64270. +} UPACKED usb_hub_status_t;
  64271. +
  64272. +typedef struct {
  64273. + uWord wPortStatus;
  64274. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  64275. +#define UPS_PORT_ENABLED 0x0002
  64276. +#define UPS_SUSPEND 0x0004
  64277. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  64278. +#define UPS_RESET 0x0010
  64279. +#define UPS_PORT_POWER 0x0100
  64280. +#define UPS_LOW_SPEED 0x0200
  64281. +#define UPS_HIGH_SPEED 0x0400
  64282. +#define UPS_PORT_TEST 0x0800
  64283. +#define UPS_PORT_INDICATOR 0x1000
  64284. + uWord wPortChange;
  64285. +#define UPS_C_CONNECT_STATUS 0x0001
  64286. +#define UPS_C_PORT_ENABLED 0x0002
  64287. +#define UPS_C_SUSPEND 0x0004
  64288. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  64289. +#define UPS_C_PORT_RESET 0x0010
  64290. +} UPACKED usb_port_status_t;
  64291. +
  64292. +#ifdef _MSC_VER
  64293. +#include <poppack.h>
  64294. +#endif
  64295. +
  64296. +/* Device class codes */
  64297. +#define UDCLASS_IN_INTERFACE 0x00
  64298. +#define UDCLASS_COMM 0x02
  64299. +#define UDCLASS_HUB 0x09
  64300. +#define UDSUBCLASS_HUB 0x00
  64301. +#define UDPROTO_FSHUB 0x00
  64302. +#define UDPROTO_HSHUBSTT 0x01
  64303. +#define UDPROTO_HSHUBMTT 0x02
  64304. +#define UDCLASS_DIAGNOSTIC 0xdc
  64305. +#define UDCLASS_WIRELESS 0xe0
  64306. +#define UDSUBCLASS_RF 0x01
  64307. +#define UDPROTO_BLUETOOTH 0x01
  64308. +#define UDCLASS_VENDOR 0xff
  64309. +
  64310. +/* Interface class codes */
  64311. +#define UICLASS_UNSPEC 0x00
  64312. +
  64313. +#define UICLASS_AUDIO 0x01
  64314. +#define UISUBCLASS_AUDIOCONTROL 1
  64315. +#define UISUBCLASS_AUDIOSTREAM 2
  64316. +#define UISUBCLASS_MIDISTREAM 3
  64317. +
  64318. +#define UICLASS_CDC 0x02 /* communication */
  64319. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  64320. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  64321. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  64322. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  64323. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  64324. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  64325. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  64326. +#define UIPROTO_CDC_AT 1
  64327. +
  64328. +#define UICLASS_HID 0x03
  64329. +#define UISUBCLASS_BOOT 1
  64330. +#define UIPROTO_BOOT_KEYBOARD 1
  64331. +
  64332. +#define UICLASS_PHYSICAL 0x05
  64333. +
  64334. +#define UICLASS_IMAGE 0x06
  64335. +
  64336. +#define UICLASS_PRINTER 0x07
  64337. +#define UISUBCLASS_PRINTER 1
  64338. +#define UIPROTO_PRINTER_UNI 1
  64339. +#define UIPROTO_PRINTER_BI 2
  64340. +#define UIPROTO_PRINTER_1284 3
  64341. +
  64342. +#define UICLASS_MASS 0x08
  64343. +#define UISUBCLASS_RBC 1
  64344. +#define UISUBCLASS_SFF8020I 2
  64345. +#define UISUBCLASS_QIC157 3
  64346. +#define UISUBCLASS_UFI 4
  64347. +#define UISUBCLASS_SFF8070I 5
  64348. +#define UISUBCLASS_SCSI 6
  64349. +#define UIPROTO_MASS_CBI_I 0
  64350. +#define UIPROTO_MASS_CBI 1
  64351. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  64352. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  64353. +
  64354. +#define UICLASS_HUB 0x09
  64355. +#define UISUBCLASS_HUB 0
  64356. +#define UIPROTO_FSHUB 0
  64357. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  64358. +#define UIPROTO_HSHUBMTT 1
  64359. +
  64360. +#define UICLASS_CDC_DATA 0x0a
  64361. +#define UISUBCLASS_DATA 0
  64362. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  64363. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  64364. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  64365. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  64366. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  64367. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  64368. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  64369. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  64370. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  64371. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  64372. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  64373. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  64374. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  64375. +
  64376. +#define UICLASS_SMARTCARD 0x0b
  64377. +
  64378. +/*#define UICLASS_FIRM_UPD 0x0c*/
  64379. +
  64380. +#define UICLASS_SECURITY 0x0d
  64381. +
  64382. +#define UICLASS_DIAGNOSTIC 0xdc
  64383. +
  64384. +#define UICLASS_WIRELESS 0xe0
  64385. +#define UISUBCLASS_RF 0x01
  64386. +#define UIPROTO_BLUETOOTH 0x01
  64387. +
  64388. +#define UICLASS_APPL_SPEC 0xfe
  64389. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  64390. +#define UISUBCLASS_IRDA 2
  64391. +#define UIPROTO_IRDA 0
  64392. +
  64393. +#define UICLASS_VENDOR 0xff
  64394. +
  64395. +#define USB_HUB_MAX_DEPTH 5
  64396. +
  64397. +/*
  64398. + * Minimum time a device needs to be powered down to go through
  64399. + * a power cycle. XXX Are these time in the spec?
  64400. + */
  64401. +#define USB_POWER_DOWN_TIME 200 /* ms */
  64402. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  64403. +
  64404. +#if 0
  64405. +/* These are the values from the spec. */
  64406. +#define USB_PORT_RESET_DELAY 10 /* ms */
  64407. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  64408. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  64409. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  64410. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  64411. +#define USB_RESUME_DELAY (20*5) /* ms */
  64412. +#define USB_RESUME_WAIT 10 /* ms */
  64413. +#define USB_RESUME_RECOVERY 10 /* ms */
  64414. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  64415. +#else
  64416. +/* Allow for marginal (i.e. non-conforming) devices. */
  64417. +#define USB_PORT_RESET_DELAY 50 /* ms */
  64418. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  64419. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  64420. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  64421. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  64422. +#define USB_RESUME_DELAY (50*5) /* ms */
  64423. +#define USB_RESUME_WAIT 50 /* ms */
  64424. +#define USB_RESUME_RECOVERY 50 /* ms */
  64425. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  64426. +#endif
  64427. +
  64428. +#define USB_MIN_POWER 100 /* mA */
  64429. +#define USB_MAX_POWER 500 /* mA */
  64430. +
  64431. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  64432. +
  64433. +#define USB_UNCONFIG_NO 0
  64434. +#define USB_UNCONFIG_INDEX (-1)
  64435. +
  64436. +/*** ioctl() related stuff ***/
  64437. +
  64438. +struct usb_ctl_request {
  64439. + int ucr_addr;
  64440. + usb_device_request_t ucr_request;
  64441. + void *ucr_data;
  64442. + int ucr_flags;
  64443. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  64444. + int ucr_actlen; /* actual length transferred */
  64445. +};
  64446. +
  64447. +struct usb_alt_interface {
  64448. + int uai_config_index;
  64449. + int uai_interface_index;
  64450. + int uai_alt_no;
  64451. +};
  64452. +
  64453. +#define USB_CURRENT_CONFIG_INDEX (-1)
  64454. +#define USB_CURRENT_ALT_INDEX (-1)
  64455. +
  64456. +struct usb_config_desc {
  64457. + int ucd_config_index;
  64458. + usb_config_descriptor_t ucd_desc;
  64459. +};
  64460. +
  64461. +struct usb_interface_desc {
  64462. + int uid_config_index;
  64463. + int uid_interface_index;
  64464. + int uid_alt_index;
  64465. + usb_interface_descriptor_t uid_desc;
  64466. +};
  64467. +
  64468. +struct usb_endpoint_desc {
  64469. + int ued_config_index;
  64470. + int ued_interface_index;
  64471. + int ued_alt_index;
  64472. + int ued_endpoint_index;
  64473. + usb_endpoint_descriptor_t ued_desc;
  64474. +};
  64475. +
  64476. +struct usb_full_desc {
  64477. + int ufd_config_index;
  64478. + u_int ufd_size;
  64479. + u_char *ufd_data;
  64480. +};
  64481. +
  64482. +struct usb_string_desc {
  64483. + int usd_string_index;
  64484. + int usd_language_id;
  64485. + usb_string_descriptor_t usd_desc;
  64486. +};
  64487. +
  64488. +struct usb_ctl_report_desc {
  64489. + int ucrd_size;
  64490. + u_char ucrd_data[1024]; /* filled data size will vary */
  64491. +};
  64492. +
  64493. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  64494. +
  64495. +#define USB_MAX_DEVNAMES 4
  64496. +#define USB_MAX_DEVNAMELEN 16
  64497. +struct usb_device_info {
  64498. + u_int8_t udi_bus;
  64499. + u_int8_t udi_addr; /* device address */
  64500. + usb_event_cookie_t udi_cookie;
  64501. + char udi_product[USB_MAX_STRING_LEN];
  64502. + char udi_vendor[USB_MAX_STRING_LEN];
  64503. + char udi_release[8];
  64504. + u_int16_t udi_productNo;
  64505. + u_int16_t udi_vendorNo;
  64506. + u_int16_t udi_releaseNo;
  64507. + u_int8_t udi_class;
  64508. + u_int8_t udi_subclass;
  64509. + u_int8_t udi_protocol;
  64510. + u_int8_t udi_config;
  64511. + u_int8_t udi_speed;
  64512. +#define USB_SPEED_UNKNOWN 0
  64513. +#define USB_SPEED_LOW 1
  64514. +#define USB_SPEED_FULL 2
  64515. +#define USB_SPEED_HIGH 3
  64516. +#define USB_SPEED_VARIABLE 4
  64517. +#define USB_SPEED_SUPER 5
  64518. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  64519. + int udi_nports;
  64520. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  64521. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  64522. +#define USB_PORT_ENABLED 0xff
  64523. +#define USB_PORT_SUSPENDED 0xfe
  64524. +#define USB_PORT_POWERED 0xfd
  64525. +#define USB_PORT_DISABLED 0xfc
  64526. +};
  64527. +
  64528. +struct usb_ctl_report {
  64529. + int ucr_report;
  64530. + u_char ucr_data[1024]; /* filled data size will vary */
  64531. +};
  64532. +
  64533. +struct usb_device_stats {
  64534. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  64535. +};
  64536. +
  64537. +#define WUSB_MIN_IE 0x80
  64538. +#define WUSB_WCTA_IE 0x80
  64539. +#define WUSB_WCONNECTACK_IE 0x81
  64540. +#define WUSB_WHOSTINFO_IE 0x82
  64541. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  64542. +#define WUHI_CA_RECONN 0x00
  64543. +#define WUHI_CA_LIMITED 0x01
  64544. +#define WUHI_CA_ALL 0x03
  64545. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  64546. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  64547. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  64548. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  64549. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  64550. +#define WUSB_WWORK_IE 0x87
  64551. +#define WUSB_WCHANNEL_STOP_IE 0x88
  64552. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  64553. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  64554. +#define WUSB_WRESETDEVICE_IE 0x8B
  64555. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  64556. +#define WUSB_MAX_IE 0x8C
  64557. +
  64558. +/* Device Notification Types */
  64559. +
  64560. +#define WUSB_DN_MIN 0x01
  64561. +#define WUSB_DN_CONNECT 0x01
  64562. +# define WUSB_DA_OLDCONN 0x00
  64563. +# define WUSB_DA_NEWCONN 0x01
  64564. +# define WUSB_DA_SELF_BEACON 0x02
  64565. +# define WUSB_DA_DIR_BEACON 0x04
  64566. +# define WUSB_DA_NO_BEACON 0x06
  64567. +#define WUSB_DN_DISCONNECT 0x02
  64568. +#define WUSB_DN_EPRDY 0x03
  64569. +#define WUSB_DN_MASAVAILCHANGED 0x04
  64570. +#define WUSB_DN_REMOTEWAKEUP 0x05
  64571. +#define WUSB_DN_SLEEP 0x06
  64572. +#define WUSB_DN_ALIVE 0x07
  64573. +#define WUSB_DN_MAX 0x07
  64574. +
  64575. +#ifdef _MSC_VER
  64576. +#include <pshpack1.h>
  64577. +#endif
  64578. +
  64579. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  64580. +typedef struct wusb_hndshk_data {
  64581. + uByte bMessageNumber;
  64582. + uByte bStatus;
  64583. + uByte tTKID[3];
  64584. + uByte bReserved;
  64585. + uByte CDID[16];
  64586. + uByte Nonce[16];
  64587. + uByte MIC[8];
  64588. +} UPACKED wusb_hndshk_data_t;
  64589. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  64590. +
  64591. +/* WUSB Connection Context */
  64592. +typedef struct wusb_conn_context {
  64593. + uByte CHID [16];
  64594. + uByte CDID [16];
  64595. + uByte CK [16];
  64596. +} UPACKED wusb_conn_context_t;
  64597. +
  64598. +/* WUSB Security Descriptor */
  64599. +typedef struct wusb_security_desc {
  64600. + uByte bLength;
  64601. + uByte bDescriptorType;
  64602. + uWord wTotalLength;
  64603. + uByte bNumEncryptionTypes;
  64604. +} UPACKED wusb_security_desc_t;
  64605. +
  64606. +/* WUSB Encryption Type Descriptor */
  64607. +typedef struct wusb_encrypt_type_desc {
  64608. + uByte bLength;
  64609. + uByte bDescriptorType;
  64610. +
  64611. + uByte bEncryptionType;
  64612. +#define WUETD_UNSECURE 0
  64613. +#define WUETD_WIRED 1
  64614. +#define WUETD_CCM_1 2
  64615. +#define WUETD_RSA_1 3
  64616. +
  64617. + uByte bEncryptionValue;
  64618. + uByte bAuthKeyIndex;
  64619. +} UPACKED wusb_encrypt_type_desc_t;
  64620. +
  64621. +/* WUSB Key Descriptor */
  64622. +typedef struct wusb_key_desc {
  64623. + uByte bLength;
  64624. + uByte bDescriptorType;
  64625. + uByte tTKID[3];
  64626. + uByte bReserved;
  64627. + uByte KeyData[1]; /* variable length */
  64628. +} UPACKED wusb_key_desc_t;
  64629. +
  64630. +/* WUSB BOS Descriptor (Binary device Object Store) */
  64631. +typedef struct wusb_bos_desc {
  64632. + uByte bLength;
  64633. + uByte bDescriptorType;
  64634. + uWord wTotalLength;
  64635. + uByte bNumDeviceCaps;
  64636. +} UPACKED wusb_bos_desc_t;
  64637. +
  64638. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  64639. +typedef struct usb_dev_cap_20_ext_desc {
  64640. + uByte bLength;
  64641. + uByte bDescriptorType;
  64642. + uByte bDevCapabilityType;
  64643. +#define USB_20_EXT_LPM 0x02
  64644. + uDWord bmAttributes;
  64645. +} UPACKED usb_dev_cap_20_ext_desc_t;
  64646. +
  64647. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  64648. +typedef struct usb_dev_cap_ss_usb {
  64649. + uByte bLength;
  64650. + uByte bDescriptorType;
  64651. + uByte bDevCapabilityType;
  64652. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  64653. + uByte bmAttributes;
  64654. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  64655. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  64656. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  64657. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  64658. + uWord wSpeedsSupported;
  64659. + uByte bFunctionalitySupport;
  64660. + uByte bU1DevExitLat;
  64661. + uWord wU2DevExitLat;
  64662. +} UPACKED usb_dev_cap_ss_usb_t;
  64663. +
  64664. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  64665. +typedef struct usb_dev_cap_container_id {
  64666. + uByte bLength;
  64667. + uByte bDescriptorType;
  64668. + uByte bDevCapabilityType;
  64669. + uByte bReserved;
  64670. + uByte containerID[16];
  64671. +} UPACKED usb_dev_cap_container_id_t;
  64672. +
  64673. +/* Device Capability Type Codes */
  64674. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  64675. +
  64676. +/* Device Capability Descriptor */
  64677. +typedef struct wusb_dev_cap_desc {
  64678. + uByte bLength;
  64679. + uByte bDescriptorType;
  64680. + uByte bDevCapabilityType;
  64681. + uByte caps[1]; /* Variable length */
  64682. +} UPACKED wusb_dev_cap_desc_t;
  64683. +
  64684. +/* Device Capability Descriptor */
  64685. +typedef struct wusb_dev_cap_uwb_desc {
  64686. + uByte bLength;
  64687. + uByte bDescriptorType;
  64688. + uByte bDevCapabilityType;
  64689. + uByte bmAttributes;
  64690. + uWord wPHYRates; /* Bitmap */
  64691. + uByte bmTFITXPowerInfo;
  64692. + uByte bmFFITXPowerInfo;
  64693. + uWord bmBandGroup;
  64694. + uByte bReserved;
  64695. +} UPACKED wusb_dev_cap_uwb_desc_t;
  64696. +
  64697. +/* Wireless USB Endpoint Companion Descriptor */
  64698. +typedef struct wusb_endpoint_companion_desc {
  64699. + uByte bLength;
  64700. + uByte bDescriptorType;
  64701. + uByte bMaxBurst;
  64702. + uByte bMaxSequence;
  64703. + uWord wMaxStreamDelay;
  64704. + uWord wOverTheAirPacketSize;
  64705. + uByte bOverTheAirInterval;
  64706. + uByte bmCompAttributes;
  64707. +} UPACKED wusb_endpoint_companion_desc_t;
  64708. +
  64709. +/* Wireless USB Numeric Association M1 Data Structure */
  64710. +typedef struct wusb_m1_data {
  64711. + uByte version;
  64712. + uWord langId;
  64713. + uByte deviceFriendlyNameLength;
  64714. + uByte sha_256_m3[32];
  64715. + uByte deviceFriendlyName[256];
  64716. +} UPACKED wusb_m1_data_t;
  64717. +
  64718. +typedef struct wusb_m2_data {
  64719. + uByte version;
  64720. + uWord langId;
  64721. + uByte hostFriendlyNameLength;
  64722. + uByte pkh[384];
  64723. + uByte hostFriendlyName[256];
  64724. +} UPACKED wusb_m2_data_t;
  64725. +
  64726. +typedef struct wusb_m3_data {
  64727. + uByte pkd[384];
  64728. + uByte nd;
  64729. +} UPACKED wusb_m3_data_t;
  64730. +
  64731. +typedef struct wusb_m4_data {
  64732. + uDWord _attributeTypeIdAndLength_1;
  64733. + uWord associationTypeId;
  64734. +
  64735. + uDWord _attributeTypeIdAndLength_2;
  64736. + uWord associationSubTypeId;
  64737. +
  64738. + uDWord _attributeTypeIdAndLength_3;
  64739. + uDWord length;
  64740. +
  64741. + uDWord _attributeTypeIdAndLength_4;
  64742. + uDWord associationStatus;
  64743. +
  64744. + uDWord _attributeTypeIdAndLength_5;
  64745. + uByte chid[16];
  64746. +
  64747. + uDWord _attributeTypeIdAndLength_6;
  64748. + uByte cdid[16];
  64749. +
  64750. + uDWord _attributeTypeIdAndLength_7;
  64751. + uByte bandGroups[2];
  64752. +} UPACKED wusb_m4_data_t;
  64753. +
  64754. +#ifdef _MSC_VER
  64755. +#include <poppack.h>
  64756. +#endif
  64757. +
  64758. +#ifdef __cplusplus
  64759. +}
  64760. +#endif
  64761. +
  64762. +#endif /* _USB_H_ */
  64763. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  64764. --- linux-3.12.38/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  64765. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2015-03-09 10:39:33.214893718 +0100
  64766. @@ -0,0 +1,224 @@
  64767. +# Doxyfile 1.3.9.1
  64768. +
  64769. +#---------------------------------------------------------------------------
  64770. +# Project related configuration options
  64771. +#---------------------------------------------------------------------------
  64772. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  64773. +PROJECT_NUMBER = v3.00a
  64774. +OUTPUT_DIRECTORY = ./doc/
  64775. +CREATE_SUBDIRS = NO
  64776. +OUTPUT_LANGUAGE = English
  64777. +BRIEF_MEMBER_DESC = YES
  64778. +REPEAT_BRIEF = YES
  64779. +ABBREVIATE_BRIEF = "The $name class" \
  64780. + "The $name widget" \
  64781. + "The $name file" \
  64782. + is \
  64783. + provides \
  64784. + specifies \
  64785. + contains \
  64786. + represents \
  64787. + a \
  64788. + an \
  64789. + the
  64790. +ALWAYS_DETAILED_SEC = NO
  64791. +INLINE_INHERITED_MEMB = NO
  64792. +FULL_PATH_NAMES = NO
  64793. +STRIP_FROM_PATH =
  64794. +STRIP_FROM_INC_PATH =
  64795. +SHORT_NAMES = NO
  64796. +JAVADOC_AUTOBRIEF = YES
  64797. +MULTILINE_CPP_IS_BRIEF = NO
  64798. +INHERIT_DOCS = YES
  64799. +DISTRIBUTE_GROUP_DOC = NO
  64800. +TAB_SIZE = 8
  64801. +ALIASES =
  64802. +OPTIMIZE_OUTPUT_FOR_C = YES
  64803. +OPTIMIZE_OUTPUT_JAVA = NO
  64804. +SUBGROUPING = YES
  64805. +#---------------------------------------------------------------------------
  64806. +# Build related configuration options
  64807. +#---------------------------------------------------------------------------
  64808. +EXTRACT_ALL = NO
  64809. +EXTRACT_PRIVATE = YES
  64810. +EXTRACT_STATIC = YES
  64811. +EXTRACT_LOCAL_CLASSES = YES
  64812. +EXTRACT_LOCAL_METHODS = NO
  64813. +HIDE_UNDOC_MEMBERS = NO
  64814. +HIDE_UNDOC_CLASSES = NO
  64815. +HIDE_FRIEND_COMPOUNDS = NO
  64816. +HIDE_IN_BODY_DOCS = NO
  64817. +INTERNAL_DOCS = NO
  64818. +CASE_SENSE_NAMES = NO
  64819. +HIDE_SCOPE_NAMES = NO
  64820. +SHOW_INCLUDE_FILES = YES
  64821. +INLINE_INFO = YES
  64822. +SORT_MEMBER_DOCS = NO
  64823. +SORT_BRIEF_DOCS = NO
  64824. +SORT_BY_SCOPE_NAME = NO
  64825. +GENERATE_TODOLIST = YES
  64826. +GENERATE_TESTLIST = YES
  64827. +GENERATE_BUGLIST = YES
  64828. +GENERATE_DEPRECATEDLIST= YES
  64829. +ENABLED_SECTIONS =
  64830. +MAX_INITIALIZER_LINES = 30
  64831. +SHOW_USED_FILES = YES
  64832. +SHOW_DIRECTORIES = YES
  64833. +#---------------------------------------------------------------------------
  64834. +# configuration options related to warning and progress messages
  64835. +#---------------------------------------------------------------------------
  64836. +QUIET = YES
  64837. +WARNINGS = YES
  64838. +WARN_IF_UNDOCUMENTED = NO
  64839. +WARN_IF_DOC_ERROR = YES
  64840. +WARN_FORMAT = "$file:$line: $text"
  64841. +WARN_LOGFILE =
  64842. +#---------------------------------------------------------------------------
  64843. +# configuration options related to the input files
  64844. +#---------------------------------------------------------------------------
  64845. +INPUT = .
  64846. +FILE_PATTERNS = *.c \
  64847. + *.h \
  64848. + ./linux/*.c \
  64849. + ./linux/*.h
  64850. +RECURSIVE = NO
  64851. +EXCLUDE = ./test/ \
  64852. + ./dwc_otg/.AppleDouble/
  64853. +EXCLUDE_SYMLINKS = YES
  64854. +EXCLUDE_PATTERNS = *.mod.*
  64855. +EXAMPLE_PATH =
  64856. +EXAMPLE_PATTERNS = *
  64857. +EXAMPLE_RECURSIVE = NO
  64858. +IMAGE_PATH =
  64859. +INPUT_FILTER =
  64860. +FILTER_PATTERNS =
  64861. +FILTER_SOURCE_FILES = NO
  64862. +#---------------------------------------------------------------------------
  64863. +# configuration options related to source browsing
  64864. +#---------------------------------------------------------------------------
  64865. +SOURCE_BROWSER = YES
  64866. +INLINE_SOURCES = NO
  64867. +STRIP_CODE_COMMENTS = YES
  64868. +REFERENCED_BY_RELATION = NO
  64869. +REFERENCES_RELATION = NO
  64870. +VERBATIM_HEADERS = NO
  64871. +#---------------------------------------------------------------------------
  64872. +# configuration options related to the alphabetical class index
  64873. +#---------------------------------------------------------------------------
  64874. +ALPHABETICAL_INDEX = NO
  64875. +COLS_IN_ALPHA_INDEX = 5
  64876. +IGNORE_PREFIX =
  64877. +#---------------------------------------------------------------------------
  64878. +# configuration options related to the HTML output
  64879. +#---------------------------------------------------------------------------
  64880. +GENERATE_HTML = YES
  64881. +HTML_OUTPUT = html
  64882. +HTML_FILE_EXTENSION = .html
  64883. +HTML_HEADER =
  64884. +HTML_FOOTER =
  64885. +HTML_STYLESHEET =
  64886. +HTML_ALIGN_MEMBERS = YES
  64887. +GENERATE_HTMLHELP = NO
  64888. +CHM_FILE =
  64889. +HHC_LOCATION =
  64890. +GENERATE_CHI = NO
  64891. +BINARY_TOC = NO
  64892. +TOC_EXPAND = NO
  64893. +DISABLE_INDEX = NO
  64894. +ENUM_VALUES_PER_LINE = 4
  64895. +GENERATE_TREEVIEW = YES
  64896. +TREEVIEW_WIDTH = 250
  64897. +#---------------------------------------------------------------------------
  64898. +# configuration options related to the LaTeX output
  64899. +#---------------------------------------------------------------------------
  64900. +GENERATE_LATEX = NO
  64901. +LATEX_OUTPUT = latex
  64902. +LATEX_CMD_NAME = latex
  64903. +MAKEINDEX_CMD_NAME = makeindex
  64904. +COMPACT_LATEX = NO
  64905. +PAPER_TYPE = a4wide
  64906. +EXTRA_PACKAGES =
  64907. +LATEX_HEADER =
  64908. +PDF_HYPERLINKS = NO
  64909. +USE_PDFLATEX = NO
  64910. +LATEX_BATCHMODE = NO
  64911. +LATEX_HIDE_INDICES = NO
  64912. +#---------------------------------------------------------------------------
  64913. +# configuration options related to the RTF output
  64914. +#---------------------------------------------------------------------------
  64915. +GENERATE_RTF = NO
  64916. +RTF_OUTPUT = rtf
  64917. +COMPACT_RTF = NO
  64918. +RTF_HYPERLINKS = NO
  64919. +RTF_STYLESHEET_FILE =
  64920. +RTF_EXTENSIONS_FILE =
  64921. +#---------------------------------------------------------------------------
  64922. +# configuration options related to the man page output
  64923. +#---------------------------------------------------------------------------
  64924. +GENERATE_MAN = NO
  64925. +MAN_OUTPUT = man
  64926. +MAN_EXTENSION = .3
  64927. +MAN_LINKS = NO
  64928. +#---------------------------------------------------------------------------
  64929. +# configuration options related to the XML output
  64930. +#---------------------------------------------------------------------------
  64931. +GENERATE_XML = NO
  64932. +XML_OUTPUT = xml
  64933. +XML_SCHEMA =
  64934. +XML_DTD =
  64935. +XML_PROGRAMLISTING = YES
  64936. +#---------------------------------------------------------------------------
  64937. +# configuration options for the AutoGen Definitions output
  64938. +#---------------------------------------------------------------------------
  64939. +GENERATE_AUTOGEN_DEF = NO
  64940. +#---------------------------------------------------------------------------
  64941. +# configuration options related to the Perl module output
  64942. +#---------------------------------------------------------------------------
  64943. +GENERATE_PERLMOD = NO
  64944. +PERLMOD_LATEX = NO
  64945. +PERLMOD_PRETTY = YES
  64946. +PERLMOD_MAKEVAR_PREFIX =
  64947. +#---------------------------------------------------------------------------
  64948. +# Configuration options related to the preprocessor
  64949. +#---------------------------------------------------------------------------
  64950. +ENABLE_PREPROCESSING = YES
  64951. +MACRO_EXPANSION = YES
  64952. +EXPAND_ONLY_PREDEF = YES
  64953. +SEARCH_INCLUDES = YES
  64954. +INCLUDE_PATH =
  64955. +INCLUDE_FILE_PATTERNS =
  64956. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  64957. +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
  64958. +SKIP_FUNCTION_MACROS = NO
  64959. +#---------------------------------------------------------------------------
  64960. +# Configuration::additions related to external references
  64961. +#---------------------------------------------------------------------------
  64962. +TAGFILES =
  64963. +GENERATE_TAGFILE =
  64964. +ALLEXTERNALS = NO
  64965. +EXTERNAL_GROUPS = YES
  64966. +PERL_PATH = /usr/bin/perl
  64967. +#---------------------------------------------------------------------------
  64968. +# Configuration options related to the dot tool
  64969. +#---------------------------------------------------------------------------
  64970. +CLASS_DIAGRAMS = YES
  64971. +HIDE_UNDOC_RELATIONS = YES
  64972. +HAVE_DOT = NO
  64973. +CLASS_GRAPH = YES
  64974. +COLLABORATION_GRAPH = YES
  64975. +UML_LOOK = NO
  64976. +TEMPLATE_RELATIONS = NO
  64977. +INCLUDE_GRAPH = YES
  64978. +INCLUDED_BY_GRAPH = YES
  64979. +CALL_GRAPH = NO
  64980. +GRAPHICAL_HIERARCHY = YES
  64981. +DOT_IMAGE_FORMAT = png
  64982. +DOT_PATH =
  64983. +DOTFILE_DIRS =
  64984. +MAX_DOT_GRAPH_DEPTH = 1000
  64985. +GENERATE_LEGEND = YES
  64986. +DOT_CLEANUP = YES
  64987. +#---------------------------------------------------------------------------
  64988. +# Configuration::additions related to the search engine
  64989. +#---------------------------------------------------------------------------
  64990. +SEARCHENGINE = NO
  64991. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  64992. --- linux-3.12.38/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  64993. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2015-03-09 10:39:33.214893718 +0100
  64994. @@ -0,0 +1,1575 @@
  64995. +/*
  64996. + * zero.c -- Gadget Zero, for USB development
  64997. + *
  64998. + * Copyright (C) 2003-2004 David Brownell
  64999. + * All rights reserved.
  65000. + *
  65001. + * Redistribution and use in source and binary forms, with or without
  65002. + * modification, are permitted provided that the following conditions
  65003. + * are met:
  65004. + * 1. Redistributions of source code must retain the above copyright
  65005. + * notice, this list of conditions, and the following disclaimer,
  65006. + * without modification.
  65007. + * 2. Redistributions in binary form must reproduce the above copyright
  65008. + * notice, this list of conditions and the following disclaimer in the
  65009. + * documentation and/or other materials provided with the distribution.
  65010. + * 3. The names of the above-listed copyright holders may not be used
  65011. + * to endorse or promote products derived from this software without
  65012. + * specific prior written permission.
  65013. + *
  65014. + * ALTERNATIVELY, this software may be distributed under the terms of the
  65015. + * GNU General Public License ("GPL") as published by the Free Software
  65016. + * Foundation, either version 2 of that License or (at your option) any
  65017. + * later version.
  65018. + *
  65019. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  65020. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  65021. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  65022. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  65023. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  65024. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  65025. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  65026. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  65027. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  65028. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  65029. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65030. + */
  65031. +
  65032. +
  65033. +/*
  65034. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  65035. + * can write a hardware-agnostic gadget driver running inside a USB device.
  65036. + *
  65037. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  65038. + * affect most of the driver.
  65039. + *
  65040. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  65041. + * functional test of your device-side usb stack, or with "usb-skeleton".
  65042. + *
  65043. + * It supports two similar configurations. One sinks whatever the usb host
  65044. + * writes, and in return sources zeroes. The other loops whatever the host
  65045. + * writes back, so the host can read it. Module options include:
  65046. + *
  65047. + * buflen=N default N=4096, buffer size used
  65048. + * qlen=N default N=32, how many buffers in the loopback queue
  65049. + * loopdefault default false, list loopback config first
  65050. + *
  65051. + * Many drivers will only have one configuration, letting them be much
  65052. + * simpler if they also don't support high speed operation (like this
  65053. + * driver does).
  65054. + */
  65055. +
  65056. +#include <linux/config.h>
  65057. +#include <linux/module.h>
  65058. +#include <linux/kernel.h>
  65059. +#include <linux/delay.h>
  65060. +#include <linux/ioport.h>
  65061. +#include <linux/sched.h>
  65062. +#include <linux/slab.h>
  65063. +#include <linux/smp_lock.h>
  65064. +#include <linux/errno.h>
  65065. +#include <linux/init.h>
  65066. +#include <linux/timer.h>
  65067. +#include <linux/list.h>
  65068. +#include <linux/interrupt.h>
  65069. +#include <linux/uts.h>
  65070. +#include <linux/version.h>
  65071. +#include <linux/device.h>
  65072. +#include <linux/moduleparam.h>
  65073. +#include <linux/proc_fs.h>
  65074. +
  65075. +#include <asm/byteorder.h>
  65076. +#include <asm/io.h>
  65077. +#include <asm/irq.h>
  65078. +#include <asm/system.h>
  65079. +#include <asm/unaligned.h>
  65080. +
  65081. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  65082. +# include <linux/usb/ch9.h>
  65083. +#else
  65084. +# include <linux/usb_ch9.h>
  65085. +#endif
  65086. +
  65087. +#include <linux/usb_gadget.h>
  65088. +
  65089. +
  65090. +/*-------------------------------------------------------------------------*/
  65091. +/*-------------------------------------------------------------------------*/
  65092. +
  65093. +
  65094. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  65095. +{
  65096. + int count = 0;
  65097. + u8 c;
  65098. + u16 uchar;
  65099. +
  65100. + /* this insists on correct encodings, though not minimal ones.
  65101. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  65102. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  65103. + */
  65104. + while (len != 0 && (c = (u8) *s++) != 0) {
  65105. + if (unlikely(c & 0x80)) {
  65106. + // 2-byte sequence:
  65107. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  65108. + if ((c & 0xe0) == 0xc0) {
  65109. + uchar = (c & 0x1f) << 6;
  65110. +
  65111. + c = (u8) *s++;
  65112. + if ((c & 0xc0) != 0xc0)
  65113. + goto fail;
  65114. + c &= 0x3f;
  65115. + uchar |= c;
  65116. +
  65117. + // 3-byte sequence (most CJKV characters):
  65118. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  65119. + } else if ((c & 0xf0) == 0xe0) {
  65120. + uchar = (c & 0x0f) << 12;
  65121. +
  65122. + c = (u8) *s++;
  65123. + if ((c & 0xc0) != 0xc0)
  65124. + goto fail;
  65125. + c &= 0x3f;
  65126. + uchar |= c << 6;
  65127. +
  65128. + c = (u8) *s++;
  65129. + if ((c & 0xc0) != 0xc0)
  65130. + goto fail;
  65131. + c &= 0x3f;
  65132. + uchar |= c;
  65133. +
  65134. + /* no bogus surrogates */
  65135. + if (0xd800 <= uchar && uchar <= 0xdfff)
  65136. + goto fail;
  65137. +
  65138. + // 4-byte sequence (surrogate pairs, currently rare):
  65139. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  65140. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  65141. + // (uuuuu = wwww + 1)
  65142. + // FIXME accept the surrogate code points (only)
  65143. +
  65144. + } else
  65145. + goto fail;
  65146. + } else
  65147. + uchar = c;
  65148. + put_unaligned (cpu_to_le16 (uchar), cp++);
  65149. + count++;
  65150. + len--;
  65151. + }
  65152. + return count;
  65153. +fail:
  65154. + return -1;
  65155. +}
  65156. +
  65157. +
  65158. +/**
  65159. + * usb_gadget_get_string - fill out a string descriptor
  65160. + * @table: of c strings encoded using UTF-8
  65161. + * @id: string id, from low byte of wValue in get string descriptor
  65162. + * @buf: at least 256 bytes
  65163. + *
  65164. + * Finds the UTF-8 string matching the ID, and converts it into a
  65165. + * string descriptor in utf16-le.
  65166. + * Returns length of descriptor (always even) or negative errno
  65167. + *
  65168. + * If your driver needs stings in multiple languages, you'll probably
  65169. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  65170. + * using this routine after choosing which set of UTF-8 strings to use.
  65171. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  65172. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  65173. + * characters (which are also widely used in C strings).
  65174. + */
  65175. +int
  65176. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  65177. +{
  65178. + struct usb_string *s;
  65179. + int len;
  65180. +
  65181. + /* descriptor 0 has the language id */
  65182. + if (id == 0) {
  65183. + buf [0] = 4;
  65184. + buf [1] = USB_DT_STRING;
  65185. + buf [2] = (u8) table->language;
  65186. + buf [3] = (u8) (table->language >> 8);
  65187. + return 4;
  65188. + }
  65189. + for (s = table->strings; s && s->s; s++)
  65190. + if (s->id == id)
  65191. + break;
  65192. +
  65193. + /* unrecognized: stall. */
  65194. + if (!s || !s->s)
  65195. + return -EINVAL;
  65196. +
  65197. + /* string descriptors have length, tag, then UTF16-LE text */
  65198. + len = min ((size_t) 126, strlen (s->s));
  65199. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  65200. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  65201. + if (len < 0)
  65202. + return -EINVAL;
  65203. + buf [0] = (len + 1) * 2;
  65204. + buf [1] = USB_DT_STRING;
  65205. + return buf [0];
  65206. +}
  65207. +
  65208. +
  65209. +/*-------------------------------------------------------------------------*/
  65210. +/*-------------------------------------------------------------------------*/
  65211. +
  65212. +
  65213. +/**
  65214. + * usb_descriptor_fillbuf - fill buffer with descriptors
  65215. + * @buf: Buffer to be filled
  65216. + * @buflen: Size of buf
  65217. + * @src: Array of descriptor pointers, terminated by null pointer.
  65218. + *
  65219. + * Copies descriptors into the buffer, returning the length or a
  65220. + * negative error code if they can't all be copied. Useful when
  65221. + * assembling descriptors for an associated set of interfaces used
  65222. + * as part of configuring a composite device; or in other cases where
  65223. + * sets of descriptors need to be marshaled.
  65224. + */
  65225. +int
  65226. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  65227. + const struct usb_descriptor_header **src)
  65228. +{
  65229. + u8 *dest = buf;
  65230. +
  65231. + if (!src)
  65232. + return -EINVAL;
  65233. +
  65234. + /* fill buffer from src[] until null descriptor ptr */
  65235. + for (; 0 != *src; src++) {
  65236. + unsigned len = (*src)->bLength;
  65237. +
  65238. + if (len > buflen)
  65239. + return -EINVAL;
  65240. + memcpy(dest, *src, len);
  65241. + buflen -= len;
  65242. + dest += len;
  65243. + }
  65244. + return dest - (u8 *)buf;
  65245. +}
  65246. +
  65247. +
  65248. +/**
  65249. + * usb_gadget_config_buf - builts a complete configuration descriptor
  65250. + * @config: Header for the descriptor, including characteristics such
  65251. + * as power requirements and number of interfaces.
  65252. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  65253. + * endpoint, etc) defining all functions in this device configuration.
  65254. + * @buf: Buffer for the resulting configuration descriptor.
  65255. + * @length: Length of buffer. If this is not big enough to hold the
  65256. + * entire configuration descriptor, an error code will be returned.
  65257. + *
  65258. + * This copies descriptors into the response buffer, building a descriptor
  65259. + * for that configuration. It returns the buffer length or a negative
  65260. + * status code. The config.wTotalLength field is set to match the length
  65261. + * of the result, but other descriptor fields (including power usage and
  65262. + * interface count) must be set by the caller.
  65263. + *
  65264. + * Gadget drivers could use this when constructing a config descriptor
  65265. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  65266. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  65267. + */
  65268. +int usb_gadget_config_buf(
  65269. + const struct usb_config_descriptor *config,
  65270. + void *buf,
  65271. + unsigned length,
  65272. + const struct usb_descriptor_header **desc
  65273. +)
  65274. +{
  65275. + struct usb_config_descriptor *cp = buf;
  65276. + int len;
  65277. +
  65278. + /* config descriptor first */
  65279. + if (length < USB_DT_CONFIG_SIZE || !desc)
  65280. + return -EINVAL;
  65281. + *cp = *config;
  65282. +
  65283. + /* then interface/endpoint/class/vendor/... */
  65284. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  65285. + length - USB_DT_CONFIG_SIZE, desc);
  65286. + if (len < 0)
  65287. + return len;
  65288. + len += USB_DT_CONFIG_SIZE;
  65289. + if (len > 0xffff)
  65290. + return -EINVAL;
  65291. +
  65292. + /* patch up the config descriptor */
  65293. + cp->bLength = USB_DT_CONFIG_SIZE;
  65294. + cp->bDescriptorType = USB_DT_CONFIG;
  65295. + cp->wTotalLength = cpu_to_le16(len);
  65296. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  65297. + return len;
  65298. +}
  65299. +
  65300. +/*-------------------------------------------------------------------------*/
  65301. +/*-------------------------------------------------------------------------*/
  65302. +
  65303. +
  65304. +#define RBUF_LEN (1024*1024)
  65305. +static int rbuf_start;
  65306. +static int rbuf_len;
  65307. +static __u8 rbuf[RBUF_LEN];
  65308. +
  65309. +/*-------------------------------------------------------------------------*/
  65310. +
  65311. +#define DRIVER_VERSION "St Patrick's Day 2004"
  65312. +
  65313. +static const char shortname [] = "zero";
  65314. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  65315. +
  65316. +static const char source_sink [] = "source and sink data";
  65317. +static const char loopback [] = "loop input to output";
  65318. +
  65319. +/*-------------------------------------------------------------------------*/
  65320. +
  65321. +/*
  65322. + * driver assumes self-powered hardware, and
  65323. + * has no way for users to trigger remote wakeup.
  65324. + *
  65325. + * this version autoconfigures as much as possible,
  65326. + * which is reasonable for most "bulk-only" drivers.
  65327. + */
  65328. +static const char *EP_IN_NAME; /* source */
  65329. +static const char *EP_OUT_NAME; /* sink */
  65330. +
  65331. +/*-------------------------------------------------------------------------*/
  65332. +
  65333. +/* big enough to hold our biggest descriptor */
  65334. +#define USB_BUFSIZ 512
  65335. +
  65336. +struct zero_dev {
  65337. + spinlock_t lock;
  65338. + struct usb_gadget *gadget;
  65339. + struct usb_request *req; /* for control responses */
  65340. +
  65341. + /* when configured, we have one of two configs:
  65342. + * - source data (in to host) and sink it (out from host)
  65343. + * - or loop it back (out from host back in to host)
  65344. + */
  65345. + u8 config;
  65346. + struct usb_ep *in_ep, *out_ep;
  65347. +
  65348. + /* autoresume timer */
  65349. + struct timer_list resume;
  65350. +};
  65351. +
  65352. +#define xprintk(d,level,fmt,args...) \
  65353. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  65354. +
  65355. +#ifdef DEBUG
  65356. +#define DBG(dev,fmt,args...) \
  65357. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  65358. +#else
  65359. +#define DBG(dev,fmt,args...) \
  65360. + do { } while (0)
  65361. +#endif /* DEBUG */
  65362. +
  65363. +#ifdef VERBOSE
  65364. +#define VDBG DBG
  65365. +#else
  65366. +#define VDBG(dev,fmt,args...) \
  65367. + do { } while (0)
  65368. +#endif /* VERBOSE */
  65369. +
  65370. +#define ERROR(dev,fmt,args...) \
  65371. + xprintk(dev , KERN_ERR , fmt , ## args)
  65372. +#define WARN(dev,fmt,args...) \
  65373. + xprintk(dev , KERN_WARNING , fmt , ## args)
  65374. +#define INFO(dev,fmt,args...) \
  65375. + xprintk(dev , KERN_INFO , fmt , ## args)
  65376. +
  65377. +/*-------------------------------------------------------------------------*/
  65378. +
  65379. +static unsigned buflen = 4096;
  65380. +static unsigned qlen = 32;
  65381. +static unsigned pattern = 0;
  65382. +
  65383. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  65384. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  65385. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  65386. +
  65387. +/*
  65388. + * if it's nonzero, autoresume says how many seconds to wait
  65389. + * before trying to wake up the host after suspend.
  65390. + */
  65391. +static unsigned autoresume = 0;
  65392. +module_param (autoresume, uint, 0);
  65393. +
  65394. +/*
  65395. + * Normally the "loopback" configuration is second (index 1) so
  65396. + * it's not the default. Here's where to change that order, to
  65397. + * work better with hosts where config changes are problematic.
  65398. + * Or controllers (like superh) that only support one config.
  65399. + */
  65400. +static int loopdefault = 0;
  65401. +
  65402. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  65403. +
  65404. +/*-------------------------------------------------------------------------*/
  65405. +
  65406. +/* Thanks to NetChip Technologies for donating this product ID.
  65407. + *
  65408. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  65409. + * Instead: allocate your own, using normal USB-IF procedures.
  65410. + */
  65411. +#ifndef CONFIG_USB_ZERO_HNPTEST
  65412. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  65413. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  65414. +#else
  65415. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  65416. +#define DRIVER_PRODUCT_NUM 0xbadd
  65417. +#endif
  65418. +
  65419. +/*-------------------------------------------------------------------------*/
  65420. +
  65421. +/*
  65422. + * DESCRIPTORS ... most are static, but strings and (full)
  65423. + * configuration descriptors are built on demand.
  65424. + */
  65425. +
  65426. +/*
  65427. +#define STRING_MANUFACTURER 25
  65428. +#define STRING_PRODUCT 42
  65429. +#define STRING_SERIAL 101
  65430. +*/
  65431. +#define STRING_MANUFACTURER 1
  65432. +#define STRING_PRODUCT 2
  65433. +#define STRING_SERIAL 3
  65434. +
  65435. +#define STRING_SOURCE_SINK 250
  65436. +#define STRING_LOOPBACK 251
  65437. +
  65438. +/*
  65439. + * This device advertises two configurations; these numbers work
  65440. + * on a pxa250 as well as more flexible hardware.
  65441. + */
  65442. +#define CONFIG_SOURCE_SINK 3
  65443. +#define CONFIG_LOOPBACK 2
  65444. +
  65445. +/*
  65446. +static struct usb_device_descriptor
  65447. +device_desc = {
  65448. + .bLength = sizeof device_desc,
  65449. + .bDescriptorType = USB_DT_DEVICE,
  65450. +
  65451. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  65452. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  65453. +
  65454. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  65455. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  65456. + .iManufacturer = STRING_MANUFACTURER,
  65457. + .iProduct = STRING_PRODUCT,
  65458. + .iSerialNumber = STRING_SERIAL,
  65459. + .bNumConfigurations = 2,
  65460. +};
  65461. +*/
  65462. +static struct usb_device_descriptor
  65463. +device_desc = {
  65464. + .bLength = sizeof device_desc,
  65465. + .bDescriptorType = USB_DT_DEVICE,
  65466. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  65467. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  65468. + .bDeviceSubClass = 0,
  65469. + .bDeviceProtocol = 0,
  65470. + .bMaxPacketSize0 = 64,
  65471. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  65472. + .idVendor = __constant_cpu_to_le16 (0x0499),
  65473. + .idProduct = __constant_cpu_to_le16 (0x3002),
  65474. + .iManufacturer = STRING_MANUFACTURER,
  65475. + .iProduct = STRING_PRODUCT,
  65476. + .iSerialNumber = STRING_SERIAL,
  65477. + .bNumConfigurations = 1,
  65478. +};
  65479. +
  65480. +static struct usb_config_descriptor
  65481. +z_config = {
  65482. + .bLength = sizeof z_config,
  65483. + .bDescriptorType = USB_DT_CONFIG,
  65484. +
  65485. + /* compute wTotalLength on the fly */
  65486. + .bNumInterfaces = 2,
  65487. + .bConfigurationValue = 1,
  65488. + .iConfiguration = 0,
  65489. + .bmAttributes = 0x40,
  65490. + .bMaxPower = 0, /* self-powered */
  65491. +};
  65492. +
  65493. +
  65494. +static struct usb_otg_descriptor
  65495. +otg_descriptor = {
  65496. + .bLength = sizeof otg_descriptor,
  65497. + .bDescriptorType = USB_DT_OTG,
  65498. +
  65499. + .bmAttributes = USB_OTG_SRP,
  65500. +};
  65501. +
  65502. +/* one interface in each configuration */
  65503. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  65504. +
  65505. +/*
  65506. + * usb 2.0 devices need to expose both high speed and full speed
  65507. + * descriptors, unless they only run at full speed.
  65508. + *
  65509. + * that means alternate endpoint descriptors (bigger packets)
  65510. + * and a "device qualifier" ... plus more construction options
  65511. + * for the config descriptor.
  65512. + */
  65513. +
  65514. +static struct usb_qualifier_descriptor
  65515. +dev_qualifier = {
  65516. + .bLength = sizeof dev_qualifier,
  65517. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  65518. +
  65519. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  65520. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  65521. +
  65522. + .bNumConfigurations = 2,
  65523. +};
  65524. +
  65525. +
  65526. +struct usb_cs_as_general_descriptor {
  65527. + __u8 bLength;
  65528. + __u8 bDescriptorType;
  65529. +
  65530. + __u8 bDescriptorSubType;
  65531. + __u8 bTerminalLink;
  65532. + __u8 bDelay;
  65533. + __u16 wFormatTag;
  65534. +} __attribute__ ((packed));
  65535. +
  65536. +struct usb_cs_as_format_descriptor {
  65537. + __u8 bLength;
  65538. + __u8 bDescriptorType;
  65539. +
  65540. + __u8 bDescriptorSubType;
  65541. + __u8 bFormatType;
  65542. + __u8 bNrChannels;
  65543. + __u8 bSubframeSize;
  65544. + __u8 bBitResolution;
  65545. + __u8 bSamfreqType;
  65546. + __u8 tLowerSamFreq[3];
  65547. + __u8 tUpperSamFreq[3];
  65548. +} __attribute__ ((packed));
  65549. +
  65550. +static const struct usb_interface_descriptor
  65551. +z_audio_control_if_desc = {
  65552. + .bLength = sizeof z_audio_control_if_desc,
  65553. + .bDescriptorType = USB_DT_INTERFACE,
  65554. + .bInterfaceNumber = 0,
  65555. + .bAlternateSetting = 0,
  65556. + .bNumEndpoints = 0,
  65557. + .bInterfaceClass = USB_CLASS_AUDIO,
  65558. + .bInterfaceSubClass = 0x1,
  65559. + .bInterfaceProtocol = 0,
  65560. + .iInterface = 0,
  65561. +};
  65562. +
  65563. +static const struct usb_interface_descriptor
  65564. +z_audio_if_desc = {
  65565. + .bLength = sizeof z_audio_if_desc,
  65566. + .bDescriptorType = USB_DT_INTERFACE,
  65567. + .bInterfaceNumber = 1,
  65568. + .bAlternateSetting = 0,
  65569. + .bNumEndpoints = 0,
  65570. + .bInterfaceClass = USB_CLASS_AUDIO,
  65571. + .bInterfaceSubClass = 0x2,
  65572. + .bInterfaceProtocol = 0,
  65573. + .iInterface = 0,
  65574. +};
  65575. +
  65576. +static const struct usb_interface_descriptor
  65577. +z_audio_if_desc2 = {
  65578. + .bLength = sizeof z_audio_if_desc,
  65579. + .bDescriptorType = USB_DT_INTERFACE,
  65580. + .bInterfaceNumber = 1,
  65581. + .bAlternateSetting = 1,
  65582. + .bNumEndpoints = 1,
  65583. + .bInterfaceClass = USB_CLASS_AUDIO,
  65584. + .bInterfaceSubClass = 0x2,
  65585. + .bInterfaceProtocol = 0,
  65586. + .iInterface = 0,
  65587. +};
  65588. +
  65589. +static const struct usb_cs_as_general_descriptor
  65590. +z_audio_cs_as_if_desc = {
  65591. + .bLength = 7,
  65592. + .bDescriptorType = 0x24,
  65593. +
  65594. + .bDescriptorSubType = 0x01,
  65595. + .bTerminalLink = 0x01,
  65596. + .bDelay = 0x0,
  65597. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  65598. +};
  65599. +
  65600. +
  65601. +static const struct usb_cs_as_format_descriptor
  65602. +z_audio_cs_as_format_desc = {
  65603. + .bLength = 0xe,
  65604. + .bDescriptorType = 0x24,
  65605. +
  65606. + .bDescriptorSubType = 2,
  65607. + .bFormatType = 1,
  65608. + .bNrChannels = 1,
  65609. + .bSubframeSize = 1,
  65610. + .bBitResolution = 8,
  65611. + .bSamfreqType = 0,
  65612. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  65613. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  65614. +};
  65615. +
  65616. +static const struct usb_endpoint_descriptor
  65617. +z_iso_ep = {
  65618. + .bLength = 0x09,
  65619. + .bDescriptorType = 0x05,
  65620. + .bEndpointAddress = 0x04,
  65621. + .bmAttributes = 0x09,
  65622. + .wMaxPacketSize = 0x0038,
  65623. + .bInterval = 0x01,
  65624. + .bRefresh = 0x00,
  65625. + .bSynchAddress = 0x00,
  65626. +};
  65627. +
  65628. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65629. +
  65630. +// 9 bytes
  65631. +static char z_ac_interface_header_desc[] =
  65632. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  65633. +
  65634. +// 12 bytes
  65635. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  65636. + 0x03, 0x00, 0x00, 0x00};
  65637. +// 13 bytes
  65638. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  65639. + 0x02, 0x00, 0x02, 0x00, 0x00};
  65640. +// 9 bytes
  65641. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  65642. + 0x00};
  65643. +
  65644. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  65645. + 0x00};
  65646. +
  65647. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65648. +
  65649. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  65650. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65651. +
  65652. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  65653. + 0x00};
  65654. +
  65655. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65656. +
  65657. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  65658. + 0x00};
  65659. +
  65660. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65661. +
  65662. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  65663. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65664. +
  65665. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  65666. + 0x00};
  65667. +
  65668. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65669. +
  65670. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  65671. + 0x00};
  65672. +
  65673. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65674. +
  65675. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  65676. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65677. +
  65678. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  65679. + 0x00};
  65680. +
  65681. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65682. +
  65683. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  65684. + 0x00};
  65685. +
  65686. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65687. +
  65688. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  65689. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65690. +
  65691. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  65692. + 0x00};
  65693. +
  65694. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65695. +
  65696. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  65697. + 0x00};
  65698. +
  65699. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  65700. +
  65701. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  65702. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  65703. +
  65704. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  65705. + 0x00};
  65706. +
  65707. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  65708. +
  65709. +
  65710. +
  65711. +static const struct usb_descriptor_header *z_function [] = {
  65712. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  65713. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  65714. + (struct usb_descriptor_header *) &z_0,
  65715. + (struct usb_descriptor_header *) &z_1,
  65716. + (struct usb_descriptor_header *) &z_2,
  65717. + (struct usb_descriptor_header *) &z_audio_if_desc,
  65718. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  65719. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  65720. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  65721. + (struct usb_descriptor_header *) &z_iso_ep,
  65722. + (struct usb_descriptor_header *) &z_iso_ep2,
  65723. + (struct usb_descriptor_header *) &za_0,
  65724. + (struct usb_descriptor_header *) &za_1,
  65725. + (struct usb_descriptor_header *) &za_2,
  65726. + (struct usb_descriptor_header *) &za_3,
  65727. + (struct usb_descriptor_header *) &za_4,
  65728. + (struct usb_descriptor_header *) &za_5,
  65729. + (struct usb_descriptor_header *) &za_6,
  65730. + (struct usb_descriptor_header *) &za_7,
  65731. + (struct usb_descriptor_header *) &za_8,
  65732. + (struct usb_descriptor_header *) &za_9,
  65733. + (struct usb_descriptor_header *) &za_10,
  65734. + (struct usb_descriptor_header *) &za_11,
  65735. + (struct usb_descriptor_header *) &za_12,
  65736. + (struct usb_descriptor_header *) &za_13,
  65737. + (struct usb_descriptor_header *) &za_14,
  65738. + (struct usb_descriptor_header *) &za_15,
  65739. + (struct usb_descriptor_header *) &za_16,
  65740. + (struct usb_descriptor_header *) &za_17,
  65741. + (struct usb_descriptor_header *) &za_18,
  65742. + (struct usb_descriptor_header *) &za_19,
  65743. + (struct usb_descriptor_header *) &za_20,
  65744. + (struct usb_descriptor_header *) &za_21,
  65745. + (struct usb_descriptor_header *) &za_22,
  65746. + (struct usb_descriptor_header *) &za_23,
  65747. + (struct usb_descriptor_header *) &za_24,
  65748. + NULL,
  65749. +};
  65750. +
  65751. +/* maxpacket and other transfer characteristics vary by speed. */
  65752. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  65753. +
  65754. +#else
  65755. +
  65756. +/* if there's no high speed support, maxpacket doesn't change. */
  65757. +#define ep_desc(g,hs,fs) fs
  65758. +
  65759. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  65760. +
  65761. +static char manufacturer [40];
  65762. +//static char serial [40];
  65763. +static char serial [] = "Ser 00 em";
  65764. +
  65765. +/* static strings, in UTF-8 */
  65766. +static struct usb_string strings [] = {
  65767. + { STRING_MANUFACTURER, manufacturer, },
  65768. + { STRING_PRODUCT, longname, },
  65769. + { STRING_SERIAL, serial, },
  65770. + { STRING_LOOPBACK, loopback, },
  65771. + { STRING_SOURCE_SINK, source_sink, },
  65772. + { } /* end of list */
  65773. +};
  65774. +
  65775. +static struct usb_gadget_strings stringtab = {
  65776. + .language = 0x0409, /* en-us */
  65777. + .strings = strings,
  65778. +};
  65779. +
  65780. +/*
  65781. + * config descriptors are also handcrafted. these must agree with code
  65782. + * that sets configurations, and with code managing interfaces and their
  65783. + * altsettings. other complexity may come from:
  65784. + *
  65785. + * - high speed support, including "other speed config" rules
  65786. + * - multiple configurations
  65787. + * - interfaces with alternate settings
  65788. + * - embedded class or vendor-specific descriptors
  65789. + *
  65790. + * this handles high speed, and has a second config that could as easily
  65791. + * have been an alternate interface setting (on most hardware).
  65792. + *
  65793. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  65794. + * should include an altsetting to test interrupt transfers, including
  65795. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  65796. + * device?)
  65797. + */
  65798. +static int
  65799. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  65800. +{
  65801. + int len;
  65802. + const struct usb_descriptor_header **function;
  65803. +
  65804. + function = z_function;
  65805. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  65806. + if (len < 0)
  65807. + return len;
  65808. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  65809. + return len;
  65810. +}
  65811. +
  65812. +/*-------------------------------------------------------------------------*/
  65813. +
  65814. +static struct usb_request *
  65815. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  65816. +{
  65817. + struct usb_request *req;
  65818. +
  65819. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  65820. + if (req) {
  65821. + req->length = length;
  65822. + req->buf = usb_ep_alloc_buffer (ep, length,
  65823. + &req->dma, GFP_ATOMIC);
  65824. + if (!req->buf) {
  65825. + usb_ep_free_request (ep, req);
  65826. + req = NULL;
  65827. + }
  65828. + }
  65829. + return req;
  65830. +}
  65831. +
  65832. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  65833. +{
  65834. + if (req->buf)
  65835. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  65836. + usb_ep_free_request (ep, req);
  65837. +}
  65838. +
  65839. +/*-------------------------------------------------------------------------*/
  65840. +
  65841. +/* optionally require specific source/sink data patterns */
  65842. +
  65843. +static int
  65844. +check_read_data (
  65845. + struct zero_dev *dev,
  65846. + struct usb_ep *ep,
  65847. + struct usb_request *req
  65848. +)
  65849. +{
  65850. + unsigned i;
  65851. + u8 *buf = req->buf;
  65852. +
  65853. + for (i = 0; i < req->actual; i++, buf++) {
  65854. + switch (pattern) {
  65855. + /* all-zeroes has no synchronization issues */
  65856. + case 0:
  65857. + if (*buf == 0)
  65858. + continue;
  65859. + break;
  65860. + /* mod63 stays in sync with short-terminated transfers,
  65861. + * or otherwise when host and gadget agree on how large
  65862. + * each usb transfer request should be. resync is done
  65863. + * with set_interface or set_config.
  65864. + */
  65865. + case 1:
  65866. + if (*buf == (u8)(i % 63))
  65867. + continue;
  65868. + break;
  65869. + }
  65870. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  65871. + usb_ep_set_halt (ep);
  65872. + return -EINVAL;
  65873. + }
  65874. + return 0;
  65875. +}
  65876. +
  65877. +/*-------------------------------------------------------------------------*/
  65878. +
  65879. +static void zero_reset_config (struct zero_dev *dev)
  65880. +{
  65881. + if (dev->config == 0)
  65882. + return;
  65883. +
  65884. + DBG (dev, "reset config\n");
  65885. +
  65886. + /* just disable endpoints, forcing completion of pending i/o.
  65887. + * all our completion handlers free their requests in this case.
  65888. + */
  65889. + if (dev->in_ep) {
  65890. + usb_ep_disable (dev->in_ep);
  65891. + dev->in_ep = NULL;
  65892. + }
  65893. + if (dev->out_ep) {
  65894. + usb_ep_disable (dev->out_ep);
  65895. + dev->out_ep = NULL;
  65896. + }
  65897. + dev->config = 0;
  65898. + del_timer (&dev->resume);
  65899. +}
  65900. +
  65901. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  65902. +
  65903. +static void
  65904. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  65905. +{
  65906. + struct zero_dev *dev = ep->driver_data;
  65907. + int status = req->status;
  65908. + int i, j;
  65909. +
  65910. + switch (status) {
  65911. +
  65912. + case 0: /* normal completion? */
  65913. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  65914. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  65915. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  65916. + rbuf[j] = ((__u8*)req->buf)[i];
  65917. + j++;
  65918. + if (j >= RBUF_LEN) j=0;
  65919. + }
  65920. + rbuf_start = j;
  65921. + //printk ("\n\n");
  65922. +
  65923. + if (rbuf_len < RBUF_LEN) {
  65924. + rbuf_len += req->actual;
  65925. + if (rbuf_len > RBUF_LEN) {
  65926. + rbuf_len = RBUF_LEN;
  65927. + }
  65928. + }
  65929. +
  65930. + break;
  65931. +
  65932. + /* this endpoint is normally active while we're configured */
  65933. + case -ECONNABORTED: /* hardware forced ep reset */
  65934. + case -ECONNRESET: /* request dequeued */
  65935. + case -ESHUTDOWN: /* disconnect from host */
  65936. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  65937. + req->actual, req->length);
  65938. + if (ep == dev->out_ep)
  65939. + check_read_data (dev, ep, req);
  65940. + free_ep_req (ep, req);
  65941. + return;
  65942. +
  65943. + case -EOVERFLOW: /* buffer overrun on read means that
  65944. + * we didn't provide a big enough
  65945. + * buffer.
  65946. + */
  65947. + default:
  65948. +#if 1
  65949. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  65950. + status, req->actual, req->length);
  65951. +#endif
  65952. + case -EREMOTEIO: /* short read */
  65953. + break;
  65954. + }
  65955. +
  65956. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  65957. + if (status) {
  65958. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  65959. + ep->name, req->length, status);
  65960. + usb_ep_set_halt (ep);
  65961. + /* FIXME recover later ... somehow */
  65962. + }
  65963. +}
  65964. +
  65965. +static struct usb_request *
  65966. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  65967. +{
  65968. + struct usb_request *req;
  65969. + int status;
  65970. +
  65971. + req = alloc_ep_req (ep, 512);
  65972. + if (!req)
  65973. + return NULL;
  65974. +
  65975. + req->complete = zero_isoc_complete;
  65976. +
  65977. + status = usb_ep_queue (ep, req, gfp_flags);
  65978. + if (status) {
  65979. + struct zero_dev *dev = ep->driver_data;
  65980. +
  65981. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  65982. + free_ep_req (ep, req);
  65983. + req = NULL;
  65984. + }
  65985. +
  65986. + return req;
  65987. +}
  65988. +
  65989. +/* change our operational config. this code must agree with the code
  65990. + * that returns config descriptors, and altsetting code.
  65991. + *
  65992. + * it's also responsible for power management interactions. some
  65993. + * configurations might not work with our current power sources.
  65994. + *
  65995. + * note that some device controller hardware will constrain what this
  65996. + * code can do, perhaps by disallowing more than one configuration or
  65997. + * by limiting configuration choices (like the pxa2xx).
  65998. + */
  65999. +static int
  66000. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  66001. +{
  66002. + int result = 0;
  66003. + struct usb_gadget *gadget = dev->gadget;
  66004. + const struct usb_endpoint_descriptor *d;
  66005. + struct usb_ep *ep;
  66006. +
  66007. + if (number == dev->config)
  66008. + return 0;
  66009. +
  66010. + zero_reset_config (dev);
  66011. +
  66012. + gadget_for_each_ep (ep, gadget) {
  66013. +
  66014. + if (strcmp (ep->name, "ep4") == 0) {
  66015. +
  66016. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  66017. + result = usb_ep_enable (ep, d);
  66018. +
  66019. + if (result == 0) {
  66020. + ep->driver_data = dev;
  66021. + dev->in_ep = ep;
  66022. +
  66023. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  66024. +
  66025. + dev->in_ep = ep;
  66026. + continue;
  66027. + }
  66028. +
  66029. + usb_ep_disable (ep);
  66030. + result = -EIO;
  66031. + }
  66032. + }
  66033. +
  66034. + }
  66035. +
  66036. + dev->config = number;
  66037. + return result;
  66038. +}
  66039. +
  66040. +/*-------------------------------------------------------------------------*/
  66041. +
  66042. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  66043. +{
  66044. + if (req->status || req->actual != req->length)
  66045. + DBG ((struct zero_dev *) ep->driver_data,
  66046. + "setup complete --> %d, %d/%d\n",
  66047. + req->status, req->actual, req->length);
  66048. +}
  66049. +
  66050. +/*
  66051. + * The setup() callback implements all the ep0 functionality that's
  66052. + * not handled lower down, in hardware or the hardware driver (like
  66053. + * device and endpoint feature flags, and their status). It's all
  66054. + * housekeeping for the gadget function we're implementing. Most of
  66055. + * the work is in config-specific setup.
  66056. + */
  66057. +static int
  66058. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  66059. +{
  66060. + struct zero_dev *dev = get_gadget_data (gadget);
  66061. + struct usb_request *req = dev->req;
  66062. + int value = -EOPNOTSUPP;
  66063. +
  66064. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  66065. + * but config change events will reconfigure hardware.
  66066. + */
  66067. + req->zero = 0;
  66068. + switch (ctrl->bRequest) {
  66069. +
  66070. + case USB_REQ_GET_DESCRIPTOR:
  66071. +
  66072. + switch (ctrl->wValue >> 8) {
  66073. +
  66074. + case USB_DT_DEVICE:
  66075. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  66076. + memcpy (req->buf, &device_desc, value);
  66077. + break;
  66078. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  66079. + case USB_DT_DEVICE_QUALIFIER:
  66080. + if (!gadget->is_dualspeed)
  66081. + break;
  66082. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  66083. + memcpy (req->buf, &dev_qualifier, value);
  66084. + break;
  66085. +
  66086. + case USB_DT_OTHER_SPEED_CONFIG:
  66087. + if (!gadget->is_dualspeed)
  66088. + break;
  66089. + // FALLTHROUGH
  66090. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  66091. + case USB_DT_CONFIG:
  66092. + value = config_buf (gadget, req->buf,
  66093. + ctrl->wValue >> 8,
  66094. + ctrl->wValue & 0xff);
  66095. + if (value >= 0)
  66096. + value = min (ctrl->wLength, (u16) value);
  66097. + break;
  66098. +
  66099. + case USB_DT_STRING:
  66100. + /* wIndex == language code.
  66101. + * this driver only handles one language, you can
  66102. + * add string tables for other languages, using
  66103. + * any UTF-8 characters
  66104. + */
  66105. + value = usb_gadget_get_string (&stringtab,
  66106. + ctrl->wValue & 0xff, req->buf);
  66107. + if (value >= 0) {
  66108. + value = min (ctrl->wLength, (u16) value);
  66109. + }
  66110. + break;
  66111. + }
  66112. + break;
  66113. +
  66114. + /* currently two configs, two speeds */
  66115. + case USB_REQ_SET_CONFIGURATION:
  66116. + if (ctrl->bRequestType != 0)
  66117. + goto unknown;
  66118. +
  66119. + spin_lock (&dev->lock);
  66120. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  66121. + spin_unlock (&dev->lock);
  66122. + break;
  66123. + case USB_REQ_GET_CONFIGURATION:
  66124. + if (ctrl->bRequestType != USB_DIR_IN)
  66125. + goto unknown;
  66126. + *(u8 *)req->buf = dev->config;
  66127. + value = min (ctrl->wLength, (u16) 1);
  66128. + break;
  66129. +
  66130. + /* until we add altsetting support, or other interfaces,
  66131. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  66132. + * and already killed pending endpoint I/O.
  66133. + */
  66134. + case USB_REQ_SET_INTERFACE:
  66135. +
  66136. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  66137. + goto unknown;
  66138. + spin_lock (&dev->lock);
  66139. + if (dev->config) {
  66140. + u8 config = dev->config;
  66141. +
  66142. + /* resets interface configuration, forgets about
  66143. + * previous transaction state (queued bufs, etc)
  66144. + * and re-inits endpoint state (toggle etc)
  66145. + * no response queued, just zero status == success.
  66146. + * if we had more than one interface we couldn't
  66147. + * use this "reset the config" shortcut.
  66148. + */
  66149. + zero_reset_config (dev);
  66150. + zero_set_config (dev, config, GFP_ATOMIC);
  66151. + value = 0;
  66152. + }
  66153. + spin_unlock (&dev->lock);
  66154. + break;
  66155. + case USB_REQ_GET_INTERFACE:
  66156. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  66157. + value = ctrl->wLength;
  66158. + break;
  66159. + }
  66160. + else {
  66161. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  66162. + goto unknown;
  66163. + if (!dev->config)
  66164. + break;
  66165. + if (ctrl->wIndex != 0) {
  66166. + value = -EDOM;
  66167. + break;
  66168. + }
  66169. + *(u8 *)req->buf = 0;
  66170. + value = min (ctrl->wLength, (u16) 1);
  66171. + }
  66172. + break;
  66173. +
  66174. + /*
  66175. + * These are the same vendor-specific requests supported by
  66176. + * Intel's USB 2.0 compliance test devices. We exceed that
  66177. + * device spec by allowing multiple-packet requests.
  66178. + */
  66179. + case 0x5b: /* control WRITE test -- fill the buffer */
  66180. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  66181. + goto unknown;
  66182. + if (ctrl->wValue || ctrl->wIndex)
  66183. + break;
  66184. + /* just read that many bytes into the buffer */
  66185. + if (ctrl->wLength > USB_BUFSIZ)
  66186. + break;
  66187. + value = ctrl->wLength;
  66188. + break;
  66189. + case 0x5c: /* control READ test -- return the buffer */
  66190. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  66191. + goto unknown;
  66192. + if (ctrl->wValue || ctrl->wIndex)
  66193. + break;
  66194. + /* expect those bytes are still in the buffer; send back */
  66195. + if (ctrl->wLength > USB_BUFSIZ
  66196. + || ctrl->wLength != req->length)
  66197. + break;
  66198. + value = ctrl->wLength;
  66199. + break;
  66200. +
  66201. + case 0x01: // SET_CUR
  66202. + case 0x02:
  66203. + case 0x03:
  66204. + case 0x04:
  66205. + case 0x05:
  66206. + value = ctrl->wLength;
  66207. + break;
  66208. + case 0x81:
  66209. + switch (ctrl->wValue) {
  66210. + case 0x0201:
  66211. + case 0x0202:
  66212. + ((u8*)req->buf)[0] = 0x00;
  66213. + ((u8*)req->buf)[1] = 0xe3;
  66214. + break;
  66215. + case 0x0300:
  66216. + case 0x0500:
  66217. + ((u8*)req->buf)[0] = 0x00;
  66218. + break;
  66219. + }
  66220. + //((u8*)req->buf)[0] = 0x81;
  66221. + //((u8*)req->buf)[1] = 0x81;
  66222. + value = ctrl->wLength;
  66223. + break;
  66224. + case 0x82:
  66225. + switch (ctrl->wValue) {
  66226. + case 0x0201:
  66227. + case 0x0202:
  66228. + ((u8*)req->buf)[0] = 0x00;
  66229. + ((u8*)req->buf)[1] = 0xc3;
  66230. + break;
  66231. + case 0x0300:
  66232. + case 0x0500:
  66233. + ((u8*)req->buf)[0] = 0x00;
  66234. + break;
  66235. + }
  66236. + //((u8*)req->buf)[0] = 0x82;
  66237. + //((u8*)req->buf)[1] = 0x82;
  66238. + value = ctrl->wLength;
  66239. + break;
  66240. + case 0x83:
  66241. + switch (ctrl->wValue) {
  66242. + case 0x0201:
  66243. + case 0x0202:
  66244. + ((u8*)req->buf)[0] = 0x00;
  66245. + ((u8*)req->buf)[1] = 0x00;
  66246. + break;
  66247. + case 0x0300:
  66248. + ((u8*)req->buf)[0] = 0x60;
  66249. + break;
  66250. + case 0x0500:
  66251. + ((u8*)req->buf)[0] = 0x18;
  66252. + break;
  66253. + }
  66254. + //((u8*)req->buf)[0] = 0x83;
  66255. + //((u8*)req->buf)[1] = 0x83;
  66256. + value = ctrl->wLength;
  66257. + break;
  66258. + case 0x84:
  66259. + switch (ctrl->wValue) {
  66260. + case 0x0201:
  66261. + case 0x0202:
  66262. + ((u8*)req->buf)[0] = 0x00;
  66263. + ((u8*)req->buf)[1] = 0x01;
  66264. + break;
  66265. + case 0x0300:
  66266. + case 0x0500:
  66267. + ((u8*)req->buf)[0] = 0x08;
  66268. + break;
  66269. + }
  66270. + //((u8*)req->buf)[0] = 0x84;
  66271. + //((u8*)req->buf)[1] = 0x84;
  66272. + value = ctrl->wLength;
  66273. + break;
  66274. + case 0x85:
  66275. + ((u8*)req->buf)[0] = 0x85;
  66276. + ((u8*)req->buf)[1] = 0x85;
  66277. + value = ctrl->wLength;
  66278. + break;
  66279. +
  66280. +
  66281. + default:
  66282. +unknown:
  66283. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  66284. + ctrl->bRequestType, ctrl->bRequest,
  66285. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  66286. + }
  66287. +
  66288. + /* respond with data transfer before status phase? */
  66289. + if (value >= 0) {
  66290. + req->length = value;
  66291. + req->zero = value < ctrl->wLength
  66292. + && (value % gadget->ep0->maxpacket) == 0;
  66293. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  66294. + if (value < 0) {
  66295. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  66296. + req->status = 0;
  66297. + zero_setup_complete (gadget->ep0, req);
  66298. + }
  66299. + }
  66300. +
  66301. + /* device either stalls (value < 0) or reports success */
  66302. + return value;
  66303. +}
  66304. +
  66305. +static void
  66306. +zero_disconnect (struct usb_gadget *gadget)
  66307. +{
  66308. + struct zero_dev *dev = get_gadget_data (gadget);
  66309. + unsigned long flags;
  66310. +
  66311. + spin_lock_irqsave (&dev->lock, flags);
  66312. + zero_reset_config (dev);
  66313. +
  66314. + /* a more significant application might have some non-usb
  66315. + * activities to quiesce here, saving resources like power
  66316. + * or pushing the notification up a network stack.
  66317. + */
  66318. + spin_unlock_irqrestore (&dev->lock, flags);
  66319. +
  66320. + /* next we may get setup() calls to enumerate new connections;
  66321. + * or an unbind() during shutdown (including removing module).
  66322. + */
  66323. +}
  66324. +
  66325. +static void
  66326. +zero_autoresume (unsigned long _dev)
  66327. +{
  66328. + struct zero_dev *dev = (struct zero_dev *) _dev;
  66329. + int status;
  66330. +
  66331. + /* normally the host would be woken up for something
  66332. + * more significant than just a timer firing...
  66333. + */
  66334. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  66335. + status = usb_gadget_wakeup (dev->gadget);
  66336. + DBG (dev, "wakeup --> %d\n", status);
  66337. + }
  66338. +}
  66339. +
  66340. +/*-------------------------------------------------------------------------*/
  66341. +
  66342. +static void
  66343. +zero_unbind (struct usb_gadget *gadget)
  66344. +{
  66345. + struct zero_dev *dev = get_gadget_data (gadget);
  66346. +
  66347. + DBG (dev, "unbind\n");
  66348. +
  66349. + /* we've already been disconnected ... no i/o is active */
  66350. + if (dev->req)
  66351. + free_ep_req (gadget->ep0, dev->req);
  66352. + del_timer_sync (&dev->resume);
  66353. + kfree (dev);
  66354. + set_gadget_data (gadget, NULL);
  66355. +}
  66356. +
  66357. +static int
  66358. +zero_bind (struct usb_gadget *gadget)
  66359. +{
  66360. + struct zero_dev *dev;
  66361. + //struct usb_ep *ep;
  66362. +
  66363. + printk("binding\n");
  66364. + /*
  66365. + * DRIVER POLICY CHOICE: you may want to do this differently.
  66366. + * One thing to avoid is reusing a bcdDevice revision code
  66367. + * with different host-visible configurations or behavior
  66368. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  66369. + */
  66370. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  66371. +
  66372. +
  66373. + /* ok, we made sense of the hardware ... */
  66374. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  66375. + if (!dev)
  66376. + return -ENOMEM;
  66377. + memset (dev, 0, sizeof *dev);
  66378. + spin_lock_init (&dev->lock);
  66379. + dev->gadget = gadget;
  66380. + set_gadget_data (gadget, dev);
  66381. +
  66382. + /* preallocate control response and buffer */
  66383. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  66384. + if (!dev->req)
  66385. + goto enomem;
  66386. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  66387. + &dev->req->dma, GFP_KERNEL);
  66388. + if (!dev->req->buf)
  66389. + goto enomem;
  66390. +
  66391. + dev->req->complete = zero_setup_complete;
  66392. +
  66393. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  66394. +
  66395. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  66396. + /* assume ep0 uses the same value for both speeds ... */
  66397. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  66398. +
  66399. + /* and that all endpoints are dual-speed */
  66400. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  66401. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  66402. +#endif
  66403. +
  66404. + usb_gadget_set_selfpowered (gadget);
  66405. +
  66406. + init_timer (&dev->resume);
  66407. + dev->resume.function = zero_autoresume;
  66408. + dev->resume.data = (unsigned long) dev;
  66409. +
  66410. + gadget->ep0->driver_data = dev;
  66411. +
  66412. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  66413. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  66414. + EP_OUT_NAME, EP_IN_NAME);
  66415. +
  66416. + snprintf (manufacturer, sizeof manufacturer,
  66417. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  66418. + gadget->name);
  66419. +
  66420. + return 0;
  66421. +
  66422. +enomem:
  66423. + zero_unbind (gadget);
  66424. + return -ENOMEM;
  66425. +}
  66426. +
  66427. +/*-------------------------------------------------------------------------*/
  66428. +
  66429. +static void
  66430. +zero_suspend (struct usb_gadget *gadget)
  66431. +{
  66432. + struct zero_dev *dev = get_gadget_data (gadget);
  66433. +
  66434. + if (gadget->speed == USB_SPEED_UNKNOWN)
  66435. + return;
  66436. +
  66437. + if (autoresume) {
  66438. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  66439. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  66440. + } else
  66441. + DBG (dev, "suspend\n");
  66442. +}
  66443. +
  66444. +static void
  66445. +zero_resume (struct usb_gadget *gadget)
  66446. +{
  66447. + struct zero_dev *dev = get_gadget_data (gadget);
  66448. +
  66449. + DBG (dev, "resume\n");
  66450. + del_timer (&dev->resume);
  66451. +}
  66452. +
  66453. +
  66454. +/*-------------------------------------------------------------------------*/
  66455. +
  66456. +static struct usb_gadget_driver zero_driver = {
  66457. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  66458. + .speed = USB_SPEED_HIGH,
  66459. +#else
  66460. + .speed = USB_SPEED_FULL,
  66461. +#endif
  66462. + .function = (char *) longname,
  66463. + .bind = zero_bind,
  66464. + .unbind = zero_unbind,
  66465. +
  66466. + .setup = zero_setup,
  66467. + .disconnect = zero_disconnect,
  66468. +
  66469. + .suspend = zero_suspend,
  66470. + .resume = zero_resume,
  66471. +
  66472. + .driver = {
  66473. + .name = (char *) shortname,
  66474. + // .shutdown = ...
  66475. + // .suspend = ...
  66476. + // .resume = ...
  66477. + },
  66478. +};
  66479. +
  66480. +MODULE_AUTHOR ("David Brownell");
  66481. +MODULE_LICENSE ("Dual BSD/GPL");
  66482. +
  66483. +static struct proc_dir_entry *pdir, *pfile;
  66484. +
  66485. +static int isoc_read_data (char *page, char **start,
  66486. + off_t off, int count,
  66487. + int *eof, void *data)
  66488. +{
  66489. + int i;
  66490. + static int c = 0;
  66491. + static int done = 0;
  66492. + static int s = 0;
  66493. +
  66494. +/*
  66495. + printk ("\ncount: %d\n", count);
  66496. + printk ("rbuf_start: %d\n", rbuf_start);
  66497. + printk ("rbuf_len: %d\n", rbuf_len);
  66498. + printk ("off: %d\n", off);
  66499. + printk ("start: %p\n\n", *start);
  66500. +*/
  66501. + if (done) {
  66502. + c = 0;
  66503. + done = 0;
  66504. + *eof = 1;
  66505. + return 0;
  66506. + }
  66507. +
  66508. + if (c == 0) {
  66509. + if (rbuf_len == RBUF_LEN)
  66510. + s = rbuf_start;
  66511. + else s = 0;
  66512. + }
  66513. +
  66514. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  66515. + page[i] = rbuf[(c+s) % RBUF_LEN];
  66516. + }
  66517. + *start = page;
  66518. +
  66519. + if (c >= rbuf_len) {
  66520. + *eof = 1;
  66521. + done = 1;
  66522. + }
  66523. +
  66524. +
  66525. + return i;
  66526. +}
  66527. +
  66528. +static int __init init (void)
  66529. +{
  66530. +
  66531. + int retval = 0;
  66532. +
  66533. + pdir = proc_mkdir("isoc_test", NULL);
  66534. + if(pdir == NULL) {
  66535. + retval = -ENOMEM;
  66536. + printk("Error creating dir\n");
  66537. + goto done;
  66538. + }
  66539. + pdir->owner = THIS_MODULE;
  66540. +
  66541. + pfile = create_proc_read_entry("isoc_data",
  66542. + 0444, pdir,
  66543. + isoc_read_data,
  66544. + NULL);
  66545. + if (pfile == NULL) {
  66546. + retval = -ENOMEM;
  66547. + printk("Error creating file\n");
  66548. + goto no_file;
  66549. + }
  66550. + pfile->owner = THIS_MODULE;
  66551. +
  66552. + return usb_gadget_register_driver (&zero_driver);
  66553. +
  66554. + no_file:
  66555. + remove_proc_entry("isoc_data", NULL);
  66556. + done:
  66557. + return retval;
  66558. +}
  66559. +module_init (init);
  66560. +
  66561. +static void __exit cleanup (void)
  66562. +{
  66563. +
  66564. + usb_gadget_unregister_driver (&zero_driver);
  66565. +
  66566. + remove_proc_entry("isoc_data", pdir);
  66567. + remove_proc_entry("isoc_test", NULL);
  66568. +}
  66569. +module_exit (cleanup);
  66570. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  66571. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  66572. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2015-03-09 10:39:33.214893718 +0100
  66573. @@ -0,0 +1,142 @@
  66574. +/* ==========================================================================
  66575. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66576. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66577. + * otherwise expressly agreed to in writing between Synopsys and you.
  66578. + *
  66579. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66580. + * any End User Software License Agreement or Agreement for Licensed Product
  66581. + * with Synopsys or any supplement thereto. You are permitted to use and
  66582. + * redistribute this Software in source and binary forms, with or without
  66583. + * modification, provided that redistributions of source code must retain this
  66584. + * notice. You may not view, use, disclose, copy or distribute this file or
  66585. + * any information contained herein except pursuant to this license grant from
  66586. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66587. + * below, then you are not authorized to use the Software.
  66588. + *
  66589. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66590. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66591. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66592. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66593. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66594. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66595. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66596. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66597. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66598. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66599. + * DAMAGE.
  66600. + * ========================================================================== */
  66601. +
  66602. +#if !defined(__DWC_CFI_COMMON_H__)
  66603. +#define __DWC_CFI_COMMON_H__
  66604. +
  66605. +//#include <linux/types.h>
  66606. +
  66607. +/**
  66608. + * @file
  66609. + *
  66610. + * This file contains the CFI specific common constants, interfaces
  66611. + * (functions and macros) and structures for Linux. No PCD specific
  66612. + * data structure or definition is to be included in this file.
  66613. + *
  66614. + */
  66615. +
  66616. +/** This is a request for all Core Features */
  66617. +#define VEN_CORE_GET_FEATURES 0xB1
  66618. +
  66619. +/** This is a request to get the value of a specific Core Feature */
  66620. +#define VEN_CORE_GET_FEATURE 0xB2
  66621. +
  66622. +/** This command allows the host to set the value of a specific Core Feature */
  66623. +#define VEN_CORE_SET_FEATURE 0xB3
  66624. +
  66625. +/** This command allows the host to set the default values of
  66626. + * either all or any specific Core Feature
  66627. + */
  66628. +#define VEN_CORE_RESET_FEATURES 0xB4
  66629. +
  66630. +/** This command forces the PCD to write the deferred values of a Core Features */
  66631. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  66632. +
  66633. +/** This request reads a DWORD value from a register at the specified offset */
  66634. +#define VEN_CORE_READ_REGISTER 0xB6
  66635. +
  66636. +/** This request writes a DWORD value into a register at the specified offset */
  66637. +#define VEN_CORE_WRITE_REGISTER 0xB7
  66638. +
  66639. +/** This structure is the header of the Core Features dataset returned to
  66640. + * the Host
  66641. + */
  66642. +struct cfi_all_features_header {
  66643. +/** The features header structure length is */
  66644. +#define CFI_ALL_FEATURES_HDR_LEN 8
  66645. + /**
  66646. + * The total length of the features dataset returned to the Host
  66647. + */
  66648. + uint16_t wTotalLen;
  66649. +
  66650. + /**
  66651. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  66652. + * This field identifies the version of the CFI Specification with which
  66653. + * the device is compliant.
  66654. + */
  66655. + uint16_t wVersion;
  66656. +
  66657. + /** The ID of the Core */
  66658. + uint16_t wCoreID;
  66659. +#define CFI_CORE_ID_UDC 1
  66660. +#define CFI_CORE_ID_OTG 2
  66661. +#define CFI_CORE_ID_WUDEV 3
  66662. +
  66663. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  66664. + uint16_t wNumFeatures;
  66665. +} UPACKED;
  66666. +
  66667. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  66668. +
  66669. +/** This structure is a header of the Core Feature descriptor dataset returned to
  66670. + * the Host after the VEN_CORE_GET_FEATURES request
  66671. + */
  66672. +struct cfi_feature_desc_header {
  66673. +#define CFI_FEATURE_DESC_HDR_LEN 8
  66674. +
  66675. + /** The feature ID */
  66676. + uint16_t wFeatureID;
  66677. +
  66678. + /** Length of this feature descriptor in bytes - including the
  66679. + * length of the feature name string
  66680. + */
  66681. + uint16_t wLength;
  66682. +
  66683. + /** The data length of this feature in bytes */
  66684. + uint16_t wDataLength;
  66685. +
  66686. + /**
  66687. + * Attributes of this features
  66688. + * D0: Access rights
  66689. + * 0 - Read/Write
  66690. + * 1 - Read only
  66691. + */
  66692. + uint8_t bmAttributes;
  66693. +#define CFI_FEATURE_ATTR_RO 1
  66694. +#define CFI_FEATURE_ATTR_RW 0
  66695. +
  66696. + /** Length of the feature name in bytes */
  66697. + uint8_t bNameLen;
  66698. +
  66699. + /** The feature name buffer */
  66700. + //uint8_t *name;
  66701. +} UPACKED;
  66702. +
  66703. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  66704. +
  66705. +/**
  66706. + * This structure describes a NULL terminated string referenced by its id field.
  66707. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  66708. + */
  66709. +struct cfi_string {
  66710. + uint16_t id;
  66711. + const uint8_t *s;
  66712. +};
  66713. +typedef struct cfi_string cfi_string_t;
  66714. +
  66715. +#endif
  66716. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  66717. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  66718. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2015-03-09 10:39:33.214893718 +0100
  66719. @@ -0,0 +1,854 @@
  66720. +/* ==========================================================================
  66721. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  66722. + * $Revision: #12 $
  66723. + * $Date: 2011/10/26 $
  66724. + * $Change: 1873028 $
  66725. + *
  66726. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66727. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66728. + * otherwise expressly agreed to in writing between Synopsys and you.
  66729. + *
  66730. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66731. + * any End User Software License Agreement or Agreement for Licensed Product
  66732. + * with Synopsys or any supplement thereto. You are permitted to use and
  66733. + * redistribute this Software in source and binary forms, with or without
  66734. + * modification, provided that redistributions of source code must retain this
  66735. + * notice. You may not view, use, disclose, copy or distribute this file or
  66736. + * any information contained herein except pursuant to this license grant from
  66737. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66738. + * below, then you are not authorized to use the Software.
  66739. + *
  66740. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66741. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66742. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66743. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66744. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66745. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66746. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66747. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66748. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66749. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66750. + * DAMAGE.
  66751. + * ========================================================================== */
  66752. +
  66753. +#include "dwc_os.h"
  66754. +#include "dwc_otg_regs.h"
  66755. +#include "dwc_otg_cil.h"
  66756. +#include "dwc_otg_adp.h"
  66757. +
  66758. +/** @file
  66759. + *
  66760. + * This file contains the most of the Attach Detect Protocol implementation for
  66761. + * the driver to support OTG Rev2.0.
  66762. + *
  66763. + */
  66764. +
  66765. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  66766. +{
  66767. + adpctl_data_t adpctl;
  66768. +
  66769. + adpctl.d32 = value;
  66770. + adpctl.b.ar = 0x2;
  66771. +
  66772. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  66773. +
  66774. + while (adpctl.b.ar) {
  66775. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  66776. + }
  66777. +
  66778. +}
  66779. +
  66780. +/**
  66781. + * Function is called to read ADP registers
  66782. + */
  66783. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  66784. +{
  66785. + adpctl_data_t adpctl;
  66786. +
  66787. + adpctl.d32 = 0;
  66788. + adpctl.b.ar = 0x1;
  66789. +
  66790. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  66791. +
  66792. + while (adpctl.b.ar) {
  66793. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  66794. + }
  66795. +
  66796. + return adpctl.d32;
  66797. +}
  66798. +
  66799. +/**
  66800. + * Function is called to read ADPCTL register and filter Write-clear bits
  66801. + */
  66802. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  66803. +{
  66804. + adpctl_data_t adpctl;
  66805. +
  66806. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  66807. + adpctl.b.adp_tmout_int = 0;
  66808. + adpctl.b.adp_prb_int = 0;
  66809. + adpctl.b.adp_tmout_int = 0;
  66810. +
  66811. + return adpctl.d32;
  66812. +}
  66813. +
  66814. +/**
  66815. + * Function is called to write ADP registers
  66816. + */
  66817. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  66818. + uint32_t set)
  66819. +{
  66820. + dwc_otg_adp_write_reg(core_if,
  66821. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  66822. +}
  66823. +
  66824. +static void adp_sense_timeout(void *ptr)
  66825. +{
  66826. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  66827. + core_if->adp.sense_timer_started = 0;
  66828. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  66829. + if (core_if->adp_enable) {
  66830. + dwc_otg_adp_sense_stop(core_if);
  66831. + dwc_otg_adp_probe_start(core_if);
  66832. + }
  66833. +}
  66834. +
  66835. +/**
  66836. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  66837. + */
  66838. +static void adp_vbuson_timeout(void *ptr)
  66839. +{
  66840. + gpwrdn_data_t gpwrdn;
  66841. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  66842. + hprt0_data_t hprt0 = {.d32 = 0 };
  66843. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  66844. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  66845. + if (core_if) {
  66846. + core_if->adp.vbuson_timer_started = 0;
  66847. + /* Turn off vbus */
  66848. + hprt0.b.prtpwr = 1;
  66849. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  66850. + gpwrdn.d32 = 0;
  66851. +
  66852. + /* Power off the core */
  66853. + if (core_if->power_down == 2) {
  66854. + /* Enable Wakeup Logic */
  66855. +// gpwrdn.b.wkupactiv = 1;
  66856. + gpwrdn.b.pmuactv = 0;
  66857. + gpwrdn.b.pwrdnrstn = 1;
  66858. + gpwrdn.b.pwrdnclmp = 1;
  66859. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  66860. + gpwrdn.d32);
  66861. +
  66862. + /* Suspend the Phy Clock */
  66863. + pcgcctl.b.stoppclk = 1;
  66864. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  66865. +
  66866. + /* Switch on VDD */
  66867. +// gpwrdn.b.wkupactiv = 1;
  66868. + gpwrdn.b.pmuactv = 1;
  66869. + gpwrdn.b.pwrdnrstn = 1;
  66870. + gpwrdn.b.pwrdnclmp = 1;
  66871. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  66872. + gpwrdn.d32);
  66873. + } else {
  66874. + /* Enable Power Down Logic */
  66875. + gpwrdn.b.pmuintsel = 1;
  66876. + gpwrdn.b.pmuactv = 1;
  66877. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66878. + }
  66879. +
  66880. + /* Power off the core */
  66881. + if (core_if->power_down == 2) {
  66882. + gpwrdn.d32 = 0;
  66883. + gpwrdn.b.pwrdnswtch = 1;
  66884. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  66885. + gpwrdn.d32, 0);
  66886. + }
  66887. +
  66888. + /* Unmask SRP detected interrupt from Power Down Logic */
  66889. + gpwrdn.d32 = 0;
  66890. + gpwrdn.b.srp_det_msk = 1;
  66891. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  66892. +
  66893. + dwc_otg_adp_probe_start(core_if);
  66894. + dwc_otg_dump_global_registers(core_if);
  66895. + dwc_otg_dump_host_registers(core_if);
  66896. + }
  66897. +
  66898. +}
  66899. +
  66900. +/**
  66901. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  66902. + * not asserted within 1.1 seconds.
  66903. + *
  66904. + * @param core_if the pointer to core_if strucure.
  66905. + */
  66906. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  66907. +{
  66908. + core_if->adp.vbuson_timer_started = 1;
  66909. + if (core_if->adp.vbuson_timer)
  66910. + {
  66911. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  66912. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  66913. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  66914. + } else {
  66915. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  66916. + }
  66917. +}
  66918. +
  66919. +#if 0
  66920. +/**
  66921. + * Masks all DWC OTG core interrupts
  66922. + *
  66923. + */
  66924. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  66925. +{
  66926. + int i;
  66927. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  66928. +
  66929. + /* Mask Host Interrupts */
  66930. +
  66931. + /* Clear and disable HCINTs */
  66932. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  66933. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  66934. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  66935. +
  66936. + }
  66937. +
  66938. + /* Clear and disable HAINT */
  66939. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  66940. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  66941. +
  66942. + /* Mask Device Interrupts */
  66943. + if (!core_if->multiproc_int_enable) {
  66944. + /* Clear and disable IN Endpoint interrupts */
  66945. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  66946. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  66947. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  66948. + diepint, 0xFFFFFFFF);
  66949. + }
  66950. +
  66951. + /* Clear and disable OUT Endpoint interrupts */
  66952. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  66953. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  66954. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  66955. + doepint, 0xFFFFFFFF);
  66956. + }
  66957. +
  66958. + /* Clear and disable DAINT */
  66959. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  66960. + 0xFFFFFFFF);
  66961. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  66962. + } else {
  66963. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  66964. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  66965. + diepeachintmsk[i], 0);
  66966. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  66967. + diepint, 0xFFFFFFFF);
  66968. + }
  66969. +
  66970. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  66971. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  66972. + doepeachintmsk[i], 0);
  66973. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  66974. + doepint, 0xFFFFFFFF);
  66975. + }
  66976. +
  66977. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  66978. + 0);
  66979. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  66980. + 0xFFFFFFFF);
  66981. +
  66982. + }
  66983. +
  66984. + /* Disable interrupts */
  66985. + ahbcfg.b.glblintrmsk = 1;
  66986. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  66987. +
  66988. + /* Disable all interrupts. */
  66989. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  66990. +
  66991. + /* Clear any pending interrupts */
  66992. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  66993. +
  66994. + /* Clear any pending OTG Interrupts */
  66995. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  66996. +}
  66997. +
  66998. +/**
  66999. + * Unmask Port Connection Detected interrupt
  67000. + *
  67001. + */
  67002. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  67003. +{
  67004. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  67005. +
  67006. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  67007. +}
  67008. +#endif
  67009. +
  67010. +/**
  67011. + * Starts the ADP Probing
  67012. + *
  67013. + * @param core_if the pointer to core_if structure.
  67014. + */
  67015. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  67016. +{
  67017. +
  67018. + adpctl_data_t adpctl = {.d32 = 0};
  67019. + gpwrdn_data_t gpwrdn;
  67020. +#if 0
  67021. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  67022. + .b.adp_sns_int = 1, b.adp_tmout_int};
  67023. +#endif
  67024. + dwc_otg_disable_global_interrupts(core_if);
  67025. + DWC_PRINTF("ADP Probe Start\n");
  67026. + core_if->adp.probe_enabled = 1;
  67027. +
  67028. + adpctl.b.adpres = 1;
  67029. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67030. +
  67031. + while (adpctl.b.adpres) {
  67032. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67033. + }
  67034. +
  67035. + adpctl.d32 = 0;
  67036. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  67037. +
  67038. + /* In Host mode unmask SRP detected interrupt */
  67039. + gpwrdn.d32 = 0;
  67040. + gpwrdn.b.sts_chngint_msk = 1;
  67041. + if (!gpwrdn.b.idsts) {
  67042. + gpwrdn.b.srp_det_msk = 1;
  67043. + }
  67044. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  67045. +
  67046. + adpctl.b.adp_tmout_int_msk = 1;
  67047. + adpctl.b.adp_prb_int_msk = 1;
  67048. + adpctl.b.prb_dschg = 1;
  67049. + adpctl.b.prb_delta = 1;
  67050. + adpctl.b.prb_per = 1;
  67051. + adpctl.b.adpen = 1;
  67052. + adpctl.b.enaprb = 1;
  67053. +
  67054. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67055. + DWC_PRINTF("ADP Probe Finish\n");
  67056. + return 0;
  67057. +}
  67058. +
  67059. +/**
  67060. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  67061. + * within 3 seconds.
  67062. + *
  67063. + * @param core_if the pointer to core_if strucure.
  67064. + */
  67065. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  67066. +{
  67067. + core_if->adp.sense_timer_started = 1;
  67068. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  67069. +}
  67070. +
  67071. +/**
  67072. + * Starts the ADP Sense
  67073. + *
  67074. + * @param core_if the pointer to core_if strucure.
  67075. + */
  67076. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  67077. +{
  67078. + adpctl_data_t adpctl;
  67079. +
  67080. + DWC_PRINTF("ADP Sense Start\n");
  67081. +
  67082. + /* Unmask ADP sense interrupt and mask all other from the core */
  67083. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  67084. + adpctl.b.adp_sns_int_msk = 1;
  67085. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67086. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  67087. +
  67088. + /* Set ADP reset bit*/
  67089. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  67090. + adpctl.b.adpres = 1;
  67091. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67092. +
  67093. + while (adpctl.b.adpres) {
  67094. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67095. + }
  67096. +
  67097. + adpctl.b.adpres = 0;
  67098. + adpctl.b.adpen = 1;
  67099. + adpctl.b.enasns = 1;
  67100. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67101. +
  67102. + dwc_otg_adp_sense_timer_start(core_if);
  67103. +
  67104. + return 0;
  67105. +}
  67106. +
  67107. +/**
  67108. + * Stops the ADP Probing
  67109. + *
  67110. + * @param core_if the pointer to core_if strucure.
  67111. + */
  67112. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  67113. +{
  67114. +
  67115. + adpctl_data_t adpctl;
  67116. + DWC_PRINTF("Stop ADP probe\n");
  67117. + core_if->adp.probe_enabled = 0;
  67118. + core_if->adp.probe_counter = 0;
  67119. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67120. +
  67121. + adpctl.b.adpen = 0;
  67122. + adpctl.b.adp_prb_int = 1;
  67123. + adpctl.b.adp_tmout_int = 1;
  67124. + adpctl.b.adp_sns_int = 1;
  67125. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67126. +
  67127. + return 0;
  67128. +}
  67129. +
  67130. +/**
  67131. + * Stops the ADP Sensing
  67132. + *
  67133. + * @param core_if the pointer to core_if strucure.
  67134. + */
  67135. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  67136. +{
  67137. + adpctl_data_t adpctl;
  67138. +
  67139. + core_if->adp.sense_enabled = 0;
  67140. +
  67141. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  67142. + adpctl.b.enasns = 0;
  67143. + adpctl.b.adp_sns_int = 1;
  67144. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67145. +
  67146. + return 0;
  67147. +}
  67148. +
  67149. +/**
  67150. + * Called to turn on the VBUS after initial ADP probe in host mode.
  67151. + * If port power was already enabled in cil_hcd_start function then
  67152. + * only schedule a timer.
  67153. + *
  67154. + * @param core_if the pointer to core_if structure.
  67155. + */
  67156. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  67157. +{
  67158. + hprt0_data_t hprt0 = {.d32 = 0 };
  67159. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  67160. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  67161. +
  67162. + if (hprt0.b.prtpwr == 0) {
  67163. + hprt0.b.prtpwr = 1;
  67164. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  67165. + }
  67166. +
  67167. + dwc_otg_adp_vbuson_timer_start(core_if);
  67168. +}
  67169. +
  67170. +/**
  67171. + * Called right after driver is loaded
  67172. + * to perform initial actions for ADP
  67173. + *
  67174. + * @param core_if the pointer to core_if structure.
  67175. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  67176. + */
  67177. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  67178. +{
  67179. + gpwrdn_data_t gpwrdn;
  67180. +
  67181. + DWC_PRINTF("ADP Initial Start\n");
  67182. + core_if->adp.adp_started = 1;
  67183. +
  67184. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  67185. + dwc_otg_disable_global_interrupts(core_if);
  67186. + if (is_host) {
  67187. + DWC_PRINTF("HOST MODE\n");
  67188. + /* Enable Power Down Logic Interrupt*/
  67189. + gpwrdn.d32 = 0;
  67190. + gpwrdn.b.pmuintsel = 1;
  67191. + gpwrdn.b.pmuactv = 1;
  67192. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  67193. + /* Initialize first ADP probe to obtain Ramp Time value */
  67194. + core_if->adp.initial_probe = 1;
  67195. + dwc_otg_adp_probe_start(core_if);
  67196. + } else {
  67197. + gotgctl_data_t gotgctl;
  67198. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  67199. + DWC_PRINTF("DEVICE MODE\n");
  67200. + if (gotgctl.b.bsesvld == 0) {
  67201. + /* Enable Power Down Logic Interrupt*/
  67202. + gpwrdn.d32 = 0;
  67203. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  67204. + gpwrdn.b.pmuintsel = 1;
  67205. + gpwrdn.b.pmuactv = 1;
  67206. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  67207. + core_if->adp.initial_probe = 1;
  67208. + dwc_otg_adp_probe_start(core_if);
  67209. + } else {
  67210. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  67211. + core_if->op_state = B_PERIPHERAL;
  67212. + dwc_otg_core_init(core_if);
  67213. + dwc_otg_enable_global_interrupts(core_if);
  67214. + cil_pcd_start(core_if);
  67215. + dwc_otg_dump_global_registers(core_if);
  67216. + dwc_otg_dump_dev_registers(core_if);
  67217. + }
  67218. + }
  67219. +}
  67220. +
  67221. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  67222. +{
  67223. + core_if->adp.adp_started = 0;
  67224. + core_if->adp.initial_probe = 0;
  67225. + core_if->adp.probe_timer_values[0] = -1;
  67226. + core_if->adp.probe_timer_values[1] = -1;
  67227. + core_if->adp.probe_enabled = 0;
  67228. + core_if->adp.sense_enabled = 0;
  67229. + core_if->adp.sense_timer_started = 0;
  67230. + core_if->adp.vbuson_timer_started = 0;
  67231. + core_if->adp.probe_counter = 0;
  67232. + core_if->adp.gpwrdn = 0;
  67233. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  67234. + /* Initialize timers */
  67235. + core_if->adp.sense_timer =
  67236. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  67237. + core_if->adp.vbuson_timer =
  67238. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  67239. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  67240. + {
  67241. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  67242. + }
  67243. +}
  67244. +
  67245. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  67246. +{
  67247. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  67248. + gpwrdn.b.pmuintsel = 1;
  67249. + gpwrdn.b.pmuactv = 1;
  67250. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67251. +
  67252. + if (core_if->adp.probe_enabled)
  67253. + dwc_otg_adp_probe_stop(core_if);
  67254. + if (core_if->adp.sense_enabled)
  67255. + dwc_otg_adp_sense_stop(core_if);
  67256. + if (core_if->adp.sense_timer_started)
  67257. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  67258. + if (core_if->adp.vbuson_timer_started)
  67259. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  67260. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  67261. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  67262. +}
  67263. +
  67264. +/////////////////////////////////////////////////////////////////////
  67265. +////////////// ADP Interrupt Handlers ///////////////////////////////
  67266. +/////////////////////////////////////////////////////////////////////
  67267. +/**
  67268. + * This function sets Ramp Timer values
  67269. + */
  67270. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  67271. +{
  67272. + if (core_if->adp.probe_timer_values[0] == -1) {
  67273. + core_if->adp.probe_timer_values[0] = val;
  67274. + core_if->adp.probe_timer_values[1] = -1;
  67275. + return 1;
  67276. + } else {
  67277. + core_if->adp.probe_timer_values[1] =
  67278. + core_if->adp.probe_timer_values[0];
  67279. + core_if->adp.probe_timer_values[0] = val;
  67280. + return 0;
  67281. + }
  67282. +}
  67283. +
  67284. +/**
  67285. + * This function compares Ramp Timer values
  67286. + */
  67287. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  67288. +{
  67289. + uint32_t diff;
  67290. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  67291. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  67292. + else
  67293. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  67294. + if(diff < 2) {
  67295. + return 0;
  67296. + } else {
  67297. + return 1;
  67298. + }
  67299. +}
  67300. +
  67301. +/**
  67302. + * This function handles ADP Probe Interrupts
  67303. + */
  67304. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  67305. + uint32_t val)
  67306. +{
  67307. + adpctl_data_t adpctl = {.d32 = 0 };
  67308. + gpwrdn_data_t gpwrdn, temp;
  67309. + adpctl.d32 = val;
  67310. +
  67311. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  67312. + core_if->adp.probe_counter++;
  67313. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  67314. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  67315. + DWC_PRINTF("RTIM value is 0\n");
  67316. + goto exit;
  67317. + }
  67318. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  67319. + core_if->adp.initial_probe) {
  67320. + core_if->adp.initial_probe = 0;
  67321. + dwc_otg_adp_probe_stop(core_if);
  67322. + gpwrdn.d32 = 0;
  67323. + gpwrdn.b.pmuactv = 1;
  67324. + gpwrdn.b.pmuintsel = 1;
  67325. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67326. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  67327. +
  67328. + /* check which value is for device mode and which for Host mode */
  67329. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  67330. + /*
  67331. + * Turn on VBUS after initial ADP probe.
  67332. + */
  67333. + core_if->op_state = A_HOST;
  67334. + dwc_otg_enable_global_interrupts(core_if);
  67335. + DWC_SPINUNLOCK(core_if->lock);
  67336. + cil_hcd_start(core_if);
  67337. + dwc_otg_adp_turnon_vbus(core_if);
  67338. + DWC_SPINLOCK(core_if->lock);
  67339. + } else {
  67340. + /*
  67341. + * Initiate SRP after initial ADP probe.
  67342. + */
  67343. + dwc_otg_enable_global_interrupts(core_if);
  67344. + dwc_otg_initiate_srp(core_if);
  67345. + }
  67346. + } else if (core_if->adp.probe_counter > 2){
  67347. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  67348. + if (compare_timer_values(core_if)) {
  67349. + DWC_PRINTF("Difference in timer values !!! \n");
  67350. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  67351. + dwc_otg_adp_probe_stop(core_if);
  67352. +
  67353. + /* Power on the core */
  67354. + if (core_if->power_down == 2) {
  67355. + gpwrdn.b.pwrdnswtch = 1;
  67356. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67357. + gpwrdn, 0, gpwrdn.d32);
  67358. + }
  67359. +
  67360. + /* check which value is for device mode and which for Host mode */
  67361. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  67362. + /* Disable Interrupt from Power Down Logic */
  67363. + gpwrdn.d32 = 0;
  67364. + gpwrdn.b.pmuintsel = 1;
  67365. + gpwrdn.b.pmuactv = 1;
  67366. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67367. + gpwrdn, gpwrdn.d32, 0);
  67368. +
  67369. + /*
  67370. + * Initialize the Core for Host mode.
  67371. + */
  67372. + core_if->op_state = A_HOST;
  67373. + dwc_otg_core_init(core_if);
  67374. + dwc_otg_enable_global_interrupts(core_if);
  67375. + cil_hcd_start(core_if);
  67376. + } else {
  67377. + gotgctl_data_t gotgctl;
  67378. + /* Mask SRP detected interrupt from Power Down Logic */
  67379. + gpwrdn.d32 = 0;
  67380. + gpwrdn.b.srp_det_msk = 1;
  67381. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67382. + gpwrdn, gpwrdn.d32, 0);
  67383. +
  67384. + /* Disable Power Down Logic */
  67385. + gpwrdn.d32 = 0;
  67386. + gpwrdn.b.pmuintsel = 1;
  67387. + gpwrdn.b.pmuactv = 1;
  67388. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67389. + gpwrdn, gpwrdn.d32, 0);
  67390. +
  67391. + /*
  67392. + * Initialize the Core for Device mode.
  67393. + */
  67394. + core_if->op_state = B_PERIPHERAL;
  67395. + dwc_otg_core_init(core_if);
  67396. + dwc_otg_enable_global_interrupts(core_if);
  67397. + cil_pcd_start(core_if);
  67398. +
  67399. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  67400. + if (!gotgctl.b.bsesvld) {
  67401. + dwc_otg_initiate_srp(core_if);
  67402. + }
  67403. + }
  67404. + }
  67405. + if (core_if->power_down == 2) {
  67406. + if (gpwrdn.b.bsessvld) {
  67407. + /* Mask SRP detected interrupt from Power Down Logic */
  67408. + gpwrdn.d32 = 0;
  67409. + gpwrdn.b.srp_det_msk = 1;
  67410. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67411. +
  67412. + /* Disable Power Down Logic */
  67413. + gpwrdn.d32 = 0;
  67414. + gpwrdn.b.pmuactv = 1;
  67415. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  67416. +
  67417. + /*
  67418. + * Initialize the Core for Device mode.
  67419. + */
  67420. + core_if->op_state = B_PERIPHERAL;
  67421. + dwc_otg_core_init(core_if);
  67422. + dwc_otg_enable_global_interrupts(core_if);
  67423. + cil_pcd_start(core_if);
  67424. + }
  67425. + }
  67426. + }
  67427. +exit:
  67428. + /* Clear interrupt */
  67429. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67430. + adpctl.b.adp_prb_int = 1;
  67431. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67432. +
  67433. + return 0;
  67434. +}
  67435. +
  67436. +/**
  67437. + * This function hadles ADP Sense Interrupt
  67438. + */
  67439. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  67440. +{
  67441. + adpctl_data_t adpctl;
  67442. + /* Stop ADP Sense timer */
  67443. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  67444. +
  67445. + /* Restart ADP Sense timer */
  67446. + dwc_otg_adp_sense_timer_start(core_if);
  67447. +
  67448. + /* Clear interrupt */
  67449. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67450. + adpctl.b.adp_sns_int = 1;
  67451. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67452. +
  67453. + return 0;
  67454. +}
  67455. +
  67456. +/**
  67457. + * This function handles ADP Probe Interrupts
  67458. + */
  67459. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  67460. + uint32_t val)
  67461. +{
  67462. + adpctl_data_t adpctl = {.d32 = 0 };
  67463. + adpctl.d32 = val;
  67464. + set_timer_value(core_if, adpctl.b.rtim);
  67465. +
  67466. + /* Clear interrupt */
  67467. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67468. + adpctl.b.adp_tmout_int = 1;
  67469. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67470. +
  67471. + return 0;
  67472. +}
  67473. +
  67474. +/**
  67475. + * ADP Interrupt handler.
  67476. + *
  67477. + */
  67478. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  67479. +{
  67480. + int retval = 0;
  67481. + adpctl_data_t adpctl = {.d32 = 0};
  67482. +
  67483. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  67484. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  67485. +
  67486. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  67487. + DWC_PRINTF("ADP Sense interrupt\n");
  67488. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  67489. + }
  67490. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  67491. + DWC_PRINTF("ADP timeout interrupt\n");
  67492. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  67493. + }
  67494. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  67495. + DWC_PRINTF("ADP Probe interrupt\n");
  67496. + adpctl.b.adp_prb_int = 1;
  67497. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  67498. + }
  67499. +
  67500. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  67501. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  67502. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  67503. +
  67504. + return retval;
  67505. +}
  67506. +
  67507. +/**
  67508. + *
  67509. + * @param core_if Programming view of DWC_otg controller.
  67510. + */
  67511. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  67512. +{
  67513. +
  67514. +#ifndef DWC_HOST_ONLY
  67515. + hprt0_data_t hprt0;
  67516. + gpwrdn_data_t gpwrdn;
  67517. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  67518. +
  67519. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  67520. + /* check which value is for device mode and which for Host mode */
  67521. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  67522. + DWC_PRINTF("SRP: Host mode\n");
  67523. +
  67524. + if (core_if->adp_enable) {
  67525. + dwc_otg_adp_probe_stop(core_if);
  67526. +
  67527. + /* Power on the core */
  67528. + if (core_if->power_down == 2) {
  67529. + gpwrdn.b.pwrdnswtch = 1;
  67530. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67531. + gpwrdn, 0, gpwrdn.d32);
  67532. + }
  67533. +
  67534. + core_if->op_state = A_HOST;
  67535. + dwc_otg_core_init(core_if);
  67536. + dwc_otg_enable_global_interrupts(core_if);
  67537. + cil_hcd_start(core_if);
  67538. + }
  67539. +
  67540. + /* Turn on the port power bit. */
  67541. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  67542. + hprt0.b.prtpwr = 1;
  67543. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  67544. +
  67545. + /* Start the Connection timer. So a message can be displayed
  67546. + * if connect does not occur within 10 seconds. */
  67547. + cil_hcd_session_start(core_if);
  67548. + } else {
  67549. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  67550. + if (core_if->adp_enable) {
  67551. + dwc_otg_adp_probe_stop(core_if);
  67552. +
  67553. + /* Power on the core */
  67554. + if (core_if->power_down == 2) {
  67555. + gpwrdn.b.pwrdnswtch = 1;
  67556. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  67557. + gpwrdn, 0, gpwrdn.d32);
  67558. + }
  67559. +
  67560. + gpwrdn.d32 = 0;
  67561. + gpwrdn.b.pmuactv = 0;
  67562. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  67563. + gpwrdn.d32);
  67564. +
  67565. + core_if->op_state = B_PERIPHERAL;
  67566. + dwc_otg_core_init(core_if);
  67567. + dwc_otg_enable_global_interrupts(core_if);
  67568. + cil_pcd_start(core_if);
  67569. + }
  67570. + }
  67571. +#endif
  67572. + return 1;
  67573. +}
  67574. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  67575. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  67576. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2015-03-09 10:39:33.214893718 +0100
  67577. @@ -0,0 +1,80 @@
  67578. +/* ==========================================================================
  67579. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  67580. + * $Revision: #7 $
  67581. + * $Date: 2011/10/24 $
  67582. + * $Change: 1871159 $
  67583. + *
  67584. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67585. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67586. + * otherwise expressly agreed to in writing between Synopsys and you.
  67587. + *
  67588. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67589. + * any End User Software License Agreement or Agreement for Licensed Product
  67590. + * with Synopsys or any supplement thereto. You are permitted to use and
  67591. + * redistribute this Software in source and binary forms, with or without
  67592. + * modification, provided that redistributions of source code must retain this
  67593. + * notice. You may not view, use, disclose, copy or distribute this file or
  67594. + * any information contained herein except pursuant to this license grant from
  67595. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67596. + * below, then you are not authorized to use the Software.
  67597. + *
  67598. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67599. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67600. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67601. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67602. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67603. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67604. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67605. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67606. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67607. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67608. + * DAMAGE.
  67609. + * ========================================================================== */
  67610. +
  67611. +#ifndef __DWC_OTG_ADP_H__
  67612. +#define __DWC_OTG_ADP_H__
  67613. +
  67614. +/**
  67615. + * @file
  67616. + *
  67617. + * This file contains the Attach Detect Protocol interfaces and defines
  67618. + * (functions) and structures for Linux.
  67619. + *
  67620. + */
  67621. +
  67622. +#define DWC_OTG_ADP_UNATTACHED 0
  67623. +#define DWC_OTG_ADP_ATTACHED 1
  67624. +#define DWC_OTG_ADP_UNKOWN 2
  67625. +
  67626. +typedef struct dwc_otg_adp {
  67627. + uint32_t adp_started;
  67628. + uint32_t initial_probe;
  67629. + int32_t probe_timer_values[2];
  67630. + uint32_t probe_enabled;
  67631. + uint32_t sense_enabled;
  67632. + dwc_timer_t *sense_timer;
  67633. + uint32_t sense_timer_started;
  67634. + dwc_timer_t *vbuson_timer;
  67635. + uint32_t vbuson_timer_started;
  67636. + uint32_t attached;
  67637. + uint32_t probe_counter;
  67638. + uint32_t gpwrdn;
  67639. +} dwc_otg_adp_t;
  67640. +
  67641. +/**
  67642. + * Attach Detect Protocol functions
  67643. + */
  67644. +
  67645. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  67646. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  67647. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  67648. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  67649. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  67650. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  67651. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  67652. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  67653. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  67654. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  67655. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  67656. +
  67657. +#endif //__DWC_OTG_ADP_H__
  67658. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  67659. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  67660. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2015-03-09 10:39:33.214893718 +0100
  67661. @@ -0,0 +1,1210 @@
  67662. +/* ==========================================================================
  67663. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  67664. + * $Revision: #44 $
  67665. + * $Date: 2010/11/29 $
  67666. + * $Change: 1636033 $
  67667. + *
  67668. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67669. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67670. + * otherwise expressly agreed to in writing between Synopsys and you.
  67671. + *
  67672. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67673. + * any End User Software License Agreement or Agreement for Licensed Product
  67674. + * with Synopsys or any supplement thereto. You are permitted to use and
  67675. + * redistribute this Software in source and binary forms, with or without
  67676. + * modification, provided that redistributions of source code must retain this
  67677. + * notice. You may not view, use, disclose, copy or distribute this file or
  67678. + * any information contained herein except pursuant to this license grant from
  67679. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67680. + * below, then you are not authorized to use the Software.
  67681. + *
  67682. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67683. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67684. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67685. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67686. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67687. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67688. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67689. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67690. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67691. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67692. + * DAMAGE.
  67693. + * ========================================================================== */
  67694. +
  67695. +/** @file
  67696. + *
  67697. + * The diagnostic interface will provide access to the controller for
  67698. + * bringing up the hardware and testing. The Linux driver attributes
  67699. + * feature will be used to provide the Linux Diagnostic
  67700. + * Interface. These attributes are accessed through sysfs.
  67701. + */
  67702. +
  67703. +/** @page "Linux Module Attributes"
  67704. + *
  67705. + * The Linux module attributes feature is used to provide the Linux
  67706. + * Diagnostic Interface. These attributes are accessed through sysfs.
  67707. + * The diagnostic interface will provide access to the controller for
  67708. + * bringing up the hardware and testing.
  67709. +
  67710. + The following table shows the attributes.
  67711. + <table>
  67712. + <tr>
  67713. + <td><b> Name</b></td>
  67714. + <td><b> Description</b></td>
  67715. + <td><b> Access</b></td>
  67716. + </tr>
  67717. +
  67718. + <tr>
  67719. + <td> mode </td>
  67720. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  67721. + <td> Read</td>
  67722. + </tr>
  67723. +
  67724. + <tr>
  67725. + <td> hnpcapable </td>
  67726. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  67727. + Read returns the current value.</td>
  67728. + <td> Read/Write</td>
  67729. + </tr>
  67730. +
  67731. + <tr>
  67732. + <td> srpcapable </td>
  67733. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  67734. + Read returns the current value.</td>
  67735. + <td> Read/Write</td>
  67736. + </tr>
  67737. +
  67738. + <tr>
  67739. + <td> hsic_connect </td>
  67740. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  67741. + Read returns the current value.</td>
  67742. + <td> Read/Write</td>
  67743. + </tr>
  67744. +
  67745. + <tr>
  67746. + <td> inv_sel_hsic </td>
  67747. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  67748. + Read returns the current value.</td>
  67749. + <td> Read/Write</td>
  67750. + </tr>
  67751. +
  67752. + <tr>
  67753. + <td> hnp </td>
  67754. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  67755. + <td> Read/Write</td>
  67756. + </tr>
  67757. +
  67758. + <tr>
  67759. + <td> srp </td>
  67760. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  67761. + <td> Read/Write</td>
  67762. + </tr>
  67763. +
  67764. + <tr>
  67765. + <td> buspower </td>
  67766. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  67767. + <td> Read/Write</td>
  67768. + </tr>
  67769. +
  67770. + <tr>
  67771. + <td> bussuspend </td>
  67772. + <td> Suspends the USB bus.</td>
  67773. + <td> Read/Write</td>
  67774. + </tr>
  67775. +
  67776. + <tr>
  67777. + <td> busconnected </td>
  67778. + <td> Gets the connection status of the bus</td>
  67779. + <td> Read</td>
  67780. + </tr>
  67781. +
  67782. + <tr>
  67783. + <td> gotgctl </td>
  67784. + <td> Gets or sets the Core Control Status Register.</td>
  67785. + <td> Read/Write</td>
  67786. + </tr>
  67787. +
  67788. + <tr>
  67789. + <td> gusbcfg </td>
  67790. + <td> Gets or sets the Core USB Configuration Register</td>
  67791. + <td> Read/Write</td>
  67792. + </tr>
  67793. +
  67794. + <tr>
  67795. + <td> grxfsiz </td>
  67796. + <td> Gets or sets the Receive FIFO Size Register</td>
  67797. + <td> Read/Write</td>
  67798. + </tr>
  67799. +
  67800. + <tr>
  67801. + <td> gnptxfsiz </td>
  67802. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  67803. + <td> Read/Write</td>
  67804. + </tr>
  67805. +
  67806. + <tr>
  67807. + <td> gpvndctl </td>
  67808. + <td> Gets or sets the PHY Vendor Control Register</td>
  67809. + <td> Read/Write</td>
  67810. + </tr>
  67811. +
  67812. + <tr>
  67813. + <td> ggpio </td>
  67814. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  67815. + or sets the upper 16 bits.</td>
  67816. + <td> Read/Write</td>
  67817. + </tr>
  67818. +
  67819. + <tr>
  67820. + <td> guid </td>
  67821. + <td> Gets or sets the value of the User ID Register</td>
  67822. + <td> Read/Write</td>
  67823. + </tr>
  67824. +
  67825. + <tr>
  67826. + <td> gsnpsid </td>
  67827. + <td> Gets the value of the Synopsys ID Regester</td>
  67828. + <td> Read</td>
  67829. + </tr>
  67830. +
  67831. + <tr>
  67832. + <td> devspeed </td>
  67833. + <td> Gets or sets the device speed setting in the DCFG register</td>
  67834. + <td> Read/Write</td>
  67835. + </tr>
  67836. +
  67837. + <tr>
  67838. + <td> enumspeed </td>
  67839. + <td> Gets the device enumeration Speed.</td>
  67840. + <td> Read</td>
  67841. + </tr>
  67842. +
  67843. + <tr>
  67844. + <td> hptxfsiz </td>
  67845. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  67846. + <td> Read</td>
  67847. + </tr>
  67848. +
  67849. + <tr>
  67850. + <td> hprt0 </td>
  67851. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  67852. + <td> Read/Write</td>
  67853. + </tr>
  67854. +
  67855. + <tr>
  67856. + <td> regoffset </td>
  67857. + <td> Sets the register offset for the next Register Access</td>
  67858. + <td> Read/Write</td>
  67859. + </tr>
  67860. +
  67861. + <tr>
  67862. + <td> regvalue </td>
  67863. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  67864. + <td> Read/Write</td>
  67865. + </tr>
  67866. +
  67867. + <tr>
  67868. + <td> remote_wakeup </td>
  67869. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  67870. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  67871. + Wakeup signalling bit in the Device Control Register is set for 1
  67872. + milli-second.</td>
  67873. + <td> Read/Write</td>
  67874. + </tr>
  67875. +
  67876. + <tr>
  67877. + <td> rem_wakeup_pwrdn </td>
  67878. + <td> On read, shows the status core - hibernated or not. On write, initiates
  67879. + a remote wakeup of the device from Hibernation. </td>
  67880. + <td> Read/Write</td>
  67881. + </tr>
  67882. +
  67883. + <tr>
  67884. + <td> mode_ch_tim_en </td>
  67885. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  67886. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  67887. + after Suspend or LPM. </td>
  67888. + <td> Read/Write</td>
  67889. + </tr>
  67890. +
  67891. + <tr>
  67892. + <td> fr_interval </td>
  67893. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  67894. + reload HFIR register during runtime. The application can write a value to this
  67895. + register only after the Port Enable bit of the Host Port Control and Status
  67896. + register (HPRT.PrtEnaPort) has been set </td>
  67897. + <td> Read/Write</td>
  67898. + </tr>
  67899. +
  67900. + <tr>
  67901. + <td> disconnect_us </td>
  67902. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  67903. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  67904. + <td> Read/Write</td>
  67905. + </tr>
  67906. +
  67907. + <tr>
  67908. + <td> regdump </td>
  67909. + <td> Dumps the contents of core registers.</td>
  67910. + <td> Read</td>
  67911. + </tr>
  67912. +
  67913. + <tr>
  67914. + <td> spramdump </td>
  67915. + <td> Dumps the contents of core registers.</td>
  67916. + <td> Read</td>
  67917. + </tr>
  67918. +
  67919. + <tr>
  67920. + <td> hcddump </td>
  67921. + <td> Dumps the current HCD state.</td>
  67922. + <td> Read</td>
  67923. + </tr>
  67924. +
  67925. + <tr>
  67926. + <td> hcd_frrem </td>
  67927. + <td> Shows the average value of the Frame Remaining
  67928. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  67929. + occurs. This can be used to determine the average interrupt latency. Also
  67930. + shows the average Frame Remaining value for start_transfer and the "a" and
  67931. + "b" sample points. The "a" and "b" sample points may be used during debugging
  67932. + bto determine how long it takes to execute a section of the HCD code.</td>
  67933. + <td> Read</td>
  67934. + </tr>
  67935. +
  67936. + <tr>
  67937. + <td> rd_reg_test </td>
  67938. + <td> Displays the time required to read the GNPTXFSIZ register many times
  67939. + (the output shows the number of times the register is read).
  67940. + <td> Read</td>
  67941. + </tr>
  67942. +
  67943. + <tr>
  67944. + <td> wr_reg_test </td>
  67945. + <td> Displays the time required to write the GNPTXFSIZ register many times
  67946. + (the output shows the number of times the register is written).
  67947. + <td> Read</td>
  67948. + </tr>
  67949. +
  67950. + <tr>
  67951. + <td> lpm_response </td>
  67952. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  67953. + <td> Write</td>
  67954. + </tr>
  67955. +
  67956. + <tr>
  67957. + <td> sleep_status </td>
  67958. + <td> Shows sleep status of device.
  67959. + <td> Read</td>
  67960. + </tr>
  67961. +
  67962. + </table>
  67963. +
  67964. + Example usage:
  67965. + To get the current mode:
  67966. + cat /sys/devices/lm0/mode
  67967. +
  67968. + To power down the USB:
  67969. + echo 0 > /sys/devices/lm0/buspower
  67970. + */
  67971. +
  67972. +#include "dwc_otg_os_dep.h"
  67973. +#include "dwc_os.h"
  67974. +#include "dwc_otg_driver.h"
  67975. +#include "dwc_otg_attr.h"
  67976. +#include "dwc_otg_core_if.h"
  67977. +#include "dwc_otg_pcd_if.h"
  67978. +#include "dwc_otg_hcd_if.h"
  67979. +
  67980. +/*
  67981. + * MACROs for defining sysfs attribute
  67982. + */
  67983. +#ifdef LM_INTERFACE
  67984. +
  67985. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  67986. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  67987. +{ \
  67988. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67989. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  67990. + uint32_t val; \
  67991. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  67992. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  67993. +}
  67994. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  67995. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  67996. + const char *buf, size_t count) \
  67997. +{ \
  67998. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  67999. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  68000. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  68001. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  68002. + return count; \
  68003. +}
  68004. +
  68005. +#elif defined(PCI_INTERFACE)
  68006. +
  68007. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  68008. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  68009. +{ \
  68010. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  68011. + uint32_t val; \
  68012. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  68013. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  68014. +}
  68015. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  68016. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  68017. + const char *buf, size_t count) \
  68018. +{ \
  68019. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  68020. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  68021. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  68022. + return count; \
  68023. +}
  68024. +
  68025. +#elif defined(PLATFORM_INTERFACE)
  68026. +
  68027. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  68028. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  68029. +{ \
  68030. + struct platform_device *platform_dev = \
  68031. + container_of(_dev, struct platform_device, dev); \
  68032. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  68033. + uint32_t val; \
  68034. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  68035. + __func__, _dev, platform_dev, otg_dev); \
  68036. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  68037. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  68038. +}
  68039. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  68040. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  68041. + const char *buf, size_t count) \
  68042. +{ \
  68043. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  68044. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  68045. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  68046. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  68047. + return count; \
  68048. +}
  68049. +#endif
  68050. +
  68051. +/*
  68052. + * MACROs for defining sysfs attribute for 32-bit registers
  68053. + */
  68054. +#ifdef LM_INTERFACE
  68055. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  68056. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  68057. +{ \
  68058. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  68059. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  68060. + uint32_t val; \
  68061. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  68062. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  68063. +}
  68064. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  68065. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  68066. + const char *buf, size_t count) \
  68067. +{ \
  68068. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  68069. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  68070. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  68071. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  68072. + return count; \
  68073. +}
  68074. +#elif defined(PCI_INTERFACE)
  68075. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  68076. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  68077. +{ \
  68078. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  68079. + uint32_t val; \
  68080. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  68081. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  68082. +}
  68083. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  68084. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  68085. + const char *buf, size_t count) \
  68086. +{ \
  68087. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  68088. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  68089. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  68090. + return count; \
  68091. +}
  68092. +
  68093. +#elif defined(PLATFORM_INTERFACE)
  68094. +#include "dwc_otg_dbg.h"
  68095. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  68096. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  68097. +{ \
  68098. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  68099. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  68100. + uint32_t val; \
  68101. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  68102. + __func__, _dev, platform_dev, otg_dev); \
  68103. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  68104. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  68105. +}
  68106. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  68107. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  68108. + const char *buf, size_t count) \
  68109. +{ \
  68110. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  68111. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  68112. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  68113. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  68114. + return count; \
  68115. +}
  68116. +
  68117. +#endif
  68118. +
  68119. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  68120. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  68121. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  68122. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  68123. +
  68124. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  68125. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  68126. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  68127. +
  68128. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  68129. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  68130. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  68131. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  68132. +
  68133. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  68134. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  68135. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  68136. +
  68137. +/** @name Functions for Show/Store of Attributes */
  68138. +/**@{*/
  68139. +
  68140. +/**
  68141. + * Helper function returning the otg_device structure of the given device
  68142. + */
  68143. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  68144. +{
  68145. + dwc_otg_device_t *otg_dev;
  68146. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  68147. + return otg_dev;
  68148. +}
  68149. +
  68150. +/**
  68151. + * Show the register offset of the Register Access.
  68152. + */
  68153. +static ssize_t regoffset_show(struct device *_dev,
  68154. + struct device_attribute *attr, char *buf)
  68155. +{
  68156. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68157. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  68158. + otg_dev->os_dep.reg_offset);
  68159. +}
  68160. +
  68161. +/**
  68162. + * Set the register offset for the next Register Access Read/Write
  68163. + */
  68164. +static ssize_t regoffset_store(struct device *_dev,
  68165. + struct device_attribute *attr,
  68166. + const char *buf, size_t count)
  68167. +{
  68168. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68169. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  68170. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  68171. + if (offset < SZ_256K) {
  68172. +#elif defined(PCI_INTERFACE)
  68173. + if (offset < 0x00040000) {
  68174. +#endif
  68175. + otg_dev->os_dep.reg_offset = offset;
  68176. + } else {
  68177. + dev_err(_dev, "invalid offset\n");
  68178. + }
  68179. +
  68180. + return count;
  68181. +}
  68182. +
  68183. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  68184. +
  68185. +/**
  68186. + * Show the value of the register at the offset in the reg_offset
  68187. + * attribute.
  68188. + */
  68189. +static ssize_t regvalue_show(struct device *_dev,
  68190. + struct device_attribute *attr, char *buf)
  68191. +{
  68192. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68193. + uint32_t val;
  68194. + volatile uint32_t *addr;
  68195. +
  68196. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  68197. + /* Calculate the address */
  68198. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  68199. + (uint8_t *) otg_dev->os_dep.base);
  68200. + val = DWC_READ_REG32(addr);
  68201. + return snprintf(buf,
  68202. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  68203. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  68204. + val);
  68205. + } else {
  68206. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  68207. + return sprintf(buf, "invalid offset\n");
  68208. + }
  68209. +}
  68210. +
  68211. +/**
  68212. + * Store the value in the register at the offset in the reg_offset
  68213. + * attribute.
  68214. + *
  68215. + */
  68216. +static ssize_t regvalue_store(struct device *_dev,
  68217. + struct device_attribute *attr,
  68218. + const char *buf, size_t count)
  68219. +{
  68220. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68221. + volatile uint32_t *addr;
  68222. + uint32_t val = simple_strtoul(buf, NULL, 16);
  68223. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  68224. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  68225. + /* Calculate the address */
  68226. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  68227. + (uint8_t *) otg_dev->os_dep.base);
  68228. + DWC_WRITE_REG32(addr, val);
  68229. + } else {
  68230. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  68231. + otg_dev->os_dep.reg_offset);
  68232. + }
  68233. + return count;
  68234. +}
  68235. +
  68236. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  68237. +
  68238. +/*
  68239. + * Attributes
  68240. + */
  68241. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  68242. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  68243. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  68244. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  68245. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  68246. +
  68247. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  68248. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  68249. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  68250. +
  68251. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  68252. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  68253. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  68254. + "GUSBCFG");
  68255. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  68256. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  68257. + "GRXFSIZ");
  68258. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  68259. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  68260. + "GNPTXFSIZ");
  68261. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  68262. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  68263. + "GPVNDCTL");
  68264. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  68265. + &(otg_dev->core_if->core_global_regs->ggpio),
  68266. + "GGPIO");
  68267. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  68268. + "GUID");
  68269. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  68270. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  68271. + "GSNPSID");
  68272. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  68273. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  68274. +
  68275. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  68276. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  68277. + "HPTXFSIZ");
  68278. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  68279. +
  68280. +/**
  68281. + * @todo Add code to initiate the HNP.
  68282. + */
  68283. +/**
  68284. + * Show the HNP status bit
  68285. + */
  68286. +static ssize_t hnp_show(struct device *_dev,
  68287. + struct device_attribute *attr, char *buf)
  68288. +{
  68289. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68290. + return sprintf(buf, "HstNegScs = 0x%x\n",
  68291. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  68292. +}
  68293. +
  68294. +/**
  68295. + * Set the HNP Request bit
  68296. + */
  68297. +static ssize_t hnp_store(struct device *_dev,
  68298. + struct device_attribute *attr,
  68299. + const char *buf, size_t count)
  68300. +{
  68301. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68302. + uint32_t in = simple_strtoul(buf, NULL, 16);
  68303. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  68304. + return count;
  68305. +}
  68306. +
  68307. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  68308. +
  68309. +/**
  68310. + * @todo Add code to initiate the SRP.
  68311. + */
  68312. +/**
  68313. + * Show the SRP status bit
  68314. + */
  68315. +static ssize_t srp_show(struct device *_dev,
  68316. + struct device_attribute *attr, char *buf)
  68317. +{
  68318. +#ifndef DWC_HOST_ONLY
  68319. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68320. + return sprintf(buf, "SesReqScs = 0x%x\n",
  68321. + dwc_otg_get_srpstatus(otg_dev->core_if));
  68322. +#else
  68323. + return sprintf(buf, "Host Only Mode!\n");
  68324. +#endif
  68325. +}
  68326. +
  68327. +/**
  68328. + * Set the SRP Request bit
  68329. + */
  68330. +static ssize_t srp_store(struct device *_dev,
  68331. + struct device_attribute *attr,
  68332. + const char *buf, size_t count)
  68333. +{
  68334. +#ifndef DWC_HOST_ONLY
  68335. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68336. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  68337. +#endif
  68338. + return count;
  68339. +}
  68340. +
  68341. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  68342. +
  68343. +/**
  68344. + * @todo Need to do more for power on/off?
  68345. + */
  68346. +/**
  68347. + * Show the Bus Power status
  68348. + */
  68349. +static ssize_t buspower_show(struct device *_dev,
  68350. + struct device_attribute *attr, char *buf)
  68351. +{
  68352. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68353. + return sprintf(buf, "Bus Power = 0x%x\n",
  68354. + dwc_otg_get_prtpower(otg_dev->core_if));
  68355. +}
  68356. +
  68357. +/**
  68358. + * Set the Bus Power status
  68359. + */
  68360. +static ssize_t buspower_store(struct device *_dev,
  68361. + struct device_attribute *attr,
  68362. + const char *buf, size_t count)
  68363. +{
  68364. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68365. + uint32_t on = simple_strtoul(buf, NULL, 16);
  68366. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  68367. + return count;
  68368. +}
  68369. +
  68370. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  68371. +
  68372. +/**
  68373. + * @todo Need to do more for suspend?
  68374. + */
  68375. +/**
  68376. + * Show the Bus Suspend status
  68377. + */
  68378. +static ssize_t bussuspend_show(struct device *_dev,
  68379. + struct device_attribute *attr, char *buf)
  68380. +{
  68381. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68382. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  68383. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  68384. +}
  68385. +
  68386. +/**
  68387. + * Set the Bus Suspend status
  68388. + */
  68389. +static ssize_t bussuspend_store(struct device *_dev,
  68390. + struct device_attribute *attr,
  68391. + const char *buf, size_t count)
  68392. +{
  68393. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68394. + uint32_t in = simple_strtoul(buf, NULL, 16);
  68395. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  68396. + return count;
  68397. +}
  68398. +
  68399. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  68400. +
  68401. +/**
  68402. + * Show the Mode Change Ready Timer status
  68403. + */
  68404. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  68405. + struct device_attribute *attr, char *buf)
  68406. +{
  68407. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68408. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  68409. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  68410. +}
  68411. +
  68412. +/**
  68413. + * Set the Mode Change Ready Timer status
  68414. + */
  68415. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  68416. + struct device_attribute *attr,
  68417. + const char *buf, size_t count)
  68418. +{
  68419. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68420. + uint32_t in = simple_strtoul(buf, NULL, 16);
  68421. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  68422. + return count;
  68423. +}
  68424. +
  68425. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  68426. +
  68427. +/**
  68428. + * Show the value of HFIR Frame Interval bitfield
  68429. + */
  68430. +static ssize_t fr_interval_show(struct device *_dev,
  68431. + struct device_attribute *attr, char *buf)
  68432. +{
  68433. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68434. + return sprintf(buf, "Frame Interval = 0x%x\n",
  68435. + dwc_otg_get_fr_interval(otg_dev->core_if));
  68436. +}
  68437. +
  68438. +/**
  68439. + * Set the HFIR Frame Interval value
  68440. + */
  68441. +static ssize_t fr_interval_store(struct device *_dev,
  68442. + struct device_attribute *attr,
  68443. + const char *buf, size_t count)
  68444. +{
  68445. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68446. + uint32_t in = simple_strtoul(buf, NULL, 10);
  68447. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  68448. + return count;
  68449. +}
  68450. +
  68451. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  68452. +
  68453. +/**
  68454. + * Show the status of Remote Wakeup.
  68455. + */
  68456. +static ssize_t remote_wakeup_show(struct device *_dev,
  68457. + struct device_attribute *attr, char *buf)
  68458. +{
  68459. +#ifndef DWC_HOST_ONLY
  68460. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68461. +
  68462. + return sprintf(buf,
  68463. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  68464. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  68465. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  68466. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  68467. +#else
  68468. + return sprintf(buf, "Host Only Mode!\n");
  68469. +#endif /* DWC_HOST_ONLY */
  68470. +}
  68471. +
  68472. +/**
  68473. + * Initiate a remote wakeup of the host. The Device control register
  68474. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  68475. + * flag is set.
  68476. + *
  68477. + */
  68478. +static ssize_t remote_wakeup_store(struct device *_dev,
  68479. + struct device_attribute *attr,
  68480. + const char *buf, size_t count)
  68481. +{
  68482. +#ifndef DWC_HOST_ONLY
  68483. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68484. + uint32_t val = simple_strtoul(buf, NULL, 16);
  68485. +
  68486. + if (val & 1) {
  68487. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  68488. + } else {
  68489. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  68490. + }
  68491. +#endif /* DWC_HOST_ONLY */
  68492. + return count;
  68493. +}
  68494. +
  68495. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  68496. + remote_wakeup_store);
  68497. +
  68498. +/**
  68499. + * Show the whether core is hibernated or not.
  68500. + */
  68501. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  68502. + struct device_attribute *attr, char *buf)
  68503. +{
  68504. +#ifndef DWC_HOST_ONLY
  68505. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68506. +
  68507. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  68508. + DWC_PRINTF("Core is in hibernation\n");
  68509. + } else {
  68510. + DWC_PRINTF("Core is not in hibernation\n");
  68511. + }
  68512. +#endif /* DWC_HOST_ONLY */
  68513. + return 0;
  68514. +}
  68515. +
  68516. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  68517. + int rem_wakeup, int reset);
  68518. +
  68519. +/**
  68520. + * Initiate a remote wakeup of the device to exit from hibernation.
  68521. + */
  68522. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  68523. + struct device_attribute *attr,
  68524. + const char *buf, size_t count)
  68525. +{
  68526. +#ifndef DWC_HOST_ONLY
  68527. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68528. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  68529. +#endif
  68530. + return count;
  68531. +}
  68532. +
  68533. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  68534. + rem_wakeup_pwrdn_store);
  68535. +
  68536. +static ssize_t disconnect_us(struct device *_dev,
  68537. + struct device_attribute *attr,
  68538. + const char *buf, size_t count)
  68539. +{
  68540. +
  68541. +#ifndef DWC_HOST_ONLY
  68542. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68543. + uint32_t val = simple_strtoul(buf, NULL, 16);
  68544. + DWC_PRINTF("The Passed value is %04x\n", val);
  68545. +
  68546. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  68547. +
  68548. +#endif /* DWC_HOST_ONLY */
  68549. + return count;
  68550. +}
  68551. +
  68552. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  68553. +
  68554. +/**
  68555. + * Dump global registers and either host or device registers (depending on the
  68556. + * current mode of the core).
  68557. + */
  68558. +static ssize_t regdump_show(struct device *_dev,
  68559. + struct device_attribute *attr, char *buf)
  68560. +{
  68561. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68562. +
  68563. + dwc_otg_dump_global_registers(otg_dev->core_if);
  68564. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  68565. + dwc_otg_dump_host_registers(otg_dev->core_if);
  68566. + } else {
  68567. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  68568. +
  68569. + }
  68570. + return sprintf(buf, "Register Dump\n");
  68571. +}
  68572. +
  68573. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  68574. +
  68575. +/**
  68576. + * Dump global registers and either host or device registers (depending on the
  68577. + * current mode of the core).
  68578. + */
  68579. +static ssize_t spramdump_show(struct device *_dev,
  68580. + struct device_attribute *attr, char *buf)
  68581. +{
  68582. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68583. +
  68584. + //dwc_otg_dump_spram(otg_dev->core_if);
  68585. +
  68586. + return sprintf(buf, "SPRAM Dump\n");
  68587. +}
  68588. +
  68589. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  68590. +
  68591. +/**
  68592. + * Dump the current hcd state.
  68593. + */
  68594. +static ssize_t hcddump_show(struct device *_dev,
  68595. + struct device_attribute *attr, char *buf)
  68596. +{
  68597. +#ifndef DWC_DEVICE_ONLY
  68598. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68599. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  68600. +#endif /* DWC_DEVICE_ONLY */
  68601. + return sprintf(buf, "HCD Dump\n");
  68602. +}
  68603. +
  68604. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  68605. +
  68606. +/**
  68607. + * Dump the average frame remaining at SOF. This can be used to
  68608. + * determine average interrupt latency. Frame remaining is also shown for
  68609. + * start transfer and two additional sample points.
  68610. + */
  68611. +static ssize_t hcd_frrem_show(struct device *_dev,
  68612. + struct device_attribute *attr, char *buf)
  68613. +{
  68614. +#ifndef DWC_DEVICE_ONLY
  68615. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68616. +
  68617. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  68618. +#endif /* DWC_DEVICE_ONLY */
  68619. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  68620. +}
  68621. +
  68622. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  68623. +
  68624. +/**
  68625. + * Displays the time required to read the GNPTXFSIZ register many times (the
  68626. + * output shows the number of times the register is read).
  68627. + */
  68628. +#define RW_REG_COUNT 10000000
  68629. +#define MSEC_PER_JIFFIE 1000/HZ
  68630. +static ssize_t rd_reg_test_show(struct device *_dev,
  68631. + struct device_attribute *attr, char *buf)
  68632. +{
  68633. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68634. + int i;
  68635. + int time;
  68636. + int start_jiffies;
  68637. +
  68638. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  68639. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  68640. + start_jiffies = jiffies;
  68641. + for (i = 0; i < RW_REG_COUNT; i++) {
  68642. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  68643. + }
  68644. + time = jiffies - start_jiffies;
  68645. + return sprintf(buf,
  68646. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  68647. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  68648. +}
  68649. +
  68650. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  68651. +
  68652. +/**
  68653. + * Displays the time required to write the GNPTXFSIZ register many times (the
  68654. + * output shows the number of times the register is written).
  68655. + */
  68656. +static ssize_t wr_reg_test_show(struct device *_dev,
  68657. + struct device_attribute *attr, char *buf)
  68658. +{
  68659. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68660. + uint32_t reg_val;
  68661. + int i;
  68662. + int time;
  68663. + int start_jiffies;
  68664. +
  68665. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  68666. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  68667. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  68668. + start_jiffies = jiffies;
  68669. + for (i = 0; i < RW_REG_COUNT; i++) {
  68670. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  68671. + }
  68672. + time = jiffies - start_jiffies;
  68673. + return sprintf(buf,
  68674. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  68675. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  68676. +}
  68677. +
  68678. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  68679. +
  68680. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68681. +
  68682. +/**
  68683. +* Show the lpm_response attribute.
  68684. +*/
  68685. +static ssize_t lpmresp_show(struct device *_dev,
  68686. + struct device_attribute *attr, char *buf)
  68687. +{
  68688. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68689. +
  68690. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  68691. + return sprintf(buf, "** LPM is DISABLED **\n");
  68692. +
  68693. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  68694. + return sprintf(buf, "** Current mode is not device mode\n");
  68695. + }
  68696. + return sprintf(buf, "lpm_response = %d\n",
  68697. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  68698. +}
  68699. +
  68700. +/**
  68701. +* Store the lpm_response attribute.
  68702. +*/
  68703. +static ssize_t lpmresp_store(struct device *_dev,
  68704. + struct device_attribute *attr,
  68705. + const char *buf, size_t count)
  68706. +{
  68707. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68708. + uint32_t val = simple_strtoul(buf, NULL, 16);
  68709. +
  68710. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  68711. + return 0;
  68712. + }
  68713. +
  68714. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  68715. + return 0;
  68716. + }
  68717. +
  68718. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  68719. + return count;
  68720. +}
  68721. +
  68722. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  68723. +
  68724. +/**
  68725. +* Show the sleep_status attribute.
  68726. +*/
  68727. +static ssize_t sleepstatus_show(struct device *_dev,
  68728. + struct device_attribute *attr, char *buf)
  68729. +{
  68730. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68731. + return sprintf(buf, "Sleep Status = %d\n",
  68732. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  68733. +}
  68734. +
  68735. +/**
  68736. + * Store the sleep_status attribure.
  68737. + */
  68738. +static ssize_t sleepstatus_store(struct device *_dev,
  68739. + struct device_attribute *attr,
  68740. + const char *buf, size_t count)
  68741. +{
  68742. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  68743. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  68744. +
  68745. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  68746. + if (dwc_otg_is_host_mode(core_if)) {
  68747. +
  68748. + DWC_PRINTF("Host initiated resume\n");
  68749. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  68750. + }
  68751. + }
  68752. +
  68753. + return count;
  68754. +}
  68755. +
  68756. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  68757. + sleepstatus_store);
  68758. +
  68759. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  68760. +
  68761. +/**@}*/
  68762. +
  68763. +/**
  68764. + * Create the device files
  68765. + */
  68766. +void dwc_otg_attr_create(
  68767. +#ifdef LM_INTERFACE
  68768. + struct lm_device *dev
  68769. +#elif defined(PCI_INTERFACE)
  68770. + struct pci_dev *dev
  68771. +#elif defined(PLATFORM_INTERFACE)
  68772. + struct platform_device *dev
  68773. +#endif
  68774. + )
  68775. +{
  68776. + int error;
  68777. +
  68778. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  68779. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  68780. + error = device_create_file(&dev->dev, &dev_attr_mode);
  68781. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  68782. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  68783. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  68784. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  68785. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  68786. + error = device_create_file(&dev->dev, &dev_attr_srp);
  68787. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  68788. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  68789. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  68790. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  68791. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  68792. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  68793. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  68794. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  68795. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  68796. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  68797. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  68798. + error = device_create_file(&dev->dev, &dev_attr_guid);
  68799. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  68800. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  68801. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  68802. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  68803. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  68804. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  68805. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  68806. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  68807. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  68808. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  68809. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  68810. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  68811. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  68812. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  68813. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68814. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  68815. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  68816. +#endif
  68817. +}
  68818. +
  68819. +/**
  68820. + * Remove the device files
  68821. + */
  68822. +void dwc_otg_attr_remove(
  68823. +#ifdef LM_INTERFACE
  68824. + struct lm_device *dev
  68825. +#elif defined(PCI_INTERFACE)
  68826. + struct pci_dev *dev
  68827. +#elif defined(PLATFORM_INTERFACE)
  68828. + struct platform_device *dev
  68829. +#endif
  68830. + )
  68831. +{
  68832. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  68833. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  68834. + device_remove_file(&dev->dev, &dev_attr_mode);
  68835. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  68836. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  68837. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  68838. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  68839. + device_remove_file(&dev->dev, &dev_attr_hnp);
  68840. + device_remove_file(&dev->dev, &dev_attr_srp);
  68841. + device_remove_file(&dev->dev, &dev_attr_buspower);
  68842. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  68843. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  68844. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  68845. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  68846. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  68847. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  68848. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  68849. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  68850. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  68851. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  68852. + device_remove_file(&dev->dev, &dev_attr_guid);
  68853. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  68854. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  68855. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  68856. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  68857. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  68858. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  68859. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  68860. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  68861. + device_remove_file(&dev->dev, &dev_attr_regdump);
  68862. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  68863. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  68864. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  68865. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  68866. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  68867. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68868. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  68869. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  68870. +#endif
  68871. +}
  68872. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  68873. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  68874. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2015-03-09 10:39:33.214893718 +0100
  68875. @@ -0,0 +1,89 @@
  68876. +/* ==========================================================================
  68877. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  68878. + * $Revision: #13 $
  68879. + * $Date: 2010/06/21 $
  68880. + * $Change: 1532021 $
  68881. + *
  68882. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68883. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68884. + * otherwise expressly agreed to in writing between Synopsys and you.
  68885. + *
  68886. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68887. + * any End User Software License Agreement or Agreement for Licensed Product
  68888. + * with Synopsys or any supplement thereto. You are permitted to use and
  68889. + * redistribute this Software in source and binary forms, with or without
  68890. + * modification, provided that redistributions of source code must retain this
  68891. + * notice. You may not view, use, disclose, copy or distribute this file or
  68892. + * any information contained herein except pursuant to this license grant from
  68893. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68894. + * below, then you are not authorized to use the Software.
  68895. + *
  68896. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68897. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68898. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68899. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68900. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68901. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68902. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68903. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68904. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68905. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68906. + * DAMAGE.
  68907. + * ========================================================================== */
  68908. +
  68909. +#if !defined(__DWC_OTG_ATTR_H__)
  68910. +#define __DWC_OTG_ATTR_H__
  68911. +
  68912. +/** @file
  68913. + * This file contains the interface to the Linux device attributes.
  68914. + */
  68915. +extern struct device_attribute dev_attr_regoffset;
  68916. +extern struct device_attribute dev_attr_regvalue;
  68917. +
  68918. +extern struct device_attribute dev_attr_mode;
  68919. +extern struct device_attribute dev_attr_hnpcapable;
  68920. +extern struct device_attribute dev_attr_srpcapable;
  68921. +extern struct device_attribute dev_attr_hnp;
  68922. +extern struct device_attribute dev_attr_srp;
  68923. +extern struct device_attribute dev_attr_buspower;
  68924. +extern struct device_attribute dev_attr_bussuspend;
  68925. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  68926. +extern struct device_attribute dev_attr_fr_interval;
  68927. +extern struct device_attribute dev_attr_busconnected;
  68928. +extern struct device_attribute dev_attr_gotgctl;
  68929. +extern struct device_attribute dev_attr_gusbcfg;
  68930. +extern struct device_attribute dev_attr_grxfsiz;
  68931. +extern struct device_attribute dev_attr_gnptxfsiz;
  68932. +extern struct device_attribute dev_attr_gpvndctl;
  68933. +extern struct device_attribute dev_attr_ggpio;
  68934. +extern struct device_attribute dev_attr_guid;
  68935. +extern struct device_attribute dev_attr_gsnpsid;
  68936. +extern struct device_attribute dev_attr_devspeed;
  68937. +extern struct device_attribute dev_attr_enumspeed;
  68938. +extern struct device_attribute dev_attr_hptxfsiz;
  68939. +extern struct device_attribute dev_attr_hprt0;
  68940. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68941. +extern struct device_attribute dev_attr_lpm_response;
  68942. +extern struct device_attribute devi_attr_sleep_status;
  68943. +#endif
  68944. +
  68945. +void dwc_otg_attr_create(
  68946. +#ifdef LM_INTERFACE
  68947. + struct lm_device *dev
  68948. +#elif defined(PCI_INTERFACE)
  68949. + struct pci_dev *dev
  68950. +#elif defined(PLATFORM_INTERFACE)
  68951. + struct platform_device *dev
  68952. +#endif
  68953. + );
  68954. +
  68955. +void dwc_otg_attr_remove(
  68956. +#ifdef LM_INTERFACE
  68957. + struct lm_device *dev
  68958. +#elif defined(PCI_INTERFACE)
  68959. + struct pci_dev *dev
  68960. +#elif defined(PLATFORM_INTERFACE)
  68961. + struct platform_device *dev
  68962. +#endif
  68963. + );
  68964. +#endif
  68965. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  68966. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  68967. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2015-03-09 10:39:33.214893718 +0100
  68968. @@ -0,0 +1,1876 @@
  68969. +/* ==========================================================================
  68970. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  68971. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  68972. + * otherwise expressly agreed to in writing between Synopsys and you.
  68973. + *
  68974. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  68975. + * any End User Software License Agreement or Agreement for Licensed Product
  68976. + * with Synopsys or any supplement thereto. You are permitted to use and
  68977. + * redistribute this Software in source and binary forms, with or without
  68978. + * modification, provided that redistributions of source code must retain this
  68979. + * notice. You may not view, use, disclose, copy or distribute this file or
  68980. + * any information contained herein except pursuant to this license grant from
  68981. + * Synopsys. If you do not agree with this notice, including the disclaimer
  68982. + * below, then you are not authorized to use the Software.
  68983. + *
  68984. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  68985. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68986. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68987. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  68988. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68989. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  68990. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  68991. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68992. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68993. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  68994. + * DAMAGE.
  68995. + * ========================================================================== */
  68996. +
  68997. +/** @file
  68998. + *
  68999. + * This file contains the most of the CFI(Core Feature Interface)
  69000. + * implementation for the OTG.
  69001. + */
  69002. +
  69003. +#ifdef DWC_UTE_CFI
  69004. +
  69005. +#include "dwc_otg_pcd.h"
  69006. +#include "dwc_otg_cfi.h"
  69007. +
  69008. +/** This definition should actually migrate to the Portability Library */
  69009. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  69010. +
  69011. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  69012. +
  69013. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  69014. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  69015. + struct dwc_otg_pcd *pcd,
  69016. + struct cfi_usb_ctrlrequest *ctrl_req);
  69017. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  69018. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  69019. + struct cfi_usb_ctrlrequest *req);
  69020. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  69021. + struct cfi_usb_ctrlrequest *req);
  69022. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  69023. + struct cfi_usb_ctrlrequest *req);
  69024. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  69025. + struct cfi_usb_ctrlrequest *req);
  69026. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  69027. +
  69028. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  69029. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  69030. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  69031. +
  69032. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  69033. +
  69034. +/** This is the header of the all features descriptor */
  69035. +static cfi_all_features_header_t all_props_desc_header = {
  69036. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  69037. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  69038. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  69039. +};
  69040. +
  69041. +/** This is an array of statically allocated feature descriptors */
  69042. +static cfi_feature_desc_header_t prop_descs[] = {
  69043. +
  69044. + /* FT_ID_DMA_MODE */
  69045. + {
  69046. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  69047. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69048. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  69049. + },
  69050. +
  69051. + /* FT_ID_DMA_BUFFER_SETUP */
  69052. + {
  69053. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  69054. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69055. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  69056. + },
  69057. +
  69058. + /* FT_ID_DMA_BUFF_ALIGN */
  69059. + {
  69060. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  69061. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69062. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  69063. + },
  69064. +
  69065. + /* FT_ID_DMA_CONCAT_SETUP */
  69066. + {
  69067. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  69068. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69069. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  69070. + },
  69071. +
  69072. + /* FT_ID_DMA_CIRCULAR */
  69073. + {
  69074. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  69075. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69076. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  69077. + },
  69078. +
  69079. + /* FT_ID_THRESHOLD_SETUP */
  69080. + {
  69081. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  69082. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69083. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  69084. + },
  69085. +
  69086. + /* FT_ID_DFIFO_DEPTH */
  69087. + {
  69088. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  69089. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  69090. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  69091. + },
  69092. +
  69093. + /* FT_ID_TX_FIFO_DEPTH */
  69094. + {
  69095. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  69096. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69097. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  69098. + },
  69099. +
  69100. + /* FT_ID_RX_FIFO_DEPTH */
  69101. + {
  69102. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  69103. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  69104. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  69105. + }
  69106. +};
  69107. +
  69108. +/** The table of feature names */
  69109. +cfi_string_t prop_name_table[] = {
  69110. + {FT_ID_DMA_MODE, "dma_mode"},
  69111. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  69112. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  69113. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  69114. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  69115. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  69116. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  69117. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  69118. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  69119. + {}
  69120. +};
  69121. +
  69122. +/************************************************************************/
  69123. +
  69124. +/**
  69125. + * Returns the name of the feature by its ID
  69126. + * or NULL if no featute ID matches.
  69127. + *
  69128. + */
  69129. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  69130. +{
  69131. + cfi_string_t *pstr;
  69132. + *len = 0;
  69133. +
  69134. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  69135. + if (pstr->id == prop_id) {
  69136. + *len = DWC_STRLEN(pstr->s);
  69137. + return pstr->s;
  69138. + }
  69139. + }
  69140. + return NULL;
  69141. +}
  69142. +
  69143. +/**
  69144. + * This function handles all CFI specific control requests.
  69145. + *
  69146. + * Return a negative value to stall the DCE.
  69147. + */
  69148. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  69149. +{
  69150. + int retval = 0;
  69151. + dwc_otg_pcd_ep_t *ep = NULL;
  69152. + cfiobject_t *cfi = pcd->cfi;
  69153. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  69154. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  69155. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  69156. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  69157. + uint32_t regaddr = 0;
  69158. + uint32_t regval = 0;
  69159. +
  69160. + /* Save this Control Request in the CFI object.
  69161. + * The data field will be assigned in the data stage completion CB function.
  69162. + */
  69163. + cfi->ctrl_req = *ctrl;
  69164. + cfi->ctrl_req.data = NULL;
  69165. +
  69166. + cfi->need_gadget_att = 0;
  69167. + cfi->need_status_in_complete = 0;
  69168. +
  69169. + switch (ctrl->bRequest) {
  69170. + case VEN_CORE_GET_FEATURES:
  69171. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  69172. + if (retval >= 0) {
  69173. + //dump_msg(cfi->buf_in.buf, retval);
  69174. + ep = &pcd->ep0;
  69175. +
  69176. + retval = min((uint16_t) retval, wLen);
  69177. + /* Transfer this buffer to the host through the EP0-IN EP */
  69178. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  69179. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  69180. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  69181. + ep->dwc_ep.xfer_len = retval;
  69182. + ep->dwc_ep.xfer_count = 0;
  69183. + ep->dwc_ep.sent_zlp = 0;
  69184. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  69185. +
  69186. + pcd->ep0_pending = 1;
  69187. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  69188. + }
  69189. + retval = 0;
  69190. + break;
  69191. +
  69192. + case VEN_CORE_GET_FEATURE:
  69193. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  69194. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  69195. + pcd, ctrl);
  69196. + if (retval >= 0) {
  69197. + ep = &pcd->ep0;
  69198. +
  69199. + retval = min((uint16_t) retval, wLen);
  69200. + /* Transfer this buffer to the host through the EP0-IN EP */
  69201. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  69202. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  69203. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  69204. + ep->dwc_ep.xfer_len = retval;
  69205. + ep->dwc_ep.xfer_count = 0;
  69206. + ep->dwc_ep.sent_zlp = 0;
  69207. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  69208. +
  69209. + pcd->ep0_pending = 1;
  69210. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  69211. + }
  69212. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  69213. + dump_msg(cfi->buf_in.buf, retval);
  69214. + break;
  69215. +
  69216. + case VEN_CORE_SET_FEATURE:
  69217. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  69218. + /* Set up an XFER to get the data stage of the control request,
  69219. + * which is the new value of the feature to be modified.
  69220. + */
  69221. + ep = &pcd->ep0;
  69222. + ep->dwc_ep.is_in = 0;
  69223. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  69224. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  69225. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  69226. + ep->dwc_ep.xfer_len = wLen;
  69227. + ep->dwc_ep.xfer_count = 0;
  69228. + ep->dwc_ep.sent_zlp = 0;
  69229. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  69230. +
  69231. + pcd->ep0_pending = 1;
  69232. + /* Read the control write's data stage */
  69233. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  69234. + retval = 0;
  69235. + break;
  69236. +
  69237. + case VEN_CORE_RESET_FEATURES:
  69238. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  69239. + cfi->need_gadget_att = 1;
  69240. + cfi->need_status_in_complete = 1;
  69241. + retval = cfi_preproc_reset(pcd, ctrl);
  69242. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  69243. + break;
  69244. +
  69245. + case VEN_CORE_ACTIVATE_FEATURES:
  69246. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  69247. + break;
  69248. +
  69249. + case VEN_CORE_READ_REGISTER:
  69250. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  69251. + /* wValue optionally contains the HI WORD of the register offset and
  69252. + * wIndex contains the LOW WORD of the register offset
  69253. + */
  69254. + if (wValue == 0) {
  69255. + /* @TODO - MAS - fix the access to the base field */
  69256. + regaddr = 0;
  69257. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  69258. + //GET_CORE_IF(pcd)->co
  69259. + regaddr |= wIndex;
  69260. + } else {
  69261. + regaddr = (wValue << 16) | wIndex;
  69262. + }
  69263. +
  69264. + /* Read a 32-bit value of the memory at the regaddr */
  69265. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  69266. +
  69267. + ep = &pcd->ep0;
  69268. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  69269. + ep->dwc_ep.is_in = 1;
  69270. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  69271. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  69272. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  69273. + ep->dwc_ep.xfer_len = wLen;
  69274. + ep->dwc_ep.xfer_count = 0;
  69275. + ep->dwc_ep.sent_zlp = 0;
  69276. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  69277. +
  69278. + pcd->ep0_pending = 1;
  69279. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  69280. + cfi->need_gadget_att = 0;
  69281. + retval = 0;
  69282. + break;
  69283. +
  69284. + case VEN_CORE_WRITE_REGISTER:
  69285. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  69286. + /* Set up an XFER to get the data stage of the control request,
  69287. + * which is the new value of the register to be modified.
  69288. + */
  69289. + ep = &pcd->ep0;
  69290. + ep->dwc_ep.is_in = 0;
  69291. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  69292. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  69293. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  69294. + ep->dwc_ep.xfer_len = wLen;
  69295. + ep->dwc_ep.xfer_count = 0;
  69296. + ep->dwc_ep.sent_zlp = 0;
  69297. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  69298. +
  69299. + pcd->ep0_pending = 1;
  69300. + /* Read the control write's data stage */
  69301. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  69302. + retval = 0;
  69303. + break;
  69304. +
  69305. + default:
  69306. + retval = -DWC_E_NOT_SUPPORTED;
  69307. + break;
  69308. + }
  69309. +
  69310. + return retval;
  69311. +}
  69312. +
  69313. +/**
  69314. + * This function prepares the core features descriptors and copies its
  69315. + * raw representation into the buffer <buf>.
  69316. + *
  69317. + * The buffer structure is as follows:
  69318. + * all_features_header (8 bytes)
  69319. + * features_#1 (8 bytes + feature name string length)
  69320. + * features_#2 (8 bytes + feature name string length)
  69321. + * .....
  69322. + * features_#n - where n=the total count of feature descriptors
  69323. + */
  69324. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  69325. +{
  69326. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  69327. + cfi_feature_desc_header_t *prop;
  69328. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  69329. + cfi_all_features_header_t *tmp;
  69330. + uint8_t *tmpbuf = buf;
  69331. + const uint8_t *pname = NULL;
  69332. + int i, j, namelen = 0, totlen;
  69333. +
  69334. + /* Prepare and copy the core features into the buffer */
  69335. + CFI_INFO("%s:\n", __func__);
  69336. +
  69337. + tmp = (cfi_all_features_header_t *) tmpbuf;
  69338. + *tmp = *all_props_hdr;
  69339. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  69340. +
  69341. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  69342. + for (i = 0; i < j; i++, prop_hdr++) {
  69343. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  69344. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  69345. + *prop = *prop_hdr;
  69346. +
  69347. + prop->bNameLen = namelen;
  69348. + prop->wLength =
  69349. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  69350. + namelen);
  69351. +
  69352. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  69353. + dwc_memcpy(tmpbuf, pname, namelen);
  69354. + tmpbuf += namelen;
  69355. + }
  69356. +
  69357. + totlen = tmpbuf - buf;
  69358. +
  69359. + if (totlen > 0) {
  69360. + tmp = (cfi_all_features_header_t *) buf;
  69361. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  69362. + }
  69363. +
  69364. + return totlen;
  69365. +}
  69366. +
  69367. +/**
  69368. + * This function releases all the dynamic memory in the CFI object.
  69369. + */
  69370. +static void cfi_release(cfiobject_t * cfiobj)
  69371. +{
  69372. + cfi_ep_t *cfiep;
  69373. + dwc_list_link_t *tmp;
  69374. +
  69375. + CFI_INFO("%s\n", __func__);
  69376. +
  69377. + if (cfiobj->buf_in.buf) {
  69378. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  69379. + cfiobj->buf_in.addr);
  69380. + cfiobj->buf_in.buf = NULL;
  69381. + }
  69382. +
  69383. + if (cfiobj->buf_out.buf) {
  69384. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  69385. + cfiobj->buf_out.addr);
  69386. + cfiobj->buf_out.buf = NULL;
  69387. + }
  69388. +
  69389. + /* Free the Buffer Setup values for each EP */
  69390. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  69391. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  69392. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  69393. + cfi_free_ep_bs_dyn_data(cfiep);
  69394. + }
  69395. +}
  69396. +
  69397. +/**
  69398. + * This function frees the dynamically allocated EP buffer setup data.
  69399. + */
  69400. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  69401. +{
  69402. + if (cfiep->bm_sg) {
  69403. + DWC_FREE(cfiep->bm_sg);
  69404. + cfiep->bm_sg = NULL;
  69405. + }
  69406. +
  69407. + if (cfiep->bm_align) {
  69408. + DWC_FREE(cfiep->bm_align);
  69409. + cfiep->bm_align = NULL;
  69410. + }
  69411. +
  69412. + if (cfiep->bm_concat) {
  69413. + if (NULL != cfiep->bm_concat->wTxBytes) {
  69414. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  69415. + cfiep->bm_concat->wTxBytes = NULL;
  69416. + }
  69417. + DWC_FREE(cfiep->bm_concat);
  69418. + cfiep->bm_concat = NULL;
  69419. + }
  69420. +}
  69421. +
  69422. +/**
  69423. + * This function initializes the default values of the features
  69424. + * for a specific endpoint and should be called only once when
  69425. + * the EP is enabled first time.
  69426. + */
  69427. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  69428. +{
  69429. + int retval = 0;
  69430. +
  69431. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  69432. + if (NULL == cfiep->bm_sg) {
  69433. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  69434. + return -DWC_E_NO_MEMORY;
  69435. + }
  69436. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  69437. +
  69438. + /* For the Concatenation feature's default value we do not allocate
  69439. + * memory for the wTxBytes field - it will be done in the set_feature_value
  69440. + * request handler.
  69441. + */
  69442. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  69443. + if (NULL == cfiep->bm_concat) {
  69444. + CFI_INFO
  69445. + ("Failed to allocate memory for CONCATENATION feature value\n");
  69446. + DWC_FREE(cfiep->bm_sg);
  69447. + return -DWC_E_NO_MEMORY;
  69448. + }
  69449. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  69450. +
  69451. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  69452. + if (NULL == cfiep->bm_align) {
  69453. + CFI_INFO
  69454. + ("Failed to allocate memory for Alignment feature value\n");
  69455. + DWC_FREE(cfiep->bm_sg);
  69456. + DWC_FREE(cfiep->bm_concat);
  69457. + return -DWC_E_NO_MEMORY;
  69458. + }
  69459. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  69460. +
  69461. + return retval;
  69462. +}
  69463. +
  69464. +/**
  69465. + * The callback function that notifies the CFI on the activation of
  69466. + * an endpoint in the PCD. The following steps are done in this function:
  69467. + *
  69468. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  69469. + * active endpoint)
  69470. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  69471. + * Set the Buffer Mode to standard
  69472. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  69473. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  69474. + */
  69475. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  69476. + struct dwc_otg_pcd_ep *ep)
  69477. +{
  69478. + cfi_ep_t *cfiep;
  69479. + int retval = -DWC_E_NOT_SUPPORTED;
  69480. +
  69481. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  69482. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  69483. + /* MAS - Check whether this endpoint already is in the list */
  69484. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  69485. +
  69486. + if (NULL == cfiep) {
  69487. + /* Allocate a cfi_ep_t object */
  69488. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  69489. + if (NULL == cfiep) {
  69490. + CFI_INFO
  69491. + ("Unable to allocate memory for <cfiep> in function %s\n",
  69492. + __func__);
  69493. + return -DWC_E_NO_MEMORY;
  69494. + }
  69495. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  69496. +
  69497. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  69498. + cfiep->ep = ep;
  69499. +
  69500. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  69501. + ep->dwc_ep.descs =
  69502. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  69503. + sizeof(dwc_otg_dma_desc_t),
  69504. + &ep->dwc_ep.descs_dma_addr);
  69505. +
  69506. + if (NULL == ep->dwc_ep.descs) {
  69507. + DWC_FREE(cfiep);
  69508. + return -DWC_E_NO_MEMORY;
  69509. + }
  69510. +
  69511. + DWC_LIST_INIT(&cfiep->lh);
  69512. +
  69513. + /* Set the buffer mode to BM_STANDARD. It will be modified
  69514. + * when building descriptors for a specific buffer mode */
  69515. + ep->dwc_ep.buff_mode = BM_STANDARD;
  69516. +
  69517. + /* Create and initialize the default values for this EP's Buffer modes */
  69518. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  69519. + return retval;
  69520. +
  69521. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  69522. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  69523. + retval = 0;
  69524. + } else { /* The sought EP already is in the list */
  69525. + CFI_INFO("%s: The sought EP already is in the list\n",
  69526. + __func__);
  69527. + }
  69528. +
  69529. + return retval;
  69530. +}
  69531. +
  69532. +/**
  69533. + * This function is called when the data stage of a 3-stage Control Write request
  69534. + * is complete.
  69535. + *
  69536. + */
  69537. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  69538. + struct dwc_otg_pcd *pcd)
  69539. +{
  69540. + uint32_t addr, reg_value;
  69541. + uint16_t wIndex, wValue;
  69542. + uint8_t bRequest;
  69543. + uint8_t *buf = cfi->buf_out.buf;
  69544. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  69545. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  69546. + int retval = -DWC_E_NOT_SUPPORTED;
  69547. +
  69548. + CFI_INFO("%s\n", __func__);
  69549. +
  69550. + bRequest = ctrl_req->bRequest;
  69551. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  69552. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  69553. +
  69554. + /*
  69555. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  69556. + * The request should be already saved in the command stage by now.
  69557. + */
  69558. + ctrl_req->data = cfi->buf_out.buf;
  69559. + cfi->need_status_in_complete = 0;
  69560. + cfi->need_gadget_att = 0;
  69561. +
  69562. + switch (bRequest) {
  69563. + case VEN_CORE_WRITE_REGISTER:
  69564. + /* The buffer contains raw data of the new value for the register */
  69565. + reg_value = *((uint32_t *) buf);
  69566. + if (wValue == 0) {
  69567. + addr = 0;
  69568. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  69569. + addr += wIndex;
  69570. + } else {
  69571. + addr = (wValue << 16) | wIndex;
  69572. + }
  69573. +
  69574. + //writel(reg_value, addr);
  69575. +
  69576. + retval = 0;
  69577. + cfi->need_status_in_complete = 1;
  69578. + break;
  69579. +
  69580. + case VEN_CORE_SET_FEATURE:
  69581. + /* The buffer contains raw data of the new value of the feature */
  69582. + retval = cfi_set_feature_value(pcd);
  69583. + if (retval < 0)
  69584. + return retval;
  69585. +
  69586. + cfi->need_status_in_complete = 1;
  69587. + break;
  69588. +
  69589. + default:
  69590. + break;
  69591. + }
  69592. +
  69593. + return retval;
  69594. +}
  69595. +
  69596. +/**
  69597. + * This function builds the DMA descriptors for the SG buffer mode.
  69598. + */
  69599. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69600. + dwc_otg_pcd_request_t * req)
  69601. +{
  69602. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69603. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  69604. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69605. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  69606. + dma_addr_t buff_addr = req->dma;
  69607. + int i;
  69608. + uint32_t txsize, off;
  69609. +
  69610. + txsize = sgval->wSize;
  69611. + off = sgval->bOffset;
  69612. +
  69613. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  69614. +// __func__, cfiep->ep->ep.name, txsize, off);
  69615. +
  69616. + for (i = 0; i < sgval->bCount; i++) {
  69617. + desc->status.b.bs = BS_HOST_BUSY;
  69618. + desc->buf = buff_addr;
  69619. + desc->status.b.l = 0;
  69620. + desc->status.b.ioc = 0;
  69621. + desc->status.b.sp = 0;
  69622. + desc->status.b.bytes = txsize;
  69623. + desc->status.b.bs = BS_HOST_READY;
  69624. +
  69625. + /* Set the next address of the buffer */
  69626. + buff_addr += txsize + off;
  69627. + desc_last = desc;
  69628. + desc++;
  69629. + }
  69630. +
  69631. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  69632. + desc_last->status.b.l = 1;
  69633. + desc_last->status.b.ioc = 1;
  69634. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  69635. + /* Save the last DMA descriptor pointer */
  69636. + cfiep->dma_desc_last = desc_last;
  69637. + cfiep->desc_count = sgval->bCount;
  69638. +}
  69639. +
  69640. +/**
  69641. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  69642. + */
  69643. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69644. + dwc_otg_pcd_request_t * req)
  69645. +{
  69646. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69647. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  69648. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69649. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  69650. + dma_addr_t buff_addr = req->dma;
  69651. + int i;
  69652. + uint16_t *txsize;
  69653. +
  69654. + txsize = concatval->wTxBytes;
  69655. +
  69656. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  69657. + desc->buf = buff_addr;
  69658. + desc->status.b.bs = BS_HOST_BUSY;
  69659. + desc->status.b.l = 0;
  69660. + desc->status.b.ioc = 0;
  69661. + desc->status.b.sp = 0;
  69662. + desc->status.b.bytes = *txsize;
  69663. + desc->status.b.bs = BS_HOST_READY;
  69664. +
  69665. + txsize++;
  69666. + /* Set the next address of the buffer */
  69667. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  69668. + desc_last = desc;
  69669. + desc++;
  69670. + }
  69671. +
  69672. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  69673. + desc_last->status.b.l = 1;
  69674. + desc_last->status.b.ioc = 1;
  69675. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  69676. + cfiep->dma_desc_last = desc_last;
  69677. + cfiep->desc_count = concatval->hdr.bDescCount;
  69678. +}
  69679. +
  69680. +/**
  69681. + * This function builds the DMA descriptors for the Circular buffer mode
  69682. + */
  69683. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69684. + dwc_otg_pcd_request_t * req)
  69685. +{
  69686. + /* @todo: MAS - add implementation when this feature needs to be tested */
  69687. +}
  69688. +
  69689. +/**
  69690. + * This function builds the DMA descriptors for the Alignment buffer mode
  69691. + */
  69692. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  69693. + dwc_otg_pcd_request_t * req)
  69694. +{
  69695. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  69696. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  69697. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  69698. + dma_addr_t buff_addr = req->dma;
  69699. +
  69700. + desc->status.b.bs = BS_HOST_BUSY;
  69701. + desc->status.b.l = 1;
  69702. + desc->status.b.ioc = 1;
  69703. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  69704. + desc->status.b.bytes = req->length;
  69705. + /* Adjust the buffer alignment */
  69706. + desc->buf = (buff_addr + alignval->bAlign);
  69707. + desc->status.b.bs = BS_HOST_READY;
  69708. + cfiep->dma_desc_last = desc;
  69709. + cfiep->desc_count = 1;
  69710. +}
  69711. +
  69712. +/**
  69713. + * This function builds the DMA descriptors chain for different modes of the
  69714. + * buffer setup of an endpoint.
  69715. + */
  69716. +static void cfi_build_descriptors(struct cfiobject *cfi,
  69717. + struct dwc_otg_pcd *pcd,
  69718. + struct dwc_otg_pcd_ep *ep,
  69719. + dwc_otg_pcd_request_t * req)
  69720. +{
  69721. + cfi_ep_t *cfiep;
  69722. +
  69723. + /* Get the cfiep by the dwc_otg_pcd_ep */
  69724. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  69725. + if (NULL == cfiep) {
  69726. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  69727. + __func__);
  69728. + return;
  69729. + }
  69730. +
  69731. + cfiep->xfer_len = req->length;
  69732. +
  69733. + /* Iterate through all the DMA descriptors */
  69734. + switch (cfiep->ep->dwc_ep.buff_mode) {
  69735. + case BM_SG:
  69736. + cfi_build_sg_descs(cfi, cfiep, req);
  69737. + break;
  69738. +
  69739. + case BM_CONCAT:
  69740. + cfi_build_concat_descs(cfi, cfiep, req);
  69741. + break;
  69742. +
  69743. + case BM_CIRCULAR:
  69744. + cfi_build_circ_descs(cfi, cfiep, req);
  69745. + break;
  69746. +
  69747. + case BM_ALIGN:
  69748. + cfi_build_align_descs(cfi, cfiep, req);
  69749. + break;
  69750. +
  69751. + default:
  69752. + break;
  69753. + }
  69754. +}
  69755. +
  69756. +/**
  69757. + * Allocate DMA buffer for different Buffer modes.
  69758. + */
  69759. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  69760. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  69761. + unsigned size, gfp_t flags)
  69762. +{
  69763. + return DWC_DMA_ALLOC(size, dma);
  69764. +}
  69765. +
  69766. +/**
  69767. + * This function initializes the CFI object.
  69768. + */
  69769. +int init_cfi(cfiobject_t * cfiobj)
  69770. +{
  69771. + CFI_INFO("%s\n", __func__);
  69772. +
  69773. + /* Allocate a buffer for IN XFERs */
  69774. + cfiobj->buf_in.buf =
  69775. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  69776. + if (NULL == cfiobj->buf_in.buf) {
  69777. + CFI_INFO("Unable to allocate buffer for INs\n");
  69778. + return -DWC_E_NO_MEMORY;
  69779. + }
  69780. +
  69781. + /* Allocate a buffer for OUT XFERs */
  69782. + cfiobj->buf_out.buf =
  69783. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  69784. + if (NULL == cfiobj->buf_out.buf) {
  69785. + CFI_INFO("Unable to allocate buffer for OUT\n");
  69786. + return -DWC_E_NO_MEMORY;
  69787. + }
  69788. +
  69789. + /* Initialize the callback function pointers */
  69790. + cfiobj->ops.release = cfi_release;
  69791. + cfiobj->ops.ep_enable = cfi_ep_enable;
  69792. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  69793. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  69794. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  69795. +
  69796. + /* Initialize the list of active endpoints in the CFI object */
  69797. + DWC_LIST_INIT(&cfiobj->active_eps);
  69798. +
  69799. + return 0;
  69800. +}
  69801. +
  69802. +/**
  69803. + * This function reads the required feature's current value into the buffer
  69804. + *
  69805. + * @retval: Returns negative as error, or the data length of the feature
  69806. + */
  69807. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  69808. + struct dwc_otg_pcd *pcd,
  69809. + struct cfi_usb_ctrlrequest *ctrl_req)
  69810. +{
  69811. + int retval = -DWC_E_NOT_SUPPORTED;
  69812. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  69813. + uint16_t dfifo, rxfifo, txfifo;
  69814. +
  69815. + switch (ctrl_req->wIndex) {
  69816. + /* Whether the DDMA is enabled or not */
  69817. + case FT_ID_DMA_MODE:
  69818. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  69819. + retval = 1;
  69820. + break;
  69821. +
  69822. + case FT_ID_DMA_BUFFER_SETUP:
  69823. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  69824. + break;
  69825. +
  69826. + case FT_ID_DMA_BUFF_ALIGN:
  69827. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  69828. + break;
  69829. +
  69830. + case FT_ID_DMA_CONCAT_SETUP:
  69831. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  69832. + break;
  69833. +
  69834. + case FT_ID_DMA_CIRCULAR:
  69835. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  69836. + break;
  69837. +
  69838. + case FT_ID_THRESHOLD_SETUP:
  69839. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  69840. + break;
  69841. +
  69842. + case FT_ID_DFIFO_DEPTH:
  69843. + dfifo = get_dfifo_size(coreif);
  69844. + *((uint16_t *) buf) = dfifo;
  69845. + retval = sizeof(uint16_t);
  69846. + break;
  69847. +
  69848. + case FT_ID_TX_FIFO_DEPTH:
  69849. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  69850. + if (retval >= 0) {
  69851. + txfifo = retval;
  69852. + *((uint16_t *) buf) = txfifo;
  69853. + retval = sizeof(uint16_t);
  69854. + }
  69855. + break;
  69856. +
  69857. + case FT_ID_RX_FIFO_DEPTH:
  69858. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  69859. + if (retval >= 0) {
  69860. + rxfifo = retval;
  69861. + *((uint16_t *) buf) = rxfifo;
  69862. + retval = sizeof(uint16_t);
  69863. + }
  69864. + break;
  69865. + }
  69866. +
  69867. + return retval;
  69868. +}
  69869. +
  69870. +/**
  69871. + * This function resets the SG for the specified EP to its default value
  69872. + */
  69873. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  69874. +{
  69875. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  69876. + return 0;
  69877. +}
  69878. +
  69879. +/**
  69880. + * This function resets the Alignment for the specified EP to its default value
  69881. + */
  69882. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  69883. +{
  69884. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  69885. + return 0;
  69886. +}
  69887. +
  69888. +/**
  69889. + * This function resets the Concatenation for the specified EP to its default value
  69890. + * This function will also set the value of the wTxBytes field to NULL after
  69891. + * freeing the memory previously allocated for this field.
  69892. + */
  69893. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  69894. +{
  69895. + /* First we need to free the wTxBytes field */
  69896. + if (cfiep->bm_concat->wTxBytes) {
  69897. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  69898. + cfiep->bm_concat->wTxBytes = NULL;
  69899. + }
  69900. +
  69901. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  69902. + return 0;
  69903. +}
  69904. +
  69905. +/**
  69906. + * This function resets all the buffer setups of the specified endpoint
  69907. + */
  69908. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  69909. +{
  69910. + cfi_reset_sg_val(cfiep);
  69911. + cfi_reset_align_val(cfiep);
  69912. + cfi_reset_concat_val(cfiep);
  69913. + return 0;
  69914. +}
  69915. +
  69916. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  69917. + uint8_t rx_rst, uint8_t tx_rst)
  69918. +{
  69919. + int retval = -DWC_E_INVALID;
  69920. + uint16_t tx_siz[15];
  69921. + uint16_t rx_siz = 0;
  69922. + dwc_otg_pcd_ep_t *ep = NULL;
  69923. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  69924. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  69925. +
  69926. + if (rx_rst) {
  69927. + rx_siz = params->dev_rx_fifo_size;
  69928. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  69929. + }
  69930. +
  69931. + if (tx_rst) {
  69932. + if (ep_addr == 0) {
  69933. + int i;
  69934. +
  69935. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  69936. + tx_siz[i] =
  69937. + core_if->core_params->dev_tx_fifo_size[i];
  69938. + core_if->core_params->dev_tx_fifo_size[i] =
  69939. + core_if->init_txfsiz[i];
  69940. + }
  69941. + } else {
  69942. +
  69943. + ep = get_ep_by_addr(pcd, ep_addr);
  69944. +
  69945. + if (NULL == ep) {
  69946. + CFI_INFO
  69947. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  69948. + __func__, ep_addr);
  69949. + return -DWC_E_INVALID;
  69950. + }
  69951. +
  69952. + tx_siz[0] =
  69953. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  69954. + 1];
  69955. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  69956. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  69957. + dwc_ep.tx_fifo_num -
  69958. + 1];
  69959. + }
  69960. + }
  69961. +
  69962. + if (resize_fifos(GET_CORE_IF(pcd))) {
  69963. + retval = 0;
  69964. + } else {
  69965. + CFI_INFO
  69966. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  69967. + __func__);
  69968. + if (rx_rst) {
  69969. + params->dev_rx_fifo_size = rx_siz;
  69970. + }
  69971. +
  69972. + if (tx_rst) {
  69973. + if (ep_addr == 0) {
  69974. + int i;
  69975. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  69976. + i++) {
  69977. + core_if->
  69978. + core_params->dev_tx_fifo_size[i] =
  69979. + tx_siz[i];
  69980. + }
  69981. + } else {
  69982. + params->dev_tx_fifo_size[ep->
  69983. + dwc_ep.tx_fifo_num -
  69984. + 1] = tx_siz[0];
  69985. + }
  69986. + }
  69987. + retval = -DWC_E_INVALID;
  69988. + }
  69989. + return retval;
  69990. +}
  69991. +
  69992. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  69993. +{
  69994. + int retval = 0;
  69995. + cfi_ep_t *cfiep;
  69996. + cfiobject_t *cfi = pcd->cfi;
  69997. + dwc_list_link_t *tmp;
  69998. +
  69999. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  70000. + if (retval < 0) {
  70001. + return retval;
  70002. + }
  70003. +
  70004. + /* If the EP address is known then reset the features for only that EP */
  70005. + if (addr) {
  70006. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70007. + if (NULL == cfiep) {
  70008. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  70009. + __func__, addr);
  70010. + return -DWC_E_INVALID;
  70011. + }
  70012. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  70013. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  70014. + }
  70015. + /* Otherwise (wValue == 0), reset all features of all EP's */
  70016. + else {
  70017. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  70018. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  70019. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70020. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70021. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  70022. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  70023. + if (retval < 0) {
  70024. + CFI_INFO
  70025. + ("%s: Error resetting the feature Reset All\n",
  70026. + __func__);
  70027. + return retval;
  70028. + }
  70029. + }
  70030. + }
  70031. + return retval;
  70032. +}
  70033. +
  70034. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  70035. + uint8_t addr)
  70036. +{
  70037. + int retval = 0;
  70038. + cfi_ep_t *cfiep;
  70039. + cfiobject_t *cfi = pcd->cfi;
  70040. + dwc_list_link_t *tmp;
  70041. +
  70042. + /* If the EP address is known then reset the features for only that EP */
  70043. + if (addr) {
  70044. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70045. + if (NULL == cfiep) {
  70046. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  70047. + __func__, addr);
  70048. + return -DWC_E_INVALID;
  70049. + }
  70050. + retval = cfi_reset_sg_val(cfiep);
  70051. + }
  70052. + /* Otherwise (wValue == 0), reset all features of all EP's */
  70053. + else {
  70054. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  70055. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  70056. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70057. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70058. + retval = cfi_reset_sg_val(cfiep);
  70059. + if (retval < 0) {
  70060. + CFI_INFO
  70061. + ("%s: Error resetting the feature Buffer Setup\n",
  70062. + __func__);
  70063. + return retval;
  70064. + }
  70065. + }
  70066. + }
  70067. + return retval;
  70068. +}
  70069. +
  70070. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  70071. +{
  70072. + int retval = 0;
  70073. + cfi_ep_t *cfiep;
  70074. + cfiobject_t *cfi = pcd->cfi;
  70075. + dwc_list_link_t *tmp;
  70076. +
  70077. + /* If the EP address is known then reset the features for only that EP */
  70078. + if (addr) {
  70079. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70080. + if (NULL == cfiep) {
  70081. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  70082. + __func__, addr);
  70083. + return -DWC_E_INVALID;
  70084. + }
  70085. + retval = cfi_reset_concat_val(cfiep);
  70086. + }
  70087. + /* Otherwise (wValue == 0), reset all features of all EP's */
  70088. + else {
  70089. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  70090. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  70091. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70092. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70093. + retval = cfi_reset_concat_val(cfiep);
  70094. + if (retval < 0) {
  70095. + CFI_INFO
  70096. + ("%s: Error resetting the feature Concatenation Value\n",
  70097. + __func__);
  70098. + return retval;
  70099. + }
  70100. + }
  70101. + }
  70102. + return retval;
  70103. +}
  70104. +
  70105. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  70106. +{
  70107. + int retval = 0;
  70108. + cfi_ep_t *cfiep;
  70109. + cfiobject_t *cfi = pcd->cfi;
  70110. + dwc_list_link_t *tmp;
  70111. +
  70112. + /* If the EP address is known then reset the features for only that EP */
  70113. + if (addr) {
  70114. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70115. + if (NULL == cfiep) {
  70116. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  70117. + __func__, addr);
  70118. + return -DWC_E_INVALID;
  70119. + }
  70120. + retval = cfi_reset_align_val(cfiep);
  70121. + }
  70122. + /* Otherwise (wValue == 0), reset all features of all EP's */
  70123. + else {
  70124. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  70125. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  70126. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  70127. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  70128. + retval = cfi_reset_align_val(cfiep);
  70129. + if (retval < 0) {
  70130. + CFI_INFO
  70131. + ("%s: Error resetting the feature Aliignment Value\n",
  70132. + __func__);
  70133. + return retval;
  70134. + }
  70135. + }
  70136. + }
  70137. + return retval;
  70138. +
  70139. +}
  70140. +
  70141. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  70142. + struct cfi_usb_ctrlrequest *req)
  70143. +{
  70144. + int retval = 0;
  70145. +
  70146. + switch (req->wIndex) {
  70147. + case 0:
  70148. + /* Reset all features */
  70149. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  70150. + break;
  70151. +
  70152. + case FT_ID_DMA_BUFFER_SETUP:
  70153. + /* Reset the SG buffer setup */
  70154. + retval =
  70155. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  70156. + break;
  70157. +
  70158. + case FT_ID_DMA_CONCAT_SETUP:
  70159. + /* Reset the Concatenation buffer setup */
  70160. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  70161. + break;
  70162. +
  70163. + case FT_ID_DMA_BUFF_ALIGN:
  70164. + /* Reset the Alignment buffer setup */
  70165. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  70166. + break;
  70167. +
  70168. + case FT_ID_TX_FIFO_DEPTH:
  70169. + retval =
  70170. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  70171. + pcd->cfi->need_gadget_att = 0;
  70172. + break;
  70173. +
  70174. + case FT_ID_RX_FIFO_DEPTH:
  70175. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  70176. + pcd->cfi->need_gadget_att = 0;
  70177. + break;
  70178. + default:
  70179. + break;
  70180. + }
  70181. + return retval;
  70182. +}
  70183. +
  70184. +/**
  70185. + * This function sets a new value for the SG buffer setup.
  70186. + */
  70187. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  70188. +{
  70189. + uint8_t inaddr, outaddr;
  70190. + cfi_ep_t *epin, *epout;
  70191. + ddma_sg_buffer_setup_t *psgval;
  70192. + uint32_t desccount, size;
  70193. +
  70194. + CFI_INFO("%s\n", __func__);
  70195. +
  70196. + psgval = (ddma_sg_buffer_setup_t *) buf;
  70197. + desccount = (uint32_t) psgval->bCount;
  70198. + size = (uint32_t) psgval->wSize;
  70199. +
  70200. + /* Check the DMA descriptor count */
  70201. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  70202. + CFI_INFO
  70203. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  70204. + __func__, MAX_DMA_DESCS_PER_EP);
  70205. + return -DWC_E_INVALID;
  70206. + }
  70207. +
  70208. + /* Check the DMA descriptor count */
  70209. +
  70210. + if (size == 0) {
  70211. +
  70212. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  70213. + __func__);
  70214. +
  70215. + return -DWC_E_INVALID;
  70216. +
  70217. + }
  70218. +
  70219. + inaddr = psgval->bInEndpointAddress;
  70220. + outaddr = psgval->bOutEndpointAddress;
  70221. +
  70222. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  70223. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  70224. +
  70225. + if (NULL == epin || NULL == epout) {
  70226. + CFI_INFO
  70227. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  70228. + __func__, inaddr, outaddr);
  70229. + return -DWC_E_INVALID;
  70230. + }
  70231. +
  70232. + epin->ep->dwc_ep.buff_mode = BM_SG;
  70233. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  70234. +
  70235. + epout->ep->dwc_ep.buff_mode = BM_SG;
  70236. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  70237. +
  70238. + return 0;
  70239. +}
  70240. +
  70241. +/**
  70242. + * This function sets a new value for the buffer Alignment setup.
  70243. + */
  70244. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  70245. +{
  70246. + cfi_ep_t *ep;
  70247. + uint8_t addr;
  70248. + ddma_align_buffer_setup_t *palignval;
  70249. +
  70250. + palignval = (ddma_align_buffer_setup_t *) buf;
  70251. + addr = palignval->bEndpointAddress;
  70252. +
  70253. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70254. +
  70255. + if (NULL == ep) {
  70256. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  70257. + __func__, addr);
  70258. + return -DWC_E_INVALID;
  70259. + }
  70260. +
  70261. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  70262. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  70263. +
  70264. + return 0;
  70265. +}
  70266. +
  70267. +/**
  70268. + * This function sets a new value for the Concatenation buffer setup.
  70269. + */
  70270. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  70271. +{
  70272. + uint8_t addr;
  70273. + cfi_ep_t *ep;
  70274. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  70275. + uint16_t *pVals;
  70276. + uint32_t desccount;
  70277. + int i;
  70278. + uint16_t mps;
  70279. +
  70280. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  70281. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  70282. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  70283. +
  70284. + /* Check the DMA descriptor count */
  70285. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  70286. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  70287. + __func__, MAX_DMA_DESCS_PER_EP);
  70288. + return -DWC_E_INVALID;
  70289. + }
  70290. +
  70291. + addr = pConcatValHdr->bEndpointAddress;
  70292. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70293. + if (NULL == ep) {
  70294. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  70295. + __func__, addr);
  70296. + return -DWC_E_INVALID;
  70297. + }
  70298. +
  70299. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  70300. +
  70301. +#if 0
  70302. + for (i = 0; i < desccount; i++) {
  70303. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  70304. + }
  70305. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  70306. +#endif
  70307. +
  70308. + /* Check the wTxSizes to be less than or equal to the mps */
  70309. + for (i = 0; i < desccount; i++) {
  70310. + if (pVals[i] > mps) {
  70311. + CFI_INFO
  70312. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  70313. + __func__, i, pVals[i]);
  70314. + return -DWC_E_INVALID;
  70315. + }
  70316. + }
  70317. +
  70318. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  70319. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  70320. +
  70321. + /* Free the previously allocated storage for the wTxBytes */
  70322. + if (ep->bm_concat->wTxBytes) {
  70323. + DWC_FREE(ep->bm_concat->wTxBytes);
  70324. + }
  70325. +
  70326. + /* Allocate a new storage for the wTxBytes field */
  70327. + ep->bm_concat->wTxBytes =
  70328. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  70329. + if (NULL == ep->bm_concat->wTxBytes) {
  70330. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  70331. + return -DWC_E_NO_MEMORY;
  70332. + }
  70333. +
  70334. + /* Copy the new values into the wTxBytes filed */
  70335. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  70336. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  70337. +
  70338. + return 0;
  70339. +}
  70340. +
  70341. +/**
  70342. + * This function calculates the total of all FIFO sizes
  70343. + *
  70344. + * @param core_if Programming view of DWC_otg controller
  70345. + *
  70346. + * @return The total of data FIFO sizes.
  70347. + *
  70348. + */
  70349. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  70350. +{
  70351. + dwc_otg_core_params_t *params = core_if->core_params;
  70352. + uint16_t dfifo_total = 0;
  70353. + int i;
  70354. +
  70355. + /* The shared RxFIFO size */
  70356. + dfifo_total =
  70357. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  70358. +
  70359. + /* Add up each TxFIFO size to the total */
  70360. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70361. + dfifo_total += params->dev_tx_fifo_size[i];
  70362. + }
  70363. +
  70364. + return dfifo_total;
  70365. +}
  70366. +
  70367. +/**
  70368. + * This function returns Rx FIFO size
  70369. + *
  70370. + * @param core_if Programming view of DWC_otg controller
  70371. + *
  70372. + * @return The total of data FIFO sizes.
  70373. + *
  70374. + */
  70375. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  70376. +{
  70377. + switch (wValue >> 8) {
  70378. + case 0:
  70379. + return (core_if->pwron_rxfsiz <
  70380. + 32768) ? core_if->pwron_rxfsiz : 32768;
  70381. + break;
  70382. + case 1:
  70383. + return core_if->core_params->dev_rx_fifo_size;
  70384. + break;
  70385. + default:
  70386. + return -DWC_E_INVALID;
  70387. + break;
  70388. + }
  70389. +}
  70390. +
  70391. +/**
  70392. + * This function returns Tx FIFO size for IN EP
  70393. + *
  70394. + * @param core_if Programming view of DWC_otg controller
  70395. + *
  70396. + * @return The total of data FIFO sizes.
  70397. + *
  70398. + */
  70399. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  70400. +{
  70401. + dwc_otg_pcd_ep_t *ep;
  70402. +
  70403. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  70404. +
  70405. + if (NULL == ep) {
  70406. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  70407. + __func__, wValue & 0xff);
  70408. + return -DWC_E_INVALID;
  70409. + }
  70410. +
  70411. + if (!ep->dwc_ep.is_in) {
  70412. + CFI_INFO
  70413. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  70414. + __func__, wValue & 0xff);
  70415. + return -DWC_E_INVALID;
  70416. + }
  70417. +
  70418. + switch (wValue >> 8) {
  70419. + case 0:
  70420. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  70421. + [ep->dwc_ep.tx_fifo_num - 1] <
  70422. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  70423. + dwc_ep.tx_fifo_num
  70424. + - 1] : 32768;
  70425. + break;
  70426. + case 1:
  70427. + return GET_CORE_IF(pcd)->core_params->
  70428. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  70429. + break;
  70430. + default:
  70431. + return -DWC_E_INVALID;
  70432. + break;
  70433. + }
  70434. +}
  70435. +
  70436. +/**
  70437. + * This function checks if the submitted combination of
  70438. + * device mode FIFO sizes is possible or not.
  70439. + *
  70440. + * @param core_if Programming view of DWC_otg controller
  70441. + *
  70442. + * @return 1 if possible, 0 otherwise.
  70443. + *
  70444. + */
  70445. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  70446. +{
  70447. + uint16_t dfifo_actual = 0;
  70448. + dwc_otg_core_params_t *params = core_if->core_params;
  70449. + uint16_t start_addr = 0;
  70450. + int i;
  70451. +
  70452. + dfifo_actual =
  70453. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  70454. +
  70455. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70456. + dfifo_actual += params->dev_tx_fifo_size[i];
  70457. + }
  70458. +
  70459. + if (dfifo_actual > core_if->total_fifo_size) {
  70460. + return 0;
  70461. + }
  70462. +
  70463. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  70464. + return 0;
  70465. +
  70466. + if (params->dev_nperio_tx_fifo_size > 32768
  70467. + || params->dev_nperio_tx_fifo_size < 16)
  70468. + return 0;
  70469. +
  70470. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70471. +
  70472. + if (params->dev_tx_fifo_size[i] > 768
  70473. + || params->dev_tx_fifo_size[i] < 4)
  70474. + return 0;
  70475. + }
  70476. +
  70477. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  70478. + return 0;
  70479. + start_addr = params->dev_rx_fifo_size;
  70480. +
  70481. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  70482. + return 0;
  70483. + start_addr += params->dev_nperio_tx_fifo_size;
  70484. +
  70485. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70486. +
  70487. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  70488. + return 0;
  70489. + start_addr += params->dev_tx_fifo_size[i];
  70490. + }
  70491. +
  70492. + return 1;
  70493. +}
  70494. +
  70495. +/**
  70496. + * This function resizes Device mode FIFOs
  70497. + *
  70498. + * @param core_if Programming view of DWC_otg controller
  70499. + *
  70500. + * @return 1 if successful, 0 otherwise
  70501. + *
  70502. + */
  70503. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  70504. +{
  70505. + int i = 0;
  70506. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  70507. + dwc_otg_core_params_t *params = core_if->core_params;
  70508. + uint32_t rx_fifo_size;
  70509. + fifosize_data_t nptxfifosize;
  70510. + fifosize_data_t txfifosize[15];
  70511. +
  70512. + uint32_t rx_fsz_bak;
  70513. + uint32_t nptxfsz_bak;
  70514. + uint32_t txfsz_bak[15];
  70515. +
  70516. + uint16_t start_address;
  70517. + uint8_t retval = 1;
  70518. +
  70519. + if (!check_fifo_sizes(core_if)) {
  70520. + return 0;
  70521. + }
  70522. +
  70523. + /* Configure data FIFO sizes */
  70524. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  70525. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  70526. + rx_fifo_size = params->dev_rx_fifo_size;
  70527. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  70528. +
  70529. + /*
  70530. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  70531. + * Indexes of the FIFO size module parameters in the
  70532. + * dev_tx_fifo_size array and the FIFO size registers in
  70533. + * the dtxfsiz array run from 0 to 14.
  70534. + */
  70535. +
  70536. + /* Non-periodic Tx FIFO */
  70537. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  70538. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  70539. + start_address = params->dev_rx_fifo_size;
  70540. + nptxfifosize.b.startaddr = start_address;
  70541. +
  70542. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  70543. +
  70544. + start_address += nptxfifosize.b.depth;
  70545. +
  70546. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70547. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  70548. +
  70549. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  70550. + txfifosize[i].b.startaddr = start_address;
  70551. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  70552. + txfifosize[i].d32);
  70553. +
  70554. + start_address += txfifosize[i].b.depth;
  70555. + }
  70556. +
  70557. + /** Check if register values are set correctly */
  70558. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  70559. + retval = 0;
  70560. + }
  70561. +
  70562. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  70563. + retval = 0;
  70564. + }
  70565. +
  70566. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70567. + if (txfifosize[i].d32 !=
  70568. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  70569. + retval = 0;
  70570. + }
  70571. + }
  70572. +
  70573. + /** If register values are not set correctly, reset old values */
  70574. + if (retval == 0) {
  70575. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  70576. +
  70577. + /* Non-periodic Tx FIFO */
  70578. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  70579. +
  70580. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  70581. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  70582. + txfsz_bak[i]);
  70583. + }
  70584. + }
  70585. + } else {
  70586. + return 0;
  70587. + }
  70588. +
  70589. + /* Flush the FIFOs */
  70590. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  70591. + dwc_otg_flush_rx_fifo(core_if);
  70592. +
  70593. + return retval;
  70594. +}
  70595. +
  70596. +/**
  70597. + * This function sets a new value for the buffer Alignment setup.
  70598. + */
  70599. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  70600. +{
  70601. + int retval;
  70602. + uint32_t fsiz;
  70603. + uint16_t size;
  70604. + uint16_t ep_addr;
  70605. + dwc_otg_pcd_ep_t *ep;
  70606. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  70607. + tx_fifo_size_setup_t *ptxfifoval;
  70608. +
  70609. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  70610. + ep_addr = ptxfifoval->bEndpointAddress;
  70611. + size = ptxfifoval->wDepth;
  70612. +
  70613. + ep = get_ep_by_addr(pcd, ep_addr);
  70614. +
  70615. + CFI_INFO
  70616. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  70617. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  70618. +
  70619. + if (NULL == ep) {
  70620. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  70621. + __func__, ep_addr);
  70622. + return -DWC_E_INVALID;
  70623. + }
  70624. +
  70625. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  70626. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  70627. +
  70628. + if (resize_fifos(GET_CORE_IF(pcd))) {
  70629. + retval = 0;
  70630. + } else {
  70631. + CFI_INFO
  70632. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  70633. + __func__, ep_addr);
  70634. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  70635. + retval = -DWC_E_INVALID;
  70636. + }
  70637. +
  70638. + return retval;
  70639. +}
  70640. +
  70641. +/**
  70642. + * This function sets a new value for the buffer Alignment setup.
  70643. + */
  70644. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  70645. +{
  70646. + int retval;
  70647. + uint32_t fsiz;
  70648. + uint16_t size;
  70649. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  70650. + rx_fifo_size_setup_t *prxfifoval;
  70651. +
  70652. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  70653. + size = prxfifoval->wDepth;
  70654. +
  70655. + fsiz = params->dev_rx_fifo_size;
  70656. + params->dev_rx_fifo_size = size;
  70657. +
  70658. + if (resize_fifos(GET_CORE_IF(pcd))) {
  70659. + retval = 0;
  70660. + } else {
  70661. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  70662. + __func__);
  70663. + params->dev_rx_fifo_size = fsiz;
  70664. + retval = -DWC_E_INVALID;
  70665. + }
  70666. +
  70667. + return retval;
  70668. +}
  70669. +
  70670. +/**
  70671. + * This function reads the SG of an EP's buffer setup into the buffer buf
  70672. + */
  70673. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70674. + struct cfi_usb_ctrlrequest *req)
  70675. +{
  70676. + int retval = -DWC_E_INVALID;
  70677. + uint8_t addr;
  70678. + cfi_ep_t *ep;
  70679. +
  70680. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70681. + addr = req->wValue & 0xFF;
  70682. + if (addr == 0) /* The address should be non-zero */
  70683. + return retval;
  70684. +
  70685. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70686. + if (NULL == ep) {
  70687. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70688. + __func__, addr);
  70689. + return retval;
  70690. + }
  70691. +
  70692. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  70693. + retval = BS_SG_VAL_DESC_LEN;
  70694. + return retval;
  70695. +}
  70696. +
  70697. +/**
  70698. + * This function reads the Concatenation value of an EP's buffer mode into
  70699. + * the buffer buf
  70700. + */
  70701. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70702. + struct cfi_usb_ctrlrequest *req)
  70703. +{
  70704. + int retval = -DWC_E_INVALID;
  70705. + uint8_t addr;
  70706. + cfi_ep_t *ep;
  70707. + uint8_t desc_count;
  70708. +
  70709. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70710. + addr = req->wValue & 0xFF;
  70711. + if (addr == 0) /* The address should be non-zero */
  70712. + return retval;
  70713. +
  70714. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70715. + if (NULL == ep) {
  70716. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70717. + __func__, addr);
  70718. + return retval;
  70719. + }
  70720. +
  70721. + /* Copy the header to the buffer */
  70722. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  70723. + /* Advance the buffer pointer by the header size */
  70724. + buf += BS_CONCAT_VAL_HDR_LEN;
  70725. +
  70726. + desc_count = ep->bm_concat->hdr.bDescCount;
  70727. + /* Copy alll the wTxBytes to the buffer */
  70728. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  70729. +
  70730. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  70731. + return retval;
  70732. +}
  70733. +
  70734. +/**
  70735. + * This function reads the buffer Alignment value of an EP's buffer mode into
  70736. + * the buffer buf
  70737. + *
  70738. + * @return The total number of bytes copied to the buffer or negative error code.
  70739. + */
  70740. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  70741. + struct cfi_usb_ctrlrequest *req)
  70742. +{
  70743. + int retval = -DWC_E_INVALID;
  70744. + uint8_t addr;
  70745. + cfi_ep_t *ep;
  70746. +
  70747. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  70748. + addr = req->wValue & 0xFF;
  70749. + if (addr == 0) /* The address should be non-zero */
  70750. + return retval;
  70751. +
  70752. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  70753. + if (NULL == ep) {
  70754. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  70755. + __func__, addr);
  70756. + return retval;
  70757. + }
  70758. +
  70759. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  70760. + retval = BS_ALIGN_VAL_HDR_LEN;
  70761. +
  70762. + return retval;
  70763. +}
  70764. +
  70765. +/**
  70766. + * This function sets a new value for the specified feature
  70767. + *
  70768. + * @param pcd A pointer to the PCD object
  70769. + *
  70770. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  70771. + */
  70772. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  70773. +{
  70774. + int retval = -DWC_E_NOT_SUPPORTED;
  70775. + uint16_t wIndex, wValue;
  70776. + uint8_t bRequest;
  70777. + struct dwc_otg_core_if *coreif;
  70778. + cfiobject_t *cfi = pcd->cfi;
  70779. + struct cfi_usb_ctrlrequest *ctrl_req;
  70780. + uint8_t *buf;
  70781. + ctrl_req = &cfi->ctrl_req;
  70782. +
  70783. + buf = pcd->cfi->ctrl_req.data;
  70784. +
  70785. + coreif = GET_CORE_IF(pcd);
  70786. + bRequest = ctrl_req->bRequest;
  70787. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  70788. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  70789. +
  70790. + /* See which feature is to be modified */
  70791. + switch (wIndex) {
  70792. + case FT_ID_DMA_BUFFER_SETUP:
  70793. + /* Modify the feature */
  70794. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  70795. + return retval;
  70796. +
  70797. + /* And send this request to the gadget */
  70798. + cfi->need_gadget_att = 1;
  70799. + break;
  70800. +
  70801. + case FT_ID_DMA_BUFF_ALIGN:
  70802. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  70803. + return retval;
  70804. + cfi->need_gadget_att = 1;
  70805. + break;
  70806. +
  70807. + case FT_ID_DMA_CONCAT_SETUP:
  70808. + /* Modify the feature */
  70809. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  70810. + return retval;
  70811. + cfi->need_gadget_att = 1;
  70812. + break;
  70813. +
  70814. + case FT_ID_DMA_CIRCULAR:
  70815. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  70816. + break;
  70817. +
  70818. + case FT_ID_THRESHOLD_SETUP:
  70819. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  70820. + break;
  70821. +
  70822. + case FT_ID_DFIFO_DEPTH:
  70823. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  70824. + break;
  70825. +
  70826. + case FT_ID_TX_FIFO_DEPTH:
  70827. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  70828. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  70829. + return retval;
  70830. + cfi->need_gadget_att = 0;
  70831. + break;
  70832. +
  70833. + case FT_ID_RX_FIFO_DEPTH:
  70834. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  70835. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  70836. + return retval;
  70837. + cfi->need_gadget_att = 0;
  70838. + break;
  70839. + }
  70840. +
  70841. + return retval;
  70842. +}
  70843. +
  70844. +#endif //DWC_UTE_CFI
  70845. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  70846. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  70847. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2015-03-09 10:39:33.214893718 +0100
  70848. @@ -0,0 +1,320 @@
  70849. +/* ==========================================================================
  70850. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  70851. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  70852. + * otherwise expressly agreed to in writing between Synopsys and you.
  70853. + *
  70854. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  70855. + * any End User Software License Agreement or Agreement for Licensed Product
  70856. + * with Synopsys or any supplement thereto. You are permitted to use and
  70857. + * redistribute this Software in source and binary forms, with or without
  70858. + * modification, provided that redistributions of source code must retain this
  70859. + * notice. You may not view, use, disclose, copy or distribute this file or
  70860. + * any information contained herein except pursuant to this license grant from
  70861. + * Synopsys. If you do not agree with this notice, including the disclaimer
  70862. + * below, then you are not authorized to use the Software.
  70863. + *
  70864. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  70865. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  70866. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70867. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  70868. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  70869. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  70870. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  70871. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  70872. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  70873. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  70874. + * DAMAGE.
  70875. + * ========================================================================== */
  70876. +
  70877. +#if !defined(__DWC_OTG_CFI_H__)
  70878. +#define __DWC_OTG_CFI_H__
  70879. +
  70880. +#include "dwc_otg_pcd.h"
  70881. +#include "dwc_cfi_common.h"
  70882. +
  70883. +/**
  70884. + * @file
  70885. + * This file contains the CFI related OTG PCD specific common constants,
  70886. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  70887. + * optional interface for internal testing purposes that a DUT may implement to
  70888. + * support testing of configurable features.
  70889. + *
  70890. + */
  70891. +
  70892. +struct dwc_otg_pcd;
  70893. +struct dwc_otg_pcd_ep;
  70894. +
  70895. +/** OTG CFI Features (properties) ID constants */
  70896. +/** This is a request for all Core Features */
  70897. +#define FT_ID_DMA_MODE 0x0001
  70898. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  70899. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  70900. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  70901. +#define FT_ID_DMA_CIRCULAR 0x0005
  70902. +#define FT_ID_THRESHOLD_SETUP 0x0006
  70903. +#define FT_ID_DFIFO_DEPTH 0x0007
  70904. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  70905. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  70906. +
  70907. +/**********************************************************/
  70908. +#define CFI_INFO_DEF
  70909. +
  70910. +#ifdef CFI_INFO_DEF
  70911. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  70912. +#else
  70913. +#define CFI_INFO(fmt...)
  70914. +#endif
  70915. +
  70916. +#define min(x,y) ({ \
  70917. + x < y ? x : y; })
  70918. +
  70919. +#define max(x,y) ({ \
  70920. + x > y ? x : y; })
  70921. +
  70922. +/**
  70923. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  70924. + * also used for setting up a buffer for Circular DDMA.
  70925. + */
  70926. +struct _ddma_sg_buffer_setup {
  70927. +#define BS_SG_VAL_DESC_LEN 6
  70928. + /* The OUT EP address */
  70929. + uint8_t bOutEndpointAddress;
  70930. + /* The IN EP address */
  70931. + uint8_t bInEndpointAddress;
  70932. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  70933. + uint8_t bOffset;
  70934. + /* The number of transfer segments (a DMA descriptors per each segment) */
  70935. + uint8_t bCount;
  70936. + /* Size (in byte) of each transfer segment */
  70937. + uint16_t wSize;
  70938. +} __attribute__ ((packed));
  70939. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  70940. +
  70941. +/** Descriptor DMA Concatenation Buffer setup structure */
  70942. +struct _ddma_concat_buffer_setup_hdr {
  70943. +#define BS_CONCAT_VAL_HDR_LEN 4
  70944. + /* The endpoint for which the buffer is to be set up */
  70945. + uint8_t bEndpointAddress;
  70946. + /* The count of descriptors to be used */
  70947. + uint8_t bDescCount;
  70948. + /* The total size of the transfer */
  70949. + uint16_t wSize;
  70950. +} __attribute__ ((packed));
  70951. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  70952. +
  70953. +/** Descriptor DMA Concatenation Buffer setup structure */
  70954. +struct _ddma_concat_buffer_setup {
  70955. + /* The SG header */
  70956. + ddma_concat_buffer_setup_hdr_t hdr;
  70957. +
  70958. + /* The XFER sizes pointer (allocated dynamically) */
  70959. + uint16_t *wTxBytes;
  70960. +} __attribute__ ((packed));
  70961. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  70962. +
  70963. +/** Descriptor DMA Alignment Buffer setup structure */
  70964. +struct _ddma_align_buffer_setup {
  70965. +#define BS_ALIGN_VAL_HDR_LEN 2
  70966. + uint8_t bEndpointAddress;
  70967. + uint8_t bAlign;
  70968. +} __attribute__ ((packed));
  70969. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  70970. +
  70971. +/** Transmit FIFO Size setup structure */
  70972. +struct _tx_fifo_size_setup {
  70973. + uint8_t bEndpointAddress;
  70974. + uint16_t wDepth;
  70975. +} __attribute__ ((packed));
  70976. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  70977. +
  70978. +/** Transmit FIFO Size setup structure */
  70979. +struct _rx_fifo_size_setup {
  70980. + uint16_t wDepth;
  70981. +} __attribute__ ((packed));
  70982. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  70983. +
  70984. +/**
  70985. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  70986. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  70987. + * to the data returned in the data stage of a 3-stage Control Write requests.
  70988. + */
  70989. +struct cfi_usb_ctrlrequest {
  70990. + uint8_t bRequestType;
  70991. + uint8_t bRequest;
  70992. + uint16_t wValue;
  70993. + uint16_t wIndex;
  70994. + uint16_t wLength;
  70995. + uint8_t *data;
  70996. +} UPACKED;
  70997. +
  70998. +/*---------------------------------------------------------------------------*/
  70999. +
  71000. +/**
  71001. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  71002. + * This structure is used to store the buffer setup data for any
  71003. + * enabled endpoint in the PCD.
  71004. + */
  71005. +struct cfi_ep {
  71006. + /* Entry for the list container */
  71007. + dwc_list_link_t lh;
  71008. + /* Pointer to the active PCD endpoint structure */
  71009. + struct dwc_otg_pcd_ep *ep;
  71010. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  71011. + struct dwc_otg_dma_desc *dma_desc_last;
  71012. + /* The SG feature value */
  71013. + ddma_sg_buffer_setup_t *bm_sg;
  71014. + /* The Circular feature value */
  71015. + ddma_sg_buffer_setup_t *bm_circ;
  71016. + /* The Concatenation feature value */
  71017. + ddma_concat_buffer_setup_t *bm_concat;
  71018. + /* The Alignment feature value */
  71019. + ddma_align_buffer_setup_t *bm_align;
  71020. + /* XFER length */
  71021. + uint32_t xfer_len;
  71022. + /*
  71023. + * Count of DMA descriptors currently used.
  71024. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  71025. + * defined in the dwc_otg_cil.h
  71026. + */
  71027. + uint32_t desc_count;
  71028. +};
  71029. +typedef struct cfi_ep cfi_ep_t;
  71030. +
  71031. +typedef struct cfi_dma_buff {
  71032. +#define CFI_IN_BUF_LEN 1024
  71033. +#define CFI_OUT_BUF_LEN 1024
  71034. + dma_addr_t addr;
  71035. + uint8_t *buf;
  71036. +} cfi_dma_buff_t;
  71037. +
  71038. +struct cfiobject;
  71039. +
  71040. +/**
  71041. + * This is the interface for the CFI operations.
  71042. + *
  71043. + * @param ep_enable Called when any endpoint is enabled and activated.
  71044. + * @param release Called when the CFI object is released and it needs to correctly
  71045. + * deallocate the dynamic memory
  71046. + * @param ctrl_write_complete Called when the data stage of the request is complete
  71047. + */
  71048. +typedef struct cfi_ops {
  71049. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  71050. + struct dwc_otg_pcd_ep * ep);
  71051. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  71052. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  71053. + unsigned size, gfp_t flags);
  71054. + void (*release) (struct cfiobject * cfi);
  71055. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  71056. + struct dwc_otg_pcd * pcd);
  71057. + void (*build_descriptors) (struct cfiobject * cfi,
  71058. + struct dwc_otg_pcd * pcd,
  71059. + struct dwc_otg_pcd_ep * ep,
  71060. + dwc_otg_pcd_request_t * req);
  71061. +} cfi_ops_t;
  71062. +
  71063. +struct cfiobject {
  71064. + cfi_ops_t ops;
  71065. + struct dwc_otg_pcd *pcd;
  71066. + struct usb_gadget *gadget;
  71067. +
  71068. + /* Buffers used to send/receive CFI-related request data */
  71069. + cfi_dma_buff_t buf_in;
  71070. + cfi_dma_buff_t buf_out;
  71071. +
  71072. + /* CFI specific Control request wrapper */
  71073. + struct cfi_usb_ctrlrequest ctrl_req;
  71074. +
  71075. + /* The list of active EP's in the PCD of type cfi_ep_t */
  71076. + dwc_list_link_t active_eps;
  71077. +
  71078. + /* This flag shall control the propagation of a specific request
  71079. + * to the gadget's processing routines.
  71080. + * 0 - no gadget handling
  71081. + * 1 - the gadget needs to know about this request (w/o completing a status
  71082. + * phase - just return a 0 to the _setup callback)
  71083. + */
  71084. + uint8_t need_gadget_att;
  71085. +
  71086. + /* Flag indicating whether the status IN phase needs to be
  71087. + * completed by the PCD
  71088. + */
  71089. + uint8_t need_status_in_complete;
  71090. +};
  71091. +typedef struct cfiobject cfiobject_t;
  71092. +
  71093. +#define DUMP_MSG
  71094. +
  71095. +#if defined(DUMP_MSG)
  71096. +static inline void dump_msg(const u8 * buf, unsigned int length)
  71097. +{
  71098. + unsigned int start, num, i;
  71099. + char line[52], *p;
  71100. +
  71101. + if (length >= 512)
  71102. + return;
  71103. +
  71104. + start = 0;
  71105. + while (length > 0) {
  71106. + num = min(length, 16u);
  71107. + p = line;
  71108. + for (i = 0; i < num; ++i) {
  71109. + if (i == 8)
  71110. + *p++ = ' ';
  71111. + DWC_SPRINTF(p, " %02x", buf[i]);
  71112. + p += 3;
  71113. + }
  71114. + *p = 0;
  71115. + DWC_DEBUG("%6x: %s\n", start, line);
  71116. + buf += num;
  71117. + start += num;
  71118. + length -= num;
  71119. + }
  71120. +}
  71121. +#else
  71122. +static inline void dump_msg(const u8 * buf, unsigned int length)
  71123. +{
  71124. +}
  71125. +#endif
  71126. +
  71127. +/**
  71128. + * This function returns a pointer to cfi_ep_t object with the addr address.
  71129. + */
  71130. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  71131. + uint8_t addr)
  71132. +{
  71133. + struct cfi_ep *pcfiep;
  71134. + dwc_list_link_t *tmp;
  71135. +
  71136. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  71137. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  71138. +
  71139. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  71140. + return pcfiep;
  71141. + }
  71142. + }
  71143. +
  71144. + return NULL;
  71145. +}
  71146. +
  71147. +/**
  71148. + * This function returns a pointer to cfi_ep_t object that matches
  71149. + * the dwc_otg_pcd_ep object.
  71150. + */
  71151. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  71152. + struct dwc_otg_pcd_ep *ep)
  71153. +{
  71154. + struct cfi_ep *pcfiep = NULL;
  71155. + dwc_list_link_t *tmp;
  71156. +
  71157. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  71158. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  71159. + if (pcfiep->ep == ep) {
  71160. + return pcfiep;
  71161. + }
  71162. + }
  71163. + return NULL;
  71164. +}
  71165. +
  71166. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  71167. +
  71168. +#endif /* (__DWC_OTG_CFI_H__) */
  71169. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  71170. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  71171. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2015-03-10 17:26:51.302216687 +0100
  71172. @@ -0,0 +1,7151 @@
  71173. +/* ==========================================================================
  71174. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  71175. + * $Revision: #191 $
  71176. + * $Date: 2012/08/10 $
  71177. + * $Change: 2047372 $
  71178. + *
  71179. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  71180. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  71181. + * otherwise expressly agreed to in writing between Synopsys and you.
  71182. + *
  71183. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  71184. + * any End User Software License Agreement or Agreement for Licensed Product
  71185. + * with Synopsys or any supplement thereto. You are permitted to use and
  71186. + * redistribute this Software in source and binary forms, with or without
  71187. + * modification, provided that redistributions of source code must retain this
  71188. + * notice. You may not view, use, disclose, copy or distribute this file or
  71189. + * any information contained herein except pursuant to this license grant from
  71190. + * Synopsys. If you do not agree with this notice, including the disclaimer
  71191. + * below, then you are not authorized to use the Software.
  71192. + *
  71193. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  71194. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  71195. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  71196. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  71197. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  71198. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  71199. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  71200. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  71201. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  71202. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  71203. + * DAMAGE.
  71204. + * ========================================================================== */
  71205. +
  71206. +/** @file
  71207. + *
  71208. + * The Core Interface Layer provides basic services for accessing and
  71209. + * managing the DWC_otg hardware. These services are used by both the
  71210. + * Host Controller Driver and the Peripheral Controller Driver.
  71211. + *
  71212. + * The CIL manages the memory map for the core so that the HCD and PCD
  71213. + * don't have to do this separately. It also handles basic tasks like
  71214. + * reading/writing the registers and data FIFOs in the controller.
  71215. + * Some of the data access functions provide encapsulation of several
  71216. + * operations required to perform a task, such as writing multiple
  71217. + * registers to start a transfer. Finally, the CIL performs basic
  71218. + * services that are not specific to either the host or device modes
  71219. + * of operation. These services include management of the OTG Host
  71220. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  71221. + * Diagnostic API is also provided to allow testing of the controller
  71222. + * hardware.
  71223. + *
  71224. + * The Core Interface Layer has the following requirements:
  71225. + * - Provides basic controller operations.
  71226. + * - Minimal use of OS services.
  71227. + * - The OS services used will be abstracted by using inline functions
  71228. + * or macros.
  71229. + *
  71230. + */
  71231. +
  71232. +#include "dwc_os.h"
  71233. +#include "dwc_otg_regs.h"
  71234. +#include "dwc_otg_cil.h"
  71235. +
  71236. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  71237. +
  71238. +/**
  71239. + * This function is called to initialize the DWC_otg CSR data
  71240. + * structures. The register addresses in the device and host
  71241. + * structures are initialized from the base address supplied by the
  71242. + * caller. The calling function must make the OS calls to get the
  71243. + * base address of the DWC_otg controller registers. The core_params
  71244. + * argument holds the parameters that specify how the core should be
  71245. + * configured.
  71246. + *
  71247. + * @param reg_base_addr Base address of DWC_otg core registers
  71248. + *
  71249. + */
  71250. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  71251. +{
  71252. + dwc_otg_core_if_t *core_if = 0;
  71253. + dwc_otg_dev_if_t *dev_if = 0;
  71254. + dwc_otg_host_if_t *host_if = 0;
  71255. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  71256. + int i = 0;
  71257. +
  71258. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  71259. +
  71260. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  71261. +
  71262. + if (core_if == NULL) {
  71263. + DWC_DEBUGPL(DBG_CIL,
  71264. + "Allocation of dwc_otg_core_if_t failed\n");
  71265. + return 0;
  71266. + }
  71267. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  71268. +
  71269. + /*
  71270. + * Allocate the Device Mode structures.
  71271. + */
  71272. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  71273. +
  71274. + if (dev_if == NULL) {
  71275. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  71276. + DWC_FREE(core_if);
  71277. + return 0;
  71278. + }
  71279. +
  71280. + dev_if->dev_global_regs =
  71281. + (dwc_otg_device_global_regs_t *) (reg_base +
  71282. + DWC_DEV_GLOBAL_REG_OFFSET);
  71283. +
  71284. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71285. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  71286. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  71287. + (i * DWC_EP_REG_OFFSET));
  71288. +
  71289. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  71290. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  71291. + (i * DWC_EP_REG_OFFSET));
  71292. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  71293. + i, &dev_if->in_ep_regs[i]->diepctl);
  71294. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  71295. + i, &dev_if->out_ep_regs[i]->doepctl);
  71296. + }
  71297. +
  71298. + dev_if->speed = 0; // unknown
  71299. +
  71300. + core_if->dev_if = dev_if;
  71301. +
  71302. + /*
  71303. + * Allocate the Host Mode structures.
  71304. + */
  71305. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  71306. +
  71307. + if (host_if == NULL) {
  71308. + DWC_DEBUGPL(DBG_CIL,
  71309. + "Allocation of dwc_otg_host_if_t failed\n");
  71310. + DWC_FREE(dev_if);
  71311. + DWC_FREE(core_if);
  71312. + return 0;
  71313. + }
  71314. +
  71315. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  71316. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  71317. +
  71318. + host_if->hprt0 =
  71319. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  71320. +
  71321. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71322. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  71323. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  71324. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  71325. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  71326. + i, &host_if->hc_regs[i]->hcchar);
  71327. + }
  71328. +
  71329. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  71330. + core_if->host_if = host_if;
  71331. +
  71332. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71333. + core_if->data_fifo[i] =
  71334. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  71335. + (i * DWC_OTG_DATA_FIFO_SIZE));
  71336. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  71337. + i, (unsigned long)core_if->data_fifo[i]);
  71338. + }
  71339. +
  71340. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  71341. +
  71342. + /* Initiate lx_state to L3 disconnected state */
  71343. + core_if->lx_state = DWC_OTG_L3;
  71344. + /*
  71345. + * Store the contents of the hardware configuration registers here for
  71346. + * easy access later.
  71347. + */
  71348. + core_if->hwcfg1.d32 =
  71349. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  71350. + core_if->hwcfg2.d32 =
  71351. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  71352. + core_if->hwcfg3.d32 =
  71353. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  71354. + core_if->hwcfg4.d32 =
  71355. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  71356. +
  71357. + /* Force host mode to get HPTXFSIZ exact power on value */
  71358. + {
  71359. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  71360. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  71361. + gusbcfg.b.force_host_mode = 1;
  71362. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  71363. + dwc_mdelay(100);
  71364. + core_if->hptxfsiz.d32 =
  71365. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  71366. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  71367. + gusbcfg.b.force_host_mode = 0;
  71368. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  71369. + dwc_mdelay(100);
  71370. + }
  71371. +
  71372. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  71373. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  71374. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  71375. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  71376. +
  71377. + core_if->hcfg.d32 =
  71378. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  71379. + core_if->dcfg.d32 =
  71380. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  71381. +
  71382. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  71383. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  71384. +
  71385. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  71386. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  71387. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  71388. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  71389. + core_if->hwcfg2.b.num_host_chan);
  71390. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  71391. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  71392. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  71393. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  71394. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  71395. + core_if->hwcfg2.b.dev_token_q_depth);
  71396. +
  71397. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  71398. + core_if->hwcfg3.b.dfifo_depth);
  71399. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  71400. + core_if->hwcfg3.b.xfer_size_cntr_width);
  71401. +
  71402. + /*
  71403. + * Set the SRP sucess bit for FS-I2c
  71404. + */
  71405. + core_if->srp_success = 0;
  71406. + core_if->srp_timer_started = 0;
  71407. +
  71408. + /*
  71409. + * Create new workqueue and init works
  71410. + */
  71411. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  71412. + if (core_if->wq_otg == 0) {
  71413. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  71414. + DWC_FREE(host_if);
  71415. + DWC_FREE(dev_if);
  71416. + DWC_FREE(core_if);
  71417. + return 0;
  71418. + }
  71419. +
  71420. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  71421. +
  71422. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  71423. + (core_if->snpsid >> 12 & 0xF),
  71424. + (core_if->snpsid >> 8 & 0xF),
  71425. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  71426. +
  71427. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  71428. + w_wakeup_detected, core_if);
  71429. + if (core_if->wkp_timer == 0) {
  71430. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  71431. + DWC_FREE(host_if);
  71432. + DWC_FREE(dev_if);
  71433. + DWC_WORKQ_FREE(core_if->wq_otg);
  71434. + DWC_FREE(core_if);
  71435. + return 0;
  71436. + }
  71437. +
  71438. + if (dwc_otg_setup_params(core_if)) {
  71439. + DWC_WARN("Error while setting core params\n");
  71440. + }
  71441. +
  71442. + core_if->hibernation_suspend = 0;
  71443. +
  71444. + /** ADP initialization */
  71445. + dwc_otg_adp_init(core_if);
  71446. +
  71447. + return core_if;
  71448. +}
  71449. +
  71450. +/**
  71451. + * This function frees the structures allocated by dwc_otg_cil_init().
  71452. + *
  71453. + * @param core_if The core interface pointer returned from
  71454. + * dwc_otg_cil_init().
  71455. + *
  71456. + */
  71457. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  71458. +{
  71459. + dctl_data_t dctl = {.d32 = 0 };
  71460. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  71461. +
  71462. + /* Disable all interrupts */
  71463. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  71464. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  71465. +
  71466. + dctl.b.sftdiscon = 1;
  71467. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  71468. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  71469. + dctl.d32);
  71470. + }
  71471. +
  71472. + if (core_if->wq_otg) {
  71473. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  71474. + DWC_WORKQ_FREE(core_if->wq_otg);
  71475. + }
  71476. + if (core_if->dev_if) {
  71477. + DWC_FREE(core_if->dev_if);
  71478. + }
  71479. + if (core_if->host_if) {
  71480. + DWC_FREE(core_if->host_if);
  71481. + }
  71482. +
  71483. + /** Remove ADP Stuff */
  71484. + dwc_otg_adp_remove(core_if);
  71485. + if (core_if->core_params) {
  71486. + DWC_FREE(core_if->core_params);
  71487. + }
  71488. + if (core_if->wkp_timer) {
  71489. + DWC_TIMER_FREE(core_if->wkp_timer);
  71490. + }
  71491. + if (core_if->srp_timer) {
  71492. + DWC_TIMER_FREE(core_if->srp_timer);
  71493. + }
  71494. + DWC_FREE(core_if);
  71495. +}
  71496. +
  71497. +/**
  71498. + * This function enables the controller's Global Interrupt in the AHB Config
  71499. + * register.
  71500. + *
  71501. + * @param core_if Programming view of DWC_otg controller.
  71502. + */
  71503. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  71504. +{
  71505. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  71506. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  71507. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  71508. +}
  71509. +
  71510. +/**
  71511. + * This function disables the controller's Global Interrupt in the AHB Config
  71512. + * register.
  71513. + *
  71514. + * @param core_if Programming view of DWC_otg controller.
  71515. + */
  71516. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  71517. +{
  71518. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  71519. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  71520. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  71521. +}
  71522. +
  71523. +/**
  71524. + * This function initializes the commmon interrupts, used in both
  71525. + * device and host modes.
  71526. + *
  71527. + * @param core_if Programming view of the DWC_otg controller
  71528. + *
  71529. + */
  71530. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  71531. +{
  71532. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  71533. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71534. +
  71535. + /* Clear any pending OTG Interrupts */
  71536. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  71537. +
  71538. + /* Clear any pending interrupts */
  71539. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  71540. +
  71541. + /*
  71542. + * Enable the interrupts in the GINTMSK.
  71543. + */
  71544. + intr_mask.b.modemismatch = 1;
  71545. + intr_mask.b.otgintr = 1;
  71546. +
  71547. + if (!core_if->dma_enable) {
  71548. + intr_mask.b.rxstsqlvl = 1;
  71549. + }
  71550. +
  71551. + intr_mask.b.conidstschng = 1;
  71552. + intr_mask.b.wkupintr = 1;
  71553. + intr_mask.b.disconnect = 0;
  71554. + intr_mask.b.usbsuspend = 1;
  71555. + intr_mask.b.sessreqintr = 1;
  71556. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71557. + if (core_if->core_params->lpm_enable) {
  71558. + intr_mask.b.lpmtranrcvd = 1;
  71559. + }
  71560. +#endif
  71561. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  71562. +}
  71563. +
  71564. +/*
  71565. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  71566. + * Hibernation. This function is for exiting from Device mode hibernation by
  71567. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  71568. + * @param core_if Programming view of DWC_otg controller.
  71569. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  71570. + * @param reset - indicates whether resume is initiated by Reset.
  71571. + */
  71572. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  71573. + int rem_wakeup, int reset)
  71574. +{
  71575. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71576. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71577. + dctl_data_t dctl = {.d32 = 0 };
  71578. +
  71579. + int timeout = 2000;
  71580. +
  71581. + if (!core_if->hibernation_suspend) {
  71582. + DWC_PRINTF("Already exited from Hibernation\n");
  71583. + return 1;
  71584. + }
  71585. +
  71586. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  71587. + /* Switch-on voltage to the core */
  71588. + gpwrdn.b.pwrdnswtch = 1;
  71589. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71590. + dwc_udelay(10);
  71591. +
  71592. + /* Reset core */
  71593. + gpwrdn.d32 = 0;
  71594. + gpwrdn.b.pwrdnrstn = 1;
  71595. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71596. + dwc_udelay(10);
  71597. +
  71598. + /* Assert Restore signal */
  71599. + gpwrdn.d32 = 0;
  71600. + gpwrdn.b.restore = 1;
  71601. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71602. + dwc_udelay(10);
  71603. +
  71604. + /* Disable power clamps */
  71605. + gpwrdn.d32 = 0;
  71606. + gpwrdn.b.pwrdnclmp = 1;
  71607. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71608. +
  71609. + if (rem_wakeup) {
  71610. + dwc_udelay(70);
  71611. + }
  71612. +
  71613. + /* Deassert Reset core */
  71614. + gpwrdn.d32 = 0;
  71615. + gpwrdn.b.pwrdnrstn = 1;
  71616. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71617. + dwc_udelay(10);
  71618. +
  71619. + /* Disable PMU interrupt */
  71620. + gpwrdn.d32 = 0;
  71621. + gpwrdn.b.pmuintsel = 1;
  71622. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71623. +
  71624. + /* Mask interrupts from gpwrdn */
  71625. + gpwrdn.d32 = 0;
  71626. + gpwrdn.b.connect_det_msk = 1;
  71627. + gpwrdn.b.srp_det_msk = 1;
  71628. + gpwrdn.b.disconn_det_msk = 1;
  71629. + gpwrdn.b.rst_det_msk = 1;
  71630. + gpwrdn.b.lnstchng_msk = 1;
  71631. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71632. +
  71633. + /* Indicates that we are going out from hibernation */
  71634. + core_if->hibernation_suspend = 0;
  71635. +
  71636. + /*
  71637. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  71638. + * indicates restore from remote_wakeup
  71639. + */
  71640. + restore_essential_regs(core_if, rem_wakeup, 0);
  71641. +
  71642. + /*
  71643. + * Wait a little for seeing new value of variable hibernation_suspend if
  71644. + * Restore done interrupt received before polling
  71645. + */
  71646. + dwc_udelay(10);
  71647. +
  71648. + if (core_if->hibernation_suspend == 0) {
  71649. + /*
  71650. + * Wait For Restore_done Interrupt. This mechanism of polling the
  71651. + * interrupt is introduced to avoid any possible race conditions
  71652. + */
  71653. + do {
  71654. + gintsts_data_t gintsts;
  71655. + gintsts.d32 =
  71656. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71657. + if (gintsts.b.restoredone) {
  71658. + gintsts.d32 = 0;
  71659. + gintsts.b.restoredone = 1;
  71660. + DWC_WRITE_REG32(&core_if->core_global_regs->
  71661. + gintsts, gintsts.d32);
  71662. + DWC_PRINTF("Restore Done Interrupt seen\n");
  71663. + break;
  71664. + }
  71665. + dwc_udelay(10);
  71666. + } while (--timeout);
  71667. + if (!timeout) {
  71668. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  71669. + }
  71670. + }
  71671. + /* Clear all pending interupts */
  71672. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71673. +
  71674. + /* De-assert Restore */
  71675. + gpwrdn.d32 = 0;
  71676. + gpwrdn.b.restore = 1;
  71677. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71678. + dwc_udelay(10);
  71679. +
  71680. + if (!rem_wakeup) {
  71681. + pcgcctl.d32 = 0;
  71682. + pcgcctl.b.rstpdwnmodule = 1;
  71683. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  71684. + }
  71685. +
  71686. + /* Restore GUSBCFG and DCFG */
  71687. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  71688. + core_if->gr_backup->gusbcfg_local);
  71689. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  71690. + core_if->dr_backup->dcfg);
  71691. +
  71692. + /* De-assert Wakeup Logic */
  71693. + gpwrdn.d32 = 0;
  71694. + gpwrdn.b.pmuactv = 1;
  71695. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71696. + dwc_udelay(10);
  71697. +
  71698. + if (!rem_wakeup) {
  71699. + /* Set Device programming done bit */
  71700. + dctl.b.pwronprgdone = 1;
  71701. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  71702. + } else {
  71703. + /* Start Remote Wakeup Signaling */
  71704. + dctl.d32 = core_if->dr_backup->dctl;
  71705. + dctl.b.rmtwkupsig = 1;
  71706. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  71707. + }
  71708. +
  71709. + dwc_mdelay(2);
  71710. + /* Clear all pending interupts */
  71711. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71712. +
  71713. + /* Restore global registers */
  71714. + dwc_otg_restore_global_regs(core_if);
  71715. + /* Restore device global registers */
  71716. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  71717. +
  71718. + if (rem_wakeup) {
  71719. + dwc_mdelay(7);
  71720. + dctl.d32 = 0;
  71721. + dctl.b.rmtwkupsig = 1;
  71722. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  71723. + }
  71724. +
  71725. + core_if->hibernation_suspend = 0;
  71726. + /* The core will be in ON STATE */
  71727. + core_if->lx_state = DWC_OTG_L0;
  71728. + DWC_PRINTF("Hibernation recovery completes here\n");
  71729. +
  71730. + return 1;
  71731. +}
  71732. +
  71733. +/*
  71734. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  71735. + * Hibernation. This function is for exiting from Host mode hibernation by
  71736. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  71737. + * @param core_if Programming view of DWC_otg controller.
  71738. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  71739. + * @param reset - indicates whether resume is initiated by Reset.
  71740. + */
  71741. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  71742. + int rem_wakeup, int reset)
  71743. +{
  71744. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  71745. + hprt0_data_t hprt0 = {.d32 = 0 };
  71746. +
  71747. + int timeout = 2000;
  71748. +
  71749. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  71750. + /* Switch-on voltage to the core */
  71751. + gpwrdn.b.pwrdnswtch = 1;
  71752. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71753. + dwc_udelay(10);
  71754. +
  71755. + /* Reset core */
  71756. + gpwrdn.d32 = 0;
  71757. + gpwrdn.b.pwrdnrstn = 1;
  71758. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71759. + dwc_udelay(10);
  71760. +
  71761. + /* Assert Restore signal */
  71762. + gpwrdn.d32 = 0;
  71763. + gpwrdn.b.restore = 1;
  71764. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71765. + dwc_udelay(10);
  71766. +
  71767. + /* Disable power clamps */
  71768. + gpwrdn.d32 = 0;
  71769. + gpwrdn.b.pwrdnclmp = 1;
  71770. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71771. +
  71772. + if (!rem_wakeup) {
  71773. + dwc_udelay(50);
  71774. + }
  71775. +
  71776. + /* Deassert Reset core */
  71777. + gpwrdn.d32 = 0;
  71778. + gpwrdn.b.pwrdnrstn = 1;
  71779. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  71780. + dwc_udelay(10);
  71781. +
  71782. + /* Disable PMU interrupt */
  71783. + gpwrdn.d32 = 0;
  71784. + gpwrdn.b.pmuintsel = 1;
  71785. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71786. +
  71787. + gpwrdn.d32 = 0;
  71788. + gpwrdn.b.connect_det_msk = 1;
  71789. + gpwrdn.b.srp_det_msk = 1;
  71790. + gpwrdn.b.disconn_det_msk = 1;
  71791. + gpwrdn.b.rst_det_msk = 1;
  71792. + gpwrdn.b.lnstchng_msk = 1;
  71793. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71794. +
  71795. + /* Indicates that we are going out from hibernation */
  71796. + core_if->hibernation_suspend = 0;
  71797. +
  71798. + /* Set Restore Essential Regs bit in PCGCCTL register */
  71799. + restore_essential_regs(core_if, rem_wakeup, 1);
  71800. +
  71801. + /* Wait a little for seeing new value of variable hibernation_suspend if
  71802. + * Restore done interrupt received before polling */
  71803. + dwc_udelay(10);
  71804. +
  71805. + if (core_if->hibernation_suspend == 0) {
  71806. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  71807. + * interrupt is introduced to avoid any possible race conditions
  71808. + */
  71809. + do {
  71810. + gintsts_data_t gintsts;
  71811. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  71812. + if (gintsts.b.restoredone) {
  71813. + gintsts.d32 = 0;
  71814. + gintsts.b.restoredone = 1;
  71815. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  71816. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  71817. + break;
  71818. + }
  71819. + dwc_udelay(10);
  71820. + } while (--timeout);
  71821. + if (!timeout) {
  71822. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  71823. + }
  71824. + }
  71825. +
  71826. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  71827. + core_if->hibernation_suspend = 0;
  71828. +
  71829. + /* This step is not described in functional spec but if not wait for this
  71830. + * delay, mismatch interrupts occurred because just after restore core is
  71831. + * in Device mode(gintsts.curmode == 0) */
  71832. + dwc_mdelay(100);
  71833. +
  71834. + /* Clear all pending interrupts */
  71835. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71836. +
  71837. + /* De-assert Restore */
  71838. + gpwrdn.d32 = 0;
  71839. + gpwrdn.b.restore = 1;
  71840. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71841. + dwc_udelay(10);
  71842. +
  71843. + /* Restore GUSBCFG and HCFG */
  71844. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  71845. + core_if->gr_backup->gusbcfg_local);
  71846. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  71847. + core_if->hr_backup->hcfg_local);
  71848. +
  71849. + /* De-assert Wakeup Logic */
  71850. + gpwrdn.d32 = 0;
  71851. + gpwrdn.b.pmuactv = 1;
  71852. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  71853. + dwc_udelay(10);
  71854. +
  71855. + /* Start the Resume operation by programming HPRT0 */
  71856. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71857. + hprt0.b.prtpwr = 1;
  71858. + hprt0.b.prtena = 0;
  71859. + hprt0.b.prtsusp = 0;
  71860. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71861. +
  71862. + DWC_PRINTF("Resume Starts Now\n");
  71863. + if (!reset) { // Indicates it is Resume Operation
  71864. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71865. + hprt0.b.prtres = 1;
  71866. + hprt0.b.prtpwr = 1;
  71867. + hprt0.b.prtena = 0;
  71868. + hprt0.b.prtsusp = 0;
  71869. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71870. +
  71871. + if (!rem_wakeup)
  71872. + hprt0.b.prtres = 0;
  71873. + /* Wait for Resume time and then program HPRT again */
  71874. + dwc_mdelay(100);
  71875. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71876. +
  71877. + } else { // Indicates it is Reset Operation
  71878. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  71879. + hprt0.b.prtrst = 1;
  71880. + hprt0.b.prtpwr = 1;
  71881. + hprt0.b.prtena = 0;
  71882. + hprt0.b.prtsusp = 0;
  71883. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71884. + /* Wait for Reset time and then program HPRT again */
  71885. + dwc_mdelay(60);
  71886. + hprt0.b.prtrst = 0;
  71887. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71888. + }
  71889. + /* Clear all interrupt status */
  71890. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  71891. + hprt0.b.prtconndet = 1;
  71892. + hprt0.b.prtenchng = 1;
  71893. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  71894. +
  71895. + /* Clear all pending interupts */
  71896. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  71897. +
  71898. + /* Restore global registers */
  71899. + dwc_otg_restore_global_regs(core_if);
  71900. + /* Restore host global registers */
  71901. + dwc_otg_restore_host_regs(core_if, reset);
  71902. +
  71903. + /* The core will be in ON STATE */
  71904. + core_if->lx_state = DWC_OTG_L0;
  71905. + DWC_PRINTF("Hibernation recovery is complete here\n");
  71906. + return 0;
  71907. +}
  71908. +
  71909. +/** Saves some register values into system memory. */
  71910. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  71911. +{
  71912. + struct dwc_otg_global_regs_backup *gr;
  71913. + int i;
  71914. +
  71915. + gr = core_if->gr_backup;
  71916. + if (!gr) {
  71917. + gr = DWC_ALLOC(sizeof(*gr));
  71918. + if (!gr) {
  71919. + return -DWC_E_NO_MEMORY;
  71920. + }
  71921. + core_if->gr_backup = gr;
  71922. + }
  71923. +
  71924. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  71925. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  71926. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  71927. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  71928. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  71929. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  71930. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  71931. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71932. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  71933. +#endif
  71934. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  71935. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  71936. + gr->gdfifocfg_local =
  71937. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  71938. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  71939. + gr->dtxfsiz_local[i] =
  71940. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  71941. + }
  71942. +
  71943. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  71944. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  71945. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  71946. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  71947. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  71948. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  71949. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  71950. + gr->gnptxfsiz_local);
  71951. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  71952. + gr->hptxfsiz_local);
  71953. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71954. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  71955. +#endif
  71956. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  71957. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  71958. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  71959. +
  71960. + return 0;
  71961. +}
  71962. +
  71963. +/** Saves GINTMSK register before setting the msk bits. */
  71964. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  71965. +{
  71966. + struct dwc_otg_global_regs_backup *gr;
  71967. +
  71968. + gr = core_if->gr_backup;
  71969. + if (!gr) {
  71970. + gr = DWC_ALLOC(sizeof(*gr));
  71971. + if (!gr) {
  71972. + return -DWC_E_NO_MEMORY;
  71973. + }
  71974. + core_if->gr_backup = gr;
  71975. + }
  71976. +
  71977. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  71978. +
  71979. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  71980. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  71981. +
  71982. + return 0;
  71983. +}
  71984. +
  71985. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  71986. +{
  71987. + struct dwc_otg_dev_regs_backup *dr;
  71988. + int i;
  71989. +
  71990. + dr = core_if->dr_backup;
  71991. + if (!dr) {
  71992. + dr = DWC_ALLOC(sizeof(*dr));
  71993. + if (!dr) {
  71994. + return -DWC_E_NO_MEMORY;
  71995. + }
  71996. + core_if->dr_backup = dr;
  71997. + }
  71998. +
  71999. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  72000. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  72001. + dr->daintmsk =
  72002. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  72003. + dr->diepmsk =
  72004. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  72005. + dr->doepmsk =
  72006. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  72007. +
  72008. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  72009. + dr->diepctl[i] =
  72010. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  72011. + dr->dieptsiz[i] =
  72012. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  72013. + dr->diepdma[i] =
  72014. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  72015. + }
  72016. +
  72017. + DWC_DEBUGPL(DBG_ANY,
  72018. + "=============Backing Host registers==============\n");
  72019. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  72020. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  72021. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  72022. + dr->daintmsk);
  72023. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  72024. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  72025. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  72026. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  72027. + dr->diepctl[i]);
  72028. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  72029. + i, dr->dieptsiz[i]);
  72030. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  72031. + dr->diepdma[i]);
  72032. + }
  72033. +
  72034. + return 0;
  72035. +}
  72036. +
  72037. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  72038. +{
  72039. + struct dwc_otg_host_regs_backup *hr;
  72040. + int i;
  72041. +
  72042. + hr = core_if->hr_backup;
  72043. + if (!hr) {
  72044. + hr = DWC_ALLOC(sizeof(*hr));
  72045. + if (!hr) {
  72046. + return -DWC_E_NO_MEMORY;
  72047. + }
  72048. + core_if->hr_backup = hr;
  72049. + }
  72050. +
  72051. + hr->hcfg_local =
  72052. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  72053. + hr->haintmsk_local =
  72054. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  72055. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  72056. + hr->hcintmsk_local[i] =
  72057. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  72058. + }
  72059. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  72060. + hr->hfir_local =
  72061. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  72062. +
  72063. + DWC_DEBUGPL(DBG_ANY,
  72064. + "=============Backing Host registers===============\n");
  72065. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  72066. + hr->hcfg_local);
  72067. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  72068. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  72069. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  72070. + hr->hcintmsk_local[i]);
  72071. + }
  72072. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  72073. + hr->hprt0_local);
  72074. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  72075. + hr->hfir_local);
  72076. +
  72077. + return 0;
  72078. +}
  72079. +
  72080. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  72081. +{
  72082. + struct dwc_otg_global_regs_backup *gr;
  72083. + int i;
  72084. +
  72085. + gr = core_if->gr_backup;
  72086. + if (!gr) {
  72087. + return -DWC_E_INVALID;
  72088. + }
  72089. +
  72090. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  72091. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  72092. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  72093. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  72094. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  72095. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  72096. + gr->gnptxfsiz_local);
  72097. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  72098. + gr->hptxfsiz_local);
  72099. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  72100. + gr->gdfifocfg_local);
  72101. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  72102. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  72103. + gr->dtxfsiz_local[i]);
  72104. + }
  72105. +
  72106. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  72107. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  72108. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  72109. + (gr->gahbcfg_local));
  72110. + return 0;
  72111. +}
  72112. +
  72113. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  72114. +{
  72115. + struct dwc_otg_dev_regs_backup *dr;
  72116. + int i;
  72117. +
  72118. + dr = core_if->dr_backup;
  72119. +
  72120. + if (!dr) {
  72121. + return -DWC_E_INVALID;
  72122. + }
  72123. +
  72124. + if (!rem_wakeup) {
  72125. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  72126. + dr->dctl);
  72127. + }
  72128. +
  72129. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  72130. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  72131. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  72132. +
  72133. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  72134. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  72135. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  72136. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  72137. + }
  72138. +
  72139. + return 0;
  72140. +}
  72141. +
  72142. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  72143. +{
  72144. + struct dwc_otg_host_regs_backup *hr;
  72145. + int i;
  72146. + hr = core_if->hr_backup;
  72147. +
  72148. + if (!hr) {
  72149. + return -DWC_E_INVALID;
  72150. + }
  72151. +
  72152. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  72153. + //if (!reset)
  72154. + //{
  72155. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  72156. + //}
  72157. +
  72158. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  72159. + hr->haintmsk_local);
  72160. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  72161. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  72162. + hr->hcintmsk_local[i]);
  72163. + }
  72164. +
  72165. + return 0;
  72166. +}
  72167. +
  72168. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  72169. +{
  72170. + struct dwc_otg_global_regs_backup *gr;
  72171. +
  72172. + gr = core_if->gr_backup;
  72173. +
  72174. + /* Restore values for LPM and I2C */
  72175. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72176. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  72177. +#endif
  72178. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  72179. +
  72180. + return 0;
  72181. +}
  72182. +
  72183. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  72184. +{
  72185. + struct dwc_otg_global_regs_backup *gr;
  72186. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72187. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  72188. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  72189. + gintmsk_data_t gintmsk = {.d32 = 0 };
  72190. +
  72191. + /* Restore LPM and I2C registers */
  72192. + restore_lpm_i2c_regs(core_if);
  72193. +
  72194. + /* Set PCGCCTL to 0 */
  72195. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  72196. +
  72197. + gr = core_if->gr_backup;
  72198. + /* Load restore values for [31:14] bits */
  72199. + DWC_WRITE_REG32(core_if->pcgcctl,
  72200. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  72201. +
  72202. + /* Umnask global Interrupt in GAHBCFG and restore it */
  72203. + gahbcfg.d32 = gr->gahbcfg_local;
  72204. + gahbcfg.b.glblintrmsk = 1;
  72205. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  72206. +
  72207. + /* Clear all pending interupts */
  72208. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  72209. +
  72210. + /* Unmask restore done interrupt */
  72211. + gintmsk.b.restoredone = 1;
  72212. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  72213. +
  72214. + /* Restore GUSBCFG and HCFG/DCFG */
  72215. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  72216. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  72217. +
  72218. + if (is_host) {
  72219. + hcfg_data_t hcfg = {.d32 = 0 };
  72220. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  72221. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  72222. + hcfg.d32);
  72223. +
  72224. + /* Load restore values for [31:14] bits */
  72225. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  72226. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  72227. +
  72228. + if (rmode)
  72229. + pcgcctl.b.restoremode = 1;
  72230. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  72231. + dwc_udelay(10);
  72232. +
  72233. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  72234. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  72235. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  72236. + pcgcctl.b.ess_reg_restored = 1;
  72237. + if (rmode)
  72238. + pcgcctl.b.restoremode = 1;
  72239. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  72240. + } else {
  72241. + dcfg_data_t dcfg = {.d32 = 0 };
  72242. + dcfg.d32 = core_if->dr_backup->dcfg;
  72243. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  72244. +
  72245. + /* Load restore values for [31:14] bits */
  72246. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  72247. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  72248. + if (!rmode) {
  72249. + pcgcctl.d32 |= 0x208;
  72250. + }
  72251. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  72252. + dwc_udelay(10);
  72253. +
  72254. + /* Load restore values for [31:14] bits */
  72255. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  72256. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  72257. + pcgcctl.b.ess_reg_restored = 1;
  72258. + if (!rmode)
  72259. + pcgcctl.d32 |= 0x208;
  72260. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  72261. + }
  72262. +
  72263. + return 0;
  72264. +}
  72265. +
  72266. +/**
  72267. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  72268. + * type.
  72269. + */
  72270. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  72271. +{
  72272. + uint32_t val;
  72273. + hcfg_data_t hcfg;
  72274. +
  72275. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  72276. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  72277. + (core_if->core_params->ulpi_fs_ls)) ||
  72278. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  72279. + /* Full speed PHY */
  72280. + val = DWC_HCFG_48_MHZ;
  72281. + } else {
  72282. + /* High speed PHY running at full speed or high speed */
  72283. + val = DWC_HCFG_30_60_MHZ;
  72284. + }
  72285. +
  72286. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  72287. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  72288. + hcfg.b.fslspclksel = val;
  72289. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  72290. +}
  72291. +
  72292. +/**
  72293. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  72294. + * and the enumeration speed of the device.
  72295. + */
  72296. +static void init_devspd(dwc_otg_core_if_t * core_if)
  72297. +{
  72298. + uint32_t val;
  72299. + dcfg_data_t dcfg;
  72300. +
  72301. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  72302. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  72303. + (core_if->core_params->ulpi_fs_ls)) ||
  72304. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  72305. + /* Full speed PHY */
  72306. + val = 0x3;
  72307. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  72308. + /* High speed PHY running at full speed */
  72309. + val = 0x1;
  72310. + } else {
  72311. + /* High speed PHY running at high speed */
  72312. + val = 0x0;
  72313. + }
  72314. +
  72315. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  72316. +
  72317. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  72318. + dcfg.b.devspd = val;
  72319. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  72320. +}
  72321. +
  72322. +/**
  72323. + * This function calculates the number of IN EPS
  72324. + * using GHWCFG1 and GHWCFG2 registers values
  72325. + *
  72326. + * @param core_if Programming view of the DWC_otg controller
  72327. + */
  72328. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  72329. +{
  72330. + uint32_t num_in_eps = 0;
  72331. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  72332. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  72333. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  72334. + int i;
  72335. +
  72336. + for (i = 0; i < num_eps; ++i) {
  72337. + if (!(hwcfg1 & 0x1))
  72338. + num_in_eps++;
  72339. +
  72340. + hwcfg1 >>= 2;
  72341. + }
  72342. +
  72343. + if (core_if->hwcfg4.b.ded_fifo_en) {
  72344. + num_in_eps =
  72345. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  72346. + }
  72347. +
  72348. + return num_in_eps;
  72349. +}
  72350. +
  72351. +/**
  72352. + * This function calculates the number of OUT EPS
  72353. + * using GHWCFG1 and GHWCFG2 registers values
  72354. + *
  72355. + * @param core_if Programming view of the DWC_otg controller
  72356. + */
  72357. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  72358. +{
  72359. + uint32_t num_out_eps = 0;
  72360. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  72361. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  72362. + int i;
  72363. +
  72364. + for (i = 0; i < num_eps; ++i) {
  72365. + if (!(hwcfg1 & 0x1))
  72366. + num_out_eps++;
  72367. +
  72368. + hwcfg1 >>= 2;
  72369. + }
  72370. + return num_out_eps;
  72371. +}
  72372. +
  72373. +/**
  72374. + * This function initializes the DWC_otg controller registers and
  72375. + * prepares the core for device mode or host mode operation.
  72376. + *
  72377. + * @param core_if Programming view of the DWC_otg controller
  72378. + *
  72379. + */
  72380. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  72381. +{
  72382. + int i = 0;
  72383. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72384. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  72385. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  72386. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  72387. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  72388. +
  72389. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  72390. + core_if, global_regs);
  72391. +
  72392. + /* Common Initialization */
  72393. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72394. +
  72395. + /* Program the ULPI External VBUS bit if needed */
  72396. + usbcfg.b.ulpi_ext_vbus_drv =
  72397. + (core_if->core_params->phy_ulpi_ext_vbus ==
  72398. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  72399. +
  72400. + /* Set external TS Dline pulsing */
  72401. + usbcfg.b.term_sel_dl_pulse =
  72402. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  72403. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72404. +
  72405. + /* Reset the Controller */
  72406. + dwc_otg_core_reset(core_if);
  72407. +
  72408. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  72409. + core_if->power_down = core_if->core_params->power_down;
  72410. + core_if->otg_sts = 0;
  72411. +
  72412. + /* Initialize parameters from Hardware configuration registers. */
  72413. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  72414. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  72415. +
  72416. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  72417. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  72418. +
  72419. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  72420. + dev_if->perio_tx_fifo_size[i] =
  72421. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  72422. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  72423. + i, dev_if->perio_tx_fifo_size[i]);
  72424. + }
  72425. +
  72426. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  72427. + dev_if->tx_fifo_size[i] =
  72428. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  72429. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  72430. + i, dev_if->tx_fifo_size[i]);
  72431. + }
  72432. +
  72433. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  72434. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  72435. + core_if->nperio_tx_fifo_size =
  72436. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  72437. +
  72438. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  72439. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  72440. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  72441. + core_if->nperio_tx_fifo_size);
  72442. +
  72443. + /* This programming sequence needs to happen in FS mode before any other
  72444. + * programming occurs */
  72445. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  72446. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  72447. + /* If FS mode with FS PHY */
  72448. +
  72449. + /* core_init() is now called on every switch so only call the
  72450. + * following for the first time through. */
  72451. + if (!core_if->phy_init_done) {
  72452. + core_if->phy_init_done = 1;
  72453. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  72454. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72455. + usbcfg.b.physel = 1;
  72456. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72457. +
  72458. + /* Reset after a PHY select */
  72459. + dwc_otg_core_reset(core_if);
  72460. + }
  72461. +
  72462. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  72463. + * do this on HNP Dev/Host mode switches (done in dev_init and
  72464. + * host_init). */
  72465. + if (dwc_otg_is_host_mode(core_if)) {
  72466. + init_fslspclksel(core_if);
  72467. + } else {
  72468. + init_devspd(core_if);
  72469. + }
  72470. +
  72471. + if (core_if->core_params->i2c_enable) {
  72472. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  72473. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  72474. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72475. + usbcfg.b.otgutmifssel = 1;
  72476. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72477. +
  72478. + /* Program GI2CCTL.I2CEn */
  72479. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  72480. + i2cctl.b.i2cdevaddr = 1;
  72481. + i2cctl.b.i2cen = 0;
  72482. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  72483. + i2cctl.b.i2cen = 1;
  72484. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  72485. + }
  72486. +
  72487. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  72488. + else {
  72489. + /* High speed PHY. */
  72490. + if (!core_if->phy_init_done) {
  72491. + core_if->phy_init_done = 1;
  72492. + /* HS PHY parameters. These parameters are preserved
  72493. + * during soft reset so only program the first time. Do
  72494. + * a soft reset immediately after setting phyif. */
  72495. +
  72496. + if (core_if->core_params->phy_type == 2) {
  72497. + /* ULPI interface */
  72498. + usbcfg.b.ulpi_utmi_sel = 1;
  72499. + usbcfg.b.phyif = 0;
  72500. + usbcfg.b.ddrsel =
  72501. + core_if->core_params->phy_ulpi_ddr;
  72502. + } else if (core_if->core_params->phy_type == 1) {
  72503. + /* UTMI+ interface */
  72504. + usbcfg.b.ulpi_utmi_sel = 0;
  72505. + if (core_if->core_params->phy_utmi_width == 16) {
  72506. + usbcfg.b.phyif = 1;
  72507. +
  72508. + } else {
  72509. + usbcfg.b.phyif = 0;
  72510. + }
  72511. + } else {
  72512. + DWC_ERROR("FS PHY TYPE\n");
  72513. + }
  72514. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72515. + /* Reset after setting the PHY parameters */
  72516. + dwc_otg_core_reset(core_if);
  72517. + }
  72518. + }
  72519. +
  72520. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  72521. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  72522. + (core_if->core_params->ulpi_fs_ls)) {
  72523. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  72524. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72525. + usbcfg.b.ulpi_fsls = 1;
  72526. + usbcfg.b.ulpi_clk_sus_m = 1;
  72527. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72528. + } else {
  72529. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72530. + usbcfg.b.ulpi_fsls = 0;
  72531. + usbcfg.b.ulpi_clk_sus_m = 0;
  72532. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72533. + }
  72534. +
  72535. + /* Program the GAHBCFG Register. */
  72536. + switch (core_if->hwcfg2.b.architecture) {
  72537. +
  72538. + case DWC_SLAVE_ONLY_ARCH:
  72539. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  72540. + ahbcfg.b.nptxfemplvl_txfemplvl =
  72541. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  72542. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  72543. + core_if->dma_enable = 0;
  72544. + core_if->dma_desc_enable = 0;
  72545. + break;
  72546. +
  72547. + case DWC_EXT_DMA_ARCH:
  72548. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  72549. + {
  72550. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  72551. + ahbcfg.b.hburstlen = 0;
  72552. + while (brst_sz > 1) {
  72553. + ahbcfg.b.hburstlen++;
  72554. + brst_sz >>= 1;
  72555. + }
  72556. + }
  72557. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  72558. + core_if->dma_desc_enable =
  72559. + (core_if->core_params->dma_desc_enable != 0);
  72560. + break;
  72561. +
  72562. + case DWC_INT_DMA_ARCH:
  72563. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  72564. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  72565. + Host mode ISOC in issue fix - vahrama */
  72566. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  72567. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  72568. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  72569. + core_if->dma_desc_enable =
  72570. + (core_if->core_params->dma_desc_enable != 0);
  72571. + break;
  72572. +
  72573. + }
  72574. + if (core_if->dma_enable) {
  72575. + if (core_if->dma_desc_enable) {
  72576. + DWC_PRINTF("Using Descriptor DMA mode\n");
  72577. + } else {
  72578. + DWC_PRINTF("Using Buffer DMA mode\n");
  72579. +
  72580. + }
  72581. + } else {
  72582. + DWC_PRINTF("Using Slave mode\n");
  72583. + core_if->dma_desc_enable = 0;
  72584. + }
  72585. +
  72586. + if (core_if->core_params->ahb_single) {
  72587. + ahbcfg.b.ahbsingle = 1;
  72588. + }
  72589. +
  72590. + ahbcfg.b.dmaenable = core_if->dma_enable;
  72591. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  72592. +
  72593. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  72594. +
  72595. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  72596. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  72597. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  72598. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  72599. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  72600. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  72601. +
  72602. + /*
  72603. + * Program the GUSBCFG register.
  72604. + */
  72605. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  72606. +
  72607. + switch (core_if->hwcfg2.b.op_mode) {
  72608. + case DWC_MODE_HNP_SRP_CAPABLE:
  72609. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  72610. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  72611. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72612. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72613. + break;
  72614. +
  72615. + case DWC_MODE_SRP_ONLY_CAPABLE:
  72616. + usbcfg.b.hnpcap = 0;
  72617. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72618. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72619. + break;
  72620. +
  72621. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  72622. + usbcfg.b.hnpcap = 0;
  72623. + usbcfg.b.srpcap = 0;
  72624. + break;
  72625. +
  72626. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  72627. + usbcfg.b.hnpcap = 0;
  72628. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72629. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72630. + break;
  72631. +
  72632. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  72633. + usbcfg.b.hnpcap = 0;
  72634. + usbcfg.b.srpcap = 0;
  72635. + break;
  72636. +
  72637. + case DWC_MODE_SRP_CAPABLE_HOST:
  72638. + usbcfg.b.hnpcap = 0;
  72639. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  72640. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  72641. + break;
  72642. +
  72643. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  72644. + usbcfg.b.hnpcap = 0;
  72645. + usbcfg.b.srpcap = 0;
  72646. + break;
  72647. + }
  72648. +
  72649. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  72650. +
  72651. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72652. + if (core_if->core_params->lpm_enable) {
  72653. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  72654. +
  72655. + /* To enable LPM support set lpm_cap_en bit */
  72656. + lpmcfg.b.lpm_cap_en = 1;
  72657. +
  72658. + /* Make AppL1Res ACK */
  72659. + lpmcfg.b.appl_resp = 1;
  72660. +
  72661. + /* Retry 3 times */
  72662. + lpmcfg.b.retry_count = 3;
  72663. +
  72664. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  72665. + 0, lpmcfg.d32);
  72666. +
  72667. + }
  72668. +#endif
  72669. + if (core_if->core_params->ic_usb_cap) {
  72670. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  72671. + gusbcfg.b.ic_usb_cap = 1;
  72672. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  72673. + 0, gusbcfg.d32);
  72674. + }
  72675. + {
  72676. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72677. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  72678. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  72679. + gotgctl.d32);
  72680. + /* Set OTG version supported */
  72681. + core_if->otg_ver = core_if->core_params->otg_ver;
  72682. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  72683. + core_if->core_params->otg_ver, core_if->otg_ver);
  72684. + }
  72685. +
  72686. +
  72687. + /* Enable common interrupts */
  72688. + dwc_otg_enable_common_interrupts(core_if);
  72689. +
  72690. + /* Do device or host intialization based on mode during PCD
  72691. + * and HCD initialization */
  72692. + if (dwc_otg_is_host_mode(core_if)) {
  72693. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  72694. + core_if->op_state = A_HOST;
  72695. + } else {
  72696. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  72697. + core_if->op_state = B_PERIPHERAL;
  72698. +#ifdef DWC_DEVICE_ONLY
  72699. + dwc_otg_core_dev_init(core_if);
  72700. +#endif
  72701. + }
  72702. +}
  72703. +
  72704. +/**
  72705. + * This function enables the Device mode interrupts.
  72706. + *
  72707. + * @param core_if Programming view of DWC_otg controller
  72708. + */
  72709. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  72710. +{
  72711. + gintmsk_data_t intr_mask = {.d32 = 0 };
  72712. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72713. +
  72714. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  72715. +
  72716. + /* Disable all interrupts. */
  72717. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  72718. +
  72719. + /* Clear any pending interrupts */
  72720. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  72721. +
  72722. + /* Enable the common interrupts */
  72723. + dwc_otg_enable_common_interrupts(core_if);
  72724. +
  72725. + /* Enable interrupts */
  72726. + intr_mask.b.usbreset = 1;
  72727. + intr_mask.b.enumdone = 1;
  72728. + /* Disable Disconnect interrupt in Device mode */
  72729. + intr_mask.b.disconnect = 0;
  72730. +
  72731. + if (!core_if->multiproc_int_enable) {
  72732. + intr_mask.b.inepintr = 1;
  72733. + intr_mask.b.outepintr = 1;
  72734. + }
  72735. +
  72736. + intr_mask.b.erlysuspend = 1;
  72737. +
  72738. + if (core_if->en_multiple_tx_fifo == 0) {
  72739. + intr_mask.b.epmismatch = 1;
  72740. + }
  72741. +
  72742. + //intr_mask.b.incomplisoout = 1;
  72743. + intr_mask.b.incomplisoin = 1;
  72744. +
  72745. +/* Enable the ignore frame number for ISOC xfers - MAS */
  72746. +/* Disable to support high bandwith ISOC transfers - manukz */
  72747. +#if 0
  72748. +#ifdef DWC_UTE_PER_IO
  72749. + if (core_if->dma_enable) {
  72750. + if (core_if->dma_desc_enable) {
  72751. + dctl_data_t dctl1 = {.d32 = 0 };
  72752. + dctl1.b.ifrmnum = 1;
  72753. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  72754. + dctl, 0, dctl1.d32);
  72755. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  72756. + DWC_READ_REG32(&core_if->dev_if->
  72757. + dev_global_regs->dctl));
  72758. + }
  72759. + }
  72760. +#endif
  72761. +#endif
  72762. +#ifdef DWC_EN_ISOC
  72763. + if (core_if->dma_enable) {
  72764. + if (core_if->dma_desc_enable == 0) {
  72765. + if (core_if->pti_enh_enable) {
  72766. + dctl_data_t dctl = {.d32 = 0 };
  72767. + dctl.b.ifrmnum = 1;
  72768. + DWC_MODIFY_REG32(&core_if->
  72769. + dev_if->dev_global_regs->dctl,
  72770. + 0, dctl.d32);
  72771. + } else {
  72772. + intr_mask.b.incomplisoin = 1;
  72773. + intr_mask.b.incomplisoout = 1;
  72774. + }
  72775. + }
  72776. + } else {
  72777. + intr_mask.b.incomplisoin = 1;
  72778. + intr_mask.b.incomplisoout = 1;
  72779. + }
  72780. +#endif /* DWC_EN_ISOC */
  72781. +
  72782. + /** @todo NGS: Should this be a module parameter? */
  72783. +#ifdef USE_PERIODIC_EP
  72784. + intr_mask.b.isooutdrop = 1;
  72785. + intr_mask.b.eopframe = 1;
  72786. + intr_mask.b.incomplisoin = 1;
  72787. + intr_mask.b.incomplisoout = 1;
  72788. +#endif
  72789. +
  72790. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  72791. +
  72792. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  72793. + DWC_READ_REG32(&global_regs->gintmsk));
  72794. +}
  72795. +
  72796. +/**
  72797. + * This function initializes the DWC_otg controller registers for
  72798. + * device mode.
  72799. + *
  72800. + * @param core_if Programming view of DWC_otg controller
  72801. + *
  72802. + */
  72803. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  72804. +{
  72805. + int i;
  72806. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  72807. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  72808. + dwc_otg_core_params_t *params = core_if->core_params;
  72809. + dcfg_data_t dcfg = {.d32 = 0 };
  72810. + depctl_data_t diepctl = {.d32 = 0 };
  72811. + grstctl_t resetctl = {.d32 = 0 };
  72812. + uint32_t rx_fifo_size;
  72813. + fifosize_data_t nptxfifosize;
  72814. + fifosize_data_t txfifosize;
  72815. + dthrctl_data_t dthrctl;
  72816. + fifosize_data_t ptxfifosize;
  72817. + uint16_t rxfsiz, nptxfsiz;
  72818. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  72819. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  72820. +
  72821. + /* Restart the Phy Clock */
  72822. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72823. +
  72824. + /* Device configuration register */
  72825. + init_devspd(core_if);
  72826. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  72827. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  72828. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  72829. + /* Enable Device OUT NAK in case of DDMA mode*/
  72830. + if (core_if->core_params->dev_out_nak) {
  72831. + dcfg.b.endevoutnak = 1;
  72832. + }
  72833. +
  72834. + if (core_if->core_params->cont_on_bna) {
  72835. + dctl_data_t dctl = {.d32 = 0 };
  72836. + dctl.b.encontonbna = 1;
  72837. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  72838. + }
  72839. +
  72840. +
  72841. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  72842. +
  72843. + /* Configure data FIFO sizes */
  72844. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  72845. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  72846. + core_if->total_fifo_size);
  72847. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  72848. + params->dev_rx_fifo_size);
  72849. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  72850. + params->dev_nperio_tx_fifo_size);
  72851. +
  72852. + /* Rx FIFO */
  72853. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  72854. + DWC_READ_REG32(&global_regs->grxfsiz));
  72855. +
  72856. +#ifdef DWC_UTE_CFI
  72857. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  72858. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  72859. +#endif
  72860. + rx_fifo_size = params->dev_rx_fifo_size;
  72861. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  72862. +
  72863. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  72864. + DWC_READ_REG32(&global_regs->grxfsiz));
  72865. +
  72866. + /** Set Periodic Tx FIFO Mask all bits 0 */
  72867. + core_if->p_tx_msk = 0;
  72868. +
  72869. + /** Set Tx FIFO Mask all bits 0 */
  72870. + core_if->tx_msk = 0;
  72871. +
  72872. + if (core_if->en_multiple_tx_fifo == 0) {
  72873. + /* Non-periodic Tx FIFO */
  72874. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  72875. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72876. +
  72877. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  72878. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  72879. +
  72880. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  72881. + nptxfifosize.d32);
  72882. +
  72883. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  72884. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72885. +
  72886. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  72887. + /*
  72888. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  72889. + * Indexes of the FIFO size module parameters in the
  72890. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  72891. + * the dptxfsiz array run from 0 to 14.
  72892. + */
  72893. + /** @todo Finish debug of this */
  72894. + ptxfifosize.b.startaddr =
  72895. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  72896. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  72897. + ptxfifosize.b.depth =
  72898. + params->dev_perio_tx_fifo_size[i];
  72899. + DWC_DEBUGPL(DBG_CIL,
  72900. + "initial dtxfsiz[%d]=%08x\n", i,
  72901. + DWC_READ_REG32(&global_regs->dtxfsiz
  72902. + [i]));
  72903. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  72904. + ptxfifosize.d32);
  72905. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  72906. + i,
  72907. + DWC_READ_REG32(&global_regs->dtxfsiz
  72908. + [i]));
  72909. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  72910. + }
  72911. + } else {
  72912. + /*
  72913. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  72914. + * Indexes of the FIFO size module parameters in the
  72915. + * dev_tx_fifo_size array and the FIFO size registers in
  72916. + * the dtxfsiz array run from 0 to 14.
  72917. + */
  72918. +
  72919. + /* Non-periodic Tx FIFO */
  72920. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  72921. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72922. +
  72923. +#ifdef DWC_UTE_CFI
  72924. + core_if->pwron_gnptxfsiz =
  72925. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  72926. + core_if->init_gnptxfsiz =
  72927. + params->dev_nperio_tx_fifo_size;
  72928. +#endif
  72929. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  72930. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  72931. +
  72932. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  72933. + nptxfifosize.d32);
  72934. +
  72935. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  72936. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  72937. +
  72938. + txfifosize.b.startaddr =
  72939. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  72940. +
  72941. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  72942. +
  72943. + txfifosize.b.depth =
  72944. + params->dev_tx_fifo_size[i];
  72945. +
  72946. + DWC_DEBUGPL(DBG_CIL,
  72947. + "initial dtxfsiz[%d]=%08x\n",
  72948. + i,
  72949. + DWC_READ_REG32(&global_regs->dtxfsiz
  72950. + [i]));
  72951. +
  72952. +#ifdef DWC_UTE_CFI
  72953. + core_if->pwron_txfsiz[i] =
  72954. + (DWC_READ_REG32
  72955. + (&global_regs->dtxfsiz[i]) >> 16);
  72956. + core_if->init_txfsiz[i] =
  72957. + params->dev_tx_fifo_size[i];
  72958. +#endif
  72959. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  72960. + txfifosize.d32);
  72961. +
  72962. + DWC_DEBUGPL(DBG_CIL,
  72963. + "new dtxfsiz[%d]=%08x\n",
  72964. + i,
  72965. + DWC_READ_REG32(&global_regs->dtxfsiz
  72966. + [i]));
  72967. +
  72968. + txfifosize.b.startaddr += txfifosize.b.depth;
  72969. + }
  72970. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  72971. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  72972. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  72973. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  72974. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  72975. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  72976. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  72977. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  72978. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  72979. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  72980. + }
  72981. + }
  72982. +
  72983. + /* Flush the FIFOs */
  72984. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  72985. + dwc_otg_flush_rx_fifo(core_if);
  72986. +
  72987. + /* Flush the Learning Queue. */
  72988. + resetctl.b.intknqflsh = 1;
  72989. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  72990. +
  72991. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  72992. + core_if->start_predict = 0;
  72993. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  72994. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  72995. + }
  72996. + core_if->nextep_seq[0] = 0;
  72997. + core_if->first_in_nextep_seq = 0;
  72998. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  72999. + diepctl.b.nextep = 0;
  73000. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  73001. +
  73002. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  73003. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  73004. + dcfg.b.epmscnt = 2;
  73005. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  73006. +
  73007. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  73008. + __func__, core_if->first_in_nextep_seq);
  73009. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  73010. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  73011. + }
  73012. + DWC_DEBUGPL(DBG_CILV,"\n");
  73013. + }
  73014. +
  73015. + /* Clear all pending Device Interrupts */
  73016. + /** @todo - if the condition needed to be checked
  73017. + * or in any case all pending interrutps should be cleared?
  73018. + */
  73019. + if (core_if->multiproc_int_enable) {
  73020. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  73021. + DWC_WRITE_REG32(&dev_if->
  73022. + dev_global_regs->diepeachintmsk[i], 0);
  73023. + }
  73024. + }
  73025. +
  73026. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  73027. + DWC_WRITE_REG32(&dev_if->
  73028. + dev_global_regs->doepeachintmsk[i], 0);
  73029. + }
  73030. +
  73031. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  73032. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  73033. + } else {
  73034. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  73035. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  73036. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  73037. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  73038. + }
  73039. +
  73040. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  73041. + depctl_data_t depctl;
  73042. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  73043. + if (depctl.b.epena) {
  73044. + depctl.d32 = 0;
  73045. + depctl.b.epdis = 1;
  73046. + depctl.b.snak = 1;
  73047. + } else {
  73048. + depctl.d32 = 0;
  73049. + }
  73050. +
  73051. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  73052. +
  73053. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  73054. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  73055. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  73056. + }
  73057. +
  73058. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  73059. + depctl_data_t depctl;
  73060. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  73061. + if (depctl.b.epena) {
  73062. + dctl_data_t dctl = {.d32 = 0 };
  73063. + gintmsk_data_t gintsts = {.d32 = 0 };
  73064. + doepint_data_t doepint = {.d32 = 0 };
  73065. + dctl.b.sgoutnak = 1;
  73066. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  73067. + do {
  73068. + dwc_udelay(10);
  73069. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  73070. + } while (!gintsts.b.goutnakeff);
  73071. + gintsts.d32 = 0;
  73072. + gintsts.b.goutnakeff = 1;
  73073. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  73074. +
  73075. + depctl.d32 = 0;
  73076. + depctl.b.epdis = 1;
  73077. + depctl.b.snak = 1;
  73078. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  73079. + do {
  73080. + dwc_udelay(10);
  73081. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  73082. + out_ep_regs[i]->doepint);
  73083. + } while (!doepint.b.epdisabled);
  73084. +
  73085. + doepint.b.epdisabled = 1;
  73086. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  73087. +
  73088. + dctl.d32 = 0;
  73089. + dctl.b.cgoutnak = 1;
  73090. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  73091. + } else {
  73092. + depctl.d32 = 0;
  73093. + }
  73094. +
  73095. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  73096. +
  73097. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  73098. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  73099. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  73100. + }
  73101. +
  73102. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  73103. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  73104. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  73105. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  73106. +
  73107. + dev_if->rx_thr_length = params->rx_thr_length;
  73108. + dev_if->tx_thr_length = params->tx_thr_length;
  73109. +
  73110. + dev_if->setup_desc_index = 0;
  73111. +
  73112. + dthrctl.d32 = 0;
  73113. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  73114. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  73115. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  73116. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  73117. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  73118. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  73119. +
  73120. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  73121. + dthrctl.d32);
  73122. +
  73123. + DWC_DEBUGPL(DBG_CIL,
  73124. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  73125. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  73126. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  73127. + dthrctl.b.rx_thr_len);
  73128. +
  73129. + }
  73130. +
  73131. + dwc_otg_enable_device_interrupts(core_if);
  73132. +
  73133. + {
  73134. + diepmsk_data_t msk = {.d32 = 0 };
  73135. + msk.b.txfifoundrn = 1;
  73136. + if (core_if->multiproc_int_enable) {
  73137. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  73138. + diepeachintmsk[0], msk.d32, msk.d32);
  73139. + } else {
  73140. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  73141. + msk.d32, msk.d32);
  73142. + }
  73143. + }
  73144. +
  73145. + if (core_if->multiproc_int_enable) {
  73146. + /* Set NAK on Babble */
  73147. + dctl_data_t dctl = {.d32 = 0 };
  73148. + dctl.b.nakonbble = 1;
  73149. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  73150. + }
  73151. +
  73152. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  73153. + dctl_data_t dctl = {.d32 = 0 };
  73154. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  73155. + dctl.b.sftdiscon = 0;
  73156. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  73157. + }
  73158. +}
  73159. +
  73160. +/**
  73161. + * This function enables the Host mode interrupts.
  73162. + *
  73163. + * @param core_if Programming view of DWC_otg controller
  73164. + */
  73165. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  73166. +{
  73167. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  73168. + gintmsk_data_t intr_mask = {.d32 = 0 };
  73169. +
  73170. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  73171. +
  73172. + /* Disable all interrupts. */
  73173. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73174. +
  73175. + /* Clear any pending interrupts. */
  73176. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  73177. +
  73178. + /* Enable the common interrupts */
  73179. + dwc_otg_enable_common_interrupts(core_if);
  73180. +
  73181. + /*
  73182. + * Enable host mode interrupts without disturbing common
  73183. + * interrupts.
  73184. + */
  73185. +
  73186. + intr_mask.b.disconnect = 1;
  73187. + intr_mask.b.portintr = 1;
  73188. + intr_mask.b.hcintr = 1;
  73189. +
  73190. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  73191. +}
  73192. +
  73193. +/**
  73194. + * This function disables the Host Mode interrupts.
  73195. + *
  73196. + * @param core_if Programming view of DWC_otg controller
  73197. + */
  73198. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  73199. +{
  73200. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  73201. + gintmsk_data_t intr_mask = {.d32 = 0 };
  73202. +
  73203. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  73204. +
  73205. + /*
  73206. + * Disable host mode interrupts without disturbing common
  73207. + * interrupts.
  73208. + */
  73209. + intr_mask.b.sofintr = 1;
  73210. + intr_mask.b.portintr = 1;
  73211. + intr_mask.b.hcintr = 1;
  73212. + intr_mask.b.ptxfempty = 1;
  73213. + intr_mask.b.nptxfempty = 1;
  73214. +
  73215. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  73216. +}
  73217. +
  73218. +/**
  73219. + * This function initializes the DWC_otg controller registers for
  73220. + * host mode.
  73221. + *
  73222. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  73223. + * request queues. Host channels are reset to ensure that they are ready for
  73224. + * performing transfers.
  73225. + *
  73226. + * @param core_if Programming view of DWC_otg controller
  73227. + *
  73228. + */
  73229. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  73230. +{
  73231. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  73232. + dwc_otg_host_if_t *host_if = core_if->host_if;
  73233. + dwc_otg_core_params_t *params = core_if->core_params;
  73234. + hprt0_data_t hprt0 = {.d32 = 0 };
  73235. + fifosize_data_t nptxfifosize;
  73236. + fifosize_data_t ptxfifosize;
  73237. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  73238. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  73239. + int i;
  73240. + hcchar_data_t hcchar;
  73241. + hcfg_data_t hcfg;
  73242. + hfir_data_t hfir;
  73243. + dwc_otg_hc_regs_t *hc_regs;
  73244. + int num_channels;
  73245. + gotgctl_data_t gotgctl = {.d32 = 0 };
  73246. +
  73247. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  73248. +
  73249. + /* Restart the Phy Clock */
  73250. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  73251. +
  73252. + /* Initialize Host Configuration Register */
  73253. + init_fslspclksel(core_if);
  73254. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  73255. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  73256. + hcfg.b.fslssupp = 1;
  73257. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  73258. +
  73259. + }
  73260. +
  73261. + /* This bit allows dynamic reloading of the HFIR register
  73262. + * during runtime. This bit needs to be programmed during
  73263. + * initial configuration and its value must not be changed
  73264. + * during runtime.*/
  73265. + if (core_if->core_params->reload_ctl == 1) {
  73266. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  73267. + hfir.b.hfirrldctrl = 1;
  73268. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  73269. + }
  73270. +
  73271. + if (core_if->core_params->dma_desc_enable) {
  73272. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  73273. + if (!
  73274. + (core_if->hwcfg4.b.desc_dma
  73275. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  73276. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  73277. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  73278. + || (op_mode ==
  73279. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  73280. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  73281. + || (op_mode ==
  73282. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  73283. +
  73284. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  73285. + "Either core version is below 2.90a or "
  73286. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  73287. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  73288. + "module parameter to 0.\n");
  73289. + return;
  73290. + }
  73291. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  73292. + hcfg.b.descdma = 1;
  73293. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  73294. + }
  73295. +
  73296. + /* Configure data FIFO sizes */
  73297. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  73298. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  73299. + core_if->total_fifo_size);
  73300. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  73301. + params->host_rx_fifo_size);
  73302. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  73303. + params->host_nperio_tx_fifo_size);
  73304. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  73305. + params->host_perio_tx_fifo_size);
  73306. +
  73307. + /* Rx FIFO */
  73308. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  73309. + DWC_READ_REG32(&global_regs->grxfsiz));
  73310. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  73311. + params->host_rx_fifo_size);
  73312. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  73313. + DWC_READ_REG32(&global_regs->grxfsiz));
  73314. +
  73315. + /* Non-periodic Tx FIFO */
  73316. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  73317. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  73318. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  73319. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  73320. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  73321. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  73322. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  73323. +
  73324. + /* Periodic Tx FIFO */
  73325. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  73326. + DWC_READ_REG32(&global_regs->hptxfsiz));
  73327. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  73328. + ptxfifosize.b.startaddr =
  73329. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  73330. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  73331. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  73332. + DWC_READ_REG32(&global_regs->hptxfsiz));
  73333. +
  73334. + if (core_if->en_multiple_tx_fifo
  73335. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  73336. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  73337. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  73338. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  73339. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  73340. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  73341. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  73342. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  73343. + }
  73344. + }
  73345. +
  73346. + /* TODO - check this */
  73347. + /* Clear Host Set HNP Enable in the OTG Control Register */
  73348. + gotgctl.b.hstsethnpen = 1;
  73349. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  73350. + /* Make sure the FIFOs are flushed. */
  73351. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  73352. + dwc_otg_flush_rx_fifo(core_if);
  73353. +
  73354. + /* Clear Host Set HNP Enable in the OTG Control Register */
  73355. + gotgctl.b.hstsethnpen = 1;
  73356. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  73357. +
  73358. + if (!core_if->core_params->dma_desc_enable) {
  73359. + /* Flush out any leftover queued requests. */
  73360. + num_channels = core_if->core_params->host_channels;
  73361. +
  73362. + for (i = 0; i < num_channels; i++) {
  73363. + hc_regs = core_if->host_if->hc_regs[i];
  73364. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73365. + hcchar.b.chen = 0;
  73366. + hcchar.b.chdis = 1;
  73367. + hcchar.b.epdir = 0;
  73368. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73369. + }
  73370. +
  73371. + /* Halt all channels to put them into a known state. */
  73372. + for (i = 0; i < num_channels; i++) {
  73373. + int count = 0;
  73374. + hc_regs = core_if->host_if->hc_regs[i];
  73375. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73376. + hcchar.b.chen = 1;
  73377. + hcchar.b.chdis = 1;
  73378. + hcchar.b.epdir = 0;
  73379. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73380. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  73381. + do {
  73382. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73383. + if (++count > 1000) {
  73384. + DWC_ERROR
  73385. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  73386. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  73387. + break;
  73388. + }
  73389. + dwc_udelay(1);
  73390. + } while (hcchar.b.chen);
  73391. + }
  73392. + }
  73393. +
  73394. + /* Turn on the vbus power. */
  73395. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  73396. + if (core_if->op_state == A_HOST) {
  73397. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73398. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  73399. + if (hprt0.b.prtpwr == 0) {
  73400. + hprt0.b.prtpwr = 1;
  73401. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  73402. + }
  73403. + }
  73404. +
  73405. + dwc_otg_enable_host_interrupts(core_if);
  73406. +}
  73407. +
  73408. +/**
  73409. + * Prepares a host channel for transferring packets to/from a specific
  73410. + * endpoint. The HCCHARn register is set up with the characteristics specified
  73411. + * in _hc. Host channel interrupts that may need to be serviced while this
  73412. + * transfer is in progress are enabled.
  73413. + *
  73414. + * @param core_if Programming view of DWC_otg controller
  73415. + * @param hc Information needed to initialize the host channel
  73416. + */
  73417. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73418. +{
  73419. + uint32_t intr_enable;
  73420. + hcintmsk_data_t hc_intr_mask;
  73421. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73422. + hcchar_data_t hcchar;
  73423. + hcsplt_data_t hcsplt;
  73424. +
  73425. + uint8_t hc_num = hc->hc_num;
  73426. + dwc_otg_host_if_t *host_if = core_if->host_if;
  73427. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  73428. +
  73429. + /* Clear old interrupt conditions for this host channel. */
  73430. + hc_intr_mask.d32 = 0xFFFFFFFF;
  73431. + hc_intr_mask.b.reserved14_31 = 0;
  73432. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  73433. +
  73434. + /* Enable channel interrupts required for this transfer. */
  73435. + hc_intr_mask.d32 = 0;
  73436. + hc_intr_mask.b.chhltd = 1;
  73437. + if (core_if->dma_enable) {
  73438. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  73439. + if (!core_if->dma_desc_enable)
  73440. + hc_intr_mask.b.ahberr = 1;
  73441. + else {
  73442. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  73443. + hc_intr_mask.b.xfercompl = 1;
  73444. + }
  73445. +
  73446. + if (hc->error_state && !hc->do_split &&
  73447. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  73448. + hc_intr_mask.b.ack = 1;
  73449. + if (hc->ep_is_in) {
  73450. + hc_intr_mask.b.datatglerr = 1;
  73451. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  73452. + hc_intr_mask.b.nak = 1;
  73453. + }
  73454. + }
  73455. + }
  73456. + } else {
  73457. + switch (hc->ep_type) {
  73458. + case DWC_OTG_EP_TYPE_CONTROL:
  73459. + case DWC_OTG_EP_TYPE_BULK:
  73460. + hc_intr_mask.b.xfercompl = 1;
  73461. + hc_intr_mask.b.stall = 1;
  73462. + hc_intr_mask.b.xacterr = 1;
  73463. + hc_intr_mask.b.datatglerr = 1;
  73464. + if (hc->ep_is_in) {
  73465. + hc_intr_mask.b.bblerr = 1;
  73466. + } else {
  73467. + hc_intr_mask.b.nak = 1;
  73468. + hc_intr_mask.b.nyet = 1;
  73469. + if (hc->do_ping) {
  73470. + hc_intr_mask.b.ack = 1;
  73471. + }
  73472. + }
  73473. +
  73474. + if (hc->do_split) {
  73475. + hc_intr_mask.b.nak = 1;
  73476. + if (hc->complete_split) {
  73477. + hc_intr_mask.b.nyet = 1;
  73478. + } else {
  73479. + hc_intr_mask.b.ack = 1;
  73480. + }
  73481. + }
  73482. +
  73483. + if (hc->error_state) {
  73484. + hc_intr_mask.b.ack = 1;
  73485. + }
  73486. + break;
  73487. + case DWC_OTG_EP_TYPE_INTR:
  73488. + hc_intr_mask.b.xfercompl = 1;
  73489. + hc_intr_mask.b.nak = 1;
  73490. + hc_intr_mask.b.stall = 1;
  73491. + hc_intr_mask.b.xacterr = 1;
  73492. + hc_intr_mask.b.datatglerr = 1;
  73493. + hc_intr_mask.b.frmovrun = 1;
  73494. +
  73495. + if (hc->ep_is_in) {
  73496. + hc_intr_mask.b.bblerr = 1;
  73497. + }
  73498. + if (hc->error_state) {
  73499. + hc_intr_mask.b.ack = 1;
  73500. + }
  73501. + if (hc->do_split) {
  73502. + if (hc->complete_split) {
  73503. + hc_intr_mask.b.nyet = 1;
  73504. + } else {
  73505. + hc_intr_mask.b.ack = 1;
  73506. + }
  73507. + }
  73508. + break;
  73509. + case DWC_OTG_EP_TYPE_ISOC:
  73510. + hc_intr_mask.b.xfercompl = 1;
  73511. + hc_intr_mask.b.frmovrun = 1;
  73512. + hc_intr_mask.b.ack = 1;
  73513. +
  73514. + if (hc->ep_is_in) {
  73515. + hc_intr_mask.b.xacterr = 1;
  73516. + hc_intr_mask.b.bblerr = 1;
  73517. + }
  73518. + break;
  73519. + }
  73520. + }
  73521. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  73522. +
  73523. + /* Enable the top level host channel interrupt. */
  73524. + intr_enable = (1 << hc_num);
  73525. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  73526. +
  73527. + /* Make sure host channel interrupts are enabled. */
  73528. + gintmsk.b.hcintr = 1;
  73529. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  73530. +
  73531. + /*
  73532. + * Program the HCCHARn register with the endpoint characteristics for
  73533. + * the current transfer.
  73534. + */
  73535. + hcchar.d32 = 0;
  73536. + hcchar.b.devaddr = hc->dev_addr;
  73537. + hcchar.b.epnum = hc->ep_num;
  73538. + hcchar.b.epdir = hc->ep_is_in;
  73539. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  73540. + hcchar.b.eptype = hc->ep_type;
  73541. + hcchar.b.mps = hc->max_packet;
  73542. +
  73543. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  73544. +
  73545. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  73546. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  73547. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  73548. + "Max Pkt %d, Multi Cnt %d\n",
  73549. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  73550. + hcchar.b.mps, hcchar.b.multicnt);
  73551. +
  73552. + /*
  73553. + * Program the HCSPLIT register for SPLITs
  73554. + */
  73555. + hcsplt.d32 = 0;
  73556. + if (hc->do_split) {
  73557. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  73558. + hc->hc_num,
  73559. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  73560. + hcsplt.b.compsplt = hc->complete_split;
  73561. + hcsplt.b.xactpos = hc->xact_pos;
  73562. + hcsplt.b.hubaddr = hc->hub_addr;
  73563. + hcsplt.b.prtaddr = hc->port_addr;
  73564. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  73565. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  73566. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  73567. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  73568. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  73569. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  73570. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  73571. + }
  73572. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  73573. +
  73574. +}
  73575. +
  73576. +/**
  73577. + * Attempts to halt a host channel. This function should only be called in
  73578. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  73579. + * normal circumstances in DMA mode, the controller halts the channel when the
  73580. + * transfer is complete or a condition occurs that requires application
  73581. + * intervention.
  73582. + *
  73583. + * In slave mode, checks for a free request queue entry, then sets the Channel
  73584. + * Enable and Channel Disable bits of the Host Channel Characteristics
  73585. + * register of the specified channel to intiate the halt. If there is no free
  73586. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  73587. + * register to flush requests for this channel. In the latter case, sets a
  73588. + * flag to indicate that the host channel needs to be halted when a request
  73589. + * queue slot is open.
  73590. + *
  73591. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  73592. + * HCCHARn register. The controller ensures there is space in the request
  73593. + * queue before submitting the halt request.
  73594. + *
  73595. + * Some time may elapse before the core flushes any posted requests for this
  73596. + * host channel and halts. The Channel Halted interrupt handler completes the
  73597. + * deactivation of the host channel.
  73598. + *
  73599. + * @param core_if Controller register interface.
  73600. + * @param hc Host channel to halt.
  73601. + * @param halt_status Reason for halting the channel.
  73602. + */
  73603. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  73604. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  73605. +{
  73606. + gnptxsts_data_t nptxsts;
  73607. + hptxsts_data_t hptxsts;
  73608. + hcchar_data_t hcchar;
  73609. + dwc_otg_hc_regs_t *hc_regs;
  73610. + dwc_otg_core_global_regs_t *global_regs;
  73611. + dwc_otg_host_global_regs_t *host_global_regs;
  73612. +
  73613. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73614. + global_regs = core_if->core_global_regs;
  73615. + host_global_regs = core_if->host_if->host_global_regs;
  73616. +
  73617. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  73618. + "halt_status = %d\n", halt_status);
  73619. +
  73620. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  73621. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  73622. + /*
  73623. + * Disable all channel interrupts except Ch Halted. The QTD
  73624. + * and QH state associated with this transfer has been cleared
  73625. + * (in the case of URB_DEQUEUE), so the channel needs to be
  73626. + * shut down carefully to prevent crashes.
  73627. + */
  73628. + hcintmsk_data_t hcintmsk;
  73629. + hcintmsk.d32 = 0;
  73630. + hcintmsk.b.chhltd = 1;
  73631. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  73632. +
  73633. + /*
  73634. + * Make sure no other interrupts besides halt are currently
  73635. + * pending. Handling another interrupt could cause a crash due
  73636. + * to the QTD and QH state.
  73637. + */
  73638. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  73639. +
  73640. + /*
  73641. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  73642. + * even if the channel was already halted for some other
  73643. + * reason.
  73644. + */
  73645. + hc->halt_status = halt_status;
  73646. +
  73647. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73648. + if (hcchar.b.chen == 0) {
  73649. + /*
  73650. + * The channel is either already halted or it hasn't
  73651. + * started yet. In DMA mode, the transfer may halt if
  73652. + * it finishes normally or a condition occurs that
  73653. + * requires driver intervention. Don't want to halt
  73654. + * the channel again. In either Slave or DMA mode,
  73655. + * it's possible that the transfer has been assigned
  73656. + * to a channel, but not started yet when an URB is
  73657. + * dequeued. Don't want to halt a channel that hasn't
  73658. + * started yet.
  73659. + */
  73660. + return;
  73661. + }
  73662. + }
  73663. + if (hc->halt_pending) {
  73664. + /*
  73665. + * A halt has already been issued for this channel. This might
  73666. + * happen when a transfer is aborted by a higher level in
  73667. + * the stack.
  73668. + */
  73669. +#ifdef DEBUG
  73670. + DWC_PRINTF
  73671. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  73672. + __func__, hc->hc_num);
  73673. +
  73674. +#endif
  73675. + return;
  73676. + }
  73677. +
  73678. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  73679. +
  73680. + /* No need to set the bit in DDMA for disabling the channel */
  73681. + //TODO check it everywhere channel is disabled
  73682. + if (!core_if->core_params->dma_desc_enable)
  73683. + hcchar.b.chen = 1;
  73684. + hcchar.b.chdis = 1;
  73685. +
  73686. + if (!core_if->dma_enable) {
  73687. + /* Check for space in the request queue to issue the halt. */
  73688. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  73689. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  73690. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  73691. + if (nptxsts.b.nptxqspcavail == 0) {
  73692. + hcchar.b.chen = 0;
  73693. + }
  73694. + } else {
  73695. + hptxsts.d32 =
  73696. + DWC_READ_REG32(&host_global_regs->hptxsts);
  73697. + if ((hptxsts.b.ptxqspcavail == 0)
  73698. + || (core_if->queuing_high_bandwidth)) {
  73699. + hcchar.b.chen = 0;
  73700. + }
  73701. + }
  73702. + }
  73703. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  73704. +
  73705. + hc->halt_status = halt_status;
  73706. +
  73707. + if (hcchar.b.chen) {
  73708. + hc->halt_pending = 1;
  73709. + hc->halt_on_queue = 0;
  73710. + } else {
  73711. + hc->halt_on_queue = 1;
  73712. + }
  73713. +
  73714. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  73715. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  73716. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  73717. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  73718. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  73719. +
  73720. + return;
  73721. +}
  73722. +
  73723. +/**
  73724. + * Clears the transfer state for a host channel. This function is normally
  73725. + * called after a transfer is done and the host channel is being released.
  73726. + *
  73727. + * @param core_if Programming view of DWC_otg controller.
  73728. + * @param hc Identifies the host channel to clean up.
  73729. + */
  73730. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73731. +{
  73732. + dwc_otg_hc_regs_t *hc_regs;
  73733. +
  73734. + hc->xfer_started = 0;
  73735. +
  73736. + /*
  73737. + * Clear channel interrupt enables and any unhandled channel interrupt
  73738. + * conditions.
  73739. + */
  73740. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73741. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  73742. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  73743. +#ifdef DEBUG
  73744. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  73745. +#endif
  73746. +}
  73747. +
  73748. +/**
  73749. + * Sets the channel property that indicates in which frame a periodic transfer
  73750. + * should occur. This is always set to the _next_ frame. This function has no
  73751. + * effect on non-periodic transfers.
  73752. + *
  73753. + * @param core_if Programming view of DWC_otg controller.
  73754. + * @param hc Identifies the host channel to set up and its properties.
  73755. + * @param hcchar Current value of the HCCHAR register for the specified host
  73756. + * channel.
  73757. + */
  73758. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  73759. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  73760. +{
  73761. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73762. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73763. + hfnum_data_t hfnum;
  73764. + hfnum.d32 =
  73765. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  73766. +
  73767. + /* 1 if _next_ frame is odd, 0 if it's even */
  73768. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  73769. +#ifdef DEBUG
  73770. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  73771. + && !hc->complete_split) {
  73772. + switch (hfnum.b.frnum & 0x7) {
  73773. + case 7:
  73774. + core_if->hfnum_7_samples++;
  73775. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  73776. + break;
  73777. + case 0:
  73778. + core_if->hfnum_0_samples++;
  73779. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  73780. + break;
  73781. + default:
  73782. + core_if->hfnum_other_samples++;
  73783. + core_if->hfnum_other_frrem_accum +=
  73784. + hfnum.b.frrem;
  73785. + break;
  73786. + }
  73787. + }
  73788. +#endif
  73789. + }
  73790. +}
  73791. +
  73792. +#ifdef DEBUG
  73793. +void hc_xfer_timeout(void *ptr)
  73794. +{
  73795. + hc_xfer_info_t *xfer_info = NULL;
  73796. + int hc_num = 0;
  73797. +
  73798. + if (ptr)
  73799. + xfer_info = (hc_xfer_info_t *) ptr;
  73800. +
  73801. + if (!xfer_info->hc) {
  73802. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  73803. + return;
  73804. + }
  73805. +
  73806. + hc_num = xfer_info->hc->hc_num;
  73807. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  73808. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  73809. + xfer_info->core_if->start_hcchar_val[hc_num]);
  73810. +}
  73811. +#endif
  73812. +
  73813. +void ep_xfer_timeout(void *ptr)
  73814. +{
  73815. + ep_xfer_info_t *xfer_info = NULL;
  73816. + int ep_num = 0;
  73817. + dctl_data_t dctl = {.d32 = 0 };
  73818. + gintsts_data_t gintsts = {.d32 = 0 };
  73819. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73820. +
  73821. + if (ptr)
  73822. + xfer_info = (ep_xfer_info_t *) ptr;
  73823. +
  73824. + if (!xfer_info->ep) {
  73825. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  73826. + return;
  73827. + }
  73828. +
  73829. + ep_num = xfer_info->ep->num;
  73830. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  73831. + /* Put the sate to 2 as it was time outed */
  73832. + xfer_info->state = 2;
  73833. +
  73834. + dctl.d32 =
  73835. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  73836. + gintsts.d32 =
  73837. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  73838. + gintmsk.d32 =
  73839. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  73840. +
  73841. + if (!gintmsk.b.goutnakeff) {
  73842. + /* Unmask it */
  73843. + gintmsk.b.goutnakeff = 1;
  73844. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  73845. + gintmsk.d32);
  73846. +
  73847. + }
  73848. +
  73849. + if (!gintsts.b.goutnakeff) {
  73850. + dctl.b.sgoutnak = 1;
  73851. + }
  73852. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  73853. + dctl.d32);
  73854. +
  73855. +}
  73856. +
  73857. +void set_pid_isoc(dwc_hc_t * hc)
  73858. +{
  73859. + /* Set up the initial PID for the transfer. */
  73860. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  73861. + if (hc->ep_is_in) {
  73862. + if (hc->multi_count == 1) {
  73863. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73864. + } else if (hc->multi_count == 2) {
  73865. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  73866. + } else {
  73867. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  73868. + }
  73869. + } else {
  73870. + if (hc->multi_count == 1) {
  73871. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73872. + } else {
  73873. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  73874. + }
  73875. + }
  73876. + } else {
  73877. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  73878. + }
  73879. +}
  73880. +
  73881. +/**
  73882. + * This function does the setup for a data transfer for a host channel and
  73883. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  73884. + * Slave mode, the caller must ensure that there is sufficient space in the
  73885. + * request queue and Tx Data FIFO.
  73886. + *
  73887. + * For an OUT transfer in Slave mode, it loads a data packet into the
  73888. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  73889. + * the Host ISR.
  73890. + *
  73891. + * For an IN transfer in Slave mode, a data packet is requested. The data
  73892. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  73893. + * additional data packets are requested in the Host ISR.
  73894. + *
  73895. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  73896. + * register along with a packet count of 1 and the channel is enabled. This
  73897. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  73898. + * simply set to 0 since no data transfer occurs in this case.
  73899. + *
  73900. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  73901. + * all the information required to perform the subsequent data transfer. In
  73902. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  73903. + * controller performs the entire PING protocol, then starts the data
  73904. + * transfer.
  73905. + *
  73906. + * @param core_if Programming view of DWC_otg controller.
  73907. + * @param hc Information needed to initialize the host channel. The xfer_len
  73908. + * value may be reduced to accommodate the max widths of the XferSize and
  73909. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  73910. + * to reflect the final xfer_len value.
  73911. + */
  73912. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  73913. +{
  73914. + hcchar_data_t hcchar;
  73915. + hctsiz_data_t hctsiz;
  73916. + uint16_t num_packets;
  73917. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  73918. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  73919. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  73920. +
  73921. + hctsiz.d32 = 0;
  73922. +
  73923. + if (hc->do_ping) {
  73924. + if (!core_if->dma_enable) {
  73925. + dwc_otg_hc_do_ping(core_if, hc);
  73926. + hc->xfer_started = 1;
  73927. + return;
  73928. + } else {
  73929. + hctsiz.b.dopng = 1;
  73930. + }
  73931. + }
  73932. +
  73933. + if (hc->do_split) {
  73934. + num_packets = 1;
  73935. +
  73936. + if (hc->complete_split && !hc->ep_is_in) {
  73937. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  73938. + * core doesn't expect any data written to the FIFO */
  73939. + hc->xfer_len = 0;
  73940. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  73941. + hc->xfer_len = hc->max_packet;
  73942. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  73943. + hc->xfer_len = 188;
  73944. + }
  73945. +
  73946. + hctsiz.b.xfersize = hc->xfer_len;
  73947. + } else {
  73948. + /*
  73949. + * Ensure that the transfer length and packet count will fit
  73950. + * in the widths allocated for them in the HCTSIZn register.
  73951. + */
  73952. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73953. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73954. + /*
  73955. + * Make sure the transfer size is no larger than one
  73956. + * (micro)frame's worth of data. (A check was done
  73957. + * when the periodic transfer was accepted to ensure
  73958. + * that a (micro)frame's worth of data can be
  73959. + * programmed into a channel.)
  73960. + */
  73961. + uint32_t max_periodic_len =
  73962. + hc->multi_count * hc->max_packet;
  73963. + if (hc->xfer_len > max_periodic_len) {
  73964. + hc->xfer_len = max_periodic_len;
  73965. + } else {
  73966. + }
  73967. + } else if (hc->xfer_len > max_hc_xfer_size) {
  73968. + /* Make sure that xfer_len is a multiple of max packet size. */
  73969. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  73970. + }
  73971. +
  73972. + if (hc->xfer_len > 0) {
  73973. + num_packets =
  73974. + (hc->xfer_len + hc->max_packet -
  73975. + 1) / hc->max_packet;
  73976. + if (num_packets > max_hc_pkt_count) {
  73977. + num_packets = max_hc_pkt_count;
  73978. + hc->xfer_len = num_packets * hc->max_packet;
  73979. + }
  73980. + } else {
  73981. + /* Need 1 packet for transfer length of 0. */
  73982. + num_packets = 1;
  73983. + }
  73984. +
  73985. + if (hc->ep_is_in) {
  73986. + /* Always program an integral # of max packets for IN transfers. */
  73987. + hc->xfer_len = num_packets * hc->max_packet;
  73988. + }
  73989. +
  73990. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  73991. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  73992. + /*
  73993. + * Make sure that the multi_count field matches the
  73994. + * actual transfer length.
  73995. + */
  73996. + hc->multi_count = num_packets;
  73997. + }
  73998. +
  73999. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  74000. + set_pid_isoc(hc);
  74001. +
  74002. + hctsiz.b.xfersize = hc->xfer_len;
  74003. + }
  74004. +
  74005. + hc->start_pkt_count = num_packets;
  74006. + hctsiz.b.pktcnt = num_packets;
  74007. + hctsiz.b.pid = hc->data_pid_start;
  74008. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  74009. +
  74010. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  74011. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  74012. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  74013. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  74014. +
  74015. + if (core_if->dma_enable) {
  74016. + dwc_dma_t dma_addr;
  74017. + if (hc->align_buff) {
  74018. + dma_addr = hc->align_buff;
  74019. + } else {
  74020. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  74021. + }
  74022. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  74023. + }
  74024. +
  74025. + /* Start the split */
  74026. + if (hc->do_split) {
  74027. + hcsplt_data_t hcsplt;
  74028. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  74029. + hcsplt.b.spltena = 1;
  74030. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  74031. + }
  74032. +
  74033. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74034. + hcchar.b.multicnt = hc->multi_count;
  74035. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  74036. +#ifdef DEBUG
  74037. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  74038. + if (hcchar.b.chdis) {
  74039. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  74040. + __func__, hc->hc_num, hcchar.d32);
  74041. + }
  74042. +#endif
  74043. +
  74044. + /* Set host channel enable after all other setup is complete. */
  74045. + hcchar.b.chen = 1;
  74046. + hcchar.b.chdis = 0;
  74047. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74048. +
  74049. + hc->xfer_started = 1;
  74050. + hc->requests++;
  74051. +
  74052. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  74053. + /* Load OUT packet into the appropriate Tx FIFO. */
  74054. + dwc_otg_hc_write_packet(core_if, hc);
  74055. + }
  74056. +#ifdef DEBUG
  74057. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  74058. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  74059. + hc->hc_num, core_if);//GRAYG
  74060. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  74061. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  74062. +
  74063. + /* Start a timer for this transfer. */
  74064. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  74065. + }
  74066. +#endif
  74067. +}
  74068. +
  74069. +/**
  74070. + * This function does the setup for a data transfer for a host channel
  74071. + * and starts the transfer in Descriptor DMA mode.
  74072. + *
  74073. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  74074. + * Sets PID and NTD values. For periodic transfers
  74075. + * initializes SCHED_INFO field with micro-frame bitmap.
  74076. + *
  74077. + * Initializes HCDMA register with descriptor list address and CTD value
  74078. + * then starts the transfer via enabling the channel.
  74079. + *
  74080. + * @param core_if Programming view of DWC_otg controller.
  74081. + * @param hc Information needed to initialize the host channel.
  74082. + */
  74083. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  74084. +{
  74085. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  74086. + hcchar_data_t hcchar;
  74087. + hctsiz_data_t hctsiz;
  74088. + hcdma_data_t hcdma;
  74089. +
  74090. + hctsiz.d32 = 0;
  74091. +
  74092. + if (hc->do_ping)
  74093. + hctsiz.b_ddma.dopng = 1;
  74094. +
  74095. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  74096. + set_pid_isoc(hc);
  74097. +
  74098. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  74099. + hctsiz.b_ddma.pid = hc->data_pid_start;
  74100. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  74101. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  74102. +
  74103. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  74104. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  74105. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  74106. +
  74107. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  74108. +
  74109. + hcdma.d32 = 0;
  74110. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  74111. +
  74112. + /* Always start from first descriptor. */
  74113. + hcdma.b.ctd = 0;
  74114. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  74115. +
  74116. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74117. + hcchar.b.multicnt = hc->multi_count;
  74118. +
  74119. +#ifdef DEBUG
  74120. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  74121. + if (hcchar.b.chdis) {
  74122. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  74123. + __func__, hc->hc_num, hcchar.d32);
  74124. + }
  74125. +#endif
  74126. +
  74127. + /* Set host channel enable after all other setup is complete. */
  74128. + hcchar.b.chen = 1;
  74129. + hcchar.b.chdis = 0;
  74130. +
  74131. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74132. +
  74133. + hc->xfer_started = 1;
  74134. + hc->requests++;
  74135. +
  74136. +#ifdef DEBUG
  74137. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  74138. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  74139. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  74140. + hc->hc_num, core_if);//GRAYG
  74141. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  74142. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  74143. + /* Start a timer for this transfer. */
  74144. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  74145. + }
  74146. +#endif
  74147. +
  74148. +}
  74149. +
  74150. +/**
  74151. + * This function continues a data transfer that was started by previous call
  74152. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  74153. + * sufficient space in the request queue and Tx Data FIFO. This function
  74154. + * should only be called in Slave mode. In DMA mode, the controller acts
  74155. + * autonomously to complete transfers programmed to a host channel.
  74156. + *
  74157. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  74158. + * if there is any data remaining to be queued. For an IN transfer, another
  74159. + * data packet is always requested. For the SETUP phase of a control transfer,
  74160. + * this function does nothing.
  74161. + *
  74162. + * @return 1 if a new request is queued, 0 if no more requests are required
  74163. + * for this transfer.
  74164. + */
  74165. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  74166. +{
  74167. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  74168. +
  74169. + if (hc->do_split) {
  74170. + /* SPLITs always queue just once per channel */
  74171. + return 0;
  74172. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  74173. + /* SETUPs are queued only once since they can't be NAKed. */
  74174. + return 0;
  74175. + } else if (hc->ep_is_in) {
  74176. + /*
  74177. + * Always queue another request for other IN transfers. If
  74178. + * back-to-back INs are issued and NAKs are received for both,
  74179. + * the driver may still be processing the first NAK when the
  74180. + * second NAK is received. When the interrupt handler clears
  74181. + * the NAK interrupt for the first NAK, the second NAK will
  74182. + * not be seen. So we can't depend on the NAK interrupt
  74183. + * handler to requeue a NAKed request. Instead, IN requests
  74184. + * are issued each time this function is called. When the
  74185. + * transfer completes, the extra requests for the channel will
  74186. + * be flushed.
  74187. + */
  74188. + hcchar_data_t hcchar;
  74189. + dwc_otg_hc_regs_t *hc_regs =
  74190. + core_if->host_if->hc_regs[hc->hc_num];
  74191. +
  74192. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74193. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  74194. + hcchar.b.chen = 1;
  74195. + hcchar.b.chdis = 0;
  74196. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  74197. + hcchar.d32);
  74198. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74199. + hc->requests++;
  74200. + return 1;
  74201. + } else {
  74202. + /* OUT transfers. */
  74203. + if (hc->xfer_count < hc->xfer_len) {
  74204. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  74205. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  74206. + hcchar_data_t hcchar;
  74207. + dwc_otg_hc_regs_t *hc_regs;
  74208. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  74209. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74210. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  74211. + }
  74212. +
  74213. + /* Load OUT packet into the appropriate Tx FIFO. */
  74214. + dwc_otg_hc_write_packet(core_if, hc);
  74215. + hc->requests++;
  74216. + return 1;
  74217. + } else {
  74218. + return 0;
  74219. + }
  74220. + }
  74221. +}
  74222. +
  74223. +/**
  74224. + * Starts a PING transfer. This function should only be called in Slave mode.
  74225. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  74226. + */
  74227. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  74228. +{
  74229. + hcchar_data_t hcchar;
  74230. + hctsiz_data_t hctsiz;
  74231. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  74232. +
  74233. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  74234. +
  74235. + hctsiz.d32 = 0;
  74236. + hctsiz.b.dopng = 1;
  74237. + hctsiz.b.pktcnt = 1;
  74238. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  74239. +
  74240. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  74241. + hcchar.b.chen = 1;
  74242. + hcchar.b.chdis = 0;
  74243. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  74244. +}
  74245. +
  74246. +/*
  74247. + * This function writes a packet into the Tx FIFO associated with the Host
  74248. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  74249. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  74250. + * periodic Tx FIFO is written. This function should only be called in Slave
  74251. + * mode.
  74252. + *
  74253. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  74254. + * then number of bytes written to the Tx FIFO.
  74255. + */
  74256. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  74257. +{
  74258. + uint32_t i;
  74259. + uint32_t remaining_count;
  74260. + uint32_t byte_count;
  74261. + uint32_t dword_count;
  74262. +
  74263. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  74264. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  74265. +
  74266. + remaining_count = hc->xfer_len - hc->xfer_count;
  74267. + if (remaining_count > hc->max_packet) {
  74268. + byte_count = hc->max_packet;
  74269. + } else {
  74270. + byte_count = remaining_count;
  74271. + }
  74272. +
  74273. + dword_count = (byte_count + 3) / 4;
  74274. +
  74275. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  74276. + /* xfer_buff is DWORD aligned. */
  74277. + for (i = 0; i < dword_count; i++, data_buff++) {
  74278. + DWC_WRITE_REG32(data_fifo, *data_buff);
  74279. + }
  74280. + } else {
  74281. + /* xfer_buff is not DWORD aligned. */
  74282. + for (i = 0; i < dword_count; i++, data_buff++) {
  74283. + uint32_t data;
  74284. + data =
  74285. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  74286. + 16 | data_buff[3] << 24);
  74287. + DWC_WRITE_REG32(data_fifo, data);
  74288. + }
  74289. + }
  74290. +
  74291. + hc->xfer_count += byte_count;
  74292. + hc->xfer_buff += byte_count;
  74293. +}
  74294. +
  74295. +/**
  74296. + * Gets the current USB frame number. This is the frame number from the last
  74297. + * SOF packet.
  74298. + */
  74299. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  74300. +{
  74301. + dsts_data_t dsts;
  74302. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  74303. +
  74304. + /* read current frame/microframe number from DSTS register */
  74305. + return dsts.b.soffn;
  74306. +}
  74307. +
  74308. +/**
  74309. + * Calculates and gets the frame Interval value of HFIR register according PHY
  74310. + * type and speed.The application can modify a value of HFIR register only after
  74311. + * the Port Enable bit of the Host Port Control and Status register
  74312. + * (HPRT.PrtEnaPort) has been set.
  74313. +*/
  74314. +
  74315. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  74316. +{
  74317. + gusbcfg_data_t usbcfg;
  74318. + hwcfg2_data_t hwcfg2;
  74319. + hprt0_data_t hprt0;
  74320. + int clock = 60; // default value
  74321. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  74322. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  74323. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  74324. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  74325. + clock = 60;
  74326. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  74327. + clock = 48;
  74328. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  74329. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  74330. + clock = 30;
  74331. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  74332. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  74333. + clock = 60;
  74334. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  74335. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  74336. + clock = 48;
  74337. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  74338. + clock = 48;
  74339. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  74340. + clock = 48;
  74341. + if (hprt0.b.prtspd == 0)
  74342. + /* High speed case */
  74343. + return 125 * clock;
  74344. + else
  74345. + /* FS/LS case */
  74346. + return 1000 * clock;
  74347. +}
  74348. +
  74349. +/**
  74350. + * This function reads a setup packet from the Rx FIFO into the destination
  74351. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  74352. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  74353. + *
  74354. + * @param core_if Programming view of DWC_otg controller.
  74355. + * @param dest Destination buffer for packet data.
  74356. + */
  74357. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  74358. +{
  74359. + device_grxsts_data_t status;
  74360. + /* Get the 8 bytes of a setup transaction data */
  74361. +
  74362. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  74363. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  74364. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  74365. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  74366. + status.d32 =
  74367. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  74368. + DWC_DEBUGPL(DBG_ANY,
  74369. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  74370. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  74371. + status.b.fn, status.b.fn);
  74372. + }
  74373. +}
  74374. +
  74375. +/**
  74376. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  74377. + * IN for transmitting packets. It is normally called when the
  74378. + * "Enumeration Done" interrupt occurs.
  74379. + *
  74380. + * @param core_if Programming view of DWC_otg controller.
  74381. + * @param ep The EP0 data.
  74382. + */
  74383. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74384. +{
  74385. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  74386. + dsts_data_t dsts;
  74387. + depctl_data_t diepctl;
  74388. + depctl_data_t doepctl;
  74389. + dctl_data_t dctl = {.d32 = 0 };
  74390. +
  74391. + ep->stp_rollover = 0;
  74392. + /* Read the Device Status and Endpoint 0 Control registers */
  74393. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  74394. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  74395. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  74396. +
  74397. + /* Set the MPS of the IN EP based on the enumeration speed */
  74398. + switch (dsts.b.enumspd) {
  74399. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  74400. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  74401. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  74402. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  74403. + break;
  74404. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  74405. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  74406. + break;
  74407. + }
  74408. +
  74409. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  74410. +
  74411. + /* Enable OUT EP for receive */
  74412. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  74413. + doepctl.b.epena = 1;
  74414. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  74415. + }
  74416. +#ifdef VERBOSE
  74417. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  74418. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  74419. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  74420. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  74421. +#endif
  74422. + dctl.b.cgnpinnak = 1;
  74423. +
  74424. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  74425. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  74426. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  74427. +
  74428. +}
  74429. +
  74430. +/**
  74431. + * This function activates an EP. The Device EP control register for
  74432. + * the EP is configured as defined in the ep structure. Note: This
  74433. + * function is not used for EP0.
  74434. + *
  74435. + * @param core_if Programming view of DWC_otg controller.
  74436. + * @param ep The EP to activate.
  74437. + */
  74438. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74439. +{
  74440. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  74441. + depctl_data_t depctl;
  74442. + volatile uint32_t *addr;
  74443. + daint_data_t daintmsk = {.d32 = 0 };
  74444. + dcfg_data_t dcfg;
  74445. + uint8_t i;
  74446. +
  74447. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  74448. + (ep->is_in ? "IN" : "OUT"));
  74449. +
  74450. +#ifdef DWC_UTE_PER_IO
  74451. + ep->xiso_frame_num = 0xFFFFFFFF;
  74452. + ep->xiso_active_xfers = 0;
  74453. + ep->xiso_queued_xfers = 0;
  74454. +#endif
  74455. + /* Read DEPCTLn register */
  74456. + if (ep->is_in == 1) {
  74457. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  74458. + daintmsk.ep.in = 1 << ep->num;
  74459. + } else {
  74460. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  74461. + daintmsk.ep.out = 1 << ep->num;
  74462. + }
  74463. +
  74464. + /* If the EP is already active don't change the EP Control
  74465. + * register. */
  74466. + depctl.d32 = DWC_READ_REG32(addr);
  74467. + if (!depctl.b.usbactep) {
  74468. + depctl.b.mps = ep->maxpacket;
  74469. + depctl.b.eptype = ep->type;
  74470. + depctl.b.txfnum = ep->tx_fifo_num;
  74471. +
  74472. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  74473. + depctl.b.setd0pid = 1; // ???
  74474. + } else {
  74475. + depctl.b.setd0pid = 1;
  74476. + }
  74477. + depctl.b.usbactep = 1;
  74478. +
  74479. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  74480. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  74481. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  74482. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  74483. + break;
  74484. + }
  74485. + core_if->nextep_seq[i] = ep->num;
  74486. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  74487. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  74488. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  74489. + dcfg.b.epmscnt++;
  74490. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  74491. +
  74492. + DWC_DEBUGPL(DBG_PCDV,
  74493. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  74494. + __func__, core_if->first_in_nextep_seq);
  74495. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  74496. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  74497. + core_if->nextep_seq[i]);
  74498. + }
  74499. +
  74500. + }
  74501. +
  74502. +
  74503. + DWC_WRITE_REG32(addr, depctl.d32);
  74504. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  74505. + }
  74506. +
  74507. + /* Enable the Interrupt for this EP */
  74508. + if (core_if->multiproc_int_enable) {
  74509. + if (ep->is_in == 1) {
  74510. + diepmsk_data_t diepmsk = {.d32 = 0 };
  74511. + diepmsk.b.xfercompl = 1;
  74512. + diepmsk.b.timeout = 1;
  74513. + diepmsk.b.epdisabled = 1;
  74514. + diepmsk.b.ahberr = 1;
  74515. + diepmsk.b.intknepmis = 1;
  74516. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  74517. + diepmsk.b.intknepmis = 0;
  74518. + diepmsk.b.txfifoundrn = 1; //?????
  74519. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  74520. + diepmsk.b.nak = 1;
  74521. + }
  74522. +
  74523. +
  74524. +
  74525. +/*
  74526. + if (core_if->dma_desc_enable) {
  74527. + diepmsk.b.bna = 1;
  74528. + }
  74529. +*/
  74530. +/*
  74531. + if (core_if->dma_enable) {
  74532. + doepmsk.b.nak = 1;
  74533. + }
  74534. +*/
  74535. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  74536. + diepeachintmsk[ep->num], diepmsk.d32);
  74537. +
  74538. + } else {
  74539. + doepmsk_data_t doepmsk = {.d32 = 0 };
  74540. + doepmsk.b.xfercompl = 1;
  74541. + doepmsk.b.ahberr = 1;
  74542. + doepmsk.b.epdisabled = 1;
  74543. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  74544. + doepmsk.b.outtknepdis = 1;
  74545. +
  74546. +/*
  74547. +
  74548. + if (core_if->dma_desc_enable) {
  74549. + doepmsk.b.bna = 1;
  74550. + }
  74551. +*/
  74552. +/*
  74553. + doepmsk.b.babble = 1;
  74554. + doepmsk.b.nyet = 1;
  74555. + doepmsk.b.nak = 1;
  74556. +*/
  74557. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  74558. + doepeachintmsk[ep->num], doepmsk.d32);
  74559. + }
  74560. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  74561. + 0, daintmsk.d32);
  74562. + } else {
  74563. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  74564. + if (ep->is_in) {
  74565. + diepmsk_data_t diepmsk = {.d32 = 0 };
  74566. + diepmsk.b.nak = 1;
  74567. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  74568. + } else {
  74569. + doepmsk_data_t doepmsk = {.d32 = 0 };
  74570. + doepmsk.b.outtknepdis = 1;
  74571. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  74572. + }
  74573. + }
  74574. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  74575. + 0, daintmsk.d32);
  74576. + }
  74577. +
  74578. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  74579. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  74580. +
  74581. + ep->stall_clear_flag = 0;
  74582. +
  74583. + return;
  74584. +}
  74585. +
  74586. +/**
  74587. + * This function deactivates an EP. This is done by clearing the USB Active
  74588. + * EP bit in the Device EP control register. Note: This function is not used
  74589. + * for EP0. EP0 cannot be deactivated.
  74590. + *
  74591. + * @param core_if Programming view of DWC_otg controller.
  74592. + * @param ep The EP to deactivate.
  74593. + */
  74594. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74595. +{
  74596. + depctl_data_t depctl = {.d32 = 0 };
  74597. + volatile uint32_t *addr;
  74598. + daint_data_t daintmsk = {.d32 = 0 };
  74599. + dcfg_data_t dcfg;
  74600. + uint8_t i = 0;
  74601. +
  74602. +#ifdef DWC_UTE_PER_IO
  74603. + ep->xiso_frame_num = 0xFFFFFFFF;
  74604. + ep->xiso_active_xfers = 0;
  74605. + ep->xiso_queued_xfers = 0;
  74606. +#endif
  74607. +
  74608. + /* Read DEPCTLn register */
  74609. + if (ep->is_in == 1) {
  74610. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  74611. + daintmsk.ep.in = 1 << ep->num;
  74612. + } else {
  74613. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  74614. + daintmsk.ep.out = 1 << ep->num;
  74615. + }
  74616. +
  74617. + depctl.d32 = DWC_READ_REG32(addr);
  74618. +
  74619. + depctl.b.usbactep = 0;
  74620. +
  74621. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  74622. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  74623. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  74624. + if (core_if->nextep_seq[i] == ep->num)
  74625. + break;
  74626. + }
  74627. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  74628. + if (core_if->first_in_nextep_seq == ep->num)
  74629. + core_if->first_in_nextep_seq = i;
  74630. + core_if->nextep_seq[ep->num] = 0xff;
  74631. + depctl.b.nextep = 0;
  74632. + dcfg.d32 =
  74633. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  74634. + dcfg.b.epmscnt--;
  74635. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  74636. + dcfg.d32);
  74637. +
  74638. + DWC_DEBUGPL(DBG_PCDV,
  74639. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  74640. + __func__, core_if->first_in_nextep_seq);
  74641. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  74642. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  74643. + }
  74644. + }
  74645. +
  74646. + if (ep->is_in == 1)
  74647. + depctl.b.txfnum = 0;
  74648. +
  74649. + if (core_if->dma_desc_enable)
  74650. + depctl.b.epdis = 1;
  74651. +
  74652. + DWC_WRITE_REG32(addr, depctl.d32);
  74653. + depctl.d32 = DWC_READ_REG32(addr);
  74654. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  74655. + && depctl.b.epena) {
  74656. + depctl_data_t depctl = {.d32 = 0};
  74657. + if (ep->is_in) {
  74658. + diepint_data_t diepint = {.d32 = 0};
  74659. +
  74660. + depctl.b.snak = 1;
  74661. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74662. + diepctl, depctl.d32);
  74663. + do {
  74664. + dwc_udelay(10);
  74665. + diepint.d32 =
  74666. + DWC_READ_REG32(&core_if->
  74667. + dev_if->in_ep_regs[ep->num]->
  74668. + diepint);
  74669. + } while (!diepint.b.inepnakeff);
  74670. + diepint.b.inepnakeff = 1;
  74671. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74672. + diepint, diepint.d32);
  74673. + depctl.d32 = 0;
  74674. + depctl.b.epdis = 1;
  74675. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74676. + diepctl, depctl.d32);
  74677. + do {
  74678. + dwc_udelay(10);
  74679. + diepint.d32 =
  74680. + DWC_READ_REG32(&core_if->
  74681. + dev_if->in_ep_regs[ep->num]->
  74682. + diepint);
  74683. + } while (!diepint.b.epdisabled);
  74684. + diepint.b.epdisabled = 1;
  74685. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  74686. + diepint, diepint.d32);
  74687. + } else {
  74688. + dctl_data_t dctl = {.d32 = 0};
  74689. + gintmsk_data_t gintsts = {.d32 = 0};
  74690. + doepint_data_t doepint = {.d32 = 0};
  74691. + dctl.b.sgoutnak = 1;
  74692. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  74693. + dctl, 0, dctl.d32);
  74694. + do {
  74695. + dwc_udelay(10);
  74696. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74697. + } while (!gintsts.b.goutnakeff);
  74698. + gintsts.d32 = 0;
  74699. + gintsts.b.goutnakeff = 1;
  74700. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  74701. +
  74702. + depctl.d32 = 0;
  74703. + depctl.b.epdis = 1;
  74704. + depctl.b.snak = 1;
  74705. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  74706. + do
  74707. + {
  74708. + dwc_udelay(10);
  74709. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  74710. + out_ep_regs[ep->num]->doepint);
  74711. + } while (!doepint.b.epdisabled);
  74712. +
  74713. + doepint.b.epdisabled = 1;
  74714. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  74715. +
  74716. + dctl.d32 = 0;
  74717. + dctl.b.cgoutnak = 1;
  74718. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  74719. + }
  74720. + }
  74721. +
  74722. + /* Disable the Interrupt for this EP */
  74723. + if (core_if->multiproc_int_enable) {
  74724. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  74725. + daintmsk.d32, 0);
  74726. +
  74727. + if (ep->is_in == 1) {
  74728. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  74729. + diepeachintmsk[ep->num], 0);
  74730. + } else {
  74731. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  74732. + doepeachintmsk[ep->num], 0);
  74733. + }
  74734. + } else {
  74735. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  74736. + daintmsk.d32, 0);
  74737. + }
  74738. +
  74739. +}
  74740. +
  74741. +/**
  74742. + * This function initializes dma descriptor chain.
  74743. + *
  74744. + * @param core_if Programming view of DWC_otg controller.
  74745. + * @param ep The EP to start the transfer on.
  74746. + */
  74747. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74748. +{
  74749. + dwc_otg_dev_dma_desc_t *dma_desc;
  74750. + uint32_t offset;
  74751. + uint32_t xfer_est;
  74752. + int i;
  74753. + unsigned maxxfer_local, total_len;
  74754. +
  74755. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  74756. + (ep->maxpacket%4)) {
  74757. + maxxfer_local = ep->maxpacket;
  74758. + total_len = ep->xfer_len;
  74759. + } else {
  74760. + maxxfer_local = ep->maxxfer;
  74761. + total_len = ep->total_len;
  74762. + }
  74763. +
  74764. + ep->desc_cnt = (total_len / maxxfer_local) +
  74765. + ((total_len % maxxfer_local) ? 1 : 0);
  74766. +
  74767. + if (!ep->desc_cnt)
  74768. + ep->desc_cnt = 1;
  74769. +
  74770. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  74771. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  74772. +
  74773. + dma_desc = ep->desc_addr;
  74774. + if (maxxfer_local == ep->maxpacket) {
  74775. + if ((total_len % maxxfer_local) &&
  74776. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  74777. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  74778. + (total_len % maxxfer_local);
  74779. + } else
  74780. + xfer_est = ep->desc_cnt * maxxfer_local;
  74781. + } else
  74782. + xfer_est = total_len;
  74783. + offset = 0;
  74784. + for (i = 0; i < ep->desc_cnt; ++i) {
  74785. + /** DMA Descriptor Setup */
  74786. + if (xfer_est > maxxfer_local) {
  74787. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74788. + dma_desc->status.b.l = 0;
  74789. + dma_desc->status.b.ioc = 0;
  74790. + dma_desc->status.b.sp = 0;
  74791. + dma_desc->status.b.bytes = maxxfer_local;
  74792. + dma_desc->buf = ep->dma_addr + offset;
  74793. + dma_desc->status.b.sts = 0;
  74794. + dma_desc->status.b.bs = BS_HOST_READY;
  74795. +
  74796. + xfer_est -= maxxfer_local;
  74797. + offset += maxxfer_local;
  74798. + } else {
  74799. + dma_desc->status.b.bs = BS_HOST_BUSY;
  74800. + dma_desc->status.b.l = 1;
  74801. + dma_desc->status.b.ioc = 1;
  74802. + if (ep->is_in) {
  74803. + dma_desc->status.b.sp =
  74804. + (xfer_est %
  74805. + ep->maxpacket) ? 1 : ((ep->
  74806. + sent_zlp) ? 1 : 0);
  74807. + dma_desc->status.b.bytes = xfer_est;
  74808. + } else {
  74809. + if (maxxfer_local == ep->maxpacket)
  74810. + dma_desc->status.b.bytes = xfer_est;
  74811. + else
  74812. + dma_desc->status.b.bytes =
  74813. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  74814. + }
  74815. +
  74816. + dma_desc->buf = ep->dma_addr + offset;
  74817. + dma_desc->status.b.sts = 0;
  74818. + dma_desc->status.b.bs = BS_HOST_READY;
  74819. + }
  74820. + dma_desc++;
  74821. + }
  74822. +}
  74823. +/**
  74824. + * This function is called when to write ISOC data into appropriate dedicated
  74825. + * periodic FIFO.
  74826. + */
  74827. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  74828. +{
  74829. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  74830. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  74831. + dtxfsts_data_t txstatus = {.d32 = 0 };
  74832. + uint32_t len = 0;
  74833. + int epnum = dwc_ep->num;
  74834. + int dwords;
  74835. +
  74836. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  74837. +
  74838. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  74839. +
  74840. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  74841. +
  74842. + if (len > dwc_ep->maxpacket) {
  74843. + len = dwc_ep->maxpacket;
  74844. + }
  74845. +
  74846. + dwords = (len + 3) / 4;
  74847. +
  74848. + /* While there is space in the queue and space in the FIFO and
  74849. + * More data to tranfer, Write packets to the Tx FIFO */
  74850. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  74851. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  74852. +
  74853. + while (txstatus.b.txfspcavail > dwords &&
  74854. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  74855. + /* Write the FIFO */
  74856. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  74857. +
  74858. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  74859. + if (len > dwc_ep->maxpacket) {
  74860. + len = dwc_ep->maxpacket;
  74861. + }
  74862. +
  74863. + dwords = (len + 3) / 4;
  74864. + txstatus.d32 =
  74865. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  74866. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  74867. + txstatus.d32);
  74868. + }
  74869. +
  74870. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  74871. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  74872. +
  74873. + return 1;
  74874. +}
  74875. +/**
  74876. + * This function does the setup for a data transfer for an EP and
  74877. + * starts the transfer. For an IN transfer, the packets will be
  74878. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  74879. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  74880. + *
  74881. + * @param core_if Programming view of DWC_otg controller.
  74882. + * @param ep The EP to start the transfer on.
  74883. + */
  74884. +
  74885. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  74886. +{
  74887. + depctl_data_t depctl;
  74888. + deptsiz_data_t deptsiz;
  74889. + gintmsk_data_t intr_mask = {.d32 = 0 };
  74890. +
  74891. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  74892. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  74893. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  74894. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  74895. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  74896. + ep->total_len);
  74897. + /* IN endpoint */
  74898. + if (ep->is_in == 1) {
  74899. + dwc_otg_dev_in_ep_regs_t *in_regs =
  74900. + core_if->dev_if->in_ep_regs[ep->num];
  74901. +
  74902. + gnptxsts_data_t gtxstatus;
  74903. +
  74904. + gtxstatus.d32 =
  74905. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  74906. +
  74907. + if (core_if->en_multiple_tx_fifo == 0
  74908. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  74909. +#ifdef DEBUG
  74910. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  74911. +#endif
  74912. + return;
  74913. + }
  74914. +
  74915. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  74916. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  74917. +
  74918. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  74919. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  74920. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  74921. + else
  74922. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  74923. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  74924. +
  74925. +
  74926. + /* Zero Length Packet? */
  74927. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  74928. + deptsiz.b.xfersize = 0;
  74929. + deptsiz.b.pktcnt = 1;
  74930. + } else {
  74931. + /* Program the transfer size and packet count
  74932. + * as follows: xfersize = N * maxpacket +
  74933. + * short_packet pktcnt = N + (short_packet
  74934. + * exist ? 1 : 0)
  74935. + */
  74936. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  74937. + deptsiz.b.pktcnt =
  74938. + (ep->xfer_len - ep->xfer_count - 1 +
  74939. + ep->maxpacket) / ep->maxpacket;
  74940. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  74941. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  74942. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  74943. + }
  74944. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  74945. + deptsiz.b.mc = deptsiz.b.pktcnt;
  74946. + }
  74947. +
  74948. + /* Write the DMA register */
  74949. + if (core_if->dma_enable) {
  74950. + if (core_if->dma_desc_enable == 0) {
  74951. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  74952. + deptsiz.b.mc = 1;
  74953. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  74954. + deptsiz.d32);
  74955. + DWC_WRITE_REG32(&(in_regs->diepdma),
  74956. + (uint32_t) ep->dma_addr);
  74957. + } else {
  74958. +#ifdef DWC_UTE_CFI
  74959. + /* The descriptor chain should be already initialized by now */
  74960. + if (ep->buff_mode != BM_STANDARD) {
  74961. + DWC_WRITE_REG32(&in_regs->diepdma,
  74962. + ep->descs_dma_addr);
  74963. + } else {
  74964. +#endif
  74965. + init_dma_desc_chain(core_if, ep);
  74966. + /** DIEPDMAn Register write */
  74967. + DWC_WRITE_REG32(&in_regs->diepdma,
  74968. + ep->dma_desc_addr);
  74969. +#ifdef DWC_UTE_CFI
  74970. + }
  74971. +#endif
  74972. + }
  74973. + } else {
  74974. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  74975. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  74976. + /**
  74977. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  74978. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  74979. + * the data will be written into the fifo by the ISR.
  74980. + */
  74981. + if (core_if->en_multiple_tx_fifo == 0) {
  74982. + intr_mask.b.nptxfempty = 1;
  74983. + DWC_MODIFY_REG32
  74984. + (&core_if->core_global_regs->gintmsk,
  74985. + intr_mask.d32, intr_mask.d32);
  74986. + } else {
  74987. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  74988. + if (ep->xfer_len > 0) {
  74989. + uint32_t fifoemptymsk = 0;
  74990. + fifoemptymsk = 1 << ep->num;
  74991. + DWC_MODIFY_REG32
  74992. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  74993. + 0, fifoemptymsk);
  74994. +
  74995. + }
  74996. + }
  74997. + } else {
  74998. + write_isoc_tx_fifo(core_if, ep);
  74999. + }
  75000. + }
  75001. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  75002. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  75003. +
  75004. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  75005. + dsts_data_t dsts = {.d32 = 0};
  75006. + if (ep->bInterval == 1) {
  75007. + dsts.d32 =
  75008. + DWC_READ_REG32(&core_if->dev_if->
  75009. + dev_global_regs->dsts);
  75010. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  75011. + if (ep->frame_num > 0x3FFF) {
  75012. + ep->frm_overrun = 1;
  75013. + ep->frame_num &= 0x3FFF;
  75014. + } else
  75015. + ep->frm_overrun = 0;
  75016. + if (ep->frame_num & 0x1) {
  75017. + depctl.b.setd1pid = 1;
  75018. + } else {
  75019. + depctl.b.setd0pid = 1;
  75020. + }
  75021. + }
  75022. + }
  75023. + /* EP enable, IN data in FIFO */
  75024. + depctl.b.cnak = 1;
  75025. + depctl.b.epena = 1;
  75026. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  75027. +
  75028. + } else {
  75029. + /* OUT endpoint */
  75030. + dwc_otg_dev_out_ep_regs_t *out_regs =
  75031. + core_if->dev_if->out_ep_regs[ep->num];
  75032. +
  75033. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  75034. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  75035. +
  75036. + if (!core_if->dma_desc_enable) {
  75037. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  75038. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  75039. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  75040. + else
  75041. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  75042. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  75043. + }
  75044. +
  75045. + /* Program the transfer size and packet count as follows:
  75046. + *
  75047. + * pktcnt = N
  75048. + * xfersize = N * maxpacket
  75049. + */
  75050. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  75051. + /* Zero Length Packet */
  75052. + deptsiz.b.xfersize = ep->maxpacket;
  75053. + deptsiz.b.pktcnt = 1;
  75054. + } else {
  75055. + deptsiz.b.pktcnt =
  75056. + (ep->xfer_len - ep->xfer_count +
  75057. + (ep->maxpacket - 1)) / ep->maxpacket;
  75058. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  75059. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  75060. + }
  75061. + if (!core_if->dma_desc_enable) {
  75062. + ep->xfer_len =
  75063. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  75064. + }
  75065. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  75066. + }
  75067. +
  75068. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  75069. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  75070. +
  75071. + if (core_if->dma_enable) {
  75072. + if (!core_if->dma_desc_enable) {
  75073. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  75074. + deptsiz.d32);
  75075. +
  75076. + DWC_WRITE_REG32(&(out_regs->doepdma),
  75077. + (uint32_t) ep->dma_addr);
  75078. + } else {
  75079. +#ifdef DWC_UTE_CFI
  75080. + /* The descriptor chain should be already initialized by now */
  75081. + if (ep->buff_mode != BM_STANDARD) {
  75082. + DWC_WRITE_REG32(&out_regs->doepdma,
  75083. + ep->descs_dma_addr);
  75084. + } else {
  75085. +#endif
  75086. + /** This is used for interrupt out transfers*/
  75087. + if (!ep->xfer_len)
  75088. + ep->xfer_len = ep->total_len;
  75089. + init_dma_desc_chain(core_if, ep);
  75090. +
  75091. + if (core_if->core_params->dev_out_nak) {
  75092. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  75093. + deptsiz.b.pktcnt = (ep->total_len +
  75094. + (ep->maxpacket - 1)) / ep->maxpacket;
  75095. + deptsiz.b.xfersize = ep->total_len;
  75096. + /* Remember initial value of doeptsiz */
  75097. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  75098. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  75099. + deptsiz.d32);
  75100. + }
  75101. + }
  75102. + /** DOEPDMAn Register write */
  75103. + DWC_WRITE_REG32(&out_regs->doepdma,
  75104. + ep->dma_desc_addr);
  75105. +#ifdef DWC_UTE_CFI
  75106. + }
  75107. +#endif
  75108. + }
  75109. + } else {
  75110. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  75111. + }
  75112. +
  75113. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  75114. + dsts_data_t dsts = {.d32 = 0};
  75115. + if (ep->bInterval == 1) {
  75116. + dsts.d32 =
  75117. + DWC_READ_REG32(&core_if->dev_if->
  75118. + dev_global_regs->dsts);
  75119. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  75120. + if (ep->frame_num > 0x3FFF) {
  75121. + ep->frm_overrun = 1;
  75122. + ep->frame_num &= 0x3FFF;
  75123. + } else
  75124. + ep->frm_overrun = 0;
  75125. +
  75126. + if (ep->frame_num & 0x1) {
  75127. + depctl.b.setd1pid = 1;
  75128. + } else {
  75129. + depctl.b.setd0pid = 1;
  75130. + }
  75131. + }
  75132. + }
  75133. +
  75134. + /* EP enable */
  75135. + depctl.b.cnak = 1;
  75136. + depctl.b.epena = 1;
  75137. +
  75138. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  75139. +
  75140. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  75141. + DWC_READ_REG32(&out_regs->doepctl),
  75142. + DWC_READ_REG32(&out_regs->doeptsiz));
  75143. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  75144. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  75145. + daintmsk),
  75146. + DWC_READ_REG32(&core_if->core_global_regs->
  75147. + gintmsk));
  75148. +
  75149. + /* Timer is scheduling only for out bulk transfers for
  75150. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  75151. + * about received data payload in case of timeout
  75152. + */
  75153. + if (core_if->core_params->dev_out_nak) {
  75154. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  75155. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  75156. + core_if->ep_xfer_info[ep->num].ep = ep;
  75157. + core_if->ep_xfer_info[ep->num].state = 1;
  75158. +
  75159. + /* Start a timer for this transfer. */
  75160. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  75161. + }
  75162. + }
  75163. + }
  75164. +}
  75165. +
  75166. +/**
  75167. + * This function setup a zero length transfer in Buffer DMA and
  75168. + * Slave modes for usb requests with zero field set
  75169. + *
  75170. + * @param core_if Programming view of DWC_otg controller.
  75171. + * @param ep The EP to start the transfer on.
  75172. + *
  75173. + */
  75174. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75175. +{
  75176. +
  75177. + depctl_data_t depctl;
  75178. + deptsiz_data_t deptsiz;
  75179. + gintmsk_data_t intr_mask = {.d32 = 0 };
  75180. +
  75181. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  75182. + DWC_PRINTF("zero length transfer is called\n");
  75183. +
  75184. + /* IN endpoint */
  75185. + if (ep->is_in == 1) {
  75186. + dwc_otg_dev_in_ep_regs_t *in_regs =
  75187. + core_if->dev_if->in_ep_regs[ep->num];
  75188. +
  75189. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  75190. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  75191. +
  75192. + deptsiz.b.xfersize = 0;
  75193. + deptsiz.b.pktcnt = 1;
  75194. +
  75195. + /* Write the DMA register */
  75196. + if (core_if->dma_enable) {
  75197. + if (core_if->dma_desc_enable == 0) {
  75198. + deptsiz.b.mc = 1;
  75199. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  75200. + deptsiz.d32);
  75201. + DWC_WRITE_REG32(&(in_regs->diepdma),
  75202. + (uint32_t) ep->dma_addr);
  75203. + }
  75204. + } else {
  75205. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  75206. + /**
  75207. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  75208. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  75209. + * the data will be written into the fifo by the ISR.
  75210. + */
  75211. + if (core_if->en_multiple_tx_fifo == 0) {
  75212. + intr_mask.b.nptxfempty = 1;
  75213. + DWC_MODIFY_REG32(&core_if->
  75214. + core_global_regs->gintmsk,
  75215. + intr_mask.d32, intr_mask.d32);
  75216. + } else {
  75217. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  75218. + if (ep->xfer_len > 0) {
  75219. + uint32_t fifoemptymsk = 0;
  75220. + fifoemptymsk = 1 << ep->num;
  75221. + DWC_MODIFY_REG32(&core_if->
  75222. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  75223. + 0, fifoemptymsk);
  75224. + }
  75225. + }
  75226. + }
  75227. +
  75228. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  75229. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  75230. + /* EP enable, IN data in FIFO */
  75231. + depctl.b.cnak = 1;
  75232. + depctl.b.epena = 1;
  75233. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  75234. +
  75235. + } else {
  75236. + /* OUT endpoint */
  75237. + dwc_otg_dev_out_ep_regs_t *out_regs =
  75238. + core_if->dev_if->out_ep_regs[ep->num];
  75239. +
  75240. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  75241. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  75242. +
  75243. + /* Zero Length Packet */
  75244. + deptsiz.b.xfersize = ep->maxpacket;
  75245. + deptsiz.b.pktcnt = 1;
  75246. +
  75247. + if (core_if->dma_enable) {
  75248. + if (!core_if->dma_desc_enable) {
  75249. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  75250. + deptsiz.d32);
  75251. +
  75252. + DWC_WRITE_REG32(&(out_regs->doepdma),
  75253. + (uint32_t) ep->dma_addr);
  75254. + }
  75255. + } else {
  75256. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  75257. + }
  75258. +
  75259. + /* EP enable */
  75260. + depctl.b.cnak = 1;
  75261. + depctl.b.epena = 1;
  75262. +
  75263. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  75264. +
  75265. + }
  75266. +}
  75267. +
  75268. +/**
  75269. + * This function does the setup for a data transfer for EP0 and starts
  75270. + * the transfer. For an IN transfer, the packets will be loaded into
  75271. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  75272. + * unloaded from the Rx FIFO in the ISR.
  75273. + *
  75274. + * @param core_if Programming view of DWC_otg controller.
  75275. + * @param ep The EP0 data.
  75276. + */
  75277. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75278. +{
  75279. + depctl_data_t depctl;
  75280. + deptsiz0_data_t deptsiz;
  75281. + gintmsk_data_t intr_mask = {.d32 = 0 };
  75282. + dwc_otg_dev_dma_desc_t *dma_desc;
  75283. +
  75284. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  75285. + "xfer_buff=%p start_xfer_buff=%p \n",
  75286. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  75287. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  75288. +
  75289. + ep->total_len = ep->xfer_len;
  75290. +
  75291. + /* IN endpoint */
  75292. + if (ep->is_in == 1) {
  75293. + dwc_otg_dev_in_ep_regs_t *in_regs =
  75294. + core_if->dev_if->in_ep_regs[0];
  75295. +
  75296. + gnptxsts_data_t gtxstatus;
  75297. +
  75298. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  75299. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  75300. + if (depctl.b.epena)
  75301. + return;
  75302. + }
  75303. +
  75304. + gtxstatus.d32 =
  75305. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  75306. +
  75307. + /* If dedicated FIFO every time flush fifo before enable ep*/
  75308. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  75309. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  75310. +
  75311. + if (core_if->en_multiple_tx_fifo == 0
  75312. + && gtxstatus.b.nptxqspcavail == 0
  75313. + && !core_if->dma_enable) {
  75314. +#ifdef DEBUG
  75315. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  75316. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  75317. + DWC_READ_REG32(&in_regs->diepctl));
  75318. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  75319. + deptsiz.d32,
  75320. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  75321. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  75322. + gtxstatus.d32);
  75323. +#endif
  75324. + return;
  75325. + }
  75326. +
  75327. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  75328. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  75329. +
  75330. + /* Zero Length Packet? */
  75331. + if (ep->xfer_len == 0) {
  75332. + deptsiz.b.xfersize = 0;
  75333. + deptsiz.b.pktcnt = 1;
  75334. + } else {
  75335. + /* Program the transfer size and packet count
  75336. + * as follows: xfersize = N * maxpacket +
  75337. + * short_packet pktcnt = N + (short_packet
  75338. + * exist ? 1 : 0)
  75339. + */
  75340. + if (ep->xfer_len > ep->maxpacket) {
  75341. + ep->xfer_len = ep->maxpacket;
  75342. + deptsiz.b.xfersize = ep->maxpacket;
  75343. + } else {
  75344. + deptsiz.b.xfersize = ep->xfer_len;
  75345. + }
  75346. + deptsiz.b.pktcnt = 1;
  75347. +
  75348. + }
  75349. + DWC_DEBUGPL(DBG_PCDV,
  75350. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  75351. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  75352. + deptsiz.d32);
  75353. +
  75354. + /* Write the DMA register */
  75355. + if (core_if->dma_enable) {
  75356. + if (core_if->dma_desc_enable == 0) {
  75357. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  75358. + deptsiz.d32);
  75359. +
  75360. + DWC_WRITE_REG32(&(in_regs->diepdma),
  75361. + (uint32_t) ep->dma_addr);
  75362. + } else {
  75363. + dma_desc = core_if->dev_if->in_desc_addr;
  75364. +
  75365. + /** DMA Descriptor Setup */
  75366. + dma_desc->status.b.bs = BS_HOST_BUSY;
  75367. + dma_desc->status.b.l = 1;
  75368. + dma_desc->status.b.ioc = 1;
  75369. + dma_desc->status.b.sp =
  75370. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  75371. + dma_desc->status.b.bytes = ep->xfer_len;
  75372. + dma_desc->buf = ep->dma_addr;
  75373. + dma_desc->status.b.sts = 0;
  75374. + dma_desc->status.b.bs = BS_HOST_READY;
  75375. +
  75376. + /** DIEPDMA0 Register write */
  75377. + DWC_WRITE_REG32(&in_regs->diepdma,
  75378. + core_if->
  75379. + dev_if->dma_in_desc_addr);
  75380. + }
  75381. + } else {
  75382. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  75383. + }
  75384. +
  75385. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  75386. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  75387. + /* EP enable, IN data in FIFO */
  75388. + depctl.b.cnak = 1;
  75389. + depctl.b.epena = 1;
  75390. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  75391. +
  75392. + /**
  75393. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  75394. + * data will be written into the fifo by the ISR.
  75395. + */
  75396. + if (!core_if->dma_enable) {
  75397. + if (core_if->en_multiple_tx_fifo == 0) {
  75398. + intr_mask.b.nptxfempty = 1;
  75399. + DWC_MODIFY_REG32(&core_if->
  75400. + core_global_regs->gintmsk,
  75401. + intr_mask.d32, intr_mask.d32);
  75402. + } else {
  75403. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  75404. + if (ep->xfer_len > 0) {
  75405. + uint32_t fifoemptymsk = 0;
  75406. + fifoemptymsk |= 1 << ep->num;
  75407. + DWC_MODIFY_REG32(&core_if->
  75408. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  75409. + 0, fifoemptymsk);
  75410. + }
  75411. + }
  75412. + }
  75413. + } else {
  75414. + /* OUT endpoint */
  75415. + dwc_otg_dev_out_ep_regs_t *out_regs =
  75416. + core_if->dev_if->out_ep_regs[0];
  75417. +
  75418. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  75419. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  75420. +
  75421. + /* Program the transfer size and packet count as follows:
  75422. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  75423. + * pktcnt = N */
  75424. + /* Zero Length Packet */
  75425. + deptsiz.b.xfersize = ep->maxpacket;
  75426. + deptsiz.b.pktcnt = 1;
  75427. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  75428. + deptsiz.b.supcnt = 3;
  75429. +
  75430. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  75431. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  75432. +
  75433. + if (core_if->dma_enable) {
  75434. + if (!core_if->dma_desc_enable) {
  75435. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  75436. + deptsiz.d32);
  75437. +
  75438. + DWC_WRITE_REG32(&(out_regs->doepdma),
  75439. + (uint32_t) ep->dma_addr);
  75440. + } else {
  75441. + dma_desc = core_if->dev_if->out_desc_addr;
  75442. +
  75443. + /** DMA Descriptor Setup */
  75444. + dma_desc->status.b.bs = BS_HOST_BUSY;
  75445. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  75446. + dma_desc->status.b.mtrf = 0;
  75447. + dma_desc->status.b.sr = 0;
  75448. + }
  75449. + dma_desc->status.b.l = 1;
  75450. + dma_desc->status.b.ioc = 1;
  75451. + dma_desc->status.b.bytes = ep->maxpacket;
  75452. + dma_desc->buf = ep->dma_addr;
  75453. + dma_desc->status.b.sts = 0;
  75454. + dma_desc->status.b.bs = BS_HOST_READY;
  75455. +
  75456. + /** DOEPDMA0 Register write */
  75457. + DWC_WRITE_REG32(&out_regs->doepdma,
  75458. + core_if->dev_if->
  75459. + dma_out_desc_addr);
  75460. + }
  75461. + } else {
  75462. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  75463. + }
  75464. +
  75465. + /* EP enable */
  75466. + depctl.b.cnak = 1;
  75467. + depctl.b.epena = 1;
  75468. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  75469. + }
  75470. +}
  75471. +
  75472. +/**
  75473. + * This function continues control IN transfers started by
  75474. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  75475. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  75476. + * bit for the packet count.
  75477. + *
  75478. + * @param core_if Programming view of DWC_otg controller.
  75479. + * @param ep The EP0 data.
  75480. + */
  75481. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75482. +{
  75483. + depctl_data_t depctl;
  75484. + deptsiz0_data_t deptsiz;
  75485. + gintmsk_data_t intr_mask = {.d32 = 0 };
  75486. + dwc_otg_dev_dma_desc_t *dma_desc;
  75487. +
  75488. + if (ep->is_in == 1) {
  75489. + dwc_otg_dev_in_ep_regs_t *in_regs =
  75490. + core_if->dev_if->in_ep_regs[0];
  75491. + gnptxsts_data_t tx_status = {.d32 = 0 };
  75492. +
  75493. + tx_status.d32 =
  75494. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  75495. + /** @todo Should there be check for room in the Tx
  75496. + * Status Queue. If not remove the code above this comment. */
  75497. +
  75498. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  75499. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  75500. +
  75501. + /* Program the transfer size and packet count
  75502. + * as follows: xfersize = N * maxpacket +
  75503. + * short_packet pktcnt = N + (short_packet
  75504. + * exist ? 1 : 0)
  75505. + */
  75506. +
  75507. + if (core_if->dma_desc_enable == 0) {
  75508. + deptsiz.b.xfersize =
  75509. + (ep->total_len - ep->xfer_count) >
  75510. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  75511. + ep->xfer_count);
  75512. + deptsiz.b.pktcnt = 1;
  75513. + if (core_if->dma_enable == 0) {
  75514. + ep->xfer_len += deptsiz.b.xfersize;
  75515. + } else {
  75516. + ep->xfer_len = deptsiz.b.xfersize;
  75517. + }
  75518. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  75519. + } else {
  75520. + ep->xfer_len =
  75521. + (ep->total_len - ep->xfer_count) >
  75522. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  75523. + ep->xfer_count);
  75524. +
  75525. + dma_desc = core_if->dev_if->in_desc_addr;
  75526. +
  75527. + /** DMA Descriptor Setup */
  75528. + dma_desc->status.b.bs = BS_HOST_BUSY;
  75529. + dma_desc->status.b.l = 1;
  75530. + dma_desc->status.b.ioc = 1;
  75531. + dma_desc->status.b.sp =
  75532. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  75533. + dma_desc->status.b.bytes = ep->xfer_len;
  75534. + dma_desc->buf = ep->dma_addr;
  75535. + dma_desc->status.b.sts = 0;
  75536. + dma_desc->status.b.bs = BS_HOST_READY;
  75537. +
  75538. + /** DIEPDMA0 Register write */
  75539. + DWC_WRITE_REG32(&in_regs->diepdma,
  75540. + core_if->dev_if->dma_in_desc_addr);
  75541. + }
  75542. +
  75543. + DWC_DEBUGPL(DBG_PCDV,
  75544. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  75545. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  75546. + deptsiz.d32);
  75547. +
  75548. + /* Write the DMA register */
  75549. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  75550. + if (core_if->dma_desc_enable == 0)
  75551. + DWC_WRITE_REG32(&(in_regs->diepdma),
  75552. + (uint32_t) ep->dma_addr);
  75553. + }
  75554. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  75555. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  75556. + /* EP enable, IN data in FIFO */
  75557. + depctl.b.cnak = 1;
  75558. + depctl.b.epena = 1;
  75559. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  75560. +
  75561. + /**
  75562. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  75563. + * data will be written into the fifo by the ISR.
  75564. + */
  75565. + if (!core_if->dma_enable) {
  75566. + if (core_if->en_multiple_tx_fifo == 0) {
  75567. + /* First clear it from GINTSTS */
  75568. + intr_mask.b.nptxfempty = 1;
  75569. + DWC_MODIFY_REG32(&core_if->
  75570. + core_global_regs->gintmsk,
  75571. + intr_mask.d32, intr_mask.d32);
  75572. +
  75573. + } else {
  75574. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  75575. + if (ep->xfer_len > 0) {
  75576. + uint32_t fifoemptymsk = 0;
  75577. + fifoemptymsk |= 1 << ep->num;
  75578. + DWC_MODIFY_REG32(&core_if->
  75579. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  75580. + 0, fifoemptymsk);
  75581. + }
  75582. + }
  75583. + }
  75584. + } else {
  75585. + dwc_otg_dev_out_ep_regs_t *out_regs =
  75586. + core_if->dev_if->out_ep_regs[0];
  75587. +
  75588. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  75589. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  75590. +
  75591. + /* Program the transfer size and packet count
  75592. + * as follows: xfersize = N * maxpacket +
  75593. + * short_packet pktcnt = N + (short_packet
  75594. + * exist ? 1 : 0)
  75595. + */
  75596. + deptsiz.b.xfersize = ep->maxpacket;
  75597. + deptsiz.b.pktcnt = 1;
  75598. +
  75599. + if (core_if->dma_desc_enable == 0) {
  75600. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  75601. + } else {
  75602. + dma_desc = core_if->dev_if->out_desc_addr;
  75603. +
  75604. + /** DMA Descriptor Setup */
  75605. + dma_desc->status.b.bs = BS_HOST_BUSY;
  75606. + dma_desc->status.b.l = 1;
  75607. + dma_desc->status.b.ioc = 1;
  75608. + dma_desc->status.b.bytes = ep->maxpacket;
  75609. + dma_desc->buf = ep->dma_addr;
  75610. + dma_desc->status.b.sts = 0;
  75611. + dma_desc->status.b.bs = BS_HOST_READY;
  75612. +
  75613. + /** DOEPDMA0 Register write */
  75614. + DWC_WRITE_REG32(&out_regs->doepdma,
  75615. + core_if->dev_if->dma_out_desc_addr);
  75616. + }
  75617. +
  75618. + DWC_DEBUGPL(DBG_PCDV,
  75619. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  75620. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  75621. + deptsiz.d32);
  75622. +
  75623. + /* Write the DMA register */
  75624. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  75625. + if (core_if->dma_desc_enable == 0)
  75626. + DWC_WRITE_REG32(&(out_regs->doepdma),
  75627. + (uint32_t) ep->dma_addr);
  75628. +
  75629. + }
  75630. +
  75631. + /* EP enable, IN data in FIFO */
  75632. + depctl.b.cnak = 1;
  75633. + depctl.b.epena = 1;
  75634. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  75635. +
  75636. + }
  75637. +}
  75638. +
  75639. +#ifdef DEBUG
  75640. +void dump_msg(const u8 * buf, unsigned int length)
  75641. +{
  75642. + unsigned int start, num, i;
  75643. + char line[52], *p;
  75644. +
  75645. + if (length >= 512)
  75646. + return;
  75647. + start = 0;
  75648. + while (length > 0) {
  75649. + num = length < 16u ? length : 16u;
  75650. + p = line;
  75651. + for (i = 0; i < num; ++i) {
  75652. + if (i == 8)
  75653. + *p++ = ' ';
  75654. + DWC_SPRINTF(p, " %02x", buf[i]);
  75655. + p += 3;
  75656. + }
  75657. + *p = 0;
  75658. + DWC_PRINTF("%6x: %s\n", start, line);
  75659. + buf += num;
  75660. + start += num;
  75661. + length -= num;
  75662. + }
  75663. +}
  75664. +#else
  75665. +static inline void dump_msg(const u8 * buf, unsigned int length)
  75666. +{
  75667. +}
  75668. +#endif
  75669. +
  75670. +/**
  75671. + * This function writes a packet into the Tx FIFO associated with the
  75672. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  75673. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  75674. + * with all packets for the next micro-frame.
  75675. + *
  75676. + * @param core_if Programming view of DWC_otg controller.
  75677. + * @param ep The EP to write packet for.
  75678. + * @param dma Indicates if DMA is being used.
  75679. + */
  75680. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  75681. + int dma)
  75682. +{
  75683. + /**
  75684. + * The buffer is padded to DWORD on a per packet basis in
  75685. + * slave/dma mode if the MPS is not DWORD aligned. The last
  75686. + * packet, if short, is also padded to a multiple of DWORD.
  75687. + *
  75688. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  75689. + * multiple of DWORD in length
  75690. + *
  75691. + * ep->xfer_len can be any number of bytes
  75692. + *
  75693. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  75694. + * packet
  75695. + *
  75696. + * FIFO access is DWORD */
  75697. +
  75698. + uint32_t i;
  75699. + uint32_t byte_count;
  75700. + uint32_t dword_count;
  75701. + uint32_t *fifo;
  75702. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  75703. +
  75704. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  75705. + ep);
  75706. + if (ep->xfer_count >= ep->xfer_len) {
  75707. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  75708. + return;
  75709. + }
  75710. +
  75711. + /* Find the byte length of the packet either short packet or MPS */
  75712. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  75713. + byte_count = ep->xfer_len - ep->xfer_count;
  75714. + } else {
  75715. + byte_count = ep->maxpacket;
  75716. + }
  75717. +
  75718. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  75719. + * is not a multiple of DWORD */
  75720. + dword_count = (byte_count + 3) / 4;
  75721. +
  75722. +#ifdef VERBOSE
  75723. + dump_msg(ep->xfer_buff, byte_count);
  75724. +#endif
  75725. +
  75726. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  75727. + * intialized? What should this be? */
  75728. +
  75729. + fifo = core_if->data_fifo[ep->num];
  75730. +
  75731. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  75732. + fifo, data_buff, *data_buff, byte_count);
  75733. +
  75734. + if (!dma) {
  75735. + for (i = 0; i < dword_count; i++, data_buff++) {
  75736. + DWC_WRITE_REG32(fifo, *data_buff);
  75737. + }
  75738. + }
  75739. +
  75740. + ep->xfer_count += byte_count;
  75741. + ep->xfer_buff += byte_count;
  75742. + ep->dma_addr += byte_count;
  75743. +}
  75744. +
  75745. +/**
  75746. + * Set the EP STALL.
  75747. + *
  75748. + * @param core_if Programming view of DWC_otg controller.
  75749. + * @param ep The EP to set the stall on.
  75750. + */
  75751. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75752. +{
  75753. + depctl_data_t depctl;
  75754. + volatile uint32_t *depctl_addr;
  75755. +
  75756. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  75757. + (ep->is_in ? "IN" : "OUT"));
  75758. +
  75759. + if (ep->is_in == 1) {
  75760. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  75761. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75762. +
  75763. + /* set the disable and stall bits */
  75764. + if (depctl.b.epena) {
  75765. + depctl.b.epdis = 1;
  75766. + }
  75767. + depctl.b.stall = 1;
  75768. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75769. + } else {
  75770. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  75771. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75772. +
  75773. + /* set the stall bit */
  75774. + depctl.b.stall = 1;
  75775. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75776. + }
  75777. +
  75778. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  75779. +
  75780. + return;
  75781. +}
  75782. +
  75783. +/**
  75784. + * Clear the EP STALL.
  75785. + *
  75786. + * @param core_if Programming view of DWC_otg controller.
  75787. + * @param ep The EP to clear stall from.
  75788. + */
  75789. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  75790. +{
  75791. + depctl_data_t depctl;
  75792. + volatile uint32_t *depctl_addr;
  75793. +
  75794. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  75795. + (ep->is_in ? "IN" : "OUT"));
  75796. +
  75797. + if (ep->is_in == 1) {
  75798. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  75799. + } else {
  75800. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  75801. + }
  75802. +
  75803. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  75804. +
  75805. + /* clear the stall bits */
  75806. + depctl.b.stall = 0;
  75807. +
  75808. + /*
  75809. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  75810. + * of whether an endpoint has the Halt feature set, a
  75811. + * ClearFeature(ENDPOINT_HALT) request always results in the
  75812. + * data toggle being reinitialized to DATA0.
  75813. + */
  75814. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  75815. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  75816. + depctl.b.setd0pid = 1; /* DATA0 */
  75817. + }
  75818. +
  75819. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  75820. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  75821. + return;
  75822. +}
  75823. +
  75824. +/**
  75825. + * This function reads a packet from the Rx FIFO into the destination
  75826. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  75827. + *
  75828. + * @param core_if Programming view of DWC_otg controller.
  75829. + * @param dest Destination buffer for the packet.
  75830. + * @param bytes Number of bytes to copy to the destination.
  75831. + */
  75832. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  75833. + uint8_t * dest, uint16_t bytes)
  75834. +{
  75835. + int i;
  75836. + int word_count = (bytes + 3) / 4;
  75837. +
  75838. + volatile uint32_t *fifo = core_if->data_fifo[0];
  75839. + uint32_t *data_buff = (uint32_t *) dest;
  75840. +
  75841. + /**
  75842. + * @todo Account for the case where _dest is not dword aligned. This
  75843. + * requires reading data from the FIFO into a uint32_t temp buffer,
  75844. + * then moving it into the data buffer.
  75845. + */
  75846. +
  75847. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  75848. + core_if, dest, bytes);
  75849. +
  75850. + for (i = 0; i < word_count; i++, data_buff++) {
  75851. + *data_buff = DWC_READ_REG32(fifo);
  75852. + }
  75853. +
  75854. + return;
  75855. +}
  75856. +
  75857. +/**
  75858. + * This functions reads the device registers and prints them
  75859. + *
  75860. + * @param core_if Programming view of DWC_otg controller.
  75861. + */
  75862. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  75863. +{
  75864. + int i;
  75865. + volatile uint32_t *addr;
  75866. +
  75867. + DWC_PRINTF("Device Global Registers\n");
  75868. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  75869. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  75870. + (unsigned long)addr, DWC_READ_REG32(addr));
  75871. + addr = &core_if->dev_if->dev_global_regs->dctl;
  75872. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  75873. + (unsigned long)addr, DWC_READ_REG32(addr));
  75874. + addr = &core_if->dev_if->dev_global_regs->dsts;
  75875. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  75876. + (unsigned long)addr, DWC_READ_REG32(addr));
  75877. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  75878. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75879. + DWC_READ_REG32(addr));
  75880. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  75881. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75882. + DWC_READ_REG32(addr));
  75883. + addr = &core_if->dev_if->dev_global_regs->daint;
  75884. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75885. + DWC_READ_REG32(addr));
  75886. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  75887. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75888. + DWC_READ_REG32(addr));
  75889. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  75890. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75891. + DWC_READ_REG32(addr));
  75892. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  75893. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  75894. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  75895. + (unsigned long)addr, DWC_READ_REG32(addr));
  75896. + }
  75897. +
  75898. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  75899. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75900. + DWC_READ_REG32(addr));
  75901. +
  75902. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  75903. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  75904. + (unsigned long)addr, DWC_READ_REG32(addr));
  75905. +
  75906. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  75907. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  75908. + (unsigned long)addr, DWC_READ_REG32(addr));
  75909. +
  75910. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  75911. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  75912. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  75913. + (unsigned long)addr, DWC_READ_REG32(addr));
  75914. + }
  75915. +
  75916. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  75917. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  75918. + DWC_READ_REG32(addr));
  75919. +
  75920. + if (core_if->hwcfg2.b.multi_proc_int) {
  75921. +
  75922. + addr = &core_if->dev_if->dev_global_regs->deachint;
  75923. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  75924. + (unsigned long)addr, DWC_READ_REG32(addr));
  75925. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  75926. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  75927. + (unsigned long)addr, DWC_READ_REG32(addr));
  75928. +
  75929. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  75930. + addr =
  75931. + &core_if->dev_if->
  75932. + dev_global_regs->diepeachintmsk[i];
  75933. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  75934. + i, (unsigned long)addr,
  75935. + DWC_READ_REG32(addr));
  75936. + }
  75937. +
  75938. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  75939. + addr =
  75940. + &core_if->dev_if->
  75941. + dev_global_regs->doepeachintmsk[i];
  75942. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  75943. + i, (unsigned long)addr,
  75944. + DWC_READ_REG32(addr));
  75945. + }
  75946. + }
  75947. +
  75948. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  75949. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  75950. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  75951. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  75952. + (unsigned long)addr, DWC_READ_REG32(addr));
  75953. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  75954. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  75955. + (unsigned long)addr, DWC_READ_REG32(addr));
  75956. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  75957. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  75958. + (unsigned long)addr, DWC_READ_REG32(addr));
  75959. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  75960. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  75961. + (unsigned long)addr, DWC_READ_REG32(addr));
  75962. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  75963. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  75964. + (unsigned long)addr, DWC_READ_REG32(addr));
  75965. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  75966. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  75967. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  75968. + }
  75969. +
  75970. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  75971. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  75972. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  75973. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  75974. + (unsigned long)addr, DWC_READ_REG32(addr));
  75975. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  75976. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  75977. + (unsigned long)addr, DWC_READ_REG32(addr));
  75978. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  75979. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  75980. + (unsigned long)addr, DWC_READ_REG32(addr));
  75981. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  75982. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  75983. + (unsigned long)addr, DWC_READ_REG32(addr));
  75984. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  75985. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  75986. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  75987. + (unsigned long)addr, DWC_READ_REG32(addr));
  75988. + }
  75989. +
  75990. + }
  75991. +}
  75992. +
  75993. +/**
  75994. + * This functions reads the SPRAM and prints its content
  75995. + *
  75996. + * @param core_if Programming view of DWC_otg controller.
  75997. + */
  75998. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  75999. +{
  76000. + volatile uint8_t *addr, *start_addr, *end_addr;
  76001. +
  76002. + DWC_PRINTF("SPRAM Data:\n");
  76003. + start_addr = (void *)core_if->core_global_regs;
  76004. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  76005. + start_addr += 0x00028000;
  76006. + end_addr = (void *)core_if->core_global_regs;
  76007. + end_addr += 0x000280e0;
  76008. +
  76009. + for (addr = start_addr; addr < end_addr; addr += 16) {
  76010. + DWC_PRINTF
  76011. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  76012. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  76013. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  76014. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  76015. + );
  76016. + }
  76017. +
  76018. + return;
  76019. +}
  76020. +
  76021. +/**
  76022. + * This function reads the host registers and prints them
  76023. + *
  76024. + * @param core_if Programming view of DWC_otg controller.
  76025. + */
  76026. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  76027. +{
  76028. + int i;
  76029. + volatile uint32_t *addr;
  76030. +
  76031. + DWC_PRINTF("Host Global Registers\n");
  76032. + addr = &core_if->host_if->host_global_regs->hcfg;
  76033. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  76034. + (unsigned long)addr, DWC_READ_REG32(addr));
  76035. + addr = &core_if->host_if->host_global_regs->hfir;
  76036. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  76037. + (unsigned long)addr, DWC_READ_REG32(addr));
  76038. + addr = &core_if->host_if->host_global_regs->hfnum;
  76039. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76040. + DWC_READ_REG32(addr));
  76041. + addr = &core_if->host_if->host_global_regs->hptxsts;
  76042. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76043. + DWC_READ_REG32(addr));
  76044. + addr = &core_if->host_if->host_global_regs->haint;
  76045. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76046. + DWC_READ_REG32(addr));
  76047. + addr = &core_if->host_if->host_global_regs->haintmsk;
  76048. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76049. + DWC_READ_REG32(addr));
  76050. + if (core_if->dma_desc_enable) {
  76051. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  76052. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  76053. + (unsigned long)addr, DWC_READ_REG32(addr));
  76054. + }
  76055. +
  76056. + addr = core_if->host_if->hprt0;
  76057. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76058. + DWC_READ_REG32(addr));
  76059. +
  76060. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  76061. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  76062. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  76063. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  76064. + (unsigned long)addr, DWC_READ_REG32(addr));
  76065. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  76066. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  76067. + (unsigned long)addr, DWC_READ_REG32(addr));
  76068. + addr = &core_if->host_if->hc_regs[i]->hcint;
  76069. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  76070. + (unsigned long)addr, DWC_READ_REG32(addr));
  76071. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  76072. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  76073. + (unsigned long)addr, DWC_READ_REG32(addr));
  76074. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  76075. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  76076. + (unsigned long)addr, DWC_READ_REG32(addr));
  76077. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  76078. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  76079. + (unsigned long)addr, DWC_READ_REG32(addr));
  76080. + if (core_if->dma_desc_enable) {
  76081. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  76082. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  76083. + (unsigned long)addr, DWC_READ_REG32(addr));
  76084. + }
  76085. +
  76086. + }
  76087. + return;
  76088. +}
  76089. +
  76090. +/**
  76091. + * This function reads the core global registers and prints them
  76092. + *
  76093. + * @param core_if Programming view of DWC_otg controller.
  76094. + */
  76095. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  76096. +{
  76097. + int i, ep_num;
  76098. + volatile uint32_t *addr;
  76099. + char *txfsiz;
  76100. +
  76101. + DWC_PRINTF("Core Global Registers\n");
  76102. + addr = &core_if->core_global_regs->gotgctl;
  76103. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76104. + DWC_READ_REG32(addr));
  76105. + addr = &core_if->core_global_regs->gotgint;
  76106. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76107. + DWC_READ_REG32(addr));
  76108. + addr = &core_if->core_global_regs->gahbcfg;
  76109. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76110. + DWC_READ_REG32(addr));
  76111. + addr = &core_if->core_global_regs->gusbcfg;
  76112. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76113. + DWC_READ_REG32(addr));
  76114. + addr = &core_if->core_global_regs->grstctl;
  76115. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76116. + DWC_READ_REG32(addr));
  76117. + addr = &core_if->core_global_regs->gintsts;
  76118. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76119. + DWC_READ_REG32(addr));
  76120. + addr = &core_if->core_global_regs->gintmsk;
  76121. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76122. + DWC_READ_REG32(addr));
  76123. + addr = &core_if->core_global_regs->grxstsr;
  76124. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76125. + DWC_READ_REG32(addr));
  76126. + addr = &core_if->core_global_regs->grxfsiz;
  76127. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76128. + DWC_READ_REG32(addr));
  76129. + addr = &core_if->core_global_regs->gnptxfsiz;
  76130. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76131. + DWC_READ_REG32(addr));
  76132. + addr = &core_if->core_global_regs->gnptxsts;
  76133. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76134. + DWC_READ_REG32(addr));
  76135. + addr = &core_if->core_global_regs->gi2cctl;
  76136. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76137. + DWC_READ_REG32(addr));
  76138. + addr = &core_if->core_global_regs->gpvndctl;
  76139. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76140. + DWC_READ_REG32(addr));
  76141. + addr = &core_if->core_global_regs->ggpio;
  76142. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76143. + DWC_READ_REG32(addr));
  76144. + addr = &core_if->core_global_regs->guid;
  76145. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  76146. + (unsigned long)addr, DWC_READ_REG32(addr));
  76147. + addr = &core_if->core_global_regs->gsnpsid;
  76148. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76149. + DWC_READ_REG32(addr));
  76150. + addr = &core_if->core_global_regs->ghwcfg1;
  76151. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76152. + DWC_READ_REG32(addr));
  76153. + addr = &core_if->core_global_regs->ghwcfg2;
  76154. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76155. + DWC_READ_REG32(addr));
  76156. + addr = &core_if->core_global_regs->ghwcfg3;
  76157. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76158. + DWC_READ_REG32(addr));
  76159. + addr = &core_if->core_global_regs->ghwcfg4;
  76160. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76161. + DWC_READ_REG32(addr));
  76162. + addr = &core_if->core_global_regs->glpmcfg;
  76163. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76164. + DWC_READ_REG32(addr));
  76165. + addr = &core_if->core_global_regs->gpwrdn;
  76166. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76167. + DWC_READ_REG32(addr));
  76168. + addr = &core_if->core_global_regs->gdfifocfg;
  76169. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76170. + DWC_READ_REG32(addr));
  76171. + addr = &core_if->core_global_regs->adpctl;
  76172. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76173. + dwc_otg_adp_read_reg(core_if));
  76174. + addr = &core_if->core_global_regs->hptxfsiz;
  76175. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76176. + DWC_READ_REG32(addr));
  76177. +
  76178. + if (core_if->en_multiple_tx_fifo == 0) {
  76179. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  76180. + txfsiz = "DPTXFSIZ";
  76181. + } else {
  76182. + ep_num = core_if->hwcfg4.b.num_in_eps;
  76183. + txfsiz = "DIENPTXF";
  76184. + }
  76185. + for (i = 0; i < ep_num; i++) {
  76186. + addr = &core_if->core_global_regs->dtxfsiz[i];
  76187. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  76188. + (unsigned long)addr, DWC_READ_REG32(addr));
  76189. + }
  76190. + addr = core_if->pcgcctl;
  76191. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  76192. + DWC_READ_REG32(addr));
  76193. +}
  76194. +
  76195. +/**
  76196. + * Flush a Tx FIFO.
  76197. + *
  76198. + * @param core_if Programming view of DWC_otg controller.
  76199. + * @param num Tx FIFO to flush.
  76200. + */
  76201. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  76202. +{
  76203. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  76204. + volatile grstctl_t greset = {.d32 = 0 };
  76205. + int count = 0;
  76206. +
  76207. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  76208. +
  76209. + greset.b.txfflsh = 1;
  76210. + greset.b.txfnum = num;
  76211. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  76212. +
  76213. + do {
  76214. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  76215. + if (++count > 10000) {
  76216. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  76217. + __func__, greset.d32,
  76218. + DWC_READ_REG32(&global_regs->gnptxsts));
  76219. + break;
  76220. + }
  76221. + dwc_udelay(1);
  76222. + } while (greset.b.txfflsh == 1);
  76223. +
  76224. + /* Wait for 3 PHY Clocks */
  76225. + dwc_udelay(1);
  76226. +}
  76227. +
  76228. +/**
  76229. + * Flush Rx FIFO.
  76230. + *
  76231. + * @param core_if Programming view of DWC_otg controller.
  76232. + */
  76233. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  76234. +{
  76235. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  76236. + volatile grstctl_t greset = {.d32 = 0 };
  76237. + int count = 0;
  76238. +
  76239. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  76240. + /*
  76241. + *
  76242. + */
  76243. + greset.b.rxfflsh = 1;
  76244. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  76245. +
  76246. + do {
  76247. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  76248. + if (++count > 10000) {
  76249. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  76250. + greset.d32);
  76251. + break;
  76252. + }
  76253. + dwc_udelay(1);
  76254. + } while (greset.b.rxfflsh == 1);
  76255. +
  76256. + /* Wait for 3 PHY Clocks */
  76257. + dwc_udelay(1);
  76258. +}
  76259. +
  76260. +/**
  76261. + * Do core a soft reset of the core. Be careful with this because it
  76262. + * resets all the internal state machines of the core.
  76263. + */
  76264. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  76265. +{
  76266. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  76267. + volatile grstctl_t greset = {.d32 = 0 };
  76268. + int count = 0;
  76269. +
  76270. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  76271. + /* Wait for AHB master IDLE state. */
  76272. + do {
  76273. + dwc_udelay(10);
  76274. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  76275. + if (++count > 100000) {
  76276. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  76277. + greset.d32);
  76278. + return;
  76279. + }
  76280. + }
  76281. + while (greset.b.ahbidle == 0);
  76282. +
  76283. + /* Core Soft Reset */
  76284. + count = 0;
  76285. + greset.b.csftrst = 1;
  76286. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  76287. + do {
  76288. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  76289. + if (++count > 10000) {
  76290. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  76291. + __func__, greset.d32);
  76292. + break;
  76293. + }
  76294. + dwc_udelay(1);
  76295. + }
  76296. + while (greset.b.csftrst == 1);
  76297. +
  76298. + /* Wait for 3 PHY Clocks */
  76299. + dwc_mdelay(100);
  76300. +}
  76301. +
  76302. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  76303. +{
  76304. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  76305. +}
  76306. +
  76307. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  76308. +{
  76309. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  76310. +}
  76311. +
  76312. +/**
  76313. + * Register HCD callbacks. The callbacks are used to start and stop
  76314. + * the HCD for interrupt processing.
  76315. + *
  76316. + * @param core_if Programming view of DWC_otg controller.
  76317. + * @param cb the HCD callback structure.
  76318. + * @param p pointer to be passed to callback function (usb_hcd*).
  76319. + */
  76320. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  76321. + dwc_otg_cil_callbacks_t * cb, void *p)
  76322. +{
  76323. + core_if->hcd_cb = cb;
  76324. + cb->p = p;
  76325. +}
  76326. +
  76327. +/**
  76328. + * Register PCD callbacks. The callbacks are used to start and stop
  76329. + * the PCD for interrupt processing.
  76330. + *
  76331. + * @param core_if Programming view of DWC_otg controller.
  76332. + * @param cb the PCD callback structure.
  76333. + * @param p pointer to be passed to callback function (pcd*).
  76334. + */
  76335. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  76336. + dwc_otg_cil_callbacks_t * cb, void *p)
  76337. +{
  76338. + core_if->pcd_cb = cb;
  76339. + cb->p = p;
  76340. +}
  76341. +
  76342. +#ifdef DWC_EN_ISOC
  76343. +
  76344. +/**
  76345. + * This function writes isoc data per 1 (micro)frame into tx fifo
  76346. + *
  76347. + * @param core_if Programming view of DWC_otg controller.
  76348. + * @param ep The EP to start the transfer on.
  76349. + *
  76350. + */
  76351. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  76352. +{
  76353. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  76354. + dtxfsts_data_t txstatus = {.d32 = 0 };
  76355. + uint32_t len = 0;
  76356. + uint32_t dwords;
  76357. +
  76358. + ep->xfer_len = ep->data_per_frame;
  76359. + ep->xfer_count = 0;
  76360. +
  76361. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  76362. +
  76363. + len = ep->xfer_len - ep->xfer_count;
  76364. +
  76365. + if (len > ep->maxpacket) {
  76366. + len = ep->maxpacket;
  76367. + }
  76368. +
  76369. + dwords = (len + 3) / 4;
  76370. +
  76371. + /* While there is space in the queue and space in the FIFO and
  76372. + * More data to tranfer, Write packets to the Tx FIFO */
  76373. + txstatus.d32 =
  76374. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  76375. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  76376. +
  76377. + while (txstatus.b.txfspcavail > dwords &&
  76378. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  76379. + /* Write the FIFO */
  76380. + dwc_otg_ep_write_packet(core_if, ep, 0);
  76381. +
  76382. + len = ep->xfer_len - ep->xfer_count;
  76383. + if (len > ep->maxpacket) {
  76384. + len = ep->maxpacket;
  76385. + }
  76386. +
  76387. + dwords = (len + 3) / 4;
  76388. + txstatus.d32 =
  76389. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  76390. + dtxfsts);
  76391. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  76392. + txstatus.d32);
  76393. + }
  76394. +}
  76395. +
  76396. +/**
  76397. + * This function initializes a descriptor chain for Isochronous transfer
  76398. + *
  76399. + * @param core_if Programming view of DWC_otg controller.
  76400. + * @param ep The EP to start the transfer on.
  76401. + *
  76402. + */
  76403. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  76404. + dwc_ep_t * ep)
  76405. +{
  76406. + deptsiz_data_t deptsiz = {.d32 = 0 };
  76407. + depctl_data_t depctl = {.d32 = 0 };
  76408. + dsts_data_t dsts = {.d32 = 0 };
  76409. + volatile uint32_t *addr;
  76410. +
  76411. + if (ep->is_in) {
  76412. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  76413. + } else {
  76414. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  76415. + }
  76416. +
  76417. + ep->xfer_len = ep->data_per_frame;
  76418. + ep->xfer_count = 0;
  76419. + ep->xfer_buff = ep->cur_pkt_addr;
  76420. + ep->dma_addr = ep->cur_pkt_dma_addr;
  76421. +
  76422. + if (ep->is_in) {
  76423. + /* Program the transfer size and packet count
  76424. + * as follows: xfersize = N * maxpacket +
  76425. + * short_packet pktcnt = N + (short_packet
  76426. + * exist ? 1 : 0)
  76427. + */
  76428. + deptsiz.b.xfersize = ep->xfer_len;
  76429. + deptsiz.b.pktcnt =
  76430. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  76431. + deptsiz.b.mc = deptsiz.b.pktcnt;
  76432. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  76433. + deptsiz.d32);
  76434. +
  76435. + /* Write the DMA register */
  76436. + if (core_if->dma_enable) {
  76437. + DWC_WRITE_REG32(&
  76438. + (core_if->dev_if->in_ep_regs[ep->num]->
  76439. + diepdma), (uint32_t) ep->dma_addr);
  76440. + }
  76441. + } else {
  76442. + deptsiz.b.pktcnt =
  76443. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  76444. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  76445. +
  76446. + DWC_WRITE_REG32(&core_if->dev_if->
  76447. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  76448. +
  76449. + if (core_if->dma_enable) {
  76450. + DWC_WRITE_REG32(&
  76451. + (core_if->dev_if->
  76452. + out_ep_regs[ep->num]->doepdma),
  76453. + (uint32_t) ep->dma_addr);
  76454. + }
  76455. + }
  76456. +
  76457. + /** Enable endpoint, clear nak */
  76458. +
  76459. + depctl.d32 = 0;
  76460. + if (ep->bInterval == 1) {
  76461. + dsts.d32 =
  76462. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  76463. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  76464. +
  76465. + if (ep->next_frame & 0x1) {
  76466. + depctl.b.setd1pid = 1;
  76467. + } else {
  76468. + depctl.b.setd0pid = 1;
  76469. + }
  76470. + } else {
  76471. + ep->next_frame += ep->bInterval;
  76472. +
  76473. + if (ep->next_frame & 0x1) {
  76474. + depctl.b.setd1pid = 1;
  76475. + } else {
  76476. + depctl.b.setd0pid = 1;
  76477. + }
  76478. + }
  76479. + depctl.b.epena = 1;
  76480. + depctl.b.cnak = 1;
  76481. +
  76482. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  76483. + depctl.d32 = DWC_READ_REG32(addr);
  76484. +
  76485. + if (ep->is_in && core_if->dma_enable == 0) {
  76486. + write_isoc_frame_data(core_if, ep);
  76487. + }
  76488. +
  76489. +}
  76490. +#endif /* DWC_EN_ISOC */
  76491. +
  76492. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  76493. +{
  76494. + int i;
  76495. + for (i = 0; i < size; i++) {
  76496. + p[i] = -1;
  76497. + }
  76498. +}
  76499. +
  76500. +static int dwc_otg_param_initialized(int32_t val)
  76501. +{
  76502. + return val != -1;
  76503. +}
  76504. +
  76505. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  76506. +{
  76507. + int i;
  76508. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  76509. + if (!core_if->core_params) {
  76510. + return -DWC_E_NO_MEMORY;
  76511. + }
  76512. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  76513. + sizeof(*core_if->core_params) /
  76514. + sizeof(int32_t));
  76515. + DWC_PRINTF("Setting default values for core params\n");
  76516. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  76517. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  76518. + dwc_otg_set_param_dma_desc_enable(core_if,
  76519. + dwc_param_dma_desc_enable_default);
  76520. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  76521. + dwc_otg_set_param_dma_burst_size(core_if,
  76522. + dwc_param_dma_burst_size_default);
  76523. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  76524. + dwc_param_host_support_fs_ls_low_power_default);
  76525. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  76526. + dwc_param_enable_dynamic_fifo_default);
  76527. + dwc_otg_set_param_data_fifo_size(core_if,
  76528. + dwc_param_data_fifo_size_default);
  76529. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  76530. + dwc_param_dev_rx_fifo_size_default);
  76531. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  76532. + dwc_param_dev_nperio_tx_fifo_size_default);
  76533. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  76534. + dwc_param_host_rx_fifo_size_default);
  76535. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  76536. + dwc_param_host_nperio_tx_fifo_size_default);
  76537. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  76538. + dwc_param_host_perio_tx_fifo_size_default);
  76539. + dwc_otg_set_param_max_transfer_size(core_if,
  76540. + dwc_param_max_transfer_size_default);
  76541. + dwc_otg_set_param_max_packet_count(core_if,
  76542. + dwc_param_max_packet_count_default);
  76543. + dwc_otg_set_param_host_channels(core_if,
  76544. + dwc_param_host_channels_default);
  76545. + dwc_otg_set_param_dev_endpoints(core_if,
  76546. + dwc_param_dev_endpoints_default);
  76547. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  76548. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  76549. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  76550. + dwc_param_host_ls_low_power_phy_clk_default);
  76551. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  76552. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  76553. + dwc_param_phy_ulpi_ext_vbus_default);
  76554. + dwc_otg_set_param_phy_utmi_width(core_if,
  76555. + dwc_param_phy_utmi_width_default);
  76556. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  76557. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  76558. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  76559. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  76560. + dwc_param_en_multiple_tx_fifo_default);
  76561. + for (i = 0; i < 15; i++) {
  76562. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  76563. + dwc_param_dev_perio_tx_fifo_size_default,
  76564. + i);
  76565. + }
  76566. +
  76567. + for (i = 0; i < 15; i++) {
  76568. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  76569. + dwc_param_dev_tx_fifo_size_default,
  76570. + i);
  76571. + }
  76572. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  76573. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  76574. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  76575. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  76576. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  76577. + dwc_otg_set_param_tx_thr_length(core_if,
  76578. + dwc_param_tx_thr_length_default);
  76579. + dwc_otg_set_param_rx_thr_length(core_if,
  76580. + dwc_param_rx_thr_length_default);
  76581. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  76582. + dwc_param_ahb_thr_ratio_default);
  76583. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  76584. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  76585. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  76586. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  76587. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  76588. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  76589. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  76590. + DWC_PRINTF("Finished setting default values for core params\n");
  76591. +
  76592. + return 0;
  76593. +}
  76594. +
  76595. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  76596. +{
  76597. + return core_if->dma_enable;
  76598. +}
  76599. +
  76600. +/* Checks if the parameter is outside of its valid range of values */
  76601. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  76602. + (((_param_) < (_low_)) || \
  76603. + ((_param_) > (_high_)))
  76604. +
  76605. +/* Parameter access functions */
  76606. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  76607. +{
  76608. + int valid;
  76609. + int retval = 0;
  76610. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  76611. + DWC_WARN("Wrong value for otg_cap parameter\n");
  76612. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  76613. + retval = -DWC_E_INVALID;
  76614. + goto out;
  76615. + }
  76616. +
  76617. + valid = 1;
  76618. + switch (val) {
  76619. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  76620. + if (core_if->hwcfg2.b.op_mode !=
  76621. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76622. + valid = 0;
  76623. + break;
  76624. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  76625. + if ((core_if->hwcfg2.b.op_mode !=
  76626. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76627. + && (core_if->hwcfg2.b.op_mode !=
  76628. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  76629. + && (core_if->hwcfg2.b.op_mode !=
  76630. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  76631. + && (core_if->hwcfg2.b.op_mode !=
  76632. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  76633. + valid = 0;
  76634. + }
  76635. + break;
  76636. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  76637. + /* always valid */
  76638. + break;
  76639. + }
  76640. + if (!valid) {
  76641. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  76642. + DWC_ERROR
  76643. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  76644. + val);
  76645. + }
  76646. + val =
  76647. + (((core_if->hwcfg2.b.op_mode ==
  76648. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  76649. + || (core_if->hwcfg2.b.op_mode ==
  76650. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  76651. + || (core_if->hwcfg2.b.op_mode ==
  76652. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  76653. + || (core_if->hwcfg2.b.op_mode ==
  76654. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  76655. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  76656. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  76657. + retval = -DWC_E_INVALID;
  76658. + }
  76659. +
  76660. + core_if->core_params->otg_cap = val;
  76661. +out:
  76662. + return retval;
  76663. +}
  76664. +
  76665. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  76666. +{
  76667. + return core_if->core_params->otg_cap;
  76668. +}
  76669. +
  76670. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  76671. +{
  76672. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76673. + DWC_WARN("Wrong value for opt parameter\n");
  76674. + return -DWC_E_INVALID;
  76675. + }
  76676. + core_if->core_params->opt = val;
  76677. + return 0;
  76678. +}
  76679. +
  76680. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  76681. +{
  76682. + return core_if->core_params->opt;
  76683. +}
  76684. +
  76685. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76686. +{
  76687. + int retval = 0;
  76688. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76689. + DWC_WARN("Wrong value for dma enable\n");
  76690. + return -DWC_E_INVALID;
  76691. + }
  76692. +
  76693. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  76694. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  76695. + DWC_ERROR
  76696. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  76697. + val);
  76698. + }
  76699. + val = 0;
  76700. + retval = -DWC_E_INVALID;
  76701. + }
  76702. +
  76703. + core_if->core_params->dma_enable = val;
  76704. + if (val == 0) {
  76705. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  76706. + }
  76707. + return retval;
  76708. +}
  76709. +
  76710. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  76711. +{
  76712. + return core_if->core_params->dma_enable;
  76713. +}
  76714. +
  76715. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  76716. +{
  76717. + int retval = 0;
  76718. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76719. + DWC_WARN("Wrong value for dma_enable\n");
  76720. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  76721. + return -DWC_E_INVALID;
  76722. + }
  76723. +
  76724. + if ((val == 1)
  76725. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  76726. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  76727. + if (dwc_otg_param_initialized
  76728. + (core_if->core_params->dma_desc_enable)) {
  76729. + DWC_ERROR
  76730. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  76731. + val);
  76732. + }
  76733. + val = 0;
  76734. + retval = -DWC_E_INVALID;
  76735. + }
  76736. + core_if->core_params->dma_desc_enable = val;
  76737. + return retval;
  76738. +}
  76739. +
  76740. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  76741. +{
  76742. + return core_if->core_params->dma_desc_enable;
  76743. +}
  76744. +
  76745. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  76746. + int32_t val)
  76747. +{
  76748. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76749. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  76750. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  76751. + return -DWC_E_INVALID;
  76752. + }
  76753. + core_if->core_params->host_support_fs_ls_low_power = val;
  76754. + return 0;
  76755. +}
  76756. +
  76757. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  76758. + core_if)
  76759. +{
  76760. + return core_if->core_params->host_support_fs_ls_low_power;
  76761. +}
  76762. +
  76763. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  76764. + int32_t val)
  76765. +{
  76766. + int retval = 0;
  76767. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  76768. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  76769. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  76770. + return -DWC_E_INVALID;
  76771. + }
  76772. +
  76773. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  76774. + if (dwc_otg_param_initialized
  76775. + (core_if->core_params->enable_dynamic_fifo)) {
  76776. + DWC_ERROR
  76777. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  76778. + val);
  76779. + }
  76780. + val = 0;
  76781. + retval = -DWC_E_INVALID;
  76782. + }
  76783. + core_if->core_params->enable_dynamic_fifo = val;
  76784. + return retval;
  76785. +}
  76786. +
  76787. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  76788. +{
  76789. + return core_if->core_params->enable_dynamic_fifo;
  76790. +}
  76791. +
  76792. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  76793. +{
  76794. + int retval = 0;
  76795. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  76796. + DWC_WARN("Wrong value for data_fifo_size\n");
  76797. + DWC_WARN("data_fifo_size must be 32-32768\n");
  76798. + return -DWC_E_INVALID;
  76799. + }
  76800. +
  76801. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  76802. + if (dwc_otg_param_initialized
  76803. + (core_if->core_params->data_fifo_size)) {
  76804. + DWC_ERROR
  76805. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  76806. + val);
  76807. + }
  76808. + val = core_if->hwcfg3.b.dfifo_depth;
  76809. + retval = -DWC_E_INVALID;
  76810. + }
  76811. +
  76812. + core_if->core_params->data_fifo_size = val;
  76813. + return retval;
  76814. +}
  76815. +
  76816. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  76817. +{
  76818. + return core_if->core_params->data_fifo_size;
  76819. +}
  76820. +
  76821. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  76822. +{
  76823. + int retval = 0;
  76824. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76825. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  76826. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  76827. + return -DWC_E_INVALID;
  76828. + }
  76829. +
  76830. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  76831. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  76832. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  76833. + }
  76834. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  76835. + retval = -DWC_E_INVALID;
  76836. + }
  76837. +
  76838. + core_if->core_params->dev_rx_fifo_size = val;
  76839. + return retval;
  76840. +}
  76841. +
  76842. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  76843. +{
  76844. + return core_if->core_params->dev_rx_fifo_size;
  76845. +}
  76846. +
  76847. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76848. + int32_t val)
  76849. +{
  76850. + int retval = 0;
  76851. +
  76852. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76853. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  76854. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  76855. + return -DWC_E_INVALID;
  76856. + }
  76857. +
  76858. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  76859. + if (dwc_otg_param_initialized
  76860. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  76861. + DWC_ERROR
  76862. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  76863. + val);
  76864. + }
  76865. + val =
  76866. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  76867. + 16);
  76868. + retval = -DWC_E_INVALID;
  76869. + }
  76870. +
  76871. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  76872. + return retval;
  76873. +}
  76874. +
  76875. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76876. +{
  76877. + return core_if->core_params->dev_nperio_tx_fifo_size;
  76878. +}
  76879. +
  76880. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  76881. + int32_t val)
  76882. +{
  76883. + int retval = 0;
  76884. +
  76885. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76886. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  76887. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  76888. + return -DWC_E_INVALID;
  76889. + }
  76890. +
  76891. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  76892. + if (dwc_otg_param_initialized
  76893. + (core_if->core_params->host_rx_fifo_size)) {
  76894. + DWC_ERROR
  76895. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  76896. + val);
  76897. + }
  76898. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  76899. + retval = -DWC_E_INVALID;
  76900. + }
  76901. +
  76902. + core_if->core_params->host_rx_fifo_size = val;
  76903. + return retval;
  76904. +
  76905. +}
  76906. +
  76907. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  76908. +{
  76909. + return core_if->core_params->host_rx_fifo_size;
  76910. +}
  76911. +
  76912. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76913. + int32_t val)
  76914. +{
  76915. + int retval = 0;
  76916. +
  76917. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76918. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  76919. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  76920. + return -DWC_E_INVALID;
  76921. + }
  76922. +
  76923. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  76924. + if (dwc_otg_param_initialized
  76925. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  76926. + DWC_ERROR
  76927. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  76928. + val);
  76929. + }
  76930. + val =
  76931. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  76932. + 16);
  76933. + retval = -DWC_E_INVALID;
  76934. + }
  76935. +
  76936. + core_if->core_params->host_nperio_tx_fifo_size = val;
  76937. + return retval;
  76938. +}
  76939. +
  76940. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76941. +{
  76942. + return core_if->core_params->host_nperio_tx_fifo_size;
  76943. +}
  76944. +
  76945. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  76946. + int32_t val)
  76947. +{
  76948. + int retval = 0;
  76949. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  76950. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  76951. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  76952. + return -DWC_E_INVALID;
  76953. + }
  76954. +
  76955. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  76956. + if (dwc_otg_param_initialized
  76957. + (core_if->core_params->host_perio_tx_fifo_size)) {
  76958. + DWC_ERROR
  76959. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  76960. + val);
  76961. + }
  76962. + val = (core_if->hptxfsiz.d32) >> 16;
  76963. + retval = -DWC_E_INVALID;
  76964. + }
  76965. +
  76966. + core_if->core_params->host_perio_tx_fifo_size = val;
  76967. + return retval;
  76968. +}
  76969. +
  76970. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  76971. +{
  76972. + return core_if->core_params->host_perio_tx_fifo_size;
  76973. +}
  76974. +
  76975. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  76976. + int32_t val)
  76977. +{
  76978. + int retval = 0;
  76979. +
  76980. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  76981. + DWC_WARN("Wrong value for max_transfer_size\n");
  76982. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  76983. + return -DWC_E_INVALID;
  76984. + }
  76985. +
  76986. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  76987. + if (dwc_otg_param_initialized
  76988. + (core_if->core_params->max_transfer_size)) {
  76989. + DWC_ERROR
  76990. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  76991. + val);
  76992. + }
  76993. + val =
  76994. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  76995. + 1);
  76996. + retval = -DWC_E_INVALID;
  76997. + }
  76998. +
  76999. + core_if->core_params->max_transfer_size = val;
  77000. + return retval;
  77001. +}
  77002. +
  77003. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  77004. +{
  77005. + return core_if->core_params->max_transfer_size;
  77006. +}
  77007. +
  77008. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  77009. +{
  77010. + int retval = 0;
  77011. +
  77012. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  77013. + DWC_WARN("Wrong value for max_packet_count\n");
  77014. + DWC_WARN("max_packet_count must be 15-511\n");
  77015. + return -DWC_E_INVALID;
  77016. + }
  77017. +
  77018. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  77019. + if (dwc_otg_param_initialized
  77020. + (core_if->core_params->max_packet_count)) {
  77021. + DWC_ERROR
  77022. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  77023. + val);
  77024. + }
  77025. + val =
  77026. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  77027. + retval = -DWC_E_INVALID;
  77028. + }
  77029. +
  77030. + core_if->core_params->max_packet_count = val;
  77031. + return retval;
  77032. +}
  77033. +
  77034. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  77035. +{
  77036. + return core_if->core_params->max_packet_count;
  77037. +}
  77038. +
  77039. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  77040. +{
  77041. + int retval = 0;
  77042. +
  77043. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  77044. + DWC_WARN("Wrong value for host_channels\n");
  77045. + DWC_WARN("host_channels must be 1-16\n");
  77046. + return -DWC_E_INVALID;
  77047. + }
  77048. +
  77049. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  77050. + if (dwc_otg_param_initialized
  77051. + (core_if->core_params->host_channels)) {
  77052. + DWC_ERROR
  77053. + ("%d invalid for host_channels. Check HW configurations.\n",
  77054. + val);
  77055. + }
  77056. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  77057. + retval = -DWC_E_INVALID;
  77058. + }
  77059. +
  77060. + core_if->core_params->host_channels = val;
  77061. + return retval;
  77062. +}
  77063. +
  77064. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  77065. +{
  77066. + return core_if->core_params->host_channels;
  77067. +}
  77068. +
  77069. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  77070. +{
  77071. + int retval = 0;
  77072. +
  77073. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  77074. + DWC_WARN("Wrong value for dev_endpoints\n");
  77075. + DWC_WARN("dev_endpoints must be 1-15\n");
  77076. + return -DWC_E_INVALID;
  77077. + }
  77078. +
  77079. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  77080. + if (dwc_otg_param_initialized
  77081. + (core_if->core_params->dev_endpoints)) {
  77082. + DWC_ERROR
  77083. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  77084. + val);
  77085. + }
  77086. + val = core_if->hwcfg2.b.num_dev_ep;
  77087. + retval = -DWC_E_INVALID;
  77088. + }
  77089. +
  77090. + core_if->core_params->dev_endpoints = val;
  77091. + return retval;
  77092. +}
  77093. +
  77094. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  77095. +{
  77096. + return core_if->core_params->dev_endpoints;
  77097. +}
  77098. +
  77099. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  77100. +{
  77101. + int retval = 0;
  77102. + int valid = 0;
  77103. +
  77104. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  77105. + DWC_WARN("Wrong value for phy_type\n");
  77106. + DWC_WARN("phy_type must be 0,1 or 2\n");
  77107. + return -DWC_E_INVALID;
  77108. + }
  77109. +#ifndef NO_FS_PHY_HW_CHECKS
  77110. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  77111. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  77112. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  77113. + valid = 1;
  77114. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  77115. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  77116. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  77117. + valid = 1;
  77118. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  77119. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  77120. + valid = 1;
  77121. + }
  77122. + if (!valid) {
  77123. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  77124. + DWC_ERROR
  77125. + ("%d invalid for phy_type. Check HW configurations.\n",
  77126. + val);
  77127. + }
  77128. + if (core_if->hwcfg2.b.hs_phy_type) {
  77129. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  77130. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  77131. + val = DWC_PHY_TYPE_PARAM_UTMI;
  77132. + } else {
  77133. + val = DWC_PHY_TYPE_PARAM_ULPI;
  77134. + }
  77135. + }
  77136. + retval = -DWC_E_INVALID;
  77137. + }
  77138. +#endif
  77139. + core_if->core_params->phy_type = val;
  77140. + return retval;
  77141. +}
  77142. +
  77143. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  77144. +{
  77145. + return core_if->core_params->phy_type;
  77146. +}
  77147. +
  77148. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  77149. +{
  77150. + int retval = 0;
  77151. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77152. + DWC_WARN("Wrong value for speed parameter\n");
  77153. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  77154. + return -DWC_E_INVALID;
  77155. + }
  77156. + if ((val == 0)
  77157. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  77158. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  77159. + DWC_ERROR
  77160. + ("%d invalid for speed paremter. Check HW configuration.\n",
  77161. + val);
  77162. + }
  77163. + val =
  77164. + (dwc_otg_get_param_phy_type(core_if) ==
  77165. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  77166. + retval = -DWC_E_INVALID;
  77167. + }
  77168. + core_if->core_params->speed = val;
  77169. + return retval;
  77170. +}
  77171. +
  77172. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  77173. +{
  77174. + return core_if->core_params->speed;
  77175. +}
  77176. +
  77177. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  77178. + int32_t val)
  77179. +{
  77180. + int retval = 0;
  77181. +
  77182. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77183. + DWC_WARN
  77184. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  77185. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  77186. + return -DWC_E_INVALID;
  77187. + }
  77188. +
  77189. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  77190. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  77191. + if (dwc_otg_param_initialized
  77192. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  77193. + DWC_ERROR
  77194. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  77195. + val);
  77196. + }
  77197. + val =
  77198. + (dwc_otg_get_param_phy_type(core_if) ==
  77199. + DWC_PHY_TYPE_PARAM_FS) ?
  77200. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  77201. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  77202. + retval = -DWC_E_INVALID;
  77203. + }
  77204. +
  77205. + core_if->core_params->host_ls_low_power_phy_clk = val;
  77206. + return retval;
  77207. +}
  77208. +
  77209. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  77210. +{
  77211. + return core_if->core_params->host_ls_low_power_phy_clk;
  77212. +}
  77213. +
  77214. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  77215. +{
  77216. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77217. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  77218. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  77219. + return -DWC_E_INVALID;
  77220. + }
  77221. +
  77222. + core_if->core_params->phy_ulpi_ddr = val;
  77223. + return 0;
  77224. +}
  77225. +
  77226. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  77227. +{
  77228. + return core_if->core_params->phy_ulpi_ddr;
  77229. +}
  77230. +
  77231. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  77232. + int32_t val)
  77233. +{
  77234. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77235. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  77236. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  77237. + return -DWC_E_INVALID;
  77238. + }
  77239. +
  77240. + core_if->core_params->phy_ulpi_ext_vbus = val;
  77241. + return 0;
  77242. +}
  77243. +
  77244. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  77245. +{
  77246. + return core_if->core_params->phy_ulpi_ext_vbus;
  77247. +}
  77248. +
  77249. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  77250. +{
  77251. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  77252. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  77253. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  77254. + return -DWC_E_INVALID;
  77255. + }
  77256. +
  77257. + core_if->core_params->phy_utmi_width = val;
  77258. + return 0;
  77259. +}
  77260. +
  77261. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  77262. +{
  77263. + return core_if->core_params->phy_utmi_width;
  77264. +}
  77265. +
  77266. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  77267. +{
  77268. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77269. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  77270. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  77271. + return -DWC_E_INVALID;
  77272. + }
  77273. +
  77274. + core_if->core_params->ulpi_fs_ls = val;
  77275. + return 0;
  77276. +}
  77277. +
  77278. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  77279. +{
  77280. + return core_if->core_params->ulpi_fs_ls;
  77281. +}
  77282. +
  77283. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  77284. +{
  77285. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77286. + DWC_WARN("Wrong valaue for ts_dline\n");
  77287. + DWC_WARN("ts_dline must be 0 or 1\n");
  77288. + return -DWC_E_INVALID;
  77289. + }
  77290. +
  77291. + core_if->core_params->ts_dline = val;
  77292. + return 0;
  77293. +}
  77294. +
  77295. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  77296. +{
  77297. + return core_if->core_params->ts_dline;
  77298. +}
  77299. +
  77300. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  77301. +{
  77302. + int retval = 0;
  77303. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77304. + DWC_WARN("Wrong valaue for i2c_enable\n");
  77305. + DWC_WARN("i2c_enable must be 0 or 1\n");
  77306. + return -DWC_E_INVALID;
  77307. + }
  77308. +#ifndef NO_FS_PHY_HW_CHECK
  77309. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  77310. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  77311. + DWC_ERROR
  77312. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  77313. + val);
  77314. + }
  77315. + val = 0;
  77316. + retval = -DWC_E_INVALID;
  77317. + }
  77318. +#endif
  77319. +
  77320. + core_if->core_params->i2c_enable = val;
  77321. + return retval;
  77322. +}
  77323. +
  77324. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  77325. +{
  77326. + return core_if->core_params->i2c_enable;
  77327. +}
  77328. +
  77329. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  77330. + int32_t val, int fifo_num)
  77331. +{
  77332. + int retval = 0;
  77333. +
  77334. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  77335. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  77336. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  77337. + return -DWC_E_INVALID;
  77338. + }
  77339. +
  77340. + if (val >
  77341. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  77342. + if (dwc_otg_param_initialized
  77343. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  77344. + DWC_ERROR
  77345. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  77346. + val, fifo_num);
  77347. + }
  77348. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  77349. + retval = -DWC_E_INVALID;
  77350. + }
  77351. +
  77352. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  77353. + return retval;
  77354. +}
  77355. +
  77356. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  77357. + int fifo_num)
  77358. +{
  77359. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  77360. +}
  77361. +
  77362. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  77363. + int32_t val)
  77364. +{
  77365. + int retval = 0;
  77366. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77367. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  77368. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  77369. + return -DWC_E_INVALID;
  77370. + }
  77371. +
  77372. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  77373. + if (dwc_otg_param_initialized
  77374. + (core_if->core_params->en_multiple_tx_fifo)) {
  77375. + DWC_ERROR
  77376. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  77377. + val);
  77378. + }
  77379. + val = 0;
  77380. + retval = -DWC_E_INVALID;
  77381. + }
  77382. +
  77383. + core_if->core_params->en_multiple_tx_fifo = val;
  77384. + return retval;
  77385. +}
  77386. +
  77387. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  77388. +{
  77389. + return core_if->core_params->en_multiple_tx_fifo;
  77390. +}
  77391. +
  77392. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  77393. + int fifo_num)
  77394. +{
  77395. + int retval = 0;
  77396. +
  77397. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  77398. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  77399. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  77400. + return -DWC_E_INVALID;
  77401. + }
  77402. +
  77403. + if (val >
  77404. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  77405. + if (dwc_otg_param_initialized
  77406. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  77407. + DWC_ERROR
  77408. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  77409. + val, fifo_num);
  77410. + }
  77411. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  77412. + retval = -DWC_E_INVALID;
  77413. + }
  77414. +
  77415. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  77416. + return retval;
  77417. +}
  77418. +
  77419. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  77420. + int fifo_num)
  77421. +{
  77422. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  77423. +}
  77424. +
  77425. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  77426. +{
  77427. + int retval = 0;
  77428. +
  77429. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  77430. + DWC_WARN("Wrong value for thr_ctl\n");
  77431. + DWC_WARN("thr_ctl must be 0-7\n");
  77432. + return -DWC_E_INVALID;
  77433. + }
  77434. +
  77435. + if ((val != 0) &&
  77436. + (!dwc_otg_get_param_dma_enable(core_if) ||
  77437. + !core_if->hwcfg4.b.ded_fifo_en)) {
  77438. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  77439. + DWC_ERROR
  77440. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  77441. + val);
  77442. + }
  77443. + val = 0;
  77444. + retval = -DWC_E_INVALID;
  77445. + }
  77446. +
  77447. + core_if->core_params->thr_ctl = val;
  77448. + return retval;
  77449. +}
  77450. +
  77451. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  77452. +{
  77453. + return core_if->core_params->thr_ctl;
  77454. +}
  77455. +
  77456. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  77457. +{
  77458. + int retval = 0;
  77459. +
  77460. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77461. + DWC_WARN("Wrong value for lpm_enable\n");
  77462. + DWC_WARN("lpm_enable must be 0 or 1\n");
  77463. + return -DWC_E_INVALID;
  77464. + }
  77465. +
  77466. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  77467. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  77468. + DWC_ERROR
  77469. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  77470. + val);
  77471. + }
  77472. + val = 0;
  77473. + retval = -DWC_E_INVALID;
  77474. + }
  77475. +
  77476. + core_if->core_params->lpm_enable = val;
  77477. + return retval;
  77478. +}
  77479. +
  77480. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  77481. +{
  77482. + return core_if->core_params->lpm_enable;
  77483. +}
  77484. +
  77485. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  77486. +{
  77487. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  77488. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  77489. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  77490. + return -DWC_E_INVALID;
  77491. + }
  77492. +
  77493. + core_if->core_params->tx_thr_length = val;
  77494. + return 0;
  77495. +}
  77496. +
  77497. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  77498. +{
  77499. + return core_if->core_params->tx_thr_length;
  77500. +}
  77501. +
  77502. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  77503. +{
  77504. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  77505. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  77506. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  77507. + return -DWC_E_INVALID;
  77508. + }
  77509. +
  77510. + core_if->core_params->rx_thr_length = val;
  77511. + return 0;
  77512. +}
  77513. +
  77514. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  77515. +{
  77516. + return core_if->core_params->rx_thr_length;
  77517. +}
  77518. +
  77519. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  77520. +{
  77521. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  77522. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  77523. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  77524. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  77525. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  77526. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  77527. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  77528. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  77529. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  77530. + return -DWC_E_INVALID;
  77531. + }
  77532. + core_if->core_params->dma_burst_size = val;
  77533. + return 0;
  77534. +}
  77535. +
  77536. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  77537. +{
  77538. + return core_if->core_params->dma_burst_size;
  77539. +}
  77540. +
  77541. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  77542. +{
  77543. + int retval = 0;
  77544. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77545. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  77546. + return -DWC_E_INVALID;
  77547. + }
  77548. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  77549. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  77550. + DWC_ERROR
  77551. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  77552. + val);
  77553. + }
  77554. + retval = -DWC_E_INVALID;
  77555. + val = 0;
  77556. + }
  77557. + core_if->core_params->pti_enable = val;
  77558. + return retval;
  77559. +}
  77560. +
  77561. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  77562. +{
  77563. + return core_if->core_params->pti_enable;
  77564. +}
  77565. +
  77566. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  77567. +{
  77568. + int retval = 0;
  77569. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77570. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  77571. + return -DWC_E_INVALID;
  77572. + }
  77573. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  77574. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  77575. + DWC_ERROR
  77576. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  77577. + val);
  77578. + }
  77579. + retval = -DWC_E_INVALID;
  77580. + val = 0;
  77581. + }
  77582. + core_if->core_params->mpi_enable = val;
  77583. + return retval;
  77584. +}
  77585. +
  77586. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  77587. +{
  77588. + return core_if->core_params->mpi_enable;
  77589. +}
  77590. +
  77591. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  77592. +{
  77593. + int retval = 0;
  77594. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77595. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  77596. + return -DWC_E_INVALID;
  77597. + }
  77598. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  77599. + if (dwc_otg_param_initialized
  77600. + (core_if->core_params->adp_supp_enable)) {
  77601. + DWC_ERROR
  77602. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  77603. + val);
  77604. + }
  77605. + retval = -DWC_E_INVALID;
  77606. + val = 0;
  77607. + }
  77608. + core_if->core_params->adp_supp_enable = val;
  77609. + /*Set OTG version 2.0 in case of enabling ADP*/
  77610. + if (val)
  77611. + dwc_otg_set_param_otg_ver(core_if, 1);
  77612. +
  77613. + return retval;
  77614. +}
  77615. +
  77616. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  77617. +{
  77618. + return core_if->core_params->adp_supp_enable;
  77619. +}
  77620. +
  77621. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  77622. +{
  77623. + int retval = 0;
  77624. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77625. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  77626. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  77627. + return -DWC_E_INVALID;
  77628. + }
  77629. +
  77630. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  77631. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  77632. + DWC_ERROR
  77633. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  77634. + val);
  77635. + }
  77636. + retval = -DWC_E_INVALID;
  77637. + val = 0;
  77638. + }
  77639. + core_if->core_params->ic_usb_cap = val;
  77640. + return retval;
  77641. +}
  77642. +
  77643. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  77644. +{
  77645. + return core_if->core_params->ic_usb_cap;
  77646. +}
  77647. +
  77648. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  77649. +{
  77650. + int retval = 0;
  77651. + int valid = 1;
  77652. +
  77653. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  77654. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  77655. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  77656. + return -DWC_E_INVALID;
  77657. + }
  77658. +
  77659. + if (val
  77660. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  77661. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  77662. + valid = 0;
  77663. + } else if (val
  77664. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  77665. + 4)) {
  77666. + valid = 0;
  77667. + }
  77668. + if (valid == 0) {
  77669. + if (dwc_otg_param_initialized
  77670. + (core_if->core_params->ahb_thr_ratio)) {
  77671. + DWC_ERROR
  77672. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  77673. + val);
  77674. + }
  77675. + retval = -DWC_E_INVALID;
  77676. + val = 0;
  77677. + }
  77678. +
  77679. + core_if->core_params->ahb_thr_ratio = val;
  77680. + return retval;
  77681. +}
  77682. +
  77683. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  77684. +{
  77685. + return core_if->core_params->ahb_thr_ratio;
  77686. +}
  77687. +
  77688. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  77689. +{
  77690. + int retval = 0;
  77691. + int valid = 1;
  77692. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  77693. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  77694. +
  77695. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  77696. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  77697. + DWC_WARN("power_down must be 0 - 2\n");
  77698. + return -DWC_E_INVALID;
  77699. + }
  77700. +
  77701. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  77702. + valid = 0;
  77703. + }
  77704. + if ((val == 3)
  77705. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  77706. + || (hwcfg4.b.xhiber == 0))) {
  77707. + valid = 0;
  77708. + }
  77709. + if (valid == 0) {
  77710. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  77711. + DWC_ERROR
  77712. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  77713. + val);
  77714. + }
  77715. + retval = -DWC_E_INVALID;
  77716. + val = 0;
  77717. + }
  77718. + core_if->core_params->power_down = val;
  77719. + return retval;
  77720. +}
  77721. +
  77722. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  77723. +{
  77724. + return core_if->core_params->power_down;
  77725. +}
  77726. +
  77727. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  77728. +{
  77729. + int retval = 0;
  77730. + int valid = 1;
  77731. +
  77732. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77733. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  77734. + DWC_WARN("reload_ctl must be 0 or 1\n");
  77735. + return -DWC_E_INVALID;
  77736. + }
  77737. +
  77738. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  77739. + valid = 0;
  77740. + }
  77741. + if (valid == 0) {
  77742. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  77743. + DWC_ERROR("%d invalid for parameter reload_ctl."
  77744. + "Check HW configuration.\n", val);
  77745. + }
  77746. + retval = -DWC_E_INVALID;
  77747. + val = 0;
  77748. + }
  77749. + core_if->core_params->reload_ctl = val;
  77750. + return retval;
  77751. +}
  77752. +
  77753. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  77754. +{
  77755. + return core_if->core_params->reload_ctl;
  77756. +}
  77757. +
  77758. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  77759. +{
  77760. + int retval = 0;
  77761. + int valid = 1;
  77762. +
  77763. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77764. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  77765. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  77766. + return -DWC_E_INVALID;
  77767. + }
  77768. +
  77769. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  77770. + !(core_if->core_params->dma_desc_enable))) {
  77771. + valid = 0;
  77772. + }
  77773. + if (valid == 0) {
  77774. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  77775. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  77776. + "Check HW configuration.\n", val);
  77777. + }
  77778. + retval = -DWC_E_INVALID;
  77779. + val = 0;
  77780. + }
  77781. + core_if->core_params->dev_out_nak = val;
  77782. + return retval;
  77783. +}
  77784. +
  77785. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  77786. +{
  77787. + return core_if->core_params->dev_out_nak;
  77788. +}
  77789. +
  77790. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  77791. +{
  77792. + int retval = 0;
  77793. + int valid = 1;
  77794. +
  77795. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77796. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  77797. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  77798. + return -DWC_E_INVALID;
  77799. + }
  77800. +
  77801. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  77802. + !(core_if->core_params->dma_desc_enable))) {
  77803. + valid = 0;
  77804. + }
  77805. + if (valid == 0) {
  77806. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  77807. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  77808. + "Check HW configuration.\n", val);
  77809. + }
  77810. + retval = -DWC_E_INVALID;
  77811. + val = 0;
  77812. + }
  77813. + core_if->core_params->cont_on_bna = val;
  77814. + return retval;
  77815. +}
  77816. +
  77817. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  77818. +{
  77819. + return core_if->core_params->cont_on_bna;
  77820. +}
  77821. +
  77822. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  77823. +{
  77824. + int retval = 0;
  77825. + int valid = 1;
  77826. +
  77827. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77828. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  77829. + DWC_WARN("ahb_single must be 0 or 1\n");
  77830. + return -DWC_E_INVALID;
  77831. + }
  77832. +
  77833. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  77834. + valid = 0;
  77835. + }
  77836. + if (valid == 0) {
  77837. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  77838. + DWC_ERROR("%d invalid for parameter ahb_single."
  77839. + "Check HW configuration.\n", val);
  77840. + }
  77841. + retval = -DWC_E_INVALID;
  77842. + val = 0;
  77843. + }
  77844. + core_if->core_params->ahb_single = val;
  77845. + return retval;
  77846. +}
  77847. +
  77848. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  77849. +{
  77850. + return core_if->core_params->ahb_single;
  77851. +}
  77852. +
  77853. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  77854. +{
  77855. + int retval = 0;
  77856. +
  77857. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  77858. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  77859. + DWC_WARN
  77860. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  77861. + return -DWC_E_INVALID;
  77862. + }
  77863. +
  77864. + core_if->core_params->otg_ver = val;
  77865. + return retval;
  77866. +}
  77867. +
  77868. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  77869. +{
  77870. + return core_if->core_params->otg_ver;
  77871. +}
  77872. +
  77873. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  77874. +{
  77875. + gotgctl_data_t otgctl;
  77876. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77877. + return otgctl.b.hstnegscs;
  77878. +}
  77879. +
  77880. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  77881. +{
  77882. + gotgctl_data_t otgctl;
  77883. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77884. + return otgctl.b.sesreqscs;
  77885. +}
  77886. +
  77887. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  77888. +{
  77889. + if(core_if->otg_ver == 0) {
  77890. + gotgctl_data_t otgctl;
  77891. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  77892. + otgctl.b.hnpreq = val;
  77893. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  77894. + } else {
  77895. + core_if->otg_sts = val;
  77896. + }
  77897. +}
  77898. +
  77899. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  77900. +{
  77901. + return core_if->snpsid;
  77902. +}
  77903. +
  77904. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  77905. +{
  77906. + gintsts_data_t gintsts;
  77907. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  77908. + return gintsts.b.curmode;
  77909. +}
  77910. +
  77911. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  77912. +{
  77913. + gusbcfg_data_t usbcfg;
  77914. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77915. + return usbcfg.b.hnpcap;
  77916. +}
  77917. +
  77918. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  77919. +{
  77920. + gusbcfg_data_t usbcfg;
  77921. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77922. + usbcfg.b.hnpcap = val;
  77923. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  77924. +}
  77925. +
  77926. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  77927. +{
  77928. + gusbcfg_data_t usbcfg;
  77929. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77930. + return usbcfg.b.srpcap;
  77931. +}
  77932. +
  77933. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  77934. +{
  77935. + gusbcfg_data_t usbcfg;
  77936. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  77937. + usbcfg.b.srpcap = val;
  77938. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  77939. +}
  77940. +
  77941. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  77942. +{
  77943. + dcfg_data_t dcfg;
  77944. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  77945. +
  77946. + dcfg.d32 = -1; //GRAYG
  77947. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  77948. + if (NULL == core_if)
  77949. + DWC_ERROR("reg request with NULL core_if\n");
  77950. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  77951. + core_if, core_if->dev_if);
  77952. + if (NULL == core_if->dev_if)
  77953. + DWC_ERROR("reg request with NULL dev_if\n");
  77954. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  77955. + "dev_global_regs(%p)\n", __func__,
  77956. + core_if, core_if->dev_if,
  77957. + core_if->dev_if->dev_global_regs);
  77958. + if (NULL == core_if->dev_if->dev_global_regs)
  77959. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  77960. + else {
  77961. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  77962. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  77963. + core_if, core_if->dev_if,
  77964. + core_if->dev_if->dev_global_regs,
  77965. + &core_if->dev_if->dev_global_regs->dcfg);
  77966. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  77967. + }
  77968. + return dcfg.b.devspd;
  77969. +}
  77970. +
  77971. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  77972. +{
  77973. + dcfg_data_t dcfg;
  77974. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  77975. + dcfg.b.devspd = val;
  77976. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  77977. +}
  77978. +
  77979. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  77980. +{
  77981. + hprt0_data_t hprt0;
  77982. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  77983. + return hprt0.b.prtconnsts;
  77984. +}
  77985. +
  77986. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  77987. +{
  77988. + dsts_data_t dsts;
  77989. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  77990. + return dsts.b.enumspd;
  77991. +}
  77992. +
  77993. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  77994. +{
  77995. + hprt0_data_t hprt0;
  77996. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  77997. + return hprt0.b.prtpwr;
  77998. +
  77999. +}
  78000. +
  78001. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  78002. +{
  78003. + return core_if->hibernation_suspend;
  78004. +}
  78005. +
  78006. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  78007. +{
  78008. + hprt0_data_t hprt0;
  78009. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  78010. + hprt0.b.prtpwr = val;
  78011. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  78012. +}
  78013. +
  78014. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  78015. +{
  78016. + hprt0_data_t hprt0;
  78017. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  78018. + return hprt0.b.prtsusp;
  78019. +
  78020. +}
  78021. +
  78022. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  78023. +{
  78024. + hprt0_data_t hprt0;
  78025. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  78026. + hprt0.b.prtsusp = val;
  78027. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  78028. +}
  78029. +
  78030. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  78031. +{
  78032. + hfir_data_t hfir;
  78033. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  78034. + return hfir.b.frint;
  78035. +
  78036. +}
  78037. +
  78038. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  78039. +{
  78040. + hfir_data_t hfir;
  78041. + uint32_t fram_int;
  78042. + fram_int = calc_frame_interval(core_if);
  78043. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  78044. + if (!core_if->core_params->reload_ctl) {
  78045. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  78046. + "not set to 1.\nShould load driver with reload_ctl=1"
  78047. + " module parameter\n");
  78048. + return;
  78049. + }
  78050. + switch (fram_int) {
  78051. + case 3750:
  78052. + if ((val < 3350) || (val > 4150)) {
  78053. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  78054. + "clock freq should be from 3350 to 4150\n");
  78055. + return;
  78056. + }
  78057. + break;
  78058. + case 30000:
  78059. + if ((val < 26820) || (val > 33180)) {
  78060. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  78061. + "clock freq should be from 26820 to 33180\n");
  78062. + return;
  78063. + }
  78064. + break;
  78065. + case 6000:
  78066. + if ((val < 5360) || (val > 6640)) {
  78067. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  78068. + "clock freq should be from 5360 to 6640\n");
  78069. + return;
  78070. + }
  78071. + break;
  78072. + case 48000:
  78073. + if ((val < 42912) || (val > 53088)) {
  78074. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  78075. + "clock freq should be from 42912 to 53088\n");
  78076. + return;
  78077. + }
  78078. + break;
  78079. + case 7500:
  78080. + if ((val < 6700) || (val > 8300)) {
  78081. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  78082. + "clock freq should be from 6700 to 8300\n");
  78083. + return;
  78084. + }
  78085. + break;
  78086. + case 60000:
  78087. + if ((val < 53640) || (val > 65536)) {
  78088. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  78089. + "clock freq should be from 53640 to 65536\n");
  78090. + return;
  78091. + }
  78092. + break;
  78093. + default:
  78094. + DWC_WARN("Unknown frame interval\n");
  78095. + return;
  78096. + break;
  78097. +
  78098. + }
  78099. + hfir.b.frint = val;
  78100. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  78101. +}
  78102. +
  78103. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  78104. +{
  78105. + hcfg_data_t hcfg;
  78106. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  78107. + return hcfg.b.modechtimen;
  78108. +
  78109. +}
  78110. +
  78111. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  78112. +{
  78113. + hcfg_data_t hcfg;
  78114. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  78115. + hcfg.b.modechtimen = val;
  78116. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  78117. +}
  78118. +
  78119. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  78120. +{
  78121. + hprt0_data_t hprt0;
  78122. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  78123. + hprt0.b.prtres = val;
  78124. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  78125. +}
  78126. +
  78127. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  78128. +{
  78129. + dctl_data_t dctl;
  78130. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  78131. + return dctl.b.rmtwkupsig;
  78132. +}
  78133. +
  78134. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  78135. +{
  78136. + glpmcfg_data_t lpmcfg;
  78137. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78138. +
  78139. + DWC_ASSERT(!
  78140. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  78141. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  78142. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  78143. +
  78144. + return lpmcfg.b.prt_sleep_sts;
  78145. +}
  78146. +
  78147. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  78148. +{
  78149. + glpmcfg_data_t lpmcfg;
  78150. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78151. + return lpmcfg.b.rem_wkup_en;
  78152. +}
  78153. +
  78154. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  78155. +{
  78156. + glpmcfg_data_t lpmcfg;
  78157. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78158. + return lpmcfg.b.appl_resp;
  78159. +}
  78160. +
  78161. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  78162. +{
  78163. + glpmcfg_data_t lpmcfg;
  78164. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78165. + lpmcfg.b.appl_resp = val;
  78166. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  78167. +}
  78168. +
  78169. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  78170. +{
  78171. + glpmcfg_data_t lpmcfg;
  78172. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78173. + return lpmcfg.b.hsic_connect;
  78174. +}
  78175. +
  78176. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  78177. +{
  78178. + glpmcfg_data_t lpmcfg;
  78179. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78180. + lpmcfg.b.hsic_connect = val;
  78181. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  78182. +}
  78183. +
  78184. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  78185. +{
  78186. + glpmcfg_data_t lpmcfg;
  78187. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78188. + return lpmcfg.b.inv_sel_hsic;
  78189. +
  78190. +}
  78191. +
  78192. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  78193. +{
  78194. + glpmcfg_data_t lpmcfg;
  78195. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  78196. + lpmcfg.b.inv_sel_hsic = val;
  78197. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  78198. +}
  78199. +
  78200. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  78201. +{
  78202. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  78203. +}
  78204. +
  78205. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  78206. +{
  78207. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  78208. +}
  78209. +
  78210. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  78211. +{
  78212. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  78213. +}
  78214. +
  78215. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  78216. +{
  78217. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  78218. +}
  78219. +
  78220. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  78221. +{
  78222. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  78223. +}
  78224. +
  78225. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  78226. +{
  78227. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  78228. +}
  78229. +
  78230. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  78231. +{
  78232. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  78233. +}
  78234. +
  78235. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  78236. +{
  78237. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  78238. +}
  78239. +
  78240. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  78241. +{
  78242. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  78243. +}
  78244. +
  78245. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  78246. +{
  78247. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  78248. +}
  78249. +
  78250. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  78251. +{
  78252. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  78253. +}
  78254. +
  78255. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  78256. +{
  78257. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  78258. +}
  78259. +
  78260. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  78261. +{
  78262. + return DWC_READ_REG32(core_if->host_if->hprt0);
  78263. +
  78264. +}
  78265. +
  78266. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  78267. +{
  78268. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  78269. +}
  78270. +
  78271. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  78272. +{
  78273. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  78274. +}
  78275. +
  78276. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  78277. +{
  78278. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  78279. +}
  78280. +
  78281. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  78282. +{
  78283. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  78284. +}
  78285. +
  78286. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  78287. +{
  78288. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  78289. +}
  78290. +
  78291. +/**
  78292. + * Start the SRP timer to detect when the SRP does not complete within
  78293. + * 6 seconds.
  78294. + *
  78295. + * @param core_if the pointer to core_if strucure.
  78296. + */
  78297. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  78298. +{
  78299. + core_if->srp_timer_started = 1;
  78300. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  78301. +}
  78302. +
  78303. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  78304. +{
  78305. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  78306. + gotgctl_data_t mem;
  78307. + gotgctl_data_t val;
  78308. +
  78309. + val.d32 = DWC_READ_REG32(addr);
  78310. + if (val.b.sesreq) {
  78311. + DWC_ERROR("Session Request Already active!\n");
  78312. + return;
  78313. + }
  78314. +
  78315. + DWC_INFO("Session Request Initated\n"); //NOTICE
  78316. + mem.d32 = DWC_READ_REG32(addr);
  78317. + mem.b.sesreq = 1;
  78318. + DWC_WRITE_REG32(addr, mem.d32);
  78319. +
  78320. + /* Start the SRP timer */
  78321. + dwc_otg_pcd_start_srp_timer(core_if);
  78322. + return;
  78323. +}
  78324. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  78325. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  78326. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2015-03-09 10:39:33.218893718 +0100
  78327. @@ -0,0 +1,1464 @@
  78328. +/* ==========================================================================
  78329. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  78330. + * $Revision: #123 $
  78331. + * $Date: 2012/08/10 $
  78332. + * $Change: 2047372 $
  78333. + *
  78334. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78335. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78336. + * otherwise expressly agreed to in writing between Synopsys and you.
  78337. + *
  78338. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78339. + * any End User Software License Agreement or Agreement for Licensed Product
  78340. + * with Synopsys or any supplement thereto. You are permitted to use and
  78341. + * redistribute this Software in source and binary forms, with or without
  78342. + * modification, provided that redistributions of source code must retain this
  78343. + * notice. You may not view, use, disclose, copy or distribute this file or
  78344. + * any information contained herein except pursuant to this license grant from
  78345. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78346. + * below, then you are not authorized to use the Software.
  78347. + *
  78348. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78349. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78350. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78351. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78352. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78353. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78354. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78355. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78356. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78357. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78358. + * DAMAGE.
  78359. + * ========================================================================== */
  78360. +
  78361. +#if !defined(__DWC_CIL_H__)
  78362. +#define __DWC_CIL_H__
  78363. +
  78364. +#include "dwc_list.h"
  78365. +#include "dwc_otg_dbg.h"
  78366. +#include "dwc_otg_regs.h"
  78367. +
  78368. +#include "dwc_otg_core_if.h"
  78369. +#include "dwc_otg_adp.h"
  78370. +
  78371. +/**
  78372. + * @file
  78373. + * This file contains the interface to the Core Interface Layer.
  78374. + */
  78375. +
  78376. +#ifdef DWC_UTE_CFI
  78377. +
  78378. +#define MAX_DMA_DESCS_PER_EP 256
  78379. +
  78380. +/**
  78381. + * Enumeration for the data buffer mode
  78382. + */
  78383. +typedef enum _data_buffer_mode {
  78384. + BM_STANDARD = 0, /* data buffer is in normal mode */
  78385. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  78386. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  78387. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  78388. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  78389. +} data_buffer_mode_e;
  78390. +#endif //DWC_UTE_CFI
  78391. +
  78392. +/** Macros defined for DWC OTG HW Release version */
  78393. +
  78394. +#define OTG_CORE_REV_2_60a 0x4F54260A
  78395. +#define OTG_CORE_REV_2_71a 0x4F54271A
  78396. +#define OTG_CORE_REV_2_72a 0x4F54272A
  78397. +#define OTG_CORE_REV_2_80a 0x4F54280A
  78398. +#define OTG_CORE_REV_2_81a 0x4F54281A
  78399. +#define OTG_CORE_REV_2_90a 0x4F54290A
  78400. +#define OTG_CORE_REV_2_91a 0x4F54291A
  78401. +#define OTG_CORE_REV_2_92a 0x4F54292A
  78402. +#define OTG_CORE_REV_2_93a 0x4F54293A
  78403. +#define OTG_CORE_REV_2_94a 0x4F54294A
  78404. +#define OTG_CORE_REV_3_00a 0x4F54300A
  78405. +
  78406. +/**
  78407. + * Information for each ISOC packet.
  78408. + */
  78409. +typedef struct iso_pkt_info {
  78410. + uint32_t offset;
  78411. + uint32_t length;
  78412. + int32_t status;
  78413. +} iso_pkt_info_t;
  78414. +
  78415. +/**
  78416. + * The <code>dwc_ep</code> structure represents the state of a single
  78417. + * endpoint when acting in device mode. It contains the data items
  78418. + * needed for an endpoint to be activated and transfer packets.
  78419. + */
  78420. +typedef struct dwc_ep {
  78421. + /** EP number used for register address lookup */
  78422. + uint8_t num;
  78423. + /** EP direction 0 = OUT */
  78424. + unsigned is_in:1;
  78425. + /** EP active. */
  78426. + unsigned active:1;
  78427. +
  78428. + /**
  78429. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  78430. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  78431. + unsigned tx_fifo_num:4;
  78432. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  78433. + unsigned type:2;
  78434. +#define DWC_OTG_EP_TYPE_CONTROL 0
  78435. +#define DWC_OTG_EP_TYPE_ISOC 1
  78436. +#define DWC_OTG_EP_TYPE_BULK 2
  78437. +#define DWC_OTG_EP_TYPE_INTR 3
  78438. +
  78439. + /** DATA start PID for INTR and BULK EP */
  78440. + unsigned data_pid_start:1;
  78441. + /** Frame (even/odd) for ISOC EP */
  78442. + unsigned even_odd_frame:1;
  78443. + /** Max Packet bytes */
  78444. + unsigned maxpacket:11;
  78445. +
  78446. + /** Max Transfer size */
  78447. + uint32_t maxxfer;
  78448. +
  78449. + /** @name Transfer state */
  78450. + /** @{ */
  78451. +
  78452. + /**
  78453. + * Pointer to the beginning of the transfer buffer -- do not modify
  78454. + * during transfer.
  78455. + */
  78456. +
  78457. + dwc_dma_t dma_addr;
  78458. +
  78459. + dwc_dma_t dma_desc_addr;
  78460. + dwc_otg_dev_dma_desc_t *desc_addr;
  78461. +
  78462. + uint8_t *start_xfer_buff;
  78463. + /** pointer to the transfer buffer */
  78464. + uint8_t *xfer_buff;
  78465. + /** Number of bytes to transfer */
  78466. + unsigned xfer_len:19;
  78467. + /** Number of bytes transferred. */
  78468. + unsigned xfer_count:19;
  78469. + /** Sent ZLP */
  78470. + unsigned sent_zlp:1;
  78471. + /** Total len for control transfer */
  78472. + unsigned total_len:19;
  78473. +
  78474. + /** stall clear flag */
  78475. + unsigned stall_clear_flag:1;
  78476. +
  78477. + /** SETUP pkt cnt rollover flag for EP0 out*/
  78478. + unsigned stp_rollover;
  78479. +
  78480. +#ifdef DWC_UTE_CFI
  78481. + /* The buffer mode */
  78482. + data_buffer_mode_e buff_mode;
  78483. +
  78484. + /* The chain of DMA descriptors.
  78485. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  78486. + */
  78487. + dwc_otg_dma_desc_t *descs;
  78488. +
  78489. + /* The DMA address of the descriptors chain start */
  78490. + dma_addr_t descs_dma_addr;
  78491. + /** This variable stores the length of the last enqueued request */
  78492. + uint32_t cfi_req_len;
  78493. +#endif //DWC_UTE_CFI
  78494. +
  78495. +/** Max DMA Descriptor count for any EP */
  78496. +#define MAX_DMA_DESC_CNT 256
  78497. + /** Allocated DMA Desc count */
  78498. + uint32_t desc_cnt;
  78499. +
  78500. + /** bInterval */
  78501. + uint32_t bInterval;
  78502. + /** Next frame num to setup next ISOC transfer */
  78503. + uint32_t frame_num;
  78504. + /** Indicates SOF number overrun in DSTS */
  78505. + uint8_t frm_overrun;
  78506. +
  78507. +#ifdef DWC_UTE_PER_IO
  78508. + /** Next frame num for which will be setup DMA Desc */
  78509. + uint32_t xiso_frame_num;
  78510. + /** bInterval */
  78511. + uint32_t xiso_bInterval;
  78512. + /** Count of currently active transfers - shall be either 0 or 1 */
  78513. + int xiso_active_xfers;
  78514. + int xiso_queued_xfers;
  78515. +#endif
  78516. +#ifdef DWC_EN_ISOC
  78517. + /**
  78518. + * Variables specific for ISOC EPs
  78519. + *
  78520. + */
  78521. + /** DMA addresses of ISOC buffers */
  78522. + dwc_dma_t dma_addr0;
  78523. + dwc_dma_t dma_addr1;
  78524. +
  78525. + dwc_dma_t iso_dma_desc_addr;
  78526. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  78527. +
  78528. + /** pointer to the transfer buffers */
  78529. + uint8_t *xfer_buff0;
  78530. + uint8_t *xfer_buff1;
  78531. +
  78532. + /** number of ISOC Buffer is processing */
  78533. + uint32_t proc_buf_num;
  78534. + /** Interval of ISOC Buffer processing */
  78535. + uint32_t buf_proc_intrvl;
  78536. + /** Data size for regular frame */
  78537. + uint32_t data_per_frame;
  78538. +
  78539. + /* todo - pattern data support is to be implemented in the future */
  78540. + /** Data size for pattern frame */
  78541. + uint32_t data_pattern_frame;
  78542. + /** Frame number of pattern data */
  78543. + uint32_t sync_frame;
  78544. +
  78545. + /** bInterval */
  78546. + uint32_t bInterval;
  78547. + /** ISO Packet number per frame */
  78548. + uint32_t pkt_per_frm;
  78549. + /** Next frame num for which will be setup DMA Desc */
  78550. + uint32_t next_frame;
  78551. + /** Number of packets per buffer processing */
  78552. + uint32_t pkt_cnt;
  78553. + /** Info for all isoc packets */
  78554. + iso_pkt_info_t *pkt_info;
  78555. + /** current pkt number */
  78556. + uint32_t cur_pkt;
  78557. + /** current pkt number */
  78558. + uint8_t *cur_pkt_addr;
  78559. + /** current pkt number */
  78560. + uint32_t cur_pkt_dma_addr;
  78561. +#endif /* DWC_EN_ISOC */
  78562. +
  78563. +/** @} */
  78564. +} dwc_ep_t;
  78565. +
  78566. +/*
  78567. + * Reasons for halting a host channel.
  78568. + */
  78569. +typedef enum dwc_otg_halt_status {
  78570. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  78571. + DWC_OTG_HC_XFER_COMPLETE,
  78572. + DWC_OTG_HC_XFER_URB_COMPLETE,
  78573. + DWC_OTG_HC_XFER_ACK,
  78574. + DWC_OTG_HC_XFER_NAK,
  78575. + DWC_OTG_HC_XFER_NYET,
  78576. + DWC_OTG_HC_XFER_STALL,
  78577. + DWC_OTG_HC_XFER_XACT_ERR,
  78578. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  78579. + DWC_OTG_HC_XFER_BABBLE_ERR,
  78580. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  78581. + DWC_OTG_HC_XFER_AHB_ERR,
  78582. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  78583. + DWC_OTG_HC_XFER_URB_DEQUEUE
  78584. +} dwc_otg_halt_status_e;
  78585. +
  78586. +/**
  78587. + * Host channel descriptor. This structure represents the state of a single
  78588. + * host channel when acting in host mode. It contains the data items needed to
  78589. + * transfer packets to an endpoint via a host channel.
  78590. + */
  78591. +typedef struct dwc_hc {
  78592. + /** Host channel number used for register address lookup */
  78593. + uint8_t hc_num;
  78594. +
  78595. + /** Device to access */
  78596. + unsigned dev_addr:7;
  78597. +
  78598. + /** EP to access */
  78599. + unsigned ep_num:4;
  78600. +
  78601. + /** EP direction. 0: OUT, 1: IN */
  78602. + unsigned ep_is_in:1;
  78603. +
  78604. + /**
  78605. + * EP speed.
  78606. + * One of the following values:
  78607. + * - DWC_OTG_EP_SPEED_LOW
  78608. + * - DWC_OTG_EP_SPEED_FULL
  78609. + * - DWC_OTG_EP_SPEED_HIGH
  78610. + */
  78611. + unsigned speed:2;
  78612. +#define DWC_OTG_EP_SPEED_LOW 0
  78613. +#define DWC_OTG_EP_SPEED_FULL 1
  78614. +#define DWC_OTG_EP_SPEED_HIGH 2
  78615. +
  78616. + /**
  78617. + * Endpoint type.
  78618. + * One of the following values:
  78619. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  78620. + * - DWC_OTG_EP_TYPE_ISOC: 1
  78621. + * - DWC_OTG_EP_TYPE_BULK: 2
  78622. + * - DWC_OTG_EP_TYPE_INTR: 3
  78623. + */
  78624. + unsigned ep_type:2;
  78625. +
  78626. + /** Max packet size in bytes */
  78627. + unsigned max_packet:11;
  78628. +
  78629. + /**
  78630. + * PID for initial transaction.
  78631. + * 0: DATA0,<br>
  78632. + * 1: DATA2,<br>
  78633. + * 2: DATA1,<br>
  78634. + * 3: MDATA (non-Control EP),
  78635. + * SETUP (Control EP)
  78636. + */
  78637. + unsigned data_pid_start:2;
  78638. +#define DWC_OTG_HC_PID_DATA0 0
  78639. +#define DWC_OTG_HC_PID_DATA2 1
  78640. +#define DWC_OTG_HC_PID_DATA1 2
  78641. +#define DWC_OTG_HC_PID_MDATA 3
  78642. +#define DWC_OTG_HC_PID_SETUP 3
  78643. +
  78644. + /** Number of periodic transactions per (micro)frame */
  78645. + unsigned multi_count:2;
  78646. +
  78647. + /** @name Transfer State */
  78648. + /** @{ */
  78649. +
  78650. + /** Pointer to the current transfer buffer position. */
  78651. + uint8_t *xfer_buff;
  78652. + /**
  78653. + * In Buffer DMA mode this buffer will be used
  78654. + * if xfer_buff is not DWORD aligned.
  78655. + */
  78656. + dwc_dma_t align_buff;
  78657. + /** Total number of bytes to transfer. */
  78658. + uint32_t xfer_len;
  78659. + /** Number of bytes transferred so far. */
  78660. + uint32_t xfer_count;
  78661. + /** Packet count at start of transfer.*/
  78662. + uint16_t start_pkt_count;
  78663. +
  78664. + /**
  78665. + * Flag to indicate whether the transfer has been started. Set to 1 if
  78666. + * it has been started, 0 otherwise.
  78667. + */
  78668. + uint8_t xfer_started;
  78669. +
  78670. + /**
  78671. + * Set to 1 to indicate that a PING request should be issued on this
  78672. + * channel. If 0, process normally.
  78673. + */
  78674. + uint8_t do_ping;
  78675. +
  78676. + /**
  78677. + * Set to 1 to indicate that the error count for this transaction is
  78678. + * non-zero. Set to 0 if the error count is 0.
  78679. + */
  78680. + uint8_t error_state;
  78681. +
  78682. + /**
  78683. + * Set to 1 to indicate that this channel should be halted the next
  78684. + * time a request is queued for the channel. This is necessary in
  78685. + * slave mode if no request queue space is available when an attempt
  78686. + * is made to halt the channel.
  78687. + */
  78688. + uint8_t halt_on_queue;
  78689. +
  78690. + /**
  78691. + * Set to 1 if the host channel has been halted, but the core is not
  78692. + * finished flushing queued requests. Otherwise 0.
  78693. + */
  78694. + uint8_t halt_pending;
  78695. +
  78696. + /**
  78697. + * Reason for halting the host channel.
  78698. + */
  78699. + dwc_otg_halt_status_e halt_status;
  78700. +
  78701. + /*
  78702. + * Split settings for the host channel
  78703. + */
  78704. + uint8_t do_split; /**< Enable split for the channel */
  78705. + uint8_t complete_split; /**< Enable complete split */
  78706. + uint8_t hub_addr; /**< Address of high speed hub */
  78707. +
  78708. + uint8_t port_addr; /**< Port of the low/full speed device */
  78709. + /** Split transaction position
  78710. + * One of the following values:
  78711. + * - DWC_HCSPLIT_XACTPOS_MID
  78712. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  78713. + * - DWC_HCSPLIT_XACTPOS_END
  78714. + * - DWC_HCSPLIT_XACTPOS_ALL */
  78715. + uint8_t xact_pos;
  78716. +
  78717. + /** Set when the host channel does a short read. */
  78718. + uint8_t short_read;
  78719. +
  78720. + /**
  78721. + * Number of requests issued for this channel since it was assigned to
  78722. + * the current transfer (not counting PINGs).
  78723. + */
  78724. + uint8_t requests;
  78725. +
  78726. + /**
  78727. + * Queue Head for the transfer being processed by this channel.
  78728. + */
  78729. + struct dwc_otg_qh *qh;
  78730. +
  78731. + /** @} */
  78732. +
  78733. + /** Entry in list of host channels. */
  78734. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  78735. +
  78736. + /** @name Descriptor DMA support */
  78737. + /** @{ */
  78738. +
  78739. + /** Number of Transfer Descriptors */
  78740. + uint16_t ntd;
  78741. +
  78742. + /** Descriptor List DMA address */
  78743. + dwc_dma_t desc_list_addr;
  78744. +
  78745. + /** Scheduling micro-frame bitmap. */
  78746. + uint8_t schinfo;
  78747. +
  78748. + /** @} */
  78749. +} dwc_hc_t;
  78750. +
  78751. +/**
  78752. + * The following parameters may be specified when starting the module. These
  78753. + * parameters define how the DWC_otg controller should be configured.
  78754. + */
  78755. +typedef struct dwc_otg_core_params {
  78756. + int32_t opt;
  78757. +
  78758. + /**
  78759. + * Specifies the OTG capabilities. The driver will automatically
  78760. + * detect the value for this parameter if none is specified.
  78761. + * 0 - HNP and SRP capable (default)
  78762. + * 1 - SRP Only capable
  78763. + * 2 - No HNP/SRP capable
  78764. + */
  78765. + int32_t otg_cap;
  78766. +
  78767. + /**
  78768. + * Specifies whether to use slave or DMA mode for accessing the data
  78769. + * FIFOs. The driver will automatically detect the value for this
  78770. + * parameter if none is specified.
  78771. + * 0 - Slave
  78772. + * 1 - DMA (default, if available)
  78773. + */
  78774. + int32_t dma_enable;
  78775. +
  78776. + /**
  78777. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  78778. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  78779. + * will automatically detect the value for this if none is specified.
  78780. + * 0 - address DMA
  78781. + * 1 - DMA Descriptor(default, if available)
  78782. + */
  78783. + int32_t dma_desc_enable;
  78784. + /** The DMA Burst size (applicable only for External DMA
  78785. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  78786. + */
  78787. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  78788. +
  78789. + /**
  78790. + * Specifies the maximum speed of operation in host and device mode.
  78791. + * The actual speed depends on the speed of the attached device and
  78792. + * the value of phy_type. The actual speed depends on the speed of the
  78793. + * attached device.
  78794. + * 0 - High Speed (default)
  78795. + * 1 - Full Speed
  78796. + */
  78797. + int32_t speed;
  78798. + /** Specifies whether low power mode is supported when attached
  78799. + * to a Full Speed or Low Speed device in host mode.
  78800. + * 0 - Don't support low power mode (default)
  78801. + * 1 - Support low power mode
  78802. + */
  78803. + int32_t host_support_fs_ls_low_power;
  78804. +
  78805. + /** Specifies the PHY clock rate in low power mode when connected to a
  78806. + * Low Speed device in host mode. This parameter is applicable only if
  78807. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  78808. + * then defaults to 6 MHZ otherwise 48 MHZ.
  78809. + *
  78810. + * 0 - 48 MHz
  78811. + * 1 - 6 MHz
  78812. + */
  78813. + int32_t host_ls_low_power_phy_clk;
  78814. +
  78815. + /**
  78816. + * 0 - Use cC FIFO size parameters
  78817. + * 1 - Allow dynamic FIFO sizing (default)
  78818. + */
  78819. + int32_t enable_dynamic_fifo;
  78820. +
  78821. + /** Total number of 4-byte words in the data FIFO memory. This
  78822. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  78823. + * Tx FIFOs.
  78824. + * 32 to 32768 (default 8192)
  78825. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  78826. + */
  78827. + int32_t data_fifo_size;
  78828. +
  78829. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  78830. + * FIFO sizing is enabled.
  78831. + * 16 to 32768 (default 1064)
  78832. + */
  78833. + int32_t dev_rx_fifo_size;
  78834. +
  78835. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  78836. + * when dynamic FIFO sizing is enabled.
  78837. + * 16 to 32768 (default 1024)
  78838. + */
  78839. + int32_t dev_nperio_tx_fifo_size;
  78840. +
  78841. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  78842. + * mode when dynamic FIFO sizing is enabled.
  78843. + * 4 to 768 (default 256)
  78844. + */
  78845. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  78846. +
  78847. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  78848. + * FIFO sizing is enabled.
  78849. + * 16 to 32768 (default 1024)
  78850. + */
  78851. + int32_t host_rx_fifo_size;
  78852. +
  78853. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  78854. + * when Dynamic FIFO sizing is enabled in the core.
  78855. + * 16 to 32768 (default 1024)
  78856. + */
  78857. + int32_t host_nperio_tx_fifo_size;
  78858. +
  78859. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  78860. + * FIFO sizing is enabled.
  78861. + * 16 to 32768 (default 1024)
  78862. + */
  78863. + int32_t host_perio_tx_fifo_size;
  78864. +
  78865. + /** The maximum transfer size supported in bytes.
  78866. + * 2047 to 65,535 (default 65,535)
  78867. + */
  78868. + int32_t max_transfer_size;
  78869. +
  78870. + /** The maximum number of packets in a transfer.
  78871. + * 15 to 511 (default 511)
  78872. + */
  78873. + int32_t max_packet_count;
  78874. +
  78875. + /** The number of host channel registers to use.
  78876. + * 1 to 16 (default 12)
  78877. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  78878. + */
  78879. + int32_t host_channels;
  78880. +
  78881. + /** The number of endpoints in addition to EP0 available for device
  78882. + * mode operations.
  78883. + * 1 to 15 (default 6 IN and OUT)
  78884. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  78885. + * endpoints in addition to EP0.
  78886. + */
  78887. + int32_t dev_endpoints;
  78888. +
  78889. + /**
  78890. + * Specifies the type of PHY interface to use. By default, the driver
  78891. + * will automatically detect the phy_type.
  78892. + *
  78893. + * 0 - Full Speed PHY
  78894. + * 1 - UTMI+ (default)
  78895. + * 2 - ULPI
  78896. + */
  78897. + int32_t phy_type;
  78898. +
  78899. + /**
  78900. + * Specifies the UTMI+ Data Width. This parameter is
  78901. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  78902. + * PHY_TYPE, this parameter indicates the data width between
  78903. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  78904. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  78905. + * to "8 and 16 bits", meaning that the core has been
  78906. + * configured to work at either data path width.
  78907. + *
  78908. + * 8 or 16 bits (default 16)
  78909. + */
  78910. + int32_t phy_utmi_width;
  78911. +
  78912. + /**
  78913. + * Specifies whether the ULPI operates at double or single
  78914. + * data rate. This parameter is only applicable if PHY_TYPE is
  78915. + * ULPI.
  78916. + *
  78917. + * 0 - single data rate ULPI interface with 8 bit wide data
  78918. + * bus (default)
  78919. + * 1 - double data rate ULPI interface with 4 bit wide data
  78920. + * bus
  78921. + */
  78922. + int32_t phy_ulpi_ddr;
  78923. +
  78924. + /**
  78925. + * Specifies whether to use the internal or external supply to
  78926. + * drive the vbus with a ULPI phy.
  78927. + */
  78928. + int32_t phy_ulpi_ext_vbus;
  78929. +
  78930. + /**
  78931. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  78932. + * parameter is only applicable if PHY_TYPE is FS.
  78933. + * 0 - No (default)
  78934. + * 1 - Yes
  78935. + */
  78936. + int32_t i2c_enable;
  78937. +
  78938. + int32_t ulpi_fs_ls;
  78939. +
  78940. + int32_t ts_dline;
  78941. +
  78942. + /**
  78943. + * Specifies whether dedicated transmit FIFOs are
  78944. + * enabled for non periodic IN endpoints in device mode
  78945. + * 0 - No
  78946. + * 1 - Yes
  78947. + */
  78948. + int32_t en_multiple_tx_fifo;
  78949. +
  78950. + /** Number of 4-byte words in each of the Tx FIFOs in device
  78951. + * mode when dynamic FIFO sizing is enabled.
  78952. + * 4 to 768 (default 256)
  78953. + */
  78954. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  78955. +
  78956. + /** Thresholding enable flag-
  78957. + * bit 0 - enable non-ISO Tx thresholding
  78958. + * bit 1 - enable ISO Tx thresholding
  78959. + * bit 2 - enable Rx thresholding
  78960. + */
  78961. + uint32_t thr_ctl;
  78962. +
  78963. + /** Thresholding length for Tx
  78964. + * FIFOs in 32 bit DWORDs
  78965. + */
  78966. + uint32_t tx_thr_length;
  78967. +
  78968. + /** Thresholding length for Rx
  78969. + * FIFOs in 32 bit DWORDs
  78970. + */
  78971. + uint32_t rx_thr_length;
  78972. +
  78973. + /**
  78974. + * Specifies whether LPM (Link Power Management) support is enabled
  78975. + */
  78976. + int32_t lpm_enable;
  78977. +
  78978. + /** Per Transfer Interrupt
  78979. + * mode enable flag
  78980. + * 1 - Enabled
  78981. + * 0 - Disabled
  78982. + */
  78983. + int32_t pti_enable;
  78984. +
  78985. + /** Multi Processor Interrupt
  78986. + * mode enable flag
  78987. + * 1 - Enabled
  78988. + * 0 - Disabled
  78989. + */
  78990. + int32_t mpi_enable;
  78991. +
  78992. + /** IS_USB Capability
  78993. + * 1 - Enabled
  78994. + * 0 - Disabled
  78995. + */
  78996. + int32_t ic_usb_cap;
  78997. +
  78998. + /** AHB Threshold Ratio
  78999. + * 2'b00 AHB Threshold = MAC Threshold
  79000. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  79001. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  79002. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  79003. + */
  79004. + int32_t ahb_thr_ratio;
  79005. +
  79006. + /** ADP Support
  79007. + * 1 - Enabled
  79008. + * 0 - Disabled
  79009. + */
  79010. + int32_t adp_supp_enable;
  79011. +
  79012. + /** HFIR Reload Control
  79013. + * 0 - The HFIR cannot be reloaded dynamically.
  79014. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  79015. + */
  79016. + int32_t reload_ctl;
  79017. +
  79018. + /** DCFG: Enable device Out NAK
  79019. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  79020. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  79021. + */
  79022. + int32_t dev_out_nak;
  79023. +
  79024. + /** DCFG: Enable Continue on BNA
  79025. + * After receiving BNA interrupt the core disables the endpoint,when the
  79026. + * endpoint is re-enabled by the application the core starts processing
  79027. + * 0 - from the DOEPDMA descriptor
  79028. + * 1 - from the descriptor which received the BNA.
  79029. + */
  79030. + int32_t cont_on_bna;
  79031. +
  79032. + /** GAHBCFG: AHB Single Support
  79033. + * This bit when programmed supports SINGLE transfers for remainder
  79034. + * data in a transfer for DMA mode of operation.
  79035. + * 0 - in this case the remainder data will be sent using INCR burst size.
  79036. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  79037. + */
  79038. + int32_t ahb_single;
  79039. +
  79040. + /** Core Power down mode
  79041. + * 0 - No Power Down is enabled
  79042. + * 1 - Reserved
  79043. + * 2 - Complete Power Down (Hibernation)
  79044. + */
  79045. + int32_t power_down;
  79046. +
  79047. + /** OTG revision supported
  79048. + * 0 - OTG 1.3 revision
  79049. + * 1 - OTG 2.0 revision
  79050. + */
  79051. + int32_t otg_ver;
  79052. +
  79053. +} dwc_otg_core_params_t;
  79054. +
  79055. +#ifdef DEBUG
  79056. +struct dwc_otg_core_if;
  79057. +typedef struct hc_xfer_info {
  79058. + struct dwc_otg_core_if *core_if;
  79059. + dwc_hc_t *hc;
  79060. +} hc_xfer_info_t;
  79061. +#endif
  79062. +
  79063. +typedef struct ep_xfer_info {
  79064. + struct dwc_otg_core_if *core_if;
  79065. + dwc_ep_t *ep;
  79066. + uint8_t state;
  79067. +} ep_xfer_info_t;
  79068. +/*
  79069. + * Device States
  79070. + */
  79071. +typedef enum dwc_otg_lx_state {
  79072. + /** On state */
  79073. + DWC_OTG_L0,
  79074. + /** LPM sleep state*/
  79075. + DWC_OTG_L1,
  79076. + /** USB suspend state*/
  79077. + DWC_OTG_L2,
  79078. + /** Off state*/
  79079. + DWC_OTG_L3
  79080. +} dwc_otg_lx_state_e;
  79081. +
  79082. +struct dwc_otg_global_regs_backup {
  79083. + uint32_t gotgctl_local;
  79084. + uint32_t gintmsk_local;
  79085. + uint32_t gahbcfg_local;
  79086. + uint32_t gusbcfg_local;
  79087. + uint32_t grxfsiz_local;
  79088. + uint32_t gnptxfsiz_local;
  79089. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79090. + uint32_t glpmcfg_local;
  79091. +#endif
  79092. + uint32_t gi2cctl_local;
  79093. + uint32_t hptxfsiz_local;
  79094. + uint32_t pcgcctl_local;
  79095. + uint32_t gdfifocfg_local;
  79096. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  79097. + uint32_t gpwrdn_local;
  79098. + uint32_t xhib_pcgcctl;
  79099. + uint32_t xhib_gpwrdn;
  79100. +};
  79101. +
  79102. +struct dwc_otg_host_regs_backup {
  79103. + uint32_t hcfg_local;
  79104. + uint32_t haintmsk_local;
  79105. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  79106. + uint32_t hprt0_local;
  79107. + uint32_t hfir_local;
  79108. +};
  79109. +
  79110. +struct dwc_otg_dev_regs_backup {
  79111. + uint32_t dcfg;
  79112. + uint32_t dctl;
  79113. + uint32_t daintmsk;
  79114. + uint32_t diepmsk;
  79115. + uint32_t doepmsk;
  79116. + uint32_t diepctl[MAX_EPS_CHANNELS];
  79117. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  79118. + uint32_t diepdma[MAX_EPS_CHANNELS];
  79119. +};
  79120. +/**
  79121. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  79122. + * the DWC_otg controller acting in either host or device mode. It
  79123. + * represents the programming view of the controller as a whole.
  79124. + */
  79125. +struct dwc_otg_core_if {
  79126. + /** Parameters that define how the core should be configured.*/
  79127. + dwc_otg_core_params_t *core_params;
  79128. +
  79129. + /** Core Global registers starting at offset 000h. */
  79130. + dwc_otg_core_global_regs_t *core_global_regs;
  79131. +
  79132. + /** Device-specific information */
  79133. + dwc_otg_dev_if_t *dev_if;
  79134. + /** Host-specific information */
  79135. + dwc_otg_host_if_t *host_if;
  79136. +
  79137. + /** Value from SNPSID register */
  79138. + uint32_t snpsid;
  79139. +
  79140. + /*
  79141. + * Set to 1 if the core PHY interface bits in USBCFG have been
  79142. + * initialized.
  79143. + */
  79144. + uint8_t phy_init_done;
  79145. +
  79146. + /*
  79147. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  79148. + */
  79149. + uint8_t srp_success;
  79150. + uint8_t srp_timer_started;
  79151. + /** Timer for SRP. If it expires before SRP is successful
  79152. + * clear the SRP. */
  79153. + dwc_timer_t *srp_timer;
  79154. +
  79155. +#ifdef DWC_DEV_SRPCAP
  79156. + /* This timer is needed to power on the hibernated host core if SRP is not
  79157. + * initiated on connected SRP capable device for limited period of time
  79158. + */
  79159. + uint8_t pwron_timer_started;
  79160. + dwc_timer_t *pwron_timer;
  79161. +#endif
  79162. + /* Common configuration information */
  79163. + /** Power and Clock Gating Control Register */
  79164. + volatile uint32_t *pcgcctl;
  79165. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  79166. +
  79167. + /** Push/pop addresses for endpoints or host channels.*/
  79168. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  79169. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  79170. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  79171. +
  79172. + /** Total RAM for FIFOs (Bytes) */
  79173. + uint16_t total_fifo_size;
  79174. + /** Size of Rx FIFO (Bytes) */
  79175. + uint16_t rx_fifo_size;
  79176. + /** Size of Non-periodic Tx FIFO (Bytes) */
  79177. + uint16_t nperio_tx_fifo_size;
  79178. +
  79179. + /** 1 if DMA is enabled, 0 otherwise. */
  79180. + uint8_t dma_enable;
  79181. +
  79182. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  79183. + uint8_t dma_desc_enable;
  79184. +
  79185. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  79186. + uint8_t pti_enh_enable;
  79187. +
  79188. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  79189. + uint8_t multiproc_int_enable;
  79190. +
  79191. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  79192. + uint8_t en_multiple_tx_fifo;
  79193. +
  79194. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  79195. + * process of being queued */
  79196. + uint8_t queuing_high_bandwidth;
  79197. +
  79198. + /** Hardware Configuration -- stored here for convenience.*/
  79199. + hwcfg1_data_t hwcfg1;
  79200. + hwcfg2_data_t hwcfg2;
  79201. + hwcfg3_data_t hwcfg3;
  79202. + hwcfg4_data_t hwcfg4;
  79203. + fifosize_data_t hptxfsiz;
  79204. +
  79205. + /** Host and Device Configuration -- stored here for convenience.*/
  79206. + hcfg_data_t hcfg;
  79207. + dcfg_data_t dcfg;
  79208. +
  79209. + /** The operational State, during transations
  79210. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  79211. + * match the core but allows the software to determine
  79212. + * transitions.
  79213. + */
  79214. + uint8_t op_state;
  79215. +
  79216. + /**
  79217. + * Set to 1 if the HCD needs to be restarted on a session request
  79218. + * interrupt. This is required if no connector ID status change has
  79219. + * occurred since the HCD was last disconnected.
  79220. + */
  79221. + uint8_t restart_hcd_on_session_req;
  79222. +
  79223. + /** HCD callbacks */
  79224. + /** A-Device is a_host */
  79225. +#define A_HOST (1)
  79226. + /** A-Device is a_suspend */
  79227. +#define A_SUSPEND (2)
  79228. + /** A-Device is a_peripherial */
  79229. +#define A_PERIPHERAL (3)
  79230. + /** B-Device is operating as a Peripheral. */
  79231. +#define B_PERIPHERAL (4)
  79232. + /** B-Device is operating as a Host. */
  79233. +#define B_HOST (5)
  79234. +
  79235. + /** HCD callbacks */
  79236. + struct dwc_otg_cil_callbacks *hcd_cb;
  79237. + /** PCD callbacks */
  79238. + struct dwc_otg_cil_callbacks *pcd_cb;
  79239. +
  79240. + /** Device mode Periodic Tx FIFO Mask */
  79241. + uint32_t p_tx_msk;
  79242. + /** Device mode Periodic Tx FIFO Mask */
  79243. + uint32_t tx_msk;
  79244. +
  79245. + /** Workqueue object used for handling several interrupts */
  79246. + dwc_workq_t *wq_otg;
  79247. +
  79248. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  79249. + dwc_timer_t *wkp_timer;
  79250. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  79251. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  79252. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  79253. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  79254. +#ifdef DEBUG
  79255. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  79256. +
  79257. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  79258. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  79259. +
  79260. + uint32_t hfnum_7_samples;
  79261. + uint64_t hfnum_7_frrem_accum;
  79262. + uint32_t hfnum_0_samples;
  79263. + uint64_t hfnum_0_frrem_accum;
  79264. + uint32_t hfnum_other_samples;
  79265. + uint64_t hfnum_other_frrem_accum;
  79266. +#endif
  79267. +
  79268. +#ifdef DWC_UTE_CFI
  79269. + uint16_t pwron_rxfsiz;
  79270. + uint16_t pwron_gnptxfsiz;
  79271. + uint16_t pwron_txfsiz[15];
  79272. +
  79273. + uint16_t init_rxfsiz;
  79274. + uint16_t init_gnptxfsiz;
  79275. + uint16_t init_txfsiz[15];
  79276. +#endif
  79277. +
  79278. + /** Lx state of device */
  79279. + dwc_otg_lx_state_e lx_state;
  79280. +
  79281. + /** Saved Core Global registers */
  79282. + struct dwc_otg_global_regs_backup *gr_backup;
  79283. + /** Saved Host registers */
  79284. + struct dwc_otg_host_regs_backup *hr_backup;
  79285. + /** Saved Device registers */
  79286. + struct dwc_otg_dev_regs_backup *dr_backup;
  79287. +
  79288. + /** Power Down Enable */
  79289. + uint32_t power_down;
  79290. +
  79291. + /** ADP support Enable */
  79292. + uint32_t adp_enable;
  79293. +
  79294. + /** ADP structure object */
  79295. + dwc_otg_adp_t adp;
  79296. +
  79297. + /** hibernation/suspend flag */
  79298. + int hibernation_suspend;
  79299. +
  79300. + /** Device mode extended hibernation flag */
  79301. + int xhib;
  79302. +
  79303. + /** OTG revision supported */
  79304. + uint32_t otg_ver;
  79305. +
  79306. + /** OTG status flag used for HNP polling */
  79307. + uint8_t otg_sts;
  79308. +
  79309. + /** Pointer to either hcd->lock or pcd->lock */
  79310. + dwc_spinlock_t *lock;
  79311. +
  79312. + /** Start predict NextEP based on Learning Queue if equal 1,
  79313. + * also used as counter of disabled NP IN EP's */
  79314. + uint8_t start_predict;
  79315. +
  79316. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  79317. + * active, 0xff otherwise */
  79318. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  79319. +
  79320. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  79321. + uint8_t first_in_nextep_seq;
  79322. +
  79323. + /** Frame number while entering to ISR - needed for ISOCs **/
  79324. + uint32_t frame_num;
  79325. +
  79326. +};
  79327. +
  79328. +#ifdef DEBUG
  79329. +/*
  79330. + * This function is called when transfer is timed out.
  79331. + */
  79332. +extern void hc_xfer_timeout(void *ptr);
  79333. +#endif
  79334. +
  79335. +/*
  79336. + * This function is called when transfer is timed out on endpoint.
  79337. + */
  79338. +extern void ep_xfer_timeout(void *ptr);
  79339. +
  79340. +/*
  79341. + * The following functions are functions for works
  79342. + * using during handling some interrupts
  79343. + */
  79344. +extern void w_conn_id_status_change(void *p);
  79345. +
  79346. +extern void w_wakeup_detected(void *p);
  79347. +
  79348. +/** Saves global register values into system memory. */
  79349. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  79350. +/** Saves device register values into system memory. */
  79351. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  79352. +/** Saves host register values into system memory. */
  79353. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  79354. +/** Restore global register values. */
  79355. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  79356. +/** Restore host register values. */
  79357. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  79358. +/** Restore device register values. */
  79359. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  79360. + int rem_wakeup);
  79361. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  79362. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  79363. + int is_host);
  79364. +
  79365. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  79366. + int restore_mode, int reset);
  79367. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  79368. + int rem_wakeup, int reset);
  79369. +
  79370. +/*
  79371. + * The following functions support initialization of the CIL driver component
  79372. + * and the DWC_otg controller.
  79373. + */
  79374. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  79375. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  79376. +
  79377. +/** @name Device CIL Functions
  79378. + * The following functions support managing the DWC_otg controller in device
  79379. + * mode.
  79380. + */
  79381. +/**@{*/
  79382. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  79383. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  79384. + uint32_t * _dest);
  79385. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  79386. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  79387. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  79388. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  79389. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  79390. + dwc_ep_t * _ep);
  79391. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  79392. + dwc_ep_t * _ep);
  79393. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  79394. + dwc_ep_t * _ep);
  79395. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  79396. + dwc_ep_t * _ep);
  79397. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  79398. + dwc_ep_t * _ep, int _dma);
  79399. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  79400. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  79401. + dwc_ep_t * _ep);
  79402. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  79403. +
  79404. +#ifdef DWC_EN_ISOC
  79405. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  79406. + dwc_ep_t * ep);
  79407. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  79408. + dwc_ep_t * ep);
  79409. +#endif /* DWC_EN_ISOC */
  79410. +/**@}*/
  79411. +
  79412. +/** @name Host CIL Functions
  79413. + * The following functions support managing the DWC_otg controller in host
  79414. + * mode.
  79415. + */
  79416. +/**@{*/
  79417. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  79418. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  79419. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  79420. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  79421. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  79422. + dwc_hc_t * _hc);
  79423. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  79424. + dwc_hc_t * _hc);
  79425. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  79426. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  79427. + dwc_hc_t * _hc);
  79428. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  79429. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  79430. +
  79431. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  79432. + dwc_hc_t * hc);
  79433. +
  79434. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  79435. +
  79436. +/* Macro used to clear one channel interrupt */
  79437. +#define clear_hc_int(_hc_regs_, _intr_) \
  79438. +do { \
  79439. + hcint_data_t hcint_clear = {.d32 = 0}; \
  79440. + hcint_clear.b._intr_ = 1; \
  79441. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  79442. +} while (0)
  79443. +
  79444. +/*
  79445. + * Macro used to disable one channel interrupt. Channel interrupts are
  79446. + * disabled when the channel is halted or released by the interrupt handler.
  79447. + * There is no need to handle further interrupts of that type until the
  79448. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  79449. + * because the channel structures are cleaned up when the channel is released.
  79450. + */
  79451. +#define disable_hc_int(_hc_regs_, _intr_) \
  79452. +do { \
  79453. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  79454. + hcintmsk.b._intr_ = 1; \
  79455. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  79456. +} while (0)
  79457. +
  79458. +/**
  79459. + * This function Reads HPRT0 in preparation to modify. It keeps the
  79460. + * WC bits 0 so that if they are read as 1, they won't clear when you
  79461. + * write it back
  79462. + */
  79463. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  79464. +{
  79465. + hprt0_data_t hprt0;
  79466. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  79467. + hprt0.b.prtena = 0;
  79468. + hprt0.b.prtconndet = 0;
  79469. + hprt0.b.prtenchng = 0;
  79470. + hprt0.b.prtovrcurrchng = 0;
  79471. + return hprt0.d32;
  79472. +}
  79473. +
  79474. +/**@}*/
  79475. +
  79476. +/** @name Common CIL Functions
  79477. + * The following functions support managing the DWC_otg controller in either
  79478. + * device or host mode.
  79479. + */
  79480. +/**@{*/
  79481. +
  79482. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  79483. + uint8_t * dest, uint16_t bytes);
  79484. +
  79485. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  79486. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  79487. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  79488. +
  79489. +/**
  79490. + * This function returns the Core Interrupt register.
  79491. + */
  79492. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  79493. +{
  79494. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  79495. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  79496. +}
  79497. +
  79498. +/**
  79499. + * This function returns the OTG Interrupt register.
  79500. + */
  79501. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  79502. +{
  79503. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  79504. +}
  79505. +
  79506. +/**
  79507. + * This function reads the Device All Endpoints Interrupt register and
  79508. + * returns the IN endpoint interrupt bits.
  79509. + */
  79510. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  79511. + core_if)
  79512. +{
  79513. +
  79514. + uint32_t v;
  79515. +
  79516. + if (core_if->multiproc_int_enable) {
  79517. + v = DWC_READ_REG32(&core_if->dev_if->
  79518. + dev_global_regs->deachint) &
  79519. + DWC_READ_REG32(&core_if->
  79520. + dev_if->dev_global_regs->deachintmsk);
  79521. + } else {
  79522. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  79523. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  79524. + }
  79525. + return (v & 0xffff);
  79526. +}
  79527. +
  79528. +/**
  79529. + * This function reads the Device All Endpoints Interrupt register and
  79530. + * returns the OUT endpoint interrupt bits.
  79531. + */
  79532. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  79533. + core_if)
  79534. +{
  79535. + uint32_t v;
  79536. +
  79537. + if (core_if->multiproc_int_enable) {
  79538. + v = DWC_READ_REG32(&core_if->dev_if->
  79539. + dev_global_regs->deachint) &
  79540. + DWC_READ_REG32(&core_if->
  79541. + dev_if->dev_global_regs->deachintmsk);
  79542. + } else {
  79543. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  79544. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  79545. + }
  79546. +
  79547. + return ((v & 0xffff0000) >> 16);
  79548. +}
  79549. +
  79550. +/**
  79551. + * This function returns the Device IN EP Interrupt register
  79552. + */
  79553. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  79554. + dwc_ep_t * ep)
  79555. +{
  79556. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  79557. + uint32_t v, msk, emp;
  79558. +
  79559. + if (core_if->multiproc_int_enable) {
  79560. + msk =
  79561. + DWC_READ_REG32(&dev_if->
  79562. + dev_global_regs->diepeachintmsk[ep->num]);
  79563. + emp =
  79564. + DWC_READ_REG32(&dev_if->
  79565. + dev_global_regs->dtknqr4_fifoemptymsk);
  79566. + msk |= ((emp >> ep->num) & 0x1) << 7;
  79567. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  79568. + } else {
  79569. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  79570. + emp =
  79571. + DWC_READ_REG32(&dev_if->
  79572. + dev_global_regs->dtknqr4_fifoemptymsk);
  79573. + msk |= ((emp >> ep->num) & 0x1) << 7;
  79574. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  79575. + }
  79576. +
  79577. + return v;
  79578. +}
  79579. +
  79580. +/**
  79581. + * This function returns the Device OUT EP Interrupt register
  79582. + */
  79583. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  79584. + _core_if, dwc_ep_t * _ep)
  79585. +{
  79586. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  79587. + uint32_t v;
  79588. + doepmsk_data_t msk = {.d32 = 0 };
  79589. +
  79590. + if (_core_if->multiproc_int_enable) {
  79591. + msk.d32 =
  79592. + DWC_READ_REG32(&dev_if->
  79593. + dev_global_regs->doepeachintmsk[_ep->num]);
  79594. + if (_core_if->pti_enh_enable) {
  79595. + msk.b.pktdrpsts = 1;
  79596. + }
  79597. + v = DWC_READ_REG32(&dev_if->
  79598. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  79599. + } else {
  79600. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  79601. + if (_core_if->pti_enh_enable) {
  79602. + msk.b.pktdrpsts = 1;
  79603. + }
  79604. + v = DWC_READ_REG32(&dev_if->
  79605. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  79606. + }
  79607. + return v;
  79608. +}
  79609. +
  79610. +/**
  79611. + * This function returns the Host All Channel Interrupt register
  79612. + */
  79613. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  79614. + _core_if)
  79615. +{
  79616. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  79617. +}
  79618. +
  79619. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  79620. + _core_if, dwc_hc_t * _hc)
  79621. +{
  79622. + return (DWC_READ_REG32
  79623. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  79624. +}
  79625. +
  79626. +/**
  79627. + * This function returns the mode of the operation, host or device.
  79628. + *
  79629. + * @return 0 - Device Mode, 1 - Host Mode
  79630. + */
  79631. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  79632. +{
  79633. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  79634. +}
  79635. +
  79636. +/**@}*/
  79637. +
  79638. +/**
  79639. + * DWC_otg CIL callback structure. This structure allows the HCD and
  79640. + * PCD to register functions used for starting and stopping the PCD
  79641. + * and HCD for role change on for a DRD.
  79642. + */
  79643. +typedef struct dwc_otg_cil_callbacks {
  79644. + /** Start function for role change */
  79645. + int (*start) (void *_p);
  79646. + /** Stop Function for role change */
  79647. + int (*stop) (void *_p);
  79648. + /** Disconnect Function for role change */
  79649. + int (*disconnect) (void *_p);
  79650. + /** Resume/Remote wakeup Function */
  79651. + int (*resume_wakeup) (void *_p);
  79652. + /** Suspend function */
  79653. + int (*suspend) (void *_p);
  79654. + /** Session Start (SRP) */
  79655. + int (*session_start) (void *_p);
  79656. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79657. + /** Sleep (switch to L0 state) */
  79658. + int (*sleep) (void *_p);
  79659. +#endif
  79660. + /** Pointer passed to start() and stop() */
  79661. + void *p;
  79662. +} dwc_otg_cil_callbacks_t;
  79663. +
  79664. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  79665. + dwc_otg_cil_callbacks_t * _cb,
  79666. + void *_p);
  79667. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  79668. + dwc_otg_cil_callbacks_t * _cb,
  79669. + void *_p);
  79670. +
  79671. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  79672. +
  79673. +//////////////////////////////////////////////////////////////////////
  79674. +/** Start the HCD. Helper function for using the HCD callbacks.
  79675. + *
  79676. + * @param core_if Programming view of DWC_otg controller.
  79677. + */
  79678. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  79679. +{
  79680. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  79681. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  79682. + }
  79683. +}
  79684. +
  79685. +/** Stop the HCD. Helper function for using the HCD callbacks.
  79686. + *
  79687. + * @param core_if Programming view of DWC_otg controller.
  79688. + */
  79689. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  79690. +{
  79691. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  79692. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  79693. + }
  79694. +}
  79695. +
  79696. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  79697. + *
  79698. + * @param core_if Programming view of DWC_otg controller.
  79699. + */
  79700. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  79701. +{
  79702. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  79703. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  79704. + }
  79705. +}
  79706. +
  79707. +/** Inform the HCD the a New Session has begun. Helper function for
  79708. + * using the HCD callbacks.
  79709. + *
  79710. + * @param core_if Programming view of DWC_otg controller.
  79711. + */
  79712. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  79713. +{
  79714. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  79715. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  79716. + }
  79717. +}
  79718. +
  79719. +#ifdef CONFIG_USB_DWC_OTG_LPM
  79720. +/**
  79721. + * Inform the HCD about LPM sleep.
  79722. + * Helper function for using the HCD callbacks.
  79723. + *
  79724. + * @param core_if Programming view of DWC_otg controller.
  79725. + */
  79726. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  79727. +{
  79728. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  79729. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  79730. + }
  79731. +}
  79732. +#endif
  79733. +
  79734. +/** Resume the HCD. Helper function for using the HCD callbacks.
  79735. + *
  79736. + * @param core_if Programming view of DWC_otg controller.
  79737. + */
  79738. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  79739. +{
  79740. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  79741. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  79742. + }
  79743. +}
  79744. +
  79745. +/** Start the PCD. Helper function for using the PCD callbacks.
  79746. + *
  79747. + * @param core_if Programming view of DWC_otg controller.
  79748. + */
  79749. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  79750. +{
  79751. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  79752. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  79753. + }
  79754. +}
  79755. +
  79756. +/** Stop the PCD. Helper function for using the PCD callbacks.
  79757. + *
  79758. + * @param core_if Programming view of DWC_otg controller.
  79759. + */
  79760. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  79761. +{
  79762. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  79763. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  79764. + }
  79765. +}
  79766. +
  79767. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  79768. + *
  79769. + * @param core_if Programming view of DWC_otg controller.
  79770. + */
  79771. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  79772. +{
  79773. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  79774. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  79775. + }
  79776. +}
  79777. +
  79778. +/** Resume the PCD. Helper function for using the PCD callbacks.
  79779. + *
  79780. + * @param core_if Programming view of DWC_otg controller.
  79781. + */
  79782. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  79783. +{
  79784. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  79785. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  79786. + }
  79787. +}
  79788. +
  79789. +//////////////////////////////////////////////////////////////////////
  79790. +
  79791. +#endif
  79792. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  79793. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  79794. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2015-03-09 10:39:33.218893718 +0100
  79795. @@ -0,0 +1,1594 @@
  79796. +/* ==========================================================================
  79797. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  79798. + * $Revision: #32 $
  79799. + * $Date: 2012/08/10 $
  79800. + * $Change: 2047372 $
  79801. + *
  79802. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79803. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79804. + * otherwise expressly agreed to in writing between Synopsys and you.
  79805. + *
  79806. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79807. + * any End User Software License Agreement or Agreement for Licensed Product
  79808. + * with Synopsys or any supplement thereto. You are permitted to use and
  79809. + * redistribute this Software in source and binary forms, with or without
  79810. + * modification, provided that redistributions of source code must retain this
  79811. + * notice. You may not view, use, disclose, copy or distribute this file or
  79812. + * any information contained herein except pursuant to this license grant from
  79813. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79814. + * below, then you are not authorized to use the Software.
  79815. + *
  79816. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79817. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79818. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79819. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79820. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79821. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79822. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79823. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79824. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79825. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79826. + * DAMAGE.
  79827. + * ========================================================================== */
  79828. +
  79829. +/** @file
  79830. + *
  79831. + * The Core Interface Layer provides basic services for accessing and
  79832. + * managing the DWC_otg hardware. These services are used by both the
  79833. + * Host Controller Driver and the Peripheral Controller Driver.
  79834. + *
  79835. + * This file contains the Common Interrupt handlers.
  79836. + */
  79837. +#include "dwc_os.h"
  79838. +#include "dwc_otg_regs.h"
  79839. +#include "dwc_otg_cil.h"
  79840. +#include "dwc_otg_driver.h"
  79841. +#include "dwc_otg_pcd.h"
  79842. +#include "dwc_otg_hcd.h"
  79843. +
  79844. +#ifdef DEBUG
  79845. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  79846. +{
  79847. + return (core_if->op_state == A_HOST ? "a_host" :
  79848. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  79849. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  79850. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  79851. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  79852. +}
  79853. +#endif
  79854. +
  79855. +/** This function will log a debug message
  79856. + *
  79857. + * @param core_if Programming view of DWC_otg controller.
  79858. + */
  79859. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  79860. +{
  79861. + gintsts_data_t gintsts;
  79862. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  79863. + dwc_otg_mode(core_if) ? "Host" : "Device");
  79864. +
  79865. + /* Clear interrupt */
  79866. + gintsts.d32 = 0;
  79867. + gintsts.b.modemismatch = 1;
  79868. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  79869. + return 1;
  79870. +}
  79871. +
  79872. +/**
  79873. + * This function handles the OTG Interrupts. It reads the OTG
  79874. + * Interrupt Register (GOTGINT) to determine what interrupt has
  79875. + * occurred.
  79876. + *
  79877. + * @param core_if Programming view of DWC_otg controller.
  79878. + */
  79879. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  79880. +{
  79881. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  79882. + gotgint_data_t gotgint;
  79883. + gotgctl_data_t gotgctl;
  79884. + gintmsk_data_t gintmsk;
  79885. + gpwrdn_data_t gpwrdn;
  79886. +
  79887. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  79888. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79889. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  79890. + op_state_str(core_if));
  79891. +
  79892. + if (gotgint.b.sesenddet) {
  79893. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79894. + "Session End Detected++ (%s)\n",
  79895. + op_state_str(core_if));
  79896. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79897. +
  79898. + if (core_if->op_state == B_HOST) {
  79899. + cil_pcd_start(core_if);
  79900. + core_if->op_state = B_PERIPHERAL;
  79901. + } else {
  79902. + /* If not B_HOST and Device HNP still set. HNP
  79903. + * Did not succeed!*/
  79904. + if (gotgctl.b.devhnpen) {
  79905. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  79906. + __DWC_ERROR("Device Not Connected/Responding!\n");
  79907. + }
  79908. +
  79909. + /* If Session End Detected the B-Cable has
  79910. + * been disconnected. */
  79911. + /* Reset PCD and Gadget driver to a
  79912. + * clean state. */
  79913. + core_if->lx_state = DWC_OTG_L0;
  79914. + DWC_SPINUNLOCK(core_if->lock);
  79915. + cil_pcd_stop(core_if);
  79916. + DWC_SPINLOCK(core_if->lock);
  79917. +
  79918. + if (core_if->adp_enable) {
  79919. + if (core_if->power_down == 2) {
  79920. + gpwrdn.d32 = 0;
  79921. + gpwrdn.b.pwrdnswtch = 1;
  79922. + DWC_MODIFY_REG32(&core_if->
  79923. + core_global_regs->
  79924. + gpwrdn, gpwrdn.d32, 0);
  79925. + }
  79926. +
  79927. + gpwrdn.d32 = 0;
  79928. + gpwrdn.b.pmuintsel = 1;
  79929. + gpwrdn.b.pmuactv = 1;
  79930. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  79931. + gpwrdn, 0, gpwrdn.d32);
  79932. +
  79933. + dwc_otg_adp_sense_start(core_if);
  79934. + }
  79935. + }
  79936. +
  79937. + gotgctl.d32 = 0;
  79938. + gotgctl.b.devhnpen = 1;
  79939. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  79940. + }
  79941. + if (gotgint.b.sesreqsucstschng) {
  79942. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  79943. + "Session Reqeust Success Status Change++\n");
  79944. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79945. + if (gotgctl.b.sesreqscs) {
  79946. +
  79947. + if ((core_if->core_params->phy_type ==
  79948. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  79949. + core_if->srp_success = 1;
  79950. + } else {
  79951. + DWC_SPINUNLOCK(core_if->lock);
  79952. + cil_pcd_resume(core_if);
  79953. + DWC_SPINLOCK(core_if->lock);
  79954. + /* Clear Session Request */
  79955. + gotgctl.d32 = 0;
  79956. + gotgctl.b.sesreq = 1;
  79957. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  79958. + gotgctl.d32, 0);
  79959. + }
  79960. + }
  79961. + }
  79962. + if (gotgint.b.hstnegsucstschng) {
  79963. + /* Print statements during the HNP interrupt handling
  79964. + * can cause it to fail.*/
  79965. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  79966. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  79967. + * this does not help*/
  79968. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  79969. + dwc_udelay(100);
  79970. + if (gotgctl.b.hstnegscs) {
  79971. + if (dwc_otg_is_host_mode(core_if)) {
  79972. + core_if->op_state = B_HOST;
  79973. + /*
  79974. + * Need to disable SOF interrupt immediately.
  79975. + * When switching from device to host, the PCD
  79976. + * interrupt handler won't handle the
  79977. + * interrupt if host mode is already set. The
  79978. + * HCD interrupt handler won't get called if
  79979. + * the HCD state is HALT. This means that the
  79980. + * interrupt does not get handled and Linux
  79981. + * complains loudly.
  79982. + */
  79983. + gintmsk.d32 = 0;
  79984. + gintmsk.b.sofintr = 1;
  79985. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  79986. + gintmsk.d32, 0);
  79987. + /* Call callback function with spin lock released */
  79988. + DWC_SPINUNLOCK(core_if->lock);
  79989. + cil_pcd_stop(core_if);
  79990. + /*
  79991. + * Initialize the Core for Host mode.
  79992. + */
  79993. + cil_hcd_start(core_if);
  79994. + DWC_SPINLOCK(core_if->lock);
  79995. + core_if->op_state = B_HOST;
  79996. + }
  79997. + } else {
  79998. + gotgctl.d32 = 0;
  79999. + gotgctl.b.hnpreq = 1;
  80000. + gotgctl.b.devhnpen = 1;
  80001. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  80002. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  80003. + __DWC_ERROR("Device Not Connected/Responding\n");
  80004. + }
  80005. + }
  80006. + if (gotgint.b.hstnegdet) {
  80007. + /* The disconnect interrupt is set at the same time as
  80008. + * Host Negotiation Detected. During the mode
  80009. + * switch all interrupts are cleared so the disconnect
  80010. + * interrupt handler will not get executed.
  80011. + */
  80012. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  80013. + "Host Negotiation Detected++ (%s)\n",
  80014. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  80015. + "Device"));
  80016. + if (dwc_otg_is_device_mode(core_if)) {
  80017. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  80018. + core_if->op_state);
  80019. + DWC_SPINUNLOCK(core_if->lock);
  80020. + cil_hcd_disconnect(core_if);
  80021. + cil_pcd_start(core_if);
  80022. + DWC_SPINLOCK(core_if->lock);
  80023. + core_if->op_state = A_PERIPHERAL;
  80024. + } else {
  80025. + /*
  80026. + * Need to disable SOF interrupt immediately. When
  80027. + * switching from device to host, the PCD interrupt
  80028. + * handler won't handle the interrupt if host mode is
  80029. + * already set. The HCD interrupt handler won't get
  80030. + * called if the HCD state is HALT. This means that
  80031. + * the interrupt does not get handled and Linux
  80032. + * complains loudly.
  80033. + */
  80034. + gintmsk.d32 = 0;
  80035. + gintmsk.b.sofintr = 1;
  80036. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  80037. + DWC_SPINUNLOCK(core_if->lock);
  80038. + cil_pcd_stop(core_if);
  80039. + cil_hcd_start(core_if);
  80040. + DWC_SPINLOCK(core_if->lock);
  80041. + core_if->op_state = A_HOST;
  80042. + }
  80043. + }
  80044. + if (gotgint.b.adevtoutchng) {
  80045. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  80046. + "A-Device Timeout Change++\n");
  80047. + }
  80048. + if (gotgint.b.debdone) {
  80049. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  80050. + }
  80051. +
  80052. + /* Clear GOTGINT */
  80053. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  80054. +
  80055. + return 1;
  80056. +}
  80057. +
  80058. +void w_conn_id_status_change(void *p)
  80059. +{
  80060. + dwc_otg_core_if_t *core_if = p;
  80061. + uint32_t count = 0;
  80062. + gotgctl_data_t gotgctl = {.d32 = 0 };
  80063. +
  80064. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  80065. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  80066. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  80067. +
  80068. + /* B-Device connector (Device Mode) */
  80069. + if (gotgctl.b.conidsts) {
  80070. + /* Wait for switch to device mode. */
  80071. + while (!dwc_otg_is_device_mode(core_if)) {
  80072. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  80073. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  80074. + "Peripheral"));
  80075. + dwc_mdelay(100);
  80076. + if (++count > 10000)
  80077. + break;
  80078. + }
  80079. + DWC_ASSERT(++count < 10000,
  80080. + "Connection id status change timed out");
  80081. + core_if->op_state = B_PERIPHERAL;
  80082. + dwc_otg_core_init(core_if);
  80083. + dwc_otg_enable_global_interrupts(core_if);
  80084. + cil_pcd_start(core_if);
  80085. + } else {
  80086. + /* A-Device connector (Host Mode) */
  80087. + while (!dwc_otg_is_host_mode(core_if)) {
  80088. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  80089. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  80090. + "Peripheral"));
  80091. + dwc_mdelay(100);
  80092. + if (++count > 10000)
  80093. + break;
  80094. + }
  80095. + DWC_ASSERT(++count < 10000,
  80096. + "Connection id status change timed out");
  80097. + core_if->op_state = A_HOST;
  80098. + /*
  80099. + * Initialize the Core for Host mode.
  80100. + */
  80101. + dwc_otg_core_init(core_if);
  80102. + dwc_otg_enable_global_interrupts(core_if);
  80103. + cil_hcd_start(core_if);
  80104. + }
  80105. +}
  80106. +
  80107. +/**
  80108. + * This function handles the Connector ID Status Change Interrupt. It
  80109. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  80110. + * is a Device to Host Mode transition or a Host Mode to Device
  80111. + * Transition.
  80112. + *
  80113. + * This only occurs when the cable is connected/removed from the PHY
  80114. + * connector.
  80115. + *
  80116. + * @param core_if Programming view of DWC_otg controller.
  80117. + */
  80118. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  80119. +{
  80120. +
  80121. + /*
  80122. + * Need to disable SOF interrupt immediately. If switching from device
  80123. + * to host, the PCD interrupt handler won't handle the interrupt if
  80124. + * host mode is already set. The HCD interrupt handler won't get
  80125. + * called if the HCD state is HALT. This means that the interrupt does
  80126. + * not get handled and Linux complains loudly.
  80127. + */
  80128. + gintmsk_data_t gintmsk = {.d32 = 0 };
  80129. + gintsts_data_t gintsts = {.d32 = 0 };
  80130. +
  80131. + gintmsk.b.sofintr = 1;
  80132. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  80133. +
  80134. + DWC_DEBUGPL(DBG_CIL,
  80135. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  80136. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  80137. +
  80138. + DWC_SPINUNLOCK(core_if->lock);
  80139. +
  80140. + /*
  80141. + * Need to schedule a work, as there are possible DELAY function calls
  80142. + * Release lock before scheduling workq as it holds spinlock during scheduling
  80143. + */
  80144. +
  80145. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  80146. + core_if, "connection id status change");
  80147. + DWC_SPINLOCK(core_if->lock);
  80148. +
  80149. + /* Set flag and clear interrupt */
  80150. + gintsts.b.conidstschng = 1;
  80151. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80152. +
  80153. + return 1;
  80154. +}
  80155. +
  80156. +/**
  80157. + * This interrupt indicates that a device is initiating the Session
  80158. + * Request Protocol to request the host to turn on bus power so a new
  80159. + * session can begin. The handler responds by turning on bus power. If
  80160. + * the DWC_otg controller is in low power mode, the handler brings the
  80161. + * controller out of low power mode before turning on bus power.
  80162. + *
  80163. + * @param core_if Programming view of DWC_otg controller.
  80164. + */
  80165. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  80166. +{
  80167. + gintsts_data_t gintsts;
  80168. +
  80169. +#ifndef DWC_HOST_ONLY
  80170. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  80171. +
  80172. + if (dwc_otg_is_device_mode(core_if)) {
  80173. + DWC_PRINTF("SRP: Device mode\n");
  80174. + } else {
  80175. + hprt0_data_t hprt0;
  80176. + DWC_PRINTF("SRP: Host mode\n");
  80177. +
  80178. + /* Turn on the port power bit. */
  80179. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  80180. + hprt0.b.prtpwr = 1;
  80181. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  80182. +
  80183. + /* Start the Connection timer. So a message can be displayed
  80184. + * if connect does not occur within 10 seconds. */
  80185. + cil_hcd_session_start(core_if);
  80186. + }
  80187. +#endif
  80188. +
  80189. + /* Clear interrupt */
  80190. + gintsts.d32 = 0;
  80191. + gintsts.b.sessreqintr = 1;
  80192. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80193. +
  80194. + return 1;
  80195. +}
  80196. +
  80197. +void w_wakeup_detected(void *p)
  80198. +{
  80199. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  80200. + /*
  80201. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  80202. + * so that OPT tests pass with all PHYs).
  80203. + */
  80204. + hprt0_data_t hprt0 = {.d32 = 0 };
  80205. +#if 0
  80206. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80207. + /* Restart the Phy Clock */
  80208. + pcgcctl.b.stoppclk = 1;
  80209. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  80210. + dwc_udelay(10);
  80211. +#endif //0
  80212. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  80213. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  80214. +// dwc_mdelay(70);
  80215. + hprt0.b.prtres = 0; /* Resume */
  80216. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  80217. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  80218. + DWC_READ_REG32(core_if->host_if->hprt0));
  80219. +
  80220. + cil_hcd_resume(core_if);
  80221. +
  80222. + /** Change to L0 state*/
  80223. + core_if->lx_state = DWC_OTG_L0;
  80224. +}
  80225. +
  80226. +/**
  80227. + * This interrupt indicates that the DWC_otg controller has detected a
  80228. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  80229. + * low power mode, the handler must brings the controller out of low
  80230. + * power mode. The controller automatically begins resume
  80231. + * signaling. The handler schedules a time to stop resume signaling.
  80232. + */
  80233. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  80234. +{
  80235. + gintsts_data_t gintsts;
  80236. +
  80237. + DWC_DEBUGPL(DBG_ANY,
  80238. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  80239. +
  80240. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  80241. +
  80242. + if (dwc_otg_is_device_mode(core_if)) {
  80243. + dctl_data_t dctl = {.d32 = 0 };
  80244. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  80245. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  80246. + dsts));
  80247. + if (core_if->lx_state == DWC_OTG_L2) {
  80248. +#ifdef PARTIAL_POWER_DOWN
  80249. + if (core_if->hwcfg4.b.power_optimiz) {
  80250. + pcgcctl_data_t power = {.d32 = 0 };
  80251. +
  80252. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  80253. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  80254. + power.d32);
  80255. +
  80256. + power.b.stoppclk = 0;
  80257. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  80258. +
  80259. + power.b.pwrclmp = 0;
  80260. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  80261. +
  80262. + power.b.rstpdwnmodule = 0;
  80263. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  80264. + }
  80265. +#endif
  80266. + /* Clear the Remote Wakeup Signaling */
  80267. + dctl.b.rmtwkupsig = 1;
  80268. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  80269. + dctl, dctl.d32, 0);
  80270. +
  80271. + DWC_SPINUNLOCK(core_if->lock);
  80272. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  80273. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  80274. + }
  80275. + DWC_SPINLOCK(core_if->lock);
  80276. + } else {
  80277. + glpmcfg_data_t lpmcfg;
  80278. + lpmcfg.d32 =
  80279. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  80280. + lpmcfg.b.hird_thres &= (~(1 << 4));
  80281. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  80282. + lpmcfg.d32);
  80283. + }
  80284. + /** Change to L0 state*/
  80285. + core_if->lx_state = DWC_OTG_L0;
  80286. + } else {
  80287. + if (core_if->lx_state != DWC_OTG_L1) {
  80288. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80289. +
  80290. + /* Restart the Phy Clock */
  80291. + pcgcctl.b.stoppclk = 1;
  80292. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  80293. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  80294. + } else {
  80295. + /** Change to L0 state*/
  80296. + core_if->lx_state = DWC_OTG_L0;
  80297. + }
  80298. + }
  80299. +
  80300. + /* Clear interrupt */
  80301. + gintsts.d32 = 0;
  80302. + gintsts.b.wkupintr = 1;
  80303. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80304. +
  80305. + return 1;
  80306. +}
  80307. +
  80308. +/**
  80309. + * This interrupt indicates that the Wakeup Logic has detected a
  80310. + * Device disconnect.
  80311. + */
  80312. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  80313. +{
  80314. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  80315. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  80316. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80317. +
  80318. + DWC_PRINTF("%s called\n", __FUNCTION__);
  80319. +
  80320. + if (!core_if->hibernation_suspend) {
  80321. + DWC_PRINTF("Already exited from Hibernation\n");
  80322. + return 1;
  80323. + }
  80324. +
  80325. + /* Switch on the voltage to the core */
  80326. + gpwrdn.b.pwrdnswtch = 1;
  80327. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80328. + dwc_udelay(10);
  80329. +
  80330. + /* Reset the core */
  80331. + gpwrdn.d32 = 0;
  80332. + gpwrdn.b.pwrdnrstn = 1;
  80333. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80334. + dwc_udelay(10);
  80335. +
  80336. + /* Disable power clamps*/
  80337. + gpwrdn.d32 = 0;
  80338. + gpwrdn.b.pwrdnclmp = 1;
  80339. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80340. +
  80341. + /* Remove reset the core signal */
  80342. + gpwrdn.d32 = 0;
  80343. + gpwrdn.b.pwrdnrstn = 1;
  80344. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  80345. + dwc_udelay(10);
  80346. +
  80347. + /* Disable PMU interrupt */
  80348. + gpwrdn.d32 = 0;
  80349. + gpwrdn.b.pmuintsel = 1;
  80350. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80351. +
  80352. + core_if->hibernation_suspend = 0;
  80353. +
  80354. + /* Disable PMU */
  80355. + gpwrdn.d32 = 0;
  80356. + gpwrdn.b.pmuactv = 1;
  80357. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80358. + dwc_udelay(10);
  80359. +
  80360. + if (gpwrdn_temp.b.idsts) {
  80361. + core_if->op_state = B_PERIPHERAL;
  80362. + dwc_otg_core_init(core_if);
  80363. + dwc_otg_enable_global_interrupts(core_if);
  80364. + cil_pcd_start(core_if);
  80365. + } else {
  80366. + core_if->op_state = A_HOST;
  80367. + dwc_otg_core_init(core_if);
  80368. + dwc_otg_enable_global_interrupts(core_if);
  80369. + cil_hcd_start(core_if);
  80370. + }
  80371. +
  80372. + return 1;
  80373. +}
  80374. +
  80375. +/**
  80376. + * This interrupt indicates that the Wakeup Logic has detected a
  80377. + * remote wakeup sequence.
  80378. + */
  80379. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  80380. +{
  80381. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80382. + DWC_DEBUGPL(DBG_ANY,
  80383. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  80384. +
  80385. + if (!core_if->hibernation_suspend) {
  80386. + DWC_PRINTF("Already exited from Hibernation\n");
  80387. + return 1;
  80388. + }
  80389. +
  80390. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80391. + if (gpwrdn.b.idsts) { // Device Mode
  80392. + if ((core_if->power_down == 2)
  80393. + && (core_if->hibernation_suspend == 1)) {
  80394. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  80395. + }
  80396. + } else {
  80397. + if ((core_if->power_down == 2)
  80398. + && (core_if->hibernation_suspend == 1)) {
  80399. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  80400. + }
  80401. + }
  80402. + return 1;
  80403. +}
  80404. +
  80405. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  80406. +{
  80407. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80408. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  80409. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  80410. +
  80411. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  80412. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80413. + if (core_if->power_down == 2) {
  80414. + if (!core_if->hibernation_suspend) {
  80415. + DWC_PRINTF("Already exited from Hibernation\n");
  80416. + return 1;
  80417. + }
  80418. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  80419. + /* Switch on the voltage to the core */
  80420. + gpwrdn.b.pwrdnswtch = 1;
  80421. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80422. + dwc_udelay(10);
  80423. +
  80424. + /* Reset the core */
  80425. + gpwrdn.d32 = 0;
  80426. + gpwrdn.b.pwrdnrstn = 1;
  80427. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80428. + dwc_udelay(10);
  80429. +
  80430. + /* Disable power clamps */
  80431. + gpwrdn.d32 = 0;
  80432. + gpwrdn.b.pwrdnclmp = 1;
  80433. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80434. +
  80435. + /* Remove reset the core signal */
  80436. + gpwrdn.d32 = 0;
  80437. + gpwrdn.b.pwrdnrstn = 1;
  80438. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  80439. + dwc_udelay(10);
  80440. +
  80441. + /* Disable PMU interrupt */
  80442. + gpwrdn.d32 = 0;
  80443. + gpwrdn.b.pmuintsel = 1;
  80444. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80445. +
  80446. + /*Indicates that we are exiting from hibernation */
  80447. + core_if->hibernation_suspend = 0;
  80448. +
  80449. + /* Disable PMU */
  80450. + gpwrdn.d32 = 0;
  80451. + gpwrdn.b.pmuactv = 1;
  80452. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80453. + dwc_udelay(10);
  80454. +
  80455. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  80456. + if (gpwrdn.b.dis_vbus == 1) {
  80457. + gpwrdn.d32 = 0;
  80458. + gpwrdn.b.dis_vbus = 1;
  80459. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80460. + }
  80461. +
  80462. + if (gpwrdn_temp.b.idsts) {
  80463. + core_if->op_state = B_PERIPHERAL;
  80464. + dwc_otg_core_init(core_if);
  80465. + dwc_otg_enable_global_interrupts(core_if);
  80466. + cil_pcd_start(core_if);
  80467. + } else {
  80468. + core_if->op_state = A_HOST;
  80469. + dwc_otg_core_init(core_if);
  80470. + dwc_otg_enable_global_interrupts(core_if);
  80471. + cil_hcd_start(core_if);
  80472. + }
  80473. + }
  80474. +
  80475. + if (core_if->adp_enable) {
  80476. + uint8_t is_host = 0;
  80477. + DWC_SPINUNLOCK(core_if->lock);
  80478. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  80479. +#ifndef DWC_HOST_ONLY
  80480. + if (gpwrdn_temp.b.idsts)
  80481. + core_if->lock = otg_dev->pcd->lock;
  80482. +#endif
  80483. +#ifndef DWC_DEVICE_ONLY
  80484. + if (!gpwrdn_temp.b.idsts) {
  80485. + core_if->lock = otg_dev->hcd->lock;
  80486. + is_host = 1;
  80487. + }
  80488. +#endif
  80489. + DWC_PRINTF("RESTART ADP\n");
  80490. + if (core_if->adp.probe_enabled)
  80491. + dwc_otg_adp_probe_stop(core_if);
  80492. + if (core_if->adp.sense_enabled)
  80493. + dwc_otg_adp_sense_stop(core_if);
  80494. + if (core_if->adp.sense_timer_started)
  80495. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  80496. + if (core_if->adp.vbuson_timer_started)
  80497. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  80498. + core_if->adp.probe_timer_values[0] = -1;
  80499. + core_if->adp.probe_timer_values[1] = -1;
  80500. + core_if->adp.sense_timer_started = 0;
  80501. + core_if->adp.vbuson_timer_started = 0;
  80502. + core_if->adp.probe_counter = 0;
  80503. + core_if->adp.gpwrdn = 0;
  80504. +
  80505. + /* Disable PMU and restart ADP */
  80506. + gpwrdn_temp.d32 = 0;
  80507. + gpwrdn_temp.b.pmuactv = 1;
  80508. + gpwrdn_temp.b.pmuintsel = 1;
  80509. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80510. + DWC_PRINTF("Check point 1\n");
  80511. + dwc_mdelay(110);
  80512. + dwc_otg_adp_start(core_if, is_host);
  80513. + DWC_SPINLOCK(core_if->lock);
  80514. + }
  80515. +
  80516. +
  80517. + return 1;
  80518. +}
  80519. +
  80520. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  80521. +{
  80522. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80523. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  80524. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  80525. +
  80526. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80527. + if (core_if->power_down == 2) {
  80528. + if (!core_if->hibernation_suspend) {
  80529. + DWC_PRINTF("Already exited from Hibernation\n");
  80530. + return 1;
  80531. + }
  80532. +
  80533. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  80534. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  80535. + gpwrdn.b.bsessvld == 0) {
  80536. + /* Save gpwrdn register for further usage if stschng interrupt */
  80537. + core_if->gr_backup->gpwrdn_local =
  80538. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80539. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  80540. + return 1;
  80541. + }
  80542. +
  80543. + /* Switch on the voltage to the core */
  80544. + gpwrdn.d32 = 0;
  80545. + gpwrdn.b.pwrdnswtch = 1;
  80546. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80547. + dwc_udelay(10);
  80548. +
  80549. + /* Reset the core */
  80550. + gpwrdn.d32 = 0;
  80551. + gpwrdn.b.pwrdnrstn = 1;
  80552. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80553. + dwc_udelay(10);
  80554. +
  80555. + /* Disable power clamps */
  80556. + gpwrdn.d32 = 0;
  80557. + gpwrdn.b.pwrdnclmp = 1;
  80558. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80559. +
  80560. + /* Remove reset the core signal */
  80561. + gpwrdn.d32 = 0;
  80562. + gpwrdn.b.pwrdnrstn = 1;
  80563. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  80564. + dwc_udelay(10);
  80565. +
  80566. + /* Disable PMU interrupt */
  80567. + gpwrdn.d32 = 0;
  80568. + gpwrdn.b.pmuintsel = 1;
  80569. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80570. + dwc_udelay(10);
  80571. +
  80572. + /*Indicates that we are exiting from hibernation */
  80573. + core_if->hibernation_suspend = 0;
  80574. +
  80575. + /* Disable PMU */
  80576. + gpwrdn.d32 = 0;
  80577. + gpwrdn.b.pmuactv = 1;
  80578. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80579. + dwc_udelay(10);
  80580. +
  80581. + core_if->op_state = B_PERIPHERAL;
  80582. + dwc_otg_core_init(core_if);
  80583. + dwc_otg_enable_global_interrupts(core_if);
  80584. + cil_pcd_start(core_if);
  80585. +
  80586. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  80587. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  80588. + /*
  80589. + * Initiate SRP after initial ADP probe.
  80590. + */
  80591. + dwc_otg_initiate_srp(core_if);
  80592. + }
  80593. + }
  80594. +
  80595. + return 1;
  80596. +}
  80597. +/**
  80598. + * This interrupt indicates that the Wakeup Logic has detected a
  80599. + * status change either on IDDIG or BSessVld.
  80600. + */
  80601. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  80602. +{
  80603. + int retval;
  80604. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80605. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  80606. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  80607. +
  80608. + DWC_PRINTF("%s called\n", __FUNCTION__);
  80609. +
  80610. + if (core_if->power_down == 2) {
  80611. + if (core_if->hibernation_suspend <= 0) {
  80612. + DWC_PRINTF("Already exited from Hibernation\n");
  80613. + return 1;
  80614. + } else
  80615. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  80616. +
  80617. + } else {
  80618. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  80619. + }
  80620. +
  80621. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80622. +
  80623. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  80624. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  80625. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  80626. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  80627. + }
  80628. +
  80629. + return retval;
  80630. +}
  80631. +
  80632. +/**
  80633. + * This interrupt indicates that the Wakeup Logic has detected a
  80634. + * SRP.
  80635. + */
  80636. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  80637. +{
  80638. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80639. +
  80640. + DWC_PRINTF("%s called\n", __FUNCTION__);
  80641. +
  80642. + if (!core_if->hibernation_suspend) {
  80643. + DWC_PRINTF("Already exited from Hibernation\n");
  80644. + return 1;
  80645. + }
  80646. +#ifdef DWC_DEV_SRPCAP
  80647. + if (core_if->pwron_timer_started) {
  80648. + core_if->pwron_timer_started = 0;
  80649. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  80650. + }
  80651. +#endif
  80652. +
  80653. + /* Switch on the voltage to the core */
  80654. + gpwrdn.b.pwrdnswtch = 1;
  80655. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80656. + dwc_udelay(10);
  80657. +
  80658. + /* Reset the core */
  80659. + gpwrdn.d32 = 0;
  80660. + gpwrdn.b.pwrdnrstn = 1;
  80661. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80662. + dwc_udelay(10);
  80663. +
  80664. + /* Disable power clamps */
  80665. + gpwrdn.d32 = 0;
  80666. + gpwrdn.b.pwrdnclmp = 1;
  80667. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80668. +
  80669. + /* Remove reset the core signal */
  80670. + gpwrdn.d32 = 0;
  80671. + gpwrdn.b.pwrdnrstn = 1;
  80672. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  80673. + dwc_udelay(10);
  80674. +
  80675. + /* Disable PMU interrupt */
  80676. + gpwrdn.d32 = 0;
  80677. + gpwrdn.b.pmuintsel = 1;
  80678. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80679. +
  80680. + /* Indicates that we are exiting from hibernation */
  80681. + core_if->hibernation_suspend = 0;
  80682. +
  80683. + /* Disable PMU */
  80684. + gpwrdn.d32 = 0;
  80685. + gpwrdn.b.pmuactv = 1;
  80686. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80687. + dwc_udelay(10);
  80688. +
  80689. + /* Programm Disable VBUS to 0 */
  80690. + gpwrdn.d32 = 0;
  80691. + gpwrdn.b.dis_vbus = 1;
  80692. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  80693. +
  80694. + /*Initialize the core as Host */
  80695. + core_if->op_state = A_HOST;
  80696. + dwc_otg_core_init(core_if);
  80697. + dwc_otg_enable_global_interrupts(core_if);
  80698. + cil_hcd_start(core_if);
  80699. +
  80700. + return 1;
  80701. +}
  80702. +
  80703. +/** This interrupt indicates that restore command after Hibernation
  80704. + * was completed by the core. */
  80705. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  80706. +{
  80707. + pcgcctl_data_t pcgcctl;
  80708. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  80709. +
  80710. + //TODO De-assert restore signal. 8.a
  80711. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  80712. + if (pcgcctl.b.restoremode == 1) {
  80713. + gintmsk_data_t gintmsk = {.d32 = 0 };
  80714. + /*
  80715. + * If restore mode is Remote Wakeup,
  80716. + * unmask Remote Wakeup interrupt.
  80717. + */
  80718. + gintmsk.b.wkupintr = 1;
  80719. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  80720. + 0, gintmsk.d32);
  80721. + }
  80722. +
  80723. + return 1;
  80724. +}
  80725. +
  80726. +/**
  80727. + * This interrupt indicates that a device has been disconnected from
  80728. + * the root port.
  80729. + */
  80730. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  80731. +{
  80732. + gintsts_data_t gintsts;
  80733. +
  80734. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  80735. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  80736. + op_state_str(core_if));
  80737. +
  80738. +/** @todo Consolidate this if statement. */
  80739. +#ifndef DWC_HOST_ONLY
  80740. + if (core_if->op_state == B_HOST) {
  80741. + /* If in device mode Disconnect and stop the HCD, then
  80742. + * start the PCD. */
  80743. + DWC_SPINUNLOCK(core_if->lock);
  80744. + cil_hcd_disconnect(core_if);
  80745. + cil_pcd_start(core_if);
  80746. + DWC_SPINLOCK(core_if->lock);
  80747. + core_if->op_state = B_PERIPHERAL;
  80748. + } else if (dwc_otg_is_device_mode(core_if)) {
  80749. + gotgctl_data_t gotgctl = {.d32 = 0 };
  80750. + gotgctl.d32 =
  80751. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  80752. + if (gotgctl.b.hstsethnpen == 1) {
  80753. + /* Do nothing, if HNP in process the OTG
  80754. + * interrupt "Host Negotiation Detected"
  80755. + * interrupt will do the mode switch.
  80756. + */
  80757. + } else if (gotgctl.b.devhnpen == 0) {
  80758. + /* If in device mode Disconnect and stop the HCD, then
  80759. + * start the PCD. */
  80760. + DWC_SPINUNLOCK(core_if->lock);
  80761. + cil_hcd_disconnect(core_if);
  80762. + cil_pcd_start(core_if);
  80763. + DWC_SPINLOCK(core_if->lock);
  80764. + core_if->op_state = B_PERIPHERAL;
  80765. + } else {
  80766. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  80767. + }
  80768. + } else {
  80769. + if (core_if->op_state == A_HOST) {
  80770. + /* A-Cable still connected but device disconnected. */
  80771. + cil_hcd_disconnect(core_if);
  80772. + if (core_if->adp_enable) {
  80773. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  80774. + cil_hcd_stop(core_if);
  80775. + /* Enable Power Down Logic */
  80776. + gpwrdn.b.pmuintsel = 1;
  80777. + gpwrdn.b.pmuactv = 1;
  80778. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80779. + gpwrdn, 0, gpwrdn.d32);
  80780. + dwc_otg_adp_probe_start(core_if);
  80781. +
  80782. + /* Power off the core */
  80783. + if (core_if->power_down == 2) {
  80784. + gpwrdn.d32 = 0;
  80785. + gpwrdn.b.pwrdnswtch = 1;
  80786. + DWC_MODIFY_REG32
  80787. + (&core_if->core_global_regs->gpwrdn,
  80788. + gpwrdn.d32, 0);
  80789. + }
  80790. + }
  80791. + }
  80792. + }
  80793. +#endif
  80794. + /* Change to L3(OFF) state */
  80795. + core_if->lx_state = DWC_OTG_L3;
  80796. +
  80797. + gintsts.d32 = 0;
  80798. + gintsts.b.disconnect = 1;
  80799. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  80800. + return 1;
  80801. +}
  80802. +
  80803. +/**
  80804. + * This interrupt indicates that SUSPEND state has been detected on
  80805. + * the USB.
  80806. + *
  80807. + * For HNP the USB Suspend interrupt signals the change from
  80808. + * "a_peripheral" to "a_host".
  80809. + *
  80810. + * When power management is enabled the core will be put in low power
  80811. + * mode.
  80812. + */
  80813. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  80814. +{
  80815. + dsts_data_t dsts;
  80816. + gintsts_data_t gintsts;
  80817. + dcfg_data_t dcfg;
  80818. +
  80819. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  80820. +
  80821. + if (dwc_otg_is_device_mode(core_if)) {
  80822. + /* Check the Device status register to determine if the Suspend
  80823. + * state is active. */
  80824. + dsts.d32 =
  80825. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  80826. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  80827. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  80828. + "HWCFG4.power Optimize=%d\n",
  80829. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  80830. +
  80831. +#ifdef PARTIAL_POWER_DOWN
  80832. +/** @todo Add a module parameter for power management. */
  80833. +
  80834. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  80835. + pcgcctl_data_t power = {.d32 = 0 };
  80836. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  80837. +
  80838. + power.b.pwrclmp = 1;
  80839. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  80840. +
  80841. + power.b.rstpdwnmodule = 1;
  80842. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  80843. +
  80844. + power.b.stoppclk = 1;
  80845. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  80846. +
  80847. + } else {
  80848. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  80849. + }
  80850. +#endif
  80851. + /* PCD callback for suspend. Release the lock inside of callback function */
  80852. + cil_pcd_suspend(core_if);
  80853. + if (core_if->power_down == 2)
  80854. + {
  80855. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  80856. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  80857. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  80858. +
  80859. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  80860. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80861. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80862. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  80863. +
  80864. + /* Change to L2(suspend) state */
  80865. + core_if->lx_state = DWC_OTG_L2;
  80866. +
  80867. + /* Clear interrupt in gintsts */
  80868. + gintsts.d32 = 0;
  80869. + gintsts.b.usbsuspend = 1;
  80870. + DWC_WRITE_REG32(&core_if->core_global_regs->
  80871. + gintsts, gintsts.d32);
  80872. + DWC_PRINTF("Start of hibernation completed\n");
  80873. + dwc_otg_save_global_regs(core_if);
  80874. + dwc_otg_save_dev_regs(core_if);
  80875. +
  80876. + gusbcfg.d32 =
  80877. + DWC_READ_REG32(&core_if->core_global_regs->
  80878. + gusbcfg);
  80879. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  80880. + /* ULPI interface */
  80881. + /* Suspend the Phy Clock */
  80882. + pcgcctl.d32 = 0;
  80883. + pcgcctl.b.stoppclk = 1;
  80884. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  80885. + pcgcctl.d32);
  80886. + dwc_udelay(10);
  80887. + gpwrdn.b.pmuactv = 1;
  80888. + DWC_MODIFY_REG32(&core_if->
  80889. + core_global_regs->
  80890. + gpwrdn, 0, gpwrdn.d32);
  80891. + } else {
  80892. + /* UTMI+ Interface */
  80893. + gpwrdn.b.pmuactv = 1;
  80894. + DWC_MODIFY_REG32(&core_if->
  80895. + core_global_regs->
  80896. + gpwrdn, 0, gpwrdn.d32);
  80897. + dwc_udelay(10);
  80898. + pcgcctl.b.stoppclk = 1;
  80899. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  80900. + pcgcctl.d32);
  80901. + dwc_udelay(10);
  80902. + }
  80903. +
  80904. + /* Set flag to indicate that we are in hibernation */
  80905. + core_if->hibernation_suspend = 1;
  80906. + /* Enable interrupts from wake up logic */
  80907. + gpwrdn.d32 = 0;
  80908. + gpwrdn.b.pmuintsel = 1;
  80909. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80910. + gpwrdn, 0, gpwrdn.d32);
  80911. + dwc_udelay(10);
  80912. +
  80913. + /* Unmask device mode interrupts in GPWRDN */
  80914. + gpwrdn.d32 = 0;
  80915. + gpwrdn.b.rst_det_msk = 1;
  80916. + gpwrdn.b.lnstchng_msk = 1;
  80917. + gpwrdn.b.sts_chngint_msk = 1;
  80918. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80919. + gpwrdn, 0, gpwrdn.d32);
  80920. + dwc_udelay(10);
  80921. +
  80922. + /* Enable Power Down Clamp */
  80923. + gpwrdn.d32 = 0;
  80924. + gpwrdn.b.pwrdnclmp = 1;
  80925. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80926. + gpwrdn, 0, gpwrdn.d32);
  80927. + dwc_udelay(10);
  80928. +
  80929. + /* Switch off VDD */
  80930. + gpwrdn.d32 = 0;
  80931. + gpwrdn.b.pwrdnswtch = 1;
  80932. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  80933. + gpwrdn, 0, gpwrdn.d32);
  80934. +
  80935. + /* Save gpwrdn register for further usage if stschng interrupt */
  80936. + core_if->gr_backup->gpwrdn_local =
  80937. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80938. + DWC_PRINTF("Hibernation completed\n");
  80939. +
  80940. + return 1;
  80941. + }
  80942. + } else if (core_if->power_down == 3) {
  80943. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  80944. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  80945. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  80946. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  80947. +
  80948. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  80949. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  80950. + core_if->xhib = 1;
  80951. +
  80952. + /* Clear interrupt in gintsts */
  80953. + gintsts.d32 = 0;
  80954. + gintsts.b.usbsuspend = 1;
  80955. + DWC_WRITE_REG32(&core_if->core_global_regs->
  80956. + gintsts, gintsts.d32);
  80957. +
  80958. + dwc_otg_save_global_regs(core_if);
  80959. + dwc_otg_save_dev_regs(core_if);
  80960. +
  80961. + /* Wait for 10 PHY clocks */
  80962. + dwc_udelay(10);
  80963. +
  80964. + /* Program GPIO register while entering to xHib */
  80965. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  80966. +
  80967. + pcgcctl.b.enbl_extnd_hiber = 1;
  80968. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80969. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80970. +
  80971. + pcgcctl.d32 = 0;
  80972. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  80973. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80974. +
  80975. + pcgcctl.d32 = 0;
  80976. + pcgcctl.b.extnd_hiber_switch = 1;
  80977. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  80978. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  80979. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  80980. +
  80981. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  80982. +
  80983. + return 1;
  80984. + }
  80985. + }
  80986. + } else {
  80987. + if (core_if->op_state == A_PERIPHERAL) {
  80988. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  80989. + /* Clear the a_peripheral flag, back to a_host. */
  80990. + DWC_SPINUNLOCK(core_if->lock);
  80991. + cil_pcd_stop(core_if);
  80992. + cil_hcd_start(core_if);
  80993. + DWC_SPINLOCK(core_if->lock);
  80994. + core_if->op_state = A_HOST;
  80995. + }
  80996. + }
  80997. +
  80998. + /* Change to L2(suspend) state */
  80999. + core_if->lx_state = DWC_OTG_L2;
  81000. +
  81001. + /* Clear interrupt */
  81002. + gintsts.d32 = 0;
  81003. + gintsts.b.usbsuspend = 1;
  81004. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  81005. +
  81006. + return 1;
  81007. +}
  81008. +
  81009. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  81010. +{
  81011. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  81012. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  81013. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  81014. +
  81015. + dwc_udelay(10);
  81016. +
  81017. + /* Program GPIO register while entering to xHib */
  81018. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  81019. +
  81020. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  81021. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  81022. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  81023. + dwc_udelay(10);
  81024. +
  81025. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  81026. + gpwrdn.b.restore = 1;
  81027. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  81028. + dwc_udelay(10);
  81029. +
  81030. + restore_lpm_i2c_regs(core_if);
  81031. +
  81032. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  81033. + pcgcctl.b.max_xcvrselect = 1;
  81034. + pcgcctl.b.ess_reg_restored = 0;
  81035. + pcgcctl.b.extnd_hiber_switch = 0;
  81036. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  81037. + pcgcctl.b.enbl_extnd_hiber = 1;
  81038. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  81039. +
  81040. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  81041. + gahbcfg.b.glblintrmsk = 1;
  81042. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  81043. +
  81044. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  81045. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  81046. +
  81047. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  81048. + core_if->gr_backup->gusbcfg_local);
  81049. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  81050. + core_if->dr_backup->dcfg);
  81051. +
  81052. + pcgcctl.d32 = 0;
  81053. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  81054. + pcgcctl.b.max_xcvrselect = 1;
  81055. + pcgcctl.d32 |= 0x608;
  81056. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  81057. + dwc_udelay(10);
  81058. +
  81059. + pcgcctl.d32 = 0;
  81060. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  81061. + pcgcctl.b.max_xcvrselect = 1;
  81062. + pcgcctl.b.ess_reg_restored = 1;
  81063. + pcgcctl.b.enbl_extnd_hiber = 1;
  81064. + pcgcctl.b.rstpdwnmodule = 1;
  81065. + pcgcctl.b.restoremode = 1;
  81066. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  81067. +
  81068. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  81069. +
  81070. + return 1;
  81071. +}
  81072. +
  81073. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81074. +/**
  81075. + * This function hadles LPM transaction received interrupt.
  81076. + */
  81077. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  81078. +{
  81079. + glpmcfg_data_t lpmcfg;
  81080. + gintsts_data_t gintsts;
  81081. +
  81082. + if (!core_if->core_params->lpm_enable) {
  81083. + DWC_PRINTF("Unexpected LPM interrupt\n");
  81084. + }
  81085. +
  81086. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  81087. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  81088. +
  81089. + if (dwc_otg_is_host_mode(core_if)) {
  81090. + cil_hcd_sleep(core_if);
  81091. + } else {
  81092. + lpmcfg.b.hird_thres |= (1 << 4);
  81093. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  81094. + lpmcfg.d32);
  81095. + }
  81096. +
  81097. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  81098. + dwc_udelay(10);
  81099. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  81100. + if (lpmcfg.b.prt_sleep_sts) {
  81101. + /* Save the current state */
  81102. + core_if->lx_state = DWC_OTG_L1;
  81103. + }
  81104. +
  81105. + /* Clear interrupt */
  81106. + gintsts.d32 = 0;
  81107. + gintsts.b.lpmtranrcvd = 1;
  81108. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  81109. + return 1;
  81110. +}
  81111. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  81112. +
  81113. +/**
  81114. + * This function returns the Core Interrupt register.
  81115. + */
  81116. +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)
  81117. +{
  81118. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  81119. + gintsts_data_t gintsts;
  81120. + gintmsk_data_t gintmsk;
  81121. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  81122. + gintmsk_common.b.wkupintr = 1;
  81123. + gintmsk_common.b.sessreqintr = 1;
  81124. + gintmsk_common.b.conidstschng = 1;
  81125. + gintmsk_common.b.otgintr = 1;
  81126. + gintmsk_common.b.modemismatch = 1;
  81127. + gintmsk_common.b.disconnect = 1;
  81128. + gintmsk_common.b.usbsuspend = 1;
  81129. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81130. + gintmsk_common.b.lpmtranrcvd = 1;
  81131. +#endif
  81132. + gintmsk_common.b.restoredone = 1;
  81133. + if(dwc_otg_is_device_mode(core_if))
  81134. + {
  81135. + /** @todo: The port interrupt occurs while in device
  81136. + * mode. Added code to CIL to clear the interrupt for now!
  81137. + */
  81138. + gintmsk_common.b.portintr = 1;
  81139. + }
  81140. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  81141. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  81142. + if(fiq_enable) {
  81143. + local_fiq_disable();
  81144. + /* Pull in the interrupts that the FIQ has masked */
  81145. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  81146. + gintmsk.d32 |= gintmsk_common.d32;
  81147. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  81148. + reenable_gintmsk->d32 = gintmsk.d32;
  81149. + local_fiq_enable();
  81150. + }
  81151. +
  81152. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  81153. +
  81154. +#ifdef DEBUG
  81155. + /* if any common interrupts set */
  81156. + if (gintsts.d32 & gintmsk_common.d32) {
  81157. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  81158. + gintsts.d32, gintmsk.d32);
  81159. + }
  81160. +#endif
  81161. + if (!fiq_enable){
  81162. + if (gahbcfg.b.glblintrmsk)
  81163. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  81164. + else
  81165. + return 0;
  81166. + } else {
  81167. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  81168. + * Can't trust the global interrupt mask bit in this case.
  81169. + */
  81170. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  81171. + }
  81172. +
  81173. +}
  81174. +
  81175. +/* MACRO for clearing interupt bits in GPWRDN register */
  81176. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  81177. +do { \
  81178. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  81179. + gpwrdn.b.__intr = 1; \
  81180. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  81181. + 0, gpwrdn.d32); \
  81182. +} while (0)
  81183. +
  81184. +/**
  81185. + * Common interrupt handler.
  81186. + *
  81187. + * The common interrupts are those that occur in both Host and Device mode.
  81188. + * This handler handles the following interrupts:
  81189. + * - Mode Mismatch Interrupt
  81190. + * - Disconnect Interrupt
  81191. + * - OTG Interrupt
  81192. + * - Connector ID Status Change Interrupt
  81193. + * - Session Request Interrupt.
  81194. + * - Resume / Remote Wakeup Detected Interrupt.
  81195. + * - LPM Transaction Received Interrupt
  81196. + * - ADP Transaction Received Interrupt
  81197. + *
  81198. + */
  81199. +int32_t dwc_otg_handle_common_intr(void *dev)
  81200. +{
  81201. + int retval = 0;
  81202. + gintsts_data_t gintsts;
  81203. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  81204. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  81205. + dwc_otg_device_t *otg_dev = dev;
  81206. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  81207. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  81208. + if (dwc_otg_is_device_mode(core_if))
  81209. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  81210. +
  81211. + if (core_if->lock)
  81212. + DWC_SPINLOCK(core_if->lock);
  81213. +
  81214. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  81215. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  81216. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  81217. + core_if->xhib = 2;
  81218. + if (core_if->lock)
  81219. + DWC_SPINUNLOCK(core_if->lock);
  81220. +
  81221. + return retval;
  81222. + }
  81223. +
  81224. + if (core_if->hibernation_suspend <= 0) {
  81225. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  81226. + * of this handler - god only knows why it's done like this
  81227. + */
  81228. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  81229. +
  81230. + if (gintsts.b.modemismatch) {
  81231. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  81232. + }
  81233. + if (gintsts.b.otgintr) {
  81234. + retval |= dwc_otg_handle_otg_intr(core_if);
  81235. + }
  81236. + if (gintsts.b.conidstschng) {
  81237. + retval |=
  81238. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  81239. + }
  81240. + if (gintsts.b.disconnect) {
  81241. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  81242. + }
  81243. + if (gintsts.b.sessreqintr) {
  81244. + retval |= dwc_otg_handle_session_req_intr(core_if);
  81245. + }
  81246. + if (gintsts.b.wkupintr) {
  81247. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  81248. + }
  81249. + if (gintsts.b.usbsuspend) {
  81250. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  81251. + }
  81252. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81253. + if (gintsts.b.lpmtranrcvd) {
  81254. + retval |= dwc_otg_handle_lpm_intr(core_if);
  81255. + }
  81256. +#endif
  81257. + if (gintsts.b.restoredone) {
  81258. + gintsts.d32 = 0;
  81259. + if (core_if->power_down == 2)
  81260. + core_if->hibernation_suspend = -1;
  81261. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  81262. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  81263. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  81264. + dctl_data_t dctl = {.d32 = 0 };
  81265. +
  81266. + DWC_WRITE_REG32(&core_if->core_global_regs->
  81267. + gintsts, 0xFFFFFFFF);
  81268. +
  81269. + DWC_DEBUGPL(DBG_ANY,
  81270. + "RESTORE DONE generated\n");
  81271. +
  81272. + gpwrdn.b.restore = 1;
  81273. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  81274. + dwc_udelay(10);
  81275. +
  81276. + pcgcctl.b.rstpdwnmodule = 1;
  81277. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  81278. +
  81279. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  81280. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  81281. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  81282. + dwc_udelay(50);
  81283. +
  81284. + dctl.b.pwronprgdone = 1;
  81285. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  81286. + dwc_udelay(10);
  81287. +
  81288. + dwc_otg_restore_global_regs(core_if);
  81289. + dwc_otg_restore_dev_regs(core_if, 0);
  81290. +
  81291. + dctl.d32 = 0;
  81292. + dctl.b.pwronprgdone = 1;
  81293. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  81294. + dwc_udelay(10);
  81295. +
  81296. + pcgcctl.d32 = 0;
  81297. + pcgcctl.b.enbl_extnd_hiber = 1;
  81298. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  81299. +
  81300. + /* The core will be in ON STATE */
  81301. + core_if->lx_state = DWC_OTG_L0;
  81302. + core_if->xhib = 0;
  81303. +
  81304. + DWC_SPINUNLOCK(core_if->lock);
  81305. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  81306. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  81307. + }
  81308. + DWC_SPINLOCK(core_if->lock);
  81309. +
  81310. + }
  81311. +
  81312. + gintsts.b.restoredone = 1;
  81313. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  81314. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  81315. + retval |= 1;
  81316. + }
  81317. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  81318. + /* The port interrupt occurs while in device mode with HPRT0
  81319. + * Port Enable/Disable.
  81320. + */
  81321. + gintsts.d32 = 0;
  81322. + gintsts.b.portintr = 1;
  81323. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  81324. + retval |= 1;
  81325. + gintmsk_reenable.b.portintr = 1;
  81326. +
  81327. + }
  81328. + /* Did we actually handle anything? if so, unmask the interrupt */
  81329. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  81330. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  81331. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  81332. + if (retval && fiq_enable) {
  81333. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  81334. + }
  81335. +
  81336. + } else {
  81337. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  81338. +
  81339. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  81340. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  81341. + if (gpwrdn.b.linestate == 0) {
  81342. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  81343. + } else {
  81344. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  81345. + }
  81346. +
  81347. + retval |= 1;
  81348. + }
  81349. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  81350. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  81351. + /* remote wakeup from hibernation */
  81352. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  81353. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  81354. + } else {
  81355. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  81356. + }
  81357. + retval |= 1;
  81358. + }
  81359. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  81360. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  81361. + if (gpwrdn.b.linestate == 0) {
  81362. + DWC_PRINTF("Reset detected\n");
  81363. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  81364. + }
  81365. + }
  81366. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  81367. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  81368. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  81369. + retval |= 1;
  81370. + }
  81371. + }
  81372. + /* Handle ADP interrupt here */
  81373. + if (gpwrdn.b.adp_int) {
  81374. + DWC_PRINTF("ADP interrupt\n");
  81375. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  81376. + dwc_otg_adp_handle_intr(core_if);
  81377. + retval |= 1;
  81378. + }
  81379. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  81380. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  81381. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  81382. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  81383. +
  81384. + retval |= 1;
  81385. + }
  81386. + if (core_if->lock)
  81387. + DWC_SPINUNLOCK(core_if->lock);
  81388. + return retval;
  81389. +}
  81390. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  81391. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  81392. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2015-03-09 10:39:33.218893718 +0100
  81393. @@ -0,0 +1,705 @@
  81394. +/* ==========================================================================
  81395. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  81396. + * $Revision: #13 $
  81397. + * $Date: 2012/08/10 $
  81398. + * $Change: 2047372 $
  81399. + *
  81400. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81401. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81402. + * otherwise expressly agreed to in writing between Synopsys and you.
  81403. + *
  81404. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81405. + * any End User Software License Agreement or Agreement for Licensed Product
  81406. + * with Synopsys or any supplement thereto. You are permitted to use and
  81407. + * redistribute this Software in source and binary forms, with or without
  81408. + * modification, provided that redistributions of source code must retain this
  81409. + * notice. You may not view, use, disclose, copy or distribute this file or
  81410. + * any information contained herein except pursuant to this license grant from
  81411. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81412. + * below, then you are not authorized to use the Software.
  81413. + *
  81414. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81415. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81416. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81417. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81418. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81419. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81420. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81421. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81422. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81423. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81424. + * DAMAGE.
  81425. + * ========================================================================== */
  81426. +#if !defined(__DWC_CORE_IF_H__)
  81427. +#define __DWC_CORE_IF_H__
  81428. +
  81429. +#include "dwc_os.h"
  81430. +
  81431. +/** @file
  81432. + * This file defines DWC_OTG Core API
  81433. + */
  81434. +
  81435. +struct dwc_otg_core_if;
  81436. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  81437. +
  81438. +/** Maximum number of Periodic FIFOs */
  81439. +#define MAX_PERIO_FIFOS 15
  81440. +/** Maximum number of Periodic FIFOs */
  81441. +#define MAX_TX_FIFOS 15
  81442. +
  81443. +/** Maximum number of Endpoints/HostChannels */
  81444. +#define MAX_EPS_CHANNELS 16
  81445. +
  81446. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  81447. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  81448. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  81449. +
  81450. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  81451. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  81452. +
  81453. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  81454. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  81455. +
  81456. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  81457. +
  81458. +/** This function should be called on every hardware interrupt. */
  81459. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  81460. +
  81461. +/** @name OTG Core Parameters */
  81462. +/** @{ */
  81463. +
  81464. +/**
  81465. + * Specifies the OTG capabilities. The driver will automatically
  81466. + * detect the value for this parameter if none is specified.
  81467. + * 0 - HNP and SRP capable (default)
  81468. + * 1 - SRP Only capable
  81469. + * 2 - No HNP/SRP capable
  81470. + */
  81471. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  81472. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  81473. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  81474. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  81475. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  81476. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  81477. +
  81478. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  81479. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  81480. +#define dwc_param_opt_default 1
  81481. +
  81482. +/**
  81483. + * Specifies whether to use slave or DMA mode for accessing the data
  81484. + * FIFOs. The driver will automatically detect the value for this
  81485. + * parameter if none is specified.
  81486. + * 0 - Slave
  81487. + * 1 - DMA (default, if available)
  81488. + */
  81489. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  81490. + int32_t val);
  81491. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  81492. +#define dwc_param_dma_enable_default 1
  81493. +
  81494. +/**
  81495. + * When DMA mode is enabled specifies whether to use
  81496. + * address DMA or DMA Descritor mode for accessing the data
  81497. + * FIFOs in device mode. The driver will automatically detect
  81498. + * the value for this parameter if none is specified.
  81499. + * 0 - address DMA
  81500. + * 1 - DMA Descriptor(default, if available)
  81501. + */
  81502. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  81503. + int32_t val);
  81504. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  81505. +//#define dwc_param_dma_desc_enable_default 1
  81506. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  81507. +
  81508. +/** The DMA Burst size (applicable only for External DMA
  81509. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  81510. + */
  81511. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  81512. + int32_t val);
  81513. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  81514. +#define dwc_param_dma_burst_size_default 32
  81515. +
  81516. +/**
  81517. + * Specifies the maximum speed of operation in host and device mode.
  81518. + * The actual speed depends on the speed of the attached device and
  81519. + * the value of phy_type. The actual speed depends on the speed of the
  81520. + * attached device.
  81521. + * 0 - High Speed (default)
  81522. + * 1 - Full Speed
  81523. + */
  81524. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  81525. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  81526. +#define dwc_param_speed_default 0
  81527. +#define DWC_SPEED_PARAM_HIGH 0
  81528. +#define DWC_SPEED_PARAM_FULL 1
  81529. +
  81530. +/** Specifies whether low power mode is supported when attached
  81531. + * to a Full Speed or Low Speed device in host mode.
  81532. + * 0 - Don't support low power mode (default)
  81533. + * 1 - Support low power mode
  81534. + */
  81535. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  81536. + core_if, int32_t val);
  81537. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  81538. + * core_if);
  81539. +#define dwc_param_host_support_fs_ls_low_power_default 0
  81540. +
  81541. +/** Specifies the PHY clock rate in low power mode when connected to a
  81542. + * Low Speed device in host mode. This parameter is applicable only if
  81543. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  81544. + * then defaults to 6 MHZ otherwise 48 MHZ.
  81545. + *
  81546. + * 0 - 48 MHz
  81547. + * 1 - 6 MHz
  81548. + */
  81549. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  81550. + core_if, int32_t val);
  81551. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  81552. + core_if);
  81553. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  81554. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  81555. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  81556. +
  81557. +/**
  81558. + * 0 - Use cC FIFO size parameters
  81559. + * 1 - Allow dynamic FIFO sizing (default)
  81560. + */
  81561. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  81562. + int32_t val);
  81563. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  81564. + core_if);
  81565. +#define dwc_param_enable_dynamic_fifo_default 1
  81566. +
  81567. +/** Total number of 4-byte words in the data FIFO memory. This
  81568. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  81569. + * Tx FIFOs.
  81570. + * 32 to 32768 (default 8192)
  81571. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  81572. + */
  81573. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  81574. + int32_t val);
  81575. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  81576. +//#define dwc_param_data_fifo_size_default 8192
  81577. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  81578. +
  81579. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  81580. + * FIFO sizing is enabled.
  81581. + * 16 to 32768 (default 1064)
  81582. + */
  81583. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  81584. + int32_t val);
  81585. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  81586. +#define dwc_param_dev_rx_fifo_size_default 1064
  81587. +
  81588. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  81589. + * when dynamic FIFO sizing is enabled.
  81590. + * 16 to 32768 (default 1024)
  81591. + */
  81592. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81593. + core_if, int32_t val);
  81594. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81595. + core_if);
  81596. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  81597. +
  81598. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  81599. + * mode when dynamic FIFO sizing is enabled.
  81600. + * 4 to 768 (default 256)
  81601. + */
  81602. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  81603. + int32_t val, int fifo_num);
  81604. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  81605. + core_if, int fifo_num);
  81606. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  81607. +
  81608. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  81609. + * FIFO sizing is enabled.
  81610. + * 16 to 32768 (default 1024)
  81611. + */
  81612. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  81613. + int32_t val);
  81614. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  81615. +//#define dwc_param_host_rx_fifo_size_default 1024
  81616. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  81617. +
  81618. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  81619. + * when Dynamic FIFO sizing is enabled in the core.
  81620. + * 16 to 32768 (default 1024)
  81621. + */
  81622. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81623. + core_if, int32_t val);
  81624. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  81625. + core_if);
  81626. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  81627. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  81628. +
  81629. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  81630. + * FIFO sizing is enabled.
  81631. + * 16 to 32768 (default 1024)
  81632. + */
  81633. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  81634. + core_if, int32_t val);
  81635. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  81636. + core_if);
  81637. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  81638. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  81639. +
  81640. +/** The maximum transfer size supported in bytes.
  81641. + * 2047 to 65,535 (default 65,535)
  81642. + */
  81643. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  81644. + int32_t val);
  81645. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  81646. +#define dwc_param_max_transfer_size_default 65535
  81647. +
  81648. +/** The maximum number of packets in a transfer.
  81649. + * 15 to 511 (default 511)
  81650. + */
  81651. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  81652. + int32_t val);
  81653. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  81654. +#define dwc_param_max_packet_count_default 511
  81655. +
  81656. +/** The number of host channel registers to use.
  81657. + * 1 to 16 (default 12)
  81658. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  81659. + */
  81660. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  81661. + int32_t val);
  81662. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  81663. +//#define dwc_param_host_channels_default 12
  81664. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  81665. +
  81666. +/** The number of endpoints in addition to EP0 available for device
  81667. + * mode operations.
  81668. + * 1 to 15 (default 6 IN and OUT)
  81669. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  81670. + * endpoints in addition to EP0.
  81671. + */
  81672. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  81673. + int32_t val);
  81674. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  81675. +#define dwc_param_dev_endpoints_default 6
  81676. +
  81677. +/**
  81678. + * Specifies the type of PHY interface to use. By default, the driver
  81679. + * will automatically detect the phy_type.
  81680. + *
  81681. + * 0 - Full Speed PHY
  81682. + * 1 - UTMI+ (default)
  81683. + * 2 - ULPI
  81684. + */
  81685. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  81686. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  81687. +#define DWC_PHY_TYPE_PARAM_FS 0
  81688. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  81689. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  81690. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  81691. +
  81692. +/**
  81693. + * Specifies the UTMI+ Data Width. This parameter is
  81694. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  81695. + * PHY_TYPE, this parameter indicates the data width between
  81696. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  81697. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  81698. + * to "8 and 16 bits", meaning that the core has been
  81699. + * configured to work at either data path width.
  81700. + *
  81701. + * 8 or 16 bits (default 16)
  81702. + */
  81703. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  81704. + int32_t val);
  81705. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  81706. +//#define dwc_param_phy_utmi_width_default 16
  81707. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  81708. +
  81709. +/**
  81710. + * Specifies whether the ULPI operates at double or single
  81711. + * data rate. This parameter is only applicable if PHY_TYPE is
  81712. + * ULPI.
  81713. + *
  81714. + * 0 - single data rate ULPI interface with 8 bit wide data
  81715. + * bus (default)
  81716. + * 1 - double data rate ULPI interface with 4 bit wide data
  81717. + * bus
  81718. + */
  81719. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  81720. + int32_t val);
  81721. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  81722. +#define dwc_param_phy_ulpi_ddr_default 0
  81723. +
  81724. +/**
  81725. + * Specifies whether to use the internal or external supply to
  81726. + * drive the vbus with a ULPI phy.
  81727. + */
  81728. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  81729. + int32_t val);
  81730. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  81731. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  81732. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  81733. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  81734. +
  81735. +/**
  81736. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  81737. + * parameter is only applicable if PHY_TYPE is FS.
  81738. + * 0 - No (default)
  81739. + * 1 - Yes
  81740. + */
  81741. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  81742. + int32_t val);
  81743. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  81744. +#define dwc_param_i2c_enable_default 0
  81745. +
  81746. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  81747. + int32_t val);
  81748. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  81749. +#define dwc_param_ulpi_fs_ls_default 0
  81750. +
  81751. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  81752. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  81753. +#define dwc_param_ts_dline_default 0
  81754. +
  81755. +/**
  81756. + * Specifies whether dedicated transmit FIFOs are
  81757. + * enabled for non periodic IN endpoints in device mode
  81758. + * 0 - No
  81759. + * 1 - Yes
  81760. + */
  81761. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  81762. + int32_t val);
  81763. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  81764. + core_if);
  81765. +#define dwc_param_en_multiple_tx_fifo_default 1
  81766. +
  81767. +/** Number of 4-byte words in each of the Tx FIFOs in device
  81768. + * mode when dynamic FIFO sizing is enabled.
  81769. + * 4 to 768 (default 256)
  81770. + */
  81771. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  81772. + int fifo_num, int32_t val);
  81773. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  81774. + int fifo_num);
  81775. +#define dwc_param_dev_tx_fifo_size_default 768
  81776. +
  81777. +/** Thresholding enable flag-
  81778. + * bit 0 - enable non-ISO Tx thresholding
  81779. + * bit 1 - enable ISO Tx thresholding
  81780. + * bit 2 - enable Rx thresholding
  81781. + */
  81782. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  81783. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  81784. +#define dwc_param_thr_ctl_default 0
  81785. +
  81786. +/** Thresholding length for Tx
  81787. + * FIFOs in 32 bit DWORDs
  81788. + */
  81789. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  81790. + int32_t val);
  81791. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  81792. +#define dwc_param_tx_thr_length_default 64
  81793. +
  81794. +/** Thresholding length for Rx
  81795. + * FIFOs in 32 bit DWORDs
  81796. + */
  81797. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  81798. + int32_t val);
  81799. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  81800. +#define dwc_param_rx_thr_length_default 64
  81801. +
  81802. +/**
  81803. + * Specifies whether LPM (Link Power Management) support is enabled
  81804. + */
  81805. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  81806. + int32_t val);
  81807. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  81808. +#define dwc_param_lpm_enable_default 1
  81809. +
  81810. +/**
  81811. + * Specifies whether PTI enhancement is enabled
  81812. + */
  81813. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  81814. + int32_t val);
  81815. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  81816. +#define dwc_param_pti_enable_default 0
  81817. +
  81818. +/**
  81819. + * Specifies whether MPI enhancement is enabled
  81820. + */
  81821. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  81822. + int32_t val);
  81823. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  81824. +#define dwc_param_mpi_enable_default 0
  81825. +
  81826. +/**
  81827. + * Specifies whether ADP capability is enabled
  81828. + */
  81829. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  81830. + int32_t val);
  81831. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  81832. +#define dwc_param_adp_enable_default 0
  81833. +
  81834. +/**
  81835. + * Specifies whether IC_USB capability is enabled
  81836. + */
  81837. +
  81838. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  81839. + int32_t val);
  81840. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  81841. +#define dwc_param_ic_usb_cap_default 0
  81842. +
  81843. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  81844. + int32_t val);
  81845. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  81846. +#define dwc_param_ahb_thr_ratio_default 0
  81847. +
  81848. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  81849. + int32_t val);
  81850. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  81851. +#define dwc_param_power_down_default 0
  81852. +
  81853. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  81854. + int32_t val);
  81855. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  81856. +#define dwc_param_reload_ctl_default 0
  81857. +
  81858. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  81859. + int32_t val);
  81860. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  81861. +#define dwc_param_dev_out_nak_default 0
  81862. +
  81863. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  81864. + int32_t val);
  81865. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  81866. +#define dwc_param_cont_on_bna_default 0
  81867. +
  81868. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  81869. + int32_t val);
  81870. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  81871. +#define dwc_param_ahb_single_default 0
  81872. +
  81873. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  81874. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  81875. +#define dwc_param_otg_ver_default 0
  81876. +
  81877. +/** @} */
  81878. +
  81879. +/** @name Access to registers and bit-fields */
  81880. +
  81881. +/**
  81882. + * Dump core registers and SPRAM
  81883. + */
  81884. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  81885. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  81886. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  81887. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  81888. +
  81889. +/**
  81890. + * Get host negotiation status.
  81891. + */
  81892. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  81893. +
  81894. +/**
  81895. + * Get srp status
  81896. + */
  81897. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  81898. +
  81899. +/**
  81900. + * Set hnpreq bit in the GOTGCTL register.
  81901. + */
  81902. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  81903. +
  81904. +/**
  81905. + * Get Content of SNPSID register.
  81906. + */
  81907. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  81908. +
  81909. +/**
  81910. + * Get current mode.
  81911. + * Returns 0 if in device mode, and 1 if in host mode.
  81912. + */
  81913. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  81914. +
  81915. +/**
  81916. + * Get value of hnpcapable field in the GUSBCFG register
  81917. + */
  81918. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  81919. +/**
  81920. + * Set value of hnpcapable field in the GUSBCFG register
  81921. + */
  81922. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  81923. +
  81924. +/**
  81925. + * Get value of srpcapable field in the GUSBCFG register
  81926. + */
  81927. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  81928. +/**
  81929. + * Set value of srpcapable field in the GUSBCFG register
  81930. + */
  81931. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  81932. +
  81933. +/**
  81934. + * Get value of devspeed field in the DCFG register
  81935. + */
  81936. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  81937. +/**
  81938. + * Set value of devspeed field in the DCFG register
  81939. + */
  81940. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  81941. +
  81942. +/**
  81943. + * Get the value of busconnected field from the HPRT0 register
  81944. + */
  81945. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  81946. +
  81947. +/**
  81948. + * Gets the device enumeration Speed.
  81949. + */
  81950. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  81951. +
  81952. +/**
  81953. + * Get value of prtpwr field from the HPRT0 register
  81954. + */
  81955. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  81956. +
  81957. +/**
  81958. + * Get value of flag indicating core state - hibernated or not
  81959. + */
  81960. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  81961. +
  81962. +/**
  81963. + * Set value of prtpwr field from the HPRT0 register
  81964. + */
  81965. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  81966. +
  81967. +/**
  81968. + * Get value of prtsusp field from the HPRT0 regsiter
  81969. + */
  81970. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  81971. +/**
  81972. + * Set value of prtpwr field from the HPRT0 register
  81973. + */
  81974. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  81975. +
  81976. +/**
  81977. + * Get value of ModeChTimEn field from the HCFG regsiter
  81978. + */
  81979. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  81980. +/**
  81981. + * Set value of ModeChTimEn field from the HCFG regsiter
  81982. + */
  81983. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  81984. +
  81985. +/**
  81986. + * Get value of Fram Interval field from the HFIR regsiter
  81987. + */
  81988. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  81989. +/**
  81990. + * Set value of Frame Interval field from the HFIR regsiter
  81991. + */
  81992. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  81993. +
  81994. +/**
  81995. + * Set value of prtres field from the HPRT0 register
  81996. + *FIXME Remove?
  81997. + */
  81998. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  81999. +
  82000. +/**
  82001. + * Get value of rmtwkupsig bit in DCTL register
  82002. + */
  82003. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  82004. +
  82005. +/**
  82006. + * Get value of prt_sleep_sts field from the GLPMCFG register
  82007. + */
  82008. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  82009. +
  82010. +/**
  82011. + * Get value of rem_wkup_en field from the GLPMCFG register
  82012. + */
  82013. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  82014. +
  82015. +/**
  82016. + * Get value of appl_resp field from the GLPMCFG register
  82017. + */
  82018. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  82019. +/**
  82020. + * Set value of appl_resp field from the GLPMCFG register
  82021. + */
  82022. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  82023. +
  82024. +/**
  82025. + * Get value of hsic_connect field from the GLPMCFG register
  82026. + */
  82027. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  82028. +/**
  82029. + * Set value of hsic_connect field from the GLPMCFG register
  82030. + */
  82031. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  82032. +
  82033. +/**
  82034. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  82035. + */
  82036. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  82037. +/**
  82038. + * Set value of inv_sel_hsic field from the GLPMFG register.
  82039. + */
  82040. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  82041. +
  82042. +/*
  82043. + * Some functions for accessing registers
  82044. + */
  82045. +
  82046. +/**
  82047. + * GOTGCTL register
  82048. + */
  82049. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  82050. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  82051. +
  82052. +/**
  82053. + * GUSBCFG register
  82054. + */
  82055. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  82056. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  82057. +
  82058. +/**
  82059. + * GRXFSIZ register
  82060. + */
  82061. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  82062. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  82063. +
  82064. +/**
  82065. + * GNPTXFSIZ register
  82066. + */
  82067. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  82068. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  82069. +
  82070. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  82071. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  82072. +
  82073. +/**
  82074. + * GGPIO register
  82075. + */
  82076. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  82077. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  82078. +
  82079. +/**
  82080. + * GUID register
  82081. + */
  82082. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  82083. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  82084. +
  82085. +/**
  82086. + * HPRT0 register
  82087. + */
  82088. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  82089. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  82090. +
  82091. +/**
  82092. + * GHPTXFSIZE
  82093. + */
  82094. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  82095. +
  82096. +/** @} */
  82097. +
  82098. +#endif /* __DWC_CORE_IF_H__ */
  82099. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  82100. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  82101. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2015-03-09 10:39:33.218893718 +0100
  82102. @@ -0,0 +1,117 @@
  82103. +/* ==========================================================================
  82104. + *
  82105. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82106. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82107. + * otherwise expressly agreed to in writing between Synopsys and you.
  82108. + *
  82109. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82110. + * any End User Software License Agreement or Agreement for Licensed Product
  82111. + * with Synopsys or any supplement thereto. You are permitted to use and
  82112. + * redistribute this Software in source and binary forms, with or without
  82113. + * modification, provided that redistributions of source code must retain this
  82114. + * notice. You may not view, use, disclose, copy or distribute this file or
  82115. + * any information contained herein except pursuant to this license grant from
  82116. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82117. + * below, then you are not authorized to use the Software.
  82118. + *
  82119. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82120. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82121. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82122. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82123. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82124. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82125. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82126. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82127. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82128. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82129. + * DAMAGE.
  82130. + * ========================================================================== */
  82131. +
  82132. +#ifndef __DWC_OTG_DBG_H__
  82133. +#define __DWC_OTG_DBG_H__
  82134. +
  82135. +/** @file
  82136. + * This file defines debug levels.
  82137. + * Debugging support vanishes in non-debug builds.
  82138. + */
  82139. +
  82140. +/**
  82141. + * The Debug Level bit-mask variable.
  82142. + */
  82143. +extern uint32_t g_dbg_lvl;
  82144. +/**
  82145. + * Set the Debug Level variable.
  82146. + */
  82147. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  82148. +{
  82149. + uint32_t old = g_dbg_lvl;
  82150. + g_dbg_lvl = new;
  82151. + return old;
  82152. +}
  82153. +
  82154. +#define DBG_USER (0x1)
  82155. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  82156. +#define DBG_CIL (0x2)
  82157. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  82158. + * messages */
  82159. +#define DBG_CILV (0x20)
  82160. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  82161. + * messages */
  82162. +#define DBG_PCD (0x4)
  82163. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  82164. + * messages */
  82165. +#define DBG_PCDV (0x40)
  82166. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  82167. +#define DBG_HCD (0x8)
  82168. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  82169. + * messages */
  82170. +#define DBG_HCDV (0x80)
  82171. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  82172. + * mode. */
  82173. +#define DBG_HCD_URB (0x800)
  82174. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  82175. + * messages. */
  82176. +#define DBG_HCDI (0x1000)
  82177. +
  82178. +/** When debug level has any bit set, display debug messages */
  82179. +#define DBG_ANY (0xFF)
  82180. +
  82181. +/** All debug messages off */
  82182. +#define DBG_OFF 0
  82183. +
  82184. +/** Prefix string for DWC_DEBUG print macros. */
  82185. +#define USB_DWC "DWC_otg: "
  82186. +
  82187. +/**
  82188. + * Print a debug message when the Global debug level variable contains
  82189. + * the bit defined in <code>lvl</code>.
  82190. + *
  82191. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  82192. + * @param[in] x - like printf
  82193. + *
  82194. + * Example:<p>
  82195. + * <code>
  82196. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  82197. + * </code>
  82198. + * <br>
  82199. + * results in:<br>
  82200. + * <code>
  82201. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  82202. + * </code>
  82203. + */
  82204. +#ifdef DEBUG
  82205. +
  82206. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  82207. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  82208. +
  82209. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  82210. +
  82211. +#else
  82212. +
  82213. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  82214. +# define DWC_DEBUGP(x...)
  82215. +
  82216. +# define CHK_DEBUG_LEVEL(level) (0)
  82217. +
  82218. +#endif /*DEBUG*/
  82219. +#endif
  82220. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  82221. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  82222. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2015-03-09 10:39:33.218893718 +0100
  82223. @@ -0,0 +1,1749 @@
  82224. +/* ==========================================================================
  82225. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  82226. + * $Revision: #92 $
  82227. + * $Date: 2012/08/10 $
  82228. + * $Change: 2047372 $
  82229. + *
  82230. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82231. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82232. + * otherwise expressly agreed to in writing between Synopsys and you.
  82233. + *
  82234. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82235. + * any End User Software License Agreement or Agreement for Licensed Product
  82236. + * with Synopsys or any supplement thereto. You are permitted to use and
  82237. + * redistribute this Software in source and binary forms, with or without
  82238. + * modification, provided that redistributions of source code must retain this
  82239. + * notice. You may not view, use, disclose, copy or distribute this file or
  82240. + * any information contained herein except pursuant to this license grant from
  82241. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82242. + * below, then you are not authorized to use the Software.
  82243. + *
  82244. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82245. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82246. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82247. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82248. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82249. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82250. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82251. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82252. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82253. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82254. + * DAMAGE.
  82255. + * ========================================================================== */
  82256. +
  82257. +/** @file
  82258. + * The dwc_otg_driver module provides the initialization and cleanup entry
  82259. + * points for the DWC_otg driver. This module will be dynamically installed
  82260. + * after Linux is booted using the insmod command. When the module is
  82261. + * installed, the dwc_otg_driver_init function is called. When the module is
  82262. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  82263. + *
  82264. + * This module also defines a data structure for the dwc_otg_driver, which is
  82265. + * used in conjunction with the standard ARM lm_device structure. These
  82266. + * structures allow the OTG driver to comply with the standard Linux driver
  82267. + * model in which devices and drivers are registered with a bus driver. This
  82268. + * has the benefit that Linux can expose attributes of the driver and device
  82269. + * in its special sysfs file system. Users can then read or write files in
  82270. + * this file system to perform diagnostics on the driver components or the
  82271. + * device.
  82272. + */
  82273. +
  82274. +#include "dwc_otg_os_dep.h"
  82275. +#include "dwc_os.h"
  82276. +#include "dwc_otg_dbg.h"
  82277. +#include "dwc_otg_driver.h"
  82278. +#include "dwc_otg_attr.h"
  82279. +#include "dwc_otg_core_if.h"
  82280. +#include "dwc_otg_pcd_if.h"
  82281. +#include "dwc_otg_hcd_if.h"
  82282. +#include "dwc_otg_fiq_fsm.h"
  82283. +
  82284. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  82285. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  82286. +
  82287. +bool microframe_schedule=true;
  82288. +
  82289. +static const char dwc_driver_name[] = "dwc_otg";
  82290. +
  82291. +
  82292. +extern int pcd_init(
  82293. +#ifdef LM_INTERFACE
  82294. + struct lm_device *_dev
  82295. +#elif defined(PCI_INTERFACE)
  82296. + struct pci_dev *_dev
  82297. +#elif defined(PLATFORM_INTERFACE)
  82298. + struct platform_device *dev
  82299. +#endif
  82300. + );
  82301. +extern int hcd_init(
  82302. +#ifdef LM_INTERFACE
  82303. + struct lm_device *_dev
  82304. +#elif defined(PCI_INTERFACE)
  82305. + struct pci_dev *_dev
  82306. +#elif defined(PLATFORM_INTERFACE)
  82307. + struct platform_device *dev
  82308. +#endif
  82309. + );
  82310. +
  82311. +extern int pcd_remove(
  82312. +#ifdef LM_INTERFACE
  82313. + struct lm_device *_dev
  82314. +#elif defined(PCI_INTERFACE)
  82315. + struct pci_dev *_dev
  82316. +#elif defined(PLATFORM_INTERFACE)
  82317. + struct platform_device *_dev
  82318. +#endif
  82319. + );
  82320. +
  82321. +extern void hcd_remove(
  82322. +#ifdef LM_INTERFACE
  82323. + struct lm_device *_dev
  82324. +#elif defined(PCI_INTERFACE)
  82325. + struct pci_dev *_dev
  82326. +#elif defined(PLATFORM_INTERFACE)
  82327. + struct platform_device *_dev
  82328. +#endif
  82329. + );
  82330. +
  82331. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  82332. +
  82333. +/*-------------------------------------------------------------------------*/
  82334. +/* Encapsulate the module parameter settings */
  82335. +
  82336. +struct dwc_otg_driver_module_params {
  82337. + int32_t opt;
  82338. + int32_t otg_cap;
  82339. + int32_t dma_enable;
  82340. + int32_t dma_desc_enable;
  82341. + int32_t dma_burst_size;
  82342. + int32_t speed;
  82343. + int32_t host_support_fs_ls_low_power;
  82344. + int32_t host_ls_low_power_phy_clk;
  82345. + int32_t enable_dynamic_fifo;
  82346. + int32_t data_fifo_size;
  82347. + int32_t dev_rx_fifo_size;
  82348. + int32_t dev_nperio_tx_fifo_size;
  82349. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  82350. + int32_t host_rx_fifo_size;
  82351. + int32_t host_nperio_tx_fifo_size;
  82352. + int32_t host_perio_tx_fifo_size;
  82353. + int32_t max_transfer_size;
  82354. + int32_t max_packet_count;
  82355. + int32_t host_channels;
  82356. + int32_t dev_endpoints;
  82357. + int32_t phy_type;
  82358. + int32_t phy_utmi_width;
  82359. + int32_t phy_ulpi_ddr;
  82360. + int32_t phy_ulpi_ext_vbus;
  82361. + int32_t i2c_enable;
  82362. + int32_t ulpi_fs_ls;
  82363. + int32_t ts_dline;
  82364. + int32_t en_multiple_tx_fifo;
  82365. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  82366. + uint32_t thr_ctl;
  82367. + uint32_t tx_thr_length;
  82368. + uint32_t rx_thr_length;
  82369. + int32_t pti_enable;
  82370. + int32_t mpi_enable;
  82371. + int32_t lpm_enable;
  82372. + int32_t ic_usb_cap;
  82373. + int32_t ahb_thr_ratio;
  82374. + int32_t power_down;
  82375. + int32_t reload_ctl;
  82376. + int32_t dev_out_nak;
  82377. + int32_t cont_on_bna;
  82378. + int32_t ahb_single;
  82379. + int32_t otg_ver;
  82380. + int32_t adp_enable;
  82381. +};
  82382. +
  82383. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  82384. + .opt = -1,
  82385. + .otg_cap = -1,
  82386. + .dma_enable = -1,
  82387. + .dma_desc_enable = -1,
  82388. + .dma_burst_size = -1,
  82389. + .speed = -1,
  82390. + .host_support_fs_ls_low_power = -1,
  82391. + .host_ls_low_power_phy_clk = -1,
  82392. + .enable_dynamic_fifo = -1,
  82393. + .data_fifo_size = -1,
  82394. + .dev_rx_fifo_size = -1,
  82395. + .dev_nperio_tx_fifo_size = -1,
  82396. + .dev_perio_tx_fifo_size = {
  82397. + /* dev_perio_tx_fifo_size_1 */
  82398. + -1,
  82399. + -1,
  82400. + -1,
  82401. + -1,
  82402. + -1,
  82403. + -1,
  82404. + -1,
  82405. + -1,
  82406. + -1,
  82407. + -1,
  82408. + -1,
  82409. + -1,
  82410. + -1,
  82411. + -1,
  82412. + -1
  82413. + /* 15 */
  82414. + },
  82415. + .host_rx_fifo_size = -1,
  82416. + .host_nperio_tx_fifo_size = -1,
  82417. + .host_perio_tx_fifo_size = -1,
  82418. + .max_transfer_size = -1,
  82419. + .max_packet_count = -1,
  82420. + .host_channels = -1,
  82421. + .dev_endpoints = -1,
  82422. + .phy_type = -1,
  82423. + .phy_utmi_width = -1,
  82424. + .phy_ulpi_ddr = -1,
  82425. + .phy_ulpi_ext_vbus = -1,
  82426. + .i2c_enable = -1,
  82427. + .ulpi_fs_ls = -1,
  82428. + .ts_dline = -1,
  82429. + .en_multiple_tx_fifo = -1,
  82430. + .dev_tx_fifo_size = {
  82431. + /* dev_tx_fifo_size */
  82432. + -1,
  82433. + -1,
  82434. + -1,
  82435. + -1,
  82436. + -1,
  82437. + -1,
  82438. + -1,
  82439. + -1,
  82440. + -1,
  82441. + -1,
  82442. + -1,
  82443. + -1,
  82444. + -1,
  82445. + -1,
  82446. + -1
  82447. + /* 15 */
  82448. + },
  82449. + .thr_ctl = -1,
  82450. + .tx_thr_length = -1,
  82451. + .rx_thr_length = -1,
  82452. + .pti_enable = -1,
  82453. + .mpi_enable = -1,
  82454. + .lpm_enable = 0,
  82455. + .ic_usb_cap = -1,
  82456. + .ahb_thr_ratio = -1,
  82457. + .power_down = -1,
  82458. + .reload_ctl = -1,
  82459. + .dev_out_nak = -1,
  82460. + .cont_on_bna = -1,
  82461. + .ahb_single = -1,
  82462. + .otg_ver = -1,
  82463. + .adp_enable = -1,
  82464. +};
  82465. +
  82466. +//Global variable to switch the fiq fix on or off
  82467. +bool fiq_enable = 1;
  82468. +// Global variable to enable the split transaction fix
  82469. +bool fiq_fsm_enable = true;
  82470. +//Bulk split-transaction NAK holdoff in microframes
  82471. +uint16_t nak_holdoff = 8;
  82472. +
  82473. +unsigned short fiq_fsm_mask = 0x07;
  82474. +
  82475. +/**
  82476. + * This function shows the Driver Version.
  82477. + */
  82478. +static ssize_t version_show(struct device_driver *dev, char *buf)
  82479. +{
  82480. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  82481. + DWC_DRIVER_VERSION);
  82482. +}
  82483. +
  82484. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  82485. +
  82486. +/**
  82487. + * Global Debug Level Mask.
  82488. + */
  82489. +uint32_t g_dbg_lvl = 0; /* OFF */
  82490. +
  82491. +/**
  82492. + * This function shows the driver Debug Level.
  82493. + */
  82494. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  82495. +{
  82496. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  82497. +}
  82498. +
  82499. +/**
  82500. + * This function stores the driver Debug Level.
  82501. + */
  82502. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  82503. + size_t count)
  82504. +{
  82505. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  82506. + return count;
  82507. +}
  82508. +
  82509. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  82510. + dbg_level_store);
  82511. +
  82512. +/**
  82513. + * This function is called during module intialization
  82514. + * to pass module parameters to the DWC_OTG CORE.
  82515. + */
  82516. +static int set_parameters(dwc_otg_core_if_t * core_if)
  82517. +{
  82518. + int retval = 0;
  82519. + int i;
  82520. +
  82521. + if (dwc_otg_module_params.otg_cap != -1) {
  82522. + retval +=
  82523. + dwc_otg_set_param_otg_cap(core_if,
  82524. + dwc_otg_module_params.otg_cap);
  82525. + }
  82526. + if (dwc_otg_module_params.dma_enable != -1) {
  82527. + retval +=
  82528. + dwc_otg_set_param_dma_enable(core_if,
  82529. + dwc_otg_module_params.
  82530. + dma_enable);
  82531. + }
  82532. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  82533. + retval +=
  82534. + dwc_otg_set_param_dma_desc_enable(core_if,
  82535. + dwc_otg_module_params.
  82536. + dma_desc_enable);
  82537. + }
  82538. + if (dwc_otg_module_params.opt != -1) {
  82539. + retval +=
  82540. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  82541. + }
  82542. + if (dwc_otg_module_params.dma_burst_size != -1) {
  82543. + retval +=
  82544. + dwc_otg_set_param_dma_burst_size(core_if,
  82545. + dwc_otg_module_params.
  82546. + dma_burst_size);
  82547. + }
  82548. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  82549. + retval +=
  82550. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  82551. + dwc_otg_module_params.
  82552. + host_support_fs_ls_low_power);
  82553. + }
  82554. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  82555. + retval +=
  82556. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  82557. + dwc_otg_module_params.
  82558. + enable_dynamic_fifo);
  82559. + }
  82560. + if (dwc_otg_module_params.data_fifo_size != -1) {
  82561. + retval +=
  82562. + dwc_otg_set_param_data_fifo_size(core_if,
  82563. + dwc_otg_module_params.
  82564. + data_fifo_size);
  82565. + }
  82566. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  82567. + retval +=
  82568. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  82569. + dwc_otg_module_params.
  82570. + dev_rx_fifo_size);
  82571. + }
  82572. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  82573. + retval +=
  82574. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  82575. + dwc_otg_module_params.
  82576. + dev_nperio_tx_fifo_size);
  82577. + }
  82578. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  82579. + retval +=
  82580. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  82581. + dwc_otg_module_params.host_rx_fifo_size);
  82582. + }
  82583. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  82584. + retval +=
  82585. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  82586. + dwc_otg_module_params.
  82587. + host_nperio_tx_fifo_size);
  82588. + }
  82589. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  82590. + retval +=
  82591. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  82592. + dwc_otg_module_params.
  82593. + host_perio_tx_fifo_size);
  82594. + }
  82595. + if (dwc_otg_module_params.max_transfer_size != -1) {
  82596. + retval +=
  82597. + dwc_otg_set_param_max_transfer_size(core_if,
  82598. + dwc_otg_module_params.
  82599. + max_transfer_size);
  82600. + }
  82601. + if (dwc_otg_module_params.max_packet_count != -1) {
  82602. + retval +=
  82603. + dwc_otg_set_param_max_packet_count(core_if,
  82604. + dwc_otg_module_params.
  82605. + max_packet_count);
  82606. + }
  82607. + if (dwc_otg_module_params.host_channels != -1) {
  82608. + retval +=
  82609. + dwc_otg_set_param_host_channels(core_if,
  82610. + dwc_otg_module_params.
  82611. + host_channels);
  82612. + }
  82613. + if (dwc_otg_module_params.dev_endpoints != -1) {
  82614. + retval +=
  82615. + dwc_otg_set_param_dev_endpoints(core_if,
  82616. + dwc_otg_module_params.
  82617. + dev_endpoints);
  82618. + }
  82619. + if (dwc_otg_module_params.phy_type != -1) {
  82620. + retval +=
  82621. + dwc_otg_set_param_phy_type(core_if,
  82622. + dwc_otg_module_params.phy_type);
  82623. + }
  82624. + if (dwc_otg_module_params.speed != -1) {
  82625. + retval +=
  82626. + dwc_otg_set_param_speed(core_if,
  82627. + dwc_otg_module_params.speed);
  82628. + }
  82629. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  82630. + retval +=
  82631. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  82632. + dwc_otg_module_params.
  82633. + host_ls_low_power_phy_clk);
  82634. + }
  82635. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  82636. + retval +=
  82637. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  82638. + dwc_otg_module_params.
  82639. + phy_ulpi_ddr);
  82640. + }
  82641. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  82642. + retval +=
  82643. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  82644. + dwc_otg_module_params.
  82645. + phy_ulpi_ext_vbus);
  82646. + }
  82647. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  82648. + retval +=
  82649. + dwc_otg_set_param_phy_utmi_width(core_if,
  82650. + dwc_otg_module_params.
  82651. + phy_utmi_width);
  82652. + }
  82653. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  82654. + retval +=
  82655. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  82656. + dwc_otg_module_params.ulpi_fs_ls);
  82657. + }
  82658. + if (dwc_otg_module_params.ts_dline != -1) {
  82659. + retval +=
  82660. + dwc_otg_set_param_ts_dline(core_if,
  82661. + dwc_otg_module_params.ts_dline);
  82662. + }
  82663. + if (dwc_otg_module_params.i2c_enable != -1) {
  82664. + retval +=
  82665. + dwc_otg_set_param_i2c_enable(core_if,
  82666. + dwc_otg_module_params.
  82667. + i2c_enable);
  82668. + }
  82669. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  82670. + retval +=
  82671. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  82672. + dwc_otg_module_params.
  82673. + en_multiple_tx_fifo);
  82674. + }
  82675. + for (i = 0; i < 15; i++) {
  82676. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  82677. + retval +=
  82678. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  82679. + dwc_otg_module_params.
  82680. + dev_perio_tx_fifo_size
  82681. + [i], i);
  82682. + }
  82683. + }
  82684. +
  82685. + for (i = 0; i < 15; i++) {
  82686. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  82687. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  82688. + dwc_otg_module_params.
  82689. + dev_tx_fifo_size
  82690. + [i], i);
  82691. + }
  82692. + }
  82693. + if (dwc_otg_module_params.thr_ctl != -1) {
  82694. + retval +=
  82695. + dwc_otg_set_param_thr_ctl(core_if,
  82696. + dwc_otg_module_params.thr_ctl);
  82697. + }
  82698. + if (dwc_otg_module_params.mpi_enable != -1) {
  82699. + retval +=
  82700. + dwc_otg_set_param_mpi_enable(core_if,
  82701. + dwc_otg_module_params.
  82702. + mpi_enable);
  82703. + }
  82704. + if (dwc_otg_module_params.pti_enable != -1) {
  82705. + retval +=
  82706. + dwc_otg_set_param_pti_enable(core_if,
  82707. + dwc_otg_module_params.
  82708. + pti_enable);
  82709. + }
  82710. + if (dwc_otg_module_params.lpm_enable != -1) {
  82711. + retval +=
  82712. + dwc_otg_set_param_lpm_enable(core_if,
  82713. + dwc_otg_module_params.
  82714. + lpm_enable);
  82715. + }
  82716. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  82717. + retval +=
  82718. + dwc_otg_set_param_ic_usb_cap(core_if,
  82719. + dwc_otg_module_params.
  82720. + ic_usb_cap);
  82721. + }
  82722. + if (dwc_otg_module_params.tx_thr_length != -1) {
  82723. + retval +=
  82724. + dwc_otg_set_param_tx_thr_length(core_if,
  82725. + dwc_otg_module_params.tx_thr_length);
  82726. + }
  82727. + if (dwc_otg_module_params.rx_thr_length != -1) {
  82728. + retval +=
  82729. + dwc_otg_set_param_rx_thr_length(core_if,
  82730. + dwc_otg_module_params.
  82731. + rx_thr_length);
  82732. + }
  82733. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  82734. + retval +=
  82735. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  82736. + dwc_otg_module_params.ahb_thr_ratio);
  82737. + }
  82738. + if (dwc_otg_module_params.power_down != -1) {
  82739. + retval +=
  82740. + dwc_otg_set_param_power_down(core_if,
  82741. + dwc_otg_module_params.power_down);
  82742. + }
  82743. + if (dwc_otg_module_params.reload_ctl != -1) {
  82744. + retval +=
  82745. + dwc_otg_set_param_reload_ctl(core_if,
  82746. + dwc_otg_module_params.reload_ctl);
  82747. + }
  82748. +
  82749. + if (dwc_otg_module_params.dev_out_nak != -1) {
  82750. + retval +=
  82751. + dwc_otg_set_param_dev_out_nak(core_if,
  82752. + dwc_otg_module_params.dev_out_nak);
  82753. + }
  82754. +
  82755. + if (dwc_otg_module_params.cont_on_bna != -1) {
  82756. + retval +=
  82757. + dwc_otg_set_param_cont_on_bna(core_if,
  82758. + dwc_otg_module_params.cont_on_bna);
  82759. + }
  82760. +
  82761. + if (dwc_otg_module_params.ahb_single != -1) {
  82762. + retval +=
  82763. + dwc_otg_set_param_ahb_single(core_if,
  82764. + dwc_otg_module_params.ahb_single);
  82765. + }
  82766. +
  82767. + if (dwc_otg_module_params.otg_ver != -1) {
  82768. + retval +=
  82769. + dwc_otg_set_param_otg_ver(core_if,
  82770. + dwc_otg_module_params.otg_ver);
  82771. + }
  82772. + if (dwc_otg_module_params.adp_enable != -1) {
  82773. + retval +=
  82774. + dwc_otg_set_param_adp_enable(core_if,
  82775. + dwc_otg_module_params.
  82776. + adp_enable);
  82777. + }
  82778. + return retval;
  82779. +}
  82780. +
  82781. +/**
  82782. + * This function is the top level interrupt handler for the Common
  82783. + * (Device and host modes) interrupts.
  82784. + */
  82785. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  82786. +{
  82787. + int32_t retval = IRQ_NONE;
  82788. +
  82789. + retval = dwc_otg_handle_common_intr(dev);
  82790. + if (retval != 0) {
  82791. + S3C2410X_CLEAR_EINTPEND();
  82792. + }
  82793. + return IRQ_RETVAL(retval);
  82794. +}
  82795. +
  82796. +/**
  82797. + * This function is called when a lm_device is unregistered with the
  82798. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  82799. + * executed. The device may or may not be electrically present. If it is
  82800. + * present, the driver stops device processing. Any resources used on behalf
  82801. + * of this device are freed.
  82802. + *
  82803. + * @param _dev
  82804. + */
  82805. +#ifdef LM_INTERFACE
  82806. +#define REM_RETVAL(n)
  82807. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  82808. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  82809. +#elif defined(PCI_INTERFACE)
  82810. +#define REM_RETVAL(n)
  82811. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  82812. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  82813. +#elif defined(PLATFORM_INTERFACE)
  82814. +#define REM_RETVAL(n) n
  82815. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  82816. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  82817. +#endif
  82818. +
  82819. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  82820. +
  82821. + if (!otg_dev) {
  82822. + /* Memory allocation for the dwc_otg_device failed. */
  82823. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  82824. + return REM_RETVAL(-ENOMEM);
  82825. + }
  82826. +#ifndef DWC_DEVICE_ONLY
  82827. + if (otg_dev->hcd) {
  82828. + hcd_remove(_dev);
  82829. + } else {
  82830. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  82831. + return REM_RETVAL(-EINVAL);
  82832. + }
  82833. +#endif
  82834. +
  82835. +#ifndef DWC_HOST_ONLY
  82836. + if (otg_dev->pcd) {
  82837. + pcd_remove(_dev);
  82838. + } else {
  82839. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  82840. + return REM_RETVAL(-EINVAL);
  82841. + }
  82842. +#endif
  82843. + /*
  82844. + * Free the IRQ
  82845. + */
  82846. + if (otg_dev->common_irq_installed) {
  82847. +#ifdef PLATFORM_INTERFACE
  82848. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  82849. +#else
  82850. + free_irq(_dev->irq, otg_dev);
  82851. +#endif
  82852. + } else {
  82853. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  82854. + return REM_RETVAL(-ENXIO);
  82855. + }
  82856. +
  82857. + if (otg_dev->core_if) {
  82858. + dwc_otg_cil_remove(otg_dev->core_if);
  82859. + } else {
  82860. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  82861. + return REM_RETVAL(-ENXIO);
  82862. + }
  82863. +
  82864. + /*
  82865. + * Remove the device attributes
  82866. + */
  82867. + dwc_otg_attr_remove(_dev);
  82868. +
  82869. + /*
  82870. + * Return the memory.
  82871. + */
  82872. + if (otg_dev->os_dep.base) {
  82873. + iounmap(otg_dev->os_dep.base);
  82874. + }
  82875. + DWC_FREE(otg_dev);
  82876. +
  82877. + /*
  82878. + * Clear the drvdata pointer.
  82879. + */
  82880. +#ifdef LM_INTERFACE
  82881. + lm_set_drvdata(_dev, 0);
  82882. +#elif defined(PCI_INTERFACE)
  82883. + release_mem_region(otg_dev->os_dep.rsrc_start,
  82884. + otg_dev->os_dep.rsrc_len);
  82885. + pci_set_drvdata(_dev, 0);
  82886. +#elif defined(PLATFORM_INTERFACE)
  82887. + platform_set_drvdata(_dev, 0);
  82888. +#endif
  82889. + return REM_RETVAL(0);
  82890. +}
  82891. +
  82892. +/**
  82893. + * This function is called when an lm_device is bound to a
  82894. + * dwc_otg_driver. It creates the driver components required to
  82895. + * control the device (CIL, HCD, and PCD) and it initializes the
  82896. + * device. The driver components are stored in a dwc_otg_device
  82897. + * structure. A reference to the dwc_otg_device is saved in the
  82898. + * lm_device. This allows the driver to access the dwc_otg_device
  82899. + * structure on subsequent calls to driver methods for this device.
  82900. + *
  82901. + * @param _dev Bus device
  82902. + */
  82903. +static int dwc_otg_driver_probe(
  82904. +#ifdef LM_INTERFACE
  82905. + struct lm_device *_dev
  82906. +#elif defined(PCI_INTERFACE)
  82907. + struct pci_dev *_dev,
  82908. + const struct pci_device_id *id
  82909. +#elif defined(PLATFORM_INTERFACE)
  82910. + struct platform_device *_dev
  82911. +#endif
  82912. + )
  82913. +{
  82914. + int retval = 0;
  82915. + dwc_otg_device_t *dwc_otg_device;
  82916. + int devirq;
  82917. +
  82918. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  82919. +#ifdef LM_INTERFACE
  82920. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  82921. +#elif defined(PCI_INTERFACE)
  82922. + if (!id) {
  82923. + DWC_ERROR("Invalid pci_device_id %p", id);
  82924. + return -EINVAL;
  82925. + }
  82926. +
  82927. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  82928. + DWC_ERROR("Invalid pci_device %p", _dev);
  82929. + return -ENODEV;
  82930. + }
  82931. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  82932. + /* other stuff needed as well? */
  82933. +
  82934. +#elif defined(PLATFORM_INTERFACE)
  82935. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  82936. + (unsigned)_dev->resource->start,
  82937. + (unsigned)(_dev->resource->end - _dev->resource->start));
  82938. +#endif
  82939. +
  82940. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  82941. +
  82942. + if (!dwc_otg_device) {
  82943. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  82944. + return -ENOMEM;
  82945. + }
  82946. +
  82947. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  82948. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  82949. +
  82950. + /*
  82951. + * Map the DWC_otg Core memory into virtual address space.
  82952. + */
  82953. +#ifdef LM_INTERFACE
  82954. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  82955. +
  82956. + if (!dwc_otg_device->os_dep.base) {
  82957. + dev_err(&_dev->dev, "ioremap() failed\n");
  82958. + DWC_FREE(dwc_otg_device);
  82959. + return -ENOMEM;
  82960. + }
  82961. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  82962. + (unsigned)dwc_otg_device->os_dep.base);
  82963. +#elif defined(PCI_INTERFACE)
  82964. + _dev->current_state = PCI_D0;
  82965. + _dev->dev.power.power_state = PMSG_ON;
  82966. +
  82967. + if (!_dev->irq) {
  82968. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  82969. + pci_name(_dev));
  82970. + iounmap(dwc_otg_device->os_dep.base);
  82971. + DWC_FREE(dwc_otg_device);
  82972. + return -ENODEV;
  82973. + }
  82974. +
  82975. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  82976. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  82977. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  82978. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  82979. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  82980. + if (!request_mem_region
  82981. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  82982. + "dwc_otg")) {
  82983. + dev_dbg(&_dev->dev, "error requesting memory\n");
  82984. + iounmap(dwc_otg_device->os_dep.base);
  82985. + DWC_FREE(dwc_otg_device);
  82986. + return -EFAULT;
  82987. + }
  82988. +
  82989. + dwc_otg_device->os_dep.base =
  82990. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  82991. + dwc_otg_device->os_dep.rsrc_len);
  82992. + if (dwc_otg_device->os_dep.base == NULL) {
  82993. + dev_dbg(&_dev->dev, "error mapping memory\n");
  82994. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  82995. + dwc_otg_device->os_dep.rsrc_len);
  82996. + iounmap(dwc_otg_device->os_dep.base);
  82997. + DWC_FREE(dwc_otg_device);
  82998. + return -EFAULT;
  82999. + }
  83000. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  83001. + dwc_otg_device->os_dep.base);
  83002. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  83003. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  83004. + dwc_otg_device->os_dep.base);
  83005. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  83006. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  83007. + dwc_otg_device->os_dep.base);
  83008. +
  83009. + pci_set_master(_dev);
  83010. + pci_set_drvdata(_dev, dwc_otg_device);
  83011. +#elif defined(PLATFORM_INTERFACE)
  83012. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  83013. + _dev->resource->start,
  83014. + _dev->resource->end - _dev->resource->start + 1);
  83015. +#if 1
  83016. + if (!request_mem_region(_dev->resource[0].start,
  83017. + _dev->resource[0].end - _dev->resource[0].start + 1,
  83018. + "dwc_otg")) {
  83019. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  83020. + retval = -EFAULT;
  83021. + goto fail;
  83022. + }
  83023. +
  83024. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  83025. + _dev->resource[0].end -
  83026. + _dev->resource[0].start+1);
  83027. + if (fiq_enable)
  83028. + {
  83029. + if (!request_mem_region(_dev->resource[1].start,
  83030. + _dev->resource[1].end - _dev->resource[1].start + 1,
  83031. + "dwc_otg")) {
  83032. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  83033. + retval = -EFAULT;
  83034. + goto fail;
  83035. + }
  83036. +
  83037. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  83038. + _dev->resource[1].end -
  83039. + _dev->resource[1].start + 1);
  83040. + }
  83041. +
  83042. +#else
  83043. + {
  83044. + struct map_desc desc = {
  83045. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  83046. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  83047. + .length = SZ_128K,
  83048. + .type = MT_DEVICE
  83049. + };
  83050. + iotable_init(&desc, 1);
  83051. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  83052. + }
  83053. +#endif
  83054. + if (!dwc_otg_device->os_dep.base) {
  83055. + dev_err(&_dev->dev, "ioremap() failed\n");
  83056. + retval = -ENOMEM;
  83057. + goto fail;
  83058. + }
  83059. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  83060. + (unsigned)dwc_otg_device->os_dep.base);
  83061. +#endif
  83062. +
  83063. + /*
  83064. + * Initialize driver data to point to the global DWC_otg
  83065. + * Device structure.
  83066. + */
  83067. +#ifdef LM_INTERFACE
  83068. + lm_set_drvdata(_dev, dwc_otg_device);
  83069. +#elif defined(PLATFORM_INTERFACE)
  83070. + platform_set_drvdata(_dev, dwc_otg_device);
  83071. +#endif
  83072. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  83073. +
  83074. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  83075. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  83076. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  83077. +
  83078. + if (!dwc_otg_device->core_if) {
  83079. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  83080. + retval = -ENOMEM;
  83081. + goto fail;
  83082. + }
  83083. +
  83084. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  83085. + /*
  83086. + * Attempt to ensure this device is really a DWC_otg Controller.
  83087. + * Read and verify the SNPSID register contents. The value should be
  83088. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  83089. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  83090. + */
  83091. +
  83092. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  83093. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  83094. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  83095. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  83096. + retval = -EINVAL;
  83097. + goto fail;
  83098. + }
  83099. +
  83100. + /*
  83101. + * Validate parameter values.
  83102. + */
  83103. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  83104. + if (set_parameters(dwc_otg_device->core_if)) {
  83105. + retval = -EINVAL;
  83106. + goto fail;
  83107. + }
  83108. +
  83109. + /*
  83110. + * Create Device Attributes in sysfs
  83111. + */
  83112. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  83113. + dwc_otg_attr_create(_dev);
  83114. +
  83115. + /*
  83116. + * Disable the global interrupt until all the interrupt
  83117. + * handlers are installed.
  83118. + */
  83119. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  83120. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  83121. +
  83122. + /*
  83123. + * Install the interrupt handler for the common interrupts before
  83124. + * enabling common interrupts in core_init below.
  83125. + */
  83126. +
  83127. +#if defined(PLATFORM_INTERFACE)
  83128. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  83129. +#else
  83130. + devirq = _dev->irq;
  83131. +#endif
  83132. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  83133. + devirq);
  83134. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  83135. + retval = request_irq(devirq, dwc_otg_common_irq,
  83136. + IRQF_SHARED,
  83137. + "dwc_otg", dwc_otg_device);
  83138. + if (retval) {
  83139. + DWC_ERROR("request of irq%d failed\n", devirq);
  83140. + retval = -EBUSY;
  83141. + goto fail;
  83142. + } else {
  83143. + dwc_otg_device->common_irq_installed = 1;
  83144. + }
  83145. +
  83146. +#ifndef IRQF_TRIGGER_LOW
  83147. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  83148. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  83149. + set_irq_type(devirq,
  83150. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  83151. + IRQT_LOW
  83152. +#else
  83153. + IRQ_TYPE_LEVEL_LOW
  83154. +#endif
  83155. + );
  83156. +#endif
  83157. +#endif /*IRQF_TRIGGER_LOW*/
  83158. +
  83159. + /*
  83160. + * Initialize the DWC_otg core.
  83161. + */
  83162. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  83163. + dwc_otg_core_init(dwc_otg_device->core_if);
  83164. +
  83165. +#ifndef DWC_HOST_ONLY
  83166. + /*
  83167. + * Initialize the PCD
  83168. + */
  83169. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  83170. + retval = pcd_init(_dev);
  83171. + if (retval != 0) {
  83172. + DWC_ERROR("pcd_init failed\n");
  83173. + dwc_otg_device->pcd = NULL;
  83174. + goto fail;
  83175. + }
  83176. +#endif
  83177. +#ifndef DWC_DEVICE_ONLY
  83178. + /*
  83179. + * Initialize the HCD
  83180. + */
  83181. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  83182. + retval = hcd_init(_dev);
  83183. + if (retval != 0) {
  83184. + DWC_ERROR("hcd_init failed\n");
  83185. + dwc_otg_device->hcd = NULL;
  83186. + goto fail;
  83187. + }
  83188. +#endif
  83189. + /* Recover from drvdata having been overwritten by hcd_init() */
  83190. +#ifdef LM_INTERFACE
  83191. + lm_set_drvdata(_dev, dwc_otg_device);
  83192. +#elif defined(PLATFORM_INTERFACE)
  83193. + platform_set_drvdata(_dev, dwc_otg_device);
  83194. +#elif defined(PCI_INTERFACE)
  83195. + pci_set_drvdata(_dev, dwc_otg_device);
  83196. + dwc_otg_device->os_dep.pcidev = _dev;
  83197. +#endif
  83198. +
  83199. + /*
  83200. + * Enable the global interrupt after all the interrupt
  83201. + * handlers are installed if there is no ADP support else
  83202. + * perform initial actions required for Internal ADP logic.
  83203. + */
  83204. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  83205. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  83206. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  83207. + dev_dbg(&_dev->dev, "Done\n");
  83208. + } else
  83209. + dwc_otg_adp_start(dwc_otg_device->core_if,
  83210. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  83211. +
  83212. + return 0;
  83213. +
  83214. +fail:
  83215. + dwc_otg_driver_remove(_dev);
  83216. + return retval;
  83217. +}
  83218. +
  83219. +/**
  83220. + * This structure defines the methods to be called by a bus driver
  83221. + * during the lifecycle of a device on that bus. Both drivers and
  83222. + * devices are registered with a bus driver. The bus driver matches
  83223. + * devices to drivers based on information in the device and driver
  83224. + * structures.
  83225. + *
  83226. + * The probe function is called when the bus driver matches a device
  83227. + * to this driver. The remove function is called when a device is
  83228. + * unregistered with the bus driver.
  83229. + */
  83230. +#ifdef LM_INTERFACE
  83231. +static struct lm_driver dwc_otg_driver = {
  83232. + .drv = {.name = (char *)dwc_driver_name,},
  83233. + .probe = dwc_otg_driver_probe,
  83234. + .remove = dwc_otg_driver_remove,
  83235. + // 'suspend' and 'resume' absent
  83236. +};
  83237. +#elif defined(PCI_INTERFACE)
  83238. +static const struct pci_device_id pci_ids[] = { {
  83239. + PCI_DEVICE(0x16c3, 0xabcd),
  83240. + .driver_data =
  83241. + (unsigned long)0xdeadbeef,
  83242. + }, { /* end: all zeroes */ }
  83243. +};
  83244. +
  83245. +MODULE_DEVICE_TABLE(pci, pci_ids);
  83246. +
  83247. +/* pci driver glue; this is a "new style" PCI driver module */
  83248. +static struct pci_driver dwc_otg_driver = {
  83249. + .name = "dwc_otg",
  83250. + .id_table = pci_ids,
  83251. +
  83252. + .probe = dwc_otg_driver_probe,
  83253. + .remove = dwc_otg_driver_remove,
  83254. +
  83255. + .driver = {
  83256. + .name = (char *)dwc_driver_name,
  83257. + },
  83258. +};
  83259. +#elif defined(PLATFORM_INTERFACE)
  83260. +static struct platform_device_id platform_ids[] = {
  83261. + {
  83262. + .name = "bcm2708_usb",
  83263. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  83264. + },
  83265. + { /* end: all zeroes */ }
  83266. +};
  83267. +MODULE_DEVICE_TABLE(platform, platform_ids);
  83268. +
  83269. +static struct platform_driver dwc_otg_driver = {
  83270. + .driver = {
  83271. + .name = (char *)dwc_driver_name,
  83272. + },
  83273. + .id_table = platform_ids,
  83274. +
  83275. + .probe = dwc_otg_driver_probe,
  83276. + .remove = dwc_otg_driver_remove,
  83277. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  83278. +};
  83279. +#endif
  83280. +
  83281. +/**
  83282. + * This function is called when the dwc_otg_driver is installed with the
  83283. + * insmod command. It registers the dwc_otg_driver structure with the
  83284. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  83285. + * to be called. In addition, the bus driver will automatically expose
  83286. + * attributes defined for the device and driver in the special sysfs file
  83287. + * system.
  83288. + *
  83289. + * @return
  83290. + */
  83291. +static int __init dwc_otg_driver_init(void)
  83292. +{
  83293. + int retval = 0;
  83294. + int error;
  83295. + struct device_driver *drv;
  83296. +
  83297. + if(fiq_fsm_enable && !fiq_enable) {
  83298. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  83299. + fiq_enable = 1;
  83300. + }
  83301. +
  83302. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  83303. + DWC_DRIVER_VERSION,
  83304. +#ifdef LM_INTERFACE
  83305. + "logicmodule");
  83306. + retval = lm_driver_register(&dwc_otg_driver);
  83307. + drv = &dwc_otg_driver.drv;
  83308. +#elif defined(PCI_INTERFACE)
  83309. + "pci");
  83310. + retval = pci_register_driver(&dwc_otg_driver);
  83311. + drv = &dwc_otg_driver.driver;
  83312. +#elif defined(PLATFORM_INTERFACE)
  83313. + "platform");
  83314. + retval = platform_driver_register(&dwc_otg_driver);
  83315. + drv = &dwc_otg_driver.driver;
  83316. +#endif
  83317. + if (retval < 0) {
  83318. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  83319. + return retval;
  83320. + }
  83321. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  83322. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  83323. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  83324. +
  83325. + error = driver_create_file(drv, &driver_attr_version);
  83326. +#ifdef DEBUG
  83327. + error = driver_create_file(drv, &driver_attr_debuglevel);
  83328. +#endif
  83329. + return retval;
  83330. +}
  83331. +
  83332. +module_init(dwc_otg_driver_init);
  83333. +
  83334. +/**
  83335. + * This function is called when the driver is removed from the kernel
  83336. + * with the rmmod command. The driver unregisters itself with its bus
  83337. + * driver.
  83338. + *
  83339. + */
  83340. +static void __exit dwc_otg_driver_cleanup(void)
  83341. +{
  83342. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  83343. +
  83344. +#ifdef LM_INTERFACE
  83345. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  83346. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  83347. + lm_driver_unregister(&dwc_otg_driver);
  83348. +#elif defined(PCI_INTERFACE)
  83349. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  83350. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  83351. + pci_unregister_driver(&dwc_otg_driver);
  83352. +#elif defined(PLATFORM_INTERFACE)
  83353. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  83354. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  83355. + platform_driver_unregister(&dwc_otg_driver);
  83356. +#endif
  83357. +
  83358. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  83359. +}
  83360. +
  83361. +module_exit(dwc_otg_driver_cleanup);
  83362. +
  83363. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  83364. +MODULE_AUTHOR("Synopsys Inc.");
  83365. +MODULE_LICENSE("GPL");
  83366. +
  83367. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  83368. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  83369. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  83370. +MODULE_PARM_DESC(opt, "OPT Mode");
  83371. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  83372. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  83373. +
  83374. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  83375. + 0444);
  83376. +MODULE_PARM_DESC(dma_desc_enable,
  83377. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  83378. +
  83379. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  83380. + 0444);
  83381. +MODULE_PARM_DESC(dma_burst_size,
  83382. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  83383. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  83384. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  83385. +module_param_named(host_support_fs_ls_low_power,
  83386. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  83387. + 0444);
  83388. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  83389. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  83390. +module_param_named(host_ls_low_power_phy_clk,
  83391. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  83392. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  83393. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  83394. +module_param_named(enable_dynamic_fifo,
  83395. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  83396. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  83397. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  83398. + 0444);
  83399. +MODULE_PARM_DESC(data_fifo_size,
  83400. + "Total number of words in the data FIFO memory 32-32768");
  83401. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  83402. + int, 0444);
  83403. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  83404. +module_param_named(dev_nperio_tx_fifo_size,
  83405. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  83406. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  83407. + "Number of words in the non-periodic Tx FIFO 16-32768");
  83408. +module_param_named(dev_perio_tx_fifo_size_1,
  83409. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  83410. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  83411. + "Number of words in the periodic Tx FIFO 4-768");
  83412. +module_param_named(dev_perio_tx_fifo_size_2,
  83413. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  83414. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  83415. + "Number of words in the periodic Tx FIFO 4-768");
  83416. +module_param_named(dev_perio_tx_fifo_size_3,
  83417. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  83418. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  83419. + "Number of words in the periodic Tx FIFO 4-768");
  83420. +module_param_named(dev_perio_tx_fifo_size_4,
  83421. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  83422. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  83423. + "Number of words in the periodic Tx FIFO 4-768");
  83424. +module_param_named(dev_perio_tx_fifo_size_5,
  83425. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  83426. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  83427. + "Number of words in the periodic Tx FIFO 4-768");
  83428. +module_param_named(dev_perio_tx_fifo_size_6,
  83429. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  83430. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  83431. + "Number of words in the periodic Tx FIFO 4-768");
  83432. +module_param_named(dev_perio_tx_fifo_size_7,
  83433. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  83434. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  83435. + "Number of words in the periodic Tx FIFO 4-768");
  83436. +module_param_named(dev_perio_tx_fifo_size_8,
  83437. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  83438. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  83439. + "Number of words in the periodic Tx FIFO 4-768");
  83440. +module_param_named(dev_perio_tx_fifo_size_9,
  83441. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  83442. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  83443. + "Number of words in the periodic Tx FIFO 4-768");
  83444. +module_param_named(dev_perio_tx_fifo_size_10,
  83445. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  83446. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  83447. + "Number of words in the periodic Tx FIFO 4-768");
  83448. +module_param_named(dev_perio_tx_fifo_size_11,
  83449. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  83450. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  83451. + "Number of words in the periodic Tx FIFO 4-768");
  83452. +module_param_named(dev_perio_tx_fifo_size_12,
  83453. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  83454. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  83455. + "Number of words in the periodic Tx FIFO 4-768");
  83456. +module_param_named(dev_perio_tx_fifo_size_13,
  83457. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  83458. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  83459. + "Number of words in the periodic Tx FIFO 4-768");
  83460. +module_param_named(dev_perio_tx_fifo_size_14,
  83461. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  83462. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  83463. + "Number of words in the periodic Tx FIFO 4-768");
  83464. +module_param_named(dev_perio_tx_fifo_size_15,
  83465. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  83466. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  83467. + "Number of words in the periodic Tx FIFO 4-768");
  83468. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  83469. + int, 0444);
  83470. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  83471. +module_param_named(host_nperio_tx_fifo_size,
  83472. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  83473. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  83474. + "Number of words in the non-periodic Tx FIFO 16-32768");
  83475. +module_param_named(host_perio_tx_fifo_size,
  83476. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  83477. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  83478. + "Number of words in the host periodic Tx FIFO 16-32768");
  83479. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  83480. + int, 0444);
  83481. +/** @todo Set the max to 512K, modify checks */
  83482. +MODULE_PARM_DESC(max_transfer_size,
  83483. + "The maximum transfer size supported in bytes 2047-65535");
  83484. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  83485. + int, 0444);
  83486. +MODULE_PARM_DESC(max_packet_count,
  83487. + "The maximum number of packets in a transfer 15-511");
  83488. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  83489. + 0444);
  83490. +MODULE_PARM_DESC(host_channels,
  83491. + "The number of host channel registers to use 1-16");
  83492. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  83493. + 0444);
  83494. +MODULE_PARM_DESC(dev_endpoints,
  83495. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  83496. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  83497. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  83498. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  83499. + 0444);
  83500. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  83501. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  83502. +MODULE_PARM_DESC(phy_ulpi_ddr,
  83503. + "ULPI at double or single data rate 0=Single 1=Double");
  83504. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  83505. + int, 0444);
  83506. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  83507. + "ULPI PHY using internal or external vbus 0=Internal");
  83508. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  83509. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  83510. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  83511. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  83512. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  83513. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  83514. +module_param_named(debug, g_dbg_lvl, int, 0444);
  83515. +MODULE_PARM_DESC(debug, "");
  83516. +
  83517. +module_param_named(en_multiple_tx_fifo,
  83518. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  83519. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  83520. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  83521. +module_param_named(dev_tx_fifo_size_1,
  83522. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  83523. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  83524. +module_param_named(dev_tx_fifo_size_2,
  83525. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  83526. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  83527. +module_param_named(dev_tx_fifo_size_3,
  83528. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  83529. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  83530. +module_param_named(dev_tx_fifo_size_4,
  83531. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  83532. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  83533. +module_param_named(dev_tx_fifo_size_5,
  83534. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  83535. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  83536. +module_param_named(dev_tx_fifo_size_6,
  83537. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  83538. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  83539. +module_param_named(dev_tx_fifo_size_7,
  83540. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  83541. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  83542. +module_param_named(dev_tx_fifo_size_8,
  83543. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  83544. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  83545. +module_param_named(dev_tx_fifo_size_9,
  83546. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  83547. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  83548. +module_param_named(dev_tx_fifo_size_10,
  83549. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  83550. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  83551. +module_param_named(dev_tx_fifo_size_11,
  83552. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  83553. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  83554. +module_param_named(dev_tx_fifo_size_12,
  83555. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  83556. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  83557. +module_param_named(dev_tx_fifo_size_13,
  83558. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  83559. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  83560. +module_param_named(dev_tx_fifo_size_14,
  83561. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  83562. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  83563. +module_param_named(dev_tx_fifo_size_15,
  83564. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  83565. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  83566. +
  83567. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  83568. +MODULE_PARM_DESC(thr_ctl,
  83569. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  83570. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  83571. + 0444);
  83572. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  83573. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  83574. + 0444);
  83575. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  83576. +
  83577. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  83578. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  83579. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  83580. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  83581. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  83582. +MODULE_PARM_DESC(ic_usb_cap,
  83583. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  83584. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  83585. + 0444);
  83586. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  83587. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  83588. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  83589. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  83590. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  83591. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  83592. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  83593. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  83594. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  83595. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  83596. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  83597. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  83598. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  83599. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  83600. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  83601. +module_param(microframe_schedule, bool, 0444);
  83602. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  83603. +
  83604. +module_param(fiq_enable, bool, 0444);
  83605. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  83606. +module_param(nak_holdoff, ushort, 0644);
  83607. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  83608. +module_param(fiq_fsm_enable, bool, 0444);
  83609. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  83610. +module_param(fiq_fsm_mask, ushort, 0444);
  83611. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  83612. + "Bit 0 : Non-periodic split transactions\n"
  83613. + "Bit 1 : Periodic split transactions\n"
  83614. + "Bit 2 : High-speed multi-transfer isochronous\n"
  83615. + "All other bits should be set 0.");
  83616. +
  83617. +
  83618. +/** @page "Module Parameters"
  83619. + *
  83620. + * The following parameters may be specified when starting the module.
  83621. + * These parameters define how the DWC_otg controller should be
  83622. + * configured. Parameter values are passed to the CIL initialization
  83623. + * function dwc_otg_cil_init
  83624. + *
  83625. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  83626. + *
  83627. +
  83628. + <table>
  83629. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  83630. +
  83631. + <tr>
  83632. + <td>otg_cap</td>
  83633. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  83634. + value for this parameter if none is specified.
  83635. + - 0: HNP and SRP capable (default, if available)
  83636. + - 1: SRP Only capable
  83637. + - 2: No HNP/SRP capable
  83638. + </td></tr>
  83639. +
  83640. + <tr>
  83641. + <td>dma_enable</td>
  83642. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  83643. + The driver will automatically detect the value for this parameter if none is
  83644. + specified.
  83645. + - 0: Slave
  83646. + - 1: DMA (default, if available)
  83647. + </td></tr>
  83648. +
  83649. + <tr>
  83650. + <td>dma_burst_size</td>
  83651. + <td>The DMA Burst size (applicable only for External DMA Mode).
  83652. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  83653. + </td></tr>
  83654. +
  83655. + <tr>
  83656. + <td>speed</td>
  83657. + <td>Specifies the maximum speed of operation in host and device mode. The
  83658. + actual speed depends on the speed of the attached device and the value of
  83659. + phy_type.
  83660. + - 0: High Speed (default)
  83661. + - 1: Full Speed
  83662. + </td></tr>
  83663. +
  83664. + <tr>
  83665. + <td>host_support_fs_ls_low_power</td>
  83666. + <td>Specifies whether low power mode is supported when attached to a Full
  83667. + Speed or Low Speed device in host mode.
  83668. + - 0: Don't support low power mode (default)
  83669. + - 1: Support low power mode
  83670. + </td></tr>
  83671. +
  83672. + <tr>
  83673. + <td>host_ls_low_power_phy_clk</td>
  83674. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  83675. + Speed device in host mode. This parameter is applicable only if
  83676. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  83677. + - 0: 48 MHz (default)
  83678. + - 1: 6 MHz
  83679. + </td></tr>
  83680. +
  83681. + <tr>
  83682. + <td>enable_dynamic_fifo</td>
  83683. + <td> Specifies whether FIFOs may be resized by the driver software.
  83684. + - 0: Use cC FIFO size parameters
  83685. + - 1: Allow dynamic FIFO sizing (default)
  83686. + </td></tr>
  83687. +
  83688. + <tr>
  83689. + <td>data_fifo_size</td>
  83690. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  83691. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  83692. + - Values: 32 to 32768 (default 8192)
  83693. +
  83694. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  83695. + </td></tr>
  83696. +
  83697. + <tr>
  83698. + <td>dev_rx_fifo_size</td>
  83699. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  83700. + FIFO sizing is enabled.
  83701. + - Values: 16 to 32768 (default 1064)
  83702. + </td></tr>
  83703. +
  83704. + <tr>
  83705. + <td>dev_nperio_tx_fifo_size</td>
  83706. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  83707. + dynamic FIFO sizing is enabled.
  83708. + - Values: 16 to 32768 (default 1024)
  83709. + </td></tr>
  83710. +
  83711. + <tr>
  83712. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  83713. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  83714. + when dynamic FIFO sizing is enabled.
  83715. + - Values: 4 to 768 (default 256)
  83716. + </td></tr>
  83717. +
  83718. + <tr>
  83719. + <td>host_rx_fifo_size</td>
  83720. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  83721. + sizing is enabled.
  83722. + - Values: 16 to 32768 (default 1024)
  83723. + </td></tr>
  83724. +
  83725. + <tr>
  83726. + <td>host_nperio_tx_fifo_size</td>
  83727. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  83728. + dynamic FIFO sizing is enabled in the core.
  83729. + - Values: 16 to 32768 (default 1024)
  83730. + </td></tr>
  83731. +
  83732. + <tr>
  83733. + <td>host_perio_tx_fifo_size</td>
  83734. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  83735. + sizing is enabled.
  83736. + - Values: 16 to 32768 (default 1024)
  83737. + </td></tr>
  83738. +
  83739. + <tr>
  83740. + <td>max_transfer_size</td>
  83741. + <td>The maximum transfer size supported in bytes.
  83742. + - Values: 2047 to 65,535 (default 65,535)
  83743. + </td></tr>
  83744. +
  83745. + <tr>
  83746. + <td>max_packet_count</td>
  83747. + <td>The maximum number of packets in a transfer.
  83748. + - Values: 15 to 511 (default 511)
  83749. + </td></tr>
  83750. +
  83751. + <tr>
  83752. + <td>host_channels</td>
  83753. + <td>The number of host channel registers to use.
  83754. + - Values: 1 to 16 (default 12)
  83755. +
  83756. + Note: The FPGA configuration supports a maximum of 12 host channels.
  83757. + </td></tr>
  83758. +
  83759. + <tr>
  83760. + <td>dev_endpoints</td>
  83761. + <td>The number of endpoints in addition to EP0 available for device mode
  83762. + operations.
  83763. + - Values: 1 to 15 (default 6 IN and OUT)
  83764. +
  83765. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  83766. + addition to EP0.
  83767. + </td></tr>
  83768. +
  83769. + <tr>
  83770. + <td>phy_type</td>
  83771. + <td>Specifies the type of PHY interface to use. By default, the driver will
  83772. + automatically detect the phy_type.
  83773. + - 0: Full Speed
  83774. + - 1: UTMI+ (default, if available)
  83775. + - 2: ULPI
  83776. + </td></tr>
  83777. +
  83778. + <tr>
  83779. + <td>phy_utmi_width</td>
  83780. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  83781. + phy_type of UTMI+. Also, this parameter is applicable only if the
  83782. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  83783. + core has been configured to work at either data path width.
  83784. + - Values: 8 or 16 bits (default 16)
  83785. + </td></tr>
  83786. +
  83787. + <tr>
  83788. + <td>phy_ulpi_ddr</td>
  83789. + <td>Specifies whether the ULPI operates at double or single data rate. This
  83790. + parameter is only applicable if phy_type is ULPI.
  83791. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  83792. + - 1: double data rate ULPI interface with 4 bit wide data bus
  83793. + </td></tr>
  83794. +
  83795. + <tr>
  83796. + <td>i2c_enable</td>
  83797. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  83798. + parameter is only applicable if PHY_TYPE is FS.
  83799. + - 0: Disabled (default)
  83800. + - 1: Enabled
  83801. + </td></tr>
  83802. +
  83803. + <tr>
  83804. + <td>ulpi_fs_ls</td>
  83805. + <td>Specifies whether to use ULPI FS/LS mode only.
  83806. + - 0: Disabled (default)
  83807. + - 1: Enabled
  83808. + </td></tr>
  83809. +
  83810. + <tr>
  83811. + <td>ts_dline</td>
  83812. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  83813. + - 0: Disabled (default)
  83814. + - 1: Enabled
  83815. + </td></tr>
  83816. +
  83817. + <tr>
  83818. + <td>en_multiple_tx_fifo</td>
  83819. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  83820. + The driver will automatically detect the value for this parameter if none is
  83821. + specified.
  83822. + - 0: Disabled
  83823. + - 1: Enabled (default, if available)
  83824. + </td></tr>
  83825. +
  83826. + <tr>
  83827. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  83828. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  83829. + when dynamic FIFO sizing is enabled.
  83830. + - Values: 4 to 768 (default 256)
  83831. + </td></tr>
  83832. +
  83833. + <tr>
  83834. + <td>tx_thr_length</td>
  83835. + <td>Transmit Threshold length in 32 bit double words
  83836. + - Values: 8 to 128 (default 64)
  83837. + </td></tr>
  83838. +
  83839. + <tr>
  83840. + <td>rx_thr_length</td>
  83841. + <td>Receive Threshold length in 32 bit double words
  83842. + - Values: 8 to 128 (default 64)
  83843. + </td></tr>
  83844. +
  83845. +<tr>
  83846. + <td>thr_ctl</td>
  83847. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  83848. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  83849. + Rx transfers accordingly.
  83850. + The driver will automatically detect the value for this parameter if none is
  83851. + specified.
  83852. + - Values: 0 to 7 (default 0)
  83853. + Bit values indicate:
  83854. + - 0: Thresholding disabled
  83855. + - 1: Thresholding enabled
  83856. + </td></tr>
  83857. +
  83858. +<tr>
  83859. + <td>dma_desc_enable</td>
  83860. + <td>Specifies whether to enable Descriptor DMA mode.
  83861. + The driver will automatically detect the value for this parameter if none is
  83862. + specified.
  83863. + - 0: Descriptor DMA disabled
  83864. + - 1: Descriptor DMA (default, if available)
  83865. + </td></tr>
  83866. +
  83867. +<tr>
  83868. + <td>mpi_enable</td>
  83869. + <td>Specifies whether to enable MPI enhancement mode.
  83870. + The driver will automatically detect the value for this parameter if none is
  83871. + specified.
  83872. + - 0: MPI disabled (default)
  83873. + - 1: MPI enable
  83874. + </td></tr>
  83875. +
  83876. +<tr>
  83877. + <td>pti_enable</td>
  83878. + <td>Specifies whether to enable PTI enhancement support.
  83879. + The driver will automatically detect the value for this parameter if none is
  83880. + specified.
  83881. + - 0: PTI disabled (default)
  83882. + - 1: PTI enable
  83883. + </td></tr>
  83884. +
  83885. +<tr>
  83886. + <td>lpm_enable</td>
  83887. + <td>Specifies whether to enable LPM support.
  83888. + The driver will automatically detect the value for this parameter if none is
  83889. + specified.
  83890. + - 0: LPM disabled
  83891. + - 1: LPM enable (default, if available)
  83892. + </td></tr>
  83893. +
  83894. +<tr>
  83895. + <td>ic_usb_cap</td>
  83896. + <td>Specifies whether to enable IC_USB capability.
  83897. + The driver will automatically detect the value for this parameter if none is
  83898. + specified.
  83899. + - 0: IC_USB disabled (default, if available)
  83900. + - 1: IC_USB enable
  83901. + </td></tr>
  83902. +
  83903. +<tr>
  83904. + <td>ahb_thr_ratio</td>
  83905. + <td>Specifies AHB Threshold ratio.
  83906. + - Values: 0 to 3 (default 0)
  83907. + </td></tr>
  83908. +
  83909. +<tr>
  83910. + <td>power_down</td>
  83911. + <td>Specifies Power Down(Hibernation) Mode.
  83912. + The driver will automatically detect the value for this parameter if none is
  83913. + specified.
  83914. + - 0: Power Down disabled (default)
  83915. + - 2: Power Down enabled
  83916. + </td></tr>
  83917. +
  83918. + <tr>
  83919. + <td>reload_ctl</td>
  83920. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  83921. + run time. The driver will automatically detect the value for this parameter if
  83922. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  83923. + the core might misbehave.
  83924. + - 0: Reload Control disabled (default)
  83925. + - 1: Reload Control enabled
  83926. + </td></tr>
  83927. +
  83928. + <tr>
  83929. + <td>dev_out_nak</td>
  83930. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  83931. + The driver will automatically detect the value for this parameter if
  83932. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  83933. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  83934. + - 1: The core sets NAK after Bulk OUT transfer complete
  83935. + </td></tr>
  83936. +
  83937. + <tr>
  83938. + <td>cont_on_bna</td>
  83939. + <td>Specifies whether Enable Continue on BNA enabled or no.
  83940. + After receiving BNA interrupt the core disables the endpoint,when the
  83941. + endpoint is re-enabled by the application the
  83942. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  83943. + - 1: Core starts processing from the descriptor which received the BNA.
  83944. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  83945. + </td></tr>
  83946. +
  83947. + <tr>
  83948. + <td>ahb_single</td>
  83949. + <td>This bit when programmed supports SINGLE transfers for remainder data
  83950. + in a transfer for DMA mode of operation.
  83951. + - 0: The remainder data will be sent using INCR burst size (default)
  83952. + - 1: The remainder data will be sent using SINGLE burst size.
  83953. + </td></tr>
  83954. +
  83955. +<tr>
  83956. + <td>adp_enable</td>
  83957. + <td>Specifies whether ADP feature is enabled.
  83958. + The driver will automatically detect the value for this parameter if none is
  83959. + specified.
  83960. + - 0: ADP feature disabled (default)
  83961. + - 1: ADP feature enabled
  83962. + </td></tr>
  83963. +
  83964. + <tr>
  83965. + <td>otg_ver</td>
  83966. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  83967. + USB OTG device.
  83968. + - 0: OTG 2.0 support disabled (default)
  83969. + - 1: OTG 2.0 support enabled
  83970. + </td></tr>
  83971. +
  83972. +*/
  83973. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  83974. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  83975. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2015-03-09 10:39:33.218893718 +0100
  83976. @@ -0,0 +1,86 @@
  83977. +/* ==========================================================================
  83978. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  83979. + * $Revision: #19 $
  83980. + * $Date: 2010/11/15 $
  83981. + * $Change: 1627671 $
  83982. + *
  83983. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  83984. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  83985. + * otherwise expressly agreed to in writing between Synopsys and you.
  83986. + *
  83987. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  83988. + * any End User Software License Agreement or Agreement for Licensed Product
  83989. + * with Synopsys or any supplement thereto. You are permitted to use and
  83990. + * redistribute this Software in source and binary forms, with or without
  83991. + * modification, provided that redistributions of source code must retain this
  83992. + * notice. You may not view, use, disclose, copy or distribute this file or
  83993. + * any information contained herein except pursuant to this license grant from
  83994. + * Synopsys. If you do not agree with this notice, including the disclaimer
  83995. + * below, then you are not authorized to use the Software.
  83996. + *
  83997. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  83998. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  83999. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84000. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84001. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84002. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84003. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84004. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84005. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84006. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84007. + * DAMAGE.
  84008. + * ========================================================================== */
  84009. +
  84010. +#ifndef __DWC_OTG_DRIVER_H__
  84011. +#define __DWC_OTG_DRIVER_H__
  84012. +
  84013. +/** @file
  84014. + * This file contains the interface to the Linux driver.
  84015. + */
  84016. +#include "dwc_otg_os_dep.h"
  84017. +#include "dwc_otg_core_if.h"
  84018. +
  84019. +/* Type declarations */
  84020. +struct dwc_otg_pcd;
  84021. +struct dwc_otg_hcd;
  84022. +
  84023. +/**
  84024. + * This structure is a wrapper that encapsulates the driver components used to
  84025. + * manage a single DWC_otg controller.
  84026. + */
  84027. +typedef struct dwc_otg_device {
  84028. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  84029. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  84030. + * require this. */
  84031. + struct os_dependent os_dep;
  84032. +
  84033. + /** Pointer to the core interface structure. */
  84034. + dwc_otg_core_if_t *core_if;
  84035. +
  84036. + /** Pointer to the PCD structure. */
  84037. + struct dwc_otg_pcd *pcd;
  84038. +
  84039. + /** Pointer to the HCD structure. */
  84040. + struct dwc_otg_hcd *hcd;
  84041. +
  84042. + /** Flag to indicate whether the common IRQ handler is installed. */
  84043. + uint8_t common_irq_installed;
  84044. +
  84045. +} dwc_otg_device_t;
  84046. +
  84047. +/*We must clear S3C24XX_EINTPEND external interrupt register
  84048. + * because after clearing in this register trigerred IRQ from
  84049. + * H/W core in kernel interrupt can be occured again before OTG
  84050. + * handlers clear all IRQ sources of Core registers because of
  84051. + * timing latencies and Low Level IRQ Type.
  84052. + */
  84053. +#ifdef CONFIG_MACH_IPMATE
  84054. +#define S3C2410X_CLEAR_EINTPEND() \
  84055. +do { \
  84056. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  84057. +} while (0)
  84058. +#else
  84059. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  84060. +#endif
  84061. +
  84062. +#endif
  84063. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  84064. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  84065. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2015-03-10 17:26:51.302216687 +0100
  84066. @@ -0,0 +1,1294 @@
  84067. +/*
  84068. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  84069. + *
  84070. + * Copyright (c) 2013 Raspberry Pi Foundation
  84071. + *
  84072. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  84073. + * All rights reserved.
  84074. + *
  84075. + * Redistribution and use in source and binary forms, with or without
  84076. + * modification, are permitted provided that the following conditions are met:
  84077. + * * Redistributions of source code must retain the above copyright
  84078. + * notice, this list of conditions and the following disclaimer.
  84079. + * * Redistributions in binary form must reproduce the above copyright
  84080. + * notice, this list of conditions and the following disclaimer in the
  84081. + * documentation and/or other materials provided with the distribution.
  84082. + * * Neither the name of Raspberry Pi nor the
  84083. + * names of its contributors may be used to endorse or promote products
  84084. + * derived from this software without specific prior written permission.
  84085. + *
  84086. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  84087. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  84088. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  84089. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  84090. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84091. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  84092. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  84093. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  84094. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  84095. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  84096. + *
  84097. + * This FIQ implements functionality that performs split transactions on
  84098. + * the dwc_otg hardware without any outside intervention. A split transaction
  84099. + * is "queued" by nominating a specific host channel to perform the entirety
  84100. + * of a split transaction. This FIQ will then perform the microframe-precise
  84101. + * scheduling required in each phase of the transaction until completion.
  84102. + *
  84103. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  84104. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  84105. + * for a FSM-enabled channel.
  84106. + *
  84107. + * NB: Large parts of this implementation have architecture-specific code.
  84108. + * For porting this functionality to other ARM machines, the minimum is required:
  84109. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  84110. + * to the FIQ
  84111. + * - A method of forcing a software generated interrupt from FIQ mode that then
  84112. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  84113. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  84114. + * processor core - there is no locking between the FIQ and IRQ (aside from
  84115. + * local_fiq_disable)
  84116. + *
  84117. + */
  84118. +
  84119. +#include "dwc_otg_fiq_fsm.h"
  84120. +
  84121. +
  84122. +char buffer[1000*16];
  84123. +int wptr;
  84124. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  84125. +{
  84126. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  84127. + va_list args;
  84128. + char text[17];
  84129. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  84130. +
  84131. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  84132. + {
  84133. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  84134. + va_start(args, fmt);
  84135. + vsnprintf(text+8, 9, fmt, args);
  84136. + va_end(args);
  84137. +
  84138. + memcpy(buffer + wptr, text, 16);
  84139. + wptr = (wptr + 16) % sizeof(buffer);
  84140. + }
  84141. +}
  84142. +
  84143. +/**
  84144. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  84145. + * @channel: channel to re-enable
  84146. + */
  84147. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  84148. +{
  84149. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  84150. +
  84151. + hcchar.b.chen = 0;
  84152. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  84153. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  84154. + /* Hardware bug workaround: update the ssplit index */
  84155. + if (st->channel[n].hcsplt_copy.b.spltena)
  84156. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  84157. +
  84158. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  84159. + }
  84160. +
  84161. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  84162. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84163. + hcchar.b.chen = 1;
  84164. +
  84165. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  84166. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  84167. +}
  84168. +
  84169. +/**
  84170. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  84171. + * @st: Pointer to the channel's state
  84172. + * @n : channel number
  84173. + *
  84174. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  84175. + * endpoint direction, set control regs up correctly.
  84176. + */
  84177. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  84178. +{
  84179. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  84180. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  84181. +
  84182. + hcsplt.b.compsplt = 1;
  84183. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  84184. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  84185. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  84186. + } else {
  84187. + // If OUT, the CSPLIT result contains handshake only.
  84188. + hctsiz.b.xfersize = 0;
  84189. + }
  84190. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  84191. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  84192. + mb();
  84193. +}
  84194. +
  84195. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  84196. +{
  84197. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  84198. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  84199. +
  84200. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  84201. + return st->channel[n].hctsiz_copy.b.xfersize;
  84202. + } else {
  84203. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  84204. + }
  84205. +
  84206. +}
  84207. +
  84208. +
  84209. +/**
  84210. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  84211. + *
  84212. + * Of use only for IN periodic transfers.
  84213. + */
  84214. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  84215. +{
  84216. + hcdma_data_t hcdma;
  84217. + int i = st->channel[n].dma_info.index;
  84218. + int len;
  84219. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  84220. +
  84221. + len = fiq_get_xfer_len(st, n);
  84222. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  84223. + st->channel[n].dma_info.slot_len[i] = len;
  84224. + i++;
  84225. + if (i > 6)
  84226. + BUG();
  84227. +
  84228. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  84229. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  84230. + st->channel[n].dma_info.index = i;
  84231. + return 0;
  84232. +}
  84233. +
  84234. +/**
  84235. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  84236. + */
  84237. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  84238. +{
  84239. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  84240. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  84241. + hctsiz.b.pktcnt = 1;
  84242. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  84243. +}
  84244. +
  84245. +/**
  84246. + * fiq_iso_out_advance() - update DMA address and split position bits
  84247. + * for isochronous OUT transactions.
  84248. + *
  84249. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  84250. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  84251. + *
  84252. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  84253. + */
  84254. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  84255. +{
  84256. + hcsplt_data_t hcsplt;
  84257. + hctsiz_data_t hctsiz;
  84258. + hcdma_data_t hcdma;
  84259. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  84260. + int last = 0;
  84261. + int i = st->channel[n].dma_info.index;
  84262. +
  84263. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  84264. + i++;
  84265. + if (i == 4)
  84266. + last = 1;
  84267. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  84268. + last = 1;
  84269. +
  84270. + /* New DMA address - address of bounce buffer referred to in index */
  84271. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  84272. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  84273. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  84274. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  84275. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  84276. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  84277. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  84278. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  84279. + /* Set up new packet length */
  84280. + hctsiz.b.pktcnt = 1;
  84281. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  84282. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  84283. +
  84284. + st->channel[n].dma_info.index++;
  84285. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  84286. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  84287. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  84288. + return last;
  84289. +}
  84290. +
  84291. +/**
  84292. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  84293. + *
  84294. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  84295. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  84296. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  84297. + * is very unlikely that filling the start-split FIFO will cause data loss.
  84298. + * This allows much better interleaving of transactions in an order-independent way-
  84299. + * there is no requirement to prioritise isochronous, just a state-space search has
  84300. + * to be performed on each periodic start-split complete interrupt.
  84301. + */
  84302. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  84303. +{
  84304. + int hub_addr = st->channel[n].hub_addr;
  84305. + int port_addr = st->channel[n].port_addr;
  84306. + int i, poked = 0;
  84307. + for (i = 0; i < num_channels; i++) {
  84308. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  84309. + continue;
  84310. + if (st->channel[i].hub_addr == hub_addr &&
  84311. + st->channel[i].port_addr == port_addr) {
  84312. + switch (st->channel[i].fsm) {
  84313. + case FIQ_PER_ISO_OUT_PENDING:
  84314. + if (st->channel[i].nrpackets == 1) {
  84315. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  84316. + } else {
  84317. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  84318. + }
  84319. + fiq_fsm_restart_channel(st, i, 0);
  84320. + poked = 1;
  84321. + break;
  84322. +
  84323. + default:
  84324. + break;
  84325. + }
  84326. + }
  84327. + if (poked)
  84328. + break;
  84329. + }
  84330. + return poked;
  84331. +}
  84332. +
  84333. +/**
  84334. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  84335. + * @n: Channel to use as reference
  84336. + *
  84337. + */
  84338. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  84339. +{
  84340. + int hub_addr = st->channel[n].hub_addr;
  84341. + int port_addr = st->channel[n].port_addr;
  84342. + int i, in_use = 0;
  84343. + for (i = 0; i < num_channels; i++) {
  84344. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  84345. + continue;
  84346. + switch (st->channel[i].fsm) {
  84347. + /* TT is reserved for channels that are in the middle of a periodic
  84348. + * split transaction.
  84349. + */
  84350. + case FIQ_PER_SSPLIT_STARTED:
  84351. + case FIQ_PER_CSPLIT_WAIT:
  84352. + case FIQ_PER_CSPLIT_NYET1:
  84353. + //case FIQ_PER_CSPLIT_POLL:
  84354. + case FIQ_PER_ISO_OUT_ACTIVE:
  84355. + case FIQ_PER_ISO_OUT_LAST:
  84356. + if (st->channel[i].hub_addr == hub_addr &&
  84357. + st->channel[i].port_addr == port_addr) {
  84358. + in_use = 1;
  84359. + }
  84360. + break;
  84361. + default:
  84362. + break;
  84363. + }
  84364. + if (in_use)
  84365. + break;
  84366. + }
  84367. + return in_use;
  84368. +}
  84369. +
  84370. +/**
  84371. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  84372. + * to be issued for this IN transaction.
  84373. + *
  84374. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  84375. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  84376. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  84377. + * size, but for endpoints that give variable-length data then we have to resort
  84378. + * to heuristics.
  84379. + *
  84380. + * We also return whether this is the last CSPLIT to be queued, again based on
  84381. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  84382. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  84383. + */
  84384. +
  84385. +/*
  84386. + * We need some way of guaranteeing if a returned periodic packet of size X
  84387. + * has a DATA0 PID.
  84388. + * The heuristic value of 144 bytes assumes that the received data has maximal
  84389. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  84390. + * permissible limit. If the transfer length results in a final packet size
  84391. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  84392. + * Also used to ensure that an endpoint will nominally only return a single
  84393. + * complete-split worth of data.
  84394. + */
  84395. +#define DATA0_PID_HEURISTIC 144
  84396. +
  84397. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  84398. +{
  84399. +
  84400. + int i;
  84401. + int total_len = 0;
  84402. + int more_needed = 1;
  84403. + struct fiq_channel_state *st = &state->channel[n];
  84404. +
  84405. + for (i = 0; i < st->dma_info.index; i++) {
  84406. + total_len += st->dma_info.slot_len[i];
  84407. + }
  84408. +
  84409. + *probably_last = 0;
  84410. +
  84411. + if (st->hcchar_copy.b.eptype == 0x3) {
  84412. + /*
  84413. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  84414. + * then this is definitely the last CSPLIT.
  84415. + */
  84416. + *probably_last = 1;
  84417. + } else {
  84418. + /* Isoc IN. This is a bit risky if we are the first transaction:
  84419. + * we may have been held off slightly. */
  84420. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  84421. + more_needed = 0;
  84422. + }
  84423. + /* If in the next uframe we will receive enough data to fill the endpoint,
  84424. + * then only issue 1 more csplit.
  84425. + */
  84426. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  84427. + *probably_last = 1;
  84428. + }
  84429. +
  84430. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  84431. + i == 6 || total_len == 0)
  84432. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  84433. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  84434. + * - in these extreme cases we will pass through a truncated packet.
  84435. + */
  84436. + more_needed = 0;
  84437. +
  84438. + return more_needed;
  84439. +}
  84440. +
  84441. +/**
  84442. + * fiq_fsm_too_late() - Test transaction for lateness
  84443. + *
  84444. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  84445. + * the hub will disable the port to the device and respond with ERR handshakes.
  84446. + * The hub status endpoint will not reflect this change.
  84447. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  84448. + */
  84449. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  84450. +{
  84451. + int uframe;
  84452. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  84453. + uframe = hfnum.b.frnum & 0x7;
  84454. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  84455. + return 1;
  84456. + } else {
  84457. + return 0;
  84458. + }
  84459. +}
  84460. +
  84461. +
  84462. +/**
  84463. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  84464. + *
  84465. + * Search pending transactions in the start-split pending state and queue them.
  84466. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  84467. + * Note: we specifically don't do isochronous OUT transactions first because better
  84468. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  84469. + */
  84470. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  84471. +{
  84472. + int n;
  84473. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  84474. + if ((hfnum.b.frnum & 0x7) == 5)
  84475. + return;
  84476. + for (n = 0; n < num_channels; n++) {
  84477. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  84478. + /* Check to see if any other transactions are using this TT */
  84479. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  84480. + if (!fiq_fsm_too_late(st, n)) {
  84481. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  84482. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  84483. + fiq_fsm_restart_channel(st, n, 0);
  84484. + } else {
  84485. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  84486. + }
  84487. + break;
  84488. + }
  84489. + }
  84490. + }
  84491. + for (n = 0; n < num_channels; n++) {
  84492. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  84493. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  84494. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  84495. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  84496. + fiq_fsm_restart_channel(st, n, 0);
  84497. + break;
  84498. + }
  84499. + }
  84500. + }
  84501. +}
  84502. +
  84503. +/**
  84504. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  84505. + * @state: Pointer to fiq_state
  84506. + * @n: Channel transaction is active on
  84507. + * @hcint: Copy of host channel interrupt register
  84508. + *
  84509. + * Returns 0 if there are no more transactions for this HC to do, 1
  84510. + * otherwise.
  84511. + */
  84512. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  84513. +{
  84514. + struct fiq_channel_state *st = &state->channel[n];
  84515. + int xfer_len = 0, nrpackets = 0;
  84516. + hcdma_data_t hcdma;
  84517. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  84518. +
  84519. + xfer_len = fiq_get_xfer_len(state, n);
  84520. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  84521. +
  84522. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  84523. +
  84524. + st->hs_isoc_info.index++;
  84525. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  84526. + return 0;
  84527. + }
  84528. +
  84529. + /* grab the next DMA address offset from the array */
  84530. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  84531. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  84532. +
  84533. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  84534. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  84535. + * this is always set to the maximum size of the endpoint. */
  84536. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  84537. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  84538. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  84539. + if (nrpackets == 0)
  84540. + nrpackets = 1;
  84541. + st->hcchar_copy.b.multicnt = nrpackets;
  84542. + st->hctsiz_copy.b.pktcnt = nrpackets;
  84543. +
  84544. + /* Initial PID also needs to be set */
  84545. + if (st->hcchar_copy.b.epdir == 0) {
  84546. + st->hctsiz_copy.b.xfersize = xfer_len;
  84547. + switch (st->hcchar_copy.b.multicnt) {
  84548. + case 1:
  84549. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  84550. + break;
  84551. + case 2:
  84552. + case 3:
  84553. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  84554. + break;
  84555. + }
  84556. +
  84557. + } else {
  84558. + switch (st->hcchar_copy.b.multicnt) {
  84559. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  84560. + case 1:
  84561. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  84562. + break;
  84563. + case 2:
  84564. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  84565. + break;
  84566. + case 3:
  84567. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  84568. + break;
  84569. + }
  84570. + }
  84571. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  84572. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  84573. + /* Channel is enabled on hcint handler exit */
  84574. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  84575. + return 1;
  84576. +}
  84577. +
  84578. +
  84579. +/**
  84580. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  84581. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  84582. + * @num_channels: set according to the DWC hardware configuration
  84583. + *
  84584. + * The SOF handler in FSM mode has two functions
  84585. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  84586. + * nothing to do
  84587. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  84588. + * of holdoff.
  84589. + *
  84590. + * The second part is architecture-specific to mach-bcm2835 -
  84591. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  84592. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  84593. + * number (USB) can be enabled. This means that certain parts of the USB specification
  84594. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  84595. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  84596. + * the SOF "timer" (125uS) to perform this task.
  84597. + */
  84598. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  84599. +{
  84600. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  84601. + int n;
  84602. + int kick_irq = 0;
  84603. +
  84604. + if ((hfnum.b.frnum & 0x7) == 1) {
  84605. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  84606. + * Check to see if there are any transactions that are stale.
  84607. + * Boot them out.
  84608. + */
  84609. + for (n = 0; n < num_channels; n++) {
  84610. + switch (state->channel[n].fsm) {
  84611. + case FIQ_PER_CSPLIT_WAIT:
  84612. + case FIQ_PER_CSPLIT_NYET1:
  84613. + case FIQ_PER_CSPLIT_POLL:
  84614. + case FIQ_PER_CSPLIT_LAST:
  84615. + /* Check if we are no longer in the same full-speed frame. */
  84616. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  84617. + (hfnum.b.frnum & ~0x7))
  84618. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  84619. + break;
  84620. + default:
  84621. + break;
  84622. + }
  84623. + }
  84624. + }
  84625. +
  84626. + for (n = 0; n < num_channels; n++) {
  84627. + switch (state->channel[n].fsm) {
  84628. +
  84629. + case FIQ_NP_SSPLIT_RETRY:
  84630. + case FIQ_NP_IN_CSPLIT_RETRY:
  84631. + case FIQ_NP_OUT_CSPLIT_RETRY:
  84632. + fiq_fsm_restart_channel(state, n, 0);
  84633. + break;
  84634. +
  84635. + case FIQ_HS_ISOC_SLEEPING:
  84636. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  84637. + fiq_fsm_restart_channel(state, n, 0);
  84638. + break;
  84639. +
  84640. + case FIQ_PER_SSPLIT_QUEUED:
  84641. + if ((hfnum.b.frnum & 0x7) == 5)
  84642. + break;
  84643. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  84644. + if (!fiq_fsm_too_late(state, n)) {
  84645. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  84646. + fiq_fsm_restart_channel(state, n, 0);
  84647. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  84648. + } else {
  84649. + /* Transaction cannot be started without risking a device babble error */
  84650. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  84651. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  84652. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  84653. + kick_irq |= 1;
  84654. + }
  84655. + }
  84656. + break;
  84657. +
  84658. + case FIQ_PER_ISO_OUT_PENDING:
  84659. + /* Ordinarily, this should be poked after the SSPLIT
  84660. + * complete interrupt for a competing transfer on the same
  84661. + * TT. Doesn't happen for aborted transactions though.
  84662. + */
  84663. + if ((hfnum.b.frnum & 0x7) >= 5)
  84664. + break;
  84665. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  84666. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  84667. + * that caused this.
  84668. + */
  84669. + fiq_fsm_restart_channel(state, n, 0);
  84670. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  84671. + if (state->channel[n].nrpackets == 1) {
  84672. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  84673. + } else {
  84674. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  84675. + }
  84676. + }
  84677. + break;
  84678. +
  84679. + case FIQ_PER_CSPLIT_WAIT:
  84680. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  84681. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  84682. + * will utterly bugger this up though.
  84683. + */
  84684. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  84685. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  84686. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  84687. + fiq_fsm_restart_channel(state, n, 0);
  84688. + fiq_fsm_start_next_periodic(state, num_channels);
  84689. +
  84690. + }
  84691. + break;
  84692. +
  84693. + case FIQ_PER_SPLIT_TIMEOUT:
  84694. + case FIQ_DEQUEUE_ISSUED:
  84695. + /* Ugly: we have to force a HCD interrupt.
  84696. + * Poke the mask for the channel in question.
  84697. + * We will take a fake SOF because of this, but
  84698. + * that's OK.
  84699. + */
  84700. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  84701. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  84702. + kick_irq |= 1;
  84703. + break;
  84704. +
  84705. + default:
  84706. + break;
  84707. + }
  84708. + }
  84709. +
  84710. + if (state->kick_np_queues ||
  84711. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  84712. + kick_irq |= 1;
  84713. +
  84714. + return !kick_irq;
  84715. +}
  84716. +
  84717. +
  84718. +/**
  84719. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  84720. + * @state: Pointer to the FIQ state struct
  84721. + * @num_channels: Number of channels as per hardware config
  84722. + * @n: channel for which HAINT(i) was raised
  84723. + *
  84724. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  84725. + */
  84726. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  84727. +{
  84728. + hcint_data_t hcint;
  84729. + hcintmsk_data_t hcintmsk;
  84730. + hcint_data_t hcint_probe;
  84731. + hcchar_data_t hcchar;
  84732. + int handled = 0;
  84733. + int restart = 0;
  84734. + int last_csplit = 0;
  84735. + int start_next_periodic = 0;
  84736. + struct fiq_channel_state *st = &state->channel[n];
  84737. + hfnum_data_t hfnum;
  84738. +
  84739. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  84740. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  84741. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  84742. +
  84743. + if (st->fsm != FIQ_PASSTHROUGH) {
  84744. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  84745. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  84746. + }
  84747. +
  84748. + switch (st->fsm) {
  84749. +
  84750. + case FIQ_PASSTHROUGH:
  84751. + case FIQ_DEQUEUE_ISSUED:
  84752. + /* doesn't belong to us, kick it upstairs */
  84753. + break;
  84754. +
  84755. + case FIQ_PASSTHROUGH_ERRORSTATE:
  84756. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  84757. + * Several interrupts are unmasked if a previous transaction failed - it's
  84758. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  84759. + * Emulate what the HCD does in this situation: mask and continue.
  84760. + * The FSM has no other state setup so this has to be handled out-of-band.
  84761. + */
  84762. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  84763. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  84764. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  84765. + /* In some random cases we can get a NAK interrupt coincident with a Xacterr
  84766. + * interrupt, after the device has disappeared.
  84767. + */
  84768. + if (!hcint.b.xacterr)
  84769. + st->nr_errors = 0;
  84770. + hcintmsk.b.nak = 0;
  84771. + hcintmsk.b.ack = 0;
  84772. + hcintmsk.b.datatglerr = 0;
  84773. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  84774. + return 1;
  84775. + }
  84776. + if (hcint_probe.b.chhltd) {
  84777. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  84778. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  84779. + return 0;
  84780. + }
  84781. + break;
  84782. +
  84783. + /* Non-periodic state groups */
  84784. + case FIQ_NP_SSPLIT_STARTED:
  84785. + case FIQ_NP_SSPLIT_RETRY:
  84786. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  84787. + if (hcint.b.ack) {
  84788. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  84789. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  84790. + */
  84791. + if(st->hcchar_copy.b.epdir == 1)
  84792. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  84793. + else
  84794. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84795. + st->nr_errors = 0;
  84796. + handled = 1;
  84797. + fiq_fsm_setup_csplit(state, n);
  84798. + } else if (hcint.b.nak) {
  84799. + // No buffer space in TT. Retry on a uframe boundary.
  84800. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  84801. + handled = 1;
  84802. + } else if (hcint.b.xacterr) {
  84803. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  84804. + st->nr_errors++;
  84805. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  84806. + if (st->nr_errors >= 3) {
  84807. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84808. + } else {
  84809. + handled = 1;
  84810. + restart = 1;
  84811. + }
  84812. + } else {
  84813. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84814. + handled = 0;
  84815. + restart = 0;
  84816. + }
  84817. + break;
  84818. +
  84819. + case FIQ_NP_IN_CSPLIT_RETRY:
  84820. + /* Received a CSPLIT done interrupt.
  84821. + * Expected Data/NAK/STALL/NYET for IN.
  84822. + */
  84823. + if (hcint.b.xfercomp) {
  84824. + /* For IN, data is present. */
  84825. + st->fsm = FIQ_NP_SPLIT_DONE;
  84826. + } else if (hcint.b.nak) {
  84827. + /* no endpoint data. Punt it upstairs */
  84828. + st->fsm = FIQ_NP_SPLIT_DONE;
  84829. + } else if (hcint.b.nyet) {
  84830. + /* CSPLIT NYET - retry on a uframe boundary. */
  84831. + handled = 1;
  84832. + st->nr_errors = 0;
  84833. + } else if (hcint.b.datatglerr) {
  84834. + /* data toggle errors do not set the xfercomp bit. */
  84835. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84836. + } else if (hcint.b.xacterr) {
  84837. + /* HS error. Retry immediate */
  84838. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  84839. + st->nr_errors++;
  84840. + if (st->nr_errors >= 3) {
  84841. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84842. + } else {
  84843. + handled = 1;
  84844. + restart = 1;
  84845. + }
  84846. + } else if (hcint.b.stall || hcint.b.bblerr) {
  84847. + /* A STALL implies either a LS bus error or a genuine STALL. */
  84848. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84849. + } else {
  84850. + /* Hardware bug. It's possible in some cases to
  84851. + * get a channel halt with nothing else set when
  84852. + * the response was a NYET. Treat as local 3-strikes retry.
  84853. + */
  84854. + hcint_data_t hcint_test = hcint;
  84855. + hcint_test.b.chhltd = 0;
  84856. + if (!hcint_test.d32) {
  84857. + st->nr_errors++;
  84858. + if (st->nr_errors >= 3) {
  84859. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84860. + } else {
  84861. + handled = 1;
  84862. + }
  84863. + } else {
  84864. + /* Bail out if something unexpected happened */
  84865. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84866. + }
  84867. + }
  84868. + break;
  84869. +
  84870. + case FIQ_NP_OUT_CSPLIT_RETRY:
  84871. + /* Received a CSPLIT done interrupt.
  84872. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  84873. + if (hcint.b.xfercomp) {
  84874. + st->fsm = FIQ_NP_SPLIT_DONE;
  84875. + } else if (hcint.b.nak) {
  84876. + // The HCD will implement the holdoff on frame boundaries.
  84877. + st->fsm = FIQ_NP_SPLIT_DONE;
  84878. + } else if (hcint.b.nyet) {
  84879. + // Hub still processing.
  84880. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84881. + handled = 1;
  84882. + st->nr_errors = 0;
  84883. + //restart = 1;
  84884. + } else if (hcint.b.xacterr) {
  84885. + /* HS error. retry immediate */
  84886. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  84887. + st->nr_errors++;
  84888. + if (st->nr_errors >= 3) {
  84889. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84890. + } else {
  84891. + handled = 1;
  84892. + restart = 1;
  84893. + }
  84894. + } else if (hcint.b.stall) {
  84895. + /* LS bus error or genuine stall */
  84896. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  84897. + } else {
  84898. + /*
  84899. + * Hardware bug. It's possible in some cases to get a
  84900. + * channel halt with nothing else set when the response was a NYET.
  84901. + * Treat as local 3-strikes retry.
  84902. + */
  84903. + hcint_data_t hcint_test = hcint;
  84904. + hcint_test.b.chhltd = 0;
  84905. + if (!hcint_test.d32) {
  84906. + st->nr_errors++;
  84907. + if (st->nr_errors >= 3) {
  84908. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84909. + } else {
  84910. + handled = 1;
  84911. + }
  84912. + } else {
  84913. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  84914. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  84915. + }
  84916. + }
  84917. + break;
  84918. +
  84919. + /* Periodic split states (except isoc out) */
  84920. + case FIQ_PER_SSPLIT_STARTED:
  84921. + /* Expect an ACK or failure for SSPLIT */
  84922. + if (hcint.b.ack) {
  84923. + /*
  84924. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  84925. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  84926. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  84927. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  84928. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  84929. + * coincident with SOF for n+1.
  84930. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  84931. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  84932. + * State machine workaround.
  84933. + */
  84934. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84935. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84936. + fiq_fsm_setup_csplit(state, n);
  84937. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  84938. + * time. If not, then we're in the next SOF.
  84939. + */
  84940. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  84941. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  84942. + st->expected_uframe = hfnum.b.frnum;
  84943. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  84944. + } else {
  84945. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  84946. + /* For isochronous IN endpoints,
  84947. + * we need to hold off if we are expecting a lot of data */
  84948. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  84949. + start_next_periodic = 1;
  84950. + }
  84951. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  84952. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  84953. + * lag. Unmask the NYET interrupt.
  84954. + */
  84955. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  84956. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  84957. + restart = 1;
  84958. + }
  84959. + handled = 1;
  84960. + } else if (hcint.b.xacterr) {
  84961. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  84962. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84963. + start_next_periodic = 1;
  84964. + } else {
  84965. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  84966. + start_next_periodic = 1;
  84967. + }
  84968. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  84969. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  84970. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  84971. + }
  84972. + break;
  84973. +
  84974. + case FIQ_PER_CSPLIT_NYET1:
  84975. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  84976. + * we are too late and the TT has dropped its CSPLIT fifo.
  84977. + */
  84978. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  84979. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  84980. + start_next_periodic = 1;
  84981. + if (hcint.b.nak) {
  84982. + st->fsm = FIQ_PER_SPLIT_DONE;
  84983. + } else if (hcint.b.xfercomp) {
  84984. + fiq_increment_dma_buf(state, num_channels, n);
  84985. + st->fsm = FIQ_PER_CSPLIT_POLL;
  84986. + st->nr_errors = 0;
  84987. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  84988. + handled = 1;
  84989. + restart = 1;
  84990. + if (!last_csplit)
  84991. + start_next_periodic = 0;
  84992. + } else {
  84993. + st->fsm = FIQ_PER_SPLIT_DONE;
  84994. + }
  84995. + } else if (hcint.b.nyet) {
  84996. + /* Doh. Data lost. */
  84997. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  84998. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  84999. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  85000. + } else {
  85001. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  85002. + }
  85003. + break;
  85004. +
  85005. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  85006. + /*
  85007. + * we got here because our host channel is in the delayed-interrupt
  85008. + * state and we cannot take a NYET interrupt any later than when it
  85009. + * occurred. Disable then re-enable the channel if this happens to force
  85010. + * CSPLITs to occur at the right time.
  85011. + */
  85012. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  85013. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  85014. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  85015. + if (hcint.b.nak) {
  85016. + st->fsm = FIQ_PER_SPLIT_DONE;
  85017. + start_next_periodic = 1;
  85018. + } else if (hcint.b.xfercomp) {
  85019. + fiq_increment_dma_buf(state, num_channels, n);
  85020. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  85021. + st->fsm = FIQ_PER_CSPLIT_POLL;
  85022. + handled = 1;
  85023. + restart = 1;
  85024. + start_next_periodic = 1;
  85025. + /* Reload HCTSIZ for the next transfer */
  85026. + fiq_fsm_reload_hctsiz(state, n);
  85027. + if (!last_csplit)
  85028. + start_next_periodic = 0;
  85029. + } else {
  85030. + st->fsm = FIQ_PER_SPLIT_DONE;
  85031. + }
  85032. + } else if (hcint.b.nyet) {
  85033. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  85034. + start_next_periodic = 1;
  85035. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  85036. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  85037. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  85038. + } else {
  85039. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  85040. + }
  85041. + break;
  85042. +
  85043. + case FIQ_PER_CSPLIT_POLL:
  85044. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  85045. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  85046. + start_next_periodic = 1;
  85047. + if (hcint.b.nak) {
  85048. + st->fsm = FIQ_PER_SPLIT_DONE;
  85049. + } else if (hcint.b.xfercomp) {
  85050. + fiq_increment_dma_buf(state, num_channels, n);
  85051. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  85052. + handled = 1;
  85053. + restart = 1;
  85054. + /* Reload HCTSIZ for the next transfer */
  85055. + fiq_fsm_reload_hctsiz(state, n);
  85056. + if (!last_csplit)
  85057. + start_next_periodic = 0;
  85058. + } else {
  85059. + st->fsm = FIQ_PER_SPLIT_DONE;
  85060. + }
  85061. + } else if (hcint.b.nyet) {
  85062. + /* Are we a NYET after the first data packet? */
  85063. + if (st->nrpackets == 0) {
  85064. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  85065. + handled = 1;
  85066. + restart = 1;
  85067. + } else {
  85068. + /* We got a NYET when polling CSPLITs. Can happen
  85069. + * if our heuristic fails, or if someone disables us
  85070. + * for any significant length of time.
  85071. + */
  85072. + if (st->nr_errors >= 3) {
  85073. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  85074. + } else {
  85075. + st->fsm = FIQ_PER_SPLIT_DONE;
  85076. + }
  85077. + }
  85078. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  85079. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  85080. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  85081. + } else {
  85082. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  85083. + }
  85084. + break;
  85085. +
  85086. + case FIQ_HS_ISOC_TURBO:
  85087. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  85088. + /* more transactions to come */
  85089. + handled = 1;
  85090. + restart = 1;
  85091. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  85092. + } else {
  85093. + st->fsm = FIQ_HS_ISOC_DONE;
  85094. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  85095. + }
  85096. + break;
  85097. +
  85098. + case FIQ_HS_ISOC_ABORTED:
  85099. + /* This abort is called by the driver rewriting the state mid-transaction
  85100. + * which allows the dequeue mechanism to work more effectively.
  85101. + */
  85102. + break;
  85103. +
  85104. + case FIQ_PER_ISO_OUT_ACTIVE:
  85105. + if (hcint.b.ack) {
  85106. + if(fiq_iso_out_advance(state, num_channels, n)) {
  85107. + /* last OUT transfer */
  85108. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  85109. + /*
  85110. + * Assuming the periodic FIFO in the dwc core
  85111. + * actually does its job properly, we can queue
  85112. + * the next ssplit now and in theory, the wire
  85113. + * transactions will be in-order.
  85114. + */
  85115. + // No it doesn't. It appears to process requests in host channel order.
  85116. + //start_next_periodic = 1;
  85117. + }
  85118. + handled = 1;
  85119. + restart = 1;
  85120. + } else {
  85121. + /*
  85122. + * Isochronous transactions carry on regardless. Log the error
  85123. + * and continue.
  85124. + */
  85125. + //explode += 1;
  85126. + st->nr_errors++;
  85127. + if(fiq_iso_out_advance(state, num_channels, n)) {
  85128. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  85129. + //start_next_periodic = 1;
  85130. + }
  85131. + handled = 1;
  85132. + restart = 1;
  85133. + }
  85134. + break;
  85135. +
  85136. + case FIQ_PER_ISO_OUT_LAST:
  85137. + if (hcint.b.ack) {
  85138. + /* All done here */
  85139. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  85140. + } else {
  85141. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  85142. + st->nr_errors++;
  85143. + }
  85144. + start_next_periodic = 1;
  85145. + break;
  85146. +
  85147. + case FIQ_PER_SPLIT_TIMEOUT:
  85148. + /* SOF kicked us because we overran. */
  85149. + start_next_periodic = 1;
  85150. + break;
  85151. +
  85152. + default:
  85153. + break;
  85154. + }
  85155. +
  85156. + if (handled) {
  85157. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  85158. + } else {
  85159. + /* Copy the regs into the state so the IRQ knows what to do */
  85160. + st->hcint_copy.d32 = hcint.d32;
  85161. + }
  85162. +
  85163. + if (restart) {
  85164. + /* Restart always implies handled. */
  85165. + if (restart == 2) {
  85166. + /* For complete-split INs, the show must go on.
  85167. + * Force a channel restart */
  85168. + fiq_fsm_restart_channel(state, n, 1);
  85169. + } else {
  85170. + fiq_fsm_restart_channel(state, n, 0);
  85171. + }
  85172. + }
  85173. + if (start_next_periodic) {
  85174. + fiq_fsm_start_next_periodic(state, num_channels);
  85175. + }
  85176. + if (st->fsm != FIQ_PASSTHROUGH)
  85177. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  85178. +
  85179. + return handled;
  85180. +}
  85181. +
  85182. +
  85183. +/**
  85184. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  85185. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  85186. + * @num_channels: set according to the DWC hardware configuration
  85187. + * @dma: pointer to DMA bounce buffers for split transaction slots
  85188. + *
  85189. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  85190. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  85191. + * interrupts each and every time a split transaction packet is received or sent successfully.
  85192. + * This results in either an interrupt storm when everything is working "properly", or
  85193. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  85194. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  85195. + * solves these problems.
  85196. + *
  85197. + * Return: void
  85198. + */
  85199. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  85200. +{
  85201. + gintsts_data_t gintsts, gintsts_handled;
  85202. + gintmsk_data_t gintmsk;
  85203. + //hfnum_data_t hfnum;
  85204. + haint_data_t haint, haint_handled;
  85205. + haintmsk_data_t haintmsk;
  85206. + int kick_irq = 0;
  85207. +
  85208. + gintsts_handled.d32 = 0;
  85209. + haint_handled.d32 = 0;
  85210. +
  85211. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  85212. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  85213. + gintsts.d32 &= gintmsk.d32;
  85214. +
  85215. + if (gintsts.b.sofintr) {
  85216. + /* For FSM mode, SOF is required to keep the state machine advance for
  85217. + * certain stages of the periodic pipeline. It's death to mask this
  85218. + * interrupt in that case.
  85219. + */
  85220. +
  85221. + if (!fiq_fsm_do_sof(state, num_channels)) {
  85222. + /* Kick IRQ once. Queue advancement means that all pending transactions
  85223. + * will get serviced when the IRQ finally executes.
  85224. + */
  85225. + if (state->gintmsk_saved.b.sofintr == 1)
  85226. + kick_irq |= 1;
  85227. + state->gintmsk_saved.b.sofintr = 0;
  85228. + }
  85229. + gintsts_handled.b.sofintr = 1;
  85230. + }
  85231. +
  85232. + if (gintsts.b.hcintr) {
  85233. + int i;
  85234. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  85235. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  85236. + haint.d32 &= haintmsk.d32;
  85237. + haint_handled.d32 = 0;
  85238. + for (i=0; i<num_channels; i++) {
  85239. + if (haint.b2.chint & (1 << i)) {
  85240. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  85241. + /* HCINT was not handled in FIQ
  85242. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  85243. + * Mask HAINT(i) but keep top-level hcint unmasked.
  85244. + */
  85245. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  85246. + } else {
  85247. + /* do_hcintr cleaned up after itself, but clear haint */
  85248. + haint_handled.b2.chint |= (1 << i);
  85249. + }
  85250. + }
  85251. + }
  85252. +
  85253. + if (haint_handled.b2.chint) {
  85254. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  85255. + }
  85256. +
  85257. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  85258. + /*
  85259. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  85260. + * where interrupts are held off and HCINTs start to pile up.
  85261. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  85262. + * masked.
  85263. + */
  85264. + haintmsk.d32 &= state->haintmsk_saved.d32;
  85265. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  85266. + kick_irq |= 1;
  85267. + }
  85268. + /* Top-Level interrupt - always handled because it's level-sensitive */
  85269. + gintsts_handled.b.hcintr = 1;
  85270. + }
  85271. +
  85272. +
  85273. + /* Clear the bits in the saved register that were not handled but were triggered. */
  85274. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  85275. +
  85276. + /* FIQ didn't handle something - mask has changed - write new mask */
  85277. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  85278. + gintmsk.d32 &= state->gintmsk_saved.d32;
  85279. + gintmsk.b.sofintr = 1;
  85280. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  85281. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  85282. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  85283. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  85284. + kick_irq |= 1;
  85285. + }
  85286. +
  85287. + if (gintsts_handled.d32) {
  85288. + /* Only applies to edge-sensitive bits in GINTSTS */
  85289. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  85290. + }
  85291. +
  85292. + /* We got an interrupt, didn't handle it. */
  85293. + if (kick_irq) {
  85294. + state->mphi_int_count++;
  85295. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  85296. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  85297. +
  85298. + }
  85299. + state->fiq_done++;
  85300. + mb();
  85301. +}
  85302. +
  85303. +
  85304. +/**
  85305. + * dwc_otg_fiq_nop() - FIQ "lite"
  85306. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  85307. + *
  85308. + * The "nop" handler does not intervene on any interrupts other than SOF.
  85309. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  85310. + * with non-periodic/periodic queues) needs to be kicked.
  85311. + *
  85312. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  85313. + *
  85314. + * Return: void
  85315. + */
  85316. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  85317. +{
  85318. + gintsts_data_t gintsts, gintsts_handled;
  85319. + gintmsk_data_t gintmsk;
  85320. + hfnum_data_t hfnum;
  85321. +
  85322. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  85323. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  85324. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  85325. + gintsts.d32 &= gintmsk.d32;
  85326. + gintsts_handled.d32 = 0;
  85327. +
  85328. + if (gintsts.b.sofintr) {
  85329. + if (!state->kick_np_queues &&
  85330. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  85331. + /* SOF handled, no work to do, just ACK interrupt */
  85332. + gintsts_handled.b.sofintr = 1;
  85333. + } else {
  85334. + /* Kick IRQ */
  85335. + state->gintmsk_saved.b.sofintr = 0;
  85336. + }
  85337. + }
  85338. +
  85339. + /* Reset handled interrupts */
  85340. + if(gintsts_handled.d32) {
  85341. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  85342. + }
  85343. +
  85344. + /* Clear the bits in the saved register that were not handled but were triggered. */
  85345. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  85346. +
  85347. + /* We got an interrupt, didn't handle it and want to mask it */
  85348. + if (~(state->gintmsk_saved.d32)) {
  85349. + state->mphi_int_count++;
  85350. + gintmsk.d32 &= state->gintmsk_saved.d32;
  85351. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  85352. + /* Force a clear before another dummy send */
  85353. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  85354. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  85355. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  85356. +
  85357. + }
  85358. + state->fiq_done++;
  85359. + mb();
  85360. +}
  85361. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  85362. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  85363. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2015-03-10 17:26:51.302216687 +0100
  85364. @@ -0,0 +1,353 @@
  85365. +/*
  85366. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  85367. + *
  85368. + * Copyright (c) 2013 Raspberry Pi Foundation
  85369. + *
  85370. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  85371. + * All rights reserved.
  85372. + *
  85373. + * Redistribution and use in source and binary forms, with or without
  85374. + * modification, are permitted provided that the following conditions are met:
  85375. + * * Redistributions of source code must retain the above copyright
  85376. + * notice, this list of conditions and the following disclaimer.
  85377. + * * Redistributions in binary form must reproduce the above copyright
  85378. + * notice, this list of conditions and the following disclaimer in the
  85379. + * documentation and/or other materials provided with the distribution.
  85380. + * * Neither the name of Raspberry Pi nor the
  85381. + * names of its contributors may be used to endorse or promote products
  85382. + * derived from this software without specific prior written permission.
  85383. + *
  85384. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  85385. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  85386. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  85387. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  85388. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85389. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  85390. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  85391. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  85392. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  85393. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  85394. + *
  85395. + * This FIQ implements functionality that performs split transactions on
  85396. + * the dwc_otg hardware without any outside intervention. A split transaction
  85397. + * is "queued" by nominating a specific host channel to perform the entirety
  85398. + * of a split transaction. This FIQ will then perform the microframe-precise
  85399. + * scheduling required in each phase of the transaction until completion.
  85400. + *
  85401. + * The FIQ functionality has been surgically implanted into the Synopsys
  85402. + * vendor-provided driver.
  85403. + *
  85404. + */
  85405. +
  85406. +#ifndef DWC_OTG_FIQ_FSM_H_
  85407. +#define DWC_OTG_FIQ_FSM_H_
  85408. +
  85409. +#include "dwc_otg_regs.h"
  85410. +#include "dwc_otg_cil.h"
  85411. +#include "dwc_otg_hcd.h"
  85412. +#include <linux/kernel.h>
  85413. +#include <linux/irqflags.h>
  85414. +#include <linux/string.h>
  85415. +#include <asm/barrier.h>
  85416. +
  85417. +#if 0
  85418. +#define FLAME_ON(x) \
  85419. +do { \
  85420. + int gpioreg; \
  85421. + \
  85422. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  85423. + gpioreg &= ~(7 << (x-20)*3); \
  85424. + gpioreg |= 0x1 << (x-20)*3; \
  85425. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  85426. + \
  85427. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  85428. +} while (0)
  85429. +
  85430. +#define FLAME_OFF(x) \
  85431. +do { \
  85432. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  85433. +} while (0)
  85434. +#else
  85435. +#define FLAME_ON(x) do { } while (0)
  85436. +#define FLAME_OFF(X) do { } while (0)
  85437. +#endif
  85438. +
  85439. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  85440. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  85441. + * reads and writes are executed in-order therefore the need for memory barriers
  85442. + * is obviated if we're only talking to USB.
  85443. + */
  85444. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  85445. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  85446. +
  85447. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  85448. +#define GINTSTS 0x014
  85449. +#define GINTMSK 0x018
  85450. +/* Debug register. Poll the top of the received packets FIFO. */
  85451. +#define GRXSTSR 0x01C
  85452. +#define HFNUM 0x408
  85453. +#define HAINT 0x414
  85454. +#define HAINTMSK 0x418
  85455. +#define HPRT0 0x440
  85456. +
  85457. +/* HC_regs start from an offset of 0x500 */
  85458. +#define HC_START 0x500
  85459. +#define HC_OFFSET 0x020
  85460. +
  85461. +#define HC_DMA 0x514
  85462. +
  85463. +#define HCCHAR 0x00
  85464. +#define HCSPLT 0x04
  85465. +#define HCINT 0x08
  85466. +#define HCINTMSK 0x0C
  85467. +#define HCTSIZ 0x10
  85468. +
  85469. +#define ISOC_XACTPOS_ALL 0b11
  85470. +#define ISOC_XACTPOS_BEGIN 0b10
  85471. +#define ISOC_XACTPOS_MID 0b00
  85472. +#define ISOC_XACTPOS_END 0b01
  85473. +
  85474. +#define DWC_PID_DATA2 0b01
  85475. +#define DWC_PID_MDATA 0b11
  85476. +#define DWC_PID_DATA1 0b10
  85477. +#define DWC_PID_DATA0 0b00
  85478. +
  85479. +typedef struct {
  85480. + volatile void* base;
  85481. + volatile void* ctrl;
  85482. + volatile void* outdda;
  85483. + volatile void* outddb;
  85484. + volatile void* intstat;
  85485. +} mphi_regs_t;
  85486. +
  85487. +
  85488. +enum fiq_debug_level {
  85489. + FIQDBG_SCHED = (1 << 0),
  85490. + FIQDBG_INT = (1 << 1),
  85491. + FIQDBG_ERR = (1 << 2),
  85492. + FIQDBG_PORTHUB = (1 << 3),
  85493. +};
  85494. +
  85495. +struct fiq_state;
  85496. +
  85497. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  85498. +#if 0
  85499. +#define fiq_print _fiq_print
  85500. +#else
  85501. +#define fiq_print(x, y, ...)
  85502. +#endif
  85503. +
  85504. +extern bool fiq_enable, fiq_fsm_enable;
  85505. +extern ushort nak_holdoff;
  85506. +
  85507. +/**
  85508. + * enum fiq_fsm_state - The FIQ FSM states.
  85509. + *
  85510. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  85511. + * USB2.0 specification for host responses to various transaction states.
  85512. + * There are modifications to this host state machine because of a variety of
  85513. + * quirks and limitations in the dwc_otg hardware.
  85514. + *
  85515. + * The fsm state is also used to communicate back to the driver on completion of
  85516. + * a split transaction. The end states are used in conjunction with the interrupts
  85517. + * raised by the final transaction.
  85518. + */
  85519. +enum fiq_fsm_state {
  85520. + /* FIQ isn't enabled for this host channel */
  85521. + FIQ_PASSTHROUGH = 0,
  85522. + /* For the first interrupt received for this channel,
  85523. + * the FIQ has to ack any interrupts indicating success. */
  85524. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  85525. + /* Nonperiodic state groups */
  85526. + FIQ_NP_SSPLIT_STARTED = 1,
  85527. + FIQ_NP_SSPLIT_RETRY = 2,
  85528. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  85529. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  85530. + FIQ_NP_SPLIT_DONE = 5,
  85531. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  85532. + /* This differentiates a HS transaction error from a LS one
  85533. + * (handling the hub state is different) */
  85534. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  85535. +
  85536. + /* Periodic state groups */
  85537. + /* Periodic transactions are either started directly by the IRQ handler
  85538. + * or deferred if the TT is already in use.
  85539. + */
  85540. + FIQ_PER_SSPLIT_QUEUED = 8,
  85541. + FIQ_PER_SSPLIT_STARTED = 9,
  85542. + FIQ_PER_SSPLIT_LAST = 10,
  85543. +
  85544. +
  85545. + FIQ_PER_ISO_OUT_PENDING = 11,
  85546. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  85547. + FIQ_PER_ISO_OUT_LAST = 13,
  85548. + FIQ_PER_ISO_OUT_DONE = 27,
  85549. +
  85550. + FIQ_PER_CSPLIT_WAIT = 14,
  85551. + FIQ_PER_CSPLIT_NYET1 = 15,
  85552. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  85553. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  85554. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  85555. + FIQ_PER_CSPLIT_POLL = 16,
  85556. + /* The last CSPLIT for a transaction has been issued, differentiates
  85557. + * for the state machine to queue the next packet.
  85558. + */
  85559. + FIQ_PER_CSPLIT_LAST = 17,
  85560. +
  85561. + FIQ_PER_SPLIT_DONE = 18,
  85562. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  85563. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  85564. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  85565. + /* Frame rollover has occurred without the transaction finishing. */
  85566. + FIQ_PER_SPLIT_TIMEOUT = 22,
  85567. +
  85568. + /* FIQ-accelerated HS Isochronous state groups */
  85569. + FIQ_HS_ISOC_TURBO = 23,
  85570. + /* For interval > 1, SOF wakes up the isochronous FSM */
  85571. + FIQ_HS_ISOC_SLEEPING = 24,
  85572. + FIQ_HS_ISOC_DONE = 25,
  85573. + FIQ_HS_ISOC_ABORTED = 26,
  85574. + FIQ_DEQUEUE_ISSUED = 30,
  85575. + FIQ_TEST = 32,
  85576. +};
  85577. +
  85578. +struct fiq_stack {
  85579. + int magic1;
  85580. + uint8_t stack[2048];
  85581. + int magic2;
  85582. +};
  85583. +
  85584. +
  85585. +/**
  85586. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  85587. + * @index: Number of slots reported used for IN transactions / number of slots
  85588. + * transmitted for an OUT transaction
  85589. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  85590. + *
  85591. + * Split transaction transfers can have variable length depending on other bus
  85592. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  85593. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  85594. + * can happen per-frame.
  85595. + */
  85596. +struct fiq_dma_info {
  85597. + u8 index;
  85598. + u8 slot_len[6];
  85599. +};
  85600. +
  85601. +struct __attribute__((packed)) fiq_split_dma_slot {
  85602. + u8 buf[188];
  85603. +};
  85604. +
  85605. +struct fiq_dma_channel {
  85606. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  85607. +};
  85608. +
  85609. +struct fiq_dma_blob {
  85610. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  85611. +};
  85612. +
  85613. +/**
  85614. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  85615. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  85616. + * @nrframes: Total length of iso_frame_desc array
  85617. + * @index: Current index (FIQ-maintained)
  85618. + *
  85619. + */
  85620. +struct fiq_hs_isoc_info {
  85621. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  85622. + unsigned int nrframes;
  85623. + unsigned int index;
  85624. +};
  85625. +
  85626. +/**
  85627. + * struct fiq_channel_state - FIQ state machine storage
  85628. + * @fsm: Current state of the channel as understood by the FIQ
  85629. + * @nr_errors: Number of transaction errors on this split-transaction
  85630. + * @hub_addr: SSPLIT/CSPLIT destination hub
  85631. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  85632. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  85633. + * split-IN, number of CSPLIT data packets that were received.
  85634. + * @hcchar_copy:
  85635. + * @hcsplt_copy:
  85636. + * @hcintmsk_copy:
  85637. + * @hctsiz_copy: Copies of the host channel registers.
  85638. + * For use as scratch, or for returning state.
  85639. + *
  85640. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  85641. + * FSM state is stored here. Members of this structure must only be set up by the
  85642. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  85643. + * has updated the state to either a COMPLETE state group or ABORT state group.
  85644. + */
  85645. +
  85646. +struct fiq_channel_state {
  85647. + enum fiq_fsm_state fsm;
  85648. + unsigned int nr_errors;
  85649. + unsigned int hub_addr;
  85650. + unsigned int port_addr;
  85651. + /* Hardware bug workaround: sometimes channel halt interrupts are
  85652. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  85653. + unsigned int expected_uframe;
  85654. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  85655. + unsigned int nrpackets;
  85656. + struct fiq_dma_info dma_info;
  85657. + struct fiq_hs_isoc_info hs_isoc_info;
  85658. + /* Copies of HC registers - in/out communication from/to IRQ handler
  85659. + * and for ease of channel setup. A bit of mungeing is performed - for
  85660. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  85661. + */
  85662. + hcchar_data_t hcchar_copy;
  85663. + hcsplt_data_t hcsplt_copy;
  85664. + hcint_data_t hcint_copy;
  85665. + hcintmsk_data_t hcintmsk_copy;
  85666. + hctsiz_data_t hctsiz_copy;
  85667. + hcdma_data_t hcdma_copy;
  85668. +};
  85669. +
  85670. +/**
  85671. + * struct fiq_state - top-level FIQ state machine storage
  85672. + * @mphi_regs: virtual address of the MPHI peripheral register file
  85673. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  85674. + * @dma_base: physical address for the base of the DMA bounce buffers
  85675. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  85676. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  85677. + * Used for determining which interrupts fired to set off the IRQ handler.
  85678. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  85679. + * @np_count: Non-periodic transactions in the active queue
  85680. + * @np_sent: Count of non-periodic transactions that have completed
  85681. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  85682. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  85683. + * passing SOF through to the driver until necessary.
  85684. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  85685. + * channels configured into the core logic.
  85686. + *
  85687. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  85688. + * It contains top-level state information.
  85689. + */
  85690. +struct fiq_state {
  85691. + mphi_regs_t mphi_regs;
  85692. + void *dwc_regs_base;
  85693. + dma_addr_t dma_base;
  85694. + struct fiq_dma_blob *fiq_dmab;
  85695. + void *dummy_send;
  85696. + gintmsk_data_t gintmsk_saved;
  85697. + haintmsk_data_t haintmsk_saved;
  85698. + int mphi_int_count;
  85699. + unsigned int fiq_done;
  85700. + unsigned int kick_np_queues;
  85701. + unsigned int next_sched_frame;
  85702. +#ifdef FIQ_DEBUG
  85703. + char * buffer;
  85704. + unsigned int bufsiz;
  85705. +#endif
  85706. + struct fiq_channel_state channel[0];
  85707. +};
  85708. +
  85709. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  85710. +
  85711. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  85712. +
  85713. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  85714. +
  85715. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  85716. +
  85717. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  85718. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  85719. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  85720. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2015-03-09 10:39:33.218893718 +0100
  85721. @@ -0,0 +1,81 @@
  85722. +/*
  85723. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  85724. + *
  85725. + * Copyright (c) 2013 Raspberry Pi Foundation
  85726. + *
  85727. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  85728. + * All rights reserved.
  85729. + *
  85730. + * Redistribution and use in source and binary forms, with or without
  85731. + * modification, are permitted provided that the following conditions are met:
  85732. + * * Redistributions of source code must retain the above copyright
  85733. + * notice, this list of conditions and the following disclaimer.
  85734. + * * Redistributions in binary form must reproduce the above copyright
  85735. + * notice, this list of conditions and the following disclaimer in the
  85736. + * documentation and/or other materials provided with the distribution.
  85737. + * * Neither the name of Raspberry Pi nor the
  85738. + * names of its contributors may be used to endorse or promote products
  85739. + * derived from this software without specific prior written permission.
  85740. + *
  85741. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  85742. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  85743. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  85744. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  85745. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85746. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  85747. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  85748. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  85749. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  85750. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  85751. + */
  85752. +
  85753. +
  85754. +#include <asm/assembler.h>
  85755. +#include <linux/linkage.h>
  85756. +
  85757. +
  85758. +.text
  85759. +
  85760. +.global _dwc_otg_fiq_stub_end;
  85761. +
  85762. +/**
  85763. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  85764. + * a C-style function call with arguments from the FIQ banked registers.
  85765. + * r0 = &hcd->fiq_state
  85766. + * r1 = &hcd->num_channels
  85767. + * r2 = &hcd->dma_buffers
  85768. + * Tramples: r0, r1, r2, r4, fp, ip
  85769. + */
  85770. +
  85771. +ENTRY(_dwc_otg_fiq_stub)
  85772. + /* Stash unbanked regs - SP will have been set up for us */
  85773. + mov ip, sp;
  85774. + stmdb sp!, {r0-r12, lr};
  85775. +#ifdef FIQ_DEBUG
  85776. + // Cycle profiling - read cycle counter at start
  85777. + mrc p15, 0, r5, c15, c12, 1;
  85778. +#endif
  85779. + /* r11 = fp, don't trample it */
  85780. + mov r4, fp;
  85781. + /* set EABI frame size */
  85782. + sub fp, ip, #512;
  85783. +
  85784. + /* for fiq NOP mode - just need state */
  85785. + mov r0, r8;
  85786. + /* r9 = num_channels */
  85787. + mov r1, r9;
  85788. + /* r10 = struct *dma_bufs */
  85789. +// mov r2, r10;
  85790. +
  85791. + /* r4 = &fiq_c_function */
  85792. + blx r4;
  85793. +#ifdef FIQ_DEBUG
  85794. + mrc p15, 0, r4, c15, c12, 1;
  85795. + subs r5, r5, r4;
  85796. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  85797. +#endif
  85798. + ldmia sp!, {r0-r12, lr};
  85799. + subs pc, lr, #4;
  85800. +_dwc_otg_fiq_stub_end:
  85801. +END(_dwc_otg_fiq_stub)
  85802. +
  85803. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  85804. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  85805. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2015-03-10 17:26:51.302216687 +0100
  85806. @@ -0,0 +1,4212 @@
  85807. +
  85808. +/* ==========================================================================
  85809. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  85810. + * $Revision: #104 $
  85811. + * $Date: 2011/10/24 $
  85812. + * $Change: 1871159 $
  85813. + *
  85814. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  85815. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  85816. + * otherwise expressly agreed to in writing between Synopsys and you.
  85817. + *
  85818. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  85819. + * any End User Software License Agreement or Agreement for Licensed Product
  85820. + * with Synopsys or any supplement thereto. You are permitted to use and
  85821. + * redistribute this Software in source and binary forms, with or without
  85822. + * modification, provided that redistributions of source code must retain this
  85823. + * notice. You may not view, use, disclose, copy or distribute this file or
  85824. + * any information contained herein except pursuant to this license grant from
  85825. + * Synopsys. If you do not agree with this notice, including the disclaimer
  85826. + * below, then you are not authorized to use the Software.
  85827. + *
  85828. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  85829. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85830. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  85831. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  85832. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  85833. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  85834. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  85835. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  85836. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  85837. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  85838. + * DAMAGE.
  85839. + * ========================================================================== */
  85840. +#ifndef DWC_DEVICE_ONLY
  85841. +
  85842. +/** @file
  85843. + * This file implements HCD Core. All code in this file is portable and doesn't
  85844. + * use any OS specific functions.
  85845. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  85846. + * header file.
  85847. + */
  85848. +
  85849. +#include <linux/usb.h>
  85850. +#include <linux/usb/hcd.h>
  85851. +
  85852. +#include "dwc_otg_hcd.h"
  85853. +#include "dwc_otg_regs.h"
  85854. +#include "dwc_otg_fiq_fsm.h"
  85855. +
  85856. +extern bool microframe_schedule;
  85857. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  85858. +
  85859. +//#define DEBUG_HOST_CHANNELS
  85860. +#ifdef DEBUG_HOST_CHANNELS
  85861. +static int last_sel_trans_num_per_scheduled = 0;
  85862. +static int last_sel_trans_num_nonper_scheduled = 0;
  85863. +static int last_sel_trans_num_avail_hc_at_start = 0;
  85864. +static int last_sel_trans_num_avail_hc_at_end = 0;
  85865. +#endif /* DEBUG_HOST_CHANNELS */
  85866. +
  85867. +
  85868. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  85869. +{
  85870. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  85871. +}
  85872. +
  85873. +/**
  85874. + * Connection timeout function. An OTG host is required to display a
  85875. + * message if the device does not connect within 10 seconds.
  85876. + */
  85877. +void dwc_otg_hcd_connect_timeout(void *ptr)
  85878. +{
  85879. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  85880. + DWC_PRINTF("Connect Timeout\n");
  85881. + __DWC_ERROR("Device Not Connected/Responding\n");
  85882. +}
  85883. +
  85884. +#if defined(DEBUG)
  85885. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  85886. +{
  85887. + if (qh->channel != NULL) {
  85888. + dwc_hc_t *hc = qh->channel;
  85889. + dwc_list_link_t *item;
  85890. + dwc_otg_qh_t *qh_item;
  85891. + int num_channels = hcd->core_if->core_params->host_channels;
  85892. + int i;
  85893. +
  85894. + dwc_otg_hc_regs_t *hc_regs;
  85895. + hcchar_data_t hcchar;
  85896. + hcsplt_data_t hcsplt;
  85897. + hctsiz_data_t hctsiz;
  85898. + uint32_t hcdma;
  85899. +
  85900. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  85901. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  85902. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  85903. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  85904. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  85905. +
  85906. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  85907. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  85908. + hcsplt.d32);
  85909. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  85910. + hcdma);
  85911. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  85912. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  85913. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  85914. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  85915. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  85916. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  85917. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  85918. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  85919. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  85920. + DWC_PRINTF(" qh: %p\n", hc->qh);
  85921. + DWC_PRINTF(" NP inactive sched:\n");
  85922. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  85923. + qh_item =
  85924. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  85925. + DWC_PRINTF(" %p\n", qh_item);
  85926. + }
  85927. + DWC_PRINTF(" NP active sched:\n");
  85928. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  85929. + qh_item =
  85930. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  85931. + DWC_PRINTF(" %p\n", qh_item);
  85932. + }
  85933. + DWC_PRINTF(" Channels: \n");
  85934. + for (i = 0; i < num_channels; i++) {
  85935. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  85936. + DWC_PRINTF(" %2d: %p\n", i, hc);
  85937. + }
  85938. + }
  85939. +}
  85940. +#else
  85941. +#define dump_channel_info(hcd, qh)
  85942. +#endif /* DEBUG */
  85943. +
  85944. +/**
  85945. + * Work queue function for starting the HCD when A-Cable is connected.
  85946. + * The hcd_start() must be called in a process context.
  85947. + */
  85948. +static void hcd_start_func(void *_vp)
  85949. +{
  85950. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  85951. +
  85952. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  85953. + if (hcd) {
  85954. + hcd->fops->start(hcd);
  85955. + }
  85956. +}
  85957. +
  85958. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  85959. +{
  85960. +#ifdef DEBUG
  85961. + int i;
  85962. + int num_channels = hcd->core_if->core_params->host_channels;
  85963. + for (i = 0; i < num_channels; i++) {
  85964. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  85965. + }
  85966. +#endif
  85967. +}
  85968. +
  85969. +static void del_timers(dwc_otg_hcd_t * hcd)
  85970. +{
  85971. + del_xfer_timers(hcd);
  85972. + DWC_TIMER_CANCEL(hcd->conn_timer);
  85973. +}
  85974. +
  85975. +/**
  85976. + * Processes all the URBs in a single list of QHs. Completes them with
  85977. + * -ESHUTDOWN and frees the QTD.
  85978. + */
  85979. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  85980. +{
  85981. + dwc_list_link_t *qh_item, *qh_tmp;
  85982. + dwc_otg_qh_t *qh;
  85983. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  85984. +
  85985. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  85986. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  85987. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  85988. + &qh->qtd_list, qtd_list_entry) {
  85989. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  85990. + if (qtd->urb != NULL) {
  85991. + hcd->fops->complete(hcd, qtd->urb->priv,
  85992. + qtd->urb, -DWC_E_SHUTDOWN);
  85993. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  85994. + }
  85995. +
  85996. + }
  85997. + if(qh->channel) {
  85998. + /* Using hcchar.chen == 1 is not a reliable test.
  85999. + * It is possible that the channel has already halted
  86000. + * but not yet been through the IRQ handler.
  86001. + */
  86002. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  86003. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  86004. + if(microframe_schedule)
  86005. + hcd->available_host_channels++;
  86006. + qh->channel = NULL;
  86007. + }
  86008. + dwc_otg_hcd_qh_remove(hcd, qh);
  86009. + }
  86010. +}
  86011. +
  86012. +/**
  86013. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  86014. + * and periodic schedules. The QTD associated with each URB is removed from
  86015. + * the schedule and freed. This function may be called when a disconnect is
  86016. + * detected or when the HCD is being stopped.
  86017. + */
  86018. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  86019. +{
  86020. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  86021. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  86022. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  86023. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  86024. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  86025. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  86026. +}
  86027. +
  86028. +/**
  86029. + * Start the connection timer. An OTG host is required to display a
  86030. + * message if the device does not connect within 10 seconds. The
  86031. + * timer is deleted if a port connect interrupt occurs before the
  86032. + * timer expires.
  86033. + */
  86034. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  86035. +{
  86036. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  86037. +}
  86038. +
  86039. +/**
  86040. + * HCD Callback function for disconnect of the HCD.
  86041. + *
  86042. + * @param p void pointer to the <code>struct usb_hcd</code>
  86043. + */
  86044. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  86045. +{
  86046. + dwc_otg_hcd_t *dwc_otg_hcd;
  86047. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  86048. + dwc_otg_hcd = p;
  86049. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  86050. + return 1;
  86051. +}
  86052. +
  86053. +/**
  86054. + * HCD Callback function for starting the HCD when A-Cable is
  86055. + * connected.
  86056. + *
  86057. + * @param p void pointer to the <code>struct usb_hcd</code>
  86058. + */
  86059. +static int32_t dwc_otg_hcd_start_cb(void *p)
  86060. +{
  86061. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  86062. + dwc_otg_core_if_t *core_if;
  86063. + hprt0_data_t hprt0;
  86064. +
  86065. + core_if = dwc_otg_hcd->core_if;
  86066. +
  86067. + if (core_if->op_state == B_HOST) {
  86068. + /*
  86069. + * Reset the port. During a HNP mode switch the reset
  86070. + * needs to occur within 1ms and have a duration of at
  86071. + * least 50ms.
  86072. + */
  86073. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  86074. + hprt0.b.prtrst = 1;
  86075. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  86076. + }
  86077. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  86078. + hcd_start_func, dwc_otg_hcd, 50,
  86079. + "start hcd");
  86080. +
  86081. + return 1;
  86082. +}
  86083. +
  86084. +/**
  86085. + * HCD Callback function for disconnect of the HCD.
  86086. + *
  86087. + * @param p void pointer to the <code>struct usb_hcd</code>
  86088. + */
  86089. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  86090. +{
  86091. + gintsts_data_t intr;
  86092. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  86093. +
  86094. + /*
  86095. + * Set status flags for the hub driver.
  86096. + */
  86097. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  86098. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  86099. + if(fiq_enable)
  86100. + local_fiq_disable();
  86101. + /*
  86102. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  86103. + * interrupt mask and status bits and disabling subsequent host
  86104. + * channel interrupts.
  86105. + */
  86106. + intr.d32 = 0;
  86107. + intr.b.nptxfempty = 1;
  86108. + intr.b.ptxfempty = 1;
  86109. + intr.b.hcintr = 1;
  86110. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  86111. + intr.d32, 0);
  86112. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  86113. + intr.d32, 0);
  86114. +
  86115. + del_timers(dwc_otg_hcd);
  86116. +
  86117. + /*
  86118. + * Turn off the vbus power only if the core has transitioned to device
  86119. + * mode. If still in host mode, need to keep power on to detect a
  86120. + * reconnection.
  86121. + */
  86122. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  86123. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  86124. + hprt0_data_t hprt0 = {.d32 = 0 };
  86125. + DWC_PRINTF("Disconnect: PortPower off\n");
  86126. + hprt0.b.prtpwr = 0;
  86127. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  86128. + hprt0.d32);
  86129. + }
  86130. +
  86131. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  86132. + }
  86133. +
  86134. + /* Respond with an error status to all URBs in the schedule. */
  86135. + kill_all_urbs(dwc_otg_hcd);
  86136. +
  86137. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  86138. + /* Clean up any host channels that were in use. */
  86139. + int num_channels;
  86140. + int i;
  86141. + dwc_hc_t *channel;
  86142. + dwc_otg_hc_regs_t *hc_regs;
  86143. + hcchar_data_t hcchar;
  86144. +
  86145. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  86146. +
  86147. + if (!dwc_otg_hcd->core_if->dma_enable) {
  86148. + /* Flush out any channel requests in slave mode. */
  86149. + for (i = 0; i < num_channels; i++) {
  86150. + channel = dwc_otg_hcd->hc_ptr_array[i];
  86151. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  86152. + (channel, hc_list_entry)) {
  86153. + hc_regs =
  86154. + dwc_otg_hcd->core_if->
  86155. + host_if->hc_regs[i];
  86156. + hcchar.d32 =
  86157. + DWC_READ_REG32(&hc_regs->hcchar);
  86158. + if (hcchar.b.chen) {
  86159. + hcchar.b.chen = 0;
  86160. + hcchar.b.chdis = 1;
  86161. + hcchar.b.epdir = 0;
  86162. + DWC_WRITE_REG32
  86163. + (&hc_regs->hcchar,
  86164. + hcchar.d32);
  86165. + }
  86166. + }
  86167. + }
  86168. + }
  86169. +
  86170. + for (i = 0; i < num_channels; i++) {
  86171. + channel = dwc_otg_hcd->hc_ptr_array[i];
  86172. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  86173. + hc_regs =
  86174. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  86175. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  86176. + if (hcchar.b.chen) {
  86177. + /* Halt the channel. */
  86178. + hcchar.b.chdis = 1;
  86179. + DWC_WRITE_REG32(&hc_regs->hcchar,
  86180. + hcchar.d32);
  86181. + }
  86182. +
  86183. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  86184. + channel);
  86185. + DWC_CIRCLEQ_INSERT_TAIL
  86186. + (&dwc_otg_hcd->free_hc_list, channel,
  86187. + hc_list_entry);
  86188. + /*
  86189. + * Added for Descriptor DMA to prevent channel double cleanup
  86190. + * in release_channel_ddma(). Which called from ep_disable
  86191. + * when device disconnect.
  86192. + */
  86193. + channel->qh = NULL;
  86194. + }
  86195. + }
  86196. + if(fiq_fsm_enable) {
  86197. + for(i=0; i < 128; i++) {
  86198. + dwc_otg_hcd->hub_port[i] = 0;
  86199. + }
  86200. + }
  86201. +
  86202. + }
  86203. +
  86204. + if(fiq_enable)
  86205. + local_fiq_enable();
  86206. +
  86207. + if (dwc_otg_hcd->fops->disconnect) {
  86208. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  86209. + }
  86210. +
  86211. + return 1;
  86212. +}
  86213. +
  86214. +/**
  86215. + * HCD Callback function for stopping the HCD.
  86216. + *
  86217. + * @param p void pointer to the <code>struct usb_hcd</code>
  86218. + */
  86219. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  86220. +{
  86221. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  86222. +
  86223. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  86224. + dwc_otg_hcd_stop(dwc_otg_hcd);
  86225. + return 1;
  86226. +}
  86227. +
  86228. +#ifdef CONFIG_USB_DWC_OTG_LPM
  86229. +/**
  86230. + * HCD Callback function for sleep of HCD.
  86231. + *
  86232. + * @param p void pointer to the <code>struct usb_hcd</code>
  86233. + */
  86234. +static int dwc_otg_hcd_sleep_cb(void *p)
  86235. +{
  86236. + dwc_otg_hcd_t *hcd = p;
  86237. +
  86238. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  86239. +
  86240. + return 0;
  86241. +}
  86242. +#endif
  86243. +
  86244. +
  86245. +/**
  86246. + * HCD Callback function for Remote Wakeup.
  86247. + *
  86248. + * @param p void pointer to the <code>struct usb_hcd</code>
  86249. + */
  86250. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  86251. +{
  86252. + dwc_otg_hcd_t *hcd = p;
  86253. +
  86254. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  86255. + hcd->flags.b.port_suspend_change = 1;
  86256. + }
  86257. +#ifdef CONFIG_USB_DWC_OTG_LPM
  86258. + else {
  86259. + hcd->flags.b.port_l1_change = 1;
  86260. + }
  86261. +#endif
  86262. + return 0;
  86263. +}
  86264. +
  86265. +/**
  86266. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  86267. + * stopped.
  86268. + */
  86269. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  86270. +{
  86271. + hprt0_data_t hprt0 = {.d32 = 0 };
  86272. +
  86273. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  86274. +
  86275. + /*
  86276. + * The root hub should be disconnected before this function is called.
  86277. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  86278. + * and the QH lists (via ..._hcd_endpoint_disable).
  86279. + */
  86280. +
  86281. + /* Turn off all host-specific interrupts. */
  86282. + dwc_otg_disable_host_interrupts(hcd->core_if);
  86283. +
  86284. + /* Turn off the vbus power */
  86285. + DWC_PRINTF("PortPower off\n");
  86286. + hprt0.b.prtpwr = 0;
  86287. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  86288. + dwc_mdelay(1);
  86289. +}
  86290. +
  86291. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  86292. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  86293. + int atomic_alloc)
  86294. +{
  86295. + int retval = 0;
  86296. + uint8_t needs_scheduling = 0;
  86297. + dwc_otg_transaction_type_e tr_type;
  86298. + dwc_otg_qtd_t *qtd;
  86299. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86300. + hprt0_data_t hprt0 = { .d32 = 0 };
  86301. +
  86302. +#ifdef DEBUG /* integrity checks (Broadcom) */
  86303. + if (NULL == hcd->core_if) {
  86304. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  86305. + /* No longer connected. */
  86306. + return -DWC_E_INVALID;
  86307. + }
  86308. +#endif
  86309. + if (!hcd->flags.b.port_connect_status) {
  86310. + /* No longer connected. */
  86311. + DWC_ERROR("Not connected\n");
  86312. + return -DWC_E_NO_DEVICE;
  86313. + }
  86314. +
  86315. + /* Some core configurations cannot support LS traffic on a FS root port */
  86316. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  86317. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  86318. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  86319. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  86320. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  86321. + return -DWC_E_NO_DEVICE;
  86322. + }
  86323. + }
  86324. +
  86325. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  86326. + if (qtd == NULL) {
  86327. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  86328. + return -DWC_E_NO_MEMORY;
  86329. + }
  86330. +#ifdef DEBUG /* integrity checks (Broadcom) */
  86331. + if (qtd->urb == NULL) {
  86332. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  86333. + return -DWC_E_NO_MEMORY;
  86334. + }
  86335. + if (qtd->urb->priv == NULL) {
  86336. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  86337. + return -DWC_E_NO_MEMORY;
  86338. + }
  86339. +#endif
  86340. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  86341. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  86342. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  86343. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  86344. + needs_scheduling = 0;
  86345. +
  86346. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  86347. + // creates a new queue in ep_handle if it doesn't exist already
  86348. + if (retval < 0) {
  86349. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  86350. + "Error status %d\n", retval);
  86351. + dwc_otg_hcd_qtd_free(qtd);
  86352. + return retval;
  86353. + }
  86354. +
  86355. + if(needs_scheduling) {
  86356. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  86357. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  86358. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  86359. + }
  86360. + }
  86361. + return retval;
  86362. +}
  86363. +
  86364. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  86365. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  86366. +{
  86367. + dwc_otg_qh_t *qh;
  86368. + dwc_otg_qtd_t *urb_qtd;
  86369. + BUG_ON(!hcd);
  86370. + BUG_ON(!dwc_otg_urb);
  86371. +
  86372. +#ifdef DEBUG /* integrity checks (Broadcom) */
  86373. +
  86374. + if (hcd == NULL) {
  86375. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  86376. + return -DWC_E_INVALID;
  86377. + }
  86378. + if (dwc_otg_urb == NULL) {
  86379. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  86380. + return -DWC_E_INVALID;
  86381. + }
  86382. + if (dwc_otg_urb->qtd == NULL) {
  86383. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  86384. + return -DWC_E_INVALID;
  86385. + }
  86386. + urb_qtd = dwc_otg_urb->qtd;
  86387. + BUG_ON(!urb_qtd);
  86388. + if (urb_qtd->qh == NULL) {
  86389. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  86390. + return -DWC_E_INVALID;
  86391. + }
  86392. +#else
  86393. + urb_qtd = dwc_otg_urb->qtd;
  86394. + BUG_ON(!urb_qtd);
  86395. +#endif
  86396. + qh = urb_qtd->qh;
  86397. + BUG_ON(!qh);
  86398. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  86399. + if (urb_qtd->in_process) {
  86400. + dump_channel_info(hcd, qh);
  86401. + }
  86402. + }
  86403. +#ifdef DEBUG /* integrity checks (Broadcom) */
  86404. + if (hcd->core_if == NULL) {
  86405. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  86406. + return -DWC_E_INVALID;
  86407. + }
  86408. +#endif
  86409. + if (urb_qtd->in_process && qh->channel) {
  86410. + /* The QTD is in process (it has been assigned to a channel). */
  86411. + if (hcd->flags.b.port_connect_status) {
  86412. + int n = qh->channel->hc_num;
  86413. + /*
  86414. + * If still connected (i.e. in host mode), halt the
  86415. + * channel so it can be used for other transfers. If
  86416. + * no longer connected, the host registers can't be
  86417. + * written to halt the channel since the core is in
  86418. + * device mode.
  86419. + */
  86420. + /* In FIQ FSM mode, we need to shut down carefully.
  86421. + * The FIQ may attempt to restart a disabled channel */
  86422. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  86423. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  86424. + qh->channel->halt_pending = 1;
  86425. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  86426. + } else {
  86427. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  86428. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  86429. + }
  86430. + }
  86431. + }
  86432. +
  86433. + /*
  86434. + * Free the QTD and clean up the associated QH. Leave the QH in the
  86435. + * schedule if it has any remaining QTDs.
  86436. + */
  86437. +
  86438. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  86439. + "delete %sQueue handler\n",
  86440. + hcd->core_if->dma_desc_enable?"DMA ":"");
  86441. + if (!hcd->core_if->dma_desc_enable) {
  86442. + uint8_t b = urb_qtd->in_process;
  86443. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  86444. + if (b) {
  86445. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  86446. + qh->channel = NULL;
  86447. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  86448. + dwc_otg_hcd_qh_remove(hcd, qh);
  86449. + }
  86450. + } else {
  86451. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  86452. + }
  86453. + return 0;
  86454. +}
  86455. +
  86456. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  86457. + int retry)
  86458. +{
  86459. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  86460. + int retval = 0;
  86461. + dwc_irqflags_t flags;
  86462. +
  86463. + if (retry < 0) {
  86464. + retval = -DWC_E_INVALID;
  86465. + goto done;
  86466. + }
  86467. +
  86468. + if (!qh) {
  86469. + retval = -DWC_E_INVALID;
  86470. + goto done;
  86471. + }
  86472. +
  86473. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86474. +
  86475. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  86476. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86477. + retry--;
  86478. + dwc_msleep(5);
  86479. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86480. + }
  86481. +
  86482. + dwc_otg_hcd_qh_remove(hcd, qh);
  86483. +
  86484. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86485. + /*
  86486. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  86487. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  86488. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  86489. + * and dwc_otg_hcd_frame_list_alloc().
  86490. + */
  86491. + dwc_otg_hcd_qh_free(hcd, qh);
  86492. +
  86493. +done:
  86494. + return retval;
  86495. +}
  86496. +
  86497. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  86498. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  86499. +{
  86500. + int retval = 0;
  86501. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  86502. + if (!qh)
  86503. + return -DWC_E_INVALID;
  86504. +
  86505. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  86506. + return retval;
  86507. +}
  86508. +#endif
  86509. +
  86510. +/**
  86511. + * HCD Callback structure for handling mode switching.
  86512. + */
  86513. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  86514. + .start = dwc_otg_hcd_start_cb,
  86515. + .stop = dwc_otg_hcd_stop_cb,
  86516. + .disconnect = dwc_otg_hcd_disconnect_cb,
  86517. + .session_start = dwc_otg_hcd_session_start_cb,
  86518. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  86519. +#ifdef CONFIG_USB_DWC_OTG_LPM
  86520. + .sleep = dwc_otg_hcd_sleep_cb,
  86521. +#endif
  86522. + .p = 0,
  86523. +};
  86524. +
  86525. +/**
  86526. + * Reset tasklet function
  86527. + */
  86528. +static void reset_tasklet_func(void *data)
  86529. +{
  86530. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  86531. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  86532. + hprt0_data_t hprt0;
  86533. +
  86534. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  86535. +
  86536. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  86537. + hprt0.b.prtrst = 1;
  86538. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  86539. + dwc_mdelay(60);
  86540. +
  86541. + hprt0.b.prtrst = 0;
  86542. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  86543. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  86544. +}
  86545. +
  86546. +static void completion_tasklet_func(void *ptr)
  86547. +{
  86548. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  86549. + struct urb *urb;
  86550. + urb_tq_entry_t *item;
  86551. + dwc_irqflags_t flags;
  86552. +
  86553. + /* This could just be spin_lock_irq */
  86554. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86555. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  86556. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  86557. + urb = item->urb;
  86558. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  86559. + urb_tq_entries);
  86560. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86561. + DWC_FREE(item);
  86562. +
  86563. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  86564. +
  86565. +
  86566. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86567. + }
  86568. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86569. + return;
  86570. +}
  86571. +
  86572. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  86573. +{
  86574. + dwc_list_link_t *item;
  86575. + dwc_otg_qh_t *qh;
  86576. + dwc_irqflags_t flags;
  86577. +
  86578. + if (!qh_list->next) {
  86579. + /* The list hasn't been initialized yet. */
  86580. + return;
  86581. + }
  86582. + /*
  86583. + * Hold spinlock here. Not needed in that case if bellow
  86584. + * function is being called from ISR
  86585. + */
  86586. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  86587. + /* Ensure there are no QTDs or URBs left. */
  86588. + kill_urbs_in_qh_list(hcd, qh_list);
  86589. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  86590. +
  86591. + DWC_LIST_FOREACH(item, qh_list) {
  86592. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  86593. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  86594. + }
  86595. +}
  86596. +
  86597. +/**
  86598. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  86599. + * Device during SRP time by host power up.
  86600. + */
  86601. +void dwc_otg_hcd_power_up(void *ptr)
  86602. +{
  86603. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  86604. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  86605. +
  86606. + DWC_PRINTF("%s called\n", __FUNCTION__);
  86607. +
  86608. + if (!core_if->hibernation_suspend) {
  86609. + DWC_PRINTF("Already exited from Hibernation\n");
  86610. + return;
  86611. + }
  86612. +
  86613. + /* Switch on the voltage to the core */
  86614. + gpwrdn.b.pwrdnswtch = 1;
  86615. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86616. + dwc_udelay(10);
  86617. +
  86618. + /* Reset the core */
  86619. + gpwrdn.d32 = 0;
  86620. + gpwrdn.b.pwrdnrstn = 1;
  86621. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86622. + dwc_udelay(10);
  86623. +
  86624. + /* Disable power clamps */
  86625. + gpwrdn.d32 = 0;
  86626. + gpwrdn.b.pwrdnclmp = 1;
  86627. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86628. +
  86629. + /* Remove reset the core signal */
  86630. + gpwrdn.d32 = 0;
  86631. + gpwrdn.b.pwrdnrstn = 1;
  86632. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  86633. + dwc_udelay(10);
  86634. +
  86635. + /* Disable PMU interrupt */
  86636. + gpwrdn.d32 = 0;
  86637. + gpwrdn.b.pmuintsel = 1;
  86638. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86639. +
  86640. + core_if->hibernation_suspend = 0;
  86641. +
  86642. + /* Disable PMU */
  86643. + gpwrdn.d32 = 0;
  86644. + gpwrdn.b.pmuactv = 1;
  86645. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86646. + dwc_udelay(10);
  86647. +
  86648. + /* Enable VBUS */
  86649. + gpwrdn.d32 = 0;
  86650. + gpwrdn.b.dis_vbus = 1;
  86651. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  86652. +
  86653. + core_if->op_state = A_HOST;
  86654. + dwc_otg_core_init(core_if);
  86655. + dwc_otg_enable_global_interrupts(core_if);
  86656. + cil_hcd_start(core_if);
  86657. +}
  86658. +
  86659. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  86660. +{
  86661. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  86662. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  86663. + int i;
  86664. +
  86665. + st->fsm = FIQ_PASSTHROUGH;
  86666. + st->hcchar_copy.d32 = 0;
  86667. + st->hcsplt_copy.d32 = 0;
  86668. + st->hcint_copy.d32 = 0;
  86669. + st->hcintmsk_copy.d32 = 0;
  86670. + st->hctsiz_copy.d32 = 0;
  86671. + st->hcdma_copy.d32 = 0;
  86672. + st->nr_errors = 0;
  86673. + st->hub_addr = 0;
  86674. + st->port_addr = 0;
  86675. + st->expected_uframe = 0;
  86676. + st->nrpackets = 0;
  86677. + st->dma_info.index = 0;
  86678. + for (i = 0; i < 6; i++)
  86679. + st->dma_info.slot_len[i] = 255;
  86680. + st->hs_isoc_info.index = 0;
  86681. + st->hs_isoc_info.iso_desc = NULL;
  86682. + st->hs_isoc_info.nrframes = 0;
  86683. +
  86684. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  86685. +}
  86686. +
  86687. +/**
  86688. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  86689. + * in the struct usb_hcd field.
  86690. + */
  86691. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  86692. +{
  86693. + int i;
  86694. +
  86695. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  86696. +
  86697. + del_timers(dwc_otg_hcd);
  86698. +
  86699. + /* Free memory for QH/QTD lists */
  86700. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  86701. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  86702. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  86703. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  86704. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  86705. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  86706. +
  86707. + /* Free memory for the host channels. */
  86708. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  86709. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  86710. +
  86711. +#ifdef DEBUG
  86712. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  86713. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  86714. + }
  86715. +#endif
  86716. + if (hc != NULL) {
  86717. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  86718. + i, hc);
  86719. + DWC_FREE(hc);
  86720. + }
  86721. + }
  86722. +
  86723. + if (dwc_otg_hcd->core_if->dma_enable) {
  86724. + if (dwc_otg_hcd->status_buf_dma) {
  86725. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  86726. + dwc_otg_hcd->status_buf,
  86727. + dwc_otg_hcd->status_buf_dma);
  86728. + }
  86729. + } else if (dwc_otg_hcd->status_buf != NULL) {
  86730. + DWC_FREE(dwc_otg_hcd->status_buf);
  86731. + }
  86732. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  86733. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  86734. + /* Set core_if's lock pointer to NULL */
  86735. + dwc_otg_hcd->core_if->lock = NULL;
  86736. +
  86737. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  86738. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  86739. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  86740. + DWC_FREE(dwc_otg_hcd->fiq_state);
  86741. +
  86742. +#ifdef DWC_DEV_SRPCAP
  86743. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  86744. + dwc_otg_hcd->core_if->pwron_timer) {
  86745. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  86746. + }
  86747. +#endif
  86748. + DWC_FREE(dwc_otg_hcd);
  86749. +}
  86750. +
  86751. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  86752. +
  86753. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  86754. +{
  86755. + int retval = 0;
  86756. + int num_channels;
  86757. + int i;
  86758. + dwc_hc_t *channel;
  86759. +
  86760. + hcd->lock = DWC_SPINLOCK_ALLOC();
  86761. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  86762. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  86763. + hcd, core_if);
  86764. + if (!hcd->lock) {
  86765. + DWC_ERROR("Could not allocate lock for pcd");
  86766. + DWC_FREE(hcd);
  86767. + retval = -DWC_E_NO_MEMORY;
  86768. + goto out;
  86769. + }
  86770. + hcd->core_if = core_if;
  86771. +
  86772. + /* Register the HCD CIL Callbacks */
  86773. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  86774. + &hcd_cil_callbacks, hcd);
  86775. +
  86776. + /* Initialize the non-periodic schedule. */
  86777. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  86778. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  86779. +
  86780. + /* Initialize the periodic schedule. */
  86781. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  86782. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  86783. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  86784. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  86785. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  86786. + /*
  86787. + * Create a host channel descriptor for each host channel implemented
  86788. + * in the controller. Initialize the channel descriptor array.
  86789. + */
  86790. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  86791. + num_channels = hcd->core_if->core_params->host_channels;
  86792. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  86793. + for (i = 0; i < num_channels; i++) {
  86794. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  86795. + if (channel == NULL) {
  86796. + retval = -DWC_E_NO_MEMORY;
  86797. + DWC_ERROR("%s: host channel allocation failed\n",
  86798. + __func__);
  86799. + dwc_otg_hcd_free(hcd);
  86800. + goto out;
  86801. + }
  86802. + channel->hc_num = i;
  86803. + hcd->hc_ptr_array[i] = channel;
  86804. +#ifdef DEBUG
  86805. + hcd->core_if->hc_xfer_timer[i] =
  86806. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  86807. + &hcd->core_if->hc_xfer_info[i]);
  86808. +#endif
  86809. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  86810. + channel);
  86811. + }
  86812. +
  86813. + if (fiq_enable) {
  86814. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  86815. + if (!hcd->fiq_state) {
  86816. + retval = -DWC_E_NO_MEMORY;
  86817. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  86818. + dwc_otg_hcd_free(hcd);
  86819. + goto out;
  86820. + }
  86821. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  86822. +
  86823. + for (i = 0; i < num_channels; i++) {
  86824. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  86825. + }
  86826. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  86827. +
  86828. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  86829. + if (!hcd->fiq_stack) {
  86830. + retval = -DWC_E_NO_MEMORY;
  86831. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  86832. + dwc_otg_hcd_free(hcd);
  86833. + goto out;
  86834. + }
  86835. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  86836. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  86837. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  86838. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  86839. +
  86840. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  86841. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  86842. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  86843. + * moderately readable array casts.
  86844. + */
  86845. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  86846. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  86847. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  86848. + sizeof(struct fiq_dma_channel) * num_channels);
  86849. +
  86850. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  86851. +
  86852. + /* pointer for debug in fiq_print */
  86853. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  86854. + if (fiq_fsm_enable) {
  86855. + int i;
  86856. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  86857. + dwc_otg_cleanup_fiq_channel(hcd, i);
  86858. + }
  86859. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s%s",
  86860. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  86861. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  86862. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "",
  86863. + (fiq_fsm_mask & 0x8) ? "Interrupt/Control Split Transaction hack enabled\n" : "");
  86864. + }
  86865. + }
  86866. +
  86867. + /* Initialize the Connection timeout timer. */
  86868. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  86869. + dwc_otg_hcd_connect_timeout, 0);
  86870. +
  86871. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  86872. + if (microframe_schedule)
  86873. + init_hcd_usecs(hcd);
  86874. +
  86875. + /* Initialize reset tasklet. */
  86876. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  86877. +
  86878. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  86879. + completion_tasklet_func, hcd);
  86880. +#ifdef DWC_DEV_SRPCAP
  86881. + if (hcd->core_if->power_down == 2) {
  86882. + /* Initialize Power on timer for Host power up in case hibernation */
  86883. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  86884. + dwc_otg_hcd_power_up, core_if);
  86885. + }
  86886. +#endif
  86887. +
  86888. + /*
  86889. + * Allocate space for storing data on status transactions. Normally no
  86890. + * data is sent, but this space acts as a bit bucket. This must be
  86891. + * done after usb_add_hcd since that function allocates the DMA buffer
  86892. + * pool.
  86893. + */
  86894. + if (hcd->core_if->dma_enable) {
  86895. + hcd->status_buf =
  86896. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  86897. + &hcd->status_buf_dma);
  86898. + } else {
  86899. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  86900. + }
  86901. + if (!hcd->status_buf) {
  86902. + retval = -DWC_E_NO_MEMORY;
  86903. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  86904. + dwc_otg_hcd_free(hcd);
  86905. + goto out;
  86906. + }
  86907. +
  86908. + hcd->otg_port = 1;
  86909. + hcd->frame_list = NULL;
  86910. + hcd->frame_list_dma = 0;
  86911. + hcd->periodic_qh_count = 0;
  86912. +
  86913. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  86914. +#ifdef FIQ_DEBUG
  86915. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  86916. +#endif
  86917. +
  86918. +out:
  86919. + return retval;
  86920. +}
  86921. +
  86922. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  86923. +{
  86924. + /* Turn off all host-specific interrupts. */
  86925. + dwc_otg_disable_host_interrupts(hcd->core_if);
  86926. +
  86927. + dwc_otg_hcd_free(hcd);
  86928. +}
  86929. +
  86930. +/**
  86931. + * Initializes dynamic portions of the DWC_otg HCD state.
  86932. + */
  86933. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  86934. +{
  86935. + int num_channels;
  86936. + int i;
  86937. + dwc_hc_t *channel;
  86938. + dwc_hc_t *channel_tmp;
  86939. +
  86940. + hcd->flags.d32 = 0;
  86941. +
  86942. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  86943. + if (!microframe_schedule) {
  86944. + hcd->non_periodic_channels = 0;
  86945. + hcd->periodic_channels = 0;
  86946. + } else {
  86947. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  86948. + }
  86949. + /*
  86950. + * Put all channels in the free channel list and clean up channel
  86951. + * states.
  86952. + */
  86953. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  86954. + &hcd->free_hc_list, hc_list_entry) {
  86955. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  86956. + }
  86957. +
  86958. + num_channels = hcd->core_if->core_params->host_channels;
  86959. + for (i = 0; i < num_channels; i++) {
  86960. + channel = hcd->hc_ptr_array[i];
  86961. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  86962. + hc_list_entry);
  86963. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  86964. + }
  86965. +
  86966. + /* Initialize the DWC core for host mode operation. */
  86967. + dwc_otg_core_host_init(hcd->core_if);
  86968. +
  86969. + /* Set core_if's lock pointer to the hcd->lock */
  86970. + hcd->core_if->lock = hcd->lock;
  86971. +}
  86972. +
  86973. +/**
  86974. + * Assigns transactions from a QTD to a free host channel and initializes the
  86975. + * host channel to perform the transactions. The host channel is removed from
  86976. + * the free list.
  86977. + *
  86978. + * @param hcd The HCD state structure.
  86979. + * @param qh Transactions from the first QTD for this QH are selected and
  86980. + * assigned to a free host channel.
  86981. + */
  86982. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  86983. +{
  86984. + dwc_hc_t *hc;
  86985. + dwc_otg_qtd_t *qtd;
  86986. + dwc_otg_hcd_urb_t *urb;
  86987. + void* ptr = NULL;
  86988. +
  86989. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  86990. +
  86991. + urb = qtd->urb;
  86992. +
  86993. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  86994. +
  86995. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  86996. + urb->actual_length = urb->length;
  86997. +
  86998. +
  86999. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  87000. +
  87001. + /* Remove the host channel from the free list. */
  87002. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  87003. +
  87004. + qh->channel = hc;
  87005. +
  87006. + qtd->in_process = 1;
  87007. +
  87008. + /*
  87009. + * Use usb_pipedevice to determine device address. This address is
  87010. + * 0 before the SET_ADDRESS command and the correct address afterward.
  87011. + */
  87012. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  87013. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  87014. + hc->speed = qh->dev_speed;
  87015. + hc->max_packet = dwc_max_packet(qh->maxp);
  87016. +
  87017. + hc->xfer_started = 0;
  87018. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  87019. + hc->error_state = (qtd->error_count > 0);
  87020. + hc->halt_on_queue = 0;
  87021. + hc->halt_pending = 0;
  87022. + hc->requests = 0;
  87023. +
  87024. + /*
  87025. + * The following values may be modified in the transfer type section
  87026. + * below. The xfer_len value may be reduced when the transfer is
  87027. + * started to accommodate the max widths of the XferSize and PktCnt
  87028. + * fields in the HCTSIZn register.
  87029. + */
  87030. +
  87031. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  87032. + if (hc->ep_is_in) {
  87033. + hc->do_ping = 0;
  87034. + } else {
  87035. + hc->do_ping = qh->ping_state;
  87036. + }
  87037. +
  87038. + hc->data_pid_start = qh->data_toggle;
  87039. + hc->multi_count = 1;
  87040. +
  87041. + if (hcd->core_if->dma_enable) {
  87042. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  87043. +
  87044. + /* For non-dword aligned case */
  87045. + if (((unsigned long)hc->xfer_buff & 0x3)
  87046. + && !hcd->core_if->dma_desc_enable) {
  87047. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  87048. + }
  87049. + } else {
  87050. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  87051. + }
  87052. + hc->xfer_len = urb->length - urb->actual_length;
  87053. + hc->xfer_count = 0;
  87054. +
  87055. + /*
  87056. + * Set the split attributes
  87057. + */
  87058. + hc->do_split = 0;
  87059. + if (qh->do_split) {
  87060. + uint32_t hub_addr, port_addr;
  87061. + hc->do_split = 1;
  87062. + hc->xact_pos = qtd->isoc_split_pos;
  87063. + /* We don't need to do complete splits anymore */
  87064. +// if(fiq_fsm_enable)
  87065. + if (0)
  87066. + hc->complete_split = qtd->complete_split = 0;
  87067. + else
  87068. + hc->complete_split = qtd->complete_split;
  87069. +
  87070. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  87071. + hc->hub_addr = (uint8_t) hub_addr;
  87072. + hc->port_addr = (uint8_t) port_addr;
  87073. + }
  87074. +
  87075. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  87076. + case UE_CONTROL:
  87077. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  87078. + switch (qtd->control_phase) {
  87079. + case DWC_OTG_CONTROL_SETUP:
  87080. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  87081. + hc->do_ping = 0;
  87082. + hc->ep_is_in = 0;
  87083. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  87084. + if (hcd->core_if->dma_enable) {
  87085. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  87086. + } else {
  87087. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  87088. + }
  87089. + hc->xfer_len = 8;
  87090. + ptr = NULL;
  87091. + break;
  87092. + case DWC_OTG_CONTROL_DATA:
  87093. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  87094. + hc->data_pid_start = qtd->data_toggle;
  87095. + break;
  87096. + case DWC_OTG_CONTROL_STATUS:
  87097. + /*
  87098. + * Direction is opposite of data direction or IN if no
  87099. + * data.
  87100. + */
  87101. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  87102. + if (urb->length == 0) {
  87103. + hc->ep_is_in = 1;
  87104. + } else {
  87105. + hc->ep_is_in =
  87106. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  87107. + }
  87108. + if (hc->ep_is_in) {
  87109. + hc->do_ping = 0;
  87110. + }
  87111. +
  87112. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  87113. +
  87114. + hc->xfer_len = 0;
  87115. + if (hcd->core_if->dma_enable) {
  87116. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  87117. + } else {
  87118. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  87119. + }
  87120. + ptr = NULL;
  87121. + break;
  87122. + }
  87123. + break;
  87124. + case UE_BULK:
  87125. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  87126. + break;
  87127. + case UE_INTERRUPT:
  87128. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  87129. + break;
  87130. + case UE_ISOCHRONOUS:
  87131. + {
  87132. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  87133. +
  87134. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  87135. +
  87136. + if (hcd->core_if->dma_desc_enable)
  87137. + break;
  87138. +
  87139. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  87140. +
  87141. + frame_desc->status = 0;
  87142. +
  87143. + if (hcd->core_if->dma_enable) {
  87144. + hc->xfer_buff = (uint8_t *) urb->dma;
  87145. + } else {
  87146. + hc->xfer_buff = (uint8_t *) urb->buf;
  87147. + }
  87148. + hc->xfer_buff +=
  87149. + frame_desc->offset + qtd->isoc_split_offset;
  87150. + hc->xfer_len =
  87151. + frame_desc->length - qtd->isoc_split_offset;
  87152. +
  87153. + /* For non-dword aligned buffers */
  87154. + if (((unsigned long)hc->xfer_buff & 0x3)
  87155. + && hcd->core_if->dma_enable) {
  87156. + ptr =
  87157. + (uint8_t *) urb->buf + frame_desc->offset +
  87158. + qtd->isoc_split_offset;
  87159. + } else
  87160. + ptr = NULL;
  87161. +
  87162. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  87163. + if (hc->xfer_len <= 188) {
  87164. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  87165. + } else {
  87166. + hc->xact_pos =
  87167. + DWC_HCSPLIT_XACTPOS_BEGIN;
  87168. + }
  87169. + }
  87170. + }
  87171. + break;
  87172. + }
  87173. + /* non DWORD-aligned buffer case */
  87174. + if (ptr) {
  87175. + uint32_t buf_size;
  87176. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  87177. + buf_size = hcd->core_if->core_params->max_transfer_size;
  87178. + } else {
  87179. + buf_size = 4096;
  87180. + }
  87181. + if (!qh->dw_align_buf) {
  87182. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  87183. + &qh->dw_align_buf_dma);
  87184. + if (!qh->dw_align_buf) {
  87185. + DWC_ERROR
  87186. + ("%s: Failed to allocate memory to handle "
  87187. + "non-dword aligned buffer case\n",
  87188. + __func__);
  87189. + return;
  87190. + }
  87191. + }
  87192. + if (!hc->ep_is_in) {
  87193. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  87194. + }
  87195. + hc->align_buff = qh->dw_align_buf_dma;
  87196. + } else {
  87197. + hc->align_buff = 0;
  87198. + }
  87199. +
  87200. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  87201. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  87202. + /*
  87203. + * This value may be modified when the transfer is started to
  87204. + * reflect the actual transfer length.
  87205. + */
  87206. + hc->multi_count = dwc_hb_mult(qh->maxp);
  87207. + }
  87208. +
  87209. + if (hcd->core_if->dma_desc_enable)
  87210. + hc->desc_list_addr = qh->desc_list_dma;
  87211. +
  87212. + dwc_otg_hc_init(hcd->core_if, hc);
  87213. + hc->qh = qh;
  87214. +}
  87215. +
  87216. +
  87217. +/**
  87218. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  87219. + * @qh: pointer to the endpoint's queue head
  87220. + *
  87221. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  87222. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  87223. + * This function's eligibility check is altered by debug parameter.
  87224. + *
  87225. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  87226. + */
  87227. +
  87228. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  87229. +{
  87230. + if (qh->do_split) {
  87231. + switch (qh->ep_type) {
  87232. + case UE_CONTROL:
  87233. + case UE_BULK:
  87234. + if (fiq_fsm_mask & (1 << 0))
  87235. + return 1;
  87236. + break;
  87237. + case UE_INTERRUPT:
  87238. + case UE_ISOCHRONOUS:
  87239. + if (fiq_fsm_mask & (1 << 1))
  87240. + return 1;
  87241. + break;
  87242. + default:
  87243. + break;
  87244. + }
  87245. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  87246. + if (fiq_fsm_mask & (1 << 2)) {
  87247. + /* HS ISOCH support. We test for compatibility:
  87248. + * - DWORD aligned buffers
  87249. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  87250. + * If yes, then the fsm enqueue function will handle the state machine setup.
  87251. + */
  87252. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  87253. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  87254. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  87255. + int nr_iso_frames = urb->packet_count;
  87256. + int i;
  87257. + uint32_t ptr;
  87258. +
  87259. + if (nr_iso_frames < 2)
  87260. + return 0;
  87261. + for (i = 0; i < nr_iso_frames; i++) {
  87262. + ptr = urb->dma + iso_descs[i]->offset;
  87263. + if (ptr & 0x3) {
  87264. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  87265. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  87266. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  87267. + return 0;
  87268. + }
  87269. + }
  87270. + return 1;
  87271. + }
  87272. + }
  87273. + return 0;
  87274. +}
  87275. +
  87276. +/**
  87277. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  87278. + * @hcd: Pointer to the dwc_otg_hcd struct
  87279. + * @qh: Pointer to the endpoint's queue head
  87280. + *
  87281. + * Periodic split transactions are transmitted modulo 188 bytes.
  87282. + * This necessitates slicing data up into buckets for isochronous out
  87283. + * and fixing up the DMA address for all IN transfers.
  87284. + *
  87285. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  87286. + * HC buffer has been used.
  87287. + */
  87288. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  87289. + {
  87290. + int frame_length, i = 0;
  87291. + uint8_t *ptr = NULL;
  87292. + dwc_hc_t *hc = qh->channel;
  87293. + struct fiq_dma_blob *blob;
  87294. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  87295. +
  87296. + for (i = 0; i < 6; i++) {
  87297. + st->dma_info.slot_len[i] = 255;
  87298. + }
  87299. + st->dma_info.index = 0;
  87300. + i = 0;
  87301. + if (hc->ep_is_in) {
  87302. + /*
  87303. + * Set dma_regs to bounce buffer. FIQ will update the
  87304. + * state depending on transaction progress.
  87305. + */
  87306. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  87307. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  87308. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  87309. + * a transaction if it fails.
  87310. + */
  87311. + frame_length = st->hcchar_copy.b.mps;
  87312. + do {
  87313. + i++;
  87314. + frame_length -= 188;
  87315. + } while (frame_length >= 0);
  87316. + st->nrpackets = i;
  87317. + return 1;
  87318. + } else {
  87319. + if (qh->ep_type == UE_ISOCHRONOUS) {
  87320. +
  87321. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  87322. +
  87323. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  87324. + frame_length = frame_desc->length;
  87325. +
  87326. + /* Virtual address for bounce buffers */
  87327. + blob = hcd->fiq_dmab;
  87328. +
  87329. + ptr = qtd->urb->buf + frame_desc->offset;
  87330. + if (frame_length == 0) {
  87331. + /*
  87332. + * for isochronous transactions, we must still transmit a packet
  87333. + * even if the length is zero.
  87334. + */
  87335. + st->dma_info.slot_len[0] = 0;
  87336. + st->nrpackets = 1;
  87337. + } else {
  87338. + do {
  87339. + if (frame_length <= 188) {
  87340. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  87341. + st->dma_info.slot_len[i] = frame_length;
  87342. + ptr += frame_length;
  87343. + } else {
  87344. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  87345. + st->dma_info.slot_len[i] = 188;
  87346. + ptr += 188;
  87347. + }
  87348. + i++;
  87349. + frame_length -= 188;
  87350. + } while (frame_length > 0);
  87351. + st->nrpackets = i;
  87352. + }
  87353. + ptr = qtd->urb->buf + frame_desc->offset;
  87354. + /* Point the HC at the DMA address of the bounce buffers */
  87355. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  87356. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  87357. +
  87358. + /* fixup xfersize to the actual packet size */
  87359. + st->hctsiz_copy.b.pid = 0;
  87360. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  87361. + return 1;
  87362. + } else {
  87363. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  87364. + return 0;
  87365. + }
  87366. + }
  87367. +}
  87368. +
  87369. +/*
  87370. + * Pushing a periodic request into the queue near the EOF1 point
  87371. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  87372. + * Usually, the request goes out on the bus causing a transfer but
  87373. + * the core does not transfer the data to memory.
  87374. + * This guard interval (in number of 60MHz clocks) is required which
  87375. + * must cater for CPU latency between reading the value and enabling
  87376. + * the channel.
  87377. + */
  87378. +#define PERIODIC_FRREM_BACKOFF 1000
  87379. +
  87380. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  87381. +{
  87382. + dwc_hc_t *hc = qh->channel;
  87383. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  87384. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  87385. + int frame;
  87386. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  87387. + int xfer_len, nrpackets;
  87388. + hcdma_data_t hcdma;
  87389. + hfnum_data_t hfnum;
  87390. +
  87391. + if (st->fsm != FIQ_PASSTHROUGH)
  87392. + return 0;
  87393. +
  87394. + st->nr_errors = 0;
  87395. +
  87396. + st->hcchar_copy.d32 = 0;
  87397. + st->hcchar_copy.b.mps = hc->max_packet;
  87398. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  87399. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  87400. + st->hcchar_copy.b.epnum = hc->ep_num;
  87401. + st->hcchar_copy.b.eptype = hc->ep_type;
  87402. +
  87403. + st->hcintmsk_copy.b.chhltd = 1;
  87404. +
  87405. + frame = dwc_otg_hcd_get_frame_number(hcd);
  87406. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  87407. +
  87408. + st->hcchar_copy.b.lspddev = 0;
  87409. + /* Enable the channel later as a final register write. */
  87410. +
  87411. + st->hcsplt_copy.d32 = 0;
  87412. +
  87413. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  87414. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  87415. + /* grab the next DMA address offset from the array */
  87416. + st->hcdma_copy.d32 = qtd->urb->dma;
  87417. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  87418. +
  87419. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  87420. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  87421. + * this is always set to the maximum size of the endpoint. */
  87422. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  87423. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  87424. + if (nrpackets == 0)
  87425. + nrpackets = 1;
  87426. + st->hcchar_copy.b.multicnt = nrpackets;
  87427. + st->hctsiz_copy.b.pktcnt = nrpackets;
  87428. +
  87429. + /* Initial PID also needs to be set */
  87430. + if (st->hcchar_copy.b.epdir == 0) {
  87431. + st->hctsiz_copy.b.xfersize = xfer_len;
  87432. + switch (st->hcchar_copy.b.multicnt) {
  87433. + case 1:
  87434. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  87435. + break;
  87436. + case 2:
  87437. + case 3:
  87438. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  87439. + break;
  87440. + }
  87441. +
  87442. + } else {
  87443. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  87444. + switch (st->hcchar_copy.b.multicnt) {
  87445. + case 1:
  87446. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  87447. + break;
  87448. + case 2:
  87449. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  87450. + break;
  87451. + case 3:
  87452. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  87453. + break;
  87454. + }
  87455. + }
  87456. +
  87457. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  87458. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  87459. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  87460. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  87461. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  87462. + local_fiq_disable();
  87463. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  87464. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  87465. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  87466. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87467. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  87468. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  87469. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  87470. + * split transaction is queued very close to EOF.
  87471. + */
  87472. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  87473. + } else {
  87474. + st->fsm = FIQ_HS_ISOC_TURBO;
  87475. + st->hcchar_copy.b.chen = 1;
  87476. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87477. + }
  87478. + mb();
  87479. + st->hcchar_copy.b.chen = 0;
  87480. + local_fiq_enable();
  87481. + return 0;
  87482. +}
  87483. +
  87484. +
  87485. +/**
  87486. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  87487. + * @hcd: Pointer to the dwc_otg_hcd struct
  87488. + * @qh: Pointer to the endpoint's queue head
  87489. + *
  87490. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  87491. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  87492. + * for the nominated host channel.
  87493. + *
  87494. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  87495. + * start is possible. If not, then the FIQ is left to start the transfer.
  87496. + */
  87497. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  87498. +{
  87499. + int start_immediate = 1, i;
  87500. + hfnum_data_t hfnum;
  87501. + dwc_hc_t *hc = qh->channel;
  87502. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  87503. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  87504. + int hub_addr, port_addr, frame, uframe;
  87505. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  87506. +
  87507. + if (st->fsm != FIQ_PASSTHROUGH)
  87508. + return 0;
  87509. + st->nr_errors = 0;
  87510. +
  87511. + st->hcchar_copy.d32 = 0;
  87512. + st->hcchar_copy.b.mps = hc->max_packet;
  87513. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  87514. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  87515. + st->hcchar_copy.b.epnum = hc->ep_num;
  87516. + st->hcchar_copy.b.eptype = hc->ep_type;
  87517. + if (hc->ep_type & 0x1) {
  87518. + if (hc->ep_is_in)
  87519. + st->hcchar_copy.b.multicnt = 3;
  87520. + else
  87521. + /* Docs say set this to 1, but driver sets to 0! */
  87522. + st->hcchar_copy.b.multicnt = 0;
  87523. + } else {
  87524. + st->hcchar_copy.b.multicnt = 1;
  87525. + st->hcchar_copy.b.oddfrm = 0;
  87526. + }
  87527. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  87528. + /* Enable the channel later as a final register write. */
  87529. +
  87530. + st->hcsplt_copy.d32 = 0;
  87531. + if(qh->do_split) {
  87532. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  87533. + st->hcsplt_copy.b.compsplt = 0;
  87534. + st->hcsplt_copy.b.spltena = 1;
  87535. + // XACTPOS is for isoc-out only but needs initialising anyway.
  87536. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  87537. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  87538. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  87539. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  87540. + * will update as necessary.
  87541. + */
  87542. + if (hc->xfer_len > 188) {
  87543. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  87544. + }
  87545. + }
  87546. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  87547. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  87548. + st->hub_addr = hub_addr;
  87549. + st->port_addr = port_addr;
  87550. + }
  87551. +
  87552. + st->hctsiz_copy.d32 = 0;
  87553. + st->hctsiz_copy.b.dopng = 0;
  87554. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  87555. +
  87556. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  87557. + hc->xfer_len = hc->max_packet;
  87558. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  87559. + hc->xfer_len = 188;
  87560. + }
  87561. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  87562. +
  87563. + st->hctsiz_copy.b.pktcnt = 1;
  87564. +
  87565. + if (hc->ep_type & 0x1) {
  87566. + /*
  87567. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  87568. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  87569. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  87570. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  87571. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  87572. + * must not touch internal driver state.
  87573. + */
  87574. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  87575. + if (hc->align_buff) {
  87576. + st->hcdma_copy.d32 = hc->align_buff;
  87577. + } else {
  87578. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87579. + }
  87580. + }
  87581. + } else {
  87582. + if (hc->align_buff) {
  87583. + st->hcdma_copy.d32 = hc->align_buff;
  87584. + } else {
  87585. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87586. + }
  87587. + }
  87588. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  87589. + * Fixup channel interrupt mask. */
  87590. + st->hcintmsk_copy.d32 = 0;
  87591. + st->hcintmsk_copy.b.chhltd = 1;
  87592. + st->hcintmsk_copy.b.ahberr = 1;
  87593. +
  87594. + /* Hack courtesy of FreeBSD: apparently forcing Interrupt Split transactions
  87595. + * as Control puts the transfer into the non-periodic request queue and the
  87596. + * non-periodic handler in the hub. Makes things lots easier.
  87597. + */
  87598. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT) {
  87599. + st->hcchar_copy.b.multicnt = 0;
  87600. + st->hcchar_copy.b.oddfrm = 0;
  87601. + st->hcchar_copy.b.eptype = UE_CONTROL;
  87602. + if (hc->align_buff) {
  87603. + st->hcdma_copy.d32 = hc->align_buff;
  87604. + } else {
  87605. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  87606. + }
  87607. + }
  87608. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  87609. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  87610. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  87611. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87612. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  87613. +
  87614. + local_fiq_disable();
  87615. + mb();
  87616. +
  87617. + if (hc->ep_type & 0x1) {
  87618. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  87619. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  87620. + uframe = hfnum.b.frnum & 0x7;
  87621. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  87622. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  87623. + * split transaction is queued very close to EOF.
  87624. + */
  87625. + start_immediate = 0;
  87626. + } else if (uframe == 5) {
  87627. + start_immediate = 0;
  87628. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  87629. + start_immediate = 0;
  87630. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  87631. + start_immediate = 0;
  87632. + } else {
  87633. + /* Search through all host channels to determine if a transaction
  87634. + * is currently in progress */
  87635. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  87636. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  87637. + continue;
  87638. + switch (hcd->fiq_state->channel[i].fsm) {
  87639. + /* TT is reserved for channels that are in the middle of a periodic
  87640. + * split transaction.
  87641. + */
  87642. + case FIQ_PER_SSPLIT_STARTED:
  87643. + case FIQ_PER_CSPLIT_WAIT:
  87644. + case FIQ_PER_CSPLIT_NYET1:
  87645. + case FIQ_PER_CSPLIT_POLL:
  87646. + case FIQ_PER_ISO_OUT_ACTIVE:
  87647. + case FIQ_PER_ISO_OUT_LAST:
  87648. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  87649. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  87650. + start_immediate = 0;
  87651. + }
  87652. + break;
  87653. + default:
  87654. + break;
  87655. + }
  87656. + if (!start_immediate)
  87657. + break;
  87658. + }
  87659. + }
  87660. + }
  87661. + if ((fiq_fsm_mask & 0x8) && hc->ep_type == UE_INTERRUPT)
  87662. + start_immediate = 1;
  87663. +
  87664. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  87665. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  87666. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  87667. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  87668. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  87669. + switch (hc->ep_type) {
  87670. + case UE_CONTROL:
  87671. + case UE_BULK:
  87672. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  87673. + break;
  87674. + case UE_ISOCHRONOUS:
  87675. + if (hc->ep_is_in) {
  87676. + if (start_immediate) {
  87677. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  87678. + } else {
  87679. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  87680. + }
  87681. + } else {
  87682. + if (start_immediate) {
  87683. + /* Single-isoc OUT packets don't require FIQ involvement */
  87684. + if (st->nrpackets == 1) {
  87685. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  87686. + } else {
  87687. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  87688. + }
  87689. + } else {
  87690. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  87691. + }
  87692. + }
  87693. + break;
  87694. + case UE_INTERRUPT:
  87695. + if (fiq_fsm_mask & 0x8) {
  87696. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  87697. + } else if (start_immediate) {
  87698. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  87699. + } else {
  87700. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  87701. + }
  87702. + default:
  87703. + break;
  87704. + }
  87705. + if (start_immediate) {
  87706. + /* Set the oddfrm bit as close as possible to actual queueing */
  87707. + frame = dwc_otg_hcd_get_frame_number(hcd);
  87708. + st->expected_uframe = (frame + 1) & 0x3FFF;
  87709. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  87710. + st->hcchar_copy.b.chen = 1;
  87711. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  87712. + }
  87713. + mb();
  87714. + local_fiq_enable();
  87715. + return 0;
  87716. +}
  87717. +
  87718. +
  87719. +/**
  87720. + * This function selects transactions from the HCD transfer schedule and
  87721. + * assigns them to available host channels. It is called from HCD interrupt
  87722. + * handler functions.
  87723. + *
  87724. + * @param hcd The HCD state structure.
  87725. + *
  87726. + * @return The types of new transactions that were assigned to host channels.
  87727. + */
  87728. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  87729. +{
  87730. + dwc_list_link_t *qh_ptr;
  87731. + dwc_otg_qh_t *qh;
  87732. + int num_channels;
  87733. + dwc_irqflags_t flags;
  87734. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  87735. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  87736. +
  87737. +#ifdef DEBUG_HOST_CHANNELS
  87738. + last_sel_trans_num_per_scheduled = 0;
  87739. + last_sel_trans_num_nonper_scheduled = 0;
  87740. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  87741. +#endif /* DEBUG_HOST_CHANNELS */
  87742. +
  87743. + /* Process entries in the periodic ready list. */
  87744. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  87745. +
  87746. + while (qh_ptr != &hcd->periodic_sched_ready &&
  87747. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  87748. +
  87749. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87750. +
  87751. + if (microframe_schedule) {
  87752. + // Make sure we leave one channel for non periodic transactions.
  87753. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87754. + if (hcd->available_host_channels <= 1) {
  87755. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87756. + break;
  87757. + }
  87758. + hcd->available_host_channels--;
  87759. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87760. +#ifdef DEBUG_HOST_CHANNELS
  87761. + last_sel_trans_num_per_scheduled++;
  87762. +#endif /* DEBUG_HOST_CHANNELS */
  87763. + }
  87764. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87765. + assign_and_init_hc(hcd, qh);
  87766. +
  87767. + /*
  87768. + * Move the QH from the periodic ready schedule to the
  87769. + * periodic assigned schedule.
  87770. + */
  87771. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87772. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87773. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  87774. + &qh->qh_list_entry);
  87775. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87776. + }
  87777. +
  87778. + /*
  87779. + * Process entries in the inactive portion of the non-periodic
  87780. + * schedule. Some free host channels may not be used if they are
  87781. + * reserved for periodic transfers.
  87782. + */
  87783. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  87784. + num_channels = hcd->core_if->core_params->host_channels;
  87785. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  87786. + (microframe_schedule || hcd->non_periodic_channels <
  87787. + num_channels - hcd->periodic_channels) &&
  87788. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  87789. +
  87790. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87791. + /*
  87792. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  87793. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  87794. + * cheeky devices that just hold off using NAKs
  87795. + */
  87796. + if (nak_holdoff && qh->do_split) {
  87797. + if (qh->nak_frame != 0xffff) {
  87798. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  87799. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  87800. + if (dwc_frame_num_le(frame, next_frame)) {
  87801. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  87802. + hcd->fiq_state->next_sched_frame = next_frame;
  87803. + }
  87804. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87805. + continue;
  87806. + } else {
  87807. + qh->nak_frame = 0xFFFF;
  87808. + }
  87809. + }
  87810. + }
  87811. +
  87812. + if (microframe_schedule) {
  87813. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87814. + if (hcd->available_host_channels < 1) {
  87815. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87816. + break;
  87817. + }
  87818. + hcd->available_host_channels--;
  87819. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87820. +#ifdef DEBUG_HOST_CHANNELS
  87821. + last_sel_trans_num_nonper_scheduled++;
  87822. +#endif /* DEBUG_HOST_CHANNELS */
  87823. + }
  87824. +
  87825. + assign_and_init_hc(hcd, qh);
  87826. +
  87827. + /*
  87828. + * Move the QH from the non-periodic inactive schedule to the
  87829. + * non-periodic active schedule.
  87830. + */
  87831. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  87832. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  87833. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  87834. + &qh->qh_list_entry);
  87835. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  87836. +
  87837. +
  87838. + if (!microframe_schedule)
  87839. + hcd->non_periodic_channels++;
  87840. + }
  87841. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  87842. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  87843. + * ran out of host channels.
  87844. + */
  87845. + if (fiq_enable) {
  87846. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  87847. + hcd->fiq_state->kick_np_queues = 0;
  87848. + } else {
  87849. + /* For each entry remaining in the NP inactive queue,
  87850. + * if this a NAK'd retransmit then don't set the kick flag.
  87851. + */
  87852. + if(nak_holdoff) {
  87853. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  87854. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87855. + if (qh->nak_frame == 0xFFFF) {
  87856. + hcd->fiq_state->kick_np_queues = 1;
  87857. + }
  87858. + }
  87859. + }
  87860. + }
  87861. + }
  87862. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  87863. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  87864. +
  87865. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  87866. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  87867. +
  87868. +
  87869. +#ifdef DEBUG_HOST_CHANNELS
  87870. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  87871. +#endif /* DEBUG_HOST_CHANNELS */
  87872. + return ret_val;
  87873. +}
  87874. +
  87875. +/**
  87876. + * Attempts to queue a single transaction request for a host channel
  87877. + * associated with either a periodic or non-periodic transfer. This function
  87878. + * assumes that there is space available in the appropriate request queue. For
  87879. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  87880. + * is available in the appropriate Tx FIFO.
  87881. + *
  87882. + * @param hcd The HCD state structure.
  87883. + * @param hc Host channel descriptor associated with either a periodic or
  87884. + * non-periodic transfer.
  87885. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  87886. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  87887. + * transfers.
  87888. + *
  87889. + * @return 1 if a request is queued and more requests may be needed to
  87890. + * complete the transfer, 0 if no more requests are required for this
  87891. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  87892. + */
  87893. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  87894. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  87895. +{
  87896. + int retval;
  87897. +
  87898. + if (hcd->core_if->dma_enable) {
  87899. + if (hcd->core_if->dma_desc_enable) {
  87900. + if (!hc->xfer_started
  87901. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  87902. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  87903. + hc->qh->ping_state = 0;
  87904. + }
  87905. + } else if (!hc->xfer_started) {
  87906. + if (fiq_fsm_enable && hc->error_state) {
  87907. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  87908. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  87909. + hcd->fiq_state->channel[hc->hc_num].fsm =
  87910. + FIQ_PASSTHROUGH_ERRORSTATE;
  87911. + }
  87912. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87913. + hc->qh->ping_state = 0;
  87914. + }
  87915. + retval = 0;
  87916. + } else if (hc->halt_pending) {
  87917. + /* Don't queue a request if the channel has been halted. */
  87918. + retval = 0;
  87919. + } else if (hc->halt_on_queue) {
  87920. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  87921. + retval = 0;
  87922. + } else if (hc->do_ping) {
  87923. + if (!hc->xfer_started) {
  87924. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87925. + }
  87926. + retval = 0;
  87927. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  87928. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  87929. + if (!hc->xfer_started) {
  87930. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87931. + retval = 1;
  87932. + } else {
  87933. + retval =
  87934. + dwc_otg_hc_continue_transfer(hcd->core_if,
  87935. + hc);
  87936. + }
  87937. + } else {
  87938. + retval = -1;
  87939. + }
  87940. + } else {
  87941. + if (!hc->xfer_started) {
  87942. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  87943. + retval = 1;
  87944. + } else {
  87945. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  87946. + }
  87947. + }
  87948. +
  87949. + return retval;
  87950. +}
  87951. +
  87952. +/**
  87953. + * Processes periodic channels for the next frame and queues transactions for
  87954. + * these channels to the DWC_otg controller. After queueing transactions, the
  87955. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  87956. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  87957. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  87958. + */
  87959. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  87960. +{
  87961. + hptxsts_data_t tx_status;
  87962. + dwc_list_link_t *qh_ptr;
  87963. + dwc_otg_qh_t *qh;
  87964. + int status = 0;
  87965. + int no_queue_space = 0;
  87966. + int no_fifo_space = 0;
  87967. +
  87968. + dwc_otg_host_global_regs_t *host_regs;
  87969. + host_regs = hcd->core_if->host_if->host_global_regs;
  87970. +
  87971. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  87972. +#ifdef DEBUG
  87973. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  87974. + DWC_DEBUGPL(DBG_HCDV,
  87975. + " P Tx Req Queue Space Avail (before queue): %d\n",
  87976. + tx_status.b.ptxqspcavail);
  87977. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  87978. + tx_status.b.ptxfspcavail);
  87979. +#endif
  87980. +
  87981. + qh_ptr = hcd->periodic_sched_assigned.next;
  87982. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  87983. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  87984. + if (tx_status.b.ptxqspcavail == 0) {
  87985. + no_queue_space = 1;
  87986. + break;
  87987. + }
  87988. +
  87989. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  87990. +
  87991. + // Do not send a split start transaction any later than frame .6
  87992. + // Note, we have to schedule a periodic in .5 to make it go in .6
  87993. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  87994. + {
  87995. + qh_ptr = qh_ptr->next;
  87996. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  87997. + continue;
  87998. + }
  87999. +
  88000. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  88001. + if (qh->do_split)
  88002. + fiq_fsm_queue_split_transaction(hcd, qh);
  88003. + else
  88004. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  88005. + } else {
  88006. +
  88007. + /*
  88008. + * Set a flag if we're queueing high-bandwidth in slave mode.
  88009. + * The flag prevents any halts to get into the request queue in
  88010. + * the middle of multiple high-bandwidth packets getting queued.
  88011. + */
  88012. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  88013. + hcd->core_if->queuing_high_bandwidth = 1;
  88014. + }
  88015. + status = queue_transaction(hcd, qh->channel,
  88016. + tx_status.b.ptxfspcavail);
  88017. + if (status < 0) {
  88018. + no_fifo_space = 1;
  88019. + break;
  88020. + }
  88021. + }
  88022. +
  88023. + /*
  88024. + * In Slave mode, stay on the current transfer until there is
  88025. + * nothing more to do or the high-bandwidth request count is
  88026. + * reached. In DMA mode, only need to queue one request. The
  88027. + * controller automatically handles multiple packets for
  88028. + * high-bandwidth transfers.
  88029. + */
  88030. + if (hcd->core_if->dma_enable || status == 0 ||
  88031. + qh->channel->requests == qh->channel->multi_count) {
  88032. + qh_ptr = qh_ptr->next;
  88033. + /*
  88034. + * Move the QH from the periodic assigned schedule to
  88035. + * the periodic queued schedule.
  88036. + */
  88037. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  88038. + &qh->qh_list_entry);
  88039. +
  88040. + /* done queuing high bandwidth */
  88041. + hcd->core_if->queuing_high_bandwidth = 0;
  88042. + }
  88043. + }
  88044. +
  88045. + if (!hcd->core_if->dma_enable) {
  88046. + dwc_otg_core_global_regs_t *global_regs;
  88047. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88048. +
  88049. + global_regs = hcd->core_if->core_global_regs;
  88050. + intr_mask.b.ptxfempty = 1;
  88051. +#ifdef DEBUG
  88052. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  88053. + DWC_DEBUGPL(DBG_HCDV,
  88054. + " P Tx Req Queue Space Avail (after queue): %d\n",
  88055. + tx_status.b.ptxqspcavail);
  88056. + DWC_DEBUGPL(DBG_HCDV,
  88057. + " P Tx FIFO Space Avail (after queue): %d\n",
  88058. + tx_status.b.ptxfspcavail);
  88059. +#endif
  88060. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  88061. + no_queue_space || no_fifo_space) {
  88062. + /*
  88063. + * May need to queue more transactions as the request
  88064. + * queue or Tx FIFO empties. Enable the periodic Tx
  88065. + * FIFO empty interrupt. (Always use the half-empty
  88066. + * level to ensure that new requests are loaded as
  88067. + * soon as possible.)
  88068. + */
  88069. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  88070. + intr_mask.d32);
  88071. + } else {
  88072. + /*
  88073. + * Disable the Tx FIFO empty interrupt since there are
  88074. + * no more transactions that need to be queued right
  88075. + * now. This function is called from interrupt
  88076. + * handlers to queue more transactions as transfer
  88077. + * states change.
  88078. + */
  88079. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  88080. + 0);
  88081. + }
  88082. + }
  88083. +}
  88084. +
  88085. +/**
  88086. + * Processes active non-periodic channels and queues transactions for these
  88087. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  88088. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  88089. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  88090. + * FIFO Empty interrupt is disabled.
  88091. + */
  88092. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  88093. +{
  88094. + gnptxsts_data_t tx_status;
  88095. + dwc_list_link_t *orig_qh_ptr;
  88096. + dwc_otg_qh_t *qh;
  88097. + int status;
  88098. + int no_queue_space = 0;
  88099. + int no_fifo_space = 0;
  88100. + int more_to_do = 0;
  88101. +
  88102. + dwc_otg_core_global_regs_t *global_regs =
  88103. + hcd->core_if->core_global_regs;
  88104. +
  88105. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  88106. +#ifdef DEBUG
  88107. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  88108. + DWC_DEBUGPL(DBG_HCDV,
  88109. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  88110. + tx_status.b.nptxqspcavail);
  88111. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  88112. + tx_status.b.nptxfspcavail);
  88113. +#endif
  88114. + /*
  88115. + * Keep track of the starting point. Skip over the start-of-list
  88116. + * entry.
  88117. + */
  88118. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  88119. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  88120. + }
  88121. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  88122. +
  88123. + /*
  88124. + * Process once through the active list or until no more space is
  88125. + * available in the request queue or the Tx FIFO.
  88126. + */
  88127. + do {
  88128. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  88129. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  88130. + no_queue_space = 1;
  88131. + break;
  88132. + }
  88133. +
  88134. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  88135. + qh_list_entry);
  88136. +
  88137. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  88138. + fiq_fsm_queue_split_transaction(hcd, qh);
  88139. + } else {
  88140. + status = queue_transaction(hcd, qh->channel,
  88141. + tx_status.b.nptxfspcavail);
  88142. +
  88143. + if (status > 0) {
  88144. + more_to_do = 1;
  88145. + } else if (status < 0) {
  88146. + no_fifo_space = 1;
  88147. + break;
  88148. + }
  88149. + }
  88150. + /* Advance to next QH, skipping start-of-list entry. */
  88151. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  88152. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  88153. + hcd->non_periodic_qh_ptr =
  88154. + hcd->non_periodic_qh_ptr->next;
  88155. + }
  88156. +
  88157. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  88158. +
  88159. + if (!hcd->core_if->dma_enable) {
  88160. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88161. + intr_mask.b.nptxfempty = 1;
  88162. +
  88163. +#ifdef DEBUG
  88164. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  88165. + DWC_DEBUGPL(DBG_HCDV,
  88166. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  88167. + tx_status.b.nptxqspcavail);
  88168. + DWC_DEBUGPL(DBG_HCDV,
  88169. + " NP Tx FIFO Space Avail (after queue): %d\n",
  88170. + tx_status.b.nptxfspcavail);
  88171. +#endif
  88172. + if (more_to_do || no_queue_space || no_fifo_space) {
  88173. + /*
  88174. + * May need to queue more transactions as the request
  88175. + * queue or Tx FIFO empties. Enable the non-periodic
  88176. + * Tx FIFO empty interrupt. (Always use the half-empty
  88177. + * level to ensure that new requests are loaded as
  88178. + * soon as possible.)
  88179. + */
  88180. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  88181. + intr_mask.d32);
  88182. + } else {
  88183. + /*
  88184. + * Disable the Tx FIFO empty interrupt since there are
  88185. + * no more transactions that need to be queued right
  88186. + * now. This function is called from interrupt
  88187. + * handlers to queue more transactions as transfer
  88188. + * states change.
  88189. + */
  88190. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  88191. + 0);
  88192. + }
  88193. + }
  88194. +}
  88195. +
  88196. +/**
  88197. + * This function processes the currently active host channels and queues
  88198. + * transactions for these channels to the DWC_otg controller. It is called
  88199. + * from HCD interrupt handler functions.
  88200. + *
  88201. + * @param hcd The HCD state structure.
  88202. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  88203. + * periodic, or both).
  88204. + */
  88205. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  88206. + dwc_otg_transaction_type_e tr_type)
  88207. +{
  88208. +#ifdef DEBUG_SOF
  88209. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  88210. +#endif
  88211. + /* Process host channels associated with periodic transfers. */
  88212. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  88213. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  88214. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  88215. +
  88216. + process_periodic_channels(hcd);
  88217. + }
  88218. +
  88219. + /* Process host channels associated with non-periodic transfers. */
  88220. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  88221. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  88222. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  88223. + process_non_periodic_channels(hcd);
  88224. + } else {
  88225. + /*
  88226. + * Ensure NP Tx FIFO empty interrupt is disabled when
  88227. + * there are no non-periodic transfers to process.
  88228. + */
  88229. + gintmsk_data_t gintmsk = {.d32 = 0 };
  88230. + gintmsk.b.nptxfempty = 1;
  88231. + DWC_MODIFY_REG32(&hcd->core_if->
  88232. + core_global_regs->gintmsk, gintmsk.d32,
  88233. + 0);
  88234. + }
  88235. + }
  88236. +}
  88237. +
  88238. +#ifdef DWC_HS_ELECT_TST
  88239. +/*
  88240. + * Quick and dirty hack to implement the HS Electrical Test
  88241. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  88242. + *
  88243. + * This code was copied from our userspace app "hset". It sends a
  88244. + * Get Device Descriptor control sequence in two parts, first the
  88245. + * Setup packet by itself, followed some time later by the In and
  88246. + * Ack packets. Rather than trying to figure out how to add this
  88247. + * functionality to the normal driver code, we just hijack the
  88248. + * hardware, using these two function to drive the hardware
  88249. + * directly.
  88250. + */
  88251. +
  88252. +static dwc_otg_core_global_regs_t *global_regs;
  88253. +static dwc_otg_host_global_regs_t *hc_global_regs;
  88254. +static dwc_otg_hc_regs_t *hc_regs;
  88255. +static uint32_t *data_fifo;
  88256. +
  88257. +static void do_setup(void)
  88258. +{
  88259. + gintsts_data_t gintsts;
  88260. + hctsiz_data_t hctsiz;
  88261. + hcchar_data_t hcchar;
  88262. + haint_data_t haint;
  88263. + hcint_data_t hcint;
  88264. +
  88265. + /* Enable HAINTs */
  88266. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  88267. +
  88268. + /* Enable HCINTs */
  88269. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  88270. +
  88271. + /* Read GINTSTS */
  88272. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88273. +
  88274. + /* Read HAINT */
  88275. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88276. +
  88277. + /* Read HCINT */
  88278. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88279. +
  88280. + /* Read HCCHAR */
  88281. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88282. +
  88283. + /* Clear HCINT */
  88284. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88285. +
  88286. + /* Clear HAINT */
  88287. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88288. +
  88289. + /* Clear GINTSTS */
  88290. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88291. +
  88292. + /* Read GINTSTS */
  88293. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88294. +
  88295. + /*
  88296. + * Send Setup packet (Get Device Descriptor)
  88297. + */
  88298. +
  88299. + /* Make sure channel is disabled */
  88300. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88301. + if (hcchar.b.chen) {
  88302. + hcchar.b.chdis = 1;
  88303. +// hcchar.b.chen = 1;
  88304. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88305. + //sleep(1);
  88306. + dwc_mdelay(1000);
  88307. +
  88308. + /* Read GINTSTS */
  88309. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88310. +
  88311. + /* Read HAINT */
  88312. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88313. +
  88314. + /* Read HCINT */
  88315. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88316. +
  88317. + /* Read HCCHAR */
  88318. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88319. +
  88320. + /* Clear HCINT */
  88321. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88322. +
  88323. + /* Clear HAINT */
  88324. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88325. +
  88326. + /* Clear GINTSTS */
  88327. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88328. +
  88329. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88330. + }
  88331. +
  88332. + /* Set HCTSIZ */
  88333. + hctsiz.d32 = 0;
  88334. + hctsiz.b.xfersize = 8;
  88335. + hctsiz.b.pktcnt = 1;
  88336. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  88337. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  88338. +
  88339. + /* Set HCCHAR */
  88340. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88341. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  88342. + hcchar.b.epdir = 0;
  88343. + hcchar.b.epnum = 0;
  88344. + hcchar.b.mps = 8;
  88345. + hcchar.b.chen = 1;
  88346. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88347. +
  88348. + /* Fill FIFO with Setup data for Get Device Descriptor */
  88349. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  88350. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  88351. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  88352. +
  88353. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88354. +
  88355. + /* Wait for host channel interrupt */
  88356. + do {
  88357. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88358. + } while (gintsts.b.hcintr == 0);
  88359. +
  88360. + /* Disable HCINTs */
  88361. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  88362. +
  88363. + /* Disable HAINTs */
  88364. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  88365. +
  88366. + /* Read HAINT */
  88367. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88368. +
  88369. + /* Read HCINT */
  88370. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88371. +
  88372. + /* Read HCCHAR */
  88373. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88374. +
  88375. + /* Clear HCINT */
  88376. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88377. +
  88378. + /* Clear HAINT */
  88379. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88380. +
  88381. + /* Clear GINTSTS */
  88382. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88383. +
  88384. + /* Read GINTSTS */
  88385. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88386. +}
  88387. +
  88388. +static void do_in_ack(void)
  88389. +{
  88390. + gintsts_data_t gintsts;
  88391. + hctsiz_data_t hctsiz;
  88392. + hcchar_data_t hcchar;
  88393. + haint_data_t haint;
  88394. + hcint_data_t hcint;
  88395. + host_grxsts_data_t grxsts;
  88396. +
  88397. + /* Enable HAINTs */
  88398. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  88399. +
  88400. + /* Enable HCINTs */
  88401. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  88402. +
  88403. + /* Read GINTSTS */
  88404. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88405. +
  88406. + /* Read HAINT */
  88407. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88408. +
  88409. + /* Read HCINT */
  88410. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88411. +
  88412. + /* Read HCCHAR */
  88413. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88414. +
  88415. + /* Clear HCINT */
  88416. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88417. +
  88418. + /* Clear HAINT */
  88419. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88420. +
  88421. + /* Clear GINTSTS */
  88422. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88423. +
  88424. + /* Read GINTSTS */
  88425. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88426. +
  88427. + /*
  88428. + * Receive Control In packet
  88429. + */
  88430. +
  88431. + /* Make sure channel is disabled */
  88432. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88433. + if (hcchar.b.chen) {
  88434. + hcchar.b.chdis = 1;
  88435. + hcchar.b.chen = 1;
  88436. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88437. + //sleep(1);
  88438. + dwc_mdelay(1000);
  88439. +
  88440. + /* Read GINTSTS */
  88441. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88442. +
  88443. + /* Read HAINT */
  88444. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88445. +
  88446. + /* Read HCINT */
  88447. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88448. +
  88449. + /* Read HCCHAR */
  88450. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88451. +
  88452. + /* Clear HCINT */
  88453. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88454. +
  88455. + /* Clear HAINT */
  88456. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88457. +
  88458. + /* Clear GINTSTS */
  88459. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88460. +
  88461. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88462. + }
  88463. +
  88464. + /* Set HCTSIZ */
  88465. + hctsiz.d32 = 0;
  88466. + hctsiz.b.xfersize = 8;
  88467. + hctsiz.b.pktcnt = 1;
  88468. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  88469. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  88470. +
  88471. + /* Set HCCHAR */
  88472. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88473. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  88474. + hcchar.b.epdir = 1;
  88475. + hcchar.b.epnum = 0;
  88476. + hcchar.b.mps = 8;
  88477. + hcchar.b.chen = 1;
  88478. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88479. +
  88480. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88481. +
  88482. + /* Wait for receive status queue interrupt */
  88483. + do {
  88484. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88485. + } while (gintsts.b.rxstsqlvl == 0);
  88486. +
  88487. + /* Read RXSTS */
  88488. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  88489. +
  88490. + /* Clear RXSTSQLVL in GINTSTS */
  88491. + gintsts.d32 = 0;
  88492. + gintsts.b.rxstsqlvl = 1;
  88493. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88494. +
  88495. + switch (grxsts.b.pktsts) {
  88496. + case DWC_GRXSTS_PKTSTS_IN:
  88497. + /* Read the data into the host buffer */
  88498. + if (grxsts.b.bcnt > 0) {
  88499. + int i;
  88500. + int word_count = (grxsts.b.bcnt + 3) / 4;
  88501. +
  88502. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  88503. +
  88504. + for (i = 0; i < word_count; i++) {
  88505. + (void)DWC_READ_REG32(data_fifo++);
  88506. + }
  88507. + }
  88508. + break;
  88509. +
  88510. + default:
  88511. + break;
  88512. + }
  88513. +
  88514. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88515. +
  88516. + /* Wait for receive status queue interrupt */
  88517. + do {
  88518. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88519. + } while (gintsts.b.rxstsqlvl == 0);
  88520. +
  88521. + /* Read RXSTS */
  88522. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  88523. +
  88524. + /* Clear RXSTSQLVL in GINTSTS */
  88525. + gintsts.d32 = 0;
  88526. + gintsts.b.rxstsqlvl = 1;
  88527. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88528. +
  88529. + switch (grxsts.b.pktsts) {
  88530. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  88531. + break;
  88532. +
  88533. + default:
  88534. + break;
  88535. + }
  88536. +
  88537. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88538. +
  88539. + /* Wait for host channel interrupt */
  88540. + do {
  88541. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88542. + } while (gintsts.b.hcintr == 0);
  88543. +
  88544. + /* Read HAINT */
  88545. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88546. +
  88547. + /* Read HCINT */
  88548. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88549. +
  88550. + /* Read HCCHAR */
  88551. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88552. +
  88553. + /* Clear HCINT */
  88554. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88555. +
  88556. + /* Clear HAINT */
  88557. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88558. +
  88559. + /* Clear GINTSTS */
  88560. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88561. +
  88562. + /* Read GINTSTS */
  88563. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88564. +
  88565. +// usleep(100000);
  88566. +// mdelay(100);
  88567. + dwc_mdelay(1);
  88568. +
  88569. + /*
  88570. + * Send handshake packet
  88571. + */
  88572. +
  88573. + /* Read HAINT */
  88574. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88575. +
  88576. + /* Read HCINT */
  88577. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88578. +
  88579. + /* Read HCCHAR */
  88580. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88581. +
  88582. + /* Clear HCINT */
  88583. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88584. +
  88585. + /* Clear HAINT */
  88586. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88587. +
  88588. + /* Clear GINTSTS */
  88589. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88590. +
  88591. + /* Read GINTSTS */
  88592. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88593. +
  88594. + /* Make sure channel is disabled */
  88595. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88596. + if (hcchar.b.chen) {
  88597. + hcchar.b.chdis = 1;
  88598. + hcchar.b.chen = 1;
  88599. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88600. + //sleep(1);
  88601. + dwc_mdelay(1000);
  88602. +
  88603. + /* Read GINTSTS */
  88604. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88605. +
  88606. + /* Read HAINT */
  88607. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88608. +
  88609. + /* Read HCINT */
  88610. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88611. +
  88612. + /* Read HCCHAR */
  88613. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88614. +
  88615. + /* Clear HCINT */
  88616. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88617. +
  88618. + /* Clear HAINT */
  88619. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88620. +
  88621. + /* Clear GINTSTS */
  88622. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88623. +
  88624. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88625. + }
  88626. +
  88627. + /* Set HCTSIZ */
  88628. + hctsiz.d32 = 0;
  88629. + hctsiz.b.xfersize = 0;
  88630. + hctsiz.b.pktcnt = 1;
  88631. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  88632. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  88633. +
  88634. + /* Set HCCHAR */
  88635. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88636. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  88637. + hcchar.b.epdir = 0;
  88638. + hcchar.b.epnum = 0;
  88639. + hcchar.b.mps = 8;
  88640. + hcchar.b.chen = 1;
  88641. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  88642. +
  88643. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88644. +
  88645. + /* Wait for host channel interrupt */
  88646. + do {
  88647. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88648. + } while (gintsts.b.hcintr == 0);
  88649. +
  88650. + /* Disable HCINTs */
  88651. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  88652. +
  88653. + /* Disable HAINTs */
  88654. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  88655. +
  88656. + /* Read HAINT */
  88657. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  88658. +
  88659. + /* Read HCINT */
  88660. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  88661. +
  88662. + /* Read HCCHAR */
  88663. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  88664. +
  88665. + /* Clear HCINT */
  88666. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  88667. +
  88668. + /* Clear HAINT */
  88669. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  88670. +
  88671. + /* Clear GINTSTS */
  88672. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  88673. +
  88674. + /* Read GINTSTS */
  88675. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  88676. +}
  88677. +#endif
  88678. +
  88679. +/** Handles hub class-specific requests. */
  88680. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  88681. + uint16_t typeReq,
  88682. + uint16_t wValue,
  88683. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  88684. +{
  88685. + int retval = 0;
  88686. +
  88687. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  88688. + usb_hub_descriptor_t *hub_desc;
  88689. + hprt0_data_t hprt0 = {.d32 = 0 };
  88690. +
  88691. + uint32_t port_status;
  88692. +
  88693. + switch (typeReq) {
  88694. + case UCR_CLEAR_HUB_FEATURE:
  88695. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88696. + "ClearHubFeature 0x%x\n", wValue);
  88697. + switch (wValue) {
  88698. + case UHF_C_HUB_LOCAL_POWER:
  88699. + case UHF_C_HUB_OVER_CURRENT:
  88700. + /* Nothing required here */
  88701. + break;
  88702. + default:
  88703. + retval = -DWC_E_INVALID;
  88704. + DWC_ERROR("DWC OTG HCD - "
  88705. + "ClearHubFeature request %xh unknown\n",
  88706. + wValue);
  88707. + }
  88708. + break;
  88709. + case UCR_CLEAR_PORT_FEATURE:
  88710. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88711. + if (wValue != UHF_PORT_L1)
  88712. +#endif
  88713. + if (!wIndex || wIndex > 1)
  88714. + goto error;
  88715. +
  88716. + switch (wValue) {
  88717. + case UHF_PORT_ENABLE:
  88718. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  88719. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  88720. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88721. + hprt0.b.prtena = 1;
  88722. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88723. + break;
  88724. + case UHF_PORT_SUSPEND:
  88725. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88726. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  88727. +
  88728. + if (core_if->power_down == 2) {
  88729. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  88730. + } else {
  88731. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  88732. + dwc_mdelay(5);
  88733. +
  88734. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88735. + hprt0.b.prtres = 1;
  88736. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88737. + hprt0.b.prtsusp = 0;
  88738. + /* Clear Resume bit */
  88739. + dwc_mdelay(100);
  88740. + hprt0.b.prtres = 0;
  88741. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88742. + }
  88743. + break;
  88744. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88745. + case UHF_PORT_L1:
  88746. + {
  88747. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88748. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  88749. +
  88750. + lpmcfg.d32 =
  88751. + DWC_READ_REG32(&core_if->
  88752. + core_global_regs->glpmcfg);
  88753. + lpmcfg.b.en_utmi_sleep = 0;
  88754. + lpmcfg.b.hird_thres &= (~(1 << 4));
  88755. + lpmcfg.b.prt_sleep_sts = 1;
  88756. + DWC_WRITE_REG32(&core_if->
  88757. + core_global_regs->glpmcfg,
  88758. + lpmcfg.d32);
  88759. +
  88760. + /* Clear Enbl_L1Gating bit. */
  88761. + pcgcctl.b.enbl_sleep_gating = 1;
  88762. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  88763. + 0);
  88764. +
  88765. + dwc_mdelay(5);
  88766. +
  88767. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88768. + hprt0.b.prtres = 1;
  88769. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  88770. + hprt0.d32);
  88771. + /* This bit will be cleared in wakeup interrupt handle */
  88772. + break;
  88773. + }
  88774. +#endif
  88775. + case UHF_PORT_POWER:
  88776. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88777. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  88778. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88779. + hprt0.b.prtpwr = 0;
  88780. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88781. + break;
  88782. + case UHF_PORT_INDICATOR:
  88783. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88784. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  88785. + /* Port inidicator not supported */
  88786. + break;
  88787. + case UHF_C_PORT_CONNECTION:
  88788. + /* Clears drivers internal connect status change
  88789. + * flag */
  88790. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88791. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  88792. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  88793. + break;
  88794. + case UHF_C_PORT_RESET:
  88795. + /* Clears the driver's internal Port Reset Change
  88796. + * flag */
  88797. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88798. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  88799. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  88800. + break;
  88801. + case UHF_C_PORT_ENABLE:
  88802. + /* Clears the driver's internal Port
  88803. + * Enable/Disable Change flag */
  88804. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88805. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  88806. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  88807. + break;
  88808. + case UHF_C_PORT_SUSPEND:
  88809. + /* Clears the driver's internal Port Suspend
  88810. + * Change flag, which is set when resume signaling on
  88811. + * the host port is complete */
  88812. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88813. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  88814. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  88815. + break;
  88816. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88817. + case UHF_C_PORT_L1:
  88818. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  88819. + break;
  88820. +#endif
  88821. + case UHF_C_PORT_OVER_CURRENT:
  88822. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88823. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  88824. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  88825. + break;
  88826. + default:
  88827. + retval = -DWC_E_INVALID;
  88828. + DWC_ERROR("DWC OTG HCD - "
  88829. + "ClearPortFeature request %xh "
  88830. + "unknown or unsupported\n", wValue);
  88831. + }
  88832. + break;
  88833. + case UCR_GET_HUB_DESCRIPTOR:
  88834. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88835. + "GetHubDescriptor\n");
  88836. + hub_desc = (usb_hub_descriptor_t *) buf;
  88837. + hub_desc->bDescLength = 9;
  88838. + hub_desc->bDescriptorType = 0x29;
  88839. + hub_desc->bNbrPorts = 1;
  88840. + USETW(hub_desc->wHubCharacteristics, 0x08);
  88841. + hub_desc->bPwrOn2PwrGood = 1;
  88842. + hub_desc->bHubContrCurrent = 0;
  88843. + hub_desc->DeviceRemovable[0] = 0;
  88844. + hub_desc->DeviceRemovable[1] = 0xff;
  88845. + break;
  88846. + case UCR_GET_HUB_STATUS:
  88847. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88848. + "GetHubStatus\n");
  88849. + DWC_MEMSET(buf, 0, 4);
  88850. + break;
  88851. + case UCR_GET_PORT_STATUS:
  88852. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88853. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  88854. + wIndex, dwc_otg_hcd->flags.d32);
  88855. + if (!wIndex || wIndex > 1)
  88856. + goto error;
  88857. +
  88858. + port_status = 0;
  88859. +
  88860. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  88861. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  88862. +
  88863. + if (dwc_otg_hcd->flags.b.port_enable_change)
  88864. + port_status |= (1 << UHF_C_PORT_ENABLE);
  88865. +
  88866. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  88867. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  88868. +
  88869. + if (dwc_otg_hcd->flags.b.port_l1_change)
  88870. + port_status |= (1 << UHF_C_PORT_L1);
  88871. +
  88872. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  88873. + port_status |= (1 << UHF_C_PORT_RESET);
  88874. + }
  88875. +
  88876. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  88877. + DWC_WARN("Overcurrent change detected\n");
  88878. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  88879. + }
  88880. +
  88881. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  88882. + /*
  88883. + * The port is disconnected, which means the core is
  88884. + * either in device mode or it soon will be. Just
  88885. + * return 0's for the remainder of the port status
  88886. + * since the port register can't be read if the core
  88887. + * is in device mode.
  88888. + */
  88889. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  88890. + break;
  88891. + }
  88892. +
  88893. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  88894. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  88895. +
  88896. + if (hprt0.b.prtconnsts)
  88897. + port_status |= (1 << UHF_PORT_CONNECTION);
  88898. +
  88899. + if (hprt0.b.prtena)
  88900. + port_status |= (1 << UHF_PORT_ENABLE);
  88901. +
  88902. + if (hprt0.b.prtsusp)
  88903. + port_status |= (1 << UHF_PORT_SUSPEND);
  88904. +
  88905. + if (hprt0.b.prtovrcurract)
  88906. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  88907. +
  88908. + if (hprt0.b.prtrst)
  88909. + port_status |= (1 << UHF_PORT_RESET);
  88910. +
  88911. + if (hprt0.b.prtpwr)
  88912. + port_status |= (1 << UHF_PORT_POWER);
  88913. +
  88914. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  88915. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  88916. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  88917. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  88918. +
  88919. + if (hprt0.b.prttstctl)
  88920. + port_status |= (1 << UHF_PORT_TEST);
  88921. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  88922. + port_status |= (1 << UHF_PORT_L1);
  88923. + }
  88924. + /*
  88925. + For Synopsys HW emulation of Power down wkup_control asserts the
  88926. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  88927. + We intentionally tell the software that port is in L2Suspend state.
  88928. + Only for STE.
  88929. + */
  88930. + if ((core_if->power_down == 2)
  88931. + && (core_if->hibernation_suspend == 1)) {
  88932. + port_status |= (1 << UHF_PORT_SUSPEND);
  88933. + }
  88934. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  88935. +
  88936. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  88937. +
  88938. + break;
  88939. + case UCR_SET_HUB_FEATURE:
  88940. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88941. + "SetHubFeature\n");
  88942. + /* No HUB features supported */
  88943. + break;
  88944. + case UCR_SET_PORT_FEATURE:
  88945. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  88946. + goto error;
  88947. +
  88948. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  88949. + /*
  88950. + * The port is disconnected, which means the core is
  88951. + * either in device mode or it soon will be. Just
  88952. + * return without doing anything since the port
  88953. + * register can't be written if the core is in device
  88954. + * mode.
  88955. + */
  88956. + break;
  88957. + }
  88958. +
  88959. + switch (wValue) {
  88960. + case UHF_PORT_SUSPEND:
  88961. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  88962. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  88963. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  88964. + goto error;
  88965. + }
  88966. + if (core_if->power_down == 2) {
  88967. + int timeout = 300;
  88968. + dwc_irqflags_t flags;
  88969. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  88970. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  88971. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  88972. +#ifdef DWC_DEV_SRPCAP
  88973. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  88974. +#endif
  88975. + DWC_PRINTF("Preparing for complete power-off\n");
  88976. +
  88977. + /* Save registers before hibernation */
  88978. + dwc_otg_save_global_regs(core_if);
  88979. + dwc_otg_save_host_regs(core_if);
  88980. +
  88981. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88982. + hprt0.b.prtsusp = 1;
  88983. + hprt0.b.prtena = 0;
  88984. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  88985. + /* Spin hprt0.b.prtsusp to became 1 */
  88986. + do {
  88987. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  88988. + if (hprt0.b.prtsusp) {
  88989. + break;
  88990. + }
  88991. + dwc_mdelay(1);
  88992. + } while (--timeout);
  88993. + if (!timeout) {
  88994. + DWC_WARN("Suspend wasn't genereted\n");
  88995. + }
  88996. + dwc_udelay(10);
  88997. +
  88998. + /*
  88999. + * We need to disable interrupts to prevent servicing of any IRQ
  89000. + * during going to hibernation
  89001. + */
  89002. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  89003. + core_if->lx_state = DWC_OTG_L2;
  89004. +#ifdef DWC_DEV_SRPCAP
  89005. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89006. + hprt0.b.prtpwr = 0;
  89007. + hprt0.b.prtena = 0;
  89008. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  89009. + hprt0.d32);
  89010. +#endif
  89011. + gusbcfg.d32 =
  89012. + DWC_READ_REG32(&core_if->core_global_regs->
  89013. + gusbcfg);
  89014. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  89015. + /* ULPI interface */
  89016. + /* Suspend the Phy Clock */
  89017. + pcgcctl.d32 = 0;
  89018. + pcgcctl.b.stoppclk = 1;
  89019. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  89020. + pcgcctl.d32);
  89021. + dwc_udelay(10);
  89022. + gpwrdn.b.pmuactv = 1;
  89023. + DWC_MODIFY_REG32(&core_if->
  89024. + core_global_regs->
  89025. + gpwrdn, 0, gpwrdn.d32);
  89026. + } else {
  89027. + /* UTMI+ Interface */
  89028. + gpwrdn.b.pmuactv = 1;
  89029. + DWC_MODIFY_REG32(&core_if->
  89030. + core_global_regs->
  89031. + gpwrdn, 0, gpwrdn.d32);
  89032. + dwc_udelay(10);
  89033. + pcgcctl.b.stoppclk = 1;
  89034. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  89035. + dwc_udelay(10);
  89036. + }
  89037. +#ifdef DWC_DEV_SRPCAP
  89038. + gpwrdn.d32 = 0;
  89039. + gpwrdn.b.dis_vbus = 1;
  89040. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89041. + gpwrdn, 0, gpwrdn.d32);
  89042. +#endif
  89043. + gpwrdn.d32 = 0;
  89044. + gpwrdn.b.pmuintsel = 1;
  89045. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89046. + gpwrdn, 0, gpwrdn.d32);
  89047. + dwc_udelay(10);
  89048. +
  89049. + gpwrdn.d32 = 0;
  89050. +#ifdef DWC_DEV_SRPCAP
  89051. + gpwrdn.b.srp_det_msk = 1;
  89052. +#endif
  89053. + gpwrdn.b.disconn_det_msk = 1;
  89054. + gpwrdn.b.lnstchng_msk = 1;
  89055. + gpwrdn.b.sts_chngint_msk = 1;
  89056. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89057. + gpwrdn, 0, gpwrdn.d32);
  89058. + dwc_udelay(10);
  89059. +
  89060. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  89061. + gpwrdn.d32 = 0;
  89062. + gpwrdn.b.pwrdnclmp = 1;
  89063. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89064. + gpwrdn, 0, gpwrdn.d32);
  89065. + dwc_udelay(10);
  89066. +
  89067. + /* Switch off VDD */
  89068. + gpwrdn.d32 = 0;
  89069. + gpwrdn.b.pwrdnswtch = 1;
  89070. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89071. + gpwrdn, 0, gpwrdn.d32);
  89072. +
  89073. +#ifdef DWC_DEV_SRPCAP
  89074. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  89075. + {
  89076. + core_if->pwron_timer_started = 1;
  89077. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  89078. + }
  89079. +#endif
  89080. + /* Save gpwrdn register for further usage if stschng interrupt */
  89081. + core_if->gr_backup->gpwrdn_local =
  89082. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  89083. +
  89084. + /* Set flag to indicate that we are in hibernation */
  89085. + core_if->hibernation_suspend = 1;
  89086. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  89087. +
  89088. + DWC_PRINTF("Host hibernation completed\n");
  89089. + // Exit from case statement
  89090. + break;
  89091. +
  89092. + }
  89093. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  89094. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  89095. + gotgctl_data_t gotgctl = {.d32 = 0 };
  89096. + gotgctl.b.hstsethnpen = 1;
  89097. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89098. + gotgctl, 0, gotgctl.d32);
  89099. + core_if->op_state = A_SUSPEND;
  89100. + }
  89101. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89102. + hprt0.b.prtsusp = 1;
  89103. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89104. + {
  89105. + dwc_irqflags_t flags;
  89106. + /* Update lx_state */
  89107. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  89108. + core_if->lx_state = DWC_OTG_L2;
  89109. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  89110. + }
  89111. + /* Suspend the Phy Clock */
  89112. + {
  89113. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  89114. + pcgcctl.b.stoppclk = 1;
  89115. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  89116. + pcgcctl.d32);
  89117. + dwc_udelay(10);
  89118. + }
  89119. +
  89120. + /* For HNP the bus must be suspended for at least 200ms. */
  89121. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  89122. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  89123. + pcgcctl.b.stoppclk = 1;
  89124. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  89125. + dwc_mdelay(200);
  89126. + }
  89127. +
  89128. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  89129. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  89130. + if (core_if->adp_enable) {
  89131. + gotgctl_data_t gotgctl = {.d32 = 0 };
  89132. + gpwrdn_data_t gpwrdn;
  89133. +
  89134. + while (gotgctl.b.asesvld == 1) {
  89135. + gotgctl.d32 =
  89136. + DWC_READ_REG32(&core_if->
  89137. + core_global_regs->
  89138. + gotgctl);
  89139. + dwc_mdelay(100);
  89140. + }
  89141. +
  89142. + /* Enable Power Down Logic */
  89143. + gpwrdn.d32 = 0;
  89144. + gpwrdn.b.pmuactv = 1;
  89145. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89146. + gpwrdn, 0, gpwrdn.d32);
  89147. +
  89148. + /* Unmask SRP detected interrupt from Power Down Logic */
  89149. + gpwrdn.d32 = 0;
  89150. + gpwrdn.b.srp_det_msk = 1;
  89151. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  89152. + gpwrdn, 0, gpwrdn.d32);
  89153. +
  89154. + dwc_otg_adp_probe_start(core_if);
  89155. + }
  89156. +#endif
  89157. + break;
  89158. + case UHF_PORT_POWER:
  89159. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  89160. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  89161. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89162. + hprt0.b.prtpwr = 1;
  89163. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89164. + break;
  89165. + case UHF_PORT_RESET:
  89166. + if ((core_if->power_down == 2)
  89167. + && (core_if->hibernation_suspend == 1)) {
  89168. + /* If we are going to exit from Hibernated
  89169. + * state via USB RESET.
  89170. + */
  89171. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  89172. + } else {
  89173. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89174. +
  89175. + DWC_DEBUGPL(DBG_HCD,
  89176. + "DWC OTG HCD HUB CONTROL - "
  89177. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  89178. + {
  89179. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  89180. + pcgcctl.b.enbl_sleep_gating = 1;
  89181. + pcgcctl.b.stoppclk = 1;
  89182. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  89183. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  89184. + }
  89185. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89186. + {
  89187. + glpmcfg_data_t lpmcfg;
  89188. + lpmcfg.d32 =
  89189. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  89190. + if (lpmcfg.b.prt_sleep_sts) {
  89191. + lpmcfg.b.en_utmi_sleep = 0;
  89192. + lpmcfg.b.hird_thres &= (~(1 << 4));
  89193. + DWC_WRITE_REG32
  89194. + (&core_if->core_global_regs->glpmcfg,
  89195. + lpmcfg.d32);
  89196. + dwc_mdelay(1);
  89197. + }
  89198. + }
  89199. +#endif
  89200. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89201. + /* Clear suspend bit if resetting from suspended state. */
  89202. + hprt0.b.prtsusp = 0;
  89203. + /* When B-Host the Port reset bit is set in
  89204. + * the Start HCD Callback function, so that
  89205. + * the reset is started within 1ms of the HNP
  89206. + * success interrupt. */
  89207. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  89208. + hprt0.b.prtpwr = 1;
  89209. + hprt0.b.prtrst = 1;
  89210. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  89211. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  89212. + hprt0.d32);
  89213. + }
  89214. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  89215. + dwc_mdelay(60);
  89216. + hprt0.b.prtrst = 0;
  89217. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89218. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  89219. + }
  89220. + break;
  89221. +#ifdef DWC_HS_ELECT_TST
  89222. + case UHF_PORT_TEST:
  89223. + {
  89224. + uint32_t t;
  89225. + gintmsk_data_t gintmsk;
  89226. +
  89227. + t = (wIndex >> 8); /* MSB wIndex USB */
  89228. + DWC_DEBUGPL(DBG_HCD,
  89229. + "DWC OTG HCD HUB CONTROL - "
  89230. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  89231. + t);
  89232. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  89233. + if (t < 6) {
  89234. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  89235. + hprt0.b.prttstctl = t;
  89236. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  89237. + hprt0.d32);
  89238. + } else {
  89239. + /* Setup global vars with reg addresses (quick and
  89240. + * dirty hack, should be cleaned up)
  89241. + */
  89242. + global_regs = core_if->core_global_regs;
  89243. + hc_global_regs =
  89244. + core_if->host_if->host_global_regs;
  89245. + hc_regs =
  89246. + (dwc_otg_hc_regs_t *) ((char *)
  89247. + global_regs +
  89248. + 0x500);
  89249. + data_fifo =
  89250. + (uint32_t *) ((char *)global_regs +
  89251. + 0x1000);
  89252. +
  89253. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  89254. + /* Save current interrupt mask */
  89255. + gintmsk.d32 =
  89256. + DWC_READ_REG32
  89257. + (&global_regs->gintmsk);
  89258. +
  89259. + /* Disable all interrupts while we muck with
  89260. + * the hardware directly
  89261. + */
  89262. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  89263. +
  89264. + /* 15 second delay per the test spec */
  89265. + dwc_mdelay(15000);
  89266. +
  89267. + /* Drive suspend on the root port */
  89268. + hprt0.d32 =
  89269. + dwc_otg_read_hprt0(core_if);
  89270. + hprt0.b.prtsusp = 1;
  89271. + hprt0.b.prtres = 0;
  89272. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89273. +
  89274. + /* 15 second delay per the test spec */
  89275. + dwc_mdelay(15000);
  89276. +
  89277. + /* Drive resume on the root port */
  89278. + hprt0.d32 =
  89279. + dwc_otg_read_hprt0(core_if);
  89280. + hprt0.b.prtsusp = 0;
  89281. + hprt0.b.prtres = 1;
  89282. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89283. + dwc_mdelay(100);
  89284. +
  89285. + /* Clear the resume bit */
  89286. + hprt0.b.prtres = 0;
  89287. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  89288. +
  89289. + /* Restore interrupts */
  89290. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  89291. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  89292. + /* Save current interrupt mask */
  89293. + gintmsk.d32 =
  89294. + DWC_READ_REG32
  89295. + (&global_regs->gintmsk);
  89296. +
  89297. + /* Disable all interrupts while we muck with
  89298. + * the hardware directly
  89299. + */
  89300. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  89301. +
  89302. + /* 15 second delay per the test spec */
  89303. + dwc_mdelay(15000);
  89304. +
  89305. + /* Send the Setup packet */
  89306. + do_setup();
  89307. +
  89308. + /* 15 second delay so nothing else happens for awhile */
  89309. + dwc_mdelay(15000);
  89310. +
  89311. + /* Restore interrupts */
  89312. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  89313. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  89314. + /* Save current interrupt mask */
  89315. + gintmsk.d32 =
  89316. + DWC_READ_REG32
  89317. + (&global_regs->gintmsk);
  89318. +
  89319. + /* Disable all interrupts while we muck with
  89320. + * the hardware directly
  89321. + */
  89322. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  89323. +
  89324. + /* Send the Setup packet */
  89325. + do_setup();
  89326. +
  89327. + /* 15 second delay so nothing else happens for awhile */
  89328. + dwc_mdelay(15000);
  89329. +
  89330. + /* Send the In and Ack packets */
  89331. + do_in_ack();
  89332. +
  89333. + /* 15 second delay so nothing else happens for awhile */
  89334. + dwc_mdelay(15000);
  89335. +
  89336. + /* Restore interrupts */
  89337. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  89338. + }
  89339. + }
  89340. + break;
  89341. + }
  89342. +#endif /* DWC_HS_ELECT_TST */
  89343. +
  89344. + case UHF_PORT_INDICATOR:
  89345. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  89346. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  89347. + /* Not supported */
  89348. + break;
  89349. + default:
  89350. + retval = -DWC_E_INVALID;
  89351. + DWC_ERROR("DWC OTG HCD - "
  89352. + "SetPortFeature request %xh "
  89353. + "unknown or unsupported\n", wValue);
  89354. + break;
  89355. + }
  89356. + break;
  89357. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89358. + case UCR_SET_AND_TEST_PORT_FEATURE:
  89359. + if (wValue != UHF_PORT_L1) {
  89360. + goto error;
  89361. + }
  89362. + {
  89363. + int portnum, hird, devaddr, remwake;
  89364. + glpmcfg_data_t lpmcfg;
  89365. + uint32_t time_usecs;
  89366. + gintsts_data_t gintsts;
  89367. + gintmsk_data_t gintmsk;
  89368. +
  89369. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  89370. + goto error;
  89371. + }
  89372. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  89373. + goto error;
  89374. + }
  89375. + /* Check if the port currently is in SLEEP state */
  89376. + lpmcfg.d32 =
  89377. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  89378. + if (lpmcfg.b.prt_sleep_sts) {
  89379. + DWC_INFO("Port is already in sleep mode\n");
  89380. + buf[0] = 0; /* Return success */
  89381. + break;
  89382. + }
  89383. +
  89384. + portnum = wIndex & 0xf;
  89385. + hird = (wIndex >> 4) & 0xf;
  89386. + devaddr = (wIndex >> 8) & 0x7f;
  89387. + remwake = (wIndex >> 15);
  89388. +
  89389. + if (portnum != 1) {
  89390. + retval = -DWC_E_INVALID;
  89391. + DWC_WARN
  89392. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  89393. + portnum);
  89394. + break;
  89395. + }
  89396. +
  89397. + DWC_PRINTF
  89398. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  89399. + portnum, hird, devaddr, remwake);
  89400. + /* Disable LPM interrupt */
  89401. + gintmsk.d32 = 0;
  89402. + gintmsk.b.lpmtranrcvd = 1;
  89403. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  89404. + gintmsk.d32, 0);
  89405. +
  89406. + if (dwc_otg_hcd_send_lpm
  89407. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  89408. + retval = -DWC_E_INVALID;
  89409. + break;
  89410. + }
  89411. +
  89412. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  89413. + /* We will consider timeout if time_usecs microseconds pass,
  89414. + * and we don't receive LPM transaction status.
  89415. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  89416. + * core will set lpmtranrcvd bit.
  89417. + */
  89418. + do {
  89419. + gintsts.d32 =
  89420. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  89421. + if (gintsts.b.lpmtranrcvd) {
  89422. + break;
  89423. + }
  89424. + dwc_udelay(1);
  89425. + } while (--time_usecs);
  89426. + /* lpm_int bit will be cleared in LPM interrupt handler */
  89427. +
  89428. + /* Now fill status
  89429. + * 0x00 - Success
  89430. + * 0x10 - NYET
  89431. + * 0x11 - Timeout
  89432. + */
  89433. + if (!gintsts.b.lpmtranrcvd) {
  89434. + buf[0] = 0x3; /* Completion code is Timeout */
  89435. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  89436. + } else {
  89437. + lpmcfg.d32 =
  89438. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  89439. + if (lpmcfg.b.lpm_resp == 0x3) {
  89440. + /* ACK responce from the device */
  89441. + buf[0] = 0x00; /* Success */
  89442. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  89443. + /* NYET responce from the device */
  89444. + buf[0] = 0x2;
  89445. + } else {
  89446. + /* Otherwise responce with Timeout */
  89447. + buf[0] = 0x3;
  89448. + }
  89449. + }
  89450. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  89451. + lpmcfg.b.lpm_resp);
  89452. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  89453. + gintmsk.d32);
  89454. +
  89455. + break;
  89456. + }
  89457. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  89458. + default:
  89459. +error:
  89460. + retval = -DWC_E_INVALID;
  89461. + DWC_WARN("DWC OTG HCD - "
  89462. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  89463. + typeReq, wIndex, wValue);
  89464. + break;
  89465. + }
  89466. +
  89467. + return retval;
  89468. +}
  89469. +
  89470. +#ifdef CONFIG_USB_DWC_OTG_LPM
  89471. +/** Returns index of host channel to perform LPM transaction. */
  89472. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  89473. +{
  89474. + dwc_otg_core_if_t *core_if = hcd->core_if;
  89475. + dwc_hc_t *hc;
  89476. + hcchar_data_t hcchar;
  89477. + gintmsk_data_t gintmsk = {.d32 = 0 };
  89478. +
  89479. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  89480. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  89481. + return -1;
  89482. + }
  89483. +
  89484. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  89485. +
  89486. + /* Mask host channel interrupts. */
  89487. + gintmsk.b.hcintr = 1;
  89488. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  89489. +
  89490. + /* Fill fields that core needs for LPM transaction */
  89491. + hcchar.b.devaddr = devaddr;
  89492. + hcchar.b.epnum = 0;
  89493. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  89494. + hcchar.b.mps = 64;
  89495. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  89496. + hcchar.b.epdir = 0; /* OUT */
  89497. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  89498. + hcchar.d32);
  89499. +
  89500. + /* Remove the host channel from the free list. */
  89501. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  89502. +
  89503. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  89504. +
  89505. + return hc->hc_num;
  89506. +}
  89507. +
  89508. +/** Release hc after performing LPM transaction */
  89509. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  89510. +{
  89511. + dwc_hc_t *hc;
  89512. + glpmcfg_data_t lpmcfg;
  89513. + uint8_t hc_num;
  89514. +
  89515. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  89516. + hc_num = lpmcfg.b.lpm_chan_index;
  89517. +
  89518. + hc = hcd->hc_ptr_array[hc_num];
  89519. +
  89520. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  89521. + /* Return host channel to free list */
  89522. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  89523. +}
  89524. +
  89525. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  89526. + uint8_t bRemoteWake)
  89527. +{
  89528. + glpmcfg_data_t lpmcfg;
  89529. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  89530. + int channel;
  89531. +
  89532. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  89533. + if (channel < 0) {
  89534. + return channel;
  89535. + }
  89536. +
  89537. + pcgcctl.b.enbl_sleep_gating = 1;
  89538. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  89539. +
  89540. + /* Read LPM config register */
  89541. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  89542. +
  89543. + /* Program LPM transaction fields */
  89544. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  89545. + lpmcfg.b.hird = hird;
  89546. + lpmcfg.b.hird_thres = 0x1c;
  89547. + lpmcfg.b.lpm_chan_index = channel;
  89548. + lpmcfg.b.en_utmi_sleep = 1;
  89549. + /* Program LPM config register */
  89550. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  89551. +
  89552. + /* Send LPM transaction */
  89553. + lpmcfg.b.send_lpm = 1;
  89554. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  89555. +
  89556. + return 0;
  89557. +}
  89558. +
  89559. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  89560. +
  89561. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  89562. +{
  89563. + int retval;
  89564. +
  89565. + if (port != 1) {
  89566. + return -DWC_E_INVALID;
  89567. + }
  89568. +
  89569. + retval = (hcd->flags.b.port_connect_status_change ||
  89570. + hcd->flags.b.port_reset_change ||
  89571. + hcd->flags.b.port_enable_change ||
  89572. + hcd->flags.b.port_suspend_change ||
  89573. + hcd->flags.b.port_over_current_change);
  89574. +#ifdef DEBUG
  89575. + if (retval) {
  89576. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  89577. + " Root port status changed\n");
  89578. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  89579. + hcd->flags.b.port_connect_status_change);
  89580. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  89581. + hcd->flags.b.port_reset_change);
  89582. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  89583. + hcd->flags.b.port_enable_change);
  89584. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  89585. + hcd->flags.b.port_suspend_change);
  89586. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  89587. + hcd->flags.b.port_over_current_change);
  89588. + }
  89589. +#endif
  89590. + return retval;
  89591. +}
  89592. +
  89593. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  89594. +{
  89595. + hfnum_data_t hfnum;
  89596. + hfnum.d32 =
  89597. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  89598. + hfnum);
  89599. +
  89600. +#ifdef DEBUG_SOF
  89601. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  89602. + hfnum.b.frnum);
  89603. +#endif
  89604. + return hfnum.b.frnum;
  89605. +}
  89606. +
  89607. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  89608. + struct dwc_otg_hcd_function_ops *fops)
  89609. +{
  89610. + int retval = 0;
  89611. +
  89612. + hcd->fops = fops;
  89613. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  89614. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  89615. + dwc_otg_hcd_reinit(hcd);
  89616. + } else {
  89617. + retval = -DWC_E_NO_DEVICE;
  89618. + }
  89619. +
  89620. + return retval;
  89621. +}
  89622. +
  89623. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  89624. +{
  89625. + return hcd->priv;
  89626. +}
  89627. +
  89628. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  89629. +{
  89630. + hcd->priv = priv_data;
  89631. +}
  89632. +
  89633. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  89634. +{
  89635. + return hcd->otg_port;
  89636. +}
  89637. +
  89638. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  89639. +{
  89640. + uint32_t is_b_host;
  89641. + if (hcd->core_if->op_state == B_HOST) {
  89642. + is_b_host = 1;
  89643. + } else {
  89644. + is_b_host = 0;
  89645. + }
  89646. +
  89647. + return is_b_host;
  89648. +}
  89649. +
  89650. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  89651. + int iso_desc_count, int atomic_alloc)
  89652. +{
  89653. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  89654. + uint32_t size;
  89655. +
  89656. + size =
  89657. + sizeof(*dwc_otg_urb) +
  89658. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  89659. + if (atomic_alloc)
  89660. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  89661. + else
  89662. + dwc_otg_urb = DWC_ALLOC(size);
  89663. +
  89664. + if (dwc_otg_urb)
  89665. + dwc_otg_urb->packet_count = iso_desc_count;
  89666. + else {
  89667. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  89668. + "%salloc of %db failed\n",
  89669. + atomic_alloc?"atomic ":"", size);
  89670. + }
  89671. + return dwc_otg_urb;
  89672. +}
  89673. +
  89674. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89675. + uint8_t dev_addr, uint8_t ep_num,
  89676. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  89677. +{
  89678. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  89679. + ep_type, ep_dir, mps);
  89680. +#if 0
  89681. + DWC_PRINTF
  89682. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  89683. + dev_addr, ep_num, ep_dir, ep_type, mps);
  89684. +#endif
  89685. +}
  89686. +
  89687. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89688. + void *urb_handle, void *buf, dwc_dma_t dma,
  89689. + uint32_t buflen, void *setup_packet,
  89690. + dwc_dma_t setup_dma, uint32_t flags,
  89691. + uint16_t interval)
  89692. +{
  89693. + dwc_otg_urb->priv = urb_handle;
  89694. + dwc_otg_urb->buf = buf;
  89695. + dwc_otg_urb->dma = dma;
  89696. + dwc_otg_urb->length = buflen;
  89697. + dwc_otg_urb->setup_packet = setup_packet;
  89698. + dwc_otg_urb->setup_dma = setup_dma;
  89699. + dwc_otg_urb->flags = flags;
  89700. + dwc_otg_urb->interval = interval;
  89701. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  89702. +}
  89703. +
  89704. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89705. +{
  89706. + return dwc_otg_urb->status;
  89707. +}
  89708. +
  89709. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89710. +{
  89711. + return dwc_otg_urb->actual_length;
  89712. +}
  89713. +
  89714. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  89715. +{
  89716. + return dwc_otg_urb->error_count;
  89717. +}
  89718. +
  89719. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89720. + int desc_num, uint32_t offset,
  89721. + uint32_t length)
  89722. +{
  89723. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  89724. + dwc_otg_urb->iso_descs[desc_num].length = length;
  89725. +}
  89726. +
  89727. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  89728. + int desc_num)
  89729. +{
  89730. + return dwc_otg_urb->iso_descs[desc_num].status;
  89731. +}
  89732. +
  89733. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  89734. + dwc_otg_urb, int desc_num)
  89735. +{
  89736. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  89737. +}
  89738. +
  89739. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  89740. +{
  89741. + int allocated = 0;
  89742. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89743. +
  89744. + if (qh) {
  89745. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  89746. + allocated = 1;
  89747. + }
  89748. + }
  89749. + return allocated;
  89750. +}
  89751. +
  89752. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  89753. +{
  89754. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89755. + int freed = 0;
  89756. + DWC_ASSERT(qh, "qh is not allocated\n");
  89757. +
  89758. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  89759. + freed = 1;
  89760. + }
  89761. +
  89762. + return freed;
  89763. +}
  89764. +
  89765. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  89766. +{
  89767. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  89768. + DWC_ASSERT(qh, "qh is not allocated\n");
  89769. + return qh->usecs;
  89770. +}
  89771. +
  89772. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  89773. +{
  89774. +#ifdef DEBUG
  89775. + int num_channels;
  89776. + int i;
  89777. + gnptxsts_data_t np_tx_status;
  89778. + hptxsts_data_t p_tx_status;
  89779. +
  89780. + num_channels = hcd->core_if->core_params->host_channels;
  89781. + DWC_PRINTF("\n");
  89782. + DWC_PRINTF
  89783. + ("************************************************************\n");
  89784. + DWC_PRINTF("HCD State:\n");
  89785. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  89786. + for (i = 0; i < num_channels; i++) {
  89787. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  89788. + DWC_PRINTF(" Channel %d:\n", i);
  89789. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  89790. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  89791. + DWC_PRINTF(" speed: %d\n", hc->speed);
  89792. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  89793. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  89794. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  89795. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  89796. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  89797. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  89798. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  89799. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  89800. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  89801. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  89802. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  89803. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  89804. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  89805. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  89806. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  89807. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  89808. + DWC_PRINTF(" requests: %d\n", hc->requests);
  89809. + DWC_PRINTF(" qh: %p\n", hc->qh);
  89810. + if (hc->xfer_started) {
  89811. + hfnum_data_t hfnum;
  89812. + hcchar_data_t hcchar;
  89813. + hctsiz_data_t hctsiz;
  89814. + hcint_data_t hcint;
  89815. + hcintmsk_data_t hcintmsk;
  89816. + hfnum.d32 =
  89817. + DWC_READ_REG32(&hcd->core_if->
  89818. + host_if->host_global_regs->hfnum);
  89819. + hcchar.d32 =
  89820. + DWC_READ_REG32(&hcd->core_if->host_if->
  89821. + hc_regs[i]->hcchar);
  89822. + hctsiz.d32 =
  89823. + DWC_READ_REG32(&hcd->core_if->host_if->
  89824. + hc_regs[i]->hctsiz);
  89825. + hcint.d32 =
  89826. + DWC_READ_REG32(&hcd->core_if->host_if->
  89827. + hc_regs[i]->hcint);
  89828. + hcintmsk.d32 =
  89829. + DWC_READ_REG32(&hcd->core_if->host_if->
  89830. + hc_regs[i]->hcintmsk);
  89831. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  89832. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  89833. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  89834. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  89835. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  89836. + }
  89837. + if (hc->xfer_started && hc->qh) {
  89838. + dwc_otg_qtd_t *qtd;
  89839. + dwc_otg_hcd_urb_t *urb;
  89840. +
  89841. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  89842. + if (!qtd->in_process)
  89843. + break;
  89844. +
  89845. + urb = qtd->urb;
  89846. + DWC_PRINTF(" URB Info:\n");
  89847. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  89848. + if (urb) {
  89849. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  89850. + dwc_otg_hcd_get_dev_addr(&urb->
  89851. + pipe_info),
  89852. + dwc_otg_hcd_get_ep_num(&urb->
  89853. + pipe_info),
  89854. + dwc_otg_hcd_is_pipe_in(&urb->
  89855. + pipe_info) ?
  89856. + "IN" : "OUT");
  89857. + DWC_PRINTF(" Max packet size: %d\n",
  89858. + dwc_otg_hcd_get_mps(&urb->
  89859. + pipe_info));
  89860. + DWC_PRINTF(" transfer_buffer: %p\n",
  89861. + urb->buf);
  89862. + DWC_PRINTF(" transfer_dma: %p\n",
  89863. + (void *)urb->dma);
  89864. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  89865. + urb->length);
  89866. + DWC_PRINTF(" actual_length: %d\n",
  89867. + urb->actual_length);
  89868. + }
  89869. + }
  89870. + }
  89871. + }
  89872. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  89873. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  89874. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  89875. + np_tx_status.d32 =
  89876. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  89877. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  89878. + np_tx_status.b.nptxqspcavail);
  89879. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  89880. + np_tx_status.b.nptxfspcavail);
  89881. + p_tx_status.d32 =
  89882. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  89883. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  89884. + p_tx_status.b.ptxqspcavail);
  89885. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  89886. + dwc_otg_hcd_dump_frrem(hcd);
  89887. + dwc_otg_dump_global_registers(hcd->core_if);
  89888. + dwc_otg_dump_host_registers(hcd->core_if);
  89889. + DWC_PRINTF
  89890. + ("************************************************************\n");
  89891. + DWC_PRINTF("\n");
  89892. +#endif
  89893. +}
  89894. +
  89895. +#ifdef DEBUG
  89896. +void dwc_print_setup_data(uint8_t * setup)
  89897. +{
  89898. + int i;
  89899. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  89900. + DWC_PRINTF("Setup Data = MSB ");
  89901. + for (i = 7; i >= 0; i--)
  89902. + DWC_PRINTF("%02x ", setup[i]);
  89903. + DWC_PRINTF("\n");
  89904. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  89905. + (setup[0] & 0x80) ? "Device-to-Host" :
  89906. + "Host-to-Device");
  89907. + DWC_PRINTF(" bmRequestType Type = ");
  89908. + switch ((setup[0] & 0x60) >> 5) {
  89909. + case 0:
  89910. + DWC_PRINTF("Standard\n");
  89911. + break;
  89912. + case 1:
  89913. + DWC_PRINTF("Class\n");
  89914. + break;
  89915. + case 2:
  89916. + DWC_PRINTF("Vendor\n");
  89917. + break;
  89918. + case 3:
  89919. + DWC_PRINTF("Reserved\n");
  89920. + break;
  89921. + }
  89922. + DWC_PRINTF(" bmRequestType Recipient = ");
  89923. + switch (setup[0] & 0x1f) {
  89924. + case 0:
  89925. + DWC_PRINTF("Device\n");
  89926. + break;
  89927. + case 1:
  89928. + DWC_PRINTF("Interface\n");
  89929. + break;
  89930. + case 2:
  89931. + DWC_PRINTF("Endpoint\n");
  89932. + break;
  89933. + case 3:
  89934. + DWC_PRINTF("Other\n");
  89935. + break;
  89936. + default:
  89937. + DWC_PRINTF("Reserved\n");
  89938. + break;
  89939. + }
  89940. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  89941. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  89942. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  89943. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  89944. + }
  89945. +}
  89946. +#endif
  89947. +
  89948. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  89949. +{
  89950. +#if 0
  89951. + DWC_PRINTF("Frame remaining at SOF:\n");
  89952. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89953. + hcd->frrem_samples, hcd->frrem_accum,
  89954. + (hcd->frrem_samples > 0) ?
  89955. + hcd->frrem_accum / hcd->frrem_samples : 0);
  89956. +
  89957. + DWC_PRINTF("\n");
  89958. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  89959. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89960. + hcd->core_if->hfnum_7_samples,
  89961. + hcd->core_if->hfnum_7_frrem_accum,
  89962. + (hcd->core_if->hfnum_7_samples >
  89963. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  89964. + hcd->core_if->hfnum_7_samples : 0);
  89965. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  89966. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89967. + hcd->core_if->hfnum_0_samples,
  89968. + hcd->core_if->hfnum_0_frrem_accum,
  89969. + (hcd->core_if->hfnum_0_samples >
  89970. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  89971. + hcd->core_if->hfnum_0_samples : 0);
  89972. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  89973. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89974. + hcd->core_if->hfnum_other_samples,
  89975. + hcd->core_if->hfnum_other_frrem_accum,
  89976. + (hcd->core_if->hfnum_other_samples >
  89977. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  89978. + hcd->core_if->hfnum_other_samples : 0);
  89979. +
  89980. + DWC_PRINTF("\n");
  89981. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  89982. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89983. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  89984. + (hcd->hfnum_7_samples_a > 0) ?
  89985. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  89986. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  89987. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89988. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  89989. + (hcd->hfnum_0_samples_a > 0) ?
  89990. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  89991. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  89992. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  89993. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  89994. + (hcd->hfnum_other_samples_a > 0) ?
  89995. + hcd->hfnum_other_frrem_accum_a /
  89996. + hcd->hfnum_other_samples_a : 0);
  89997. +
  89998. + DWC_PRINTF("\n");
  89999. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  90000. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  90001. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  90002. + (hcd->hfnum_7_samples_b > 0) ?
  90003. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  90004. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  90005. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  90006. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  90007. + (hcd->hfnum_0_samples_b > 0) ?
  90008. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  90009. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  90010. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  90011. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  90012. + (hcd->hfnum_other_samples_b > 0) ?
  90013. + hcd->hfnum_other_frrem_accum_b /
  90014. + hcd->hfnum_other_samples_b : 0);
  90015. +#endif
  90016. +}
  90017. +
  90018. +#endif /* DWC_DEVICE_ONLY */
  90019. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  90020. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  90021. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2015-03-09 10:39:33.218893718 +0100
  90022. @@ -0,0 +1,1132 @@
  90023. +/*==========================================================================
  90024. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  90025. + * $Revision: #10 $
  90026. + * $Date: 2011/10/20 $
  90027. + * $Change: 1869464 $
  90028. + *
  90029. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90030. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90031. + * otherwise expressly agreed to in writing between Synopsys and you.
  90032. + *
  90033. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90034. + * any End User Software License Agreement or Agreement for Licensed Product
  90035. + * with Synopsys or any supplement thereto. You are permitted to use and
  90036. + * redistribute this Software in source and binary forms, with or without
  90037. + * modification, provided that redistributions of source code must retain this
  90038. + * notice. You may not view, use, disclose, copy or distribute this file or
  90039. + * any information contained herein except pursuant to this license grant from
  90040. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90041. + * below, then you are not authorized to use the Software.
  90042. + *
  90043. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90044. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90045. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90046. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90047. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90048. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90049. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90050. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90051. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90052. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90053. + * DAMAGE.
  90054. + * ========================================================================== */
  90055. +#ifndef DWC_DEVICE_ONLY
  90056. +
  90057. +/** @file
  90058. + * This file contains Descriptor DMA support implementation for host mode.
  90059. + */
  90060. +
  90061. +#include "dwc_otg_hcd.h"
  90062. +#include "dwc_otg_regs.h"
  90063. +
  90064. +extern bool microframe_schedule;
  90065. +
  90066. +static inline uint8_t frame_list_idx(uint16_t frame)
  90067. +{
  90068. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  90069. +}
  90070. +
  90071. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  90072. +{
  90073. + return (idx + inc) &
  90074. + (((speed ==
  90075. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  90076. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  90077. +}
  90078. +
  90079. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  90080. +{
  90081. + return (idx - inc) &
  90082. + (((speed ==
  90083. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  90084. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  90085. +}
  90086. +
  90087. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  90088. +{
  90089. + return (((qh->ep_type == UE_ISOCHRONOUS)
  90090. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  90091. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  90092. +}
  90093. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  90094. +{
  90095. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  90096. + ? ((qh->interval + 8 - 1) / 8)
  90097. + : qh->interval);
  90098. +}
  90099. +
  90100. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  90101. +{
  90102. + int retval = 0;
  90103. +
  90104. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  90105. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  90106. + &qh->desc_list_dma);
  90107. +
  90108. + if (!qh->desc_list) {
  90109. + retval = -DWC_E_NO_MEMORY;
  90110. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  90111. +
  90112. + }
  90113. +
  90114. + dwc_memset(qh->desc_list, 0x00,
  90115. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  90116. +
  90117. + qh->n_bytes =
  90118. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  90119. +
  90120. + if (!qh->n_bytes) {
  90121. + retval = -DWC_E_NO_MEMORY;
  90122. + DWC_ERROR
  90123. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  90124. + __func__);
  90125. +
  90126. + }
  90127. + return retval;
  90128. +
  90129. +}
  90130. +
  90131. +static void desc_list_free(dwc_otg_qh_t * qh)
  90132. +{
  90133. + if (qh->desc_list) {
  90134. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  90135. + qh->desc_list_dma);
  90136. + qh->desc_list = NULL;
  90137. + }
  90138. +
  90139. + if (qh->n_bytes) {
  90140. + DWC_FREE(qh->n_bytes);
  90141. + qh->n_bytes = NULL;
  90142. + }
  90143. +}
  90144. +
  90145. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  90146. +{
  90147. + int retval = 0;
  90148. + if (hcd->frame_list)
  90149. + return 0;
  90150. +
  90151. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  90152. + &hcd->frame_list_dma);
  90153. + if (!hcd->frame_list) {
  90154. + retval = -DWC_E_NO_MEMORY;
  90155. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  90156. + }
  90157. +
  90158. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  90159. +
  90160. + return retval;
  90161. +}
  90162. +
  90163. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  90164. +{
  90165. + if (!hcd->frame_list)
  90166. + return;
  90167. +
  90168. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  90169. + hcd->frame_list = NULL;
  90170. +}
  90171. +
  90172. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  90173. +{
  90174. +
  90175. + hcfg_data_t hcfg;
  90176. +
  90177. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  90178. +
  90179. + if (hcfg.b.perschedena) {
  90180. + /* already enabled */
  90181. + return;
  90182. + }
  90183. +
  90184. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  90185. + hcd->frame_list_dma);
  90186. +
  90187. + switch (fr_list_en) {
  90188. + case 64:
  90189. + hcfg.b.frlisten = 3;
  90190. + break;
  90191. + case 32:
  90192. + hcfg.b.frlisten = 2;
  90193. + break;
  90194. + case 16:
  90195. + hcfg.b.frlisten = 1;
  90196. + break;
  90197. + case 8:
  90198. + hcfg.b.frlisten = 0;
  90199. + break;
  90200. + default:
  90201. + break;
  90202. + }
  90203. +
  90204. + hcfg.b.perschedena = 1;
  90205. +
  90206. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  90207. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  90208. +
  90209. +}
  90210. +
  90211. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  90212. +{
  90213. + hcfg_data_t hcfg;
  90214. +
  90215. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  90216. +
  90217. + if (!hcfg.b.perschedena) {
  90218. + /* already disabled */
  90219. + return;
  90220. + }
  90221. + hcfg.b.perschedena = 0;
  90222. +
  90223. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  90224. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  90225. +}
  90226. +
  90227. +/*
  90228. + * Activates/Deactivates FrameList entries for the channel
  90229. + * based on endpoint servicing period.
  90230. + */
  90231. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  90232. +{
  90233. + uint16_t i, j, inc;
  90234. + dwc_hc_t *hc = NULL;
  90235. +
  90236. + if (!qh->channel) {
  90237. + DWC_ERROR("qh->channel = %p", qh->channel);
  90238. + return;
  90239. + }
  90240. +
  90241. + if (!hcd) {
  90242. + DWC_ERROR("------hcd = %p", hcd);
  90243. + return;
  90244. + }
  90245. +
  90246. + if (!hcd->frame_list) {
  90247. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  90248. + return;
  90249. + }
  90250. +
  90251. + hc = qh->channel;
  90252. + inc = frame_incr_val(qh);
  90253. + if (qh->ep_type == UE_ISOCHRONOUS)
  90254. + i = frame_list_idx(qh->sched_frame);
  90255. + else
  90256. + i = 0;
  90257. +
  90258. + j = i;
  90259. + do {
  90260. + if (enable)
  90261. + hcd->frame_list[j] |= (1 << hc->hc_num);
  90262. + else
  90263. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  90264. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  90265. + }
  90266. + while (j != i);
  90267. + if (!enable)
  90268. + return;
  90269. + hc->schinfo = 0;
  90270. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  90271. + j = 1;
  90272. + /* TODO - check this */
  90273. + inc = (8 + qh->interval - 1) / qh->interval;
  90274. + for (i = 0; i < inc; i++) {
  90275. + hc->schinfo |= j;
  90276. + j = j << qh->interval;
  90277. + }
  90278. + } else {
  90279. + hc->schinfo = 0xff;
  90280. + }
  90281. +}
  90282. +
  90283. +#if 1
  90284. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  90285. +{
  90286. + int i = 0;
  90287. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  90288. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  90289. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  90290. + if (!(i % 8) && i)
  90291. + DWC_PRINTF("\n");
  90292. + }
  90293. + DWC_PRINTF("\n----\n");
  90294. +
  90295. +}
  90296. +#endif
  90297. +
  90298. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90299. +{
  90300. + dwc_irqflags_t flags;
  90301. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  90302. +
  90303. + dwc_hc_t *hc = qh->channel;
  90304. + if (dwc_qh_is_non_per(qh)) {
  90305. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  90306. + if (!microframe_schedule)
  90307. + hcd->non_periodic_channels--;
  90308. + else
  90309. + hcd->available_host_channels++;
  90310. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  90311. + } else
  90312. + update_frame_list(hcd, qh, 0);
  90313. +
  90314. + /*
  90315. + * The condition is added to prevent double cleanup try in case of device
  90316. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  90317. + */
  90318. + if (hc->qh) {
  90319. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  90320. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  90321. + hc->qh = NULL;
  90322. + }
  90323. +
  90324. + qh->channel = NULL;
  90325. + qh->ntd = 0;
  90326. +
  90327. + if (qh->desc_list) {
  90328. + dwc_memset(qh->desc_list, 0x00,
  90329. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  90330. + }
  90331. +}
  90332. +
  90333. +/**
  90334. + * Initializes a QH structure's Descriptor DMA related members.
  90335. + * Allocates memory for descriptor list.
  90336. + * On first periodic QH, allocates memory for FrameList
  90337. + * and enables periodic scheduling.
  90338. + *
  90339. + * @param hcd The HCD state structure for the DWC OTG controller.
  90340. + * @param qh The QH to init.
  90341. + *
  90342. + * @return 0 if successful, negative error code otherwise.
  90343. + */
  90344. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90345. +{
  90346. + int retval = 0;
  90347. +
  90348. + if (qh->do_split) {
  90349. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  90350. + return -1;
  90351. + }
  90352. +
  90353. + retval = desc_list_alloc(qh);
  90354. +
  90355. + if ((retval == 0)
  90356. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  90357. + if (!hcd->frame_list) {
  90358. + retval = frame_list_alloc(hcd);
  90359. + /* Enable periodic schedule on first periodic QH */
  90360. + if (retval == 0)
  90361. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  90362. + }
  90363. + }
  90364. +
  90365. + qh->ntd = 0;
  90366. +
  90367. + return retval;
  90368. +}
  90369. +
  90370. +/**
  90371. + * Frees descriptor list memory associated with the QH.
  90372. + * If QH is periodic and the last, frees FrameList memory
  90373. + * and disables periodic scheduling.
  90374. + *
  90375. + * @param hcd The HCD state structure for the DWC OTG controller.
  90376. + * @param qh The QH to init.
  90377. + */
  90378. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90379. +{
  90380. + desc_list_free(qh);
  90381. +
  90382. + /*
  90383. + * Channel still assigned due to some reasons.
  90384. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  90385. + * ChHalted interrupt to release the channel. Afterwards
  90386. + * when it comes here from endpoint disable routine
  90387. + * channel remains assigned.
  90388. + */
  90389. + if (qh->channel)
  90390. + release_channel_ddma(hcd, qh);
  90391. +
  90392. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  90393. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  90394. +
  90395. + per_sched_disable(hcd);
  90396. + frame_list_free(hcd);
  90397. + }
  90398. +}
  90399. +
  90400. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  90401. +{
  90402. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  90403. + /*
  90404. + * Descriptor set(8 descriptors) index
  90405. + * which is 8-aligned.
  90406. + */
  90407. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  90408. + } else {
  90409. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  90410. + }
  90411. +}
  90412. +
  90413. +/*
  90414. + * Determine starting frame for Isochronous transfer.
  90415. + * Few frames skipped to prevent race condition with HC.
  90416. + */
  90417. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  90418. + uint8_t * skip_frames)
  90419. +{
  90420. + uint16_t frame = 0;
  90421. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  90422. +
  90423. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  90424. +
  90425. + /*
  90426. + * skip_frames is used to limit activated descriptors number
  90427. + * to avoid the situation when HC services the last activated
  90428. + * descriptor firstly.
  90429. + * Example for FS:
  90430. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  90431. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  90432. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  90433. + * list will be fully programmed with Active descriptors and it is possible
  90434. + * case(rare) that the latest descriptor(considering rollback) corresponding
  90435. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  90436. + * up to 11 uframes(16 in the code) may be skipped.
  90437. + */
  90438. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  90439. + /*
  90440. + * Consider uframe counter also, to start xfer asap.
  90441. + * If half of the frame elapsed skip 2 frames otherwise
  90442. + * just 1 frame.
  90443. + * Starting descriptor index must be 8-aligned, so
  90444. + * if the current frame is near to complete the next one
  90445. + * is skipped as well.
  90446. + */
  90447. +
  90448. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  90449. + *skip_frames = 2 * 8;
  90450. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  90451. + } else {
  90452. + *skip_frames = 1 * 8;
  90453. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  90454. + }
  90455. +
  90456. + frame = dwc_full_frame_num(frame);
  90457. + } else {
  90458. + /*
  90459. + * Two frames are skipped for FS - the current and the next.
  90460. + * But for descriptor programming, 1 frame(descriptor) is enough,
  90461. + * see example above.
  90462. + */
  90463. + *skip_frames = 1;
  90464. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  90465. + }
  90466. +
  90467. + return frame;
  90468. +}
  90469. +
  90470. +/*
  90471. + * Calculate initial descriptor index for isochronous transfer
  90472. + * based on scheduled frame.
  90473. + */
  90474. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90475. +{
  90476. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  90477. + uint8_t skip_frames = 0;
  90478. + /*
  90479. + * With current ISOC processing algorithm the channel is being
  90480. + * released when no more QTDs in the list(qh->ntd == 0).
  90481. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  90482. + *
  90483. + * So qh->channel != NULL branch is not used and just not removed from the
  90484. + * source file. It is required for another possible approach which is,
  90485. + * do not disable and release the channel when ISOC session completed,
  90486. + * just move QH to inactive schedule until new QTD arrives.
  90487. + * On new QTD, the QH moved back to 'ready' schedule,
  90488. + * starting frame and therefore starting desc_index are recalculated.
  90489. + * In this case channel is released only on ep_disable.
  90490. + */
  90491. +
  90492. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  90493. + if (qh->channel) {
  90494. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  90495. + /*
  90496. + * Calculate initial descriptor index based on FrameList current bitmap
  90497. + * and servicing period.
  90498. + */
  90499. + fr_idx_tmp = frame_list_idx(frame);
  90500. + fr_idx =
  90501. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  90502. + fr_idx_tmp)
  90503. + % frame_incr_val(qh);
  90504. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  90505. + } else {
  90506. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  90507. + fr_idx = frame_list_idx(qh->sched_frame);
  90508. + }
  90509. +
  90510. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  90511. +
  90512. + return skip_frames;
  90513. +}
  90514. +
  90515. +#define ISOC_URB_GIVEBACK_ASAP
  90516. +
  90517. +#define MAX_ISOC_XFER_SIZE_FS 1023
  90518. +#define MAX_ISOC_XFER_SIZE_HS 3072
  90519. +#define DESCNUM_THRESHOLD 4
  90520. +
  90521. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  90522. + uint8_t skip_frames)
  90523. +{
  90524. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  90525. + dwc_otg_qtd_t *qtd;
  90526. + dwc_otg_host_dma_desc_t *dma_desc;
  90527. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  90528. +
  90529. + idx = qh->td_last;
  90530. + inc = qh->interval;
  90531. + n_desc = 0;
  90532. +
  90533. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  90534. + if (skip_frames && !qh->channel)
  90535. + ntd_max = ntd_max - skip_frames / qh->interval;
  90536. +
  90537. + max_xfer_size =
  90538. + (qh->dev_speed ==
  90539. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  90540. + MAX_ISOC_XFER_SIZE_FS;
  90541. +
  90542. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  90543. + while ((qh->ntd < ntd_max)
  90544. + && (qtd->isoc_frame_index_last <
  90545. + qtd->urb->packet_count)) {
  90546. +
  90547. + dma_desc = &qh->desc_list[idx];
  90548. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  90549. +
  90550. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  90551. +
  90552. + if (frame_desc->length > max_xfer_size)
  90553. + qh->n_bytes[idx] = max_xfer_size;
  90554. + else
  90555. + qh->n_bytes[idx] = frame_desc->length;
  90556. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  90557. + dma_desc->status.b_isoc.a = 1;
  90558. + dma_desc->status.b_isoc.sts = 0;
  90559. +
  90560. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  90561. +
  90562. + qh->ntd++;
  90563. +
  90564. + qtd->isoc_frame_index_last++;
  90565. +
  90566. +#ifdef ISOC_URB_GIVEBACK_ASAP
  90567. + /*
  90568. + * Set IOC for each descriptor corresponding to the
  90569. + * last frame of the URB.
  90570. + */
  90571. + if (qtd->isoc_frame_index_last ==
  90572. + qtd->urb->packet_count)
  90573. + dma_desc->status.b_isoc.ioc = 1;
  90574. +
  90575. +#endif
  90576. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  90577. + n_desc++;
  90578. +
  90579. + }
  90580. + qtd->in_process = 1;
  90581. + }
  90582. +
  90583. + qh->td_last = idx;
  90584. +
  90585. +#ifdef ISOC_URB_GIVEBACK_ASAP
  90586. + /* Set IOC for the last descriptor if descriptor list is full */
  90587. + if (qh->ntd == ntd_max) {
  90588. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  90589. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  90590. + }
  90591. +#else
  90592. + /*
  90593. + * Set IOC bit only for one descriptor.
  90594. + * Always try to be ahead of HW processing,
  90595. + * i.e. on IOC generation driver activates next descriptors but
  90596. + * core continues to process descriptors followed the one with IOC set.
  90597. + */
  90598. +
  90599. + if (n_desc > DESCNUM_THRESHOLD) {
  90600. + /*
  90601. + * Move IOC "up". Required even if there is only one QTD
  90602. + * in the list, cause QTDs migth continue to be queued,
  90603. + * but during the activation it was only one queued.
  90604. + * Actually more than one QTD might be in the list if this function called
  90605. + * from XferCompletion - QTDs was queued during HW processing of the previous
  90606. + * descriptor chunk.
  90607. + */
  90608. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  90609. + } else {
  90610. + /*
  90611. + * Set the IOC for the latest descriptor
  90612. + * if either number of descriptor is not greather than threshold
  90613. + * or no more new descriptors activated.
  90614. + */
  90615. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  90616. + }
  90617. +
  90618. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  90619. +#endif
  90620. +}
  90621. +
  90622. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90623. +{
  90624. +
  90625. + dwc_hc_t *hc;
  90626. + dwc_otg_host_dma_desc_t *dma_desc;
  90627. + dwc_otg_qtd_t *qtd;
  90628. + int num_packets, len, n_desc = 0;
  90629. +
  90630. + hc = qh->channel;
  90631. +
  90632. + /*
  90633. + * Start with hc->xfer_buff initialized in
  90634. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  90635. + * this pointer re-assigned to the buffer of the currently processed QTD.
  90636. + * For non-SG request there is always one QTD active.
  90637. + */
  90638. +
  90639. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  90640. +
  90641. + if (n_desc) {
  90642. + /* SG request - more than 1 QTDs */
  90643. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  90644. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  90645. + }
  90646. +
  90647. + qtd->n_desc = 0;
  90648. +
  90649. + do {
  90650. + dma_desc = &qh->desc_list[n_desc];
  90651. + len = hc->xfer_len;
  90652. +
  90653. + if (len > MAX_DMA_DESC_SIZE)
  90654. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  90655. +
  90656. + if (hc->ep_is_in) {
  90657. + if (len > 0) {
  90658. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  90659. + } else {
  90660. + /* Need 1 packet for transfer length of 0. */
  90661. + num_packets = 1;
  90662. + }
  90663. + /* Always program an integral # of max packets for IN transfers. */
  90664. + len = num_packets * hc->max_packet;
  90665. + }
  90666. +
  90667. + dma_desc->status.b.n_bytes = len;
  90668. +
  90669. + qh->n_bytes[n_desc] = len;
  90670. +
  90671. + if ((qh->ep_type == UE_CONTROL)
  90672. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  90673. + dma_desc->status.b.sup = 1; /* Setup Packet */
  90674. +
  90675. + dma_desc->status.b.a = 1; /* Active descriptor */
  90676. + dma_desc->status.b.sts = 0;
  90677. +
  90678. + dma_desc->buf =
  90679. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  90680. +
  90681. + /*
  90682. + * Last descriptor(or single) of IN transfer
  90683. + * with actual size less than MaxPacket.
  90684. + */
  90685. + if (len > hc->xfer_len) {
  90686. + hc->xfer_len = 0;
  90687. + } else {
  90688. + hc->xfer_buff += len;
  90689. + hc->xfer_len -= len;
  90690. + }
  90691. +
  90692. + qtd->n_desc++;
  90693. + n_desc++;
  90694. + }
  90695. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  90696. +
  90697. +
  90698. + qtd->in_process = 1;
  90699. +
  90700. + if (qh->ep_type == UE_CONTROL)
  90701. + break;
  90702. +
  90703. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  90704. + break;
  90705. + }
  90706. +
  90707. + if (n_desc) {
  90708. + /* Request Transfer Complete interrupt for the last descriptor */
  90709. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  90710. + /* End of List indicator */
  90711. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  90712. +
  90713. + hc->ntd = n_desc;
  90714. + }
  90715. +}
  90716. +
  90717. +/**
  90718. + * For Control and Bulk endpoints initializes descriptor list
  90719. + * and starts the transfer.
  90720. + *
  90721. + * For Interrupt and Isochronous endpoints initializes descriptor list
  90722. + * then updates FrameList, marking appropriate entries as active.
  90723. + * In case of Isochronous, the starting descriptor index is calculated based
  90724. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  90725. + * Then starts the transfer via enabling the channel.
  90726. + * For Isochronous endpoint the channel is not halted on XferComplete
  90727. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  90728. + *
  90729. + * @param hcd The HCD state structure for the DWC OTG controller.
  90730. + * @param qh The QH to init.
  90731. + *
  90732. + * @return 0 if successful, negative error code otherwise.
  90733. + */
  90734. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  90735. +{
  90736. + /* Channel is already assigned */
  90737. + dwc_hc_t *hc = qh->channel;
  90738. + uint8_t skip_frames = 0;
  90739. +
  90740. + switch (hc->ep_type) {
  90741. + case DWC_OTG_EP_TYPE_CONTROL:
  90742. + case DWC_OTG_EP_TYPE_BULK:
  90743. + init_non_isoc_dma_desc(hcd, qh);
  90744. +
  90745. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90746. + break;
  90747. + case DWC_OTG_EP_TYPE_INTR:
  90748. + init_non_isoc_dma_desc(hcd, qh);
  90749. +
  90750. + update_frame_list(hcd, qh, 1);
  90751. +
  90752. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90753. + break;
  90754. + case DWC_OTG_EP_TYPE_ISOC:
  90755. +
  90756. + if (!qh->ntd)
  90757. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  90758. +
  90759. + init_isoc_dma_desc(hcd, qh, skip_frames);
  90760. +
  90761. + if (!hc->xfer_started) {
  90762. +
  90763. + update_frame_list(hcd, qh, 1);
  90764. +
  90765. + /*
  90766. + * Always set to max, instead of actual size.
  90767. + * Otherwise ntd will be changed with
  90768. + * channel being enabled. Not recommended.
  90769. + *
  90770. + */
  90771. + hc->ntd = max_desc_num(qh);
  90772. + /* Enable channel only once for ISOC */
  90773. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  90774. + }
  90775. +
  90776. + break;
  90777. + default:
  90778. +
  90779. + break;
  90780. + }
  90781. +}
  90782. +
  90783. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  90784. + dwc_hc_t * hc,
  90785. + dwc_otg_hc_regs_t * hc_regs,
  90786. + dwc_otg_halt_status_e halt_status)
  90787. +{
  90788. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  90789. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  90790. + dwc_otg_qh_t *qh;
  90791. + dwc_otg_host_dma_desc_t *dma_desc;
  90792. + uint16_t idx, remain;
  90793. + uint8_t urb_compl;
  90794. +
  90795. + qh = hc->qh;
  90796. + idx = qh->td_first;
  90797. +
  90798. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90799. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  90800. + qtd->in_process = 0;
  90801. + return;
  90802. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  90803. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  90804. + /*
  90805. + * Channel is halted in these error cases.
  90806. + * Considered as serious issues.
  90807. + * Complete all URBs marking all frames as failed,
  90808. + * irrespective whether some of the descriptors(frames) succeeded or no.
  90809. + * Pass error code to completion routine as well, to
  90810. + * update urb->status, some of class drivers might use it to stop
  90811. + * queing transfer requests.
  90812. + */
  90813. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  90814. + ? (-DWC_E_IO)
  90815. + : (-DWC_E_OVERFLOW);
  90816. +
  90817. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90818. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  90819. + frame_desc = &qtd->urb->iso_descs[idx];
  90820. + frame_desc->status = err;
  90821. + }
  90822. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  90823. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  90824. + }
  90825. + return;
  90826. + }
  90827. +
  90828. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90829. +
  90830. + if (!qtd->in_process)
  90831. + break;
  90832. +
  90833. + urb_compl = 0;
  90834. +
  90835. + do {
  90836. +
  90837. + dma_desc = &qh->desc_list[idx];
  90838. +
  90839. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  90840. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  90841. +
  90842. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  90843. + /*
  90844. + * XactError or, unable to complete all the transactions
  90845. + * in the scheduled micro-frame/frame,
  90846. + * both indicated by DMA_DESC_STS_PKTERR.
  90847. + */
  90848. + qtd->urb->error_count++;
  90849. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  90850. + frame_desc->status = -DWC_E_PROTOCOL;
  90851. + } else {
  90852. + /* Success */
  90853. +
  90854. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  90855. + frame_desc->status = 0;
  90856. + }
  90857. +
  90858. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  90859. + /*
  90860. + * urb->status is not used for isoc transfers here.
  90861. + * The individual frame_desc status are used instead.
  90862. + */
  90863. +
  90864. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  90865. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  90866. +
  90867. + /*
  90868. + * This check is necessary because urb_dequeue can be called
  90869. + * from urb complete callback(sound driver example).
  90870. + * All pending URBs are dequeued there, so no need for
  90871. + * further processing.
  90872. + */
  90873. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90874. + return;
  90875. + }
  90876. +
  90877. + urb_compl = 1;
  90878. +
  90879. + }
  90880. +
  90881. + qh->ntd--;
  90882. +
  90883. + /* Stop if IOC requested descriptor reached */
  90884. + if (dma_desc->status.b_isoc.ioc) {
  90885. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  90886. + goto stop_scan;
  90887. + }
  90888. +
  90889. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  90890. +
  90891. + if (urb_compl)
  90892. + break;
  90893. + }
  90894. + while (idx != qh->td_first);
  90895. + }
  90896. +stop_scan:
  90897. + qh->td_first = idx;
  90898. +}
  90899. +
  90900. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  90901. + dwc_hc_t * hc,
  90902. + dwc_otg_qtd_t * qtd,
  90903. + dwc_otg_host_dma_desc_t * dma_desc,
  90904. + dwc_otg_halt_status_e halt_status,
  90905. + uint32_t n_bytes, uint8_t * xfer_done)
  90906. +{
  90907. +
  90908. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  90909. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  90910. +
  90911. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  90912. + urb->status = -DWC_E_IO;
  90913. + return 1;
  90914. + }
  90915. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  90916. + switch (halt_status) {
  90917. + case DWC_OTG_HC_XFER_STALL:
  90918. + urb->status = -DWC_E_PIPE;
  90919. + break;
  90920. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  90921. + urb->status = -DWC_E_OVERFLOW;
  90922. + break;
  90923. + case DWC_OTG_HC_XFER_XACT_ERR:
  90924. + urb->status = -DWC_E_PROTOCOL;
  90925. + break;
  90926. + default:
  90927. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  90928. + halt_status);
  90929. + break;
  90930. + }
  90931. + return 1;
  90932. + }
  90933. +
  90934. + if (dma_desc->status.b.a == 1) {
  90935. + DWC_DEBUGPL(DBG_HCDV,
  90936. + "Active descriptor encountered on channel %d\n",
  90937. + hc->hc_num);
  90938. + return 0;
  90939. + }
  90940. +
  90941. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  90942. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  90943. + urb->actual_length += n_bytes - remain;
  90944. + if (remain || urb->actual_length == urb->length) {
  90945. + /*
  90946. + * For Control Data stage do not set urb->status=0 to prevent
  90947. + * URB callback. Set it when Status phase done. See below.
  90948. + */
  90949. + *xfer_done = 1;
  90950. + }
  90951. +
  90952. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  90953. + urb->status = 0;
  90954. + *xfer_done = 1;
  90955. + }
  90956. + /* No handling for SETUP stage */
  90957. + } else {
  90958. + /* BULK and INTR */
  90959. + urb->actual_length += n_bytes - remain;
  90960. + if (remain || urb->actual_length == urb->length) {
  90961. + urb->status = 0;
  90962. + *xfer_done = 1;
  90963. + }
  90964. + }
  90965. +
  90966. + return 0;
  90967. +}
  90968. +
  90969. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  90970. + dwc_hc_t * hc,
  90971. + dwc_otg_hc_regs_t * hc_regs,
  90972. + dwc_otg_halt_status_e halt_status)
  90973. +{
  90974. + dwc_otg_hcd_urb_t *urb = NULL;
  90975. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  90976. + dwc_otg_qh_t *qh;
  90977. + dwc_otg_host_dma_desc_t *dma_desc;
  90978. + uint32_t n_bytes, n_desc, i;
  90979. + uint8_t failed = 0, xfer_done;
  90980. +
  90981. + n_desc = 0;
  90982. +
  90983. + qh = hc->qh;
  90984. +
  90985. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  90986. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  90987. + qtd->in_process = 0;
  90988. + }
  90989. + return;
  90990. + }
  90991. +
  90992. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  90993. +
  90994. + urb = qtd->urb;
  90995. +
  90996. + n_bytes = 0;
  90997. + xfer_done = 0;
  90998. +
  90999. + for (i = 0; i < qtd->n_desc; i++) {
  91000. + dma_desc = &qh->desc_list[n_desc];
  91001. +
  91002. + n_bytes = qh->n_bytes[n_desc];
  91003. +
  91004. + failed =
  91005. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  91006. + dma_desc,
  91007. + halt_status, n_bytes,
  91008. + &xfer_done);
  91009. +
  91010. + if (failed
  91011. + || (xfer_done
  91012. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  91013. +
  91014. + hcd->fops->complete(hcd, urb->priv, urb,
  91015. + urb->status);
  91016. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  91017. +
  91018. + if (failed)
  91019. + goto stop_scan;
  91020. + } else if (qh->ep_type == UE_CONTROL) {
  91021. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  91022. + if (urb->length > 0) {
  91023. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  91024. + } else {
  91025. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  91026. + }
  91027. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  91028. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  91029. + if (xfer_done) {
  91030. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  91031. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  91032. + } else if (i + 1 == qtd->n_desc) {
  91033. + /*
  91034. + * Last descriptor for Control data stage which is
  91035. + * not completed yet.
  91036. + */
  91037. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  91038. + }
  91039. + }
  91040. + }
  91041. +
  91042. + n_desc++;
  91043. + }
  91044. +
  91045. + }
  91046. +
  91047. +stop_scan:
  91048. +
  91049. + if (qh->ep_type != UE_CONTROL) {
  91050. + /*
  91051. + * Resetting the data toggle for bulk
  91052. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  91053. + */
  91054. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  91055. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  91056. + else
  91057. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  91058. + }
  91059. +
  91060. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  91061. + hcint_data_t hcint;
  91062. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  91063. + if (hcint.b.nyet) {
  91064. + /*
  91065. + * Got a NYET on the last transaction of the transfer. It
  91066. + * means that the endpoint should be in the PING state at the
  91067. + * beginning of the next transfer.
  91068. + */
  91069. + qh->ping_state = 1;
  91070. + clear_hc_int(hc_regs, nyet);
  91071. + }
  91072. +
  91073. + }
  91074. +
  91075. +}
  91076. +
  91077. +/**
  91078. + * This function is called from interrupt handlers.
  91079. + * Scans the descriptor list, updates URB's status and
  91080. + * calls completion routine for the URB if it's done.
  91081. + * Releases the channel to be used by other transfers.
  91082. + * In case of Isochronous endpoint the channel is not halted until
  91083. + * the end of the session, i.e. QTD list is empty.
  91084. + * If periodic channel released the FrameList is updated accordingly.
  91085. + *
  91086. + * Calls transaction selection routines to activate pending transfers.
  91087. + *
  91088. + * @param hcd The HCD state structure for the DWC OTG controller.
  91089. + * @param hc Host channel, the transfer is completed on.
  91090. + * @param hc_regs Host channel registers.
  91091. + * @param halt_status Reason the channel is being halted,
  91092. + * or just XferComplete for isochronous transfer
  91093. + */
  91094. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  91095. + dwc_hc_t * hc,
  91096. + dwc_otg_hc_regs_t * hc_regs,
  91097. + dwc_otg_halt_status_e halt_status)
  91098. +{
  91099. + uint8_t continue_isoc_xfer = 0;
  91100. + dwc_otg_transaction_type_e tr_type;
  91101. + dwc_otg_qh_t *qh = hc->qh;
  91102. +
  91103. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  91104. +
  91105. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  91106. +
  91107. + /* Release the channel if halted or session completed */
  91108. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  91109. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  91110. +
  91111. + /* Halt the channel if session completed */
  91112. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  91113. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  91114. + }
  91115. +
  91116. + release_channel_ddma(hcd, qh);
  91117. + dwc_otg_hcd_qh_remove(hcd, qh);
  91118. + } else {
  91119. + /* Keep in assigned schedule to continue transfer */
  91120. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  91121. + &qh->qh_list_entry);
  91122. + continue_isoc_xfer = 1;
  91123. +
  91124. + }
  91125. + /** @todo Consider the case when period exceeds FrameList size.
  91126. + * Frame Rollover interrupt should be used.
  91127. + */
  91128. + } else {
  91129. + /* Scan descriptor list to complete the URB(s), then release the channel */
  91130. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  91131. +
  91132. + release_channel_ddma(hcd, qh);
  91133. + dwc_otg_hcd_qh_remove(hcd, qh);
  91134. +
  91135. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  91136. + /* Add back to inactive non-periodic schedule on normal completion */
  91137. + dwc_otg_hcd_qh_add(hcd, qh);
  91138. + }
  91139. +
  91140. + }
  91141. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  91142. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  91143. + if (continue_isoc_xfer) {
  91144. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  91145. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  91146. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  91147. + tr_type = DWC_OTG_TRANSACTION_ALL;
  91148. + }
  91149. + }
  91150. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  91151. + }
  91152. +}
  91153. +
  91154. +#endif /* DWC_DEVICE_ONLY */
  91155. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  91156. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  91157. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2015-03-09 10:39:33.218893718 +0100
  91158. @@ -0,0 +1,862 @@
  91159. +/* ==========================================================================
  91160. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  91161. + * $Revision: #58 $
  91162. + * $Date: 2011/09/15 $
  91163. + * $Change: 1846647 $
  91164. + *
  91165. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  91166. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  91167. + * otherwise expressly agreed to in writing between Synopsys and you.
  91168. + *
  91169. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  91170. + * any End User Software License Agreement or Agreement for Licensed Product
  91171. + * with Synopsys or any supplement thereto. You are permitted to use and
  91172. + * redistribute this Software in source and binary forms, with or without
  91173. + * modification, provided that redistributions of source code must retain this
  91174. + * notice. You may not view, use, disclose, copy or distribute this file or
  91175. + * any information contained herein except pursuant to this license grant from
  91176. + * Synopsys. If you do not agree with this notice, including the disclaimer
  91177. + * below, then you are not authorized to use the Software.
  91178. + *
  91179. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  91180. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  91181. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  91182. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  91183. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  91184. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  91185. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  91186. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  91187. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  91188. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  91189. + * DAMAGE.
  91190. + * ========================================================================== */
  91191. +#ifndef DWC_DEVICE_ONLY
  91192. +#ifndef __DWC_HCD_H__
  91193. +#define __DWC_HCD_H__
  91194. +
  91195. +#include "dwc_otg_os_dep.h"
  91196. +#include "usb.h"
  91197. +#include "dwc_otg_hcd_if.h"
  91198. +#include "dwc_otg_core_if.h"
  91199. +#include "dwc_list.h"
  91200. +#include "dwc_otg_cil.h"
  91201. +#include "dwc_otg_fiq_fsm.h"
  91202. +
  91203. +
  91204. +/**
  91205. + * @file
  91206. + *
  91207. + * This file contains the structures, constants, and interfaces for
  91208. + * the Host Contoller Driver (HCD).
  91209. + *
  91210. + * The Host Controller Driver (HCD) is responsible for translating requests
  91211. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  91212. + * It isolates the USBD from the specifics of the controller by providing an
  91213. + * API to the USBD.
  91214. + */
  91215. +
  91216. +struct dwc_otg_hcd_pipe_info {
  91217. + uint8_t dev_addr;
  91218. + uint8_t ep_num;
  91219. + uint8_t pipe_type;
  91220. + uint8_t pipe_dir;
  91221. + uint16_t mps;
  91222. +};
  91223. +
  91224. +struct dwc_otg_hcd_iso_packet_desc {
  91225. + uint32_t offset;
  91226. + uint32_t length;
  91227. + uint32_t actual_length;
  91228. + uint32_t status;
  91229. +};
  91230. +
  91231. +struct dwc_otg_qtd;
  91232. +
  91233. +struct dwc_otg_hcd_urb {
  91234. + void *priv;
  91235. + struct dwc_otg_qtd *qtd;
  91236. + void *buf;
  91237. + dwc_dma_t dma;
  91238. + void *setup_packet;
  91239. + dwc_dma_t setup_dma;
  91240. + uint32_t length;
  91241. + uint32_t actual_length;
  91242. + uint32_t status;
  91243. + uint32_t error_count;
  91244. + uint32_t packet_count;
  91245. + uint32_t flags;
  91246. + uint16_t interval;
  91247. + struct dwc_otg_hcd_pipe_info pipe_info;
  91248. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  91249. +};
  91250. +
  91251. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  91252. +{
  91253. + return pipe->ep_num;
  91254. +}
  91255. +
  91256. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  91257. + *pipe)
  91258. +{
  91259. + return pipe->pipe_type;
  91260. +}
  91261. +
  91262. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  91263. +{
  91264. + return pipe->mps;
  91265. +}
  91266. +
  91267. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  91268. + *pipe)
  91269. +{
  91270. + return pipe->dev_addr;
  91271. +}
  91272. +
  91273. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  91274. + *pipe)
  91275. +{
  91276. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  91277. +}
  91278. +
  91279. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  91280. + *pipe)
  91281. +{
  91282. + return (pipe->pipe_type == UE_INTERRUPT);
  91283. +}
  91284. +
  91285. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  91286. + *pipe)
  91287. +{
  91288. + return (pipe->pipe_type == UE_BULK);
  91289. +}
  91290. +
  91291. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  91292. + *pipe)
  91293. +{
  91294. + return (pipe->pipe_type == UE_CONTROL);
  91295. +}
  91296. +
  91297. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  91298. +{
  91299. + return (pipe->pipe_dir == UE_DIR_IN);
  91300. +}
  91301. +
  91302. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  91303. + *pipe)
  91304. +{
  91305. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  91306. +}
  91307. +
  91308. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  91309. + uint8_t devaddr, uint8_t ep_num,
  91310. + uint8_t pipe_type, uint8_t pipe_dir,
  91311. + uint16_t mps)
  91312. +{
  91313. + pipe->dev_addr = devaddr;
  91314. + pipe->ep_num = ep_num;
  91315. + pipe->pipe_type = pipe_type;
  91316. + pipe->pipe_dir = pipe_dir;
  91317. + pipe->mps = mps;
  91318. +}
  91319. +
  91320. +/**
  91321. + * Phases for control transfers.
  91322. + */
  91323. +typedef enum dwc_otg_control_phase {
  91324. + DWC_OTG_CONTROL_SETUP,
  91325. + DWC_OTG_CONTROL_DATA,
  91326. + DWC_OTG_CONTROL_STATUS
  91327. +} dwc_otg_control_phase_e;
  91328. +
  91329. +/** Transaction types. */
  91330. +typedef enum dwc_otg_transaction_type {
  91331. + DWC_OTG_TRANSACTION_NONE = 0,
  91332. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  91333. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  91334. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  91335. +} dwc_otg_transaction_type_e;
  91336. +
  91337. +struct dwc_otg_qh;
  91338. +
  91339. +/**
  91340. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  91341. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  91342. + * (of one of these types) submitted to the HCD. The transfer associated with
  91343. + * a QTD may require one or multiple transactions.
  91344. + *
  91345. + * A QTD is linked to a Queue Head, which is entered in either the
  91346. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  91347. + * execution, some or all of its transactions may be executed. After
  91348. + * execution, the state of the QTD is updated. The QTD may be retired if all
  91349. + * its transactions are complete or if an error occurred. Otherwise, it
  91350. + * remains in the schedule so more transactions can be executed later.
  91351. + */
  91352. +typedef struct dwc_otg_qtd {
  91353. + /**
  91354. + * Determines the PID of the next data packet for the data phase of
  91355. + * control transfers. Ignored for other transfer types.<br>
  91356. + * One of the following values:
  91357. + * - DWC_OTG_HC_PID_DATA0
  91358. + * - DWC_OTG_HC_PID_DATA1
  91359. + */
  91360. + uint8_t data_toggle;
  91361. +
  91362. + /** Current phase for control transfers (Setup, Data, or Status). */
  91363. + dwc_otg_control_phase_e control_phase;
  91364. +
  91365. + /** Keep track of the current split type
  91366. + * for FS/LS endpoints on a HS Hub */
  91367. + uint8_t complete_split;
  91368. +
  91369. + /** How many bytes transferred during SSPLIT OUT */
  91370. + uint32_t ssplit_out_xfer_count;
  91371. +
  91372. + /**
  91373. + * Holds the number of bus errors that have occurred for a transaction
  91374. + * within this transfer.
  91375. + */
  91376. + uint8_t error_count;
  91377. +
  91378. + /**
  91379. + * Index of the next frame descriptor for an isochronous transfer. A
  91380. + * frame descriptor describes the buffer position and length of the
  91381. + * data to be transferred in the next scheduled (micro)frame of an
  91382. + * isochronous transfer. It also holds status for that transaction.
  91383. + * The frame index starts at 0.
  91384. + */
  91385. + uint16_t isoc_frame_index;
  91386. +
  91387. + /** Position of the ISOC split on full/low speed */
  91388. + uint8_t isoc_split_pos;
  91389. +
  91390. + /** Position of the ISOC split in the buffer for the current frame */
  91391. + uint16_t isoc_split_offset;
  91392. +
  91393. + /** URB for this transfer */
  91394. + struct dwc_otg_hcd_urb *urb;
  91395. +
  91396. + struct dwc_otg_qh *qh;
  91397. +
  91398. + /** This list of QTDs */
  91399. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  91400. +
  91401. + /** Indicates if this QTD is currently processed by HW. */
  91402. + uint8_t in_process;
  91403. +
  91404. + /** Number of DMA descriptors for this QTD */
  91405. + uint8_t n_desc;
  91406. +
  91407. + /**
  91408. + * Last activated frame(packet) index.
  91409. + * Used in Descriptor DMA mode only.
  91410. + */
  91411. + uint16_t isoc_frame_index_last;
  91412. +
  91413. +} dwc_otg_qtd_t;
  91414. +
  91415. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  91416. +
  91417. +/**
  91418. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  91419. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  91420. + * be entered in either the non-periodic or periodic schedule.
  91421. + */
  91422. +typedef struct dwc_otg_qh {
  91423. + /**
  91424. + * Endpoint type.
  91425. + * One of the following values:
  91426. + * - UE_CONTROL
  91427. + * - UE_BULK
  91428. + * - UE_INTERRUPT
  91429. + * - UE_ISOCHRONOUS
  91430. + */
  91431. + uint8_t ep_type;
  91432. + uint8_t ep_is_in;
  91433. +
  91434. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  91435. + uint16_t maxp;
  91436. +
  91437. + /**
  91438. + * Device speed.
  91439. + * One of the following values:
  91440. + * - DWC_OTG_EP_SPEED_LOW
  91441. + * - DWC_OTG_EP_SPEED_FULL
  91442. + * - DWC_OTG_EP_SPEED_HIGH
  91443. + */
  91444. + uint8_t dev_speed;
  91445. +
  91446. + /**
  91447. + * Determines the PID of the next data packet for non-control
  91448. + * transfers. Ignored for control transfers.<br>
  91449. + * One of the following values:
  91450. + * - DWC_OTG_HC_PID_DATA0
  91451. + * - DWC_OTG_HC_PID_DATA1
  91452. + */
  91453. + uint8_t data_toggle;
  91454. +
  91455. + /** Ping state if 1. */
  91456. + uint8_t ping_state;
  91457. +
  91458. + /**
  91459. + * List of QTDs for this QH.
  91460. + */
  91461. + struct dwc_otg_qtd_list qtd_list;
  91462. +
  91463. + /** Host channel currently processing transfers for this QH. */
  91464. + struct dwc_hc *channel;
  91465. +
  91466. + /** Full/low speed endpoint on high-speed hub requires split. */
  91467. + uint8_t do_split;
  91468. +
  91469. + /** @name Periodic schedule information */
  91470. + /** @{ */
  91471. +
  91472. + /** Bandwidth in microseconds per (micro)frame. */
  91473. + uint16_t usecs;
  91474. +
  91475. + /** Interval between transfers in (micro)frames. */
  91476. + uint16_t interval;
  91477. +
  91478. + /**
  91479. + * (micro)frame to initialize a periodic transfer. The transfer
  91480. + * executes in the following (micro)frame.
  91481. + */
  91482. + uint16_t sched_frame;
  91483. +
  91484. + /*
  91485. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  91486. + */
  91487. + uint16_t nak_frame;
  91488. +
  91489. + /** (micro)frame at which last start split was initialized. */
  91490. + uint16_t start_split_frame;
  91491. +
  91492. + /** @} */
  91493. +
  91494. + /**
  91495. + * Used instead of original buffer if
  91496. + * it(physical address) is not dword-aligned.
  91497. + */
  91498. + uint8_t *dw_align_buf;
  91499. + dwc_dma_t dw_align_buf_dma;
  91500. +
  91501. + /** Entry for QH in either the periodic or non-periodic schedule. */
  91502. + dwc_list_link_t qh_list_entry;
  91503. +
  91504. + /** @name Descriptor DMA support */
  91505. + /** @{ */
  91506. +
  91507. + /** Descriptor List. */
  91508. + dwc_otg_host_dma_desc_t *desc_list;
  91509. +
  91510. + /** Descriptor List physical address. */
  91511. + dwc_dma_t desc_list_dma;
  91512. +
  91513. + /**
  91514. + * Xfer Bytes array.
  91515. + * Each element corresponds to a descriptor and indicates
  91516. + * original XferSize size value for the descriptor.
  91517. + */
  91518. + uint32_t *n_bytes;
  91519. +
  91520. + /** Actual number of transfer descriptors in a list. */
  91521. + uint16_t ntd;
  91522. +
  91523. + /** First activated isochronous transfer descriptor index. */
  91524. + uint8_t td_first;
  91525. + /** Last activated isochronous transfer descriptor index. */
  91526. + uint8_t td_last;
  91527. +
  91528. + /** @} */
  91529. +
  91530. +
  91531. + uint16_t speed;
  91532. + uint16_t frame_usecs[8];
  91533. +
  91534. + uint32_t skip_count;
  91535. +} dwc_otg_qh_t;
  91536. +
  91537. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  91538. +
  91539. +typedef struct urb_tq_entry {
  91540. + struct urb *urb;
  91541. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  91542. +} urb_tq_entry_t;
  91543. +
  91544. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  91545. +
  91546. +/**
  91547. + * This structure holds the state of the HCD, including the non-periodic and
  91548. + * periodic schedules.
  91549. + */
  91550. +struct dwc_otg_hcd {
  91551. + /** The DWC otg device pointer */
  91552. + struct dwc_otg_device *otg_dev;
  91553. + /** DWC OTG Core Interface Layer */
  91554. + dwc_otg_core_if_t *core_if;
  91555. +
  91556. + /** Function HCD driver callbacks */
  91557. + struct dwc_otg_hcd_function_ops *fops;
  91558. +
  91559. + /** Internal DWC HCD Flags */
  91560. + volatile union dwc_otg_hcd_internal_flags {
  91561. + uint32_t d32;
  91562. + struct {
  91563. + unsigned port_connect_status_change:1;
  91564. + unsigned port_connect_status:1;
  91565. + unsigned port_reset_change:1;
  91566. + unsigned port_enable_change:1;
  91567. + unsigned port_suspend_change:1;
  91568. + unsigned port_over_current_change:1;
  91569. + unsigned port_l1_change:1;
  91570. + unsigned reserved:26;
  91571. + } b;
  91572. + } flags;
  91573. +
  91574. + /**
  91575. + * Inactive items in the non-periodic schedule. This is a list of
  91576. + * Queue Heads. Transfers associated with these Queue Heads are not
  91577. + * currently assigned to a host channel.
  91578. + */
  91579. + dwc_list_link_t non_periodic_sched_inactive;
  91580. +
  91581. + /**
  91582. + * Active items in the non-periodic schedule. This is a list of
  91583. + * Queue Heads. Transfers associated with these Queue Heads are
  91584. + * currently assigned to a host channel.
  91585. + */
  91586. + dwc_list_link_t non_periodic_sched_active;
  91587. +
  91588. + /**
  91589. + * Pointer to the next Queue Head to process in the active
  91590. + * non-periodic schedule.
  91591. + */
  91592. + dwc_list_link_t *non_periodic_qh_ptr;
  91593. +
  91594. + /**
  91595. + * Inactive items in the periodic schedule. This is a list of QHs for
  91596. + * periodic transfers that are _not_ scheduled for the next frame.
  91597. + * Each QH in the list has an interval counter that determines when it
  91598. + * needs to be scheduled for execution. This scheduling mechanism
  91599. + * allows only a simple calculation for periodic bandwidth used (i.e.
  91600. + * must assume that all periodic transfers may need to execute in the
  91601. + * same frame). However, it greatly simplifies scheduling and should
  91602. + * be sufficient for the vast majority of OTG hosts, which need to
  91603. + * connect to a small number of peripherals at one time.
  91604. + *
  91605. + * Items move from this list to periodic_sched_ready when the QH
  91606. + * interval counter is 0 at SOF.
  91607. + */
  91608. + dwc_list_link_t periodic_sched_inactive;
  91609. +
  91610. + /**
  91611. + * List of periodic QHs that are ready for execution in the next
  91612. + * frame, but have not yet been assigned to host channels.
  91613. + *
  91614. + * Items move from this list to periodic_sched_assigned as host
  91615. + * channels become available during the current frame.
  91616. + */
  91617. + dwc_list_link_t periodic_sched_ready;
  91618. +
  91619. + /**
  91620. + * List of periodic QHs to be executed in the next frame that are
  91621. + * assigned to host channels.
  91622. + *
  91623. + * Items move from this list to periodic_sched_queued as the
  91624. + * transactions for the QH are queued to the DWC_otg controller.
  91625. + */
  91626. + dwc_list_link_t periodic_sched_assigned;
  91627. +
  91628. + /**
  91629. + * List of periodic QHs that have been queued for execution.
  91630. + *
  91631. + * Items move from this list to either periodic_sched_inactive or
  91632. + * periodic_sched_ready when the channel associated with the transfer
  91633. + * is released. If the interval for the QH is 1, the item moves to
  91634. + * periodic_sched_ready because it must be rescheduled for the next
  91635. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  91636. + */
  91637. + dwc_list_link_t periodic_sched_queued;
  91638. +
  91639. + /**
  91640. + * Total bandwidth claimed so far for periodic transfers. This value
  91641. + * is in microseconds per (micro)frame. The assumption is that all
  91642. + * periodic transfers may occur in the same (micro)frame.
  91643. + */
  91644. + uint16_t periodic_usecs;
  91645. +
  91646. + /**
  91647. + * Total bandwidth claimed so far for all periodic transfers
  91648. + * in a frame.
  91649. + * This will include a mixture of HS and FS transfers.
  91650. + * Units are microseconds per (micro)frame.
  91651. + * We have a budget per frame and have to schedule
  91652. + * transactions accordingly.
  91653. + * Watch out for the fact that things are actually scheduled for the
  91654. + * "next frame".
  91655. + */
  91656. + uint16_t frame_usecs[8];
  91657. +
  91658. +
  91659. + /**
  91660. + * Frame number read from the core at SOF. The value ranges from 0 to
  91661. + * DWC_HFNUM_MAX_FRNUM.
  91662. + */
  91663. + uint16_t frame_number;
  91664. +
  91665. + /**
  91666. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  91667. + */
  91668. + uint16_t periodic_qh_count;
  91669. +
  91670. + /**
  91671. + * Free host channels in the controller. This is a list of
  91672. + * dwc_hc_t items.
  91673. + */
  91674. + struct hc_list free_hc_list;
  91675. + /**
  91676. + * Number of host channels assigned to periodic transfers. Currently
  91677. + * assuming that there is a dedicated host channel for each periodic
  91678. + * transaction and at least one host channel available for
  91679. + * non-periodic transactions.
  91680. + */
  91681. + int periodic_channels; /* microframe_schedule==0 */
  91682. +
  91683. + /**
  91684. + * Number of host channels assigned to non-periodic transfers.
  91685. + */
  91686. + int non_periodic_channels; /* microframe_schedule==0 */
  91687. +
  91688. + /**
  91689. + * Number of host channels assigned to non-periodic transfers.
  91690. + */
  91691. + int available_host_channels;
  91692. +
  91693. + /**
  91694. + * Array of pointers to the host channel descriptors. Allows accessing
  91695. + * a host channel descriptor given the host channel number. This is
  91696. + * useful in interrupt handlers.
  91697. + */
  91698. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  91699. +
  91700. + /**
  91701. + * Buffer to use for any data received during the status phase of a
  91702. + * control transfer. Normally no data is transferred during the status
  91703. + * phase. This buffer is used as a bit bucket.
  91704. + */
  91705. + uint8_t *status_buf;
  91706. +
  91707. + /**
  91708. + * DMA address for status_buf.
  91709. + */
  91710. + dma_addr_t status_buf_dma;
  91711. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  91712. +
  91713. + /**
  91714. + * Connection timer. An OTG host must display a message if the device
  91715. + * does not connect. Started when the VBus power is turned on via
  91716. + * sysfs attribute "buspower".
  91717. + */
  91718. + dwc_timer_t *conn_timer;
  91719. +
  91720. + /* Tasket to do a reset */
  91721. + dwc_tasklet_t *reset_tasklet;
  91722. +
  91723. + dwc_tasklet_t *completion_tasklet;
  91724. + struct urb_list completed_urb_list;
  91725. +
  91726. + /* */
  91727. + dwc_spinlock_t *lock;
  91728. + dwc_spinlock_t *channel_lock;
  91729. + /**
  91730. + * Private data that could be used by OS wrapper.
  91731. + */
  91732. + void *priv;
  91733. +
  91734. + uint8_t otg_port;
  91735. +
  91736. + /** Frame List */
  91737. + uint32_t *frame_list;
  91738. +
  91739. + /** Hub - Port assignment */
  91740. + int hub_port[128];
  91741. +#ifdef FIQ_DEBUG
  91742. + int hub_port_alloc[2048];
  91743. +#endif
  91744. +
  91745. + /** Frame List DMA address */
  91746. + dma_addr_t frame_list_dma;
  91747. +
  91748. + struct fiq_stack *fiq_stack;
  91749. + struct fiq_state *fiq_state;
  91750. +
  91751. + /** Virtual address for split transaction DMA bounce buffers */
  91752. + struct fiq_dma_blob *fiq_dmab;
  91753. +
  91754. +#ifdef DEBUG
  91755. + uint32_t frrem_samples;
  91756. + uint64_t frrem_accum;
  91757. +
  91758. + uint32_t hfnum_7_samples_a;
  91759. + uint64_t hfnum_7_frrem_accum_a;
  91760. + uint32_t hfnum_0_samples_a;
  91761. + uint64_t hfnum_0_frrem_accum_a;
  91762. + uint32_t hfnum_other_samples_a;
  91763. + uint64_t hfnum_other_frrem_accum_a;
  91764. +
  91765. + uint32_t hfnum_7_samples_b;
  91766. + uint64_t hfnum_7_frrem_accum_b;
  91767. + uint32_t hfnum_0_samples_b;
  91768. + uint64_t hfnum_0_frrem_accum_b;
  91769. + uint32_t hfnum_other_samples_b;
  91770. + uint64_t hfnum_other_frrem_accum_b;
  91771. +#endif
  91772. +};
  91773. +
  91774. +/** @name Transaction Execution Functions */
  91775. +/** @{ */
  91776. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  91777. + * hcd);
  91778. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  91779. + dwc_otg_transaction_type_e tr_type);
  91780. +
  91781. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  91782. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  91783. +
  91784. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  91785. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  91786. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  91787. +
  91788. +/** @} */
  91789. +
  91790. +/** @name Interrupt Handler Functions */
  91791. +/** @{ */
  91792. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91793. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91794. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  91795. + dwc_otg_hcd);
  91796. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  91797. + dwc_otg_hcd);
  91798. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  91799. + dwc_otg_hcd);
  91800. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  91801. + dwc_otg_hcd);
  91802. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91803. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  91804. + dwc_otg_hcd);
  91805. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91806. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91807. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  91808. + uint32_t num);
  91809. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  91810. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  91811. + dwc_otg_hcd);
  91812. +/** @} */
  91813. +
  91814. +/** @name Schedule Queue Functions */
  91815. +/** @{ */
  91816. +
  91817. +/* Implemented in dwc_otg_hcd_queue.c */
  91818. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  91819. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  91820. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91821. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91822. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91823. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  91824. + int sched_csplit);
  91825. +
  91826. +/** Remove and free a QH */
  91827. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  91828. + dwc_otg_qh_t * qh)
  91829. +{
  91830. + dwc_irqflags_t flags;
  91831. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  91832. + dwc_otg_hcd_qh_remove(hcd, qh);
  91833. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  91834. + dwc_otg_hcd_qh_free(hcd, qh);
  91835. +}
  91836. +
  91837. +/** Allocates memory for a QH structure.
  91838. + * @return Returns the memory allocate or NULL on error. */
  91839. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  91840. +{
  91841. + if (atomic_alloc)
  91842. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  91843. + else
  91844. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  91845. +}
  91846. +
  91847. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  91848. + int atomic_alloc);
  91849. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  91850. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  91851. + dwc_otg_qh_t ** qh, int atomic_alloc);
  91852. +
  91853. +/** Allocates memory for a QTD structure.
  91854. + * @return Returns the memory allocate or NULL on error. */
  91855. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  91856. +{
  91857. + if (atomic_alloc)
  91858. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  91859. + else
  91860. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  91861. +}
  91862. +
  91863. +/** Frees the memory for a QTD structure. QTD should already be removed from
  91864. + * list.
  91865. + * @param qtd QTD to free.*/
  91866. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  91867. +{
  91868. + DWC_FREE(qtd);
  91869. +}
  91870. +
  91871. +/** Removes a QTD from list.
  91872. + * @param hcd HCD instance.
  91873. + * @param qtd QTD to remove from list.
  91874. + * @param qh QTD belongs to.
  91875. + */
  91876. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  91877. + dwc_otg_qtd_t * qtd,
  91878. + dwc_otg_qh_t * qh)
  91879. +{
  91880. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  91881. +}
  91882. +
  91883. +/** Remove and free a QTD
  91884. + * Need to disable IRQ and hold hcd lock while calling this function out of
  91885. + * interrupt servicing chain */
  91886. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  91887. + dwc_otg_qtd_t * qtd,
  91888. + dwc_otg_qh_t * qh)
  91889. +{
  91890. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  91891. + dwc_otg_hcd_qtd_free(qtd);
  91892. +}
  91893. +
  91894. +/** @} */
  91895. +
  91896. +/** @name Descriptor DMA Supporting Functions */
  91897. +/** @{ */
  91898. +
  91899. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91900. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  91901. + dwc_hc_t * hc,
  91902. + dwc_otg_hc_regs_t * hc_regs,
  91903. + dwc_otg_halt_status_e halt_status);
  91904. +
  91905. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91906. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  91907. +
  91908. +/** @} */
  91909. +
  91910. +/** @name Internal Functions */
  91911. +/** @{ */
  91912. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  91913. +/** @} */
  91914. +
  91915. +#ifdef CONFIG_USB_DWC_OTG_LPM
  91916. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  91917. + uint8_t devaddr);
  91918. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  91919. +#endif
  91920. +
  91921. +/** Gets the QH that contains the list_head */
  91922. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  91923. +
  91924. +/** Gets the QTD that contains the list_head */
  91925. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  91926. +
  91927. +/** Check if QH is non-periodic */
  91928. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  91929. + (_qh_ptr_->ep_type == UE_CONTROL))
  91930. +
  91931. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  91932. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  91933. +
  91934. +/** Packet size for any kind of endpoint descriptor */
  91935. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  91936. +
  91937. +/**
  91938. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  91939. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  91940. + * frame number when the max frame number is reached.
  91941. + */
  91942. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  91943. +{
  91944. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  91945. + (DWC_HFNUM_MAX_FRNUM >> 1);
  91946. +}
  91947. +
  91948. +/**
  91949. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  91950. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  91951. + * number when the max frame number is reached.
  91952. + */
  91953. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  91954. +{
  91955. + return (frame1 != frame2) &&
  91956. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  91957. + (DWC_HFNUM_MAX_FRNUM >> 1));
  91958. +}
  91959. +
  91960. +/**
  91961. + * Increments _frame by the amount specified by _inc. The addition is done
  91962. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  91963. + */
  91964. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  91965. +{
  91966. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  91967. +}
  91968. +
  91969. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  91970. +{
  91971. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  91972. +}
  91973. +
  91974. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  91975. +{
  91976. + return frame & 0x7;
  91977. +}
  91978. +
  91979. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  91980. + dwc_otg_hc_regs_t * hc_regs,
  91981. + dwc_otg_qtd_t * qtd);
  91982. +
  91983. +#ifdef DEBUG
  91984. +/**
  91985. + * Macro to sample the remaining PHY clocks left in the current frame. This
  91986. + * may be used during debugging to determine the average time it takes to
  91987. + * execute sections of code. There are two possible sample points, "a" and
  91988. + * "b", so the _letter argument must be one of these values.
  91989. + *
  91990. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  91991. + * example, "cat /sys/devices/lm0/hcd_frrem".
  91992. + */
  91993. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  91994. +{ \
  91995. + hfnum_data_t hfnum; \
  91996. + dwc_otg_qtd_t *qtd; \
  91997. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  91998. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  91999. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  92000. + switch (hfnum.b.frnum & 0x7) { \
  92001. + case 7: \
  92002. + _hcd->hfnum_7_samples_##_letter++; \
  92003. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  92004. + break; \
  92005. + case 0: \
  92006. + _hcd->hfnum_0_samples_##_letter++; \
  92007. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  92008. + break; \
  92009. + default: \
  92010. + _hcd->hfnum_other_samples_##_letter++; \
  92011. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  92012. + break; \
  92013. + } \
  92014. + } \
  92015. +}
  92016. +#else
  92017. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  92018. +#endif
  92019. +#endif
  92020. +#endif /* DWC_DEVICE_ONLY */
  92021. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  92022. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  92023. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2015-03-09 10:39:33.218893718 +0100
  92024. @@ -0,0 +1,417 @@
  92025. +/* ==========================================================================
  92026. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  92027. + * $Revision: #12 $
  92028. + * $Date: 2011/10/26 $
  92029. + * $Change: 1873028 $
  92030. + *
  92031. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  92032. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  92033. + * otherwise expressly agreed to in writing between Synopsys and you.
  92034. + *
  92035. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  92036. + * any End User Software License Agreement or Agreement for Licensed Product
  92037. + * with Synopsys or any supplement thereto. You are permitted to use and
  92038. + * redistribute this Software in source and binary forms, with or without
  92039. + * modification, provided that redistributions of source code must retain this
  92040. + * notice. You may not view, use, disclose, copy or distribute this file or
  92041. + * any information contained herein except pursuant to this license grant from
  92042. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92043. + * below, then you are not authorized to use the Software.
  92044. + *
  92045. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92046. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92047. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92048. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92049. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92050. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92051. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92052. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92053. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92054. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92055. + * DAMAGE.
  92056. + * ========================================================================== */
  92057. +#ifndef DWC_DEVICE_ONLY
  92058. +#ifndef __DWC_HCD_IF_H__
  92059. +#define __DWC_HCD_IF_H__
  92060. +
  92061. +#include "dwc_otg_core_if.h"
  92062. +
  92063. +/** @file
  92064. + * This file defines DWC_OTG HCD Core API.
  92065. + */
  92066. +
  92067. +struct dwc_otg_hcd;
  92068. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  92069. +
  92070. +struct dwc_otg_hcd_urb;
  92071. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  92072. +
  92073. +/** @name HCD Function Driver Callbacks */
  92074. +/** @{ */
  92075. +
  92076. +/** This function is called whenever core switches to host mode. */
  92077. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  92078. +
  92079. +/** This function is called when device has been disconnected */
  92080. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  92081. +
  92082. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  92083. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  92084. + void *urb_handle,
  92085. + uint32_t * hub_addr,
  92086. + uint32_t * port_addr);
  92087. +/** Via this function HCD core gets device speed */
  92088. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  92089. + void *urb_handle);
  92090. +
  92091. +/** This function is called when urb is completed */
  92092. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  92093. + void *urb_handle,
  92094. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  92095. + int32_t status);
  92096. +
  92097. +/** Via this function HCD core gets b_hnp_enable parameter */
  92098. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  92099. +
  92100. +struct dwc_otg_hcd_function_ops {
  92101. + dwc_otg_hcd_start_cb_t start;
  92102. + dwc_otg_hcd_disconnect_cb_t disconnect;
  92103. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  92104. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  92105. + dwc_otg_hcd_complete_urb_cb_t complete;
  92106. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  92107. +};
  92108. +/** @} */
  92109. +
  92110. +/** @name HCD Core API */
  92111. +/** @{ */
  92112. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  92113. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  92114. +
  92115. +/** This function should be called to initiate HCD Core.
  92116. + *
  92117. + * @param hcd The HCD
  92118. + * @param core_if The DWC_OTG Core
  92119. + *
  92120. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  92121. + * Returns 0 on success
  92122. + */
  92123. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  92124. +
  92125. +/** Frees HCD
  92126. + *
  92127. + * @param hcd The HCD
  92128. + */
  92129. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  92130. +
  92131. +/** This function should be called on every hardware interrupt.
  92132. + *
  92133. + * @param dwc_otg_hcd The HCD
  92134. + *
  92135. + * Returns non zero if interrupt is handled
  92136. + * Return 0 if interrupt is not handled
  92137. + */
  92138. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  92139. +
  92140. +/** This function is used to handle the fast interrupt
  92141. + *
  92142. + */
  92143. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  92144. +
  92145. +/**
  92146. + * Returns private data set by
  92147. + * dwc_otg_hcd_set_priv_data function.
  92148. + *
  92149. + * @param hcd The HCD
  92150. + */
  92151. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  92152. +
  92153. +/**
  92154. + * Set private data.
  92155. + *
  92156. + * @param hcd The HCD
  92157. + * @param priv_data pointer to be stored in private data
  92158. + */
  92159. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  92160. +
  92161. +/**
  92162. + * This function initializes the HCD Core.
  92163. + *
  92164. + * @param hcd The HCD
  92165. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  92166. + *
  92167. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  92168. + * Returns 0 on success
  92169. + */
  92170. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  92171. + struct dwc_otg_hcd_function_ops *fops);
  92172. +
  92173. +/**
  92174. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  92175. + * stopped.
  92176. + *
  92177. + * @param hcd The HCD
  92178. + */
  92179. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  92180. +
  92181. +/**
  92182. + * Handles hub class-specific requests.
  92183. + *
  92184. + * @param dwc_otg_hcd The HCD
  92185. + * @param typeReq Request Type
  92186. + * @param wValue wValue from control request
  92187. + * @param wIndex wIndex from control request
  92188. + * @param buf data buffer
  92189. + * @param wLength data buffer length
  92190. + *
  92191. + * Returns -DWC_E_INVALID if invalid argument is passed
  92192. + * Returns 0 on success
  92193. + */
  92194. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  92195. + uint16_t typeReq, uint16_t wValue,
  92196. + uint16_t wIndex, uint8_t * buf,
  92197. + uint16_t wLength);
  92198. +
  92199. +/**
  92200. + * Returns otg port number.
  92201. + *
  92202. + * @param hcd The HCD
  92203. + */
  92204. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  92205. +
  92206. +/**
  92207. + * Returns OTG version - either 1.3 or 2.0.
  92208. + *
  92209. + * @param core_if The core_if structure pointer
  92210. + */
  92211. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  92212. +
  92213. +/**
  92214. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  92215. + *
  92216. + * @param hcd The HCD
  92217. + */
  92218. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  92219. +
  92220. +/**
  92221. + * Returns current frame number.
  92222. + *
  92223. + * @param hcd The HCD
  92224. + */
  92225. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  92226. +
  92227. +/**
  92228. + * Dumps hcd state.
  92229. + *
  92230. + * @param hcd The HCD
  92231. + */
  92232. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  92233. +
  92234. +/**
  92235. + * Dump the average frame remaining at SOF. This can be used to
  92236. + * determine average interrupt latency. Frame remaining is also shown for
  92237. + * start transfer and two additional sample points.
  92238. + * Currently this function is not implemented.
  92239. + *
  92240. + * @param hcd The HCD
  92241. + */
  92242. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  92243. +
  92244. +/**
  92245. + * Sends LPM transaction to the local device.
  92246. + *
  92247. + * @param hcd The HCD
  92248. + * @param devaddr Device Address
  92249. + * @param hird Host initiated resume duration
  92250. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  92251. + *
  92252. + * Returns negative value if sending LPM transaction was not succeeded.
  92253. + * Returns 0 on success.
  92254. + */
  92255. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  92256. + uint8_t hird, uint8_t bRemoteWake);
  92257. +
  92258. +/* URB interface */
  92259. +
  92260. +/**
  92261. + * Allocates memory for dwc_otg_hcd_urb structure.
  92262. + * Allocated memory should be freed by call of DWC_FREE.
  92263. + *
  92264. + * @param hcd The HCD
  92265. + * @param iso_desc_count Count of ISOC descriptors
  92266. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  92267. + */
  92268. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  92269. + int iso_desc_count,
  92270. + int atomic_alloc);
  92271. +
  92272. +/**
  92273. + * Set pipe information in URB.
  92274. + *
  92275. + * @param hcd_urb DWC_OTG URB
  92276. + * @param devaddr Device Address
  92277. + * @param ep_num Endpoint Number
  92278. + * @param ep_type Endpoint Type
  92279. + * @param ep_dir Endpoint Direction
  92280. + * @param mps Max Packet Size
  92281. + */
  92282. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  92283. + uint8_t devaddr, uint8_t ep_num,
  92284. + uint8_t ep_type, uint8_t ep_dir,
  92285. + uint16_t mps);
  92286. +
  92287. +/* Transfer flags */
  92288. +#define URB_GIVEBACK_ASAP 0x1
  92289. +#define URB_SEND_ZERO_PACKET 0x2
  92290. +
  92291. +/**
  92292. + * Sets dwc_otg_hcd_urb parameters.
  92293. + *
  92294. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  92295. + * @param urb_handle Unique handle for request, this will be passed back
  92296. + * to function driver in completion callback.
  92297. + * @param buf The buffer for the data
  92298. + * @param dma The DMA buffer for the data
  92299. + * @param buflen Transfer length
  92300. + * @param sp Buffer for setup data
  92301. + * @param sp_dma DMA address of setup data buffer
  92302. + * @param flags Transfer flags
  92303. + * @param interval Polling interval for interrupt or isochronous transfers.
  92304. + */
  92305. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  92306. + void *urb_handle, void *buf,
  92307. + dwc_dma_t dma, uint32_t buflen, void *sp,
  92308. + dwc_dma_t sp_dma, uint32_t flags,
  92309. + uint16_t interval);
  92310. +
  92311. +/** Gets status from dwc_otg_hcd_urb
  92312. + *
  92313. + * @param dwc_otg_urb DWC_OTG URB
  92314. + */
  92315. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  92316. +
  92317. +/** Gets actual length from dwc_otg_hcd_urb
  92318. + *
  92319. + * @param dwc_otg_urb DWC_OTG URB
  92320. + */
  92321. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  92322. + dwc_otg_urb);
  92323. +
  92324. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  92325. + *
  92326. + * @param dwc_otg_urb DWC_OTG URB
  92327. + */
  92328. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  92329. + dwc_otg_urb);
  92330. +
  92331. +/** Set ISOC descriptor offset and length
  92332. + *
  92333. + * @param dwc_otg_urb DWC_OTG URB
  92334. + * @param desc_num ISOC descriptor number
  92335. + * @param offset Offset from beginig of buffer.
  92336. + * @param length Transaction length
  92337. + */
  92338. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  92339. + int desc_num, uint32_t offset,
  92340. + uint32_t length);
  92341. +
  92342. +/** Get status of ISOC descriptor, specified by desc_num
  92343. + *
  92344. + * @param dwc_otg_urb DWC_OTG URB
  92345. + * @param desc_num ISOC descriptor number
  92346. + */
  92347. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  92348. + dwc_otg_urb, int desc_num);
  92349. +
  92350. +/** Get actual length of ISOC descriptor, specified by desc_num
  92351. + *
  92352. + * @param dwc_otg_urb DWC_OTG URB
  92353. + * @param desc_num ISOC descriptor number
  92354. + */
  92355. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  92356. + dwc_otg_urb,
  92357. + int desc_num);
  92358. +
  92359. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  92360. + *
  92361. + * @param dwc_otg_hcd The HCD
  92362. + * @param dwc_otg_urb DWC_OTG URB
  92363. + * @param ep_handle Out parameter for returning endpoint handle
  92364. + * @param atomic_alloc Flag to do atomic allocation if needed
  92365. + *
  92366. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  92367. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  92368. + * Returns 0 on success.
  92369. + */
  92370. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  92371. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  92372. + void **ep_handle, int atomic_alloc);
  92373. +
  92374. +/** De-queue the specified URB
  92375. + *
  92376. + * @param dwc_otg_hcd The HCD
  92377. + * @param dwc_otg_urb DWC_OTG URB
  92378. + */
  92379. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  92380. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  92381. +
  92382. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  92383. + * Any URBs for the endpoint must already be dequeued.
  92384. + *
  92385. + * @param hcd The HCD
  92386. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  92387. + * @param retry Number of retries if there are queued transfers.
  92388. + *
  92389. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  92390. + * Returns 0 on success
  92391. + */
  92392. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  92393. + int retry);
  92394. +
  92395. +/* Resets the data toggle in qh structure. This function can be called from
  92396. + * usb_clear_halt routine.
  92397. + *
  92398. + * @param hcd The HCD
  92399. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  92400. + *
  92401. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  92402. + * Returns 0 on success
  92403. + */
  92404. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  92405. +
  92406. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  92407. + *
  92408. + * @param hcd The HCD
  92409. + * @param port Port number
  92410. + */
  92411. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  92412. +
  92413. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  92414. + * Only for ISOC and INTERRUPT endpoints.
  92415. + *
  92416. + * @param hcd The HCD
  92417. + * @param ep_handle Endpoint handle
  92418. + */
  92419. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  92420. + void *ep_handle);
  92421. +
  92422. +/** Call this function to check if bandwidth was freed for specified endpoint.
  92423. + *
  92424. + * @param hcd The HCD
  92425. + * @param ep_handle Endpoint handle
  92426. + */
  92427. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  92428. +
  92429. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  92430. + * Only for ISOC and INTERRUPT endpoints.
  92431. + *
  92432. + * @param hcd The HCD
  92433. + * @param ep_handle Endpoint handle
  92434. + */
  92435. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  92436. + void *ep_handle);
  92437. +
  92438. +/** @} */
  92439. +
  92440. +#endif /* __DWC_HCD_IF_H__ */
  92441. +#endif /* DWC_DEVICE_ONLY */
  92442. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  92443. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  92444. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2015-03-10 17:26:51.302216687 +0100
  92445. @@ -0,0 +1,2688 @@
  92446. +/* ==========================================================================
  92447. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  92448. + * $Revision: #89 $
  92449. + * $Date: 2011/10/20 $
  92450. + * $Change: 1869487 $
  92451. + *
  92452. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  92453. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  92454. + * otherwise expressly agreed to in writing between Synopsys and you.
  92455. + *
  92456. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  92457. + * any End User Software License Agreement or Agreement for Licensed Product
  92458. + * with Synopsys or any supplement thereto. You are permitted to use and
  92459. + * redistribute this Software in source and binary forms, with or without
  92460. + * modification, provided that redistributions of source code must retain this
  92461. + * notice. You may not view, use, disclose, copy or distribute this file or
  92462. + * any information contained herein except pursuant to this license grant from
  92463. + * Synopsys. If you do not agree with this notice, including the disclaimer
  92464. + * below, then you are not authorized to use the Software.
  92465. + *
  92466. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  92467. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  92468. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  92469. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  92470. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  92471. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  92472. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  92473. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  92474. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  92475. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  92476. + * DAMAGE.
  92477. + * ========================================================================== */
  92478. +#ifndef DWC_DEVICE_ONLY
  92479. +
  92480. +#include "dwc_otg_hcd.h"
  92481. +#include "dwc_otg_regs.h"
  92482. +
  92483. +#include <linux/jiffies.h>
  92484. +#include <mach/hardware.h>
  92485. +#include <asm/fiq.h>
  92486. +
  92487. +
  92488. +extern bool microframe_schedule;
  92489. +
  92490. +/** @file
  92491. + * This file contains the implementation of the HCD Interrupt handlers.
  92492. + */
  92493. +
  92494. +int fiq_done, int_done;
  92495. +
  92496. +#ifdef FIQ_DEBUG
  92497. +char buffer[1000*16];
  92498. +int wptr;
  92499. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  92500. +{
  92501. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  92502. + va_list args;
  92503. + char text[17];
  92504. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  92505. +
  92506. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  92507. + {
  92508. + local_fiq_disable();
  92509. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  92510. + va_start(args, fmt);
  92511. + vsnprintf(text+8, 9, fmt, args);
  92512. + va_end(args);
  92513. +
  92514. + memcpy(buffer + wptr, text, 16);
  92515. + wptr = (wptr + 16) % sizeof(buffer);
  92516. + local_fiq_enable();
  92517. + }
  92518. +}
  92519. +#endif
  92520. +
  92521. +/** This function handles interrupts for the HCD. */
  92522. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92523. +{
  92524. + int retval = 0;
  92525. + static int last_time;
  92526. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  92527. + gintsts_data_t gintsts;
  92528. + gintmsk_data_t gintmsk;
  92529. + hfnum_data_t hfnum;
  92530. + haintmsk_data_t haintmsk;
  92531. +
  92532. +#ifdef DEBUG
  92533. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  92534. +
  92535. +#endif
  92536. +
  92537. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  92538. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  92539. +
  92540. + /* Exit from ISR if core is hibernated */
  92541. + if (core_if->hibernation_suspend == 1) {
  92542. + goto exit_handler_routine;
  92543. + }
  92544. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  92545. + /* Check if HOST Mode */
  92546. + if (dwc_otg_is_host_mode(core_if)) {
  92547. + if (fiq_enable) {
  92548. + local_fiq_disable();
  92549. + /* Pull in from the FIQ's disabled mask */
  92550. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  92551. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  92552. + }
  92553. +
  92554. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  92555. + gintsts.b.hcintr = 1;
  92556. + }
  92557. +
  92558. + /* Danger will robinson: fake a SOF if necessary */
  92559. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  92560. + gintsts.b.sofintr = 1;
  92561. + }
  92562. + gintsts.d32 &= gintmsk.d32;
  92563. +
  92564. + if (fiq_enable)
  92565. + local_fiq_enable();
  92566. +
  92567. + if (!gintsts.d32) {
  92568. + goto exit_handler_routine;
  92569. + }
  92570. +
  92571. +#ifdef DEBUG
  92572. + // We should be OK doing this because the common interrupts should already have been serviced
  92573. + /* Don't print debug message in the interrupt handler on SOF */
  92574. +#ifndef DEBUG_SOF
  92575. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92576. +#endif
  92577. + DWC_DEBUGPL(DBG_HCDI, "\n");
  92578. +#endif
  92579. +
  92580. +#ifdef DEBUG
  92581. +#ifndef DEBUG_SOF
  92582. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92583. +#endif
  92584. + DWC_DEBUGPL(DBG_HCDI,
  92585. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  92586. + gintsts.d32, core_if);
  92587. +#endif
  92588. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  92589. + if (gintsts.b.sofintr) {
  92590. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  92591. + }
  92592. +
  92593. + if (gintsts.b.rxstsqlvl) {
  92594. + retval |=
  92595. + dwc_otg_hcd_handle_rx_status_q_level_intr
  92596. + (dwc_otg_hcd);
  92597. + }
  92598. + if (gintsts.b.nptxfempty) {
  92599. + retval |=
  92600. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  92601. + (dwc_otg_hcd);
  92602. + }
  92603. + if (gintsts.b.i2cintr) {
  92604. + /** @todo Implement i2cintr handler. */
  92605. + }
  92606. + if (gintsts.b.portintr) {
  92607. +
  92608. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  92609. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  92610. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  92611. + }
  92612. + if (gintsts.b.hcintr) {
  92613. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  92614. + }
  92615. + if (gintsts.b.ptxfempty) {
  92616. + retval |=
  92617. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  92618. + (dwc_otg_hcd);
  92619. + }
  92620. +#ifdef DEBUG
  92621. +#ifndef DEBUG_SOF
  92622. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92623. +#endif
  92624. + {
  92625. + DWC_DEBUGPL(DBG_HCDI,
  92626. + "DWC OTG HCD Finished Servicing Interrupts\n");
  92627. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  92628. + DWC_READ_REG32(&global_regs->gintsts));
  92629. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  92630. + DWC_READ_REG32(&global_regs->gintmsk));
  92631. + }
  92632. +#endif
  92633. +
  92634. +#ifdef DEBUG
  92635. +#ifndef DEBUG_SOF
  92636. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  92637. +#endif
  92638. + DWC_DEBUGPL(DBG_HCDI, "\n");
  92639. +#endif
  92640. +
  92641. + }
  92642. +
  92643. +exit_handler_routine:
  92644. + if (fiq_enable) {
  92645. + gintmsk_data_t gintmsk_new;
  92646. + haintmsk_data_t haintmsk_new;
  92647. + local_fiq_disable();
  92648. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  92649. + if(fiq_fsm_enable)
  92650. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  92651. + else
  92652. + haintmsk_new.d32 = 0x0000FFFF;
  92653. +
  92654. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  92655. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  92656. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  92657. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  92658. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  92659. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  92660. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  92661. + ;
  92662. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  92663. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  92664. + }
  92665. + int_done++;
  92666. + }
  92667. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  92668. + /* Re-enable interrupts that the FIQ masked (first time round) */
  92669. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  92670. + local_fiq_enable();
  92671. +
  92672. + if ((jiffies / HZ) > last_time) {
  92673. + //dwc_otg_qh_t *qh;
  92674. + //dwc_list_link_t *cur;
  92675. + /* Once a second output the fiq and irq numbers, useful for debug */
  92676. + last_time = jiffies / HZ;
  92677. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  92678. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  92679. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  92680. + //printk(KERN_WARNING "Periodic queues:\n");
  92681. + }
  92682. + }
  92683. +
  92684. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  92685. + return retval;
  92686. +}
  92687. +
  92688. +#ifdef DWC_TRACK_MISSED_SOFS
  92689. +
  92690. +#warning Compiling code to track missed SOFs
  92691. +#define FRAME_NUM_ARRAY_SIZE 1000
  92692. +/**
  92693. + * This function is for debug only.
  92694. + */
  92695. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  92696. +{
  92697. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  92698. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  92699. + static int frame_num_idx = 0;
  92700. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  92701. + static int dumped_frame_num_array = 0;
  92702. +
  92703. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  92704. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  92705. + curr_frame_number) {
  92706. + frame_num_array[frame_num_idx] = curr_frame_number;
  92707. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  92708. + }
  92709. + } else if (!dumped_frame_num_array) {
  92710. + int i;
  92711. + DWC_PRINTF("Frame Last Frame\n");
  92712. + DWC_PRINTF("----- ----------\n");
  92713. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  92714. + DWC_PRINTF("0x%04x 0x%04x\n",
  92715. + frame_num_array[i], last_frame_num_array[i]);
  92716. + }
  92717. + dumped_frame_num_array = 1;
  92718. + }
  92719. + last_frame_num = curr_frame_number;
  92720. +}
  92721. +#endif
  92722. +
  92723. +/**
  92724. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  92725. + * transactions may be queued to the DWC_otg controller for the current
  92726. + * (micro)frame. Periodic transactions may be queued to the controller for the
  92727. + * next (micro)frame.
  92728. + */
  92729. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  92730. +{
  92731. + hfnum_data_t hfnum;
  92732. + gintsts_data_t gintsts = { .d32 = 0 };
  92733. + dwc_list_link_t *qh_entry;
  92734. + dwc_otg_qh_t *qh;
  92735. + dwc_otg_transaction_type_e tr_type;
  92736. + int did_something = 0;
  92737. + int32_t next_sched_frame = -1;
  92738. +
  92739. + hfnum.d32 =
  92740. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  92741. +
  92742. +#ifdef DEBUG_SOF
  92743. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  92744. +#endif
  92745. + hcd->frame_number = hfnum.b.frnum;
  92746. +
  92747. +#ifdef DEBUG
  92748. + hcd->frrem_accum += hfnum.b.frrem;
  92749. + hcd->frrem_samples++;
  92750. +#endif
  92751. +
  92752. +#ifdef DWC_TRACK_MISSED_SOFS
  92753. + track_missed_sofs(hcd->frame_number);
  92754. +#endif
  92755. + /* Determine whether any periodic QHs should be executed. */
  92756. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  92757. + while (qh_entry != &hcd->periodic_sched_inactive) {
  92758. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  92759. + qh_entry = qh_entry->next;
  92760. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  92761. +
  92762. + /*
  92763. + * Move QH to the ready list to be executed next
  92764. + * (micro)frame.
  92765. + */
  92766. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  92767. + &qh->qh_list_entry);
  92768. +
  92769. + did_something = 1;
  92770. + }
  92771. + else
  92772. + {
  92773. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  92774. + {
  92775. + next_sched_frame = qh->sched_frame;
  92776. + }
  92777. + }
  92778. + }
  92779. + if (fiq_enable)
  92780. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  92781. +
  92782. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  92783. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  92784. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  92785. + did_something = 1;
  92786. + }
  92787. +
  92788. + /* Clear interrupt - but do not trample on the FIQ sof */
  92789. + if (!fiq_fsm_enable) {
  92790. + gintsts.b.sofintr = 1;
  92791. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  92792. + }
  92793. + return 1;
  92794. +}
  92795. +
  92796. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  92797. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  92798. + * memory if the DWC_otg controller is operating in Slave mode. */
  92799. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92800. +{
  92801. + host_grxsts_data_t grxsts;
  92802. + dwc_hc_t *hc = NULL;
  92803. +
  92804. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  92805. +
  92806. + grxsts.d32 =
  92807. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  92808. +
  92809. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  92810. + if (!hc) {
  92811. + DWC_ERROR("Unable to get corresponding channel\n");
  92812. + return 0;
  92813. + }
  92814. +
  92815. + /* Packet Status */
  92816. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  92817. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  92818. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  92819. + hc->data_pid_start);
  92820. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  92821. +
  92822. + switch (grxsts.b.pktsts) {
  92823. + case DWC_GRXSTS_PKTSTS_IN:
  92824. + /* Read the data into the host buffer. */
  92825. + if (grxsts.b.bcnt > 0) {
  92826. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  92827. + hc->xfer_buff, grxsts.b.bcnt);
  92828. +
  92829. + /* Update the HC fields for the next packet received. */
  92830. + hc->xfer_count += grxsts.b.bcnt;
  92831. + hc->xfer_buff += grxsts.b.bcnt;
  92832. + }
  92833. +
  92834. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  92835. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  92836. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  92837. + /* Handled in interrupt, just ignore data */
  92838. + break;
  92839. + default:
  92840. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  92841. + grxsts.b.pktsts);
  92842. + break;
  92843. + }
  92844. +
  92845. + return 1;
  92846. +}
  92847. +
  92848. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  92849. + * data packets may be written to the FIFO for OUT transfers. More requests
  92850. + * may be written to the non-periodic request queue for IN transfers. This
  92851. + * interrupt is enabled only in Slave mode. */
  92852. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92853. +{
  92854. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  92855. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  92856. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  92857. + return 1;
  92858. +}
  92859. +
  92860. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  92861. + * packets may be written to the FIFO for OUT transfers. More requests may be
  92862. + * written to the periodic request queue for IN transfers. This interrupt is
  92863. + * enabled only in Slave mode. */
  92864. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92865. +{
  92866. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  92867. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  92868. + DWC_OTG_TRANSACTION_PERIODIC);
  92869. + return 1;
  92870. +}
  92871. +
  92872. +/** There are multiple conditions that can cause a port interrupt. This function
  92873. + * determines which interrupt conditions have occurred and handles them
  92874. + * appropriately. */
  92875. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  92876. +{
  92877. + int retval = 0;
  92878. + hprt0_data_t hprt0;
  92879. + hprt0_data_t hprt0_modify;
  92880. +
  92881. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92882. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92883. +
  92884. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  92885. + * GINTSTS */
  92886. +
  92887. + hprt0_modify.b.prtena = 0;
  92888. + hprt0_modify.b.prtconndet = 0;
  92889. + hprt0_modify.b.prtenchng = 0;
  92890. + hprt0_modify.b.prtovrcurrchng = 0;
  92891. +
  92892. + /* Port Connect Detected
  92893. + * Set flag and clear if detected */
  92894. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  92895. + // Dont modify port status if we are in hibernation state
  92896. + hprt0_modify.b.prtconndet = 1;
  92897. + hprt0_modify.b.prtenchng = 1;
  92898. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  92899. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  92900. + return retval;
  92901. + }
  92902. +
  92903. + if (hprt0.b.prtconndet) {
  92904. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  92905. + if (dwc_otg_hcd->core_if->adp_enable &&
  92906. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  92907. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  92908. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  92909. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  92910. + /* TODO - check if this is required, as
  92911. + * host initialization was already performed
  92912. + * after initial ADP probing
  92913. + */
  92914. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  92915. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  92916. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  92917. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  92918. + } else {
  92919. +
  92920. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  92921. + "Port Connect Detected--\n", hprt0.d32);
  92922. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  92923. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  92924. + hprt0_modify.b.prtconndet = 1;
  92925. +
  92926. + /* B-Device has connected, Delete the connection timer. */
  92927. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  92928. + }
  92929. + /* The Hub driver asserts a reset when it sees port connect
  92930. + * status change flag */
  92931. + retval |= 1;
  92932. + }
  92933. +
  92934. + /* Port Enable Changed
  92935. + * Clear if detected - Set internal flag if disabled */
  92936. + if (hprt0.b.prtenchng) {
  92937. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  92938. + "Port Enable Changed--\n", hprt0.d32);
  92939. + hprt0_modify.b.prtenchng = 1;
  92940. + if (hprt0.b.prtena == 1) {
  92941. + hfir_data_t hfir;
  92942. + int do_reset = 0;
  92943. + dwc_otg_core_params_t *params =
  92944. + dwc_otg_hcd->core_if->core_params;
  92945. + dwc_otg_core_global_regs_t *global_regs =
  92946. + dwc_otg_hcd->core_if->core_global_regs;
  92947. + dwc_otg_host_if_t *host_if =
  92948. + dwc_otg_hcd->core_if->host_if;
  92949. +
  92950. + /* Every time when port enables calculate
  92951. + * HFIR.FrInterval
  92952. + */
  92953. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  92954. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  92955. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  92956. +
  92957. + /* Check if we need to adjust the PHY clock speed for
  92958. + * low power and adjust it */
  92959. + if (params->host_support_fs_ls_low_power) {
  92960. + gusbcfg_data_t usbcfg;
  92961. +
  92962. + usbcfg.d32 =
  92963. + DWC_READ_REG32(&global_regs->gusbcfg);
  92964. +
  92965. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  92966. + || hprt0.b.prtspd ==
  92967. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  92968. + /*
  92969. + * Low power
  92970. + */
  92971. + hcfg_data_t hcfg;
  92972. + if (usbcfg.b.phylpwrclksel == 0) {
  92973. + /* Set PHY low power clock select for FS/LS devices */
  92974. + usbcfg.b.phylpwrclksel = 1;
  92975. + DWC_WRITE_REG32
  92976. + (&global_regs->gusbcfg,
  92977. + usbcfg.d32);
  92978. + do_reset = 1;
  92979. + }
  92980. +
  92981. + hcfg.d32 =
  92982. + DWC_READ_REG32
  92983. + (&host_if->host_global_regs->hcfg);
  92984. +
  92985. + if (hprt0.b.prtspd ==
  92986. + DWC_HPRT0_PRTSPD_LOW_SPEED
  92987. + && params->host_ls_low_power_phy_clk
  92988. + ==
  92989. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  92990. + {
  92991. + /* 6 MHZ */
  92992. + DWC_DEBUGPL(DBG_CIL,
  92993. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  92994. + if (hcfg.b.fslspclksel !=
  92995. + DWC_HCFG_6_MHZ) {
  92996. + hcfg.b.fslspclksel =
  92997. + DWC_HCFG_6_MHZ;
  92998. + DWC_WRITE_REG32
  92999. + (&host_if->host_global_regs->hcfg,
  93000. + hcfg.d32);
  93001. + do_reset = 1;
  93002. + }
  93003. + } else {
  93004. + /* 48 MHZ */
  93005. + DWC_DEBUGPL(DBG_CIL,
  93006. + "FS_PHY programming HCFG to 48 MHz ()\n");
  93007. + if (hcfg.b.fslspclksel !=
  93008. + DWC_HCFG_48_MHZ) {
  93009. + hcfg.b.fslspclksel =
  93010. + DWC_HCFG_48_MHZ;
  93011. + DWC_WRITE_REG32
  93012. + (&host_if->host_global_regs->hcfg,
  93013. + hcfg.d32);
  93014. + do_reset = 1;
  93015. + }
  93016. + }
  93017. + } else {
  93018. + /*
  93019. + * Not low power
  93020. + */
  93021. + if (usbcfg.b.phylpwrclksel == 1) {
  93022. + usbcfg.b.phylpwrclksel = 0;
  93023. + DWC_WRITE_REG32
  93024. + (&global_regs->gusbcfg,
  93025. + usbcfg.d32);
  93026. + do_reset = 1;
  93027. + }
  93028. + }
  93029. +
  93030. + if (do_reset) {
  93031. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  93032. + }
  93033. + }
  93034. +
  93035. + if (!do_reset) {
  93036. + /* Port has been enabled set the reset change flag */
  93037. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  93038. + }
  93039. + } else {
  93040. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  93041. + }
  93042. + retval |= 1;
  93043. + }
  93044. +
  93045. + /** Overcurrent Change Interrupt */
  93046. + if (hprt0.b.prtovrcurrchng) {
  93047. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  93048. + "Port Overcurrent Changed--\n", hprt0.d32);
  93049. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  93050. + hprt0_modify.b.prtovrcurrchng = 1;
  93051. + retval |= 1;
  93052. + }
  93053. +
  93054. + /* Clear Port Interrupts */
  93055. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  93056. +
  93057. + return retval;
  93058. +}
  93059. +
  93060. +/** This interrupt indicates that one or more host channels has a pending
  93061. + * interrupt. There are multiple conditions that can cause each host channel
  93062. + * interrupt. This function determines which conditions have occurred for each
  93063. + * host channel interrupt and handles them appropriately. */
  93064. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  93065. +{
  93066. + int i;
  93067. + int retval = 0;
  93068. + haint_data_t haint = { .d32 = 0 } ;
  93069. +
  93070. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  93071. + * GINTSTS */
  93072. +
  93073. + if (!fiq_fsm_enable)
  93074. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  93075. +
  93076. + // Overwrite with saved interrupts from fiq handler
  93077. + if(fiq_fsm_enable)
  93078. + {
  93079. + /* check the mask? */
  93080. + local_fiq_disable();
  93081. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  93082. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  93083. + local_fiq_enable();
  93084. + }
  93085. +
  93086. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  93087. + if (haint.b2.chint & (1 << i)) {
  93088. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  93089. + }
  93090. + }
  93091. +
  93092. + return retval;
  93093. +}
  93094. +
  93095. +/**
  93096. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  93097. + * holds the reason for the halt.
  93098. + *
  93099. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  93100. + * *short_read is set to 1 upon return if less than the requested
  93101. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  93102. + * return. short_read may also be NULL on entry, in which case it remains
  93103. + * unchanged.
  93104. + */
  93105. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  93106. + dwc_otg_hc_regs_t * hc_regs,
  93107. + dwc_otg_qtd_t * qtd,
  93108. + dwc_otg_halt_status_e halt_status,
  93109. + int *short_read)
  93110. +{
  93111. + hctsiz_data_t hctsiz;
  93112. + uint32_t length;
  93113. +
  93114. + if (short_read != NULL) {
  93115. + *short_read = 0;
  93116. + }
  93117. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93118. +
  93119. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  93120. + if (hc->ep_is_in) {
  93121. + length = hc->xfer_len - hctsiz.b.xfersize;
  93122. + if (short_read != NULL) {
  93123. + *short_read = (hctsiz.b.xfersize != 0);
  93124. + }
  93125. + } else if (hc->qh->do_split) {
  93126. + //length = split_out_xfersize[hc->hc_num];
  93127. + length = qtd->ssplit_out_xfer_count;
  93128. + } else {
  93129. + length = hc->xfer_len;
  93130. + }
  93131. + } else {
  93132. + /*
  93133. + * Must use the hctsiz.pktcnt field to determine how much data
  93134. + * has been transferred. This field reflects the number of
  93135. + * packets that have been transferred via the USB. This is
  93136. + * always an integral number of packets if the transfer was
  93137. + * halted before its normal completion. (Can't use the
  93138. + * hctsiz.xfersize field because that reflects the number of
  93139. + * bytes transferred via the AHB, not the USB).
  93140. + */
  93141. + length =
  93142. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  93143. + }
  93144. +
  93145. + return length;
  93146. +}
  93147. +
  93148. +/**
  93149. + * Updates the state of the URB after a Transfer Complete interrupt on the
  93150. + * host channel. Updates the actual_length field of the URB based on the
  93151. + * number of bytes transferred via the host channel. Sets the URB status
  93152. + * if the data transfer is finished.
  93153. + *
  93154. + * @return 1 if the data transfer specified by the URB is completely finished,
  93155. + * 0 otherwise.
  93156. + */
  93157. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  93158. + dwc_otg_hc_regs_t * hc_regs,
  93159. + dwc_otg_hcd_urb_t * urb,
  93160. + dwc_otg_qtd_t * qtd)
  93161. +{
  93162. + int xfer_done = 0;
  93163. + int short_read = 0;
  93164. +
  93165. + int xfer_length;
  93166. +
  93167. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  93168. + DWC_OTG_HC_XFER_COMPLETE,
  93169. + &short_read);
  93170. +
  93171. + /* non DWORD-aligned buffer case handling. */
  93172. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  93173. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  93174. + xfer_length);
  93175. + }
  93176. +
  93177. + urb->actual_length += xfer_length;
  93178. +
  93179. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  93180. + (urb->flags & URB_SEND_ZERO_PACKET)
  93181. + && (urb->actual_length == urb->length)
  93182. + && !(urb->length % hc->max_packet)) {
  93183. + xfer_done = 0;
  93184. + } else if (short_read || urb->actual_length >= urb->length) {
  93185. + xfer_done = 1;
  93186. + urb->status = 0;
  93187. + }
  93188. +
  93189. +#ifdef DEBUG
  93190. + {
  93191. + hctsiz_data_t hctsiz;
  93192. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93193. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  93194. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  93195. + hc->hc_num);
  93196. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  93197. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  93198. + hctsiz.b.xfersize);
  93199. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  93200. + urb->length);
  93201. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  93202. + urb->actual_length);
  93203. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  93204. + short_read, xfer_done);
  93205. + }
  93206. +#endif
  93207. +
  93208. + return xfer_done;
  93209. +}
  93210. +
  93211. +/*
  93212. + * Save the starting data toggle for the next transfer. The data toggle is
  93213. + * saved in the QH for non-control transfers and it's saved in the QTD for
  93214. + * control transfers.
  93215. + */
  93216. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  93217. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  93218. +{
  93219. + hctsiz_data_t hctsiz;
  93220. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93221. +
  93222. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  93223. + dwc_otg_qh_t *qh = hc->qh;
  93224. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  93225. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  93226. + } else {
  93227. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  93228. + }
  93229. + } else {
  93230. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  93231. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  93232. + } else {
  93233. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  93234. + }
  93235. + }
  93236. +}
  93237. +
  93238. +/**
  93239. + * Updates the state of an Isochronous URB when the transfer is stopped for
  93240. + * any reason. The fields of the current entry in the frame descriptor array
  93241. + * are set based on the transfer state and the input _halt_status. Completes
  93242. + * the Isochronous URB if all the URB frames have been completed.
  93243. + *
  93244. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  93245. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  93246. + */
  93247. +static dwc_otg_halt_status_e
  93248. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  93249. + dwc_hc_t * hc,
  93250. + dwc_otg_hc_regs_t * hc_regs,
  93251. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  93252. +{
  93253. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93254. + dwc_otg_halt_status_e ret_val = halt_status;
  93255. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  93256. +
  93257. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  93258. + switch (halt_status) {
  93259. + case DWC_OTG_HC_XFER_COMPLETE:
  93260. + frame_desc->status = 0;
  93261. + frame_desc->actual_length =
  93262. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  93263. +
  93264. + /* non DWORD-aligned buffer case handling. */
  93265. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  93266. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  93267. + hc->qh->dw_align_buf, frame_desc->actual_length);
  93268. + }
  93269. +
  93270. + break;
  93271. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  93272. + urb->error_count++;
  93273. + if (hc->ep_is_in) {
  93274. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  93275. + } else {
  93276. + frame_desc->status = -DWC_E_COMMUNICATION;
  93277. + }
  93278. + frame_desc->actual_length = 0;
  93279. + break;
  93280. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  93281. + urb->error_count++;
  93282. + frame_desc->status = -DWC_E_OVERFLOW;
  93283. + /* Don't need to update actual_length in this case. */
  93284. + break;
  93285. + case DWC_OTG_HC_XFER_XACT_ERR:
  93286. + urb->error_count++;
  93287. + frame_desc->status = -DWC_E_PROTOCOL;
  93288. + frame_desc->actual_length =
  93289. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  93290. +
  93291. + /* non DWORD-aligned buffer case handling. */
  93292. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  93293. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  93294. + hc->qh->dw_align_buf, frame_desc->actual_length);
  93295. + }
  93296. + /* Skip whole frame */
  93297. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  93298. + hc->ep_is_in && hcd->core_if->dma_enable) {
  93299. + qtd->complete_split = 0;
  93300. + qtd->isoc_split_offset = 0;
  93301. + }
  93302. +
  93303. + break;
  93304. + default:
  93305. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  93306. + break;
  93307. + }
  93308. + if (++qtd->isoc_frame_index == urb->packet_count) {
  93309. + /*
  93310. + * urb->status is not used for isoc transfers.
  93311. + * The individual frame_desc statuses are used instead.
  93312. + */
  93313. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  93314. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  93315. + } else {
  93316. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  93317. + }
  93318. + return ret_val;
  93319. +}
  93320. +
  93321. +/**
  93322. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  93323. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  93324. + * still linked to the QH, the QH is added to the end of the inactive
  93325. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  93326. + * schedule if no more QTDs are linked to the QH.
  93327. + */
  93328. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  93329. +{
  93330. + int continue_split = 0;
  93331. + dwc_otg_qtd_t *qtd;
  93332. +
  93333. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  93334. +
  93335. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  93336. +
  93337. + if (qtd->complete_split) {
  93338. + continue_split = 1;
  93339. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  93340. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  93341. + continue_split = 1;
  93342. + }
  93343. +
  93344. + if (free_qtd) {
  93345. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  93346. + continue_split = 0;
  93347. + }
  93348. +
  93349. + qh->channel = NULL;
  93350. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  93351. +}
  93352. +
  93353. +/**
  93354. + * Releases a host channel for use by other transfers. Attempts to select and
  93355. + * queue more transactions since at least one host channel is available.
  93356. + *
  93357. + * @param hcd The HCD state structure.
  93358. + * @param hc The host channel to release.
  93359. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  93360. + * if the transfer is complete or an error has occurred.
  93361. + * @param halt_status Reason the channel is being released. This status
  93362. + * determines the actions taken by this function.
  93363. + */
  93364. +static void release_channel(dwc_otg_hcd_t * hcd,
  93365. + dwc_hc_t * hc,
  93366. + dwc_otg_qtd_t * qtd,
  93367. + dwc_otg_halt_status_e halt_status)
  93368. +{
  93369. + dwc_otg_transaction_type_e tr_type;
  93370. + int free_qtd;
  93371. + dwc_irqflags_t flags;
  93372. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  93373. +
  93374. + int hog_port = 0;
  93375. +
  93376. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  93377. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  93378. +
  93379. + if(fiq_fsm_enable && hc->do_split) {
  93380. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  93381. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  93382. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  93383. + hog_port = 0;
  93384. + }
  93385. + }
  93386. + }
  93387. +
  93388. + switch (halt_status) {
  93389. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  93390. + free_qtd = 1;
  93391. + break;
  93392. + case DWC_OTG_HC_XFER_AHB_ERR:
  93393. + case DWC_OTG_HC_XFER_STALL:
  93394. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  93395. + free_qtd = 1;
  93396. + break;
  93397. + case DWC_OTG_HC_XFER_XACT_ERR:
  93398. + if (qtd->error_count >= 3) {
  93399. + DWC_DEBUGPL(DBG_HCDV,
  93400. + " Complete URB with transaction error\n");
  93401. + free_qtd = 1;
  93402. + qtd->urb->status = -DWC_E_PROTOCOL;
  93403. + hcd->fops->complete(hcd, qtd->urb->priv,
  93404. + qtd->urb, -DWC_E_PROTOCOL);
  93405. + } else {
  93406. + free_qtd = 0;
  93407. + }
  93408. + break;
  93409. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  93410. + /*
  93411. + * The QTD has already been removed and the QH has been
  93412. + * deactivated. Don't want to do anything except release the
  93413. + * host channel and try to queue more transfers.
  93414. + */
  93415. + goto cleanup;
  93416. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  93417. + free_qtd = 0;
  93418. + break;
  93419. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  93420. + DWC_DEBUGPL(DBG_HCDV,
  93421. + " Complete URB with I/O error\n");
  93422. + free_qtd = 1;
  93423. + qtd->urb->status = -DWC_E_IO;
  93424. + hcd->fops->complete(hcd, qtd->urb->priv,
  93425. + qtd->urb, -DWC_E_IO);
  93426. + break;
  93427. + default:
  93428. + free_qtd = 0;
  93429. + break;
  93430. + }
  93431. +
  93432. + deactivate_qh(hcd, hc->qh, free_qtd);
  93433. +
  93434. +cleanup:
  93435. + /*
  93436. + * Release the host channel for use by other transfers. The cleanup
  93437. + * function clears the channel interrupt enables and conditions, so
  93438. + * there's no need to clear the Channel Halted interrupt separately.
  93439. + */
  93440. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  93441. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  93442. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  93443. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  93444. +
  93445. + if (!microframe_schedule) {
  93446. + switch (hc->ep_type) {
  93447. + case DWC_OTG_EP_TYPE_CONTROL:
  93448. + case DWC_OTG_EP_TYPE_BULK:
  93449. + hcd->non_periodic_channels--;
  93450. + break;
  93451. +
  93452. + default:
  93453. + /*
  93454. + * Don't release reservations for periodic channels here.
  93455. + * That's done when a periodic transfer is descheduled (i.e.
  93456. + * when the QH is removed from the periodic schedule).
  93457. + */
  93458. + break;
  93459. + }
  93460. + } else {
  93461. +
  93462. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  93463. + hcd->available_host_channels++;
  93464. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  93465. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  93466. + }
  93467. +
  93468. + /* Try to queue more transfers now that there's a free channel. */
  93469. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  93470. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  93471. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  93472. + }
  93473. +}
  93474. +
  93475. +/**
  93476. + * Halts a host channel. If the channel cannot be halted immediately because
  93477. + * the request queue is full, this function ensures that the FIFO empty
  93478. + * interrupt for the appropriate queue is enabled so that the halt request can
  93479. + * be queued when there is space in the request queue.
  93480. + *
  93481. + * This function may also be called in DMA mode. In that case, the channel is
  93482. + * simply released since the core always halts the channel automatically in
  93483. + * DMA mode.
  93484. + */
  93485. +static void halt_channel(dwc_otg_hcd_t * hcd,
  93486. + dwc_hc_t * hc,
  93487. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  93488. +{
  93489. + if (hcd->core_if->dma_enable) {
  93490. + release_channel(hcd, hc, qtd, halt_status);
  93491. + return;
  93492. + }
  93493. +
  93494. + /* Slave mode processing... */
  93495. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  93496. +
  93497. + if (hc->halt_on_queue) {
  93498. + gintmsk_data_t gintmsk = {.d32 = 0 };
  93499. + dwc_otg_core_global_regs_t *global_regs;
  93500. + global_regs = hcd->core_if->core_global_regs;
  93501. +
  93502. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  93503. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  93504. + /*
  93505. + * Make sure the Non-periodic Tx FIFO empty interrupt
  93506. + * is enabled so that the non-periodic schedule will
  93507. + * be processed.
  93508. + */
  93509. + gintmsk.b.nptxfempty = 1;
  93510. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93511. + } else {
  93512. + /*
  93513. + * Move the QH from the periodic queued schedule to
  93514. + * the periodic assigned schedule. This allows the
  93515. + * halt to be queued when the periodic schedule is
  93516. + * processed.
  93517. + */
  93518. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  93519. + &hc->qh->qh_list_entry);
  93520. +
  93521. + /*
  93522. + * Make sure the Periodic Tx FIFO Empty interrupt is
  93523. + * enabled so that the periodic schedule will be
  93524. + * processed.
  93525. + */
  93526. + gintmsk.b.ptxfempty = 1;
  93527. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  93528. + }
  93529. + }
  93530. +}
  93531. +
  93532. +/**
  93533. + * Performs common cleanup for non-periodic transfers after a Transfer
  93534. + * Complete interrupt. This function should be called after any endpoint type
  93535. + * specific handling is finished to release the host channel.
  93536. + */
  93537. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  93538. + dwc_hc_t * hc,
  93539. + dwc_otg_hc_regs_t * hc_regs,
  93540. + dwc_otg_qtd_t * qtd,
  93541. + dwc_otg_halt_status_e halt_status)
  93542. +{
  93543. + hcint_data_t hcint;
  93544. +
  93545. + qtd->error_count = 0;
  93546. +
  93547. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  93548. + if (hcint.b.nyet) {
  93549. + /*
  93550. + * Got a NYET on the last transaction of the transfer. This
  93551. + * means that the endpoint should be in the PING state at the
  93552. + * beginning of the next transfer.
  93553. + */
  93554. + hc->qh->ping_state = 1;
  93555. + clear_hc_int(hc_regs, nyet);
  93556. + }
  93557. +
  93558. + /*
  93559. + * Always halt and release the host channel to make it available for
  93560. + * more transfers. There may still be more phases for a control
  93561. + * transfer or more data packets for a bulk transfer at this point,
  93562. + * but the host channel is still halted. A channel will be reassigned
  93563. + * to the transfer when the non-periodic schedule is processed after
  93564. + * the channel is released. This allows transactions to be queued
  93565. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  93566. + * Tx FIFO Empty interrupt if necessary.
  93567. + */
  93568. + if (hc->ep_is_in) {
  93569. + /*
  93570. + * IN transfers in Slave mode require an explicit disable to
  93571. + * halt the channel. (In DMA mode, this call simply releases
  93572. + * the channel.)
  93573. + */
  93574. + halt_channel(hcd, hc, qtd, halt_status);
  93575. + } else {
  93576. + /*
  93577. + * The channel is automatically disabled by the core for OUT
  93578. + * transfers in Slave mode.
  93579. + */
  93580. + release_channel(hcd, hc, qtd, halt_status);
  93581. + }
  93582. +}
  93583. +
  93584. +/**
  93585. + * Performs common cleanup for periodic transfers after a Transfer Complete
  93586. + * interrupt. This function should be called after any endpoint type specific
  93587. + * handling is finished to release the host channel.
  93588. + */
  93589. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  93590. + dwc_hc_t * hc,
  93591. + dwc_otg_hc_regs_t * hc_regs,
  93592. + dwc_otg_qtd_t * qtd,
  93593. + dwc_otg_halt_status_e halt_status)
  93594. +{
  93595. + hctsiz_data_t hctsiz;
  93596. + qtd->error_count = 0;
  93597. +
  93598. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93599. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  93600. + /* Core halts channel in these cases. */
  93601. + release_channel(hcd, hc, qtd, halt_status);
  93602. + } else {
  93603. + /* Flush any outstanding requests from the Tx queue. */
  93604. + halt_channel(hcd, hc, qtd, halt_status);
  93605. + }
  93606. +}
  93607. +
  93608. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  93609. + dwc_hc_t * hc,
  93610. + dwc_otg_hc_regs_t * hc_regs,
  93611. + dwc_otg_qtd_t * qtd)
  93612. +{
  93613. + uint32_t len;
  93614. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  93615. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  93616. +
  93617. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  93618. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  93619. +
  93620. + if (!len) {
  93621. + qtd->complete_split = 0;
  93622. + qtd->isoc_split_offset = 0;
  93623. + return 0;
  93624. + }
  93625. + frame_desc->actual_length += len;
  93626. +
  93627. + if (hc->align_buff && len)
  93628. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  93629. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  93630. + qtd->isoc_split_offset += len;
  93631. +
  93632. + if (frame_desc->length == frame_desc->actual_length) {
  93633. + frame_desc->status = 0;
  93634. + qtd->isoc_frame_index++;
  93635. + qtd->complete_split = 0;
  93636. + qtd->isoc_split_offset = 0;
  93637. + }
  93638. +
  93639. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  93640. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  93641. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  93642. + } else {
  93643. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  93644. + }
  93645. +
  93646. + return 1; /* Indicates that channel released */
  93647. +}
  93648. +
  93649. +/**
  93650. + * Handles a host channel Transfer Complete interrupt. This handler may be
  93651. + * called in either DMA mode or Slave mode.
  93652. + */
  93653. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  93654. + dwc_hc_t * hc,
  93655. + dwc_otg_hc_regs_t * hc_regs,
  93656. + dwc_otg_qtd_t * qtd)
  93657. +{
  93658. + int urb_xfer_done;
  93659. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93660. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93661. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  93662. +
  93663. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93664. + "Transfer Complete--\n", hc->hc_num);
  93665. +
  93666. + if (hcd->core_if->dma_desc_enable) {
  93667. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  93668. + if (pipe_type == UE_ISOCHRONOUS) {
  93669. + /* Do not disable the interrupt, just clear it */
  93670. + clear_hc_int(hc_regs, xfercomp);
  93671. + return 1;
  93672. + }
  93673. + goto handle_xfercomp_done;
  93674. + }
  93675. +
  93676. + /*
  93677. + * Handle xfer complete on CSPLIT.
  93678. + */
  93679. +
  93680. + if (hc->qh->do_split) {
  93681. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  93682. + && hcd->core_if->dma_enable) {
  93683. + if (qtd->complete_split
  93684. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  93685. + qtd))
  93686. + goto handle_xfercomp_done;
  93687. + } else {
  93688. + qtd->complete_split = 0;
  93689. + }
  93690. + }
  93691. +
  93692. + /* Update the QTD and URB states. */
  93693. + switch (pipe_type) {
  93694. + case UE_CONTROL:
  93695. + switch (qtd->control_phase) {
  93696. + case DWC_OTG_CONTROL_SETUP:
  93697. + if (urb->length > 0) {
  93698. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  93699. + } else {
  93700. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  93701. + }
  93702. + DWC_DEBUGPL(DBG_HCDV,
  93703. + " Control setup transaction done\n");
  93704. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93705. + break;
  93706. + case DWC_OTG_CONTROL_DATA:{
  93707. + urb_xfer_done =
  93708. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  93709. + qtd);
  93710. + if (urb_xfer_done) {
  93711. + qtd->control_phase =
  93712. + DWC_OTG_CONTROL_STATUS;
  93713. + DWC_DEBUGPL(DBG_HCDV,
  93714. + " Control data transfer done\n");
  93715. + } else {
  93716. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93717. + }
  93718. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93719. + break;
  93720. + }
  93721. + case DWC_OTG_CONTROL_STATUS:
  93722. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  93723. + if (urb->status == -DWC_E_IN_PROGRESS) {
  93724. + urb->status = 0;
  93725. + }
  93726. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93727. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93728. + break;
  93729. + }
  93730. +
  93731. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93732. + break;
  93733. + case UE_BULK:
  93734. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  93735. + urb_xfer_done =
  93736. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  93737. + if (urb_xfer_done) {
  93738. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93739. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93740. + } else {
  93741. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93742. + }
  93743. +
  93744. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93745. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93746. + break;
  93747. + case UE_INTERRUPT:
  93748. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  93749. + urb_xfer_done =
  93750. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  93751. +
  93752. + /*
  93753. + * Interrupt URB is done on the first transfer complete
  93754. + * interrupt.
  93755. + */
  93756. + if (urb_xfer_done) {
  93757. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  93758. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  93759. + } else {
  93760. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  93761. + }
  93762. +
  93763. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93764. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93765. + break;
  93766. + case UE_ISOCHRONOUS:
  93767. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  93768. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  93769. + halt_status =
  93770. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  93771. + DWC_OTG_HC_XFER_COMPLETE);
  93772. + }
  93773. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  93774. + break;
  93775. + }
  93776. +
  93777. +handle_xfercomp_done:
  93778. + disable_hc_int(hc_regs, xfercompl);
  93779. +
  93780. + return 1;
  93781. +}
  93782. +
  93783. +/**
  93784. + * Handles a host channel STALL interrupt. This handler may be called in
  93785. + * either DMA mode or Slave mode.
  93786. + */
  93787. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  93788. + dwc_hc_t * hc,
  93789. + dwc_otg_hc_regs_t * hc_regs,
  93790. + dwc_otg_qtd_t * qtd)
  93791. +{
  93792. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  93793. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  93794. +
  93795. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  93796. + "STALL Received--\n", hc->hc_num);
  93797. +
  93798. + if (hcd->core_if->dma_desc_enable) {
  93799. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  93800. + goto handle_stall_done;
  93801. + }
  93802. +
  93803. + if (pipe_type == UE_CONTROL) {
  93804. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  93805. + }
  93806. +
  93807. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  93808. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  93809. + /*
  93810. + * USB protocol requires resetting the data toggle for bulk
  93811. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  93812. + * setup command is issued to the endpoint. Anticipate the
  93813. + * CLEAR_FEATURE command since a STALL has occurred and reset
  93814. + * the data toggle now.
  93815. + */
  93816. + hc->qh->data_toggle = 0;
  93817. + }
  93818. +
  93819. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  93820. +
  93821. +handle_stall_done:
  93822. + disable_hc_int(hc_regs, stall);
  93823. +
  93824. + return 1;
  93825. +}
  93826. +
  93827. +/*
  93828. + * Updates the state of the URB when a transfer has been stopped due to an
  93829. + * abnormal condition before the transfer completes. Modifies the
  93830. + * actual_length field of the URB to reflect the number of bytes that have
  93831. + * actually been transferred via the host channel.
  93832. + */
  93833. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  93834. + dwc_otg_hc_regs_t * hc_regs,
  93835. + dwc_otg_hcd_urb_t * urb,
  93836. + dwc_otg_qtd_t * qtd,
  93837. + dwc_otg_halt_status_e halt_status)
  93838. +{
  93839. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  93840. + halt_status, NULL);
  93841. + /* non DWORD-aligned buffer case handling. */
  93842. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  93843. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  93844. + bytes_transferred);
  93845. + }
  93846. +
  93847. + urb->actual_length += bytes_transferred;
  93848. +
  93849. +#ifdef DEBUG
  93850. + {
  93851. + hctsiz_data_t hctsiz;
  93852. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  93853. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  93854. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  93855. + hc->hc_num);
  93856. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  93857. + hc->start_pkt_count);
  93858. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  93859. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  93860. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  93861. + bytes_transferred);
  93862. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  93863. + urb->actual_length);
  93864. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  93865. + urb->length);
  93866. + }
  93867. +#endif
  93868. +}
  93869. +
  93870. +/**
  93871. + * Handles a host channel NAK interrupt. This handler may be called in either
  93872. + * DMA mode or Slave mode.
  93873. + */
  93874. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  93875. + dwc_hc_t * hc,
  93876. + dwc_otg_hc_regs_t * hc_regs,
  93877. + dwc_otg_qtd_t * qtd)
  93878. +{
  93879. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93880. + "NAK Received--\n", hc->hc_num);
  93881. +
  93882. + /*
  93883. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  93884. + * the beginning of the next frame
  93885. + */
  93886. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93887. + case UE_BULK:
  93888. + case UE_CONTROL:
  93889. + if (nak_holdoff && qtd->qh->do_split)
  93890. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  93891. + }
  93892. +
  93893. + /*
  93894. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  93895. + * interrupt. Re-start the SSPLIT transfer.
  93896. + */
  93897. + if (hc->do_split) {
  93898. + if (hc->complete_split) {
  93899. + qtd->error_count = 0;
  93900. + }
  93901. + qtd->complete_split = 0;
  93902. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93903. + goto handle_nak_done;
  93904. + }
  93905. +
  93906. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  93907. + case UE_CONTROL:
  93908. + case UE_BULK:
  93909. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  93910. + /*
  93911. + * NAK interrupts are enabled on bulk/control IN
  93912. + * transfers in DMA mode for the sole purpose of
  93913. + * resetting the error count after a transaction error
  93914. + * occurs. The core will continue transferring data.
  93915. + * Disable other interrupts unmasked for the same
  93916. + * reason.
  93917. + */
  93918. + disable_hc_int(hc_regs, datatglerr);
  93919. + disable_hc_int(hc_regs, ack);
  93920. + qtd->error_count = 0;
  93921. + goto handle_nak_done;
  93922. + }
  93923. +
  93924. + /*
  93925. + * NAK interrupts normally occur during OUT transfers in DMA
  93926. + * or Slave mode. For IN transfers, more requests will be
  93927. + * queued as request queue space is available.
  93928. + */
  93929. + qtd->error_count = 0;
  93930. +
  93931. + if (!hc->qh->ping_state) {
  93932. + update_urb_state_xfer_intr(hc, hc_regs,
  93933. + qtd->urb, qtd,
  93934. + DWC_OTG_HC_XFER_NAK);
  93935. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  93936. +
  93937. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  93938. + hc->qh->ping_state = 1;
  93939. + }
  93940. +
  93941. + /*
  93942. + * Halt the channel so the transfer can be re-started from
  93943. + * the appropriate point or the PING protocol will
  93944. + * start/continue.
  93945. + */
  93946. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93947. + break;
  93948. + case UE_INTERRUPT:
  93949. + qtd->error_count = 0;
  93950. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  93951. + break;
  93952. + case UE_ISOCHRONOUS:
  93953. + /* Should never get called for isochronous transfers. */
  93954. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  93955. + break;
  93956. + }
  93957. +
  93958. +handle_nak_done:
  93959. + disable_hc_int(hc_regs, nak);
  93960. +
  93961. + return 1;
  93962. +}
  93963. +
  93964. +/**
  93965. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  93966. + * performing the PING protocol in Slave mode, when errors occur during
  93967. + * either Slave mode or DMA mode, and during Start Split transactions.
  93968. + */
  93969. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  93970. + dwc_hc_t * hc,
  93971. + dwc_otg_hc_regs_t * hc_regs,
  93972. + dwc_otg_qtd_t * qtd)
  93973. +{
  93974. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  93975. + "ACK Received--\n", hc->hc_num);
  93976. +
  93977. + if (hc->do_split) {
  93978. + /*
  93979. + * Handle ACK on SSPLIT.
  93980. + * ACK should not occur in CSPLIT.
  93981. + */
  93982. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  93983. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  93984. + }
  93985. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  93986. + /* Don't need complete for isochronous out transfers. */
  93987. + qtd->complete_split = 1;
  93988. + }
  93989. +
  93990. + /* ISOC OUT */
  93991. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  93992. + switch (hc->xact_pos) {
  93993. + case DWC_HCSPLIT_XACTPOS_ALL:
  93994. + break;
  93995. + case DWC_HCSPLIT_XACTPOS_END:
  93996. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  93997. + qtd->isoc_split_offset = 0;
  93998. + break;
  93999. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  94000. + case DWC_HCSPLIT_XACTPOS_MID:
  94001. + /*
  94002. + * For BEGIN or MID, calculate the length for
  94003. + * the next microframe to determine the correct
  94004. + * SSPLIT token, either MID or END.
  94005. + */
  94006. + {
  94007. + struct dwc_otg_hcd_iso_packet_desc
  94008. + *frame_desc;
  94009. +
  94010. + frame_desc =
  94011. + &qtd->urb->
  94012. + iso_descs[qtd->isoc_frame_index];
  94013. + qtd->isoc_split_offset += 188;
  94014. +
  94015. + if ((frame_desc->length -
  94016. + qtd->isoc_split_offset) <= 188) {
  94017. + qtd->isoc_split_pos =
  94018. + DWC_HCSPLIT_XACTPOS_END;
  94019. + } else {
  94020. + qtd->isoc_split_pos =
  94021. + DWC_HCSPLIT_XACTPOS_MID;
  94022. + }
  94023. +
  94024. + }
  94025. + break;
  94026. + }
  94027. + } else {
  94028. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  94029. + }
  94030. + } else {
  94031. + /*
  94032. + * An unmasked ACK on a non-split DMA transaction is
  94033. + * for the sole purpose of resetting error counts. Disable other
  94034. + * interrupts unmasked for the same reason.
  94035. + */
  94036. + if(hcd->core_if->dma_enable) {
  94037. + disable_hc_int(hc_regs, datatglerr);
  94038. + disable_hc_int(hc_regs, nak);
  94039. + }
  94040. + qtd->error_count = 0;
  94041. +
  94042. + if (hc->qh->ping_state) {
  94043. + hc->qh->ping_state = 0;
  94044. + /*
  94045. + * Halt the channel so the transfer can be re-started
  94046. + * from the appropriate point. This only happens in
  94047. + * Slave mode. In DMA mode, the ping_state is cleared
  94048. + * when the transfer is started because the core
  94049. + * automatically executes the PING, then the transfer.
  94050. + */
  94051. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  94052. + }
  94053. + }
  94054. +
  94055. + /*
  94056. + * If the ACK occurred when _not_ in the PING state, let the channel
  94057. + * continue transferring data after clearing the error count.
  94058. + */
  94059. +
  94060. + disable_hc_int(hc_regs, ack);
  94061. +
  94062. + return 1;
  94063. +}
  94064. +
  94065. +/**
  94066. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  94067. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  94068. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  94069. + * handled in the xfercomp interrupt handler, not here. This handler may be
  94070. + * called in either DMA mode or Slave mode.
  94071. + */
  94072. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  94073. + dwc_hc_t * hc,
  94074. + dwc_otg_hc_regs_t * hc_regs,
  94075. + dwc_otg_qtd_t * qtd)
  94076. +{
  94077. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94078. + "NYET Received--\n", hc->hc_num);
  94079. +
  94080. + /*
  94081. + * NYET on CSPLIT
  94082. + * re-do the CSPLIT immediately on non-periodic
  94083. + */
  94084. + if (hc->do_split && hc->complete_split) {
  94085. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  94086. + && hcd->core_if->dma_enable) {
  94087. + qtd->complete_split = 0;
  94088. + qtd->isoc_split_offset = 0;
  94089. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  94090. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94091. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94092. + }
  94093. + else
  94094. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94095. + goto handle_nyet_done;
  94096. + }
  94097. +
  94098. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  94099. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  94100. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  94101. +
  94102. + // With the FIQ running we only ever see the failed NYET
  94103. + if (dwc_full_frame_num(frnum) !=
  94104. + dwc_full_frame_num(hc->qh->sched_frame) ||
  94105. + fiq_fsm_enable) {
  94106. + /*
  94107. + * No longer in the same full speed frame.
  94108. + * Treat this as a transaction error.
  94109. + */
  94110. +#if 0
  94111. + /** @todo Fix system performance so this can
  94112. + * be treated as an error. Right now complete
  94113. + * splits cannot be scheduled precisely enough
  94114. + * due to other system activity, so this error
  94115. + * occurs regularly in Slave mode.
  94116. + */
  94117. + qtd->error_count++;
  94118. +#endif
  94119. + qtd->complete_split = 0;
  94120. + halt_channel(hcd, hc, qtd,
  94121. + DWC_OTG_HC_XFER_XACT_ERR);
  94122. + /** @todo add support for isoc release */
  94123. + goto handle_nyet_done;
  94124. + }
  94125. + }
  94126. +
  94127. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  94128. + goto handle_nyet_done;
  94129. + }
  94130. +
  94131. + hc->qh->ping_state = 1;
  94132. + qtd->error_count = 0;
  94133. +
  94134. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  94135. + DWC_OTG_HC_XFER_NYET);
  94136. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94137. +
  94138. + /*
  94139. + * Halt the channel and re-start the transfer so the PING
  94140. + * protocol will start.
  94141. + */
  94142. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  94143. +
  94144. +handle_nyet_done:
  94145. + disable_hc_int(hc_regs, nyet);
  94146. + return 1;
  94147. +}
  94148. +
  94149. +/**
  94150. + * Handles a host channel babble interrupt. This handler may be called in
  94151. + * either DMA mode or Slave mode.
  94152. + */
  94153. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  94154. + dwc_hc_t * hc,
  94155. + dwc_otg_hc_regs_t * hc_regs,
  94156. + dwc_otg_qtd_t * qtd)
  94157. +{
  94158. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94159. + "Babble Error--\n", hc->hc_num);
  94160. +
  94161. + if (hcd->core_if->dma_desc_enable) {
  94162. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  94163. + DWC_OTG_HC_XFER_BABBLE_ERR);
  94164. + goto handle_babble_done;
  94165. + }
  94166. +
  94167. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  94168. + hcd->fops->complete(hcd, qtd->urb->priv,
  94169. + qtd->urb, -DWC_E_OVERFLOW);
  94170. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  94171. + } else {
  94172. + dwc_otg_halt_status_e halt_status;
  94173. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  94174. + DWC_OTG_HC_XFER_BABBLE_ERR);
  94175. + halt_channel(hcd, hc, qtd, halt_status);
  94176. + }
  94177. +
  94178. +handle_babble_done:
  94179. + disable_hc_int(hc_regs, bblerr);
  94180. + return 1;
  94181. +}
  94182. +
  94183. +/**
  94184. + * Handles a host channel AHB error interrupt. This handler is only called in
  94185. + * DMA mode.
  94186. + */
  94187. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  94188. + dwc_hc_t * hc,
  94189. + dwc_otg_hc_regs_t * hc_regs,
  94190. + dwc_otg_qtd_t * qtd)
  94191. +{
  94192. + hcchar_data_t hcchar;
  94193. + hcsplt_data_t hcsplt;
  94194. + hctsiz_data_t hctsiz;
  94195. + uint32_t hcdma;
  94196. + char *pipetype, *speed;
  94197. +
  94198. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  94199. +
  94200. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94201. + "AHB Error--\n", hc->hc_num);
  94202. +
  94203. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  94204. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  94205. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  94206. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  94207. +
  94208. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  94209. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  94210. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  94211. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  94212. + DWC_ERROR(" Device address: %d\n",
  94213. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  94214. + DWC_ERROR(" Endpoint: %d, %s\n",
  94215. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  94216. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  94217. +
  94218. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  94219. + case UE_CONTROL:
  94220. + pipetype = "CONTROL";
  94221. + break;
  94222. + case UE_BULK:
  94223. + pipetype = "BULK";
  94224. + break;
  94225. + case UE_INTERRUPT:
  94226. + pipetype = "INTERRUPT";
  94227. + break;
  94228. + case UE_ISOCHRONOUS:
  94229. + pipetype = "ISOCHRONOUS";
  94230. + break;
  94231. + default:
  94232. + pipetype = "UNKNOWN";
  94233. + break;
  94234. + }
  94235. +
  94236. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  94237. +
  94238. + switch (hc->speed) {
  94239. + case DWC_OTG_EP_SPEED_HIGH:
  94240. + speed = "HIGH";
  94241. + break;
  94242. + case DWC_OTG_EP_SPEED_FULL:
  94243. + speed = "FULL";
  94244. + break;
  94245. + case DWC_OTG_EP_SPEED_LOW:
  94246. + speed = "LOW";
  94247. + break;
  94248. + default:
  94249. + speed = "UNKNOWN";
  94250. + break;
  94251. + };
  94252. +
  94253. + DWC_ERROR(" Speed: %s\n", speed);
  94254. +
  94255. + DWC_ERROR(" Max packet size: %d\n",
  94256. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  94257. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  94258. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  94259. + urb->buf, (void *)urb->dma);
  94260. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  94261. + urb->setup_packet, (void *)urb->setup_dma);
  94262. + DWC_ERROR(" Interval: %d\n", urb->interval);
  94263. +
  94264. + /* Core haltes the channel for Descriptor DMA mode */
  94265. + if (hcd->core_if->dma_desc_enable) {
  94266. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  94267. + DWC_OTG_HC_XFER_AHB_ERR);
  94268. + goto handle_ahberr_done;
  94269. + }
  94270. +
  94271. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  94272. +
  94273. + /*
  94274. + * Force a channel halt. Don't call halt_channel because that won't
  94275. + * write to the HCCHARn register in DMA mode to force the halt.
  94276. + */
  94277. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  94278. +handle_ahberr_done:
  94279. + disable_hc_int(hc_regs, ahberr);
  94280. + return 1;
  94281. +}
  94282. +
  94283. +/**
  94284. + * Handles a host channel transaction error interrupt. This handler may be
  94285. + * called in either DMA mode or Slave mode.
  94286. + */
  94287. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  94288. + dwc_hc_t * hc,
  94289. + dwc_otg_hc_regs_t * hc_regs,
  94290. + dwc_otg_qtd_t * qtd)
  94291. +{
  94292. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94293. + "Transaction Error--\n", hc->hc_num);
  94294. +
  94295. + if (hcd->core_if->dma_desc_enable) {
  94296. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  94297. + DWC_OTG_HC_XFER_XACT_ERR);
  94298. + goto handle_xacterr_done;
  94299. + }
  94300. +
  94301. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  94302. + case UE_CONTROL:
  94303. + case UE_BULK:
  94304. + qtd->error_count++;
  94305. + if (!hc->qh->ping_state) {
  94306. +
  94307. + update_urb_state_xfer_intr(hc, hc_regs,
  94308. + qtd->urb, qtd,
  94309. + DWC_OTG_HC_XFER_XACT_ERR);
  94310. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94311. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  94312. + hc->qh->ping_state = 1;
  94313. + }
  94314. + }
  94315. +
  94316. + /*
  94317. + * Halt the channel so the transfer can be re-started from
  94318. + * the appropriate point or the PING protocol will start.
  94319. + */
  94320. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94321. + break;
  94322. + case UE_INTERRUPT:
  94323. + qtd->error_count++;
  94324. + if (hc->do_split && hc->complete_split) {
  94325. + qtd->complete_split = 0;
  94326. + }
  94327. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94328. + break;
  94329. + case UE_ISOCHRONOUS:
  94330. + {
  94331. + dwc_otg_halt_status_e halt_status;
  94332. + halt_status =
  94333. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  94334. + DWC_OTG_HC_XFER_XACT_ERR);
  94335. +
  94336. + halt_channel(hcd, hc, qtd, halt_status);
  94337. + }
  94338. + break;
  94339. + }
  94340. +handle_xacterr_done:
  94341. + disable_hc_int(hc_regs, xacterr);
  94342. +
  94343. + return 1;
  94344. +}
  94345. +
  94346. +/**
  94347. + * Handles a host channel frame overrun interrupt. This handler may be called
  94348. + * in either DMA mode or Slave mode.
  94349. + */
  94350. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  94351. + dwc_hc_t * hc,
  94352. + dwc_otg_hc_regs_t * hc_regs,
  94353. + dwc_otg_qtd_t * qtd)
  94354. +{
  94355. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94356. + "Frame Overrun--\n", hc->hc_num);
  94357. +
  94358. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  94359. + case UE_CONTROL:
  94360. + case UE_BULK:
  94361. + break;
  94362. + case UE_INTERRUPT:
  94363. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  94364. + break;
  94365. + case UE_ISOCHRONOUS:
  94366. + {
  94367. + dwc_otg_halt_status_e halt_status;
  94368. + halt_status =
  94369. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  94370. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  94371. +
  94372. + halt_channel(hcd, hc, qtd, halt_status);
  94373. + }
  94374. + break;
  94375. + }
  94376. +
  94377. + disable_hc_int(hc_regs, frmovrun);
  94378. +
  94379. + return 1;
  94380. +}
  94381. +
  94382. +/**
  94383. + * Handles a host channel data toggle error interrupt. This handler may be
  94384. + * called in either DMA mode or Slave mode.
  94385. + */
  94386. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  94387. + dwc_hc_t * hc,
  94388. + dwc_otg_hc_regs_t * hc_regs,
  94389. + dwc_otg_qtd_t * qtd)
  94390. +{
  94391. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94392. + "Data Toggle Error on %s transfer--\n",
  94393. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  94394. +
  94395. + /* Data toggles on split transactions cause the hc to halt.
  94396. + * restart transfer */
  94397. + if(hc->qh->do_split)
  94398. + {
  94399. + qtd->error_count++;
  94400. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94401. + update_urb_state_xfer_intr(hc, hc_regs,
  94402. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94403. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94404. + } else if (hc->ep_is_in) {
  94405. + /* An unmasked data toggle error on a non-split DMA transaction is
  94406. + * for the sole purpose of resetting error counts. Disable other
  94407. + * interrupts unmasked for the same reason.
  94408. + */
  94409. + if(hcd->core_if->dma_enable) {
  94410. + disable_hc_int(hc_regs, ack);
  94411. + disable_hc_int(hc_regs, nak);
  94412. + }
  94413. + qtd->error_count = 0;
  94414. + }
  94415. +
  94416. + disable_hc_int(hc_regs, datatglerr);
  94417. +
  94418. + return 1;
  94419. +}
  94420. +
  94421. +#ifdef DEBUG
  94422. +/**
  94423. + * This function is for debug only. It checks that a valid halt status is set
  94424. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  94425. + * taken and a warning is issued.
  94426. + * @return 1 if halt status is ok, 0 otherwise.
  94427. + */
  94428. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  94429. + dwc_hc_t * hc,
  94430. + dwc_otg_hc_regs_t * hc_regs,
  94431. + dwc_otg_qtd_t * qtd)
  94432. +{
  94433. + hcchar_data_t hcchar;
  94434. + hctsiz_data_t hctsiz;
  94435. + hcint_data_t hcint;
  94436. + hcintmsk_data_t hcintmsk;
  94437. + hcsplt_data_t hcsplt;
  94438. +
  94439. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  94440. + /*
  94441. + * This code is here only as a check. This condition should
  94442. + * never happen. Ignore the halt if it does occur.
  94443. + */
  94444. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  94445. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  94446. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  94447. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  94448. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  94449. + DWC_WARN
  94450. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  94451. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  94452. + "hcint 0x%08x, hcintmsk 0x%08x, "
  94453. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  94454. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  94455. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  94456. +
  94457. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  94458. + __func__, hc->hc_num);
  94459. + DWC_WARN("\n");
  94460. + clear_hc_int(hc_regs, chhltd);
  94461. + return 0;
  94462. + }
  94463. +
  94464. + /*
  94465. + * This code is here only as a check. hcchar.chdis should
  94466. + * never be set when the halt interrupt occurs. Halt the
  94467. + * channel again if it does occur.
  94468. + */
  94469. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  94470. + if (hcchar.b.chdis) {
  94471. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  94472. + "hcchar 0x%08x, trying to halt again\n",
  94473. + __func__, hcchar.d32);
  94474. + clear_hc_int(hc_regs, chhltd);
  94475. + hc->halt_pending = 0;
  94476. + halt_channel(hcd, hc, qtd, hc->halt_status);
  94477. + return 0;
  94478. + }
  94479. +
  94480. + return 1;
  94481. +}
  94482. +#endif
  94483. +
  94484. +/**
  94485. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  94486. + * determines the reason the channel halted and proceeds accordingly.
  94487. + */
  94488. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  94489. + dwc_hc_t * hc,
  94490. + dwc_otg_hc_regs_t * hc_regs,
  94491. + dwc_otg_qtd_t * qtd)
  94492. +{
  94493. + int out_nak_enh = 0;
  94494. + hcint_data_t hcint;
  94495. + hcintmsk_data_t hcintmsk;
  94496. + /* For core with OUT NAK enhancement, the flow for high-
  94497. + * speed CONTROL/BULK OUT is handled a little differently.
  94498. + */
  94499. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  94500. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  94501. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  94502. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  94503. + out_nak_enh = 1;
  94504. + }
  94505. + }
  94506. +
  94507. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  94508. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  94509. + && !hcd->core_if->dma_desc_enable)) {
  94510. + /*
  94511. + * Just release the channel. A dequeue can happen on a
  94512. + * transfer timeout. In the case of an AHB Error, the channel
  94513. + * was forced to halt because there's no way to gracefully
  94514. + * recover.
  94515. + */
  94516. + if (hcd->core_if->dma_desc_enable)
  94517. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  94518. + hc->halt_status);
  94519. + else
  94520. + release_channel(hcd, hc, qtd, hc->halt_status);
  94521. + return;
  94522. + }
  94523. +
  94524. + /* Read the HCINTn register to determine the cause for the halt. */
  94525. +
  94526. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  94527. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  94528. +
  94529. + if (hcint.b.xfercomp) {
  94530. + /** @todo This is here because of a possible hardware bug. Spec
  94531. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  94532. + * interrupt w/ACK bit set should occur, but I only see the
  94533. + * XFERCOMP bit, even with it masked out. This is a workaround
  94534. + * for that behavior. Should fix this when hardware is fixed.
  94535. + */
  94536. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  94537. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  94538. + }
  94539. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  94540. + } else if (hcint.b.stall) {
  94541. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94542. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  94543. + if (out_nak_enh) {
  94544. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  94545. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  94546. + qtd->error_count = 0;
  94547. + } else {
  94548. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  94549. + }
  94550. + }
  94551. +
  94552. + /*
  94553. + * Must handle xacterr before nak or ack. Could get a xacterr
  94554. + * at the same time as either of these on a BULK/CONTROL OUT
  94555. + * that started with a PING. The xacterr takes precedence.
  94556. + */
  94557. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94558. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  94559. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94560. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  94561. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94562. + } else if (hcint.b.bblerr) {
  94563. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94564. + } else if (hcint.b.frmovrun) {
  94565. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  94566. + } else if (hcint.b.datatglerr) {
  94567. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  94568. + } else if (!out_nak_enh) {
  94569. + if (hcint.b.nyet) {
  94570. + /*
  94571. + * Must handle nyet before nak or ack. Could get a nyet at the
  94572. + * same time as either of those on a BULK/CONTROL OUT that
  94573. + * started with a PING. The nyet takes precedence.
  94574. + */
  94575. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  94576. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  94577. + /*
  94578. + * If nak is not masked, it's because a non-split IN transfer
  94579. + * is in an error state. In that case, the nak is handled by
  94580. + * the nak interrupt handler, not here. Handle nak here for
  94581. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  94582. + * rewinding the buffer pointer.
  94583. + */
  94584. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94585. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  94586. + /*
  94587. + * If ack is not masked, it's because a non-split IN transfer
  94588. + * is in an error state. In that case, the ack is handled by
  94589. + * the ack interrupt handler, not here. Handle ack here for
  94590. + * split transfers. Start splits halt on ACK.
  94591. + */
  94592. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  94593. + } else {
  94594. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  94595. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  94596. + /*
  94597. + * A periodic transfer halted with no other channel
  94598. + * interrupts set. Assume it was halted by the core
  94599. + * because it could not be completed in its scheduled
  94600. + * (micro)frame.
  94601. + */
  94602. +#ifdef DEBUG
  94603. + DWC_PRINTF
  94604. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  94605. + __func__, hc->hc_num);
  94606. +#endif
  94607. + halt_channel(hcd, hc, qtd,
  94608. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  94609. + } else {
  94610. + DWC_ERROR
  94611. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  94612. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  94613. + __func__, hc->hc_num, hcint.d32,
  94614. + DWC_READ_REG32(&hcd->
  94615. + core_if->core_global_regs->
  94616. + gintsts));
  94617. + /* Failthrough: use 3-strikes rule */
  94618. + qtd->error_count++;
  94619. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94620. + update_urb_state_xfer_intr(hc, hc_regs,
  94621. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94622. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94623. + }
  94624. +
  94625. + }
  94626. + } else {
  94627. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  94628. + hcint.d32);
  94629. + /* Failthrough: use 3-strikes rule */
  94630. + qtd->error_count++;
  94631. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94632. + update_urb_state_xfer_intr(hc, hc_regs,
  94633. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94634. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  94635. + }
  94636. +}
  94637. +
  94638. +/**
  94639. + * Handles a host channel Channel Halted interrupt.
  94640. + *
  94641. + * In slave mode, this handler is called only when the driver specifically
  94642. + * requests a halt. This occurs during handling other host channel interrupts
  94643. + * (e.g. nak, xacterr, stall, nyet, etc.).
  94644. + *
  94645. + * In DMA mode, this is the interrupt that occurs when the core has finished
  94646. + * processing a transfer on a channel. Other host channel interrupts (except
  94647. + * ahberr) are disabled in DMA mode.
  94648. + */
  94649. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  94650. + dwc_hc_t * hc,
  94651. + dwc_otg_hc_regs_t * hc_regs,
  94652. + dwc_otg_qtd_t * qtd)
  94653. +{
  94654. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  94655. + "Channel Halted--\n", hc->hc_num);
  94656. +
  94657. + if (hcd->core_if->dma_enable) {
  94658. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  94659. + } else {
  94660. +#ifdef DEBUG
  94661. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  94662. + return 1;
  94663. + }
  94664. +#endif
  94665. + release_channel(hcd, hc, qtd, hc->halt_status);
  94666. + }
  94667. +
  94668. + return 1;
  94669. +}
  94670. +
  94671. +
  94672. +/**
  94673. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  94674. + * FIQ transfer completion
  94675. + * @hcd: Pointer to dwc_otg_hcd struct
  94676. + * @num: Host channel number
  94677. + *
  94678. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  94679. + * 2. Copy it from the dwc_otg_urb into the real URB
  94680. + */
  94681. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  94682. +{
  94683. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  94684. + int nr_frames = dwc_urb->packet_count;
  94685. + int i;
  94686. + hcint_data_t frame_hcint;
  94687. +
  94688. + for (i = 0; i < nr_frames; i++) {
  94689. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  94690. + if (frame_hcint.b.xfercomp) {
  94691. + dwc_urb->iso_descs[i].status = 0;
  94692. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  94693. + } else if (frame_hcint.b.frmovrun) {
  94694. + if (qh->ep_is_in)
  94695. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  94696. + else
  94697. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  94698. + dwc_urb->error_count++;
  94699. + dwc_urb->iso_descs[i].actual_length = 0;
  94700. + } else if (frame_hcint.b.xacterr) {
  94701. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  94702. + dwc_urb->error_count++;
  94703. + dwc_urb->iso_descs[i].actual_length = 0;
  94704. + } else if (frame_hcint.b.bblerr) {
  94705. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  94706. + dwc_urb->error_count++;
  94707. + dwc_urb->iso_descs[i].actual_length = 0;
  94708. + } else {
  94709. + /* Something went wrong */
  94710. + dwc_urb->iso_descs[i].status = -1;
  94711. + dwc_urb->iso_descs[i].actual_length = 0;
  94712. + dwc_urb->error_count++;
  94713. + }
  94714. + }
  94715. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  94716. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  94717. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  94718. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94719. +}
  94720. +
  94721. +/**
  94722. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  94723. + * @hcd: Pointer to dwc_otg_hcd struct
  94724. + * @num: Host channel number
  94725. + *
  94726. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  94727. + * Returns total length of data or -1 if the buffers were not used.
  94728. + *
  94729. + */
  94730. +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)
  94731. +{
  94732. + dwc_hc_t *hc = qh->channel;
  94733. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  94734. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  94735. + uint8_t *ptr = NULL;
  94736. + int index = 0, len = 0;
  94737. + int i = 0;
  94738. + if (hc->ep_is_in) {
  94739. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  94740. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  94741. + ptr = qtd->urb->buf;
  94742. + if (qh->ep_type == UE_ISOCHRONOUS) {
  94743. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  94744. + index = qtd->isoc_frame_index;
  94745. + ptr += qtd->urb->iso_descs[index].offset;
  94746. + } else {
  94747. + /* Need to increment by actual_length for interrupt IN */
  94748. + ptr += qtd->urb->actual_length;
  94749. + }
  94750. +
  94751. + for (i = 0; i < st->dma_info.index; i++) {
  94752. + len += st->dma_info.slot_len[i];
  94753. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  94754. + ptr += st->dma_info.slot_len[i];
  94755. + }
  94756. + return len;
  94757. + } else {
  94758. + /* OUT endpoints - nothing to do. */
  94759. + return -1;
  94760. + }
  94761. +
  94762. +}
  94763. +/**
  94764. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  94765. + * from a channel handled in the FIQ
  94766. + * @hcd: Pointer to dwc_otg_hcd struct
  94767. + * @num: Host channel number
  94768. + *
  94769. + * If a host channel interrupt was received by the IRQ and this was a channel
  94770. + * used by the FIQ, the execution flow for transfer completion is substantially
  94771. + * different from the normal (messy) path. This function and its friends handles
  94772. + * channel cleanup and transaction completion from a FIQ transaction.
  94773. + */
  94774. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  94775. +{
  94776. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  94777. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  94778. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  94779. + dwc_otg_qh_t *qh = hc->qh;
  94780. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  94781. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  94782. + int hostchannels = 0;
  94783. + int ret = 0;
  94784. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  94785. +
  94786. + hostchannels = hcd->available_host_channels;
  94787. + switch (st->fsm) {
  94788. + case FIQ_TEST:
  94789. + break;
  94790. +
  94791. + case FIQ_DEQUEUE_ISSUED:
  94792. + /* hc_halt was called. QTD no longer exists. */
  94793. + /* TODO: for a nonperiodic split transaction, need to issue a
  94794. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  94795. + */
  94796. + release_channel(hcd, hc, NULL, hc->halt_status);
  94797. + ret = 1;
  94798. + break;
  94799. +
  94800. + case FIQ_NP_SPLIT_DONE:
  94801. + /* Nonperiodic transaction complete. */
  94802. + if (!hc->ep_is_in) {
  94803. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  94804. + }
  94805. + if (hcint.b.xfercomp) {
  94806. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  94807. + } else if (hcint.b.nak) {
  94808. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94809. + }
  94810. + ret = 1;
  94811. + break;
  94812. +
  94813. + case FIQ_NP_SPLIT_HS_ABORTED:
  94814. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  94815. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  94816. + * because there's no guarantee which order a non-periodic split happened in.
  94817. + * We could end up clearing a perfectly good transaction out of the buffer.
  94818. + */
  94819. + if (hcint.b.xacterr) {
  94820. + qtd->error_count += st->nr_errors;
  94821. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94822. + } else if (hcint.b.ahberr) {
  94823. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94824. + } else {
  94825. + local_fiq_disable();
  94826. + BUG();
  94827. + }
  94828. + break;
  94829. +
  94830. + case FIQ_NP_SPLIT_LS_ABORTED:
  94831. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  94832. + * STALL/data toggle error response on a CSPLIT */
  94833. + if (hcint.b.stall) {
  94834. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94835. + } else if (hcint.b.datatglerr) {
  94836. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  94837. + } else if (hcint.b.bblerr) {
  94838. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94839. + } else if (hcint.b.ahberr) {
  94840. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  94841. + } else {
  94842. + local_fiq_disable();
  94843. + BUG();
  94844. + }
  94845. + break;
  94846. +
  94847. + case FIQ_PER_SPLIT_DONE:
  94848. + /* Isoc IN or Interrupt IN/OUT */
  94849. +
  94850. + /* Flow control here is different from the normal execution by the driver.
  94851. + * We need to completely ignore most of the driver's method of handling
  94852. + * split transactions and do it ourselves.
  94853. + */
  94854. + if (hc->ep_type == UE_INTERRUPT) {
  94855. + if (hcint.b.nak) {
  94856. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  94857. + } else if (hc->ep_is_in) {
  94858. + int len;
  94859. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  94860. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  94861. + qtd->urb->actual_length += len;
  94862. + if (qtd->urb->actual_length >= qtd->urb->length) {
  94863. + qtd->urb->status = 0;
  94864. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94865. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94866. + } else {
  94867. + /* Interrupt transfer not complete yet - is it a short read? */
  94868. + if (len < hc->max_packet) {
  94869. + /* Interrupt transaction complete */
  94870. + qtd->urb->status = 0;
  94871. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94872. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94873. + } else {
  94874. + /* Further transactions required */
  94875. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94876. + }
  94877. + }
  94878. + } else {
  94879. + /* Interrupt OUT complete. */
  94880. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  94881. + qtd->urb->actual_length += hc->xfer_len;
  94882. + if (qtd->urb->actual_length >= qtd->urb->length) {
  94883. + qtd->urb->status = 0;
  94884. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  94885. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94886. + } else {
  94887. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94888. + }
  94889. + }
  94890. + } else {
  94891. + /* ISOC IN complete. */
  94892. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94893. + int len = 0;
  94894. + /* Record errors, update qtd. */
  94895. + if (st->nr_errors) {
  94896. + frame_desc->actual_length = 0;
  94897. + frame_desc->status = -DWC_E_PROTOCOL;
  94898. + } else {
  94899. + frame_desc->status = 0;
  94900. + /* Unswizzle dma */
  94901. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  94902. + frame_desc->actual_length = len;
  94903. + }
  94904. + qtd->isoc_frame_index++;
  94905. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94906. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94907. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94908. + } else {
  94909. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94910. + }
  94911. + }
  94912. + break;
  94913. +
  94914. + case FIQ_PER_ISO_OUT_DONE: {
  94915. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94916. + /* Record errors, update qtd. */
  94917. + if (st->nr_errors) {
  94918. + frame_desc->actual_length = 0;
  94919. + frame_desc->status = -DWC_E_PROTOCOL;
  94920. + } else {
  94921. + frame_desc->status = 0;
  94922. + frame_desc->actual_length = frame_desc->length;
  94923. + }
  94924. + qtd->isoc_frame_index++;
  94925. + qtd->isoc_split_offset = 0;
  94926. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94927. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94928. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94929. + } else {
  94930. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94931. + }
  94932. + }
  94933. + break;
  94934. +
  94935. + case FIQ_PER_SPLIT_NYET_ABORTED:
  94936. + /* Doh. lost the data. */
  94937. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  94938. + "- FIQ reported NYET. Data may have been lost.\n",
  94939. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  94940. + if (hc->ep_type == UE_ISOCHRONOUS) {
  94941. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  94942. + /* Record errors, update qtd. */
  94943. + frame_desc->actual_length = 0;
  94944. + frame_desc->status = -DWC_E_PROTOCOL;
  94945. + qtd->isoc_frame_index++;
  94946. + qtd->isoc_split_offset = 0;
  94947. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  94948. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  94949. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  94950. + } else {
  94951. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  94952. + }
  94953. + } else {
  94954. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94955. + }
  94956. + break;
  94957. +
  94958. + case FIQ_HS_ISOC_DONE:
  94959. + /* The FIQ has performed a whole pile of isochronous transactions.
  94960. + * The status is recorded as the interrupt state should the transaction
  94961. + * fail.
  94962. + */
  94963. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  94964. + break;
  94965. +
  94966. + case FIQ_PER_SPLIT_LS_ABORTED:
  94967. + if (hcint.b.xacterr) {
  94968. + /* Hub has responded with an ERR packet. Device
  94969. + * has been unplugged or the port has been disabled.
  94970. + * TODO: need to issue a reset to the hub port. */
  94971. + qtd->error_count += 3;
  94972. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94973. + } else if (hcint.b.stall) {
  94974. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  94975. + } else if (hcint.b.bblerr) {
  94976. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  94977. + } else {
  94978. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  94979. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  94980. + st->fsm, hc->dev_addr, hc->ep_num);
  94981. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94982. + }
  94983. + break;
  94984. +
  94985. + case FIQ_PER_SPLIT_HS_ABORTED:
  94986. + /* Either the SSPLIT phase suffered transaction errors or something
  94987. + * unexpected happened.
  94988. + */
  94989. + qtd->error_count += 3;
  94990. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  94991. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  94992. + break;
  94993. +
  94994. + case FIQ_PER_SPLIT_TIMEOUT:
  94995. + /* Couldn't complete in the nominated frame */
  94996. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  94997. + "- FIQ timed out. Data may have been lost.\n",
  94998. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  94999. + if (hc->ep_type == UE_ISOCHRONOUS) {
  95000. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  95001. + /* Record errors, update qtd. */
  95002. + frame_desc->actual_length = 0;
  95003. + if (hc->ep_is_in) {
  95004. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  95005. + } else {
  95006. + frame_desc->status = -DWC_E_COMMUNICATION;
  95007. + }
  95008. + qtd->isoc_frame_index++;
  95009. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  95010. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  95011. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  95012. + } else {
  95013. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  95014. + }
  95015. + } else {
  95016. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  95017. + }
  95018. + break;
  95019. +
  95020. + default:
  95021. + local_fiq_disable();
  95022. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  95023. + BUG();
  95024. + }
  95025. + //if (hostchannels != hcd->available_host_channels) {
  95026. + /* should have incremented by now! */
  95027. + // BUG();
  95028. +// }
  95029. + return ret;
  95030. +}
  95031. +
  95032. +/** Handles interrupt for a specific Host Channel */
  95033. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  95034. +{
  95035. + int retval = 0;
  95036. + hcint_data_t hcint;
  95037. + hcintmsk_data_t hcintmsk;
  95038. + dwc_hc_t *hc;
  95039. + dwc_otg_hc_regs_t *hc_regs;
  95040. + dwc_otg_qtd_t *qtd;
  95041. +
  95042. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  95043. +
  95044. + hc = dwc_otg_hcd->hc_ptr_array[num];
  95045. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  95046. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  95047. + /* We are responding to a channel disable. Driver
  95048. + * state is cleared - our qtd has gone away.
  95049. + */
  95050. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  95051. + return 1;
  95052. + }
  95053. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  95054. +
  95055. + /*
  95056. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  95057. + * Execution path is fundamentally different for the channels after a FIQ has completed
  95058. + * a split transaction.
  95059. + */
  95060. + if (fiq_fsm_enable) {
  95061. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  95062. + case FIQ_PASSTHROUGH:
  95063. + break;
  95064. + case FIQ_PASSTHROUGH_ERRORSTATE:
  95065. + /* Hook into the error count */
  95066. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  95067. + if (!dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  95068. + qtd->error_count = 0;
  95069. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  95070. + }
  95071. + break;
  95072. + default:
  95073. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  95074. + return 1;
  95075. + }
  95076. + }
  95077. +
  95078. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  95079. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  95080. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  95081. + if (!dwc_otg_hcd->core_if->dma_enable) {
  95082. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  95083. + hcint.b.chhltd = 0;
  95084. + }
  95085. + }
  95086. +
  95087. + if (hcint.b.xfercomp) {
  95088. + retval |=
  95089. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95090. + /*
  95091. + * If NYET occurred at same time as Xfer Complete, the NYET is
  95092. + * handled by the Xfer Complete interrupt handler. Don't want
  95093. + * to call the NYET interrupt handler in this case.
  95094. + */
  95095. + hcint.b.nyet = 0;
  95096. + }
  95097. + if (hcint.b.chhltd) {
  95098. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95099. + }
  95100. + if (hcint.b.ahberr) {
  95101. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95102. + }
  95103. + if (hcint.b.stall) {
  95104. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95105. + }
  95106. + if (hcint.b.nak) {
  95107. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95108. + }
  95109. + if (hcint.b.ack) {
  95110. + if(!hcint.b.chhltd)
  95111. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95112. + }
  95113. + if (hcint.b.nyet) {
  95114. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95115. + }
  95116. + if (hcint.b.xacterr) {
  95117. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95118. + }
  95119. + if (hcint.b.bblerr) {
  95120. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95121. + }
  95122. + if (hcint.b.frmovrun) {
  95123. + retval |=
  95124. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95125. + }
  95126. + if (hcint.b.datatglerr) {
  95127. + retval |=
  95128. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  95129. + }
  95130. +
  95131. + return retval;
  95132. +}
  95133. +#endif /* DWC_DEVICE_ONLY */
  95134. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  95135. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  95136. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2015-03-10 17:26:51.302216687 +0100
  95137. @@ -0,0 +1,985 @@
  95138. +
  95139. +/* ==========================================================================
  95140. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  95141. + * $Revision: #20 $
  95142. + * $Date: 2011/10/26 $
  95143. + * $Change: 1872981 $
  95144. + *
  95145. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  95146. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  95147. + * otherwise expressly agreed to in writing between Synopsys and you.
  95148. + *
  95149. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  95150. + * any End User Software License Agreement or Agreement for Licensed Product
  95151. + * with Synopsys or any supplement thereto. You are permitted to use and
  95152. + * redistribute this Software in source and binary forms, with or without
  95153. + * modification, provided that redistributions of source code must retain this
  95154. + * notice. You may not view, use, disclose, copy or distribute this file or
  95155. + * any information contained herein except pursuant to this license grant from
  95156. + * Synopsys. If you do not agree with this notice, including the disclaimer
  95157. + * below, then you are not authorized to use the Software.
  95158. + *
  95159. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  95160. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  95161. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  95162. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  95163. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  95164. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  95165. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  95166. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  95167. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  95168. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  95169. + * DAMAGE.
  95170. + * ========================================================================== */
  95171. +#ifndef DWC_DEVICE_ONLY
  95172. +
  95173. +/**
  95174. + * @file
  95175. + *
  95176. + * This file contains the implementation of the HCD. In Linux, the HCD
  95177. + * implements the hc_driver API.
  95178. + */
  95179. +#include <linux/kernel.h>
  95180. +#include <linux/module.h>
  95181. +#include <linux/moduleparam.h>
  95182. +#include <linux/init.h>
  95183. +#include <linux/device.h>
  95184. +#include <linux/errno.h>
  95185. +#include <linux/list.h>
  95186. +#include <linux/interrupt.h>
  95187. +#include <linux/string.h>
  95188. +#include <linux/dma-mapping.h>
  95189. +#include <linux/version.h>
  95190. +#include <asm/io.h>
  95191. +#include <asm/fiq.h>
  95192. +#include <linux/usb.h>
  95193. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  95194. +#include <../drivers/usb/core/hcd.h>
  95195. +#else
  95196. +#include <linux/usb/hcd.h>
  95197. +#endif
  95198. +#include <asm/bug.h>
  95199. +
  95200. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  95201. +#define USB_URB_EP_LINKING 1
  95202. +#else
  95203. +#define USB_URB_EP_LINKING 0
  95204. +#endif
  95205. +
  95206. +#include "dwc_otg_hcd_if.h"
  95207. +#include "dwc_otg_dbg.h"
  95208. +#include "dwc_otg_driver.h"
  95209. +#include "dwc_otg_hcd.h"
  95210. +
  95211. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  95212. +
  95213. +/**
  95214. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  95215. + * qualified with its direction (possible 32 endpoints per device).
  95216. + */
  95217. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  95218. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  95219. +
  95220. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  95221. +
  95222. +extern bool fiq_enable;
  95223. +
  95224. +/** @name Linux HC Driver API Functions */
  95225. +/** @{ */
  95226. +/* manage i/o requests, device state */
  95227. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  95228. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95229. + struct usb_host_endpoint *ep,
  95230. +#endif
  95231. + struct urb *urb, gfp_t mem_flags);
  95232. +
  95233. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  95234. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95235. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  95236. +#endif
  95237. +#else /* kernels at or post 2.6.30 */
  95238. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  95239. + struct urb *urb, int status);
  95240. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  95241. +
  95242. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  95243. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  95244. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  95245. +#endif
  95246. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  95247. +extern int hcd_start(struct usb_hcd *hcd);
  95248. +extern void hcd_stop(struct usb_hcd *hcd);
  95249. +static int get_frame_number(struct usb_hcd *hcd);
  95250. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  95251. +extern int hub_control(struct usb_hcd *hcd,
  95252. + u16 typeReq,
  95253. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  95254. +
  95255. +struct wrapper_priv_data {
  95256. + dwc_otg_hcd_t *dwc_otg_hcd;
  95257. +};
  95258. +
  95259. +/** @} */
  95260. +
  95261. +static struct hc_driver dwc_otg_hc_driver = {
  95262. +
  95263. + .description = dwc_otg_hcd_name,
  95264. + .product_desc = "DWC OTG Controller",
  95265. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  95266. +
  95267. + .irq = dwc_otg_hcd_irq,
  95268. +
  95269. + .flags = HCD_MEMORY | HCD_USB2,
  95270. +
  95271. + //.reset =
  95272. + .start = hcd_start,
  95273. + //.suspend =
  95274. + //.resume =
  95275. + .stop = hcd_stop,
  95276. +
  95277. + .urb_enqueue = dwc_otg_urb_enqueue,
  95278. + .urb_dequeue = dwc_otg_urb_dequeue,
  95279. + .endpoint_disable = endpoint_disable,
  95280. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  95281. + .endpoint_reset = endpoint_reset,
  95282. +#endif
  95283. + .get_frame_number = get_frame_number,
  95284. +
  95285. + .hub_status_data = hub_status_data,
  95286. + .hub_control = hub_control,
  95287. + //.bus_suspend =
  95288. + //.bus_resume =
  95289. +};
  95290. +
  95291. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  95292. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  95293. +{
  95294. + struct wrapper_priv_data *p;
  95295. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  95296. + return p->dwc_otg_hcd;
  95297. +}
  95298. +
  95299. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  95300. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  95301. +{
  95302. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  95303. +}
  95304. +
  95305. +/** Gets the usb_host_endpoint associated with an URB. */
  95306. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  95307. +{
  95308. + struct usb_device *dev = urb->dev;
  95309. + int ep_num = usb_pipeendpoint(urb->pipe);
  95310. +
  95311. + if (usb_pipein(urb->pipe))
  95312. + return dev->ep_in[ep_num];
  95313. + else
  95314. + return dev->ep_out[ep_num];
  95315. +}
  95316. +
  95317. +static int _disconnect(dwc_otg_hcd_t * hcd)
  95318. +{
  95319. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  95320. +
  95321. + usb_hcd->self.is_b_host = 0;
  95322. + return 0;
  95323. +}
  95324. +
  95325. +static int _start(dwc_otg_hcd_t * hcd)
  95326. +{
  95327. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  95328. +
  95329. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  95330. + hcd_start(usb_hcd);
  95331. +
  95332. + return 0;
  95333. +}
  95334. +
  95335. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  95336. + uint32_t * port_addr)
  95337. +{
  95338. + struct urb *urb = (struct urb *)urb_handle;
  95339. + struct usb_bus *bus;
  95340. +#if 1 //GRAYG - temporary
  95341. + if (NULL == urb_handle)
  95342. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  95343. + if (NULL == urb->dev)
  95344. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  95345. + if (NULL == port_addr)
  95346. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  95347. +#endif
  95348. + if (urb->dev->tt) {
  95349. + if (NULL == urb->dev->tt->hub) {
  95350. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  95351. + __func__); //GRAYG
  95352. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  95353. + *hub_addr = 0; //GRAYG
  95354. + // we probably shouldn't have a transaction translator if
  95355. + // there's no associated hub?
  95356. + } else {
  95357. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  95358. + if (urb->dev->tt->hub == bus->root_hub)
  95359. + *hub_addr = 0;
  95360. + else
  95361. + *hub_addr = urb->dev->tt->hub->devnum;
  95362. + }
  95363. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  95364. + } else {
  95365. + *hub_addr = 0;
  95366. + *port_addr = urb->dev->ttport;
  95367. + }
  95368. + return 0;
  95369. +}
  95370. +
  95371. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  95372. +{
  95373. + struct urb *urb = (struct urb *)urb_handle;
  95374. + return urb->dev->speed;
  95375. +}
  95376. +
  95377. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  95378. +{
  95379. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  95380. + return usb_hcd->self.b_hnp_enable;
  95381. +}
  95382. +
  95383. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  95384. + struct urb *urb)
  95385. +{
  95386. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  95387. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95388. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  95389. + } else {
  95390. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  95391. + }
  95392. +}
  95393. +
  95394. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  95395. + struct urb *urb)
  95396. +{
  95397. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  95398. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95399. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  95400. + } else {
  95401. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  95402. + }
  95403. +}
  95404. +
  95405. +/**
  95406. + * Sets the final status of an URB and returns it to the device driver. Any
  95407. + * required cleanup of the URB is performed. The HCD lock should be held on
  95408. + * entry.
  95409. + */
  95410. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  95411. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  95412. +{
  95413. + struct urb *urb = (struct urb *)urb_handle;
  95414. + urb_tq_entry_t *new_entry;
  95415. + int rc = 0;
  95416. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95417. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  95418. + __func__, urb, usb_pipedevice(urb->pipe),
  95419. + usb_pipeendpoint(urb->pipe),
  95420. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  95421. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95422. + int i;
  95423. + for (i = 0; i < urb->number_of_packets; i++) {
  95424. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  95425. + i, urb->iso_frame_desc[i].status);
  95426. + }
  95427. + }
  95428. + }
  95429. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  95430. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  95431. + /* Convert status value. */
  95432. + switch (status) {
  95433. + case -DWC_E_PROTOCOL:
  95434. + status = -EPROTO;
  95435. + break;
  95436. + case -DWC_E_IN_PROGRESS:
  95437. + status = -EINPROGRESS;
  95438. + break;
  95439. + case -DWC_E_PIPE:
  95440. + status = -EPIPE;
  95441. + break;
  95442. + case -DWC_E_IO:
  95443. + status = -EIO;
  95444. + break;
  95445. + case -DWC_E_TIMEOUT:
  95446. + status = -ETIMEDOUT;
  95447. + break;
  95448. + case -DWC_E_OVERFLOW:
  95449. + status = -EOVERFLOW;
  95450. + break;
  95451. + case -DWC_E_SHUTDOWN:
  95452. + status = -ESHUTDOWN;
  95453. + break;
  95454. + default:
  95455. + if (status) {
  95456. + DWC_PRINTF("Uknown urb status %d\n", status);
  95457. +
  95458. + }
  95459. + }
  95460. +
  95461. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95462. + int i;
  95463. +
  95464. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  95465. + for (i = 0; i < urb->number_of_packets; ++i) {
  95466. + urb->iso_frame_desc[i].actual_length =
  95467. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  95468. + (dwc_otg_urb, i);
  95469. + urb->iso_frame_desc[i].status =
  95470. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  95471. + }
  95472. + }
  95473. +
  95474. + urb->status = status;
  95475. + urb->hcpriv = NULL;
  95476. + if (!status) {
  95477. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  95478. + (urb->actual_length < urb->transfer_buffer_length)) {
  95479. + urb->status = -EREMOTEIO;
  95480. + }
  95481. + }
  95482. +
  95483. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  95484. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  95485. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  95486. + if (ep) {
  95487. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  95488. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  95489. + ep->hcpriv),
  95490. + urb);
  95491. + }
  95492. + }
  95493. + DWC_FREE(dwc_otg_urb);
  95494. + if (!new_entry) {
  95495. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  95496. + urb->status = -EPROTO;
  95497. + /* don't schedule the tasklet -
  95498. + * directly return the packet here with error. */
  95499. +#if USB_URB_EP_LINKING
  95500. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  95501. +#endif
  95502. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95503. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  95504. +#else
  95505. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  95506. +#endif
  95507. + } else {
  95508. + new_entry->urb = urb;
  95509. +#if USB_URB_EP_LINKING
  95510. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  95511. + if(0 == rc) {
  95512. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  95513. + }
  95514. +#endif
  95515. + if(0 == rc) {
  95516. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  95517. + urb_tq_entries);
  95518. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  95519. + }
  95520. + }
  95521. + return 0;
  95522. +}
  95523. +
  95524. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  95525. + .start = _start,
  95526. + .disconnect = _disconnect,
  95527. + .hub_info = _hub_info,
  95528. + .speed = _speed,
  95529. + .complete = _complete,
  95530. + .get_b_hnp_enable = _get_b_hnp_enable,
  95531. +};
  95532. +
  95533. +static struct fiq_handler fh = {
  95534. + .name = "usb_fiq",
  95535. +};
  95536. +
  95537. +
  95538. +
  95539. +/**
  95540. + * Initializes the HCD. This function allocates memory for and initializes the
  95541. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  95542. + * USB bus with the core and calls the hc_driver->start() function. It returns
  95543. + * a negative error on failure.
  95544. + */
  95545. +int hcd_init(dwc_bus_dev_t *_dev)
  95546. +{
  95547. + struct usb_hcd *hcd = NULL;
  95548. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  95549. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  95550. + int retval = 0;
  95551. + u64 dmamask;
  95552. + struct pt_regs regs;
  95553. +
  95554. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  95555. +
  95556. + /* Set device flags indicating whether the HCD supports DMA. */
  95557. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  95558. + dmamask = DMA_BIT_MASK(32);
  95559. + else
  95560. + dmamask = 0;
  95561. +
  95562. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  95563. + dma_set_mask(&_dev->dev, dmamask);
  95564. + dma_set_coherent_mask(&_dev->dev, dmamask);
  95565. +#elif defined(PCI_INTERFACE)
  95566. + pci_set_dma_mask(_dev, dmamask);
  95567. + pci_set_consistent_dma_mask(_dev, dmamask);
  95568. +#endif
  95569. +
  95570. + /*
  95571. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  95572. + * Initialize the base HCD.
  95573. + */
  95574. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  95575. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  95576. +#else
  95577. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  95578. + hcd->has_tt = 1;
  95579. +// hcd->uses_new_polling = 1;
  95580. +// hcd->poll_rh = 0;
  95581. +#endif
  95582. + if (!hcd) {
  95583. + retval = -ENOMEM;
  95584. + goto error1;
  95585. + }
  95586. +
  95587. + hcd->regs = otg_dev->os_dep.base;
  95588. +
  95589. +
  95590. + /* Initialize the DWC OTG HCD. */
  95591. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  95592. + if (!dwc_otg_hcd) {
  95593. + goto error2;
  95594. + }
  95595. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  95596. + dwc_otg_hcd;
  95597. + otg_dev->hcd = dwc_otg_hcd;
  95598. +
  95599. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  95600. + goto error2;
  95601. + }
  95602. +
  95603. + if (fiq_enable)
  95604. + {
  95605. + if (claim_fiq(&fh)) {
  95606. + DWC_ERROR("Can't claim FIQ");
  95607. + goto error2;
  95608. + }
  95609. +
  95610. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  95611. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  95612. +
  95613. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  95614. + memset(&regs,0,sizeof(regs));
  95615. +
  95616. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  95617. + if (fiq_fsm_enable) {
  95618. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  95619. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  95620. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  95621. + } else {
  95622. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  95623. + }
  95624. +
  95625. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  95626. +
  95627. +// __show_regs(&regs);
  95628. + set_fiq_regs(&regs);
  95629. +
  95630. + //Set the mphi periph to the required registers
  95631. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  95632. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  95633. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  95634. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  95635. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  95636. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  95637. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  95638. + //Enable mphi peripheral
  95639. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  95640. +#ifdef DEBUG
  95641. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  95642. + DWC_WARN("MPHI periph has been enabled");
  95643. + else
  95644. + DWC_WARN("MPHI periph has NOT been enabled");
  95645. +#endif
  95646. + // Enable FIQ interrupt from USB peripheral
  95647. + enable_fiq(INTERRUPT_VC_USB);
  95648. + local_fiq_enable();
  95649. + }
  95650. +
  95651. +
  95652. + otg_dev->hcd->otg_dev = otg_dev;
  95653. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  95654. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  95655. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  95656. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  95657. +#endif
  95658. + /* Don't support SG list at this point */
  95659. + hcd->self.sg_tablesize = 0;
  95660. +#endif
  95661. + /*
  95662. + * Finish generic HCD initialization and start the HCD. This function
  95663. + * allocates the DMA buffer pool, registers the USB bus, requests the
  95664. + * IRQ line, and calls hcd_start method.
  95665. + */
  95666. +#ifdef PLATFORM_INTERFACE
  95667. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  95668. +#else
  95669. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  95670. +#endif
  95671. + if (retval < 0) {
  95672. + goto error2;
  95673. + }
  95674. +
  95675. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  95676. + return 0;
  95677. +
  95678. +error2:
  95679. + usb_put_hcd(hcd);
  95680. +error1:
  95681. + return retval;
  95682. +}
  95683. +
  95684. +/**
  95685. + * Removes the HCD.
  95686. + * Frees memory and resources associated with the HCD and deregisters the bus.
  95687. + */
  95688. +void hcd_remove(dwc_bus_dev_t *_dev)
  95689. +{
  95690. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  95691. + dwc_otg_hcd_t *dwc_otg_hcd;
  95692. + struct usb_hcd *hcd;
  95693. +
  95694. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  95695. +
  95696. + if (!otg_dev) {
  95697. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  95698. + return;
  95699. + }
  95700. +
  95701. + dwc_otg_hcd = otg_dev->hcd;
  95702. +
  95703. + if (!dwc_otg_hcd) {
  95704. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  95705. + return;
  95706. + }
  95707. +
  95708. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  95709. +
  95710. + if (!hcd) {
  95711. + DWC_DEBUGPL(DBG_ANY,
  95712. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  95713. + __func__);
  95714. + return;
  95715. + }
  95716. + usb_remove_hcd(hcd);
  95717. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  95718. + dwc_otg_hcd_remove(dwc_otg_hcd);
  95719. + usb_put_hcd(hcd);
  95720. +}
  95721. +
  95722. +/* =========================================================================
  95723. + * Linux HC Driver Functions
  95724. + * ========================================================================= */
  95725. +
  95726. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  95727. + * mode operation. Activates the root port. Returns 0 on success and a negative
  95728. + * error code on failure. */
  95729. +int hcd_start(struct usb_hcd *hcd)
  95730. +{
  95731. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95732. + struct usb_bus *bus;
  95733. +
  95734. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  95735. + bus = hcd_to_bus(hcd);
  95736. +
  95737. + hcd->state = HC_STATE_RUNNING;
  95738. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  95739. + return 0;
  95740. + }
  95741. +
  95742. + /* Initialize and connect root hub if one is not already attached */
  95743. + if (bus->root_hub) {
  95744. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  95745. + /* Inform the HUB driver to resume. */
  95746. + usb_hcd_resume_root_hub(hcd);
  95747. + }
  95748. +
  95749. + return 0;
  95750. +}
  95751. +
  95752. +/**
  95753. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  95754. + * stopped.
  95755. + */
  95756. +void hcd_stop(struct usb_hcd *hcd)
  95757. +{
  95758. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95759. +
  95760. + dwc_otg_hcd_stop(dwc_otg_hcd);
  95761. +}
  95762. +
  95763. +/** Returns the current frame number. */
  95764. +static int get_frame_number(struct usb_hcd *hcd)
  95765. +{
  95766. + hprt0_data_t hprt0;
  95767. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95768. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  95769. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  95770. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  95771. + else
  95772. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  95773. +}
  95774. +
  95775. +#ifdef DEBUG
  95776. +static void dump_urb_info(struct urb *urb, char *fn_name)
  95777. +{
  95778. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  95779. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  95780. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  95781. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  95782. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  95783. + char *pipetype;
  95784. + switch (usb_pipetype(urb->pipe)) {
  95785. +case PIPE_CONTROL:
  95786. +pipetype = "CONTROL"; break; case PIPE_BULK:
  95787. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  95788. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  95789. +pipetype = "ISOCHRONOUS"; break; default:
  95790. + pipetype = "UNKNOWN"; break;};
  95791. + pipetype;}
  95792. + )) ;
  95793. + DWC_PRINTF(" Speed: %s\n", ( {
  95794. + char *speed; switch (urb->dev->speed) {
  95795. +case USB_SPEED_HIGH:
  95796. +speed = "HIGH"; break; case USB_SPEED_FULL:
  95797. +speed = "FULL"; break; case USB_SPEED_LOW:
  95798. +speed = "LOW"; break; default:
  95799. + speed = "UNKNOWN"; break;};
  95800. + speed;}
  95801. + )) ;
  95802. + DWC_PRINTF(" Max packet size: %d\n",
  95803. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  95804. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  95805. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  95806. + urb->transfer_buffer, (void *)urb->transfer_dma);
  95807. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  95808. + urb->setup_packet, (void *)urb->setup_dma);
  95809. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  95810. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  95811. + int i;
  95812. + for (i = 0; i < urb->number_of_packets; i++) {
  95813. + DWC_PRINTF(" ISO Desc %d:\n", i);
  95814. + DWC_PRINTF(" offset: %d, length %d\n",
  95815. + urb->iso_frame_desc[i].offset,
  95816. + urb->iso_frame_desc[i].length);
  95817. + }
  95818. + }
  95819. +}
  95820. +#endif
  95821. +
  95822. +/** Starts processing a USB transfer request specified by a USB Request Block
  95823. + * (URB). mem_flags indicates the type of memory allocation to use while
  95824. + * processing this URB. */
  95825. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  95826. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95827. + struct usb_host_endpoint *ep,
  95828. +#endif
  95829. + struct urb *urb, gfp_t mem_flags)
  95830. +{
  95831. + int retval = 0;
  95832. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  95833. + struct usb_host_endpoint *ep = urb->ep;
  95834. +#endif
  95835. + dwc_irqflags_t irqflags;
  95836. + void **ref_ep_hcpriv = &ep->hcpriv;
  95837. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95838. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  95839. + int i;
  95840. + int alloc_bandwidth = 0;
  95841. + uint8_t ep_type = 0;
  95842. + uint32_t flags = 0;
  95843. + void *buf;
  95844. +
  95845. +#ifdef DEBUG
  95846. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95847. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  95848. + }
  95849. +#endif
  95850. +
  95851. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  95852. + return -EINVAL;
  95853. +
  95854. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  95855. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  95856. + if (!dwc_otg_hcd_is_bandwidth_allocated
  95857. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  95858. + alloc_bandwidth = 1;
  95859. + }
  95860. + }
  95861. +
  95862. + switch (usb_pipetype(urb->pipe)) {
  95863. + case PIPE_CONTROL:
  95864. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  95865. + break;
  95866. + case PIPE_ISOCHRONOUS:
  95867. + ep_type = USB_ENDPOINT_XFER_ISOC;
  95868. + break;
  95869. + case PIPE_BULK:
  95870. + ep_type = USB_ENDPOINT_XFER_BULK;
  95871. + break;
  95872. + case PIPE_INTERRUPT:
  95873. + ep_type = USB_ENDPOINT_XFER_INT;
  95874. + break;
  95875. + default:
  95876. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  95877. + }
  95878. +
  95879. + /* # of packets is often 0 - do we really need to call this then? */
  95880. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  95881. + urb->number_of_packets,
  95882. + mem_flags == GFP_ATOMIC ? 1 : 0);
  95883. +
  95884. + if(dwc_otg_urb == NULL)
  95885. + return -ENOMEM;
  95886. +
  95887. + if (!dwc_otg_urb && urb->number_of_packets)
  95888. + return -ENOMEM;
  95889. +
  95890. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  95891. + usb_pipeendpoint(urb->pipe), ep_type,
  95892. + usb_pipein(urb->pipe),
  95893. + usb_maxpacket(urb->dev, urb->pipe,
  95894. + !(usb_pipein(urb->pipe))));
  95895. +
  95896. + buf = urb->transfer_buffer;
  95897. + if (hcd->self.uses_dma) {
  95898. + /*
  95899. + * Calculate virtual address from physical address,
  95900. + * because some class driver may not fill transfer_buffer.
  95901. + * In Buffer DMA mode virual address is used,
  95902. + * when handling non DWORD aligned buffers.
  95903. + */
  95904. + //buf = phys_to_virt(urb->transfer_dma);
  95905. + // DMA addresses are bus addresses not physical addresses!
  95906. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  95907. + }
  95908. +
  95909. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  95910. + flags |= URB_GIVEBACK_ASAP;
  95911. + if (urb->transfer_flags & URB_ZERO_PACKET)
  95912. + flags |= URB_SEND_ZERO_PACKET;
  95913. +
  95914. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  95915. + urb->transfer_dma,
  95916. + urb->transfer_buffer_length,
  95917. + urb->setup_packet,
  95918. + urb->setup_dma, flags, urb->interval);
  95919. +
  95920. + for (i = 0; i < urb->number_of_packets; ++i) {
  95921. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  95922. + urb->
  95923. + iso_frame_desc[i].offset,
  95924. + urb->
  95925. + iso_frame_desc[i].length);
  95926. + }
  95927. +
  95928. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  95929. + urb->hcpriv = dwc_otg_urb;
  95930. +#if USB_URB_EP_LINKING
  95931. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  95932. + if (0 == retval)
  95933. +#endif
  95934. + {
  95935. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  95936. + /*(dwc_otg_qh_t **)*/
  95937. + ref_ep_hcpriv, 1);
  95938. + if (0 == retval) {
  95939. + if (alloc_bandwidth) {
  95940. + allocate_bus_bandwidth(hcd,
  95941. + dwc_otg_hcd_get_ep_bandwidth(
  95942. + dwc_otg_hcd, *ref_ep_hcpriv),
  95943. + urb);
  95944. + }
  95945. + } else {
  95946. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  95947. +#if USB_URB_EP_LINKING
  95948. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  95949. +#endif
  95950. + DWC_FREE(dwc_otg_urb);
  95951. + urb->hcpriv = NULL;
  95952. + if (retval == -DWC_E_NO_DEVICE)
  95953. + retval = -ENODEV;
  95954. + }
  95955. + }
  95956. +#if USB_URB_EP_LINKING
  95957. + else
  95958. + {
  95959. + DWC_FREE(dwc_otg_urb);
  95960. + urb->hcpriv = NULL;
  95961. + }
  95962. +#endif
  95963. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  95964. + return retval;
  95965. +}
  95966. +
  95967. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  95968. + * success. */
  95969. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  95970. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  95971. +#else
  95972. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  95973. +#endif
  95974. +{
  95975. + dwc_irqflags_t flags;
  95976. + dwc_otg_hcd_t *dwc_otg_hcd;
  95977. + int rc;
  95978. +
  95979. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  95980. +
  95981. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  95982. +
  95983. +#ifdef DEBUG
  95984. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  95985. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  95986. + }
  95987. +#endif
  95988. +
  95989. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  95990. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  95991. + if (0 == rc) {
  95992. + if(urb->hcpriv != NULL) {
  95993. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  95994. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  95995. +
  95996. + DWC_FREE(urb->hcpriv);
  95997. + urb->hcpriv = NULL;
  95998. + }
  95999. + }
  96000. +
  96001. + if (0 == rc) {
  96002. + /* Higher layer software sets URB status. */
  96003. +#if USB_URB_EP_LINKING
  96004. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  96005. +#endif
  96006. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  96007. +
  96008. +
  96009. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  96010. + usb_hcd_giveback_urb(hcd, urb);
  96011. +#else
  96012. + usb_hcd_giveback_urb(hcd, urb, status);
  96013. +#endif
  96014. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  96015. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  96016. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  96017. + }
  96018. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  96019. + } else {
  96020. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  96021. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  96022. + rc);
  96023. + }
  96024. +
  96025. + return rc;
  96026. +}
  96027. +
  96028. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  96029. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  96030. + * must already be dequeued. */
  96031. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  96032. +{
  96033. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  96034. +
  96035. + DWC_DEBUGPL(DBG_HCD,
  96036. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  96037. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  96038. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  96039. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  96040. + ep->hcpriv = NULL;
  96041. +}
  96042. +
  96043. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  96044. +/* Resets endpoint specific parameter values, in current version used to reset
  96045. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  96046. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  96047. +{
  96048. + dwc_irqflags_t flags;
  96049. + struct usb_device *udev = NULL;
  96050. + int epnum = usb_endpoint_num(&ep->desc);
  96051. + int is_out = usb_endpoint_dir_out(&ep->desc);
  96052. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  96053. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  96054. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  96055. +
  96056. + if (dev)
  96057. + udev = to_usb_device(dev);
  96058. + else
  96059. + return;
  96060. +
  96061. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  96062. +
  96063. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  96064. + usb_settoggle(udev, epnum, is_out, 0);
  96065. + if (is_control)
  96066. + usb_settoggle(udev, epnum, !is_out, 0);
  96067. +
  96068. + if (ep->hcpriv) {
  96069. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  96070. + }
  96071. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  96072. +}
  96073. +#endif
  96074. +
  96075. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  96076. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  96077. + * interrupt.
  96078. + *
  96079. + * This function is called by the USB core when an interrupt occurs */
  96080. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  96081. +{
  96082. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  96083. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  96084. + if (retval != 0) {
  96085. + S3C2410X_CLEAR_EINTPEND();
  96086. + }
  96087. + return IRQ_RETVAL(retval);
  96088. +}
  96089. +
  96090. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  96091. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  96092. + * is the status change indicator for the single root port. Returns 1 if either
  96093. + * change indicator is 1, otherwise returns 0. */
  96094. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  96095. +{
  96096. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  96097. +
  96098. + buf[0] = 0;
  96099. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  96100. +
  96101. + return (buf[0] != 0);
  96102. +}
  96103. +
  96104. +/** Handles hub class-specific requests. */
  96105. +int hub_control(struct usb_hcd *hcd,
  96106. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  96107. +{
  96108. + int retval;
  96109. +
  96110. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  96111. + typeReq, wValue, wIndex, buf, wLength);
  96112. +
  96113. + switch (retval) {
  96114. + case -DWC_E_INVALID:
  96115. + retval = -EINVAL;
  96116. + break;
  96117. + }
  96118. +
  96119. + return retval;
  96120. +}
  96121. +
  96122. +#endif /* DWC_DEVICE_ONLY */
  96123. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  96124. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  96125. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2015-03-10 17:26:51.306216687 +0100
  96126. @@ -0,0 +1,942 @@
  96127. +/* ==========================================================================
  96128. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  96129. + * $Revision: #44 $
  96130. + * $Date: 2011/10/26 $
  96131. + * $Change: 1873028 $
  96132. + *
  96133. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  96134. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  96135. + * otherwise expressly agreed to in writing between Synopsys and you.
  96136. + *
  96137. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  96138. + * any End User Software License Agreement or Agreement for Licensed Product
  96139. + * with Synopsys or any supplement thereto. You are permitted to use and
  96140. + * redistribute this Software in source and binary forms, with or without
  96141. + * modification, provided that redistributions of source code must retain this
  96142. + * notice. You may not view, use, disclose, copy or distribute this file or
  96143. + * any information contained herein except pursuant to this license grant from
  96144. + * Synopsys. If you do not agree with this notice, including the disclaimer
  96145. + * below, then you are not authorized to use the Software.
  96146. + *
  96147. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  96148. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  96149. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  96150. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  96151. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  96152. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  96153. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  96154. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  96155. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  96156. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  96157. + * DAMAGE.
  96158. + * ========================================================================== */
  96159. +#ifndef DWC_DEVICE_ONLY
  96160. +
  96161. +/**
  96162. + * @file
  96163. + *
  96164. + * This file contains the functions to manage Queue Heads and Queue
  96165. + * Transfer Descriptors.
  96166. + */
  96167. +
  96168. +#include "dwc_otg_hcd.h"
  96169. +#include "dwc_otg_regs.h"
  96170. +
  96171. +extern bool microframe_schedule;
  96172. +
  96173. +/**
  96174. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  96175. + * removed from a list. QTD list should already be empty if called from URB
  96176. + * Dequeue.
  96177. + *
  96178. + * @param hcd HCD instance.
  96179. + * @param qh The QH to free.
  96180. + */
  96181. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96182. +{
  96183. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  96184. +
  96185. + /* Free each QTD in the QTD list */
  96186. + DWC_SPINLOCK(hcd->lock);
  96187. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  96188. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  96189. + dwc_otg_hcd_qtd_free(qtd);
  96190. + }
  96191. +
  96192. + if (hcd->core_if->dma_desc_enable) {
  96193. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  96194. + } else if (qh->dw_align_buf) {
  96195. + uint32_t buf_size;
  96196. + if (qh->ep_type == UE_ISOCHRONOUS) {
  96197. + buf_size = 4096;
  96198. + } else {
  96199. + buf_size = hcd->core_if->core_params->max_transfer_size;
  96200. + }
  96201. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  96202. + }
  96203. +
  96204. + DWC_FREE(qh);
  96205. + DWC_SPINUNLOCK(hcd->lock);
  96206. + return;
  96207. +}
  96208. +
  96209. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  96210. +#define HS_HOST_DELAY 5 /* nanoseconds */
  96211. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  96212. +#define HUB_LS_SETUP 333 /* nanoseconds */
  96213. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  96214. + /* convert & round nanoseconds to microseconds */
  96215. +
  96216. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  96217. +{
  96218. + unsigned long retval;
  96219. +
  96220. + switch (speed) {
  96221. + case USB_SPEED_HIGH:
  96222. + if (is_isoc) {
  96223. + retval =
  96224. + ((38 * 8 * 2083) +
  96225. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  96226. + HS_HOST_DELAY;
  96227. + } else {
  96228. + retval =
  96229. + ((55 * 8 * 2083) +
  96230. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  96231. + HS_HOST_DELAY;
  96232. + }
  96233. + break;
  96234. + case USB_SPEED_FULL:
  96235. + if (is_isoc) {
  96236. + retval =
  96237. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  96238. + if (is_in) {
  96239. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  96240. + } else {
  96241. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  96242. + }
  96243. + } else {
  96244. + retval =
  96245. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  96246. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  96247. + }
  96248. + break;
  96249. + case USB_SPEED_LOW:
  96250. + if (is_in) {
  96251. + retval =
  96252. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  96253. + 1000;
  96254. + retval =
  96255. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  96256. + retval;
  96257. + } else {
  96258. + retval =
  96259. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  96260. + 1000;
  96261. + retval =
  96262. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  96263. + retval;
  96264. + }
  96265. + break;
  96266. + default:
  96267. + DWC_WARN("Unknown device speed\n");
  96268. + retval = -1;
  96269. + }
  96270. +
  96271. + return NS_TO_US(retval);
  96272. +}
  96273. +
  96274. +/**
  96275. + * Initializes a QH structure.
  96276. + *
  96277. + * @param hcd The HCD state structure for the DWC OTG controller.
  96278. + * @param qh The QH to init.
  96279. + * @param urb Holds the information about the device/endpoint that we need
  96280. + * to initialize the QH.
  96281. + */
  96282. +#define SCHEDULE_SLOP 10
  96283. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  96284. +{
  96285. + char *speed, *type;
  96286. + int dev_speed;
  96287. + uint32_t hub_addr, hub_port;
  96288. +
  96289. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  96290. +
  96291. + /* Initialize QH */
  96292. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  96293. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  96294. +
  96295. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  96296. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  96297. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  96298. + DWC_LIST_INIT(&qh->qh_list_entry);
  96299. + qh->channel = NULL;
  96300. +
  96301. + /* FS/LS Enpoint on HS Hub
  96302. + * NOT virtual root hub */
  96303. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  96304. +
  96305. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  96306. + qh->do_split = 0;
  96307. + if (microframe_schedule)
  96308. + qh->speed = dev_speed;
  96309. +
  96310. + qh->nak_frame = 0xffff;
  96311. +
  96312. + if (((dev_speed == USB_SPEED_LOW) ||
  96313. + (dev_speed == USB_SPEED_FULL)) &&
  96314. + (hub_addr != 0 && hub_addr != 1)) {
  96315. + DWC_DEBUGPL(DBG_HCD,
  96316. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  96317. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  96318. + hub_port);
  96319. + qh->do_split = 1;
  96320. + qh->skip_count = 0;
  96321. + }
  96322. +
  96323. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  96324. + /* Compute scheduling parameters once and save them. */
  96325. + hprt0_data_t hprt;
  96326. +
  96327. + /** @todo Account for split transfers in the bus time. */
  96328. + int bytecount =
  96329. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  96330. +
  96331. + qh->usecs =
  96332. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  96333. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  96334. + bytecount);
  96335. + /* Start in a slightly future (micro)frame. */
  96336. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  96337. + SCHEDULE_SLOP);
  96338. + qh->interval = urb->interval;
  96339. +
  96340. +#if 0
  96341. + /* Increase interrupt polling rate for debugging. */
  96342. + if (qh->ep_type == UE_INTERRUPT) {
  96343. + qh->interval = 8;
  96344. + }
  96345. +#endif
  96346. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  96347. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  96348. + ((dev_speed == USB_SPEED_LOW) ||
  96349. + (dev_speed == USB_SPEED_FULL))) {
  96350. + qh->interval *= 8;
  96351. + qh->sched_frame |= 0x7;
  96352. + qh->start_split_frame = qh->sched_frame;
  96353. + }
  96354. +
  96355. + }
  96356. +
  96357. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  96358. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  96359. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  96360. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  96361. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  96362. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  96363. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  96364. + switch (dev_speed) {
  96365. + case USB_SPEED_LOW:
  96366. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  96367. + speed = "low";
  96368. + break;
  96369. + case USB_SPEED_FULL:
  96370. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  96371. + speed = "full";
  96372. + break;
  96373. + case USB_SPEED_HIGH:
  96374. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  96375. + speed = "high";
  96376. + break;
  96377. + default:
  96378. + speed = "?";
  96379. + break;
  96380. + }
  96381. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  96382. +
  96383. + switch (qh->ep_type) {
  96384. + case UE_ISOCHRONOUS:
  96385. + type = "isochronous";
  96386. + break;
  96387. + case UE_INTERRUPT:
  96388. + type = "interrupt";
  96389. + break;
  96390. + case UE_CONTROL:
  96391. + type = "control";
  96392. + break;
  96393. + case UE_BULK:
  96394. + type = "bulk";
  96395. + break;
  96396. + default:
  96397. + type = "?";
  96398. + break;
  96399. + }
  96400. +
  96401. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  96402. +
  96403. +#ifdef DEBUG
  96404. + if (qh->ep_type == UE_INTERRUPT) {
  96405. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  96406. + qh->usecs);
  96407. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  96408. + qh->interval);
  96409. + }
  96410. +#endif
  96411. +
  96412. +}
  96413. +
  96414. +/**
  96415. + * This function allocates and initializes a QH.
  96416. + *
  96417. + * @param hcd The HCD state structure for the DWC OTG controller.
  96418. + * @param urb Holds the information about the device/endpoint that we need
  96419. + * to initialize the QH.
  96420. + * @param atomic_alloc Flag to do atomic allocation if needed
  96421. + *
  96422. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  96423. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  96424. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  96425. +{
  96426. + dwc_otg_qh_t *qh;
  96427. +
  96428. + /* Allocate memory */
  96429. + /** @todo add memflags argument */
  96430. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  96431. + if (qh == NULL) {
  96432. + DWC_ERROR("qh allocation failed");
  96433. + return NULL;
  96434. + }
  96435. +
  96436. + qh_init(hcd, qh, urb);
  96437. +
  96438. + if (hcd->core_if->dma_desc_enable
  96439. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  96440. + dwc_otg_hcd_qh_free(hcd, qh);
  96441. + return NULL;
  96442. + }
  96443. +
  96444. + return qh;
  96445. +}
  96446. +
  96447. +/* microframe_schedule=0 start */
  96448. +
  96449. +/**
  96450. + * Checks that a channel is available for a periodic transfer.
  96451. + *
  96452. + * @return 0 if successful, negative error code otherise.
  96453. + */
  96454. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  96455. +{
  96456. + /*
  96457. + * Currently assuming that there is a dedicated host channnel for each
  96458. + * periodic transaction plus at least one host channel for
  96459. + * non-periodic transactions.
  96460. + */
  96461. + int status;
  96462. + int num_channels;
  96463. +
  96464. + num_channels = hcd->core_if->core_params->host_channels;
  96465. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  96466. + && (hcd->periodic_channels < num_channels - 1)) {
  96467. + status = 0;
  96468. + } else {
  96469. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  96470. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  96471. + status = -DWC_E_NO_SPACE;
  96472. + }
  96473. +
  96474. + return status;
  96475. +}
  96476. +
  96477. +/**
  96478. + * Checks that there is sufficient bandwidth for the specified QH in the
  96479. + * periodic schedule. For simplicity, this calculation assumes that all the
  96480. + * transfers in the periodic schedule may occur in the same (micro)frame.
  96481. + *
  96482. + * @param hcd The HCD state structure for the DWC OTG controller.
  96483. + * @param qh QH containing periodic bandwidth required.
  96484. + *
  96485. + * @return 0 if successful, negative error code otherwise.
  96486. + */
  96487. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96488. +{
  96489. + int status;
  96490. + int16_t max_claimed_usecs;
  96491. +
  96492. + status = 0;
  96493. +
  96494. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  96495. + /*
  96496. + * High speed mode.
  96497. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  96498. + */
  96499. +
  96500. + max_claimed_usecs = 100 - qh->usecs;
  96501. + } else {
  96502. + /*
  96503. + * Full speed mode.
  96504. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  96505. + */
  96506. + max_claimed_usecs = 900 - qh->usecs;
  96507. + }
  96508. +
  96509. + if (hcd->periodic_usecs > max_claimed_usecs) {
  96510. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  96511. + status = -DWC_E_NO_SPACE;
  96512. + }
  96513. +
  96514. + return status;
  96515. +}
  96516. +
  96517. +/* microframe_schedule=0 end */
  96518. +
  96519. +/**
  96520. + * Microframe scheduler
  96521. + * track the total use in hcd->frame_usecs
  96522. + * keep each qh use in qh->frame_usecs
  96523. + * when surrendering the qh then donate the time back
  96524. + */
  96525. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  96526. +
  96527. +/*
  96528. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  96529. + */
  96530. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  96531. +{
  96532. + int i;
  96533. + for (i=0; i<8; i++) {
  96534. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  96535. + }
  96536. + return 0;
  96537. +}
  96538. +
  96539. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96540. +{
  96541. + int i;
  96542. + unsigned short utime;
  96543. + int t_left;
  96544. + int ret;
  96545. + int done;
  96546. +
  96547. + ret = -1;
  96548. + utime = _qh->usecs;
  96549. + t_left = utime;
  96550. + i = 0;
  96551. + done = 0;
  96552. + while (done == 0) {
  96553. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  96554. + if (utime <= _hcd->frame_usecs[i]) {
  96555. + _hcd->frame_usecs[i] -= utime;
  96556. + _qh->frame_usecs[i] += utime;
  96557. + t_left -= utime;
  96558. + ret = i;
  96559. + done = 1;
  96560. + return ret;
  96561. + } else {
  96562. + i++;
  96563. + if (i == 8) {
  96564. + done = 1;
  96565. + ret = -1;
  96566. + }
  96567. + }
  96568. + }
  96569. + return ret;
  96570. + }
  96571. +
  96572. +/*
  96573. + * use this for FS apps that can span multiple uframes
  96574. + */
  96575. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96576. +{
  96577. + int i;
  96578. + int j;
  96579. + unsigned short utime;
  96580. + int t_left;
  96581. + int ret;
  96582. + int done;
  96583. + unsigned short xtime;
  96584. +
  96585. + ret = -1;
  96586. + utime = _qh->usecs;
  96587. + t_left = utime;
  96588. + i = 0;
  96589. + done = 0;
  96590. +loop:
  96591. + while (done == 0) {
  96592. + if(_hcd->frame_usecs[i] <= 0) {
  96593. + i++;
  96594. + if (i == 8) {
  96595. + done = 1;
  96596. + ret = -1;
  96597. + }
  96598. + goto loop;
  96599. + }
  96600. +
  96601. + /*
  96602. + * we need n consecutive slots
  96603. + * so use j as a start slot j plus j+1 must be enough time (for now)
  96604. + */
  96605. + xtime= _hcd->frame_usecs[i];
  96606. + for (j = i+1 ; j < 8 ; j++ ) {
  96607. + /*
  96608. + * if we add this frame remaining time to xtime we may
  96609. + * be OK, if not we need to test j for a complete frame
  96610. + */
  96611. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  96612. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  96613. + j = 8;
  96614. + ret = -1;
  96615. + continue;
  96616. + }
  96617. + }
  96618. + if (xtime >= utime) {
  96619. + ret = i;
  96620. + j = 8; /* stop loop with a good value ret */
  96621. + continue;
  96622. + }
  96623. + /* add the frame time to x time */
  96624. + xtime += _hcd->frame_usecs[j];
  96625. + /* we must have a fully available next frame or break */
  96626. + if ((xtime < utime)
  96627. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  96628. + ret = -1;
  96629. + j = 8; /* stop loop with a bad value ret */
  96630. + continue;
  96631. + }
  96632. + }
  96633. + if (ret >= 0) {
  96634. + t_left = utime;
  96635. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  96636. + t_left -= _hcd->frame_usecs[j];
  96637. + if ( t_left <= 0 ) {
  96638. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  96639. + _hcd->frame_usecs[j]= -t_left;
  96640. + ret = i;
  96641. + done = 1;
  96642. + } else {
  96643. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  96644. + _hcd->frame_usecs[j] = 0;
  96645. + }
  96646. + }
  96647. + } else {
  96648. + i++;
  96649. + if (i == 8) {
  96650. + done = 1;
  96651. + ret = -1;
  96652. + }
  96653. + }
  96654. + }
  96655. + return ret;
  96656. +}
  96657. +
  96658. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  96659. +{
  96660. + int ret;
  96661. + ret = -1;
  96662. +
  96663. + if (_qh->speed == USB_SPEED_HIGH) {
  96664. + /* if this is a hs transaction we need a full frame */
  96665. + ret = find_single_uframe(_hcd, _qh);
  96666. + } else {
  96667. + /* if this is a fs transaction we may need a sequence of frames */
  96668. + ret = find_multi_uframe(_hcd, _qh);
  96669. + }
  96670. + return ret;
  96671. +}
  96672. +
  96673. +/**
  96674. + * Checks that the max transfer size allowed in a host channel is large enough
  96675. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  96676. + * transfer.
  96677. + *
  96678. + * @param hcd The HCD state structure for the DWC OTG controller.
  96679. + * @param qh QH for a periodic endpoint.
  96680. + *
  96681. + * @return 0 if successful, negative error code otherwise.
  96682. + */
  96683. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96684. +{
  96685. + int status;
  96686. + uint32_t max_xfer_size;
  96687. + uint32_t max_channel_xfer_size;
  96688. +
  96689. + status = 0;
  96690. +
  96691. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  96692. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  96693. +
  96694. + if (max_xfer_size > max_channel_xfer_size) {
  96695. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  96696. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  96697. + status = -DWC_E_NO_SPACE;
  96698. + }
  96699. +
  96700. + return status;
  96701. +}
  96702. +
  96703. +
  96704. +
  96705. +/**
  96706. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  96707. + *
  96708. + * @param hcd The HCD state structure for the DWC OTG controller.
  96709. + * @param qh QH for the periodic transfer. The QH should already contain the
  96710. + * scheduling information.
  96711. + *
  96712. + * @return 0 if successful, negative error code otherwise.
  96713. + */
  96714. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96715. +{
  96716. + int status = 0;
  96717. +
  96718. + if (microframe_schedule) {
  96719. + int frame;
  96720. + status = find_uframe(hcd, qh);
  96721. + frame = -1;
  96722. + if (status == 0) {
  96723. + frame = 7;
  96724. + } else {
  96725. + if (status > 0 )
  96726. + frame = status-1;
  96727. + }
  96728. +
  96729. + /* Set the new frame up */
  96730. + if (frame > -1) {
  96731. + qh->sched_frame &= ~0x7;
  96732. + qh->sched_frame |= (frame & 7);
  96733. + }
  96734. +
  96735. + if (status != -1)
  96736. + status = 0;
  96737. + } else {
  96738. + status = periodic_channel_available(hcd);
  96739. + if (status) {
  96740. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  96741. + return status;
  96742. + }
  96743. +
  96744. + status = check_periodic_bandwidth(hcd, qh);
  96745. + }
  96746. + if (status) {
  96747. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  96748. + "periodic transfer.\n", __func__);
  96749. + return status;
  96750. + }
  96751. + status = check_max_xfer_size(hcd, qh);
  96752. + if (status) {
  96753. + DWC_INFO("%s: Channel max transfer size too small "
  96754. + "for periodic transfer.\n", __func__);
  96755. + return status;
  96756. + }
  96757. +
  96758. + if (hcd->core_if->dma_desc_enable) {
  96759. + /* Don't rely on SOF and start in ready schedule */
  96760. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  96761. + }
  96762. + else {
  96763. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  96764. + {
  96765. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  96766. +
  96767. + }
  96768. + /* Always start in the inactive schedule. */
  96769. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  96770. + }
  96771. +
  96772. + if (!microframe_schedule) {
  96773. + /* Reserve the periodic channel. */
  96774. + hcd->periodic_channels++;
  96775. + }
  96776. +
  96777. + /* Update claimed usecs per (micro)frame. */
  96778. + hcd->periodic_usecs += qh->usecs;
  96779. +
  96780. + return status;
  96781. +}
  96782. +
  96783. +
  96784. +/**
  96785. + * This function adds a QH to either the non periodic or periodic schedule if
  96786. + * it is not already in the schedule. If the QH is already in the schedule, no
  96787. + * action is taken.
  96788. + *
  96789. + * @return 0 if successful, negative error code otherwise.
  96790. + */
  96791. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96792. +{
  96793. + int status = 0;
  96794. + gintmsk_data_t intr_mask = {.d32 = 0 };
  96795. +
  96796. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  96797. + /* QH already in a schedule. */
  96798. + return status;
  96799. + }
  96800. +
  96801. + /* Add the new QH to the appropriate schedule */
  96802. + if (dwc_qh_is_non_per(qh)) {
  96803. + /* Always start in the inactive schedule. */
  96804. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  96805. + &qh->qh_list_entry);
  96806. + //hcd->fiq_state->kick_np_queues = 1;
  96807. + } else {
  96808. + status = schedule_periodic(hcd, qh);
  96809. + if ( !hcd->periodic_qh_count ) {
  96810. + intr_mask.b.sofintr = 1;
  96811. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  96812. + intr_mask.d32, intr_mask.d32);
  96813. + }
  96814. + hcd->periodic_qh_count++;
  96815. + }
  96816. +
  96817. + return status;
  96818. +}
  96819. +
  96820. +/**
  96821. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  96822. + *
  96823. + * @param hcd The HCD state structure for the DWC OTG controller.
  96824. + * @param qh QH for the periodic transfer.
  96825. + */
  96826. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96827. +{
  96828. + int i;
  96829. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  96830. +
  96831. + /* Update claimed usecs per (micro)frame. */
  96832. + hcd->periodic_usecs -= qh->usecs;
  96833. +
  96834. + if (!microframe_schedule) {
  96835. + /* Release the periodic channel reservation. */
  96836. + hcd->periodic_channels--;
  96837. + } else {
  96838. + for (i = 0; i < 8; i++) {
  96839. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  96840. + qh->frame_usecs[i] = 0;
  96841. + }
  96842. + }
  96843. +}
  96844. +
  96845. +/**
  96846. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  96847. + * not freed.
  96848. + *
  96849. + * @param hcd The HCD state structure.
  96850. + * @param qh QH to remove from schedule. */
  96851. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  96852. +{
  96853. + gintmsk_data_t intr_mask = {.d32 = 0 };
  96854. +
  96855. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  96856. + /* QH is not in a schedule. */
  96857. + return;
  96858. + }
  96859. +
  96860. + if (dwc_qh_is_non_per(qh)) {
  96861. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  96862. + hcd->non_periodic_qh_ptr =
  96863. + hcd->non_periodic_qh_ptr->next;
  96864. + }
  96865. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  96866. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  96867. + // hcd->fiq_state->kick_np_queues = 1;
  96868. + } else {
  96869. + deschedule_periodic(hcd, qh);
  96870. + hcd->periodic_qh_count--;
  96871. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  96872. + intr_mask.b.sofintr = 1;
  96873. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  96874. + intr_mask.d32, 0);
  96875. + }
  96876. + }
  96877. +}
  96878. +
  96879. +/**
  96880. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  96881. + * non-periodic schedule. The QH is added to the inactive non-periodic
  96882. + * schedule if any QTDs are still attached to the QH.
  96883. + *
  96884. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  96885. + * there are any QTDs still attached to the QH, the QH is added to either the
  96886. + * periodic inactive schedule or the periodic ready schedule and its next
  96887. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  96888. + * the scheduled frame has been reached already. Otherwise it's placed in the
  96889. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  96890. + * completely removed from the periodic schedule.
  96891. + */
  96892. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  96893. + int sched_next_periodic_split)
  96894. +{
  96895. + if (dwc_qh_is_non_per(qh)) {
  96896. + dwc_otg_hcd_qh_remove(hcd, qh);
  96897. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  96898. + /* Add back to inactive non-periodic schedule. */
  96899. + dwc_otg_hcd_qh_add(hcd, qh);
  96900. + //hcd->fiq_state->kick_np_queues = 1;
  96901. + }
  96902. + } else {
  96903. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  96904. +
  96905. + if (qh->do_split) {
  96906. + /* Schedule the next continuing periodic split transfer */
  96907. + if (sched_next_periodic_split) {
  96908. +
  96909. + qh->sched_frame = frame_number;
  96910. +
  96911. + if (dwc_frame_num_le(frame_number,
  96912. + dwc_frame_num_inc
  96913. + (qh->start_split_frame,
  96914. + 1))) {
  96915. + /*
  96916. + * Allow one frame to elapse after start
  96917. + * split microframe before scheduling
  96918. + * complete split, but DONT if we are
  96919. + * doing the next start split in the
  96920. + * same frame for an ISOC out.
  96921. + */
  96922. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  96923. + (qh->ep_is_in != 0)) {
  96924. + qh->sched_frame =
  96925. + dwc_frame_num_inc(qh->sched_frame, 1);
  96926. + }
  96927. + }
  96928. + } else {
  96929. + qh->sched_frame =
  96930. + dwc_frame_num_inc(qh->start_split_frame,
  96931. + qh->interval);
  96932. + if (dwc_frame_num_le
  96933. + (qh->sched_frame, frame_number)) {
  96934. + qh->sched_frame = frame_number;
  96935. + }
  96936. + qh->sched_frame |= 0x7;
  96937. + qh->start_split_frame = qh->sched_frame;
  96938. + }
  96939. + } else {
  96940. + qh->sched_frame =
  96941. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  96942. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  96943. + qh->sched_frame = frame_number;
  96944. + }
  96945. + }
  96946. +
  96947. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  96948. + dwc_otg_hcd_qh_remove(hcd, qh);
  96949. + } else {
  96950. + /*
  96951. + * Remove from periodic_sched_queued and move to
  96952. + * appropriate queue.
  96953. + */
  96954. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  96955. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  96956. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  96957. + &qh->qh_list_entry);
  96958. + } else {
  96959. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  96960. + {
  96961. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  96962. + }
  96963. +
  96964. + DWC_LIST_MOVE_HEAD
  96965. + (&hcd->periodic_sched_inactive,
  96966. + &qh->qh_list_entry);
  96967. + }
  96968. + }
  96969. + }
  96970. +}
  96971. +
  96972. +/**
  96973. + * This function allocates and initializes a QTD.
  96974. + *
  96975. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  96976. + * pointing to each other so each pair should have a unique correlation.
  96977. + * @param atomic_alloc Flag to do atomic alloc if needed
  96978. + *
  96979. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  96980. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  96981. +{
  96982. + dwc_otg_qtd_t *qtd;
  96983. +
  96984. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  96985. + if (qtd == NULL) {
  96986. + return NULL;
  96987. + }
  96988. +
  96989. + dwc_otg_hcd_qtd_init(qtd, urb);
  96990. + return qtd;
  96991. +}
  96992. +
  96993. +/**
  96994. + * Initializes a QTD structure.
  96995. + *
  96996. + * @param qtd The QTD to initialize.
  96997. + * @param urb The URB to use for initialization. */
  96998. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  96999. +{
  97000. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  97001. + qtd->urb = urb;
  97002. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  97003. + /*
  97004. + * The only time the QTD data toggle is used is on the data
  97005. + * phase of control transfers. This phase always starts with
  97006. + * DATA1.
  97007. + */
  97008. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  97009. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  97010. + }
  97011. +
  97012. + /* start split */
  97013. + qtd->complete_split = 0;
  97014. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  97015. + qtd->isoc_split_offset = 0;
  97016. + qtd->in_process = 0;
  97017. +
  97018. + /* Store the qtd ptr in the urb to reference what QTD. */
  97019. + urb->qtd = qtd;
  97020. + return;
  97021. +}
  97022. +
  97023. +/**
  97024. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  97025. + * QH to place the QTD into. If it does not find a QH, then it will create a
  97026. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  97027. + * is placed into the proper schedule based on its EP type.
  97028. + * HCD lock must be held and interrupts must be disabled on entry
  97029. + *
  97030. + * @param[in] qtd The QTD to add
  97031. + * @param[in] hcd The DWC HCD structure
  97032. + * @param[out] qh out parameter to return queue head
  97033. + * @param atomic_alloc Flag to do atomic alloc if needed
  97034. + *
  97035. + * @return 0 if successful, negative error code otherwise.
  97036. + */
  97037. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  97038. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  97039. +{
  97040. + int retval = 0;
  97041. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  97042. +
  97043. + /*
  97044. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  97045. + * doesn't exist.
  97046. + */
  97047. + if (*qh == NULL) {
  97048. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  97049. + if (*qh == NULL) {
  97050. + retval = -DWC_E_NO_MEMORY;
  97051. + goto done;
  97052. + } else {
  97053. + if (fiq_enable)
  97054. + hcd->fiq_state->kick_np_queues = 1;
  97055. + }
  97056. + }
  97057. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  97058. + if (retval == 0) {
  97059. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  97060. + qtd_list_entry);
  97061. + qtd->qh = *qh;
  97062. + }
  97063. +done:
  97064. +
  97065. + return retval;
  97066. +}
  97067. +
  97068. +#endif /* DWC_DEVICE_ONLY */
  97069. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  97070. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  97071. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2015-03-09 10:39:33.218893718 +0100
  97072. @@ -0,0 +1,188 @@
  97073. +#ifndef _DWC_OS_DEP_H_
  97074. +#define _DWC_OS_DEP_H_
  97075. +
  97076. +/**
  97077. + * @file
  97078. + *
  97079. + * This file contains OS dependent structures.
  97080. + *
  97081. + */
  97082. +
  97083. +#include <linux/kernel.h>
  97084. +#include <linux/module.h>
  97085. +#include <linux/moduleparam.h>
  97086. +#include <linux/init.h>
  97087. +#include <linux/device.h>
  97088. +#include <linux/errno.h>
  97089. +#include <linux/types.h>
  97090. +#include <linux/slab.h>
  97091. +#include <linux/list.h>
  97092. +#include <linux/interrupt.h>
  97093. +#include <linux/ctype.h>
  97094. +#include <linux/string.h>
  97095. +#include <linux/dma-mapping.h>
  97096. +#include <linux/jiffies.h>
  97097. +#include <linux/delay.h>
  97098. +#include <linux/timer.h>
  97099. +#include <linux/workqueue.h>
  97100. +#include <linux/stat.h>
  97101. +#include <linux/pci.h>
  97102. +
  97103. +#include <linux/version.h>
  97104. +
  97105. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  97106. +# include <linux/irq.h>
  97107. +#endif
  97108. +
  97109. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  97110. +# include <linux/usb/ch9.h>
  97111. +#else
  97112. +# include <linux/usb_ch9.h>
  97113. +#endif
  97114. +
  97115. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  97116. +# include <linux/usb/gadget.h>
  97117. +#else
  97118. +# include <linux/usb_gadget.h>
  97119. +#endif
  97120. +
  97121. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  97122. +# include <asm/irq.h>
  97123. +#endif
  97124. +
  97125. +#ifdef PCI_INTERFACE
  97126. +# include <asm/io.h>
  97127. +#endif
  97128. +
  97129. +#ifdef LM_INTERFACE
  97130. +# include <asm/unaligned.h>
  97131. +# include <asm/sizes.h>
  97132. +# include <asm/param.h>
  97133. +# include <asm/io.h>
  97134. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  97135. +# include <asm/arch/hardware.h>
  97136. +# include <asm/arch/lm.h>
  97137. +# include <asm/arch/irqs.h>
  97138. +# include <asm/arch/regs-irq.h>
  97139. +# else
  97140. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  97141. + here we assume that the machine architecture provides definitions
  97142. + in its own header
  97143. +*/
  97144. +# include <mach/lm.h>
  97145. +# include <mach/hardware.h>
  97146. +# endif
  97147. +#endif
  97148. +
  97149. +#ifdef PLATFORM_INTERFACE
  97150. +#include <linux/platform_device.h>
  97151. +#include <asm/mach/map.h>
  97152. +#endif
  97153. +
  97154. +/** The OS page size */
  97155. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  97156. +
  97157. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  97158. +typedef int gfp_t;
  97159. +#endif
  97160. +
  97161. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  97162. +# define IRQF_SHARED SA_SHIRQ
  97163. +#endif
  97164. +
  97165. +typedef struct os_dependent {
  97166. + /** Base address returned from ioremap() */
  97167. + void *base;
  97168. +
  97169. + /** Register offset for Diagnostic API */
  97170. + uint32_t reg_offset;
  97171. +
  97172. + /** Base address for MPHI peripheral */
  97173. + void *mphi_base;
  97174. +
  97175. +#ifdef LM_INTERFACE
  97176. + struct lm_device *lmdev;
  97177. +#elif defined(PCI_INTERFACE)
  97178. + struct pci_dev *pcidev;
  97179. +
  97180. + /** Start address of a PCI region */
  97181. + resource_size_t rsrc_start;
  97182. +
  97183. + /** Length address of a PCI region */
  97184. + resource_size_t rsrc_len;
  97185. +#elif defined(PLATFORM_INTERFACE)
  97186. + struct platform_device *platformdev;
  97187. +#endif
  97188. +
  97189. +} os_dependent_t;
  97190. +
  97191. +#ifdef __cplusplus
  97192. +}
  97193. +#endif
  97194. +
  97195. +
  97196. +
  97197. +/* Type for the our device on the chosen bus */
  97198. +#if defined(LM_INTERFACE)
  97199. +typedef struct lm_device dwc_bus_dev_t;
  97200. +#elif defined(PCI_INTERFACE)
  97201. +typedef struct pci_dev dwc_bus_dev_t;
  97202. +#elif defined(PLATFORM_INTERFACE)
  97203. +typedef struct platform_device dwc_bus_dev_t;
  97204. +#endif
  97205. +
  97206. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  97207. +#if defined(LM_INTERFACE)
  97208. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  97209. +#elif defined(PCI_INTERFACE)
  97210. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  97211. +#elif defined(PLATFORM_INTERFACE)
  97212. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  97213. +#endif
  97214. +
  97215. +/**
  97216. + * Helper macro returning the otg_device structure of a given struct device
  97217. + *
  97218. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  97219. + */
  97220. +#ifdef LM_INTERFACE
  97221. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  97222. + struct lm_device *lm_dev = \
  97223. + container_of(_dev, struct lm_device, dev); \
  97224. + _var = lm_get_drvdata(lm_dev); \
  97225. + } while (0)
  97226. +
  97227. +#elif defined(PCI_INTERFACE)
  97228. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  97229. + _var = dev_get_drvdata(_dev); \
  97230. + } while (0)
  97231. +
  97232. +#elif defined(PLATFORM_INTERFACE)
  97233. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  97234. + struct platform_device *platform_dev = \
  97235. + container_of(_dev, struct platform_device, dev); \
  97236. + _var = platform_get_drvdata(platform_dev); \
  97237. + } while (0)
  97238. +#endif
  97239. +
  97240. +
  97241. +/**
  97242. + * Helper macro returning the struct dev of the given struct os_dependent
  97243. + *
  97244. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  97245. + */
  97246. +#ifdef LM_INTERFACE
  97247. +#define DWC_OTG_OS_GETDEV(_osdep) \
  97248. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  97249. +#elif defined(PCI_INTERFACE)
  97250. +#define DWC_OTG_OS_GETDEV(_osdep) \
  97251. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  97252. +#elif defined(PLATFORM_INTERFACE)
  97253. +#define DWC_OTG_OS_GETDEV(_osdep) \
  97254. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  97255. +#endif
  97256. +
  97257. +
  97258. +
  97259. +
  97260. +#endif /* _DWC_OS_DEP_H_ */
  97261. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  97262. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  97263. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2015-03-10 17:26:51.306216687 +0100
  97264. @@ -0,0 +1,2708 @@
  97265. +/* ==========================================================================
  97266. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  97267. + * $Revision: #101 $
  97268. + * $Date: 2012/08/10 $
  97269. + * $Change: 2047372 $
  97270. + *
  97271. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  97272. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  97273. + * otherwise expressly agreed to in writing between Synopsys and you.
  97274. + *
  97275. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  97276. + * any End User Software License Agreement or Agreement for Licensed Product
  97277. + * with Synopsys or any supplement thereto. You are permitted to use and
  97278. + * redistribute this Software in source and binary forms, with or without
  97279. + * modification, provided that redistributions of source code must retain this
  97280. + * notice. You may not view, use, disclose, copy or distribute this file or
  97281. + * any information contained herein except pursuant to this license grant from
  97282. + * Synopsys. If you do not agree with this notice, including the disclaimer
  97283. + * below, then you are not authorized to use the Software.
  97284. + *
  97285. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  97286. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  97287. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  97288. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  97289. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  97290. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  97291. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  97292. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  97293. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  97294. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  97295. + * DAMAGE.
  97296. + * ========================================================================== */
  97297. +#ifndef DWC_HOST_ONLY
  97298. +
  97299. +/** @file
  97300. + * This file implements PCD Core. All code in this file is portable and doesn't
  97301. + * use any OS specific functions.
  97302. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  97303. + * header file, which can be used to implement OS specific PCD interface.
  97304. + *
  97305. + * An important function of the PCD is managing interrupts generated
  97306. + * by the DWC_otg controller. The implementation of the DWC_otg device
  97307. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  97308. + *
  97309. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  97310. + * @todo Does it work when the request size is greater than DEPTSIZ
  97311. + * transfer size
  97312. + *
  97313. + */
  97314. +
  97315. +#include "dwc_otg_pcd.h"
  97316. +
  97317. +#ifdef DWC_UTE_CFI
  97318. +#include "dwc_otg_cfi.h"
  97319. +
  97320. +extern int init_cfi(cfiobject_t * cfiobj);
  97321. +#endif
  97322. +
  97323. +/**
  97324. + * Choose endpoint from ep arrays using usb_ep structure.
  97325. + */
  97326. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  97327. +{
  97328. + int i;
  97329. + if (pcd->ep0.priv == handle) {
  97330. + return &pcd->ep0;
  97331. + }
  97332. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  97333. + if (pcd->in_ep[i].priv == handle)
  97334. + return &pcd->in_ep[i];
  97335. + if (pcd->out_ep[i].priv == handle)
  97336. + return &pcd->out_ep[i];
  97337. + }
  97338. +
  97339. + return NULL;
  97340. +}
  97341. +
  97342. +/**
  97343. + * This function completes a request. It call's the request call back.
  97344. + */
  97345. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  97346. + int32_t status)
  97347. +{
  97348. + unsigned stopped = ep->stopped;
  97349. +
  97350. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  97351. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  97352. +
  97353. + /* don't modify queue heads during completion callback */
  97354. + ep->stopped = 1;
  97355. + /* spin_unlock/spin_lock now done in fops->complete() */
  97356. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  97357. + req->actual);
  97358. +
  97359. + if (ep->pcd->request_pending > 0) {
  97360. + --ep->pcd->request_pending;
  97361. + }
  97362. +
  97363. + ep->stopped = stopped;
  97364. + DWC_FREE(req);
  97365. +}
  97366. +
  97367. +/**
  97368. + * This function terminates all the requsts in the EP request queue.
  97369. + */
  97370. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  97371. +{
  97372. + dwc_otg_pcd_request_t *req;
  97373. +
  97374. + ep->stopped = 1;
  97375. +
  97376. + /* called with irqs blocked?? */
  97377. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  97378. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  97379. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  97380. + }
  97381. +}
  97382. +
  97383. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  97384. + const struct dwc_otg_pcd_function_ops *fops)
  97385. +{
  97386. + pcd->fops = fops;
  97387. +}
  97388. +
  97389. +/**
  97390. + * PCD Callback function for initializing the PCD when switching to
  97391. + * device mode.
  97392. + *
  97393. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97394. + */
  97395. +static int32_t dwc_otg_pcd_start_cb(void *p)
  97396. +{
  97397. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97398. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  97399. +
  97400. + /*
  97401. + * Initialized the Core for Device mode.
  97402. + */
  97403. + if (dwc_otg_is_device_mode(core_if)) {
  97404. + dwc_otg_core_dev_init(core_if);
  97405. + /* Set core_if's lock pointer to the pcd->lock */
  97406. + core_if->lock = pcd->lock;
  97407. + }
  97408. + return 1;
  97409. +}
  97410. +
  97411. +/** CFI-specific buffer allocation function for EP */
  97412. +#ifdef DWC_UTE_CFI
  97413. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  97414. + size_t buflen, int flags)
  97415. +{
  97416. + dwc_otg_pcd_ep_t *ep;
  97417. + ep = get_ep_from_handle(pcd, pep);
  97418. + if (!ep) {
  97419. + DWC_WARN("bad ep\n");
  97420. + return -DWC_E_INVALID;
  97421. + }
  97422. +
  97423. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  97424. + flags);
  97425. +}
  97426. +#else
  97427. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  97428. + size_t buflen, int flags);
  97429. +#endif
  97430. +
  97431. +/**
  97432. + * PCD Callback function for notifying the PCD when resuming from
  97433. + * suspend.
  97434. + *
  97435. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97436. + */
  97437. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  97438. +{
  97439. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97440. +
  97441. + if (pcd->fops->resume) {
  97442. + pcd->fops->resume(pcd);
  97443. + }
  97444. +
  97445. + /* Stop the SRP timeout timer. */
  97446. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  97447. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  97448. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  97449. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  97450. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  97451. + }
  97452. + }
  97453. + return 1;
  97454. +}
  97455. +
  97456. +/**
  97457. + * PCD Callback function for notifying the PCD device is suspended.
  97458. + *
  97459. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97460. + */
  97461. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  97462. +{
  97463. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97464. +
  97465. + if (pcd->fops->suspend) {
  97466. + DWC_SPINUNLOCK(pcd->lock);
  97467. + pcd->fops->suspend(pcd);
  97468. + DWC_SPINLOCK(pcd->lock);
  97469. + }
  97470. +
  97471. + return 1;
  97472. +}
  97473. +
  97474. +/**
  97475. + * PCD Callback function for stopping the PCD when switching to Host
  97476. + * mode.
  97477. + *
  97478. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  97479. + */
  97480. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  97481. +{
  97482. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  97483. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  97484. +
  97485. + dwc_otg_pcd_stop(pcd);
  97486. + return 1;
  97487. +}
  97488. +
  97489. +/**
  97490. + * PCD Callback structure for handling mode switching.
  97491. + */
  97492. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  97493. + .start = dwc_otg_pcd_start_cb,
  97494. + .stop = dwc_otg_pcd_stop_cb,
  97495. + .suspend = dwc_otg_pcd_suspend_cb,
  97496. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  97497. + .p = 0, /* Set at registration */
  97498. +};
  97499. +
  97500. +/**
  97501. + * This function allocates a DMA Descriptor chain for the Endpoint
  97502. + * buffer to be used for a transfer to/from the specified endpoint.
  97503. + */
  97504. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  97505. + uint32_t count)
  97506. +{
  97507. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  97508. + dma_desc_addr);
  97509. +}
  97510. +
  97511. +/**
  97512. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  97513. + */
  97514. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  97515. + uint32_t dma_desc_addr, uint32_t count)
  97516. +{
  97517. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  97518. + dma_desc_addr);
  97519. +}
  97520. +
  97521. +#ifdef DWC_EN_ISOC
  97522. +
  97523. +/**
  97524. + * This function initializes a descriptor chain for Isochronous transfer
  97525. + *
  97526. + * @param core_if Programming view of DWC_otg controller.
  97527. + * @param dwc_ep The EP to start the transfer on.
  97528. + *
  97529. + */
  97530. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  97531. + dwc_ep_t * dwc_ep)
  97532. +{
  97533. +
  97534. + dsts_data_t dsts = {.d32 = 0 };
  97535. + depctl_data_t depctl = {.d32 = 0 };
  97536. + volatile uint32_t *addr;
  97537. + int i, j;
  97538. + uint32_t len;
  97539. +
  97540. + if (dwc_ep->is_in)
  97541. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  97542. + else
  97543. + dwc_ep->desc_cnt =
  97544. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  97545. + dwc_ep->bInterval;
  97546. +
  97547. + /** Allocate descriptors for double buffering */
  97548. + dwc_ep->iso_desc_addr =
  97549. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  97550. + dwc_ep->desc_cnt * 2);
  97551. + if (dwc_ep->desc_addr) {
  97552. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  97553. + return;
  97554. + }
  97555. +
  97556. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  97557. +
  97558. + /** ISO OUT EP */
  97559. + if (dwc_ep->is_in == 0) {
  97560. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  97561. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  97562. + dma_addr_t dma_ad;
  97563. + uint32_t data_per_desc;
  97564. + dwc_otg_dev_out_ep_regs_t *out_regs =
  97565. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  97566. + int offset;
  97567. +
  97568. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  97569. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  97570. +
  97571. + /** Buffer 0 descriptors setup */
  97572. + dma_ad = dwc_ep->dma_addr0;
  97573. +
  97574. + sts.b_iso_out.bs = BS_HOST_READY;
  97575. + sts.b_iso_out.rxsts = 0;
  97576. + sts.b_iso_out.l = 0;
  97577. + sts.b_iso_out.sp = 0;
  97578. + sts.b_iso_out.ioc = 0;
  97579. + sts.b_iso_out.pid = 0;
  97580. + sts.b_iso_out.framenum = 0;
  97581. +
  97582. + offset = 0;
  97583. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97584. + i += dwc_ep->pkt_per_frm) {
  97585. +
  97586. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  97587. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97588. + if (len > dwc_ep->data_per_frame)
  97589. + data_per_desc =
  97590. + dwc_ep->data_per_frame -
  97591. + j * dwc_ep->maxpacket;
  97592. + else
  97593. + data_per_desc = dwc_ep->maxpacket;
  97594. + len = data_per_desc % 4;
  97595. + if (len)
  97596. + data_per_desc += 4 - len;
  97597. +
  97598. + sts.b_iso_out.rxbytes = data_per_desc;
  97599. + dma_desc->buf = dma_ad;
  97600. + dma_desc->status.d32 = sts.d32;
  97601. +
  97602. + offset += data_per_desc;
  97603. + dma_desc++;
  97604. + dma_ad += data_per_desc;
  97605. + }
  97606. + }
  97607. +
  97608. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  97609. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97610. + if (len > dwc_ep->data_per_frame)
  97611. + data_per_desc =
  97612. + dwc_ep->data_per_frame -
  97613. + j * dwc_ep->maxpacket;
  97614. + else
  97615. + data_per_desc = dwc_ep->maxpacket;
  97616. + len = data_per_desc % 4;
  97617. + if (len)
  97618. + data_per_desc += 4 - len;
  97619. + sts.b_iso_out.rxbytes = data_per_desc;
  97620. + dma_desc->buf = dma_ad;
  97621. + dma_desc->status.d32 = sts.d32;
  97622. +
  97623. + offset += data_per_desc;
  97624. + dma_desc++;
  97625. + dma_ad += data_per_desc;
  97626. + }
  97627. +
  97628. + sts.b_iso_out.ioc = 1;
  97629. + len = (j + 1) * dwc_ep->maxpacket;
  97630. + if (len > dwc_ep->data_per_frame)
  97631. + data_per_desc =
  97632. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  97633. + else
  97634. + data_per_desc = dwc_ep->maxpacket;
  97635. + len = data_per_desc % 4;
  97636. + if (len)
  97637. + data_per_desc += 4 - len;
  97638. + sts.b_iso_out.rxbytes = data_per_desc;
  97639. +
  97640. + dma_desc->buf = dma_ad;
  97641. + dma_desc->status.d32 = sts.d32;
  97642. + dma_desc++;
  97643. +
  97644. + /** Buffer 1 descriptors setup */
  97645. + sts.b_iso_out.ioc = 0;
  97646. + dma_ad = dwc_ep->dma_addr1;
  97647. +
  97648. + offset = 0;
  97649. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97650. + i += dwc_ep->pkt_per_frm) {
  97651. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  97652. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  97653. + if (len > dwc_ep->data_per_frame)
  97654. + data_per_desc =
  97655. + dwc_ep->data_per_frame -
  97656. + j * dwc_ep->maxpacket;
  97657. + else
  97658. + data_per_desc = dwc_ep->maxpacket;
  97659. + len = data_per_desc % 4;
  97660. + if (len)
  97661. + data_per_desc += 4 - len;
  97662. +
  97663. + data_per_desc =
  97664. + sts.b_iso_out.rxbytes = data_per_desc;
  97665. + dma_desc->buf = dma_ad;
  97666. + dma_desc->status.d32 = sts.d32;
  97667. +
  97668. + offset += data_per_desc;
  97669. + dma_desc++;
  97670. + dma_ad += data_per_desc;
  97671. + }
  97672. + }
  97673. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  97674. + data_per_desc =
  97675. + ((j + 1) * dwc_ep->maxpacket >
  97676. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  97677. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  97678. + data_per_desc +=
  97679. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  97680. + sts.b_iso_out.rxbytes = data_per_desc;
  97681. + dma_desc->buf = dma_ad;
  97682. + dma_desc->status.d32 = sts.d32;
  97683. +
  97684. + offset += data_per_desc;
  97685. + dma_desc++;
  97686. + dma_ad += data_per_desc;
  97687. + }
  97688. +
  97689. + sts.b_iso_out.ioc = 1;
  97690. + sts.b_iso_out.l = 1;
  97691. + data_per_desc =
  97692. + ((j + 1) * dwc_ep->maxpacket >
  97693. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  97694. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  97695. + data_per_desc +=
  97696. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  97697. + sts.b_iso_out.rxbytes = data_per_desc;
  97698. +
  97699. + dma_desc->buf = dma_ad;
  97700. + dma_desc->status.d32 = sts.d32;
  97701. +
  97702. + dwc_ep->next_frame = 0;
  97703. +
  97704. + /** Write dma_ad into DOEPDMA register */
  97705. + DWC_WRITE_REG32(&(out_regs->doepdma),
  97706. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  97707. +
  97708. + }
  97709. + /** ISO IN EP */
  97710. + else {
  97711. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  97712. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  97713. + dma_addr_t dma_ad;
  97714. + dwc_otg_dev_in_ep_regs_t *in_regs =
  97715. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  97716. + unsigned int frmnumber;
  97717. + fifosize_data_t txfifosize, rxfifosize;
  97718. +
  97719. + txfifosize.d32 =
  97720. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  97721. + dtxfsts);
  97722. + rxfifosize.d32 =
  97723. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  97724. +
  97725. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  97726. +
  97727. + dma_ad = dwc_ep->dma_addr0;
  97728. +
  97729. + dsts.d32 =
  97730. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  97731. +
  97732. + sts.b_iso_in.bs = BS_HOST_READY;
  97733. + sts.b_iso_in.txsts = 0;
  97734. + sts.b_iso_in.sp =
  97735. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  97736. + sts.b_iso_in.ioc = 0;
  97737. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  97738. +
  97739. + frmnumber = dwc_ep->next_frame;
  97740. +
  97741. + sts.b_iso_in.framenum = frmnumber;
  97742. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  97743. + sts.b_iso_in.l = 0;
  97744. +
  97745. + /** Buffer 0 descriptors setup */
  97746. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  97747. + dma_desc->buf = dma_ad;
  97748. + dma_desc->status.d32 = sts.d32;
  97749. + dma_desc++;
  97750. +
  97751. + dma_ad += dwc_ep->data_per_frame;
  97752. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  97753. + }
  97754. +
  97755. + sts.b_iso_in.ioc = 1;
  97756. + dma_desc->buf = dma_ad;
  97757. + dma_desc->status.d32 = sts.d32;
  97758. + ++dma_desc;
  97759. +
  97760. + /** Buffer 1 descriptors setup */
  97761. + sts.b_iso_in.ioc = 0;
  97762. + dma_ad = dwc_ep->dma_addr1;
  97763. +
  97764. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  97765. + i += dwc_ep->pkt_per_frm) {
  97766. + dma_desc->buf = dma_ad;
  97767. + dma_desc->status.d32 = sts.d32;
  97768. + dma_desc++;
  97769. +
  97770. + dma_ad += dwc_ep->data_per_frame;
  97771. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  97772. +
  97773. + sts.b_iso_in.ioc = 0;
  97774. + }
  97775. + sts.b_iso_in.ioc = 1;
  97776. + sts.b_iso_in.l = 1;
  97777. +
  97778. + dma_desc->buf = dma_ad;
  97779. + dma_desc->status.d32 = sts.d32;
  97780. +
  97781. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  97782. +
  97783. + /** Write dma_ad into diepdma register */
  97784. + DWC_WRITE_REG32(&(in_regs->diepdma),
  97785. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  97786. + }
  97787. + /** Enable endpoint, clear nak */
  97788. + depctl.d32 = 0;
  97789. + depctl.b.epena = 1;
  97790. + depctl.b.usbactep = 1;
  97791. + depctl.b.cnak = 1;
  97792. +
  97793. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  97794. + depctl.d32 = DWC_READ_REG32(addr);
  97795. +}
  97796. +
  97797. +/**
  97798. + * This function initializes a descriptor chain for Isochronous transfer
  97799. + *
  97800. + * @param core_if Programming view of DWC_otg controller.
  97801. + * @param ep The EP to start the transfer on.
  97802. + *
  97803. + */
  97804. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  97805. + dwc_ep_t * ep)
  97806. +{
  97807. + depctl_data_t depctl = {.d32 = 0 };
  97808. + volatile uint32_t *addr;
  97809. +
  97810. + if (ep->is_in) {
  97811. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  97812. + } else {
  97813. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  97814. + }
  97815. +
  97816. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  97817. + return;
  97818. + } else {
  97819. + deptsiz_data_t deptsiz = {.d32 = 0 };
  97820. +
  97821. + ep->xfer_len =
  97822. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  97823. + ep->pkt_cnt =
  97824. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  97825. + ep->xfer_count = 0;
  97826. + ep->xfer_buff =
  97827. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  97828. + ep->dma_addr =
  97829. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  97830. +
  97831. + if (ep->is_in) {
  97832. + /* Program the transfer size and packet count
  97833. + * as follows: xfersize = N * maxpacket +
  97834. + * short_packet pktcnt = N + (short_packet
  97835. + * exist ? 1 : 0)
  97836. + */
  97837. + deptsiz.b.mc = ep->pkt_per_frm;
  97838. + deptsiz.b.xfersize = ep->xfer_len;
  97839. + deptsiz.b.pktcnt =
  97840. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  97841. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  97842. + dieptsiz, deptsiz.d32);
  97843. +
  97844. + /* Write the DMA register */
  97845. + DWC_WRITE_REG32(&
  97846. + (core_if->dev_if->in_ep_regs[ep->num]->
  97847. + diepdma), (uint32_t) ep->dma_addr);
  97848. +
  97849. + } else {
  97850. + deptsiz.b.pktcnt =
  97851. + (ep->xfer_len + (ep->maxpacket - 1)) /
  97852. + ep->maxpacket;
  97853. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  97854. +
  97855. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  97856. + doeptsiz, deptsiz.d32);
  97857. +
  97858. + /* Write the DMA register */
  97859. + DWC_WRITE_REG32(&
  97860. + (core_if->dev_if->out_ep_regs[ep->num]->
  97861. + doepdma), (uint32_t) ep->dma_addr);
  97862. +
  97863. + }
  97864. + /** Enable endpoint, clear nak */
  97865. + depctl.d32 = 0;
  97866. + depctl.b.epena = 1;
  97867. + depctl.b.cnak = 1;
  97868. +
  97869. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  97870. + }
  97871. +}
  97872. +
  97873. +/**
  97874. + * This function does the setup for a data transfer for an EP and
  97875. + * starts the transfer. For an IN transfer, the packets will be
  97876. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  97877. + * the packets are unloaded from the Rx FIFO in the ISR.
  97878. + *
  97879. + * @param core_if Programming view of DWC_otg controller.
  97880. + * @param ep The EP to start the transfer on.
  97881. + */
  97882. +
  97883. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  97884. + dwc_ep_t * ep)
  97885. +{
  97886. + if (core_if->dma_enable) {
  97887. + if (core_if->dma_desc_enable) {
  97888. + if (ep->is_in) {
  97889. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  97890. + } else {
  97891. + ep->desc_cnt = ep->pkt_cnt;
  97892. + }
  97893. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  97894. + } else {
  97895. + if (core_if->pti_enh_enable) {
  97896. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  97897. + } else {
  97898. + ep->cur_pkt_addr =
  97899. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  97900. + xfer_buff0;
  97901. + ep->cur_pkt_dma_addr =
  97902. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  97903. + dma_addr0;
  97904. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  97905. + }
  97906. + }
  97907. + } else {
  97908. + ep->cur_pkt_addr =
  97909. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  97910. + ep->cur_pkt_dma_addr =
  97911. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  97912. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  97913. + }
  97914. +}
  97915. +
  97916. +/**
  97917. + * This function stops transfer for an EP and
  97918. + * resets the ep's variables.
  97919. + *
  97920. + * @param core_if Programming view of DWC_otg controller.
  97921. + * @param ep The EP to start the transfer on.
  97922. + */
  97923. +
  97924. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  97925. +{
  97926. + depctl_data_t depctl = {.d32 = 0 };
  97927. + volatile uint32_t *addr;
  97928. +
  97929. + if (ep->is_in == 1) {
  97930. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  97931. + } else {
  97932. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  97933. + }
  97934. +
  97935. + /* disable the ep */
  97936. + depctl.d32 = DWC_READ_REG32(addr);
  97937. +
  97938. + depctl.b.epdis = 1;
  97939. + depctl.b.snak = 1;
  97940. +
  97941. + DWC_WRITE_REG32(addr, depctl.d32);
  97942. +
  97943. + if (core_if->dma_desc_enable &&
  97944. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  97945. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  97946. + ep->iso_dma_desc_addr,
  97947. + ep->desc_cnt * 2);
  97948. + }
  97949. +
  97950. + /* reset varibales */
  97951. + ep->dma_addr0 = 0;
  97952. + ep->dma_addr1 = 0;
  97953. + ep->xfer_buff0 = 0;
  97954. + ep->xfer_buff1 = 0;
  97955. + ep->data_per_frame = 0;
  97956. + ep->data_pattern_frame = 0;
  97957. + ep->sync_frame = 0;
  97958. + ep->buf_proc_intrvl = 0;
  97959. + ep->bInterval = 0;
  97960. + ep->proc_buf_num = 0;
  97961. + ep->pkt_per_frm = 0;
  97962. + ep->pkt_per_frm = 0;
  97963. + ep->desc_cnt = 0;
  97964. + ep->iso_desc_addr = 0;
  97965. + ep->iso_dma_desc_addr = 0;
  97966. +}
  97967. +
  97968. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  97969. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  97970. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  97971. + int data_per_frame, int start_frame,
  97972. + int buf_proc_intrvl, void *req_handle,
  97973. + int atomic_alloc)
  97974. +{
  97975. + dwc_otg_pcd_ep_t *ep;
  97976. + dwc_irqflags_t flags = 0;
  97977. + dwc_ep_t *dwc_ep;
  97978. + int32_t frm_data;
  97979. + dsts_data_t dsts;
  97980. + dwc_otg_core_if_t *core_if;
  97981. +
  97982. + ep = get_ep_from_handle(pcd, ep_handle);
  97983. +
  97984. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  97985. + DWC_WARN("bad ep\n");
  97986. + return -DWC_E_INVALID;
  97987. + }
  97988. +
  97989. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  97990. + core_if = GET_CORE_IF(pcd);
  97991. + dwc_ep = &ep->dwc_ep;
  97992. +
  97993. + if (ep->iso_req_handle) {
  97994. + DWC_WARN("ISO request in progress\n");
  97995. + }
  97996. +
  97997. + dwc_ep->dma_addr0 = dma0;
  97998. + dwc_ep->dma_addr1 = dma1;
  97999. +
  98000. + dwc_ep->xfer_buff0 = buf0;
  98001. + dwc_ep->xfer_buff1 = buf1;
  98002. +
  98003. + dwc_ep->data_per_frame = data_per_frame;
  98004. +
  98005. + /** @todo - pattern data support is to be implemented in the future */
  98006. + dwc_ep->data_pattern_frame = dp_frame;
  98007. + dwc_ep->sync_frame = sync_frame;
  98008. +
  98009. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  98010. +
  98011. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  98012. +
  98013. + dwc_ep->proc_buf_num = 0;
  98014. +
  98015. + dwc_ep->pkt_per_frm = 0;
  98016. + frm_data = ep->dwc_ep.data_per_frame;
  98017. + while (frm_data > 0) {
  98018. + dwc_ep->pkt_per_frm++;
  98019. + frm_data -= ep->dwc_ep.maxpacket;
  98020. + }
  98021. +
  98022. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  98023. +
  98024. + if (start_frame == -1) {
  98025. + dwc_ep->next_frame = dsts.b.soffn + 1;
  98026. + if (dwc_ep->bInterval != 1) {
  98027. + dwc_ep->next_frame =
  98028. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  98029. + dwc_ep->next_frame %
  98030. + dwc_ep->bInterval);
  98031. + }
  98032. + } else {
  98033. + dwc_ep->next_frame = start_frame;
  98034. + }
  98035. +
  98036. + if (!core_if->pti_enh_enable) {
  98037. + dwc_ep->pkt_cnt =
  98038. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  98039. + dwc_ep->bInterval;
  98040. + } else {
  98041. + dwc_ep->pkt_cnt =
  98042. + (dwc_ep->data_per_frame *
  98043. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  98044. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  98045. + }
  98046. +
  98047. + if (core_if->dma_desc_enable) {
  98048. + dwc_ep->desc_cnt =
  98049. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  98050. + dwc_ep->bInterval;
  98051. + }
  98052. +
  98053. + if (atomic_alloc) {
  98054. + dwc_ep->pkt_info =
  98055. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  98056. + } else {
  98057. + dwc_ep->pkt_info =
  98058. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  98059. + }
  98060. + if (!dwc_ep->pkt_info) {
  98061. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98062. + return -DWC_E_NO_MEMORY;
  98063. + }
  98064. + if (core_if->pti_enh_enable) {
  98065. + dwc_memset(dwc_ep->pkt_info, 0,
  98066. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  98067. + }
  98068. +
  98069. + dwc_ep->cur_pkt = 0;
  98070. + ep->iso_req_handle = req_handle;
  98071. +
  98072. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98073. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  98074. + return 0;
  98075. +}
  98076. +
  98077. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  98078. + void *req_handle)
  98079. +{
  98080. + dwc_irqflags_t flags = 0;
  98081. + dwc_otg_pcd_ep_t *ep;
  98082. + dwc_ep_t *dwc_ep;
  98083. +
  98084. + ep = get_ep_from_handle(pcd, ep_handle);
  98085. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  98086. + DWC_WARN("bad ep\n");
  98087. + return -DWC_E_INVALID;
  98088. + }
  98089. + dwc_ep = &ep->dwc_ep;
  98090. +
  98091. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  98092. +
  98093. + DWC_FREE(dwc_ep->pkt_info);
  98094. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98095. + if (ep->iso_req_handle != req_handle) {
  98096. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98097. + return -DWC_E_INVALID;
  98098. + }
  98099. +
  98100. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98101. +
  98102. + ep->iso_req_handle = 0;
  98103. + return 0;
  98104. +}
  98105. +
  98106. +/**
  98107. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  98108. + * for Isochronous EPs
  98109. + *
  98110. + * - Every time a sync period completes this function is called to
  98111. + * perform data exchange between PCD and gadget
  98112. + */
  98113. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  98114. + void *req_handle)
  98115. +{
  98116. + int i;
  98117. + dwc_ep_t *dwc_ep;
  98118. +
  98119. + dwc_ep = &ep->dwc_ep;
  98120. +
  98121. + DWC_SPINUNLOCK(ep->pcd->lock);
  98122. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  98123. + dwc_ep->proc_buf_num ^ 0x1);
  98124. + DWC_SPINLOCK(ep->pcd->lock);
  98125. +
  98126. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  98127. + dwc_ep->pkt_info[i].status = 0;
  98128. + dwc_ep->pkt_info[i].offset = 0;
  98129. + dwc_ep->pkt_info[i].length = 0;
  98130. + }
  98131. +}
  98132. +
  98133. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  98134. + void *iso_req_handle)
  98135. +{
  98136. + dwc_otg_pcd_ep_t *ep;
  98137. + dwc_ep_t *dwc_ep;
  98138. +
  98139. + ep = get_ep_from_handle(pcd, ep_handle);
  98140. + if (!ep->desc || ep->dwc_ep.num == 0) {
  98141. + DWC_WARN("bad ep\n");
  98142. + return -DWC_E_INVALID;
  98143. + }
  98144. + dwc_ep = &ep->dwc_ep;
  98145. +
  98146. + return dwc_ep->pkt_cnt;
  98147. +}
  98148. +
  98149. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  98150. + void *iso_req_handle, int packet,
  98151. + int *status, int *actual, int *offset)
  98152. +{
  98153. + dwc_otg_pcd_ep_t *ep;
  98154. + dwc_ep_t *dwc_ep;
  98155. +
  98156. + ep = get_ep_from_handle(pcd, ep_handle);
  98157. + if (!ep)
  98158. + DWC_WARN("bad ep\n");
  98159. +
  98160. + dwc_ep = &ep->dwc_ep;
  98161. +
  98162. + *status = dwc_ep->pkt_info[packet].status;
  98163. + *actual = dwc_ep->pkt_info[packet].length;
  98164. + *offset = dwc_ep->pkt_info[packet].offset;
  98165. +}
  98166. +
  98167. +#endif /* DWC_EN_ISOC */
  98168. +
  98169. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  98170. + uint32_t is_in, uint32_t ep_num)
  98171. +{
  98172. + /* Init EP structure */
  98173. + pcd_ep->desc = 0;
  98174. + pcd_ep->pcd = pcd;
  98175. + pcd_ep->stopped = 1;
  98176. + pcd_ep->queue_sof = 0;
  98177. +
  98178. + /* Init DWC ep structure */
  98179. + pcd_ep->dwc_ep.is_in = is_in;
  98180. + pcd_ep->dwc_ep.num = ep_num;
  98181. + pcd_ep->dwc_ep.active = 0;
  98182. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  98183. + /* Control until ep is actvated */
  98184. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  98185. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  98186. + pcd_ep->dwc_ep.dma_addr = 0;
  98187. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  98188. + pcd_ep->dwc_ep.xfer_buff = 0;
  98189. + pcd_ep->dwc_ep.xfer_len = 0;
  98190. + pcd_ep->dwc_ep.xfer_count = 0;
  98191. + pcd_ep->dwc_ep.sent_zlp = 0;
  98192. + pcd_ep->dwc_ep.total_len = 0;
  98193. + pcd_ep->dwc_ep.desc_addr = 0;
  98194. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  98195. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  98196. +}
  98197. +
  98198. +/**
  98199. + * Initialize ep's
  98200. + */
  98201. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  98202. +{
  98203. + int i;
  98204. + uint32_t hwcfg1;
  98205. + dwc_otg_pcd_ep_t *ep;
  98206. + int in_ep_cntr, out_ep_cntr;
  98207. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  98208. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  98209. +
  98210. + /**
  98211. + * Initialize the EP0 structure.
  98212. + */
  98213. + ep = &pcd->ep0;
  98214. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  98215. +
  98216. + in_ep_cntr = 0;
  98217. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  98218. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  98219. + if ((hwcfg1 & 0x1) == 0) {
  98220. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  98221. + in_ep_cntr++;
  98222. + /**
  98223. + * @todo NGS: Add direction to EP, based on contents
  98224. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  98225. + * sprintf(";r
  98226. + */
  98227. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  98228. +
  98229. + DWC_CIRCLEQ_INIT(&ep->queue);
  98230. + }
  98231. + hwcfg1 >>= 2;
  98232. + }
  98233. +
  98234. + out_ep_cntr = 0;
  98235. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  98236. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  98237. + if ((hwcfg1 & 0x1) == 0) {
  98238. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  98239. + out_ep_cntr++;
  98240. + /**
  98241. + * @todo NGS: Add direction to EP, based on contents
  98242. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  98243. + * sprintf(";r
  98244. + */
  98245. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  98246. + DWC_CIRCLEQ_INIT(&ep->queue);
  98247. + }
  98248. + hwcfg1 >>= 2;
  98249. + }
  98250. +
  98251. + pcd->ep0state = EP0_DISCONNECT;
  98252. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  98253. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  98254. +}
  98255. +
  98256. +/**
  98257. + * This function is called when the SRP timer expires. The SRP should
  98258. + * complete within 6 seconds.
  98259. + */
  98260. +static void srp_timeout(void *ptr)
  98261. +{
  98262. + gotgctl_data_t gotgctl;
  98263. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  98264. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  98265. +
  98266. + gotgctl.d32 = DWC_READ_REG32(addr);
  98267. +
  98268. + core_if->srp_timer_started = 0;
  98269. +
  98270. + if (core_if->adp_enable) {
  98271. + if (gotgctl.b.bsesvld == 0) {
  98272. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  98273. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  98274. + /* Power off the core */
  98275. + if (core_if->power_down == 2) {
  98276. + gpwrdn.b.pwrdnswtch = 1;
  98277. + DWC_MODIFY_REG32(&core_if->
  98278. + core_global_regs->gpwrdn,
  98279. + gpwrdn.d32, 0);
  98280. + }
  98281. +
  98282. + gpwrdn.d32 = 0;
  98283. + gpwrdn.b.pmuintsel = 1;
  98284. + gpwrdn.b.pmuactv = 1;
  98285. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  98286. + gpwrdn.d32);
  98287. + dwc_otg_adp_probe_start(core_if);
  98288. + } else {
  98289. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  98290. + core_if->op_state = B_PERIPHERAL;
  98291. + dwc_otg_core_init(core_if);
  98292. + dwc_otg_enable_global_interrupts(core_if);
  98293. + cil_pcd_start(core_if);
  98294. + }
  98295. + }
  98296. +
  98297. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  98298. + (core_if->core_params->i2c_enable)) {
  98299. + DWC_PRINTF("SRP Timeout\n");
  98300. +
  98301. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  98302. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  98303. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  98304. + }
  98305. +
  98306. + /* Clear Session Request */
  98307. + gotgctl.d32 = 0;
  98308. + gotgctl.b.sesreq = 1;
  98309. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  98310. + gotgctl.d32, 0);
  98311. +
  98312. + core_if->srp_success = 0;
  98313. + } else {
  98314. + __DWC_ERROR("Device not connected/responding\n");
  98315. + gotgctl.b.sesreq = 0;
  98316. + DWC_WRITE_REG32(addr, gotgctl.d32);
  98317. + }
  98318. + } else if (gotgctl.b.sesreq) {
  98319. + DWC_PRINTF("SRP Timeout\n");
  98320. +
  98321. + __DWC_ERROR("Device not connected/responding\n");
  98322. + gotgctl.b.sesreq = 0;
  98323. + DWC_WRITE_REG32(addr, gotgctl.d32);
  98324. + } else {
  98325. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  98326. + }
  98327. +}
  98328. +
  98329. +/**
  98330. + * Tasklet
  98331. + *
  98332. + */
  98333. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  98334. +
  98335. +static void start_xfer_tasklet_func(void *data)
  98336. +{
  98337. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  98338. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  98339. +
  98340. + int i;
  98341. + depctl_data_t diepctl;
  98342. +
  98343. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  98344. +
  98345. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  98346. +
  98347. + if (pcd->ep0.queue_sof) {
  98348. + pcd->ep0.queue_sof = 0;
  98349. + start_next_request(&pcd->ep0);
  98350. + // break;
  98351. + }
  98352. +
  98353. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  98354. + depctl_data_t diepctl;
  98355. + diepctl.d32 =
  98356. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  98357. +
  98358. + if (pcd->in_ep[i].queue_sof) {
  98359. + pcd->in_ep[i].queue_sof = 0;
  98360. + start_next_request(&pcd->in_ep[i]);
  98361. + // break;
  98362. + }
  98363. + }
  98364. +
  98365. + return;
  98366. +}
  98367. +
  98368. +/**
  98369. + * This function initialized the PCD portion of the driver.
  98370. + *
  98371. + */
  98372. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  98373. +{
  98374. + dwc_otg_pcd_t *pcd = NULL;
  98375. + dwc_otg_dev_if_t *dev_if;
  98376. + int i;
  98377. +
  98378. + /*
  98379. + * Allocate PCD structure
  98380. + */
  98381. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  98382. +
  98383. + if (pcd == NULL) {
  98384. + return NULL;
  98385. + }
  98386. +
  98387. + pcd->lock = DWC_SPINLOCK_ALLOC();
  98388. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  98389. + pcd, core_if);//GRAYG
  98390. + if (!pcd->lock) {
  98391. + DWC_ERROR("Could not allocate lock for pcd");
  98392. + DWC_FREE(pcd);
  98393. + return NULL;
  98394. + }
  98395. + /* Set core_if's lock pointer to hcd->lock */
  98396. + core_if->lock = pcd->lock;
  98397. + pcd->core_if = core_if;
  98398. +
  98399. + dev_if = core_if->dev_if;
  98400. + dev_if->isoc_ep = NULL;
  98401. +
  98402. + if (core_if->hwcfg4.b.ded_fifo_en) {
  98403. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  98404. + } else {
  98405. + DWC_PRINTF("Shared Tx FIFO mode\n");
  98406. + }
  98407. +
  98408. + /*
  98409. + * Initialized the Core for Device mode here if there is nod ADP support.
  98410. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  98411. + */
  98412. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  98413. + dwc_otg_core_dev_init(core_if);
  98414. + }
  98415. +
  98416. + /*
  98417. + * Register the PCD Callbacks.
  98418. + */
  98419. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  98420. +
  98421. + /*
  98422. + * Initialize the DMA buffer for SETUP packets
  98423. + */
  98424. + if (GET_CORE_IF(pcd)->dma_enable) {
  98425. + pcd->setup_pkt =
  98426. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  98427. + &pcd->setup_pkt_dma_handle);
  98428. + if (pcd->setup_pkt == NULL) {
  98429. + DWC_FREE(pcd);
  98430. + return NULL;
  98431. + }
  98432. +
  98433. + pcd->status_buf =
  98434. + DWC_DMA_ALLOC(sizeof(uint16_t),
  98435. + &pcd->status_buf_dma_handle);
  98436. + if (pcd->status_buf == NULL) {
  98437. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  98438. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  98439. + DWC_FREE(pcd);
  98440. + return NULL;
  98441. + }
  98442. +
  98443. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98444. + dev_if->setup_desc_addr[0] =
  98445. + dwc_otg_ep_alloc_desc_chain
  98446. + (&dev_if->dma_setup_desc_addr[0], 1);
  98447. + dev_if->setup_desc_addr[1] =
  98448. + dwc_otg_ep_alloc_desc_chain
  98449. + (&dev_if->dma_setup_desc_addr[1], 1);
  98450. + dev_if->in_desc_addr =
  98451. + dwc_otg_ep_alloc_desc_chain
  98452. + (&dev_if->dma_in_desc_addr, 1);
  98453. + dev_if->out_desc_addr =
  98454. + dwc_otg_ep_alloc_desc_chain
  98455. + (&dev_if->dma_out_desc_addr, 1);
  98456. + pcd->data_terminated = 0;
  98457. +
  98458. + if (dev_if->setup_desc_addr[0] == 0
  98459. + || dev_if->setup_desc_addr[1] == 0
  98460. + || dev_if->in_desc_addr == 0
  98461. + || dev_if->out_desc_addr == 0) {
  98462. +
  98463. + if (dev_if->out_desc_addr)
  98464. + dwc_otg_ep_free_desc_chain
  98465. + (dev_if->out_desc_addr,
  98466. + dev_if->dma_out_desc_addr, 1);
  98467. + if (dev_if->in_desc_addr)
  98468. + dwc_otg_ep_free_desc_chain
  98469. + (dev_if->in_desc_addr,
  98470. + dev_if->dma_in_desc_addr, 1);
  98471. + if (dev_if->setup_desc_addr[1])
  98472. + dwc_otg_ep_free_desc_chain
  98473. + (dev_if->setup_desc_addr[1],
  98474. + dev_if->dma_setup_desc_addr[1], 1);
  98475. + if (dev_if->setup_desc_addr[0])
  98476. + dwc_otg_ep_free_desc_chain
  98477. + (dev_if->setup_desc_addr[0],
  98478. + dev_if->dma_setup_desc_addr[0], 1);
  98479. +
  98480. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  98481. + pcd->setup_pkt,
  98482. + pcd->setup_pkt_dma_handle);
  98483. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  98484. + pcd->status_buf,
  98485. + pcd->status_buf_dma_handle);
  98486. +
  98487. + DWC_FREE(pcd);
  98488. +
  98489. + return NULL;
  98490. + }
  98491. + }
  98492. + } else {
  98493. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  98494. + if (pcd->setup_pkt == NULL) {
  98495. + DWC_FREE(pcd);
  98496. + return NULL;
  98497. + }
  98498. +
  98499. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  98500. + if (pcd->status_buf == NULL) {
  98501. + DWC_FREE(pcd->setup_pkt);
  98502. + DWC_FREE(pcd);
  98503. + return NULL;
  98504. + }
  98505. + }
  98506. +
  98507. + dwc_otg_pcd_reinit(pcd);
  98508. +
  98509. + /* Allocate the cfi object for the PCD */
  98510. +#ifdef DWC_UTE_CFI
  98511. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  98512. + if (NULL == pcd->cfi)
  98513. + goto fail;
  98514. + if (init_cfi(pcd->cfi)) {
  98515. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  98516. + goto fail;
  98517. + }
  98518. +#endif
  98519. +
  98520. + /* Initialize tasklets */
  98521. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  98522. + start_xfer_tasklet_func, pcd);
  98523. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  98524. + do_test_mode, pcd);
  98525. +
  98526. + /* Initialize SRP timer */
  98527. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  98528. +
  98529. + if (core_if->core_params->dev_out_nak) {
  98530. + /**
  98531. + * Initialize xfer timeout timer. Implemented for
  98532. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  98533. + */
  98534. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  98535. + pcd->core_if->ep_xfer_timer[i] =
  98536. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  98537. + &pcd->core_if->ep_xfer_info[i]);
  98538. + }
  98539. + }
  98540. +
  98541. + return pcd;
  98542. +#ifdef DWC_UTE_CFI
  98543. +fail:
  98544. +#endif
  98545. + if (pcd->setup_pkt)
  98546. + DWC_FREE(pcd->setup_pkt);
  98547. + if (pcd->status_buf)
  98548. + DWC_FREE(pcd->status_buf);
  98549. +#ifdef DWC_UTE_CFI
  98550. + if (pcd->cfi)
  98551. + DWC_FREE(pcd->cfi);
  98552. +#endif
  98553. + if (pcd)
  98554. + DWC_FREE(pcd);
  98555. + return NULL;
  98556. +
  98557. +}
  98558. +
  98559. +/**
  98560. + * Remove PCD specific data
  98561. + */
  98562. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  98563. +{
  98564. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  98565. + int i;
  98566. + if (pcd->core_if->core_params->dev_out_nak) {
  98567. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  98568. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  98569. + pcd->core_if->ep_xfer_info[i].state = 0;
  98570. + }
  98571. + }
  98572. +
  98573. + if (GET_CORE_IF(pcd)->dma_enable) {
  98574. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  98575. + pcd->setup_pkt_dma_handle);
  98576. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  98577. + pcd->status_buf_dma_handle);
  98578. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98579. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  98580. + dev_if->dma_setup_desc_addr
  98581. + [0], 1);
  98582. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  98583. + dev_if->dma_setup_desc_addr
  98584. + [1], 1);
  98585. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  98586. + dev_if->dma_in_desc_addr, 1);
  98587. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  98588. + dev_if->dma_out_desc_addr,
  98589. + 1);
  98590. + }
  98591. + } else {
  98592. + DWC_FREE(pcd->setup_pkt);
  98593. + DWC_FREE(pcd->status_buf);
  98594. + }
  98595. + DWC_SPINLOCK_FREE(pcd->lock);
  98596. + /* Set core_if's lock pointer to NULL */
  98597. + pcd->core_if->lock = NULL;
  98598. +
  98599. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  98600. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  98601. + if (pcd->core_if->core_params->dev_out_nak) {
  98602. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  98603. + if (pcd->core_if->ep_xfer_timer[i]) {
  98604. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  98605. + }
  98606. + }
  98607. + }
  98608. +
  98609. +/* Release the CFI object's dynamic memory */
  98610. +#ifdef DWC_UTE_CFI
  98611. + if (pcd->cfi->ops.release) {
  98612. + pcd->cfi->ops.release(pcd->cfi);
  98613. + }
  98614. +#endif
  98615. +
  98616. + DWC_FREE(pcd);
  98617. +}
  98618. +
  98619. +/**
  98620. + * Returns whether registered pcd is dual speed or not
  98621. + */
  98622. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  98623. +{
  98624. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  98625. +
  98626. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  98627. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  98628. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  98629. + (core_if->core_params->ulpi_fs_ls))) {
  98630. + return 0;
  98631. + }
  98632. +
  98633. + return 1;
  98634. +}
  98635. +
  98636. +/**
  98637. + * Returns whether registered pcd is OTG capable or not
  98638. + */
  98639. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  98640. +{
  98641. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  98642. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  98643. +
  98644. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  98645. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  98646. + return 0;
  98647. + }
  98648. +
  98649. + return 1;
  98650. +}
  98651. +
  98652. +/**
  98653. + * This function assigns periodic Tx FIFO to an periodic EP
  98654. + * in shared Tx FIFO mode
  98655. + */
  98656. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  98657. +{
  98658. + uint32_t TxMsk = 1;
  98659. + int i;
  98660. +
  98661. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  98662. + if ((TxMsk & core_if->tx_msk) == 0) {
  98663. + core_if->tx_msk |= TxMsk;
  98664. + return i + 1;
  98665. + }
  98666. + TxMsk <<= 1;
  98667. + }
  98668. + return 0;
  98669. +}
  98670. +
  98671. +/**
  98672. + * This function assigns periodic Tx FIFO to an periodic EP
  98673. + * in shared Tx FIFO mode
  98674. + */
  98675. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  98676. +{
  98677. + uint32_t PerTxMsk = 1;
  98678. + int i;
  98679. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  98680. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  98681. + core_if->p_tx_msk |= PerTxMsk;
  98682. + return i + 1;
  98683. + }
  98684. + PerTxMsk <<= 1;
  98685. + }
  98686. + return 0;
  98687. +}
  98688. +
  98689. +/**
  98690. + * This function releases periodic Tx FIFO
  98691. + * in shared Tx FIFO mode
  98692. + */
  98693. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  98694. + uint32_t fifo_num)
  98695. +{
  98696. + core_if->p_tx_msk =
  98697. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  98698. +}
  98699. +
  98700. +/**
  98701. + * This function releases periodic Tx FIFO
  98702. + * in shared Tx FIFO mode
  98703. + */
  98704. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  98705. +{
  98706. + core_if->tx_msk =
  98707. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  98708. +}
  98709. +
  98710. +/**
  98711. + * This function is being called from gadget
  98712. + * to enable PCD endpoint.
  98713. + */
  98714. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  98715. + const uint8_t * ep_desc, void *usb_ep)
  98716. +{
  98717. + int num, dir;
  98718. + dwc_otg_pcd_ep_t *ep = NULL;
  98719. + const usb_endpoint_descriptor_t *desc;
  98720. + dwc_irqflags_t flags;
  98721. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  98722. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  98723. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  98724. + int retval = 0;
  98725. + int i, epcount;
  98726. +
  98727. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  98728. +
  98729. + if (!desc) {
  98730. + pcd->ep0.priv = usb_ep;
  98731. + ep = &pcd->ep0;
  98732. + retval = -DWC_E_INVALID;
  98733. + goto out;
  98734. + }
  98735. +
  98736. + num = UE_GET_ADDR(desc->bEndpointAddress);
  98737. + dir = UE_GET_DIR(desc->bEndpointAddress);
  98738. +
  98739. + if (!desc->wMaxPacketSize) {
  98740. + DWC_WARN("bad maxpacketsize\n");
  98741. + retval = -DWC_E_INVALID;
  98742. + goto out;
  98743. + }
  98744. +
  98745. + if (dir == UE_DIR_IN) {
  98746. + epcount = pcd->core_if->dev_if->num_in_eps;
  98747. + for (i = 0; i < epcount; i++) {
  98748. + if (num == pcd->in_ep[i].dwc_ep.num) {
  98749. + ep = &pcd->in_ep[i];
  98750. + break;
  98751. + }
  98752. + }
  98753. + } else {
  98754. + epcount = pcd->core_if->dev_if->num_out_eps;
  98755. + for (i = 0; i < epcount; i++) {
  98756. + if (num == pcd->out_ep[i].dwc_ep.num) {
  98757. + ep = &pcd->out_ep[i];
  98758. + break;
  98759. + }
  98760. + }
  98761. + }
  98762. +
  98763. + if (!ep) {
  98764. + DWC_WARN("bad address\n");
  98765. + retval = -DWC_E_INVALID;
  98766. + goto out;
  98767. + }
  98768. +
  98769. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98770. +
  98771. + ep->desc = desc;
  98772. + ep->priv = usb_ep;
  98773. +
  98774. + /*
  98775. + * Activate the EP
  98776. + */
  98777. + ep->stopped = 0;
  98778. +
  98779. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  98780. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  98781. +
  98782. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  98783. +
  98784. + if (ep->dwc_ep.is_in) {
  98785. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98786. + ep->dwc_ep.tx_fifo_num = 0;
  98787. +
  98788. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  98789. + /*
  98790. + * if ISOC EP then assign a Periodic Tx FIFO.
  98791. + */
  98792. + ep->dwc_ep.tx_fifo_num =
  98793. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  98794. + }
  98795. + } else {
  98796. + /*
  98797. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  98798. + */
  98799. + ep->dwc_ep.tx_fifo_num =
  98800. + assign_tx_fifo(GET_CORE_IF(pcd));
  98801. + }
  98802. +
  98803. + /* Calculating EP info controller base address */
  98804. + if (ep->dwc_ep.tx_fifo_num
  98805. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98806. + gdfifocfg.d32 =
  98807. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  98808. + core_global_regs->gdfifocfg);
  98809. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  98810. + dptxfsiz.d32 =
  98811. + (DWC_READ_REG32
  98812. + (&GET_CORE_IF(pcd)->core_global_regs->
  98813. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  98814. + gdfifocfg.b.epinfobase =
  98815. + gdfifocfgbase.d32 + dptxfsiz.d32;
  98816. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  98817. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  98818. + core_global_regs->gdfifocfg,
  98819. + gdfifocfg.d32);
  98820. + }
  98821. + }
  98822. + }
  98823. + /* Set initial data PID. */
  98824. + if (ep->dwc_ep.type == UE_BULK) {
  98825. + ep->dwc_ep.data_pid_start = 0;
  98826. + }
  98827. +
  98828. + /* Alloc DMA Descriptors */
  98829. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98830. +#ifndef DWC_UTE_PER_IO
  98831. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  98832. +#endif
  98833. + ep->dwc_ep.desc_addr =
  98834. + dwc_otg_ep_alloc_desc_chain(&ep->
  98835. + dwc_ep.dma_desc_addr,
  98836. + MAX_DMA_DESC_CNT);
  98837. + if (!ep->dwc_ep.desc_addr) {
  98838. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  98839. + __func__);
  98840. + retval = -DWC_E_SHUTDOWN;
  98841. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98842. + goto out;
  98843. + }
  98844. +#ifndef DWC_UTE_PER_IO
  98845. + }
  98846. +#endif
  98847. + }
  98848. +
  98849. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  98850. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  98851. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  98852. +#ifdef DWC_UTE_PER_IO
  98853. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  98854. +#endif
  98855. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  98856. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  98857. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  98858. + }
  98859. +
  98860. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  98861. +
  98862. +#ifdef DWC_UTE_CFI
  98863. + if (pcd->cfi->ops.ep_enable) {
  98864. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  98865. + }
  98866. +#endif
  98867. +
  98868. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98869. +
  98870. +out:
  98871. + return retval;
  98872. +}
  98873. +
  98874. +/**
  98875. + * This function is being called from gadget
  98876. + * to disable PCD endpoint.
  98877. + */
  98878. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  98879. +{
  98880. + dwc_otg_pcd_ep_t *ep;
  98881. + dwc_irqflags_t flags;
  98882. + dwc_otg_dev_dma_desc_t *desc_addr;
  98883. + dwc_dma_t dma_desc_addr;
  98884. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  98885. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  98886. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  98887. +
  98888. + ep = get_ep_from_handle(pcd, ep_handle);
  98889. +
  98890. + if (!ep || !ep->desc) {
  98891. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  98892. + return -DWC_E_INVALID;
  98893. + }
  98894. +
  98895. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  98896. +
  98897. + dwc_otg_request_nuke(ep);
  98898. +
  98899. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  98900. + if (pcd->core_if->core_params->dev_out_nak) {
  98901. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  98902. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  98903. + }
  98904. + ep->desc = NULL;
  98905. + ep->stopped = 1;
  98906. +
  98907. + gdfifocfg.d32 =
  98908. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  98909. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  98910. +
  98911. + if (ep->dwc_ep.is_in) {
  98912. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98913. + /* Flush the Tx FIFO */
  98914. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  98915. + ep->dwc_ep.tx_fifo_num);
  98916. + }
  98917. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  98918. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  98919. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  98920. + /* Decreasing EPinfo Base Addr */
  98921. + dptxfsiz.d32 =
  98922. + (DWC_READ_REG32
  98923. + (&GET_CORE_IF(pcd)->
  98924. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  98925. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  98926. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  98927. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  98928. + gdfifocfg.d32);
  98929. + }
  98930. + }
  98931. + }
  98932. +
  98933. + /* Free DMA Descriptors */
  98934. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  98935. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  98936. + desc_addr = ep->dwc_ep.desc_addr;
  98937. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  98938. +
  98939. + /* Cannot call dma_free_coherent() with IRQs disabled */
  98940. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98941. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  98942. + MAX_DMA_DESC_CNT);
  98943. +
  98944. + goto out_unlocked;
  98945. + }
  98946. + }
  98947. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  98948. +
  98949. +out_unlocked:
  98950. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  98951. + ep->dwc_ep.is_in ? "IN" : "OUT");
  98952. + return 0;
  98953. +
  98954. +}
  98955. +
  98956. +/******************************************************************************/
  98957. +#ifdef DWC_UTE_PER_IO
  98958. +
  98959. +/**
  98960. + * Free the request and its extended parts
  98961. + *
  98962. + */
  98963. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  98964. +{
  98965. + DWC_FREE(req->ext_req.per_io_frame_descs);
  98966. + DWC_FREE(req);
  98967. +}
  98968. +
  98969. +/**
  98970. + * Start the next request in the endpoint's queue.
  98971. + *
  98972. + */
  98973. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  98974. + dwc_otg_pcd_ep_t * ep)
  98975. +{
  98976. + int i;
  98977. + dwc_otg_pcd_request_t *req = NULL;
  98978. + dwc_ep_t *dwcep = NULL;
  98979. + struct dwc_iso_xreq_port *ereq = NULL;
  98980. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  98981. + uint16_t nat;
  98982. + depctl_data_t diepctl;
  98983. +
  98984. + dwcep = &ep->dwc_ep;
  98985. +
  98986. + if (dwcep->xiso_active_xfers > 0) {
  98987. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  98988. + DWC_WARN("There are currently active transfers for EP%d \
  98989. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  98990. + dwcep->xiso_queued_xfers);
  98991. +#endif
  98992. + return 0;
  98993. + }
  98994. +
  98995. + nat = UGETW(ep->desc->wMaxPacketSize);
  98996. + nat = (nat >> 11) & 0x03;
  98997. +
  98998. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  98999. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  99000. + ereq = &req->ext_req;
  99001. + ep->stopped = 0;
  99002. +
  99003. + /* Get the frame number */
  99004. + dwcep->xiso_frame_num =
  99005. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  99006. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  99007. +
  99008. + ddesc_iso = ereq->per_io_frame_descs;
  99009. +
  99010. + if (dwcep->is_in) {
  99011. + /* Setup DMA Descriptor chain for IN Isoc request */
  99012. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  99013. + //if ((i % (nat + 1)) == 0)
  99014. + if ( i > 0 )
  99015. + dwcep->xiso_frame_num =
  99016. + (dwcep->xiso_bInterval +
  99017. + dwcep->xiso_frame_num) & 0x3FFF;
  99018. + dwcep->desc_addr[i].buf =
  99019. + req->dma + ddesc_iso[i].offset;
  99020. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  99021. + ddesc_iso[i].length;
  99022. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  99023. + dwcep->xiso_frame_num;
  99024. + dwcep->desc_addr[i].status.b_iso_in.bs =
  99025. + BS_HOST_READY;
  99026. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  99027. + dwcep->desc_addr[i].status.b_iso_in.sp =
  99028. + (ddesc_iso[i].length %
  99029. + dwcep->maxpacket) ? 1 : 0;
  99030. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  99031. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  99032. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  99033. +
  99034. + /* Process the last descriptor */
  99035. + if (i == ereq->pio_pkt_count - 1) {
  99036. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  99037. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  99038. + }
  99039. + }
  99040. +
  99041. + /* Setup and start the transfer for this endpoint */
  99042. + dwcep->xiso_active_xfers++;
  99043. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  99044. + in_ep_regs[dwcep->num]->diepdma,
  99045. + dwcep->dma_desc_addr);
  99046. + diepctl.d32 = 0;
  99047. + diepctl.b.epena = 1;
  99048. + diepctl.b.cnak = 1;
  99049. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  99050. + in_ep_regs[dwcep->num]->diepctl, 0,
  99051. + diepctl.d32);
  99052. + } else {
  99053. + /* Setup DMA Descriptor chain for OUT Isoc request */
  99054. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  99055. + //if ((i % (nat + 1)) == 0)
  99056. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  99057. + dwcep->xiso_frame_num) & 0x3FFF;
  99058. + dwcep->desc_addr[i].buf =
  99059. + req->dma + ddesc_iso[i].offset;
  99060. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  99061. + ddesc_iso[i].length;
  99062. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  99063. + dwcep->xiso_frame_num;
  99064. + dwcep->desc_addr[i].status.b_iso_out.bs =
  99065. + BS_HOST_READY;
  99066. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  99067. + dwcep->desc_addr[i].status.b_iso_out.sp =
  99068. + (ddesc_iso[i].length %
  99069. + dwcep->maxpacket) ? 1 : 0;
  99070. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  99071. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  99072. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  99073. +
  99074. + /* Process the last descriptor */
  99075. + if (i == ereq->pio_pkt_count - 1) {
  99076. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  99077. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  99078. + }
  99079. + }
  99080. +
  99081. + /* Setup and start the transfer for this endpoint */
  99082. + dwcep->xiso_active_xfers++;
  99083. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  99084. + dev_if->out_ep_regs[dwcep->num]->
  99085. + doepdma, dwcep->dma_desc_addr);
  99086. + diepctl.d32 = 0;
  99087. + diepctl.b.epena = 1;
  99088. + diepctl.b.cnak = 1;
  99089. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  99090. + dev_if->out_ep_regs[dwcep->num]->
  99091. + doepctl, 0, diepctl.d32);
  99092. + }
  99093. +
  99094. + } else {
  99095. + ep->stopped = 1;
  99096. + }
  99097. +
  99098. + return 0;
  99099. +}
  99100. +
  99101. +/**
  99102. + * - Remove the request from the queue
  99103. + */
  99104. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  99105. +{
  99106. + dwc_otg_pcd_request_t *req = NULL;
  99107. + struct dwc_iso_xreq_port *ereq = NULL;
  99108. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  99109. + dwc_ep_t *dwcep = NULL;
  99110. + int i;
  99111. +
  99112. + //DWC_DEBUG();
  99113. + dwcep = &ep->dwc_ep;
  99114. +
  99115. + /* Get the first pending request from the queue */
  99116. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  99117. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  99118. + if (!req) {
  99119. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  99120. + return;
  99121. + }
  99122. + dwcep->xiso_active_xfers--;
  99123. + dwcep->xiso_queued_xfers--;
  99124. + /* Remove this request from the queue */
  99125. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  99126. + } else {
  99127. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  99128. + return;
  99129. + }
  99130. +
  99131. + ep->stopped = 1;
  99132. + ereq = &req->ext_req;
  99133. + ddesc_iso = ereq->per_io_frame_descs;
  99134. +
  99135. + if (dwcep->xiso_active_xfers < 0) {
  99136. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  99137. + dwcep->xiso_active_xfers);
  99138. + }
  99139. +
  99140. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  99141. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  99142. + if (dwcep->is_in) { /* IN endpoints */
  99143. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  99144. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  99145. + ddesc_iso[i].status =
  99146. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  99147. + } else { /* OUT endpoints */
  99148. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  99149. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  99150. + ddesc_iso[i].status =
  99151. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  99152. + }
  99153. + }
  99154. +
  99155. + DWC_SPINUNLOCK(ep->pcd->lock);
  99156. +
  99157. + /* Call the completion function in the non-portable logic */
  99158. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  99159. + &req->ext_req);
  99160. +
  99161. + DWC_SPINLOCK(ep->pcd->lock);
  99162. +
  99163. + /* Free the request - specific freeing needed for extended request object */
  99164. + dwc_pcd_xiso_ereq_free(ep, req);
  99165. +
  99166. + /* Start the next request */
  99167. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  99168. +
  99169. + return;
  99170. +}
  99171. +
  99172. +/**
  99173. + * Create and initialize the Isoc pkt descriptors of the extended request.
  99174. + *
  99175. + */
  99176. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  99177. + void *ereq_nonport,
  99178. + int atomic_alloc)
  99179. +{
  99180. + struct dwc_iso_xreq_port *ereq = NULL;
  99181. + struct dwc_iso_xreq_port *req_mapped = NULL;
  99182. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  99183. + uint32_t pkt_count;
  99184. + int i;
  99185. +
  99186. + ereq = &req->ext_req;
  99187. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  99188. + pkt_count = req_mapped->pio_pkt_count;
  99189. +
  99190. + /* Create the isoc descs */
  99191. + if (atomic_alloc) {
  99192. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  99193. + } else {
  99194. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  99195. + }
  99196. +
  99197. + if (!ipds) {
  99198. + DWC_ERROR("Failed to allocate isoc descriptors");
  99199. + return -DWC_E_NO_MEMORY;
  99200. + }
  99201. +
  99202. + /* Initialize the extended request fields */
  99203. + ereq->per_io_frame_descs = ipds;
  99204. + ereq->error_count = 0;
  99205. + ereq->pio_alloc_pkt_count = pkt_count;
  99206. + ereq->pio_pkt_count = pkt_count;
  99207. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  99208. +
  99209. + /* Init the Isoc descriptors */
  99210. + for (i = 0; i < pkt_count; i++) {
  99211. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  99212. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  99213. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  99214. + ipds[i].actual_length =
  99215. + req_mapped->per_io_frame_descs[i].actual_length;
  99216. + }
  99217. +
  99218. + return 0;
  99219. +}
  99220. +
  99221. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  99222. +{
  99223. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  99224. + int i;
  99225. +
  99226. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  99227. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  99228. + DWC_DEBUG("error_count=%d", ereq->error_count);
  99229. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  99230. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  99231. + DWC_DEBUG("res=%d", ereq->res);
  99232. +
  99233. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  99234. + xfd = &ereq->per_io_frame_descs[0];
  99235. + DWC_DEBUG("FD #%d", i);
  99236. +
  99237. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  99238. + DWC_DEBUG("xfd->length=%d", xfd->length);
  99239. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  99240. + DWC_DEBUG("xfd->status=%d", xfd->status);
  99241. + }
  99242. +}
  99243. +
  99244. +/**
  99245. + *
  99246. + */
  99247. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  99248. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  99249. + int zero, void *req_handle, int atomic_alloc,
  99250. + void *ereq_nonport)
  99251. +{
  99252. + dwc_otg_pcd_request_t *req = NULL;
  99253. + dwc_otg_pcd_ep_t *ep;
  99254. + dwc_irqflags_t flags;
  99255. + int res;
  99256. +
  99257. + ep = get_ep_from_handle(pcd, ep_handle);
  99258. + if (!ep) {
  99259. + DWC_WARN("bad ep\n");
  99260. + return -DWC_E_INVALID;
  99261. + }
  99262. +
  99263. + /* We support this extension only for DDMA mode */
  99264. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  99265. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  99266. + return -DWC_E_INVALID;
  99267. +
  99268. + /* Create a dwc_otg_pcd_request_t object */
  99269. + if (atomic_alloc) {
  99270. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  99271. + } else {
  99272. + req = DWC_ALLOC(sizeof(*req));
  99273. + }
  99274. +
  99275. + if (!req) {
  99276. + return -DWC_E_NO_MEMORY;
  99277. + }
  99278. +
  99279. + /* Create the Isoc descs for this request which shall be the exact match
  99280. + * of the structure sent to us from the non-portable logic */
  99281. + res =
  99282. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  99283. + if (res) {
  99284. + DWC_WARN("Failed to init the Isoc descriptors");
  99285. + DWC_FREE(req);
  99286. + return res;
  99287. + }
  99288. +
  99289. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99290. +
  99291. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  99292. + req->buf = buf;
  99293. + req->dma = dma_buf;
  99294. + req->length = buflen;
  99295. + req->sent_zlp = zero;
  99296. + req->priv = req_handle;
  99297. +
  99298. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99299. + ep->dwc_ep.dma_addr = dma_buf;
  99300. + ep->dwc_ep.start_xfer_buff = buf;
  99301. + ep->dwc_ep.xfer_buff = buf;
  99302. + ep->dwc_ep.xfer_len = 0;
  99303. + ep->dwc_ep.xfer_count = 0;
  99304. + ep->dwc_ep.sent_zlp = 0;
  99305. + ep->dwc_ep.total_len = buflen;
  99306. +
  99307. + /* Add this request to the tail */
  99308. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  99309. + ep->dwc_ep.xiso_queued_xfers++;
  99310. +
  99311. +//DWC_DEBUG("CP_0");
  99312. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  99313. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  99314. +//prn_ext_request(&req->ext_req);
  99315. +
  99316. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99317. +
  99318. + /* If the req->status == ASAP then check if there is any active transfer
  99319. + * for this endpoint. If no active transfers, then get the first entry
  99320. + * from the queue and start that transfer
  99321. + */
  99322. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  99323. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  99324. + if (res) {
  99325. + DWC_WARN("Failed to start the next Isoc transfer");
  99326. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99327. + DWC_FREE(req);
  99328. + return res;
  99329. + }
  99330. + }
  99331. +
  99332. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99333. + return 0;
  99334. +}
  99335. +
  99336. +#endif
  99337. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  99338. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  99339. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  99340. + int zero, void *req_handle, int atomic_alloc)
  99341. +{
  99342. + dwc_irqflags_t flags;
  99343. + dwc_otg_pcd_request_t *req;
  99344. + dwc_otg_pcd_ep_t *ep;
  99345. + uint32_t max_transfer;
  99346. +
  99347. + ep = get_ep_from_handle(pcd, ep_handle);
  99348. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  99349. + DWC_WARN("bad ep\n");
  99350. + return -DWC_E_INVALID;
  99351. + }
  99352. +
  99353. + if (atomic_alloc) {
  99354. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  99355. + } else {
  99356. + req = DWC_ALLOC(sizeof(*req));
  99357. + }
  99358. +
  99359. + if (!req) {
  99360. + return -DWC_E_NO_MEMORY;
  99361. + }
  99362. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  99363. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  99364. + if (ep->dwc_ep.num != 0) {
  99365. + DWC_ERROR("queue req %p, len %d buf %p\n",
  99366. + req_handle, buflen, buf);
  99367. + }
  99368. + }
  99369. +
  99370. + req->buf = buf;
  99371. + req->dma = dma_buf;
  99372. + req->length = buflen;
  99373. + req->sent_zlp = zero;
  99374. + req->priv = req_handle;
  99375. + req->dw_align_buf = NULL;
  99376. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  99377. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  99378. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  99379. + &req->dw_align_buf_dma);
  99380. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99381. +
  99382. + /*
  99383. + * After adding request to the queue for IN ISOC wait for In Token Received
  99384. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  99385. + * Received when EP is disabled interrupt to obtain starting microframe
  99386. + * (odd/even) start transfer
  99387. + */
  99388. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  99389. + if (req != 0) {
  99390. + depctl_data_t depctl = {.d32 =
  99391. + DWC_READ_REG32(&pcd->core_if->dev_if->
  99392. + in_ep_regs[ep->dwc_ep.num]->
  99393. + diepctl) };
  99394. + ++pcd->request_pending;
  99395. +
  99396. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  99397. + if (ep->dwc_ep.is_in) {
  99398. + depctl.b.cnak = 1;
  99399. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  99400. + in_ep_regs[ep->dwc_ep.num]->
  99401. + diepctl, depctl.d32);
  99402. + }
  99403. +
  99404. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99405. + }
  99406. + return 0;
  99407. + }
  99408. +
  99409. + /*
  99410. + * For EP0 IN without premature status, zlp is required?
  99411. + */
  99412. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  99413. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  99414. + //_req->zero = 1;
  99415. + }
  99416. +
  99417. + /* Start the transfer */
  99418. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  99419. + /* EP0 Transfer? */
  99420. + if (ep->dwc_ep.num == 0) {
  99421. + switch (pcd->ep0state) {
  99422. + case EP0_IN_DATA_PHASE:
  99423. + DWC_DEBUGPL(DBG_PCD,
  99424. + "%s ep0: EP0_IN_DATA_PHASE\n",
  99425. + __func__);
  99426. + break;
  99427. +
  99428. + case EP0_OUT_DATA_PHASE:
  99429. + DWC_DEBUGPL(DBG_PCD,
  99430. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  99431. + __func__);
  99432. + if (pcd->request_config) {
  99433. + /* Complete STATUS PHASE */
  99434. + ep->dwc_ep.is_in = 1;
  99435. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  99436. + }
  99437. + break;
  99438. +
  99439. + case EP0_IN_STATUS_PHASE:
  99440. + DWC_DEBUGPL(DBG_PCD,
  99441. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  99442. + __func__);
  99443. + break;
  99444. +
  99445. + default:
  99446. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  99447. + pcd->ep0state);
  99448. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99449. + return -DWC_E_SHUTDOWN;
  99450. + }
  99451. +
  99452. + ep->dwc_ep.dma_addr = dma_buf;
  99453. + ep->dwc_ep.start_xfer_buff = buf;
  99454. + ep->dwc_ep.xfer_buff = buf;
  99455. + ep->dwc_ep.xfer_len = buflen;
  99456. + ep->dwc_ep.xfer_count = 0;
  99457. + ep->dwc_ep.sent_zlp = 0;
  99458. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  99459. +
  99460. + if (zero) {
  99461. + if ((ep->dwc_ep.xfer_len %
  99462. + ep->dwc_ep.maxpacket == 0)
  99463. + && (ep->dwc_ep.xfer_len != 0)) {
  99464. + ep->dwc_ep.sent_zlp = 1;
  99465. + }
  99466. +
  99467. + }
  99468. +
  99469. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  99470. + &ep->dwc_ep);
  99471. + } // non-ep0 endpoints
  99472. + else {
  99473. +#ifdef DWC_UTE_CFI
  99474. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  99475. + /* store the request length */
  99476. + ep->dwc_ep.cfi_req_len = buflen;
  99477. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  99478. + ep, req);
  99479. + } else {
  99480. +#endif
  99481. + max_transfer =
  99482. + GET_CORE_IF(ep->pcd)->core_params->
  99483. + max_transfer_size;
  99484. +
  99485. + /* Setup and start the Transfer */
  99486. + if (req->dw_align_buf){
  99487. + if (ep->dwc_ep.is_in)
  99488. + dwc_memcpy(req->dw_align_buf,
  99489. + buf, buflen);
  99490. + ep->dwc_ep.dma_addr =
  99491. + req->dw_align_buf_dma;
  99492. + ep->dwc_ep.start_xfer_buff =
  99493. + req->dw_align_buf;
  99494. + ep->dwc_ep.xfer_buff =
  99495. + req->dw_align_buf;
  99496. + } else {
  99497. + ep->dwc_ep.dma_addr = dma_buf;
  99498. + ep->dwc_ep.start_xfer_buff = buf;
  99499. + ep->dwc_ep.xfer_buff = buf;
  99500. + }
  99501. + ep->dwc_ep.xfer_len = 0;
  99502. + ep->dwc_ep.xfer_count = 0;
  99503. + ep->dwc_ep.sent_zlp = 0;
  99504. + ep->dwc_ep.total_len = buflen;
  99505. +
  99506. + ep->dwc_ep.maxxfer = max_transfer;
  99507. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  99508. + uint32_t out_max_xfer =
  99509. + DDMA_MAX_TRANSFER_SIZE -
  99510. + (DDMA_MAX_TRANSFER_SIZE % 4);
  99511. + if (ep->dwc_ep.is_in) {
  99512. + if (ep->dwc_ep.maxxfer >
  99513. + DDMA_MAX_TRANSFER_SIZE) {
  99514. + ep->dwc_ep.maxxfer =
  99515. + DDMA_MAX_TRANSFER_SIZE;
  99516. + }
  99517. + } else {
  99518. + if (ep->dwc_ep.maxxfer >
  99519. + out_max_xfer) {
  99520. + ep->dwc_ep.maxxfer =
  99521. + out_max_xfer;
  99522. + }
  99523. + }
  99524. + }
  99525. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  99526. + ep->dwc_ep.maxxfer -=
  99527. + (ep->dwc_ep.maxxfer %
  99528. + ep->dwc_ep.maxpacket);
  99529. + }
  99530. +
  99531. + if (zero) {
  99532. + if ((ep->dwc_ep.total_len %
  99533. + ep->dwc_ep.maxpacket == 0)
  99534. + && (ep->dwc_ep.total_len != 0)) {
  99535. + ep->dwc_ep.sent_zlp = 1;
  99536. + }
  99537. + }
  99538. +#ifdef DWC_UTE_CFI
  99539. + }
  99540. +#endif
  99541. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  99542. + &ep->dwc_ep);
  99543. + }
  99544. + }
  99545. +
  99546. + if (req != 0) {
  99547. + ++pcd->request_pending;
  99548. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  99549. + if (ep->dwc_ep.is_in && ep->stopped
  99550. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  99551. + /** @todo NGS Create a function for this. */
  99552. + diepmsk_data_t diepmsk = {.d32 = 0 };
  99553. + diepmsk.b.intktxfemp = 1;
  99554. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  99555. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  99556. + dev_if->dev_global_regs->diepeachintmsk
  99557. + [ep->dwc_ep.num], 0,
  99558. + diepmsk.d32);
  99559. + } else {
  99560. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  99561. + dev_if->dev_global_regs->
  99562. + diepmsk, 0, diepmsk.d32);
  99563. + }
  99564. +
  99565. + }
  99566. + }
  99567. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99568. +
  99569. + return 0;
  99570. +}
  99571. +
  99572. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  99573. + void *req_handle)
  99574. +{
  99575. + dwc_irqflags_t flags;
  99576. + dwc_otg_pcd_request_t *req;
  99577. + dwc_otg_pcd_ep_t *ep;
  99578. +
  99579. + ep = get_ep_from_handle(pcd, ep_handle);
  99580. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  99581. + DWC_WARN("bad argument\n");
  99582. + return -DWC_E_INVALID;
  99583. + }
  99584. +
  99585. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99586. +
  99587. + /* make sure it's actually queued on this endpoint */
  99588. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  99589. + if (req->priv == (void *)req_handle) {
  99590. + break;
  99591. + }
  99592. + }
  99593. +
  99594. + if (req->priv != (void *)req_handle) {
  99595. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99596. + return -DWC_E_INVALID;
  99597. + }
  99598. +
  99599. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  99600. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  99601. + } else {
  99602. + req = NULL;
  99603. + }
  99604. +
  99605. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99606. +
  99607. + return req ? 0 : -DWC_E_SHUTDOWN;
  99608. +
  99609. +}
  99610. +
  99611. +/**
  99612. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  99613. + *
  99614. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  99615. + * requests. If the gadget driver clears the halt status, it will
  99616. + * automatically unwedge the endpoint.
  99617. + *
  99618. + * Returns zero on success, else negative DWC error code.
  99619. + */
  99620. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  99621. +{
  99622. + dwc_otg_pcd_ep_t *ep;
  99623. + dwc_irqflags_t flags;
  99624. + int retval = 0;
  99625. +
  99626. + ep = get_ep_from_handle(pcd, ep_handle);
  99627. +
  99628. + if ((!ep->desc && ep != &pcd->ep0) ||
  99629. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  99630. + DWC_WARN("%s, bad ep\n", __func__);
  99631. + return -DWC_E_INVALID;
  99632. + }
  99633. +
  99634. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99635. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  99636. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  99637. + ep->dwc_ep.is_in ? "IN" : "OUT");
  99638. + retval = -DWC_E_AGAIN;
  99639. + } else {
  99640. + /* This code needs to be reviewed */
  99641. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  99642. + dtxfsts_data_t txstatus;
  99643. + fifosize_data_t txfifosize;
  99644. +
  99645. + txfifosize.d32 =
  99646. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  99647. + core_global_regs->dtxfsiz[ep->dwc_ep.
  99648. + tx_fifo_num]);
  99649. + txstatus.d32 =
  99650. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  99651. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  99652. + dtxfsts);
  99653. +
  99654. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  99655. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  99656. + retval = -DWC_E_AGAIN;
  99657. + } else {
  99658. + if (ep->dwc_ep.num == 0) {
  99659. + pcd->ep0state = EP0_STALL;
  99660. + }
  99661. +
  99662. + ep->stopped = 1;
  99663. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  99664. + &ep->dwc_ep);
  99665. + }
  99666. + } else {
  99667. + if (ep->dwc_ep.num == 0) {
  99668. + pcd->ep0state = EP0_STALL;
  99669. + }
  99670. +
  99671. + ep->stopped = 1;
  99672. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99673. + }
  99674. + }
  99675. +
  99676. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99677. +
  99678. + return retval;
  99679. +}
  99680. +
  99681. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  99682. +{
  99683. + dwc_otg_pcd_ep_t *ep;
  99684. + dwc_irqflags_t flags;
  99685. + int retval = 0;
  99686. +
  99687. + ep = get_ep_from_handle(pcd, ep_handle);
  99688. +
  99689. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  99690. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  99691. + DWC_WARN("%s, bad ep\n", __func__);
  99692. + return -DWC_E_INVALID;
  99693. + }
  99694. +
  99695. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99696. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  99697. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  99698. + ep->dwc_ep.is_in ? "IN" : "OUT");
  99699. + retval = -DWC_E_AGAIN;
  99700. + } else if (value == 0) {
  99701. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99702. + } else if (value == 1) {
  99703. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  99704. + dtxfsts_data_t txstatus;
  99705. + fifosize_data_t txfifosize;
  99706. +
  99707. + txfifosize.d32 =
  99708. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  99709. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  99710. + txstatus.d32 =
  99711. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  99712. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  99713. +
  99714. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  99715. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  99716. + retval = -DWC_E_AGAIN;
  99717. + } else {
  99718. + if (ep->dwc_ep.num == 0) {
  99719. + pcd->ep0state = EP0_STALL;
  99720. + }
  99721. +
  99722. + ep->stopped = 1;
  99723. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  99724. + &ep->dwc_ep);
  99725. + }
  99726. + } else {
  99727. + if (ep->dwc_ep.num == 0) {
  99728. + pcd->ep0state = EP0_STALL;
  99729. + }
  99730. +
  99731. + ep->stopped = 1;
  99732. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  99733. + }
  99734. + } else if (value == 2) {
  99735. + ep->dwc_ep.stall_clear_flag = 0;
  99736. + } else if (value == 3) {
  99737. + ep->dwc_ep.stall_clear_flag = 1;
  99738. + }
  99739. +
  99740. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99741. +
  99742. + return retval;
  99743. +}
  99744. +
  99745. +/**
  99746. + * This function initiates remote wakeup of the host from suspend state.
  99747. + */
  99748. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  99749. +{
  99750. + dctl_data_t dctl = { 0 };
  99751. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99752. + dsts_data_t dsts;
  99753. +
  99754. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  99755. + if (!dsts.b.suspsts) {
  99756. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  99757. + }
  99758. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  99759. + if (pcd->remote_wakeup_enable) {
  99760. + if (set) {
  99761. +
  99762. + if (core_if->adp_enable) {
  99763. + gpwrdn_data_t gpwrdn;
  99764. +
  99765. + dwc_otg_adp_probe_stop(core_if);
  99766. +
  99767. + /* Mask SRP detected interrupt from Power Down Logic */
  99768. + gpwrdn.d32 = 0;
  99769. + gpwrdn.b.srp_det_msk = 1;
  99770. + DWC_MODIFY_REG32(&core_if->
  99771. + core_global_regs->gpwrdn,
  99772. + gpwrdn.d32, 0);
  99773. +
  99774. + /* Disable Power Down Logic */
  99775. + gpwrdn.d32 = 0;
  99776. + gpwrdn.b.pmuactv = 1;
  99777. + DWC_MODIFY_REG32(&core_if->
  99778. + core_global_regs->gpwrdn,
  99779. + gpwrdn.d32, 0);
  99780. +
  99781. + /*
  99782. + * Initialize the Core for Device mode.
  99783. + */
  99784. + core_if->op_state = B_PERIPHERAL;
  99785. + dwc_otg_core_init(core_if);
  99786. + dwc_otg_enable_global_interrupts(core_if);
  99787. + cil_pcd_start(core_if);
  99788. +
  99789. + dwc_otg_initiate_srp(core_if);
  99790. + }
  99791. +
  99792. + dctl.b.rmtwkupsig = 1;
  99793. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  99794. + dctl, 0, dctl.d32);
  99795. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  99796. +
  99797. + dwc_mdelay(2);
  99798. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  99799. + dctl, dctl.d32, 0);
  99800. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  99801. + }
  99802. + } else {
  99803. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  99804. + }
  99805. +}
  99806. +
  99807. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99808. +/**
  99809. + * This function initiates remote wakeup of the host from L1 sleep state.
  99810. + */
  99811. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  99812. +{
  99813. + glpmcfg_data_t lpmcfg;
  99814. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99815. +
  99816. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99817. +
  99818. + /* Check if we are in L1 state */
  99819. + if (!lpmcfg.b.prt_sleep_sts) {
  99820. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  99821. + return;
  99822. + }
  99823. +
  99824. + /* Check if host allows remote wakeup */
  99825. + if (!lpmcfg.b.rem_wkup_en) {
  99826. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  99827. + return;
  99828. + }
  99829. +
  99830. + /* Check if Resume OK */
  99831. + if (!lpmcfg.b.sleep_state_resumeok) {
  99832. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  99833. + return;
  99834. + }
  99835. +
  99836. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  99837. + lpmcfg.b.en_utmi_sleep = 0;
  99838. + lpmcfg.b.hird_thres &= (~(1 << 4));
  99839. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  99840. +
  99841. + if (set) {
  99842. + dctl_data_t dctl = {.d32 = 0 };
  99843. + dctl.b.rmtwkupsig = 1;
  99844. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  99845. + * Hardware will automatically clear this bit.
  99846. + */
  99847. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  99848. + 0, dctl.d32);
  99849. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  99850. + }
  99851. +
  99852. +}
  99853. +#endif
  99854. +
  99855. +/**
  99856. + * Performs remote wakeup.
  99857. + */
  99858. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  99859. +{
  99860. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99861. + dwc_irqflags_t flags;
  99862. + if (dwc_otg_is_device_mode(core_if)) {
  99863. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99864. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99865. + if (core_if->lx_state == DWC_OTG_L1) {
  99866. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  99867. + } else {
  99868. +#endif
  99869. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  99870. +#ifdef CONFIG_USB_DWC_OTG_LPM
  99871. + }
  99872. +#endif
  99873. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99874. + }
  99875. + return;
  99876. +}
  99877. +
  99878. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  99879. +{
  99880. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  99881. + dctl_data_t dctl = { 0 };
  99882. +
  99883. + if (dwc_otg_is_device_mode(core_if)) {
  99884. + dctl.b.sftdiscon = 1;
  99885. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  99886. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  99887. + dwc_udelay(no_of_usecs);
  99888. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  99889. +
  99890. + } else{
  99891. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  99892. + }
  99893. + return;
  99894. +
  99895. +}
  99896. +
  99897. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  99898. +{
  99899. + dsts_data_t dsts;
  99900. + gotgctl_data_t gotgctl;
  99901. +
  99902. + /*
  99903. + * This function starts the Protocol if no session is in progress. If
  99904. + * a session is already in progress, but the device is suspended,
  99905. + * remote wakeup signaling is started.
  99906. + */
  99907. +
  99908. + /* Check if valid session */
  99909. + gotgctl.d32 =
  99910. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  99911. + if (gotgctl.b.bsesvld) {
  99912. + /* Check if suspend state */
  99913. + dsts.d32 =
  99914. + DWC_READ_REG32(&
  99915. + (GET_CORE_IF(pcd)->dev_if->
  99916. + dev_global_regs->dsts));
  99917. + if (dsts.b.suspsts) {
  99918. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  99919. + }
  99920. + } else {
  99921. + dwc_otg_pcd_initiate_srp(pcd);
  99922. + }
  99923. +
  99924. + return 0;
  99925. +
  99926. +}
  99927. +
  99928. +/**
  99929. + * Start the SRP timer to detect when the SRP does not complete within
  99930. + * 6 seconds.
  99931. + *
  99932. + * @param pcd the pcd structure.
  99933. + */
  99934. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  99935. +{
  99936. + dwc_irqflags_t flags;
  99937. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  99938. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  99939. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  99940. +}
  99941. +
  99942. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  99943. +{
  99944. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  99945. +}
  99946. +
  99947. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  99948. +{
  99949. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  99950. +}
  99951. +
  99952. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  99953. +{
  99954. + return pcd->b_hnp_enable;
  99955. +}
  99956. +
  99957. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  99958. +{
  99959. + return pcd->a_hnp_support;
  99960. +}
  99961. +
  99962. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  99963. +{
  99964. + return pcd->a_alt_hnp_support;
  99965. +}
  99966. +
  99967. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  99968. +{
  99969. + return pcd->remote_wakeup_enable;
  99970. +}
  99971. +
  99972. +#endif /* DWC_HOST_ONLY */
  99973. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  99974. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  99975. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2015-03-09 10:39:33.218893718 +0100
  99976. @@ -0,0 +1,266 @@
  99977. +/* ==========================================================================
  99978. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  99979. + * $Revision: #48 $
  99980. + * $Date: 2012/08/10 $
  99981. + * $Change: 2047372 $
  99982. + *
  99983. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  99984. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  99985. + * otherwise expressly agreed to in writing between Synopsys and you.
  99986. + *
  99987. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  99988. + * any End User Software License Agreement or Agreement for Licensed Product
  99989. + * with Synopsys or any supplement thereto. You are permitted to use and
  99990. + * redistribute this Software in source and binary forms, with or without
  99991. + * modification, provided that redistributions of source code must retain this
  99992. + * notice. You may not view, use, disclose, copy or distribute this file or
  99993. + * any information contained herein except pursuant to this license grant from
  99994. + * Synopsys. If you do not agree with this notice, including the disclaimer
  99995. + * below, then you are not authorized to use the Software.
  99996. + *
  99997. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  99998. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  99999. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  100000. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  100001. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  100002. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  100003. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  100004. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100005. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  100006. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  100007. + * DAMAGE.
  100008. + * ========================================================================== */
  100009. +#ifndef DWC_HOST_ONLY
  100010. +#if !defined(__DWC_PCD_H__)
  100011. +#define __DWC_PCD_H__
  100012. +
  100013. +#include "dwc_otg_os_dep.h"
  100014. +#include "usb.h"
  100015. +#include "dwc_otg_cil.h"
  100016. +#include "dwc_otg_pcd_if.h"
  100017. +struct cfiobject;
  100018. +
  100019. +/**
  100020. + * @file
  100021. + *
  100022. + * This file contains the structures, constants, and interfaces for
  100023. + * the Perpherial Contoller Driver (PCD).
  100024. + *
  100025. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  100026. + * Gadget API, so that the existing Gadget drivers can be used. For
  100027. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  100028. + * (FBS) driver will be used. The FBS driver supports the
  100029. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  100030. + * transports.
  100031. + *
  100032. + */
  100033. +
  100034. +/** Invalid DMA Address */
  100035. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  100036. +
  100037. +/** Max Transfer size for any EP */
  100038. +#define DDMA_MAX_TRANSFER_SIZE 65535
  100039. +
  100040. +/**
  100041. + * Get the pointer to the core_if from the pcd pointer.
  100042. + */
  100043. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  100044. +
  100045. +/**
  100046. + * States of EP0.
  100047. + */
  100048. +typedef enum ep0_state {
  100049. + EP0_DISCONNECT, /* no host */
  100050. + EP0_IDLE,
  100051. + EP0_IN_DATA_PHASE,
  100052. + EP0_OUT_DATA_PHASE,
  100053. + EP0_IN_STATUS_PHASE,
  100054. + EP0_OUT_STATUS_PHASE,
  100055. + EP0_STALL,
  100056. +} ep0state_e;
  100057. +
  100058. +/** Fordward declaration.*/
  100059. +struct dwc_otg_pcd;
  100060. +
  100061. +/** DWC_otg iso request structure.
  100062. + *
  100063. + */
  100064. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  100065. +
  100066. +#ifdef DWC_UTE_PER_IO
  100067. +
  100068. +/**
  100069. + * This shall be the exact analogy of the same type structure defined in the
  100070. + * usb_gadget.h. Each descriptor contains
  100071. + */
  100072. +struct dwc_iso_pkt_desc_port {
  100073. + uint32_t offset;
  100074. + uint32_t length; /* expected length */
  100075. + uint32_t actual_length;
  100076. + uint32_t status;
  100077. +};
  100078. +
  100079. +struct dwc_iso_xreq_port {
  100080. + /** transfer/submission flag */
  100081. + uint32_t tr_sub_flags;
  100082. + /** Start the request ASAP */
  100083. +#define DWC_EREQ_TF_ASAP 0x00000002
  100084. + /** Just enqueue the request w/o initiating a transfer */
  100085. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  100086. +
  100087. + /**
  100088. + * count of ISO packets attached to this request - shall
  100089. + * not exceed the pio_alloc_pkt_count
  100090. + */
  100091. + uint32_t pio_pkt_count;
  100092. + /** count of ISO packets allocated for this request */
  100093. + uint32_t pio_alloc_pkt_count;
  100094. + /** number of ISO packet errors */
  100095. + uint32_t error_count;
  100096. + /** reserved for future extension */
  100097. + uint32_t res;
  100098. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  100099. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  100100. +};
  100101. +#endif
  100102. +/** DWC_otg request structure.
  100103. + * This structure is a list of requests.
  100104. + */
  100105. +typedef struct dwc_otg_pcd_request {
  100106. + void *priv;
  100107. + void *buf;
  100108. + dwc_dma_t dma;
  100109. + uint32_t length;
  100110. + uint32_t actual;
  100111. + unsigned sent_zlp:1;
  100112. + /**
  100113. + * Used instead of original buffer if
  100114. + * it(physical address) is not dword-aligned.
  100115. + **/
  100116. + uint8_t *dw_align_buf;
  100117. + dwc_dma_t dw_align_buf_dma;
  100118. +
  100119. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  100120. +#ifdef DWC_UTE_PER_IO
  100121. + struct dwc_iso_xreq_port ext_req;
  100122. + //void *priv_ereq_nport; /* */
  100123. +#endif
  100124. +} dwc_otg_pcd_request_t;
  100125. +
  100126. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  100127. +
  100128. +/** PCD EP structure.
  100129. + * This structure describes an EP, there is an array of EPs in the PCD
  100130. + * structure.
  100131. + */
  100132. +typedef struct dwc_otg_pcd_ep {
  100133. + /** USB EP Descriptor */
  100134. + const usb_endpoint_descriptor_t *desc;
  100135. +
  100136. + /** queue of dwc_otg_pcd_requests. */
  100137. + struct req_list queue;
  100138. + unsigned stopped:1;
  100139. + unsigned disabling:1;
  100140. + unsigned dma:1;
  100141. + unsigned queue_sof:1;
  100142. +
  100143. +#ifdef DWC_EN_ISOC
  100144. + /** ISOC req handle passed */
  100145. + void *iso_req_handle;
  100146. +#endif //_EN_ISOC_
  100147. +
  100148. + /** DWC_otg ep data. */
  100149. + dwc_ep_t dwc_ep;
  100150. +
  100151. + /** Pointer to PCD */
  100152. + struct dwc_otg_pcd *pcd;
  100153. +
  100154. + void *priv;
  100155. +} dwc_otg_pcd_ep_t;
  100156. +
  100157. +/** DWC_otg PCD Structure.
  100158. + * This structure encapsulates the data for the dwc_otg PCD.
  100159. + */
  100160. +struct dwc_otg_pcd {
  100161. + const struct dwc_otg_pcd_function_ops *fops;
  100162. + /** The DWC otg device pointer */
  100163. + struct dwc_otg_device *otg_dev;
  100164. + /** Core Interface */
  100165. + dwc_otg_core_if_t *core_if;
  100166. + /** State of EP0 */
  100167. + ep0state_e ep0state;
  100168. + /** EP0 Request is pending */
  100169. + unsigned ep0_pending:1;
  100170. + /** Indicates when SET CONFIGURATION Request is in process */
  100171. + unsigned request_config:1;
  100172. + /** The state of the Remote Wakeup Enable. */
  100173. + unsigned remote_wakeup_enable:1;
  100174. + /** The state of the B-Device HNP Enable. */
  100175. + unsigned b_hnp_enable:1;
  100176. + /** The state of A-Device HNP Support. */
  100177. + unsigned a_hnp_support:1;
  100178. + /** The state of the A-Device Alt HNP support. */
  100179. + unsigned a_alt_hnp_support:1;
  100180. + /** Count of pending Requests */
  100181. + unsigned request_pending;
  100182. +
  100183. + /** SETUP packet for EP0
  100184. + * This structure is allocated as a DMA buffer on PCD initialization
  100185. + * with enough space for up to 3 setup packets.
  100186. + */
  100187. + union {
  100188. + usb_device_request_t req;
  100189. + uint32_t d32[2];
  100190. + } *setup_pkt;
  100191. +
  100192. + dwc_dma_t setup_pkt_dma_handle;
  100193. +
  100194. + /* Additional buffer and flag for CTRL_WR premature case */
  100195. + uint8_t *backup_buf;
  100196. + unsigned data_terminated;
  100197. +
  100198. + /** 2-byte dma buffer used to return status from GET_STATUS */
  100199. + uint16_t *status_buf;
  100200. + dwc_dma_t status_buf_dma_handle;
  100201. +
  100202. + /** EP0 */
  100203. + dwc_otg_pcd_ep_t ep0;
  100204. +
  100205. + /** Array of IN EPs. */
  100206. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  100207. + /** Array of OUT EPs. */
  100208. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  100209. + /** number of valid EPs in the above array. */
  100210. +// unsigned num_eps : 4;
  100211. + dwc_spinlock_t *lock;
  100212. +
  100213. + /** Tasklet to defer starting of TEST mode transmissions until
  100214. + * Status Phase has been completed.
  100215. + */
  100216. + dwc_tasklet_t *test_mode_tasklet;
  100217. +
  100218. + /** Tasklet to delay starting of xfer in DMA mode */
  100219. + dwc_tasklet_t *start_xfer_tasklet;
  100220. +
  100221. + /** The test mode to enter when the tasklet is executed. */
  100222. + unsigned test_mode;
  100223. + /** The cfi_api structure that implements most of the CFI API
  100224. + * and OTG specific core configuration functionality
  100225. + */
  100226. +#ifdef DWC_UTE_CFI
  100227. + struct cfiobject *cfi;
  100228. +#endif
  100229. +
  100230. +};
  100231. +
  100232. +//FIXME this functions should be static, and this prototypes should be removed
  100233. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  100234. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  100235. + dwc_otg_pcd_request_t * req, int32_t status);
  100236. +
  100237. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  100238. + void *req_handle);
  100239. +
  100240. +extern void do_test_mode(void *data);
  100241. +#endif
  100242. +#endif /* DWC_HOST_ONLY */
  100243. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  100244. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  100245. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2015-03-09 10:39:33.218893718 +0100
  100246. @@ -0,0 +1,360 @@
  100247. +/* ==========================================================================
  100248. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  100249. + * $Revision: #11 $
  100250. + * $Date: 2011/10/26 $
  100251. + * $Change: 1873028 $
  100252. + *
  100253. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  100254. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  100255. + * otherwise expressly agreed to in writing between Synopsys and you.
  100256. + *
  100257. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  100258. + * any End User Software License Agreement or Agreement for Licensed Product
  100259. + * with Synopsys or any supplement thereto. You are permitted to use and
  100260. + * redistribute this Software in source and binary forms, with or without
  100261. + * modification, provided that redistributions of source code must retain this
  100262. + * notice. You may not view, use, disclose, copy or distribute this file or
  100263. + * any information contained herein except pursuant to this license grant from
  100264. + * Synopsys. If you do not agree with this notice, including the disclaimer
  100265. + * below, then you are not authorized to use the Software.
  100266. + *
  100267. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  100268. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  100269. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  100270. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  100271. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  100272. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  100273. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  100274. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100275. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  100276. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  100277. + * DAMAGE.
  100278. + * ========================================================================== */
  100279. +#ifndef DWC_HOST_ONLY
  100280. +
  100281. +#if !defined(__DWC_PCD_IF_H__)
  100282. +#define __DWC_PCD_IF_H__
  100283. +
  100284. +//#include "dwc_os.h"
  100285. +#include "dwc_otg_core_if.h"
  100286. +
  100287. +/** @file
  100288. + * This file defines DWC_OTG PCD Core API.
  100289. + */
  100290. +
  100291. +struct dwc_otg_pcd;
  100292. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  100293. +
  100294. +/** Maxpacket size for EP0 */
  100295. +#define MAX_EP0_SIZE 64
  100296. +/** Maxpacket size for any EP */
  100297. +#define MAX_PACKET_SIZE 1024
  100298. +
  100299. +/** @name Function Driver Callbacks */
  100300. +/** @{ */
  100301. +
  100302. +/** This function will be called whenever a previously queued request has
  100303. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  100304. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  100305. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  100306. + * parameters. */
  100307. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  100308. + void *req_handle, int32_t status,
  100309. + uint32_t actual);
  100310. +/**
  100311. + * This function will be called whenever a previousle queued ISOC request has
  100312. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  100313. + * function.
  100314. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  100315. + * functions.
  100316. + */
  100317. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  100318. + void *req_handle, int proc_buf_num);
  100319. +/** This function should handle any SETUP request that cannot be handled by the
  100320. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  100321. + * class-specific requests, etc. The function must non-blocking.
  100322. + *
  100323. + * Returns 0 on success.
  100324. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  100325. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  100326. + * Returns -DWC_E_SHUTDOWN on any other error. */
  100327. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  100328. +/** This is called whenever the device has been disconnected. The function
  100329. + * driver should take appropriate action to clean up all pending requests in the
  100330. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  100331. + * state. */
  100332. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  100333. +/** This function is called when device has been connected. */
  100334. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  100335. +/** This function is called when device has been suspended */
  100336. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  100337. +/** This function is called when device has received LPM tokens, i.e.
  100338. + * device has been sent to sleep state. */
  100339. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  100340. +/** This function is called when device has been resumed
  100341. + * from suspend(L2) or L1 sleep state. */
  100342. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  100343. +/** This function is called whenever hnp params has been changed.
  100344. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  100345. + * to get hnp parameters. */
  100346. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  100347. +/** This function is called whenever USB RESET is detected. */
  100348. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  100349. +
  100350. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  100351. +
  100352. +/**
  100353. + *
  100354. + * @param ep_handle Void pointer to the usb_ep structure
  100355. + * @param ereq_port Pointer to the extended request structure created in the
  100356. + * portable part.
  100357. + */
  100358. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  100359. + void *req_handle, int32_t status,
  100360. + void *ereq_port);
  100361. +/** Function Driver Ops Data Structure */
  100362. +struct dwc_otg_pcd_function_ops {
  100363. + dwc_connect_cb_t connect;
  100364. + dwc_disconnect_cb_t disconnect;
  100365. + dwc_setup_cb_t setup;
  100366. + dwc_completion_cb_t complete;
  100367. + dwc_isoc_completion_cb_t isoc_complete;
  100368. + dwc_suspend_cb_t suspend;
  100369. + dwc_sleep_cb_t sleep;
  100370. + dwc_resume_cb_t resume;
  100371. + dwc_reset_cb_t reset;
  100372. + dwc_hnp_params_changed_cb_t hnp_changed;
  100373. + cfi_setup_cb_t cfi_setup;
  100374. +#ifdef DWC_UTE_PER_IO
  100375. + xiso_completion_cb_t xisoc_complete;
  100376. +#endif
  100377. +};
  100378. +/** @} */
  100379. +
  100380. +/** @name Function Driver Functions */
  100381. +/** @{ */
  100382. +
  100383. +/** Call this function to get pointer on dwc_otg_pcd_t,
  100384. + * this pointer will be used for all PCD API functions.
  100385. + *
  100386. + * @param core_if The DWC_OTG Core
  100387. + */
  100388. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  100389. +
  100390. +/** Frees PCD allocated by dwc_otg_pcd_init
  100391. + *
  100392. + * @param pcd The PCD
  100393. + */
  100394. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  100395. +
  100396. +/** Call this to bind the function driver to the PCD Core.
  100397. + *
  100398. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  100399. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  100400. + */
  100401. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  100402. + const struct dwc_otg_pcd_function_ops *fops);
  100403. +
  100404. +/** Enables an endpoint for use. This function enables an endpoint in
  100405. + * the PCD. The endpoint is described by the ep_desc which has the
  100406. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  100407. + * to the endpoint from other API functions and in callbacks. Normally this
  100408. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  100409. + * core for that interface.
  100410. + *
  100411. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100412. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100413. + * Returns 0 on success.
  100414. + *
  100415. + * @param pcd The PCD
  100416. + * @param ep_desc Endpoint descriptor
  100417. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  100418. + */
  100419. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  100420. + const uint8_t * ep_desc, void *usb_ep);
  100421. +
  100422. +/** Disable the endpoint referenced by ep_handle.
  100423. + *
  100424. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100425. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  100426. + * Returns 0 on success. */
  100427. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  100428. +
  100429. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  100430. + * After the transfer is completes, the complete callback will be called with
  100431. + * the request status.
  100432. + *
  100433. + * @param pcd The PCD
  100434. + * @param ep_handle The handle of the endpoint
  100435. + * @param buf The buffer for the data
  100436. + * @param dma_buf The DMA buffer for the data
  100437. + * @param buflen The length of the data transfer
  100438. + * @param zero Specifies whether to send zero length last packet.
  100439. + * @param req_handle Set this handle to any value to use to reference this
  100440. + * request in the ep_dequeue function or from the complete callback
  100441. + * @param atomic_alloc If driver need to perform atomic allocations
  100442. + * for internal data structures.
  100443. + *
  100444. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100445. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100446. + * Returns 0 on success. */
  100447. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  100448. + uint8_t * buf, dwc_dma_t dma_buf,
  100449. + uint32_t buflen, int zero, void *req_handle,
  100450. + int atomic_alloc);
  100451. +#ifdef DWC_UTE_PER_IO
  100452. +/**
  100453. + *
  100454. + * @param ereq_nonport Pointer to the extended request part of the
  100455. + * usb_request structure defined in usb_gadget.h file.
  100456. + */
  100457. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  100458. + uint8_t * buf, dwc_dma_t dma_buf,
  100459. + uint32_t buflen, int zero,
  100460. + void *req_handle, int atomic_alloc,
  100461. + void *ereq_nonport);
  100462. +
  100463. +#endif
  100464. +
  100465. +/** De-queue the specified data transfer that has not yet completed.
  100466. + *
  100467. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100468. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100469. + * Returns 0 on success. */
  100470. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  100471. + void *req_handle);
  100472. +
  100473. +/** Halt (STALL) an endpoint or clear it.
  100474. + *
  100475. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  100476. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  100477. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  100478. + * Returns 0 on success. */
  100479. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  100480. +
  100481. +/** This function */
  100482. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  100483. +
  100484. +/** This function should be called on every hardware interrupt */
  100485. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  100486. +
  100487. +/** This function returns current frame number */
  100488. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  100489. +
  100490. +/**
  100491. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  100492. + * For isochronous transfers duble buffering is used.
  100493. + * After processing each of buffers comlete callback will be called with
  100494. + * status for each transaction.
  100495. + *
  100496. + * @param pcd The PCD
  100497. + * @param ep_handle The handle of the endpoint
  100498. + * @param buf0 The virtual address of first data buffer
  100499. + * @param buf1 The virtual address of second data buffer
  100500. + * @param dma0 The DMA address of first data buffer
  100501. + * @param dma1 The DMA address of second data buffer
  100502. + * @param sync_frame Data pattern frame number
  100503. + * @param dp_frame Data size for pattern frame
  100504. + * @param data_per_frame Data size for regular frame
  100505. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  100506. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  100507. + * @param req_handle Handle of ISOC request
  100508. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  100509. + * internal data structures.
  100510. + *
  100511. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  100512. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  100513. + * Returns -DW_E_SHUTDOWN for any other error.
  100514. + * Returns 0 on success
  100515. + */
  100516. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  100517. + uint8_t * buf0, uint8_t * buf1,
  100518. + dwc_dma_t dma0, dwc_dma_t dma1,
  100519. + int sync_frame, int dp_frame,
  100520. + int data_per_frame, int start_frame,
  100521. + int buf_proc_intrvl, void *req_handle,
  100522. + int atomic_alloc);
  100523. +
  100524. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  100525. + *
  100526. + * @param pcd The PCD
  100527. + * @param ep_handle The handle of the endpoint
  100528. + * @param req_handle Handle of ISOC request
  100529. + *
  100530. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  100531. + * Returns 0 on success
  100532. + */
  100533. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  100534. + void *req_handle);
  100535. +
  100536. +/** Get ISOC packet status.
  100537. + *
  100538. + * @param pcd The PCD
  100539. + * @param ep_handle The handle of the endpoint
  100540. + * @param iso_req_handle Isochronoush request handle
  100541. + * @param packet Number of packet
  100542. + * @param status Out parameter for returning status
  100543. + * @param actual Out parameter for returning actual length
  100544. + * @param offset Out parameter for returning offset
  100545. + *
  100546. + */
  100547. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  100548. + void *ep_handle,
  100549. + void *iso_req_handle, int packet,
  100550. + int *status, int *actual,
  100551. + int *offset);
  100552. +
  100553. +/** Get ISOC packet count.
  100554. + *
  100555. + * @param pcd The PCD
  100556. + * @param ep_handle The handle of the endpoint
  100557. + * @param iso_req_handle
  100558. + */
  100559. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  100560. + void *ep_handle,
  100561. + void *iso_req_handle);
  100562. +
  100563. +/** This function starts the SRP Protocol if no session is in progress. If
  100564. + * a session is already in progress, but the device is suspended,
  100565. + * remote wakeup signaling is started.
  100566. + */
  100567. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  100568. +
  100569. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  100570. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  100571. +
  100572. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  100573. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  100574. +
  100575. +/** Initiate SRP */
  100576. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  100577. +
  100578. +/** Starts remote wakeup signaling. */
  100579. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  100580. +
  100581. +/** Starts micorsecond soft disconnect. */
  100582. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  100583. +/** This function returns whether device is dualspeed.*/
  100584. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  100585. +
  100586. +/** This function returns whether device is otg. */
  100587. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  100588. +
  100589. +/** These functions allow to get hnp parameters */
  100590. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  100591. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  100592. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  100593. +
  100594. +/** CFI specific Interface functions */
  100595. +/** Allocate a cfi buffer */
  100596. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  100597. + dwc_dma_t * addr, size_t buflen,
  100598. + int flags);
  100599. +
  100600. +/******************************************************************************/
  100601. +
  100602. +/** @} */
  100603. +
  100604. +#endif /* __DWC_PCD_IF_H__ */
  100605. +
  100606. +#endif /* DWC_HOST_ONLY */
  100607. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  100608. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  100609. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2015-03-09 10:39:33.218893718 +0100
  100610. @@ -0,0 +1,5147 @@
  100611. +/* ==========================================================================
  100612. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  100613. + * $Revision: #116 $
  100614. + * $Date: 2012/08/10 $
  100615. + * $Change: 2047372 $
  100616. + *
  100617. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  100618. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  100619. + * otherwise expressly agreed to in writing between Synopsys and you.
  100620. + *
  100621. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  100622. + * any End User Software License Agreement or Agreement for Licensed Product
  100623. + * with Synopsys or any supplement thereto. You are permitted to use and
  100624. + * redistribute this Software in source and binary forms, with or without
  100625. + * modification, provided that redistributions of source code must retain this
  100626. + * notice. You may not view, use, disclose, copy or distribute this file or
  100627. + * any information contained herein except pursuant to this license grant from
  100628. + * Synopsys. If you do not agree with this notice, including the disclaimer
  100629. + * below, then you are not authorized to use the Software.
  100630. + *
  100631. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  100632. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  100633. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  100634. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  100635. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  100636. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  100637. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  100638. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  100639. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  100640. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  100641. + * DAMAGE.
  100642. + * ========================================================================== */
  100643. +#ifndef DWC_HOST_ONLY
  100644. +
  100645. +#include "dwc_otg_pcd.h"
  100646. +
  100647. +#ifdef DWC_UTE_CFI
  100648. +#include "dwc_otg_cfi.h"
  100649. +#endif
  100650. +
  100651. +#ifdef DWC_UTE_PER_IO
  100652. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  100653. +#endif
  100654. +//#define PRINT_CFI_DMA_DESCS
  100655. +
  100656. +#define DEBUG_EP0
  100657. +
  100658. +/**
  100659. + * This function updates OTG.
  100660. + */
  100661. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  100662. +{
  100663. +
  100664. + if (reset) {
  100665. + pcd->b_hnp_enable = 0;
  100666. + pcd->a_hnp_support = 0;
  100667. + pcd->a_alt_hnp_support = 0;
  100668. + }
  100669. +
  100670. + if (pcd->fops->hnp_changed) {
  100671. + pcd->fops->hnp_changed(pcd);
  100672. + }
  100673. +}
  100674. +
  100675. +/** @file
  100676. + * This file contains the implementation of the PCD Interrupt handlers.
  100677. + *
  100678. + * The PCD handles the device interrupts. Many conditions can cause a
  100679. + * device interrupt. When an interrupt occurs, the device interrupt
  100680. + * service routine determines the cause of the interrupt and
  100681. + * dispatches handling to the appropriate function. These interrupt
  100682. + * handling functions are described below.
  100683. + * All interrupt registers are processed from LSB to MSB.
  100684. + */
  100685. +
  100686. +/**
  100687. + * This function prints the ep0 state for debug purposes.
  100688. + */
  100689. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  100690. +{
  100691. +#ifdef DEBUG
  100692. + char str[40];
  100693. +
  100694. + switch (pcd->ep0state) {
  100695. + case EP0_DISCONNECT:
  100696. + dwc_strcpy(str, "EP0_DISCONNECT");
  100697. + break;
  100698. + case EP0_IDLE:
  100699. + dwc_strcpy(str, "EP0_IDLE");
  100700. + break;
  100701. + case EP0_IN_DATA_PHASE:
  100702. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  100703. + break;
  100704. + case EP0_OUT_DATA_PHASE:
  100705. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  100706. + break;
  100707. + case EP0_IN_STATUS_PHASE:
  100708. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  100709. + break;
  100710. + case EP0_OUT_STATUS_PHASE:
  100711. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  100712. + break;
  100713. + case EP0_STALL:
  100714. + dwc_strcpy(str, "EP0_STALL");
  100715. + break;
  100716. + default:
  100717. + dwc_strcpy(str, "EP0_INVALID");
  100718. + }
  100719. +
  100720. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  100721. +#endif
  100722. +}
  100723. +
  100724. +/**
  100725. + * This function calculate the size of the payload in the memory
  100726. + * for out endpoints and prints size for debug purposes(used in
  100727. + * 2.93a DevOutNak feature).
  100728. + */
  100729. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  100730. +{
  100731. +#ifdef DEBUG
  100732. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  100733. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  100734. + int pack_num;
  100735. + unsigned payload;
  100736. +
  100737. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  100738. + deptsiz_updt.d32 =
  100739. + DWC_READ_REG32(&pcd->core_if->dev_if->
  100740. + out_ep_regs[ep->num]->doeptsiz);
  100741. + /* Payload will be */
  100742. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  100743. + /* Packet count is decremented every time a packet
  100744. + * is written to the RxFIFO not in to the external memory
  100745. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  100746. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  100747. + DWC_DEBUGPL(DBG_PCDV,
  100748. + "Payload for EP%d-%s\n",
  100749. + ep->num, (ep->is_in ? "IN" : "OUT"));
  100750. + DWC_DEBUGPL(DBG_PCDV,
  100751. + "Number of transfered bytes = 0x%08x\n", payload);
  100752. + DWC_DEBUGPL(DBG_PCDV,
  100753. + "Number of transfered packets = %d\n", pack_num);
  100754. +#endif
  100755. +}
  100756. +
  100757. +
  100758. +#ifdef DWC_UTE_CFI
  100759. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  100760. + const uint8_t * epname, int descnum)
  100761. +{
  100762. + CFI_INFO
  100763. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  100764. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  100765. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  100766. + ddesc->status.b.bs);
  100767. +}
  100768. +#endif
  100769. +
  100770. +/**
  100771. + * This function returns pointer to in ep struct with number ep_num
  100772. + */
  100773. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  100774. +{
  100775. + int i;
  100776. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  100777. + if (ep_num == 0) {
  100778. + return &pcd->ep0;
  100779. + } else {
  100780. + for (i = 0; i < num_in_eps; ++i) {
  100781. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  100782. + return &pcd->in_ep[i];
  100783. + }
  100784. + return 0;
  100785. + }
  100786. +}
  100787. +
  100788. +/**
  100789. + * This function returns pointer to out ep struct with number ep_num
  100790. + */
  100791. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  100792. +{
  100793. + int i;
  100794. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  100795. + if (ep_num == 0) {
  100796. + return &pcd->ep0;
  100797. + } else {
  100798. + for (i = 0; i < num_out_eps; ++i) {
  100799. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  100800. + return &pcd->out_ep[i];
  100801. + }
  100802. + return 0;
  100803. + }
  100804. +}
  100805. +
  100806. +/**
  100807. + * This functions gets a pointer to an EP from the wIndex address
  100808. + * value of the control request.
  100809. + */
  100810. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  100811. +{
  100812. + dwc_otg_pcd_ep_t *ep;
  100813. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  100814. +
  100815. + if (ep_num == 0) {
  100816. + ep = &pcd->ep0;
  100817. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  100818. + ep = &pcd->in_ep[ep_num - 1];
  100819. + } else {
  100820. + ep = &pcd->out_ep[ep_num - 1];
  100821. + }
  100822. +
  100823. + return ep;
  100824. +}
  100825. +
  100826. +/**
  100827. + * This function checks the EP request queue, if the queue is not
  100828. + * empty the next request is started.
  100829. + */
  100830. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  100831. +{
  100832. + dwc_otg_pcd_request_t *req = 0;
  100833. + uint32_t max_transfer =
  100834. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  100835. +
  100836. +#ifdef DWC_UTE_CFI
  100837. + struct dwc_otg_pcd *pcd;
  100838. + pcd = ep->pcd;
  100839. +#endif
  100840. +
  100841. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  100842. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  100843. +
  100844. +#ifdef DWC_UTE_CFI
  100845. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  100846. + ep->dwc_ep.cfi_req_len = req->length;
  100847. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  100848. + } else {
  100849. +#endif
  100850. + /* Setup and start the Transfer */
  100851. + if (req->dw_align_buf) {
  100852. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  100853. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  100854. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  100855. + } else {
  100856. + ep->dwc_ep.dma_addr = req->dma;
  100857. + ep->dwc_ep.start_xfer_buff = req->buf;
  100858. + ep->dwc_ep.xfer_buff = req->buf;
  100859. + }
  100860. + ep->dwc_ep.sent_zlp = 0;
  100861. + ep->dwc_ep.total_len = req->length;
  100862. + ep->dwc_ep.xfer_len = 0;
  100863. + ep->dwc_ep.xfer_count = 0;
  100864. +
  100865. + ep->dwc_ep.maxxfer = max_transfer;
  100866. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  100867. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  100868. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  100869. + if (ep->dwc_ep.is_in) {
  100870. + if (ep->dwc_ep.maxxfer >
  100871. + DDMA_MAX_TRANSFER_SIZE) {
  100872. + ep->dwc_ep.maxxfer =
  100873. + DDMA_MAX_TRANSFER_SIZE;
  100874. + }
  100875. + } else {
  100876. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  100877. + ep->dwc_ep.maxxfer =
  100878. + out_max_xfer;
  100879. + }
  100880. + }
  100881. + }
  100882. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  100883. + ep->dwc_ep.maxxfer -=
  100884. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  100885. + }
  100886. + if (req->sent_zlp) {
  100887. + if ((ep->dwc_ep.total_len %
  100888. + ep->dwc_ep.maxpacket == 0)
  100889. + && (ep->dwc_ep.total_len != 0)) {
  100890. + ep->dwc_ep.sent_zlp = 1;
  100891. + }
  100892. +
  100893. + }
  100894. +#ifdef DWC_UTE_CFI
  100895. + }
  100896. +#endif
  100897. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  100898. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  100899. + DWC_PRINTF("There are no more ISOC requests \n");
  100900. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  100901. + }
  100902. +}
  100903. +
  100904. +/**
  100905. + * This function handles the SOF Interrupts. At this time the SOF
  100906. + * Interrupt is disabled.
  100907. + */
  100908. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  100909. +{
  100910. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100911. +
  100912. + gintsts_data_t gintsts;
  100913. +
  100914. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  100915. +
  100916. + /* Clear interrupt */
  100917. + gintsts.d32 = 0;
  100918. + gintsts.b.sofintr = 1;
  100919. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  100920. +
  100921. + return 1;
  100922. +}
  100923. +
  100924. +/**
  100925. + * This function handles the Rx Status Queue Level Interrupt, which
  100926. + * indicates that there is a least one packet in the Rx FIFO. The
  100927. + * packets are moved from the FIFO to memory, where they will be
  100928. + * processed when the Endpoint Interrupt Register indicates Transfer
  100929. + * Complete or SETUP Phase Done.
  100930. + *
  100931. + * Repeat the following until the Rx Status Queue is empty:
  100932. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  100933. + * info
  100934. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  100935. + * and exit
  100936. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  100937. + * SETUP data to the buffer
  100938. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  100939. + * to the destination buffer
  100940. + */
  100941. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  100942. +{
  100943. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  100944. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  100945. + gintmsk_data_t gintmask = {.d32 = 0 };
  100946. + device_grxsts_data_t status;
  100947. + dwc_otg_pcd_ep_t *ep;
  100948. + gintsts_data_t gintsts;
  100949. +#ifdef DEBUG
  100950. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  100951. +#endif
  100952. +
  100953. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  100954. + /* Disable the Rx Status Queue Level interrupt */
  100955. + gintmask.b.rxstsqlvl = 1;
  100956. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  100957. +
  100958. + /* Get the Status from the top of the FIFO */
  100959. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  100960. +
  100961. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  100962. + "pktsts:%x Frame:%d(0x%0x)\n",
  100963. + status.b.epnum, status.b.bcnt,
  100964. + dpid_str[status.b.dpid],
  100965. + status.b.pktsts, status.b.fn, status.b.fn);
  100966. + /* Get pointer to EP structure */
  100967. + ep = get_out_ep(pcd, status.b.epnum);
  100968. +
  100969. + switch (status.b.pktsts) {
  100970. + case DWC_DSTS_GOUT_NAK:
  100971. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  100972. + break;
  100973. + case DWC_STS_DATA_UPDT:
  100974. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  100975. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  100976. + /** @todo NGS Check for buffer overflow? */
  100977. + dwc_otg_read_packet(core_if,
  100978. + ep->dwc_ep.xfer_buff,
  100979. + status.b.bcnt);
  100980. + ep->dwc_ep.xfer_count += status.b.bcnt;
  100981. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  100982. + }
  100983. + break;
  100984. + case DWC_STS_XFER_COMP:
  100985. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  100986. + break;
  100987. + case DWC_DSTS_SETUP_COMP:
  100988. +#ifdef DEBUG_EP0
  100989. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  100990. +#endif
  100991. + break;
  100992. + case DWC_DSTS_SETUP_UPDT:
  100993. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  100994. +#ifdef DEBUG_EP0
  100995. + DWC_DEBUGPL(DBG_PCD,
  100996. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  100997. + pcd->setup_pkt->req.bmRequestType,
  100998. + pcd->setup_pkt->req.bRequest,
  100999. + UGETW(pcd->setup_pkt->req.wValue),
  101000. + UGETW(pcd->setup_pkt->req.wIndex),
  101001. + UGETW(pcd->setup_pkt->req.wLength));
  101002. +#endif
  101003. + ep->dwc_ep.xfer_count += status.b.bcnt;
  101004. + break;
  101005. + default:
  101006. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  101007. + status.b.pktsts);
  101008. + break;
  101009. + }
  101010. +
  101011. + /* Enable the Rx Status Queue Level interrupt */
  101012. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  101013. + /* Clear interrupt */
  101014. + gintsts.d32 = 0;
  101015. + gintsts.b.rxstsqlvl = 1;
  101016. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  101017. +
  101018. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  101019. + return 1;
  101020. +}
  101021. +
  101022. +/**
  101023. + * This function examines the Device IN Token Learning Queue to
  101024. + * determine the EP number of the last IN token received. This
  101025. + * implementation is for the Mass Storage device where there are only
  101026. + * 2 IN EPs (Control-IN and BULK-IN).
  101027. + *
  101028. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  101029. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  101030. + *
  101031. + * @param core_if Programming view of DWC_otg controller.
  101032. + *
  101033. + */
  101034. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  101035. +{
  101036. + dwc_otg_device_global_regs_t *dev_global_regs =
  101037. + core_if->dev_if->dev_global_regs;
  101038. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  101039. + /* Number of Token Queue Registers */
  101040. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  101041. + dtknq1_data_t dtknqr1;
  101042. + uint32_t in_tkn_epnums[4];
  101043. + int ndx = 0;
  101044. + int i = 0;
  101045. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  101046. + int epnum = 0;
  101047. +
  101048. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  101049. +
  101050. + /* Read the DTKNQ Registers */
  101051. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  101052. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  101053. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  101054. + in_tkn_epnums[i]);
  101055. + if (addr == &dev_global_regs->dvbusdis) {
  101056. + addr = &dev_global_regs->dtknqr3_dthrctl;
  101057. + } else {
  101058. + ++addr;
  101059. + }
  101060. +
  101061. + }
  101062. +
  101063. + /* Copy the DTKNQR1 data to the bit field. */
  101064. + dtknqr1.d32 = in_tkn_epnums[0];
  101065. + /* Get the EP numbers */
  101066. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  101067. + ndx = dtknqr1.b.intknwptr - 1;
  101068. +
  101069. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  101070. + if (ndx == -1) {
  101071. + /** @todo Find a simpler way to calculate the max
  101072. + * queue position.*/
  101073. + int cnt = TOKEN_Q_DEPTH;
  101074. + if (TOKEN_Q_DEPTH <= 6) {
  101075. + cnt = TOKEN_Q_DEPTH - 1;
  101076. + } else if (TOKEN_Q_DEPTH <= 14) {
  101077. + cnt = TOKEN_Q_DEPTH - 7;
  101078. + } else if (TOKEN_Q_DEPTH <= 22) {
  101079. + cnt = TOKEN_Q_DEPTH - 15;
  101080. + } else {
  101081. + cnt = TOKEN_Q_DEPTH - 23;
  101082. + }
  101083. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  101084. + } else {
  101085. + if (ndx <= 5) {
  101086. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  101087. + } else if (ndx <= 13) {
  101088. + ndx -= 6;
  101089. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  101090. + } else if (ndx <= 21) {
  101091. + ndx -= 14;
  101092. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  101093. + } else if (ndx <= 29) {
  101094. + ndx -= 22;
  101095. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  101096. + }
  101097. + }
  101098. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  101099. + return epnum;
  101100. +}
  101101. +
  101102. +/**
  101103. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  101104. + * The active request is checked for the next packet to be loaded into
  101105. + * the non-periodic Tx FIFO.
  101106. + */
  101107. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  101108. +{
  101109. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101110. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  101111. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  101112. + gnptxsts_data_t txstatus = {.d32 = 0 };
  101113. + gintsts_data_t gintsts;
  101114. +
  101115. + int epnum = 0;
  101116. + dwc_otg_pcd_ep_t *ep = 0;
  101117. + uint32_t len = 0;
  101118. + int dwords;
  101119. +
  101120. + /* Get the epnum from the IN Token Learning Queue. */
  101121. + epnum = get_ep_of_last_in_token(core_if);
  101122. + ep = get_in_ep(pcd, epnum);
  101123. +
  101124. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  101125. +
  101126. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  101127. +
  101128. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  101129. + if (len > ep->dwc_ep.maxpacket) {
  101130. + len = ep->dwc_ep.maxpacket;
  101131. + }
  101132. + dwords = (len + 3) / 4;
  101133. +
  101134. + /* While there is space in the queue and space in the FIFO and
  101135. + * More data to tranfer, Write packets to the Tx FIFO */
  101136. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  101137. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  101138. +
  101139. + while (txstatus.b.nptxqspcavail > 0 &&
  101140. + txstatus.b.nptxfspcavail > dwords &&
  101141. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  101142. + /* Write the FIFO */
  101143. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  101144. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  101145. +
  101146. + if (len > ep->dwc_ep.maxpacket) {
  101147. + len = ep->dwc_ep.maxpacket;
  101148. + }
  101149. +
  101150. + dwords = (len + 3) / 4;
  101151. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  101152. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  101153. + }
  101154. +
  101155. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  101156. + DWC_READ_REG32(&global_regs->gnptxsts));
  101157. +
  101158. + /* Clear interrupt */
  101159. + gintsts.d32 = 0;
  101160. + gintsts.b.nptxfempty = 1;
  101161. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  101162. +
  101163. + return 1;
  101164. +}
  101165. +
  101166. +/**
  101167. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  101168. + * The active request is checked for the next packet to be loaded into
  101169. + * apropriate Tx FIFO.
  101170. + */
  101171. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  101172. +{
  101173. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101174. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  101175. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  101176. + dtxfsts_data_t txstatus = {.d32 = 0 };
  101177. + dwc_otg_pcd_ep_t *ep = 0;
  101178. + uint32_t len = 0;
  101179. + int dwords;
  101180. +
  101181. + ep = get_in_ep(pcd, epnum);
  101182. +
  101183. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  101184. +
  101185. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  101186. +
  101187. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  101188. +
  101189. + if (len > ep->dwc_ep.maxpacket) {
  101190. + len = ep->dwc_ep.maxpacket;
  101191. + }
  101192. +
  101193. + dwords = (len + 3) / 4;
  101194. +
  101195. + /* While there is space in the queue and space in the FIFO and
  101196. + * More data to tranfer, Write packets to the Tx FIFO */
  101197. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  101198. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  101199. +
  101200. + while (txstatus.b.txfspcavail > dwords &&
  101201. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  101202. + ep->dwc_ep.xfer_len != 0) {
  101203. + /* Write the FIFO */
  101204. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  101205. +
  101206. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  101207. + if (len > ep->dwc_ep.maxpacket) {
  101208. + len = ep->dwc_ep.maxpacket;
  101209. + }
  101210. +
  101211. + dwords = (len + 3) / 4;
  101212. + txstatus.d32 =
  101213. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  101214. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  101215. + txstatus.d32);
  101216. + }
  101217. +
  101218. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  101219. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  101220. +
  101221. + return 1;
  101222. +}
  101223. +
  101224. +/**
  101225. + * This function is called when the Device is disconnected. It stops
  101226. + * any active requests and informs the Gadget driver of the
  101227. + * disconnect.
  101228. + */
  101229. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  101230. +{
  101231. + int i, num_in_eps, num_out_eps;
  101232. + dwc_otg_pcd_ep_t *ep;
  101233. +
  101234. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101235. +
  101236. + DWC_SPINLOCK(pcd->lock);
  101237. +
  101238. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  101239. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  101240. +
  101241. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  101242. + /* don't disconnect drivers more than once */
  101243. + if (pcd->ep0state == EP0_DISCONNECT) {
  101244. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  101245. + DWC_SPINUNLOCK(pcd->lock);
  101246. + return;
  101247. + }
  101248. + pcd->ep0state = EP0_DISCONNECT;
  101249. +
  101250. + /* Reset the OTG state. */
  101251. + dwc_otg_pcd_update_otg(pcd, 1);
  101252. +
  101253. + /* Disable the NP Tx Fifo Empty Interrupt. */
  101254. + intr_mask.b.nptxfempty = 1;
  101255. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101256. + intr_mask.d32, 0);
  101257. +
  101258. + /* Flush the FIFOs */
  101259. + /**@todo NGS Flush Periodic FIFOs */
  101260. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  101261. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  101262. +
  101263. + /* prevent new request submissions, kill any outstanding requests */
  101264. + ep = &pcd->ep0;
  101265. + dwc_otg_request_nuke(ep);
  101266. + /* prevent new request submissions, kill any outstanding requests */
  101267. + for (i = 0; i < num_in_eps; i++) {
  101268. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  101269. + dwc_otg_request_nuke(ep);
  101270. + }
  101271. + /* prevent new request submissions, kill any outstanding requests */
  101272. + for (i = 0; i < num_out_eps; i++) {
  101273. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  101274. + dwc_otg_request_nuke(ep);
  101275. + }
  101276. +
  101277. + /* report disconnect; the driver is already quiesced */
  101278. + if (pcd->fops->disconnect) {
  101279. + DWC_SPINUNLOCK(pcd->lock);
  101280. + pcd->fops->disconnect(pcd);
  101281. + DWC_SPINLOCK(pcd->lock);
  101282. + }
  101283. + DWC_SPINUNLOCK(pcd->lock);
  101284. +}
  101285. +
  101286. +/**
  101287. + * This interrupt indicates that ...
  101288. + */
  101289. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  101290. +{
  101291. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101292. + gintsts_data_t gintsts;
  101293. +
  101294. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  101295. + intr_mask.b.i2cintr = 1;
  101296. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101297. + intr_mask.d32, 0);
  101298. +
  101299. + /* Clear interrupt */
  101300. + gintsts.d32 = 0;
  101301. + gintsts.b.i2cintr = 1;
  101302. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101303. + gintsts.d32);
  101304. + return 1;
  101305. +}
  101306. +
  101307. +/**
  101308. + * This interrupt indicates that ...
  101309. + */
  101310. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  101311. +{
  101312. + gintsts_data_t gintsts;
  101313. +#if defined(VERBOSE)
  101314. + DWC_PRINTF("Early Suspend Detected\n");
  101315. +#endif
  101316. +
  101317. + /* Clear interrupt */
  101318. + gintsts.d32 = 0;
  101319. + gintsts.b.erlysuspend = 1;
  101320. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101321. + gintsts.d32);
  101322. + return 1;
  101323. +}
  101324. +
  101325. +/**
  101326. + * This function configures EPO to receive SETUP packets.
  101327. + *
  101328. + * @todo NGS: Update the comments from the HW FS.
  101329. + *
  101330. + * -# Program the following fields in the endpoint specific registers
  101331. + * for Control OUT EP 0, in order to receive a setup packet
  101332. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  101333. + * setup packets)
  101334. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  101335. + * to back setup packets)
  101336. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  101337. + * store any setup packets received
  101338. + *
  101339. + * @param core_if Programming view of DWC_otg controller.
  101340. + * @param pcd Programming view of the PCD.
  101341. + */
  101342. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  101343. + dwc_otg_pcd_t * pcd)
  101344. +{
  101345. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  101346. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  101347. + dwc_otg_dev_dma_desc_t *dma_desc;
  101348. + depctl_data_t doepctl = {.d32 = 0 };
  101349. +
  101350. +#ifdef VERBOSE
  101351. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  101352. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  101353. +#endif
  101354. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  101355. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  101356. + if (doepctl.b.epena) {
  101357. + return;
  101358. + }
  101359. + }
  101360. +
  101361. + doeptsize0.b.supcnt = 3;
  101362. + doeptsize0.b.pktcnt = 1;
  101363. + doeptsize0.b.xfersize = 8 * 3;
  101364. +
  101365. + if (core_if->dma_enable) {
  101366. + if (!core_if->dma_desc_enable) {
  101367. + /** put here as for Hermes mode deptisz register should not be written */
  101368. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  101369. + doeptsize0.d32);
  101370. +
  101371. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  101372. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  101373. + pcd->setup_pkt_dma_handle);
  101374. + } else {
  101375. + dev_if->setup_desc_index =
  101376. + (dev_if->setup_desc_index + 1) & 1;
  101377. + dma_desc =
  101378. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  101379. +
  101380. + /** DMA Descriptor Setup */
  101381. + dma_desc->status.b.bs = BS_HOST_BUSY;
  101382. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  101383. + dma_desc->status.b.sr = 0;
  101384. + dma_desc->status.b.mtrf = 0;
  101385. + }
  101386. + dma_desc->status.b.l = 1;
  101387. + dma_desc->status.b.ioc = 1;
  101388. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  101389. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  101390. + dma_desc->status.b.sts = 0;
  101391. + dma_desc->status.b.bs = BS_HOST_READY;
  101392. +
  101393. + /** DOEPDMA0 Register write */
  101394. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  101395. + dev_if->dma_setup_desc_addr
  101396. + [dev_if->setup_desc_index]);
  101397. + }
  101398. +
  101399. + } else {
  101400. + /** put here as for Hermes mode deptisz register should not be written */
  101401. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  101402. + doeptsize0.d32);
  101403. + }
  101404. +
  101405. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  101406. + doepctl.d32 = 0;
  101407. + doepctl.b.epena = 1;
  101408. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  101409. + doepctl.b.cnak = 1;
  101410. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  101411. + } else {
  101412. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  101413. + }
  101414. +
  101415. +#ifdef VERBOSE
  101416. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  101417. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  101418. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  101419. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  101420. +#endif
  101421. +}
  101422. +
  101423. +/**
  101424. + * This interrupt occurs when a USB Reset is detected. When the USB
  101425. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  101426. + * EP0 state is set to IDLE.
  101427. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  101428. + * -# Unmask the following interrupt bits
  101429. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  101430. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  101431. + * - DOEPMSK.SETUP = 1
  101432. + * - DOEPMSK.XferCompl = 1
  101433. + * - DIEPMSK.XferCompl = 1
  101434. + * - DIEPMSK.TimeOut = 1
  101435. + * -# Program the following fields in the endpoint specific registers
  101436. + * for Control OUT EP 0, in order to receive a setup packet
  101437. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  101438. + * setup packets)
  101439. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  101440. + * to back setup packets)
  101441. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  101442. + * store any setup packets received
  101443. + * At this point, all the required initialization, except for enabling
  101444. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  101445. + */
  101446. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  101447. +{
  101448. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101449. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  101450. + depctl_data_t doepctl = {.d32 = 0 };
  101451. + depctl_data_t diepctl = {.d32 = 0 };
  101452. + daint_data_t daintmsk = {.d32 = 0 };
  101453. + doepmsk_data_t doepmsk = {.d32 = 0 };
  101454. + diepmsk_data_t diepmsk = {.d32 = 0 };
  101455. + dcfg_data_t dcfg = {.d32 = 0 };
  101456. + grstctl_t resetctl = {.d32 = 0 };
  101457. + dctl_data_t dctl = {.d32 = 0 };
  101458. + int i = 0;
  101459. + gintsts_data_t gintsts;
  101460. + pcgcctl_data_t power = {.d32 = 0 };
  101461. +
  101462. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  101463. + if (power.b.stoppclk) {
  101464. + power.d32 = 0;
  101465. + power.b.stoppclk = 1;
  101466. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101467. +
  101468. + power.b.pwrclmp = 1;
  101469. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101470. +
  101471. + power.b.rstpdwnmodule = 1;
  101472. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  101473. + }
  101474. +
  101475. + core_if->lx_state = DWC_OTG_L0;
  101476. +
  101477. + DWC_PRINTF("USB RESET\n");
  101478. +#ifdef DWC_EN_ISOC
  101479. + for (i = 1; i < 16; ++i) {
  101480. + dwc_otg_pcd_ep_t *ep;
  101481. + dwc_ep_t *dwc_ep;
  101482. + ep = get_in_ep(pcd, i);
  101483. + if (ep != 0) {
  101484. + dwc_ep = &ep->dwc_ep;
  101485. + dwc_ep->next_frame = 0xffffffff;
  101486. + }
  101487. + }
  101488. +#endif /* DWC_EN_ISOC */
  101489. +
  101490. + /* reset the HNP settings */
  101491. + dwc_otg_pcd_update_otg(pcd, 1);
  101492. +
  101493. + /* Clear the Remote Wakeup Signalling */
  101494. + dctl.b.rmtwkupsig = 1;
  101495. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  101496. +
  101497. + /* Set NAK for all OUT EPs */
  101498. + doepctl.b.snak = 1;
  101499. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  101500. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  101501. + }
  101502. +
  101503. + /* Flush the NP Tx FIFO */
  101504. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  101505. + /* Flush the Learning Queue */
  101506. + resetctl.b.intknqflsh = 1;
  101507. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  101508. +
  101509. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  101510. + core_if->start_predict = 0;
  101511. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  101512. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  101513. + }
  101514. + core_if->nextep_seq[0] = 0;
  101515. + core_if->first_in_nextep_seq = 0;
  101516. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  101517. + diepctl.b.nextep = 0;
  101518. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  101519. +
  101520. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  101521. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  101522. + dcfg.b.epmscnt = 2;
  101523. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  101524. +
  101525. + DWC_DEBUGPL(DBG_PCDV,
  101526. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  101527. + __func__, core_if->first_in_nextep_seq);
  101528. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  101529. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  101530. + }
  101531. + }
  101532. +
  101533. + if (core_if->multiproc_int_enable) {
  101534. + daintmsk.b.inep0 = 1;
  101535. + daintmsk.b.outep0 = 1;
  101536. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  101537. + daintmsk.d32);
  101538. +
  101539. + doepmsk.b.setup = 1;
  101540. + doepmsk.b.xfercompl = 1;
  101541. + doepmsk.b.ahberr = 1;
  101542. + doepmsk.b.epdisabled = 1;
  101543. +
  101544. + if ((core_if->dma_desc_enable) ||
  101545. + (core_if->dma_enable
  101546. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  101547. + doepmsk.b.stsphsercvd = 1;
  101548. + }
  101549. + if (core_if->dma_desc_enable)
  101550. + doepmsk.b.bna = 1;
  101551. +/*
  101552. + doepmsk.b.babble = 1;
  101553. + doepmsk.b.nyet = 1;
  101554. +
  101555. + if (core_if->dma_enable) {
  101556. + doepmsk.b.nak = 1;
  101557. + }
  101558. +*/
  101559. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  101560. + doepmsk.d32);
  101561. +
  101562. + diepmsk.b.xfercompl = 1;
  101563. + diepmsk.b.timeout = 1;
  101564. + diepmsk.b.epdisabled = 1;
  101565. + diepmsk.b.ahberr = 1;
  101566. + diepmsk.b.intknepmis = 1;
  101567. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  101568. + diepmsk.b.intknepmis = 0;
  101569. +
  101570. +/* if (core_if->dma_desc_enable) {
  101571. + diepmsk.b.bna = 1;
  101572. + }
  101573. +*/
  101574. +/*
  101575. + if (core_if->dma_enable) {
  101576. + diepmsk.b.nak = 1;
  101577. + }
  101578. +*/
  101579. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  101580. + diepmsk.d32);
  101581. + } else {
  101582. + daintmsk.b.inep0 = 1;
  101583. + daintmsk.b.outep0 = 1;
  101584. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  101585. + daintmsk.d32);
  101586. +
  101587. + doepmsk.b.setup = 1;
  101588. + doepmsk.b.xfercompl = 1;
  101589. + doepmsk.b.ahberr = 1;
  101590. + doepmsk.b.epdisabled = 1;
  101591. +
  101592. + if ((core_if->dma_desc_enable) ||
  101593. + (core_if->dma_enable
  101594. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  101595. + doepmsk.b.stsphsercvd = 1;
  101596. + }
  101597. + if (core_if->dma_desc_enable)
  101598. + doepmsk.b.bna = 1;
  101599. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  101600. +
  101601. + diepmsk.b.xfercompl = 1;
  101602. + diepmsk.b.timeout = 1;
  101603. + diepmsk.b.epdisabled = 1;
  101604. + diepmsk.b.ahberr = 1;
  101605. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  101606. + diepmsk.b.intknepmis = 0;
  101607. +/*
  101608. + if (core_if->dma_desc_enable) {
  101609. + diepmsk.b.bna = 1;
  101610. + }
  101611. +*/
  101612. +
  101613. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  101614. + }
  101615. +
  101616. + /* Reset Device Address */
  101617. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  101618. + dcfg.b.devaddr = 0;
  101619. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  101620. +
  101621. + /* setup EP0 to receive SETUP packets */
  101622. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  101623. + ep0_out_start(core_if, pcd);
  101624. +
  101625. + /* Clear interrupt */
  101626. + gintsts.d32 = 0;
  101627. + gintsts.b.usbreset = 1;
  101628. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101629. +
  101630. + return 1;
  101631. +}
  101632. +
  101633. +/**
  101634. + * Get the device speed from the device status register and convert it
  101635. + * to USB speed constant.
  101636. + *
  101637. + * @param core_if Programming view of DWC_otg controller.
  101638. + */
  101639. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  101640. +{
  101641. + dsts_data_t dsts;
  101642. + int speed = 0;
  101643. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  101644. +
  101645. + switch (dsts.b.enumspd) {
  101646. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  101647. + speed = USB_SPEED_HIGH;
  101648. + break;
  101649. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  101650. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  101651. + speed = USB_SPEED_FULL;
  101652. + break;
  101653. +
  101654. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  101655. + speed = USB_SPEED_LOW;
  101656. + break;
  101657. + }
  101658. +
  101659. + return speed;
  101660. +}
  101661. +
  101662. +/**
  101663. + * Read the device status register and set the device speed in the
  101664. + * data structure.
  101665. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  101666. + */
  101667. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  101668. +{
  101669. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101670. + gintsts_data_t gintsts;
  101671. + gusbcfg_data_t gusbcfg;
  101672. + dwc_otg_core_global_regs_t *global_regs =
  101673. + GET_CORE_IF(pcd)->core_global_regs;
  101674. + uint8_t utmi16b, utmi8b;
  101675. + int speed;
  101676. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  101677. +
  101678. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  101679. + utmi16b = 6; //vahrama old value was 6;
  101680. + utmi8b = 9;
  101681. + } else {
  101682. + utmi16b = 4;
  101683. + utmi8b = 8;
  101684. + }
  101685. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101686. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  101687. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  101688. + }
  101689. +
  101690. +#ifdef DEBUG_EP0
  101691. + print_ep0_state(pcd);
  101692. +#endif
  101693. +
  101694. + if (pcd->ep0state == EP0_DISCONNECT) {
  101695. + pcd->ep0state = EP0_IDLE;
  101696. + } else if (pcd->ep0state == EP0_STALL) {
  101697. + pcd->ep0state = EP0_IDLE;
  101698. + }
  101699. +
  101700. + pcd->ep0state = EP0_IDLE;
  101701. +
  101702. + ep0->stopped = 0;
  101703. +
  101704. + speed = get_device_speed(GET_CORE_IF(pcd));
  101705. + pcd->fops->connect(pcd, speed);
  101706. +
  101707. + /* Set USB turnaround time based on device speed and PHY interface. */
  101708. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  101709. + if (speed == USB_SPEED_HIGH) {
  101710. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101711. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  101712. + /* ULPI interface */
  101713. + gusbcfg.b.usbtrdtim = 9;
  101714. + }
  101715. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101716. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  101717. + /* UTMI+ interface */
  101718. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  101719. + gusbcfg.b.usbtrdtim = utmi8b;
  101720. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  101721. + b.utmi_phy_data_width == 1) {
  101722. + gusbcfg.b.usbtrdtim = utmi16b;
  101723. + } else if (GET_CORE_IF(pcd)->
  101724. + core_params->phy_utmi_width == 8) {
  101725. + gusbcfg.b.usbtrdtim = utmi8b;
  101726. + } else {
  101727. + gusbcfg.b.usbtrdtim = utmi16b;
  101728. + }
  101729. + }
  101730. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  101731. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  101732. + /* UTMI+ OR ULPI interface */
  101733. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  101734. + /* ULPI interface */
  101735. + gusbcfg.b.usbtrdtim = 9;
  101736. + } else {
  101737. + /* UTMI+ interface */
  101738. + if (GET_CORE_IF(pcd)->
  101739. + core_params->phy_utmi_width == 16) {
  101740. + gusbcfg.b.usbtrdtim = utmi16b;
  101741. + } else {
  101742. + gusbcfg.b.usbtrdtim = utmi8b;
  101743. + }
  101744. + }
  101745. + }
  101746. + } else {
  101747. + /* Full or low speed */
  101748. + gusbcfg.b.usbtrdtim = 9;
  101749. + }
  101750. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  101751. +
  101752. + /* Clear interrupt */
  101753. + gintsts.d32 = 0;
  101754. + gintsts.b.enumdone = 1;
  101755. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101756. + gintsts.d32);
  101757. + return 1;
  101758. +}
  101759. +
  101760. +/**
  101761. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  101762. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  101763. + * read all the data from the Rx FIFO.
  101764. + */
  101765. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  101766. +{
  101767. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101768. + gintsts_data_t gintsts;
  101769. +
  101770. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  101771. + "ISOC Out Dropped");
  101772. +
  101773. + intr_mask.b.isooutdrop = 1;
  101774. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101775. + intr_mask.d32, 0);
  101776. +
  101777. + /* Clear interrupt */
  101778. + gintsts.d32 = 0;
  101779. + gintsts.b.isooutdrop = 1;
  101780. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101781. + gintsts.d32);
  101782. +
  101783. + return 1;
  101784. +}
  101785. +
  101786. +/**
  101787. + * This interrupt indicates the end of the portion of the micro-frame
  101788. + * for periodic transactions. If there is a periodic transaction for
  101789. + * the next frame, load the packets into the EP periodic Tx FIFO.
  101790. + */
  101791. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  101792. +{
  101793. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101794. + gintsts_data_t gintsts;
  101795. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  101796. +
  101797. + intr_mask.b.eopframe = 1;
  101798. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  101799. + intr_mask.d32, 0);
  101800. +
  101801. + /* Clear interrupt */
  101802. + gintsts.d32 = 0;
  101803. + gintsts.b.eopframe = 1;
  101804. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  101805. + gintsts.d32);
  101806. +
  101807. + return 1;
  101808. +}
  101809. +
  101810. +/**
  101811. + * This interrupt indicates that EP of the packet on the top of the
  101812. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  101813. + *
  101814. + * The "Device IN Token Queue" Registers are read to determine the
  101815. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  101816. + * is flushed, so it can be reloaded in the order seen in the IN Token
  101817. + * Queue.
  101818. + */
  101819. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  101820. +{
  101821. + gintsts_data_t gintsts;
  101822. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101823. + dctl_data_t dctl;
  101824. + gintmsk_data_t intr_mask = {.d32 = 0 };
  101825. +
  101826. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  101827. + core_if->start_predict = 1;
  101828. +
  101829. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  101830. +
  101831. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  101832. + if (!gintsts.b.ginnakeff) {
  101833. + /* Disable EP Mismatch interrupt */
  101834. + intr_mask.d32 = 0;
  101835. + intr_mask.b.epmismatch = 1;
  101836. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  101837. + /* Enable the Global IN NAK Effective Interrupt */
  101838. + intr_mask.d32 = 0;
  101839. + intr_mask.b.ginnakeff = 1;
  101840. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  101841. + /* Set the global non-periodic IN NAK handshake */
  101842. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  101843. + dctl.b.sgnpinnak = 1;
  101844. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  101845. + } else {
  101846. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  101847. + }
  101848. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  101849. + * handler after Global IN NAK Effective interrupt will be asserted */
  101850. + }
  101851. + /* Clear interrupt */
  101852. + gintsts.d32 = 0;
  101853. + gintsts.b.epmismatch = 1;
  101854. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101855. +
  101856. + return 1;
  101857. +}
  101858. +
  101859. +/**
  101860. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  101861. + * core has stopped fetching data for IN endpoints due to the unavailability of
  101862. + * TxFIFO space or Request Queue space. This interrupt is used by the
  101863. + * application for an endpoint mismatch algorithm.
  101864. + *
  101865. + * @param pcd The PCD
  101866. + */
  101867. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  101868. +{
  101869. + gintsts_data_t gintsts;
  101870. + gintmsk_data_t gintmsk_data;
  101871. + dctl_data_t dctl;
  101872. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  101873. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  101874. +
  101875. + /* Clear the global non-periodic IN NAK handshake */
  101876. + dctl.d32 = 0;
  101877. + dctl.b.cgnpinnak = 1;
  101878. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  101879. +
  101880. + /* Mask GINTSTS.FETSUSP interrupt */
  101881. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  101882. + gintmsk_data.b.fetsusp = 0;
  101883. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  101884. +
  101885. + /* Clear interrupt */
  101886. + gintsts.d32 = 0;
  101887. + gintsts.b.fetsusp = 1;
  101888. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  101889. +
  101890. + return 1;
  101891. +}
  101892. +/**
  101893. + * This funcion stalls EP0.
  101894. + */
  101895. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  101896. +{
  101897. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101898. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  101899. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  101900. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  101901. +
  101902. + ep0->dwc_ep.is_in = 1;
  101903. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101904. + pcd->ep0.stopped = 1;
  101905. + pcd->ep0state = EP0_IDLE;
  101906. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  101907. +}
  101908. +
  101909. +/**
  101910. + * This functions delegates the setup command to the gadget driver.
  101911. + */
  101912. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  101913. + usb_device_request_t * ctrl)
  101914. +{
  101915. + int ret = 0;
  101916. + DWC_SPINUNLOCK(pcd->lock);
  101917. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  101918. + DWC_SPINLOCK(pcd->lock);
  101919. + if (ret < 0) {
  101920. + ep0_do_stall(pcd, ret);
  101921. + }
  101922. +
  101923. + /** @todo This is a g_file_storage gadget driver specific
  101924. + * workaround: a DELAYED_STATUS result from the fsg_setup
  101925. + * routine will result in the gadget queueing a EP0 IN status
  101926. + * phase for a two-stage control transfer. Exactly the same as
  101927. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  101928. + * specific request. Need a generic way to know when the gadget
  101929. + * driver will queue the status phase. Can we assume when we
  101930. + * call the gadget driver setup() function that it will always
  101931. + * queue and require the following flag? Need to look into
  101932. + * this.
  101933. + */
  101934. +
  101935. + if (ret == 256 + 999) {
  101936. + pcd->request_config = 1;
  101937. + }
  101938. +}
  101939. +
  101940. +#ifdef DWC_UTE_CFI
  101941. +/**
  101942. + * This functions delegates the CFI setup commands to the gadget driver.
  101943. + * This function will return a negative value to indicate a failure.
  101944. + */
  101945. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  101946. + struct cfi_usb_ctrlrequest *ctrl_req)
  101947. +{
  101948. + int ret = 0;
  101949. +
  101950. + if (pcd->fops && pcd->fops->cfi_setup) {
  101951. + DWC_SPINUNLOCK(pcd->lock);
  101952. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  101953. + DWC_SPINLOCK(pcd->lock);
  101954. + if (ret < 0) {
  101955. + ep0_do_stall(pcd, ret);
  101956. + return ret;
  101957. + }
  101958. + }
  101959. +
  101960. + return ret;
  101961. +}
  101962. +#endif
  101963. +
  101964. +/**
  101965. + * This function starts the Zero-Length Packet for the IN status phase
  101966. + * of a 2 stage control transfer.
  101967. + */
  101968. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  101969. +{
  101970. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  101971. + if (pcd->ep0state == EP0_STALL) {
  101972. + return;
  101973. + }
  101974. +
  101975. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  101976. +
  101977. + /* Prepare for more SETUP Packets */
  101978. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  101979. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  101980. + && (pcd->core_if->dma_desc_enable)
  101981. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  101982. + DWC_DEBUGPL(DBG_PCDV,
  101983. + "Data terminated wait next packet in out_desc_addr\n");
  101984. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  101985. + pcd->data_terminated = 1;
  101986. + }
  101987. + ep0->dwc_ep.xfer_len = 0;
  101988. + ep0->dwc_ep.xfer_count = 0;
  101989. + ep0->dwc_ep.is_in = 1;
  101990. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  101991. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  101992. +
  101993. + /* Prepare for more SETUP Packets */
  101994. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  101995. +}
  101996. +
  101997. +/**
  101998. + * This function starts the Zero-Length Packet for the OUT status phase
  101999. + * of a 2 stage control transfer.
  102000. + */
  102001. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  102002. +{
  102003. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  102004. + if (pcd->ep0state == EP0_STALL) {
  102005. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  102006. + return;
  102007. + }
  102008. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  102009. +
  102010. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  102011. + ep0->dwc_ep.xfer_len = 0;
  102012. + ep0->dwc_ep.xfer_count = 0;
  102013. + ep0->dwc_ep.is_in = 0;
  102014. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  102015. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  102016. +
  102017. + /* Prepare for more SETUP Packets */
  102018. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  102019. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  102020. + }
  102021. +}
  102022. +
  102023. +/**
  102024. + * Clear the EP halt (STALL) and if pending requests start the
  102025. + * transfer.
  102026. + */
  102027. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  102028. +{
  102029. + if (ep->dwc_ep.stall_clear_flag == 0)
  102030. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  102031. +
  102032. + /* Reactive the EP */
  102033. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  102034. + if (ep->stopped) {
  102035. + ep->stopped = 0;
  102036. + /* If there is a request in the EP queue start it */
  102037. +
  102038. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  102039. + * epmismatch not yet implemented. */
  102040. +
  102041. + /*
  102042. + * Above fixme is solved by implmenting a tasklet to call the
  102043. + * start_next_request(), outside of interrupt context at some
  102044. + * time after the current time, after a clear-halt setup packet.
  102045. + * Still need to implement ep mismatch in the future if a gadget
  102046. + * ever uses more than one endpoint at once
  102047. + */
  102048. + ep->queue_sof = 1;
  102049. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  102050. + }
  102051. + /* Start Control Status Phase */
  102052. + do_setup_in_status_phase(pcd);
  102053. +}
  102054. +
  102055. +/**
  102056. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  102057. + * is sent from the host. The Device Control register is written with
  102058. + * the Test Mode bits set to the specified Test Mode. This is done as
  102059. + * a tasklet so that the "Status" phase of the control transfer
  102060. + * completes before transmitting the TEST packets.
  102061. + *
  102062. + * @todo This has not been tested since the tasklet struct was put
  102063. + * into the PCD struct!
  102064. + *
  102065. + */
  102066. +void do_test_mode(void *data)
  102067. +{
  102068. + dctl_data_t dctl;
  102069. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  102070. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  102071. + int test_mode = pcd->test_mode;
  102072. +
  102073. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  102074. +
  102075. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  102076. + switch (test_mode) {
  102077. + case 1: // TEST_J
  102078. + dctl.b.tstctl = 1;
  102079. + break;
  102080. +
  102081. + case 2: // TEST_K
  102082. + dctl.b.tstctl = 2;
  102083. + break;
  102084. +
  102085. + case 3: // TEST_SE0_NAK
  102086. + dctl.b.tstctl = 3;
  102087. + break;
  102088. +
  102089. + case 4: // TEST_PACKET
  102090. + dctl.b.tstctl = 4;
  102091. + break;
  102092. +
  102093. + case 5: // TEST_FORCE_ENABLE
  102094. + dctl.b.tstctl = 5;
  102095. + break;
  102096. + }
  102097. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  102098. +}
  102099. +
  102100. +/**
  102101. + * This function process the GET_STATUS Setup Commands.
  102102. + */
  102103. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  102104. +{
  102105. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  102106. + dwc_otg_pcd_ep_t *ep;
  102107. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  102108. + uint16_t *status = pcd->status_buf;
  102109. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  102110. +
  102111. +#ifdef DEBUG_EP0
  102112. + DWC_DEBUGPL(DBG_PCD,
  102113. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  102114. + ctrl.bmRequestType, ctrl.bRequest,
  102115. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  102116. + UGETW(ctrl.wLength));
  102117. +#endif
  102118. +
  102119. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  102120. + case UT_DEVICE:
  102121. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  102122. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  102123. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  102124. + DWC_PRINTF("OTG CAP - %d, %d\n",
  102125. + core_if->core_params->otg_cap,
  102126. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  102127. + if (core_if->otg_ver == 1
  102128. + && core_if->core_params->otg_cap ==
  102129. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  102130. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  102131. + *otgsts = (core_if->otg_sts & 0x1);
  102132. + pcd->ep0_pending = 1;
  102133. + ep0->dwc_ep.start_xfer_buff =
  102134. + (uint8_t *) otgsts;
  102135. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  102136. + ep0->dwc_ep.dma_addr =
  102137. + pcd->status_buf_dma_handle;
  102138. + ep0->dwc_ep.xfer_len = 1;
  102139. + ep0->dwc_ep.xfer_count = 0;
  102140. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  102141. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  102142. + &ep0->dwc_ep);
  102143. + return;
  102144. + } else {
  102145. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102146. + return;
  102147. + }
  102148. + break;
  102149. + } else {
  102150. + *status = 0x1; /* Self powered */
  102151. + *status |= pcd->remote_wakeup_enable << 1;
  102152. + break;
  102153. + }
  102154. + case UT_INTERFACE:
  102155. + *status = 0;
  102156. + break;
  102157. +
  102158. + case UT_ENDPOINT:
  102159. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  102160. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  102161. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102162. + return;
  102163. + }
  102164. + /** @todo check for EP stall */
  102165. + *status = ep->stopped;
  102166. + break;
  102167. + }
  102168. + pcd->ep0_pending = 1;
  102169. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  102170. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  102171. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  102172. + ep0->dwc_ep.xfer_len = 2;
  102173. + ep0->dwc_ep.xfer_count = 0;
  102174. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  102175. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  102176. +}
  102177. +
  102178. +/**
  102179. + * This function process the SET_FEATURE Setup Commands.
  102180. + */
  102181. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  102182. +{
  102183. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  102184. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  102185. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  102186. + dwc_otg_pcd_ep_t *ep = 0;
  102187. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  102188. + gotgctl_data_t gotgctl = {.d32 = 0 };
  102189. +
  102190. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  102191. + ctrl.bmRequestType, ctrl.bRequest,
  102192. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  102193. + UGETW(ctrl.wLength));
  102194. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  102195. +
  102196. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  102197. + case UT_DEVICE:
  102198. + switch (UGETW(ctrl.wValue)) {
  102199. + case UF_DEVICE_REMOTE_WAKEUP:
  102200. + pcd->remote_wakeup_enable = 1;
  102201. + break;
  102202. +
  102203. + case UF_TEST_MODE:
  102204. + /* Setup the Test Mode tasklet to do the Test
  102205. + * Packet generation after the SETUP Status
  102206. + * phase has completed. */
  102207. +
  102208. + /** @todo This has not been tested since the
  102209. + * tasklet struct was put into the PCD
  102210. + * struct! */
  102211. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  102212. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  102213. + break;
  102214. +
  102215. + case UF_DEVICE_B_HNP_ENABLE:
  102216. + DWC_DEBUGPL(DBG_PCDV,
  102217. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  102218. +
  102219. + /* dev may initiate HNP */
  102220. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  102221. + pcd->b_hnp_enable = 1;
  102222. + dwc_otg_pcd_update_otg(pcd, 0);
  102223. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  102224. + /**@todo Is the gotgctl.devhnpen cleared
  102225. + * by a USB Reset? */
  102226. + gotgctl.b.devhnpen = 1;
  102227. + gotgctl.b.hnpreq = 1;
  102228. + DWC_WRITE_REG32(&global_regs->gotgctl,
  102229. + gotgctl.d32);
  102230. + } else {
  102231. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102232. + return;
  102233. + }
  102234. + break;
  102235. +
  102236. + case UF_DEVICE_A_HNP_SUPPORT:
  102237. + /* RH port supports HNP */
  102238. + DWC_DEBUGPL(DBG_PCDV,
  102239. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  102240. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  102241. + pcd->a_hnp_support = 1;
  102242. + dwc_otg_pcd_update_otg(pcd, 0);
  102243. + } else {
  102244. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102245. + return;
  102246. + }
  102247. + break;
  102248. +
  102249. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  102250. + /* other RH port does */
  102251. + DWC_DEBUGPL(DBG_PCDV,
  102252. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  102253. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  102254. + pcd->a_alt_hnp_support = 1;
  102255. + dwc_otg_pcd_update_otg(pcd, 0);
  102256. + } else {
  102257. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102258. + return;
  102259. + }
  102260. + break;
  102261. +
  102262. + default:
  102263. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102264. + return;
  102265. +
  102266. + }
  102267. + do_setup_in_status_phase(pcd);
  102268. + break;
  102269. +
  102270. + case UT_INTERFACE:
  102271. + do_gadget_setup(pcd, &ctrl);
  102272. + break;
  102273. +
  102274. + case UT_ENDPOINT:
  102275. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  102276. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  102277. + if (ep == 0) {
  102278. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102279. + return;
  102280. + }
  102281. + ep->stopped = 1;
  102282. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  102283. + }
  102284. + do_setup_in_status_phase(pcd);
  102285. + break;
  102286. + }
  102287. +}
  102288. +
  102289. +/**
  102290. + * This function process the CLEAR_FEATURE Setup Commands.
  102291. + */
  102292. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  102293. +{
  102294. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  102295. + dwc_otg_pcd_ep_t *ep = 0;
  102296. +
  102297. + DWC_DEBUGPL(DBG_PCD,
  102298. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  102299. + ctrl.bmRequestType, ctrl.bRequest,
  102300. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  102301. + UGETW(ctrl.wLength));
  102302. +
  102303. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  102304. + case UT_DEVICE:
  102305. + switch (UGETW(ctrl.wValue)) {
  102306. + case UF_DEVICE_REMOTE_WAKEUP:
  102307. + pcd->remote_wakeup_enable = 0;
  102308. + break;
  102309. +
  102310. + case UF_TEST_MODE:
  102311. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  102312. + break;
  102313. +
  102314. + default:
  102315. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102316. + return;
  102317. + }
  102318. + do_setup_in_status_phase(pcd);
  102319. + break;
  102320. +
  102321. + case UT_ENDPOINT:
  102322. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  102323. + if (ep == 0) {
  102324. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  102325. + return;
  102326. + }
  102327. +
  102328. + pcd_clear_halt(pcd, ep);
  102329. +
  102330. + break;
  102331. + }
  102332. +}
  102333. +
  102334. +/**
  102335. + * This function process the SET_ADDRESS Setup Commands.
  102336. + */
  102337. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  102338. +{
  102339. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  102340. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  102341. +
  102342. + if (ctrl.bmRequestType == UT_DEVICE) {
  102343. + dcfg_data_t dcfg = {.d32 = 0 };
  102344. +
  102345. +#ifdef DEBUG_EP0
  102346. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  102347. +#endif
  102348. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  102349. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  102350. + do_setup_in_status_phase(pcd);
  102351. + }
  102352. +}
  102353. +
  102354. +/**
  102355. + * This function processes SETUP commands. In Linux, the USB Command
  102356. + * processing is done in two places - the first being the PCD and the
  102357. + * second in the Gadget Driver (for example, the File-Backed Storage
  102358. + * Gadget Driver).
  102359. + *
  102360. + * <table>
  102361. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  102362. + *
  102363. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  102364. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  102365. + * </td></tr>
  102366. + *
  102367. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  102368. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  102369. + * interface requests are ignored.</td></tr>
  102370. + *
  102371. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  102372. + * requests are processed by the PCD. Interface requests are passed
  102373. + * to the Gadget Driver.</td></tr>
  102374. + *
  102375. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  102376. + * with device address received </td></tr>
  102377. + *
  102378. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  102379. + * requested descriptor</td></tr>
  102380. + *
  102381. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  102382. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  102383. + *
  102384. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  102385. + * all EPs and enable EPs for new configuration.</td></tr>
  102386. + *
  102387. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  102388. + * the current configuration</td></tr>
  102389. + *
  102390. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  102391. + * EPs and enable EPs for new configuration.</td></tr>
  102392. + *
  102393. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  102394. + * current interface.</td></tr>
  102395. + *
  102396. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  102397. + * message.</td></tr>
  102398. + * </table>
  102399. + *
  102400. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  102401. + * processed by pcd_setup. Calling the Function Driver's setup function from
  102402. + * pcd_setup processes the gadget SETUP commands.
  102403. + */
  102404. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  102405. +{
  102406. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  102407. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  102408. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  102409. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  102410. +
  102411. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  102412. +
  102413. +#ifdef DWC_UTE_CFI
  102414. + int retval = 0;
  102415. + struct cfi_usb_ctrlrequest cfi_req;
  102416. +#endif
  102417. +
  102418. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  102419. +
  102420. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  102421. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  102422. + && (doeptsize0.b.supcnt < 2)
  102423. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  102424. + DWC_ERROR
  102425. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  102426. + }
  102427. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  102428. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  102429. + ctrl =
  102430. + (pcd->setup_pkt +
  102431. + (3 - doeptsize0.b.supcnt - 1 +
  102432. + ep0->dwc_ep.stp_rollover))->req;
  102433. + }
  102434. +#ifdef DEBUG_EP0
  102435. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  102436. + ctrl.bmRequestType, ctrl.bRequest,
  102437. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  102438. + UGETW(ctrl.wLength));
  102439. +#endif
  102440. +
  102441. + /* Clean up the request queue */
  102442. + dwc_otg_request_nuke(ep0);
  102443. + ep0->stopped = 0;
  102444. +
  102445. + if (ctrl.bmRequestType & UE_DIR_IN) {
  102446. + ep0->dwc_ep.is_in = 1;
  102447. + pcd->ep0state = EP0_IN_DATA_PHASE;
  102448. + } else {
  102449. + ep0->dwc_ep.is_in = 0;
  102450. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  102451. + }
  102452. +
  102453. + if (UGETW(ctrl.wLength) == 0) {
  102454. + ep0->dwc_ep.is_in = 1;
  102455. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  102456. + }
  102457. +
  102458. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  102459. +
  102460. +#ifdef DWC_UTE_CFI
  102461. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  102462. +
  102463. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  102464. + ctrl.bRequestType, ctrl.bRequest);
  102465. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  102466. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  102467. + retval = cfi_setup(pcd, &cfi_req);
  102468. + if (retval < 0) {
  102469. + ep0_do_stall(pcd, retval);
  102470. + pcd->ep0_pending = 0;
  102471. + return;
  102472. + }
  102473. +
  102474. + /* if need gadget setup then call it and check the retval */
  102475. + if (pcd->cfi->need_gadget_att) {
  102476. + retval =
  102477. + cfi_gadget_setup(pcd,
  102478. + &pcd->
  102479. + cfi->ctrl_req);
  102480. + if (retval < 0) {
  102481. + pcd->ep0_pending = 0;
  102482. + return;
  102483. + }
  102484. + }
  102485. +
  102486. + if (pcd->cfi->need_status_in_complete) {
  102487. + do_setup_in_status_phase(pcd);
  102488. + }
  102489. + return;
  102490. + }
  102491. + }
  102492. +#endif
  102493. +
  102494. + /* handle non-standard (class/vendor) requests in the gadget driver */
  102495. + do_gadget_setup(pcd, &ctrl);
  102496. + return;
  102497. + }
  102498. +
  102499. + /** @todo NGS: Handle bad setup packet? */
  102500. +
  102501. +///////////////////////////////////////////
  102502. +//// --- Standard Request handling --- ////
  102503. +
  102504. + switch (ctrl.bRequest) {
  102505. + case UR_GET_STATUS:
  102506. + do_get_status(pcd);
  102507. + break;
  102508. +
  102509. + case UR_CLEAR_FEATURE:
  102510. + do_clear_feature(pcd);
  102511. + break;
  102512. +
  102513. + case UR_SET_FEATURE:
  102514. + do_set_feature(pcd);
  102515. + break;
  102516. +
  102517. + case UR_SET_ADDRESS:
  102518. + do_set_address(pcd);
  102519. + break;
  102520. +
  102521. + case UR_SET_INTERFACE:
  102522. + case UR_SET_CONFIG:
  102523. +// _pcd->request_config = 1; /* Configuration changed */
  102524. + do_gadget_setup(pcd, &ctrl);
  102525. + break;
  102526. +
  102527. + case UR_SYNCH_FRAME:
  102528. + do_gadget_setup(pcd, &ctrl);
  102529. + break;
  102530. +
  102531. + default:
  102532. + /* Call the Gadget Driver's setup functions */
  102533. + do_gadget_setup(pcd, &ctrl);
  102534. + break;
  102535. + }
  102536. +}
  102537. +
  102538. +/**
  102539. + * This function completes the ep0 control transfer.
  102540. + */
  102541. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  102542. +{
  102543. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  102544. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  102545. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  102546. + dev_if->in_ep_regs[ep->dwc_ep.num];
  102547. +#ifdef DEBUG_EP0
  102548. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  102549. + dev_if->out_ep_regs[ep->dwc_ep.num];
  102550. +#endif
  102551. + deptsiz0_data_t deptsiz;
  102552. + dev_dma_desc_sts_t desc_sts;
  102553. + dwc_otg_pcd_request_t *req;
  102554. + int is_last = 0;
  102555. + dwc_otg_pcd_t *pcd = ep->pcd;
  102556. +
  102557. +#ifdef DWC_UTE_CFI
  102558. + struct cfi_usb_ctrlrequest *ctrlreq;
  102559. + int retval = -DWC_E_NOT_SUPPORTED;
  102560. +#endif
  102561. +
  102562. + desc_sts.b.bytes = 0;
  102563. +
  102564. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102565. + if (ep->dwc_ep.is_in) {
  102566. +#ifdef DEBUG_EP0
  102567. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  102568. +#endif
  102569. + do_setup_out_status_phase(pcd);
  102570. + } else {
  102571. +#ifdef DEBUG_EP0
  102572. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  102573. +#endif
  102574. +
  102575. +#ifdef DWC_UTE_CFI
  102576. + ctrlreq = &pcd->cfi->ctrl_req;
  102577. +
  102578. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  102579. + if (ctrlreq->bRequest > 0xB0
  102580. + && ctrlreq->bRequest < 0xBF) {
  102581. +
  102582. + /* Return if the PCD failed to handle the request */
  102583. + if ((retval =
  102584. + pcd->cfi->ops.
  102585. + ctrl_write_complete(pcd->cfi,
  102586. + pcd)) < 0) {
  102587. + CFI_INFO
  102588. + ("ERROR setting a new value in the PCD(%d)\n",
  102589. + retval);
  102590. + ep0_do_stall(pcd, retval);
  102591. + pcd->ep0_pending = 0;
  102592. + return 0;
  102593. + }
  102594. +
  102595. + /* If the gadget needs to be notified on the request */
  102596. + if (pcd->cfi->need_gadget_att == 1) {
  102597. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  102598. + retval =
  102599. + cfi_gadget_setup(pcd,
  102600. + &pcd->cfi->
  102601. + ctrl_req);
  102602. +
  102603. + /* Return from the function if the gadget failed to process
  102604. + * the request properly - this should never happen !!!
  102605. + */
  102606. + if (retval < 0) {
  102607. + CFI_INFO
  102608. + ("ERROR setting a new value in the gadget(%d)\n",
  102609. + retval);
  102610. + pcd->ep0_pending = 0;
  102611. + return 0;
  102612. + }
  102613. + }
  102614. +
  102615. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  102616. + retval);
  102617. + /* If we hit here then the PCD and the gadget has properly
  102618. + * handled the request - so send the ZLP IN to the host.
  102619. + */
  102620. + /* @todo: MAS - decide whether we need to start the setup
  102621. + * stage based on the need_setup value of the cfi object
  102622. + */
  102623. + do_setup_in_status_phase(pcd);
  102624. + pcd->ep0_pending = 0;
  102625. + return 1;
  102626. + }
  102627. + }
  102628. +#endif
  102629. +
  102630. + do_setup_in_status_phase(pcd);
  102631. + }
  102632. + pcd->ep0_pending = 0;
  102633. + return 1;
  102634. + }
  102635. +
  102636. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102637. + return 0;
  102638. + }
  102639. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  102640. +
  102641. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  102642. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  102643. + is_last = 1;
  102644. + } else if (ep->dwc_ep.is_in) {
  102645. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  102646. + if (core_if->dma_desc_enable != 0)
  102647. + desc_sts = dev_if->in_desc_addr->status;
  102648. +#ifdef DEBUG_EP0
  102649. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  102650. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  102651. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102652. +#endif
  102653. +
  102654. + if (((core_if->dma_desc_enable == 0)
  102655. + && (deptsiz.b.xfersize == 0))
  102656. + || ((core_if->dma_desc_enable != 0)
  102657. + && (desc_sts.b.bytes == 0))) {
  102658. + req->actual = ep->dwc_ep.xfer_count;
  102659. + /* Is a Zero Len Packet needed? */
  102660. + if (req->sent_zlp) {
  102661. +#ifdef DEBUG_EP0
  102662. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  102663. +#endif
  102664. + req->sent_zlp = 0;
  102665. + }
  102666. + do_setup_out_status_phase(pcd);
  102667. + }
  102668. + } else {
  102669. + /* ep0-OUT */
  102670. +#ifdef DEBUG_EP0
  102671. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  102672. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  102673. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  102674. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102675. +#endif
  102676. + req->actual = ep->dwc_ep.xfer_count;
  102677. +
  102678. + /* Is a Zero Len Packet needed? */
  102679. + if (req->sent_zlp) {
  102680. +#ifdef DEBUG_EP0
  102681. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  102682. +#endif
  102683. + req->sent_zlp = 0;
  102684. + }
  102685. + /* For older cores do setup in status phase in Slave/BDMA modes,
  102686. + * starting from 3.00 do that only in slave, and for DMA modes
  102687. + * just re-enable ep 0 OUT here*/
  102688. + if (core_if->dma_enable == 0
  102689. + || (core_if->dma_desc_enable == 0
  102690. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  102691. + do_setup_in_status_phase(pcd);
  102692. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  102693. + DWC_DEBUGPL(DBG_PCDV,
  102694. + "Enable out ep before in status phase\n");
  102695. + ep0_out_start(core_if, pcd);
  102696. + }
  102697. + }
  102698. +
  102699. + /* Complete the request */
  102700. + if (is_last) {
  102701. + dwc_otg_request_done(ep, req, 0);
  102702. + ep->dwc_ep.start_xfer_buff = 0;
  102703. + ep->dwc_ep.xfer_buff = 0;
  102704. + ep->dwc_ep.xfer_len = 0;
  102705. + return 1;
  102706. + }
  102707. + return 0;
  102708. +}
  102709. +
  102710. +#ifdef DWC_UTE_CFI
  102711. +/**
  102712. + * This function calculates traverses all the CFI DMA descriptors and
  102713. + * and accumulates the bytes that are left to be transfered.
  102714. + *
  102715. + * @return The total bytes left to transfered, or a negative value as failure
  102716. + */
  102717. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  102718. +{
  102719. + int32_t ret = 0;
  102720. + int i;
  102721. + struct dwc_otg_dma_desc *ddesc = NULL;
  102722. + struct cfi_ep *cfiep;
  102723. +
  102724. + /* See if the pcd_ep has its respective cfi_ep mapped */
  102725. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  102726. + if (!cfiep) {
  102727. + CFI_INFO("%s: Failed to find ep\n", __func__);
  102728. + return -1;
  102729. + }
  102730. +
  102731. + ddesc = ep->dwc_ep.descs;
  102732. +
  102733. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  102734. +
  102735. +#if defined(PRINT_CFI_DMA_DESCS)
  102736. + print_desc(ddesc, ep->ep.name, i);
  102737. +#endif
  102738. + ret += ddesc->status.b.bytes;
  102739. + ddesc++;
  102740. + }
  102741. +
  102742. + if (ret)
  102743. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  102744. + ret);
  102745. +
  102746. + return ret;
  102747. +}
  102748. +#endif
  102749. +
  102750. +/**
  102751. + * This function completes the request for the EP. If there are
  102752. + * additional requests for the EP in the queue they will be started.
  102753. + */
  102754. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  102755. +{
  102756. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  102757. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  102758. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  102759. + dev_if->in_ep_regs[ep->dwc_ep.num];
  102760. + deptsiz_data_t deptsiz;
  102761. + dev_dma_desc_sts_t desc_sts;
  102762. + dwc_otg_pcd_request_t *req = 0;
  102763. + dwc_otg_dev_dma_desc_t *dma_desc;
  102764. + uint32_t byte_count = 0;
  102765. + int is_last = 0;
  102766. + int i;
  102767. +
  102768. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  102769. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  102770. +
  102771. + /* Get any pending requests */
  102772. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  102773. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  102774. + if (!req) {
  102775. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  102776. + return;
  102777. + }
  102778. + } else {
  102779. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  102780. + return;
  102781. + }
  102782. +
  102783. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  102784. +
  102785. + if (ep->dwc_ep.is_in) {
  102786. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  102787. +
  102788. + if (core_if->dma_enable) {
  102789. + if (core_if->dma_desc_enable == 0) {
  102790. + if (deptsiz.b.xfersize == 0
  102791. + && deptsiz.b.pktcnt == 0) {
  102792. + byte_count =
  102793. + ep->dwc_ep.xfer_len -
  102794. + ep->dwc_ep.xfer_count;
  102795. +
  102796. + ep->dwc_ep.xfer_buff += byte_count;
  102797. + ep->dwc_ep.dma_addr += byte_count;
  102798. + ep->dwc_ep.xfer_count += byte_count;
  102799. +
  102800. + DWC_DEBUGPL(DBG_PCDV,
  102801. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  102802. + ep->dwc_ep.num,
  102803. + (ep->dwc_ep.
  102804. + is_in ? "IN" : "OUT"),
  102805. + ep->dwc_ep.xfer_len,
  102806. + deptsiz.b.xfersize,
  102807. + deptsiz.b.pktcnt);
  102808. +
  102809. + if (ep->dwc_ep.xfer_len <
  102810. + ep->dwc_ep.total_len) {
  102811. + dwc_otg_ep_start_transfer
  102812. + (core_if, &ep->dwc_ep);
  102813. + } else if (ep->dwc_ep.sent_zlp) {
  102814. + /*
  102815. + * This fragment of code should initiate 0
  102816. + * length transfer in case if it is queued
  102817. + * a transfer with size divisible to EPs max
  102818. + * packet size and with usb_request zero field
  102819. + * is set, which means that after data is transfered,
  102820. + * it is also should be transfered
  102821. + * a 0 length packet at the end. For Slave and
  102822. + * Buffer DMA modes in this case SW has
  102823. + * to initiate 2 transfers one with transfer size,
  102824. + * and the second with 0 size. For Descriptor
  102825. + * DMA mode SW is able to initiate a transfer,
  102826. + * which will handle all the packets including
  102827. + * the last 0 length.
  102828. + */
  102829. + ep->dwc_ep.sent_zlp = 0;
  102830. + dwc_otg_ep_start_zl_transfer
  102831. + (core_if, &ep->dwc_ep);
  102832. + } else {
  102833. + is_last = 1;
  102834. + }
  102835. + } else {
  102836. + if (ep->dwc_ep.type ==
  102837. + DWC_OTG_EP_TYPE_ISOC) {
  102838. + req->actual = 0;
  102839. + dwc_otg_request_done(ep, req, 0);
  102840. +
  102841. + ep->dwc_ep.start_xfer_buff = 0;
  102842. + ep->dwc_ep.xfer_buff = 0;
  102843. + ep->dwc_ep.xfer_len = 0;
  102844. +
  102845. + /* If there is a request in the queue start it. */
  102846. + start_next_request(ep);
  102847. + } else
  102848. + DWC_WARN
  102849. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  102850. + ep->dwc_ep.num,
  102851. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  102852. + deptsiz.b.xfersize,
  102853. + deptsiz.b.pktcnt);
  102854. + }
  102855. + } else {
  102856. + dma_desc = ep->dwc_ep.desc_addr;
  102857. + byte_count = 0;
  102858. + ep->dwc_ep.sent_zlp = 0;
  102859. +
  102860. +#ifdef DWC_UTE_CFI
  102861. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  102862. + ep->dwc_ep.buff_mode);
  102863. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  102864. + int residue;
  102865. +
  102866. + residue = cfi_calc_desc_residue(ep);
  102867. + if (residue < 0)
  102868. + return;
  102869. +
  102870. + byte_count = residue;
  102871. + } else {
  102872. +#endif
  102873. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  102874. + ++i) {
  102875. + desc_sts = dma_desc->status;
  102876. + byte_count += desc_sts.b.bytes;
  102877. + dma_desc++;
  102878. + }
  102879. +#ifdef DWC_UTE_CFI
  102880. + }
  102881. +#endif
  102882. + if (byte_count == 0) {
  102883. + ep->dwc_ep.xfer_count =
  102884. + ep->dwc_ep.total_len;
  102885. + is_last = 1;
  102886. + } else {
  102887. + DWC_WARN("Incomplete transfer\n");
  102888. + }
  102889. + }
  102890. + } else {
  102891. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  102892. + DWC_DEBUGPL(DBG_PCDV,
  102893. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  102894. + ep->dwc_ep.num,
  102895. + ep->dwc_ep.is_in ? "IN" : "OUT",
  102896. + ep->dwc_ep.xfer_len,
  102897. + deptsiz.b.xfersize,
  102898. + deptsiz.b.pktcnt);
  102899. +
  102900. + /* Check if the whole transfer was completed,
  102901. + * if no, setup transfer for next portion of data
  102902. + */
  102903. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  102904. + dwc_otg_ep_start_transfer(core_if,
  102905. + &ep->dwc_ep);
  102906. + } else if (ep->dwc_ep.sent_zlp) {
  102907. + /*
  102908. + * This fragment of code should initiate 0
  102909. + * length trasfer in case if it is queued
  102910. + * a trasfer with size divisible to EPs max
  102911. + * packet size and with usb_request zero field
  102912. + * is set, which means that after data is transfered,
  102913. + * it is also should be transfered
  102914. + * a 0 length packet at the end. For Slave and
  102915. + * Buffer DMA modes in this case SW has
  102916. + * to initiate 2 transfers one with transfer size,
  102917. + * and the second with 0 size. For Desriptor
  102918. + * DMA mode SW is able to initiate a transfer,
  102919. + * which will handle all the packets including
  102920. + * the last 0 legth.
  102921. + */
  102922. + ep->dwc_ep.sent_zlp = 0;
  102923. + dwc_otg_ep_start_zl_transfer(core_if,
  102924. + &ep->dwc_ep);
  102925. + } else {
  102926. + is_last = 1;
  102927. + }
  102928. + } else {
  102929. + DWC_WARN
  102930. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  102931. + ep->dwc_ep.num,
  102932. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  102933. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  102934. + }
  102935. + }
  102936. + } else {
  102937. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  102938. + dev_if->out_ep_regs[ep->dwc_ep.num];
  102939. + desc_sts.d32 = 0;
  102940. + if (core_if->dma_enable) {
  102941. + if (core_if->dma_desc_enable) {
  102942. + dma_desc = ep->dwc_ep.desc_addr;
  102943. + byte_count = 0;
  102944. + ep->dwc_ep.sent_zlp = 0;
  102945. +
  102946. +#ifdef DWC_UTE_CFI
  102947. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  102948. + ep->dwc_ep.buff_mode);
  102949. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  102950. + int residue;
  102951. + residue = cfi_calc_desc_residue(ep);
  102952. + if (residue < 0)
  102953. + return;
  102954. + byte_count = residue;
  102955. + } else {
  102956. +#endif
  102957. +
  102958. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  102959. + ++i) {
  102960. + desc_sts = dma_desc->status;
  102961. + byte_count += desc_sts.b.bytes;
  102962. + dma_desc++;
  102963. + }
  102964. +
  102965. +#ifdef DWC_UTE_CFI
  102966. + }
  102967. +#endif
  102968. + /* Checking for interrupt Out transfers with not
  102969. + * dword aligned mps sizes
  102970. + */
  102971. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  102972. + (ep->dwc_ep.maxpacket%4)) {
  102973. + ep->dwc_ep.xfer_count =
  102974. + ep->dwc_ep.total_len - byte_count;
  102975. + if ((ep->dwc_ep.xfer_len %
  102976. + ep->dwc_ep.maxpacket)
  102977. + && (ep->dwc_ep.xfer_len /
  102978. + ep->dwc_ep.maxpacket <
  102979. + MAX_DMA_DESC_CNT))
  102980. + ep->dwc_ep.xfer_len -=
  102981. + (ep->dwc_ep.desc_cnt -
  102982. + 1) * ep->dwc_ep.maxpacket +
  102983. + ep->dwc_ep.xfer_len %
  102984. + ep->dwc_ep.maxpacket;
  102985. + else
  102986. + ep->dwc_ep.xfer_len -=
  102987. + ep->dwc_ep.desc_cnt *
  102988. + ep->dwc_ep.maxpacket;
  102989. + if (ep->dwc_ep.xfer_len > 0) {
  102990. + dwc_otg_ep_start_transfer
  102991. + (core_if, &ep->dwc_ep);
  102992. + } else {
  102993. + is_last = 1;
  102994. + }
  102995. + } else {
  102996. + ep->dwc_ep.xfer_count =
  102997. + ep->dwc_ep.total_len - byte_count +
  102998. + ((4 -
  102999. + (ep->dwc_ep.
  103000. + total_len & 0x3)) & 0x3);
  103001. + is_last = 1;
  103002. + }
  103003. + } else {
  103004. + deptsiz.d32 = 0;
  103005. + deptsiz.d32 =
  103006. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  103007. +
  103008. + byte_count = (ep->dwc_ep.xfer_len -
  103009. + ep->dwc_ep.xfer_count -
  103010. + deptsiz.b.xfersize);
  103011. + ep->dwc_ep.xfer_buff += byte_count;
  103012. + ep->dwc_ep.dma_addr += byte_count;
  103013. + ep->dwc_ep.xfer_count += byte_count;
  103014. +
  103015. + /* Check if the whole transfer was completed,
  103016. + * if no, setup transfer for next portion of data
  103017. + */
  103018. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  103019. + dwc_otg_ep_start_transfer(core_if,
  103020. + &ep->dwc_ep);
  103021. + } else if (ep->dwc_ep.sent_zlp) {
  103022. + /*
  103023. + * This fragment of code should initiate 0
  103024. + * length trasfer in case if it is queued
  103025. + * a trasfer with size divisible to EPs max
  103026. + * packet size and with usb_request zero field
  103027. + * is set, which means that after data is transfered,
  103028. + * it is also should be transfered
  103029. + * a 0 length packet at the end. For Slave and
  103030. + * Buffer DMA modes in this case SW has
  103031. + * to initiate 2 transfers one with transfer size,
  103032. + * and the second with 0 size. For Desriptor
  103033. + * DMA mode SW is able to initiate a transfer,
  103034. + * which will handle all the packets including
  103035. + * the last 0 legth.
  103036. + */
  103037. + ep->dwc_ep.sent_zlp = 0;
  103038. + dwc_otg_ep_start_zl_transfer(core_if,
  103039. + &ep->dwc_ep);
  103040. + } else {
  103041. + is_last = 1;
  103042. + }
  103043. + }
  103044. + } else {
  103045. + /* Check if the whole transfer was completed,
  103046. + * if no, setup transfer for next portion of data
  103047. + */
  103048. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  103049. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  103050. + } else if (ep->dwc_ep.sent_zlp) {
  103051. + /*
  103052. + * This fragment of code should initiate 0
  103053. + * length transfer in case if it is queued
  103054. + * a transfer with size divisible to EPs max
  103055. + * packet size and with usb_request zero field
  103056. + * is set, which means that after data is transfered,
  103057. + * it is also should be transfered
  103058. + * a 0 length packet at the end. For Slave and
  103059. + * Buffer DMA modes in this case SW has
  103060. + * to initiate 2 transfers one with transfer size,
  103061. + * and the second with 0 size. For Descriptor
  103062. + * DMA mode SW is able to initiate a transfer,
  103063. + * which will handle all the packets including
  103064. + * the last 0 length.
  103065. + */
  103066. + ep->dwc_ep.sent_zlp = 0;
  103067. + dwc_otg_ep_start_zl_transfer(core_if,
  103068. + &ep->dwc_ep);
  103069. + } else {
  103070. + is_last = 1;
  103071. + }
  103072. + }
  103073. +
  103074. + DWC_DEBUGPL(DBG_PCDV,
  103075. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  103076. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  103077. + ep->dwc_ep.is_in ? "IN" : "OUT",
  103078. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  103079. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  103080. + }
  103081. +
  103082. + /* Complete the request */
  103083. + if (is_last) {
  103084. +#ifdef DWC_UTE_CFI
  103085. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  103086. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  103087. + } else {
  103088. +#endif
  103089. + req->actual = ep->dwc_ep.xfer_count;
  103090. +#ifdef DWC_UTE_CFI
  103091. + }
  103092. +#endif
  103093. + if (req->dw_align_buf) {
  103094. + if (!ep->dwc_ep.is_in) {
  103095. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  103096. + }
  103097. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  103098. + req->dw_align_buf_dma);
  103099. + }
  103100. +
  103101. + dwc_otg_request_done(ep, req, 0);
  103102. +
  103103. + ep->dwc_ep.start_xfer_buff = 0;
  103104. + ep->dwc_ep.xfer_buff = 0;
  103105. + ep->dwc_ep.xfer_len = 0;
  103106. +
  103107. + /* If there is a request in the queue start it. */
  103108. + start_next_request(ep);
  103109. + }
  103110. +}
  103111. +
  103112. +#ifdef DWC_EN_ISOC
  103113. +
  103114. +/**
  103115. + * This function BNA interrupt for Isochronous EPs
  103116. + *
  103117. + */
  103118. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  103119. +{
  103120. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  103121. + volatile uint32_t *addr;
  103122. + depctl_data_t depctl = {.d32 = 0 };
  103123. + dwc_otg_pcd_t *pcd = ep->pcd;
  103124. + dwc_otg_dev_dma_desc_t *dma_desc;
  103125. + int i;
  103126. +
  103127. + dma_desc =
  103128. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  103129. +
  103130. + if (dwc_ep->is_in) {
  103131. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103132. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  103133. + sts.d32 = dma_desc->status.d32;
  103134. + sts.b_iso_in.bs = BS_HOST_READY;
  103135. + dma_desc->status.d32 = sts.d32;
  103136. + }
  103137. + } else {
  103138. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103139. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  103140. + sts.d32 = dma_desc->status.d32;
  103141. + sts.b_iso_out.bs = BS_HOST_READY;
  103142. + dma_desc->status.d32 = sts.d32;
  103143. + }
  103144. + }
  103145. +
  103146. + if (dwc_ep->is_in == 0) {
  103147. + addr =
  103148. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  103149. + num]->doepctl;
  103150. + } else {
  103151. + addr =
  103152. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  103153. + }
  103154. + depctl.b.epena = 1;
  103155. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  103156. +}
  103157. +
  103158. +/**
  103159. + * This function sets latest iso packet information(non-PTI mode)
  103160. + *
  103161. + * @param core_if Programming view of DWC_otg controller.
  103162. + * @param ep The EP to start the transfer on.
  103163. + *
  103164. + */
  103165. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  103166. +{
  103167. + deptsiz_data_t deptsiz = {.d32 = 0 };
  103168. + dma_addr_t dma_addr;
  103169. + uint32_t offset;
  103170. +
  103171. + if (ep->proc_buf_num)
  103172. + dma_addr = ep->dma_addr1;
  103173. + else
  103174. + dma_addr = ep->dma_addr0;
  103175. +
  103176. + if (ep->is_in) {
  103177. + deptsiz.d32 =
  103178. + DWC_READ_REG32(&core_if->dev_if->
  103179. + in_ep_regs[ep->num]->dieptsiz);
  103180. + offset = ep->data_per_frame;
  103181. + } else {
  103182. + deptsiz.d32 =
  103183. + DWC_READ_REG32(&core_if->dev_if->
  103184. + out_ep_regs[ep->num]->doeptsiz);
  103185. + offset =
  103186. + ep->data_per_frame +
  103187. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  103188. + }
  103189. +
  103190. + if (!deptsiz.b.xfersize) {
  103191. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  103192. + ep->pkt_info[ep->cur_pkt].offset =
  103193. + ep->cur_pkt_dma_addr - dma_addr;
  103194. + ep->pkt_info[ep->cur_pkt].status = 0;
  103195. + } else {
  103196. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  103197. + ep->pkt_info[ep->cur_pkt].offset =
  103198. + ep->cur_pkt_dma_addr - dma_addr;
  103199. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  103200. + }
  103201. + ep->cur_pkt_addr += offset;
  103202. + ep->cur_pkt_dma_addr += offset;
  103203. + ep->cur_pkt++;
  103204. +}
  103205. +
  103206. +/**
  103207. + * This function sets latest iso packet information(DDMA mode)
  103208. + *
  103209. + * @param core_if Programming view of DWC_otg controller.
  103210. + * @param dwc_ep The EP to start the transfer on.
  103211. + *
  103212. + */
  103213. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  103214. + dwc_ep_t * dwc_ep)
  103215. +{
  103216. + dwc_otg_dev_dma_desc_t *dma_desc;
  103217. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103218. + iso_pkt_info_t *iso_packet;
  103219. + uint32_t data_per_desc;
  103220. + uint32_t offset;
  103221. + int i, j;
  103222. +
  103223. + iso_packet = dwc_ep->pkt_info;
  103224. +
  103225. + /** Reinit closed DMA Descriptors*/
  103226. + /** ISO OUT EP */
  103227. + if (dwc_ep->is_in == 0) {
  103228. + dma_desc =
  103229. + dwc_ep->iso_desc_addr +
  103230. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  103231. + offset = 0;
  103232. +
  103233. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  103234. + i += dwc_ep->pkt_per_frm) {
  103235. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  103236. + data_per_desc =
  103237. + ((j + 1) * dwc_ep->maxpacket >
  103238. + dwc_ep->
  103239. + data_per_frame) ? dwc_ep->data_per_frame -
  103240. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103241. + data_per_desc +=
  103242. + (data_per_desc % 4) ? (4 -
  103243. + data_per_desc %
  103244. + 4) : 0;
  103245. +
  103246. + sts.d32 = dma_desc->status.d32;
  103247. +
  103248. + /* Write status in iso_packet_decsriptor */
  103249. + iso_packet->status =
  103250. + sts.b_iso_out.rxsts +
  103251. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  103252. + if (iso_packet->status) {
  103253. + iso_packet->status = -DWC_E_NO_DATA;
  103254. + }
  103255. +
  103256. + /* Received data length */
  103257. + if (!sts.b_iso_out.rxbytes) {
  103258. + iso_packet->length =
  103259. + data_per_desc -
  103260. + sts.b_iso_out.rxbytes;
  103261. + } else {
  103262. + iso_packet->length =
  103263. + data_per_desc -
  103264. + sts.b_iso_out.rxbytes + (4 -
  103265. + dwc_ep->data_per_frame
  103266. + % 4);
  103267. + }
  103268. +
  103269. + iso_packet->offset = offset;
  103270. +
  103271. + offset += data_per_desc;
  103272. + dma_desc++;
  103273. + iso_packet++;
  103274. + }
  103275. + }
  103276. +
  103277. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  103278. + data_per_desc =
  103279. + ((j + 1) * dwc_ep->maxpacket >
  103280. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  103281. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103282. + data_per_desc +=
  103283. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  103284. +
  103285. + sts.d32 = dma_desc->status.d32;
  103286. +
  103287. + /* Write status in iso_packet_decsriptor */
  103288. + iso_packet->status =
  103289. + sts.b_iso_out.rxsts +
  103290. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  103291. + if (iso_packet->status) {
  103292. + iso_packet->status = -DWC_E_NO_DATA;
  103293. + }
  103294. +
  103295. + /* Received data length */
  103296. + iso_packet->length =
  103297. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  103298. +
  103299. + iso_packet->offset = offset;
  103300. +
  103301. + offset += data_per_desc;
  103302. + iso_packet++;
  103303. + dma_desc++;
  103304. + }
  103305. +
  103306. + sts.d32 = dma_desc->status.d32;
  103307. +
  103308. + /* Write status in iso_packet_decsriptor */
  103309. + iso_packet->status =
  103310. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  103311. + if (iso_packet->status) {
  103312. + iso_packet->status = -DWC_E_NO_DATA;
  103313. + }
  103314. + /* Received data length */
  103315. + if (!sts.b_iso_out.rxbytes) {
  103316. + iso_packet->length =
  103317. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  103318. + } else {
  103319. + iso_packet->length =
  103320. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  103321. + (4 - dwc_ep->data_per_frame % 4);
  103322. + }
  103323. +
  103324. + iso_packet->offset = offset;
  103325. + } else {
  103326. +/** ISO IN EP */
  103327. +
  103328. + dma_desc =
  103329. + dwc_ep->iso_desc_addr +
  103330. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  103331. +
  103332. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  103333. + sts.d32 = dma_desc->status.d32;
  103334. +
  103335. + /* Write status in iso packet descriptor */
  103336. + iso_packet->status =
  103337. + sts.b_iso_in.txsts +
  103338. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  103339. + if (iso_packet->status != 0) {
  103340. + iso_packet->status = -DWC_E_NO_DATA;
  103341. +
  103342. + }
  103343. + /* Bytes has been transfered */
  103344. + iso_packet->length =
  103345. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  103346. +
  103347. + dma_desc++;
  103348. + iso_packet++;
  103349. + }
  103350. +
  103351. + sts.d32 = dma_desc->status.d32;
  103352. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  103353. + sts.d32 = dma_desc->status.d32;
  103354. + }
  103355. +
  103356. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  103357. + iso_packet->status =
  103358. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  103359. + if (iso_packet->status != 0) {
  103360. + iso_packet->status = -DWC_E_NO_DATA;
  103361. + }
  103362. +
  103363. + /* Bytes has been transfered */
  103364. + iso_packet->length =
  103365. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  103366. + }
  103367. +}
  103368. +
  103369. +/**
  103370. + * This function reinitialize DMA Descriptors for Isochronous transfer
  103371. + *
  103372. + * @param core_if Programming view of DWC_otg controller.
  103373. + * @param dwc_ep The EP to start the transfer on.
  103374. + *
  103375. + */
  103376. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  103377. +{
  103378. + int i, j;
  103379. + dwc_otg_dev_dma_desc_t *dma_desc;
  103380. + dma_addr_t dma_ad;
  103381. + volatile uint32_t *addr;
  103382. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103383. + uint32_t data_per_desc;
  103384. +
  103385. + if (dwc_ep->is_in == 0) {
  103386. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  103387. + } else {
  103388. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  103389. + }
  103390. +
  103391. + if (dwc_ep->proc_buf_num == 0) {
  103392. + /** Buffer 0 descriptors setup */
  103393. + dma_ad = dwc_ep->dma_addr0;
  103394. + } else {
  103395. + /** Buffer 1 descriptors setup */
  103396. + dma_ad = dwc_ep->dma_addr1;
  103397. + }
  103398. +
  103399. + /** Reinit closed DMA Descriptors*/
  103400. + /** ISO OUT EP */
  103401. + if (dwc_ep->is_in == 0) {
  103402. + dma_desc =
  103403. + dwc_ep->iso_desc_addr +
  103404. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  103405. +
  103406. + sts.b_iso_out.bs = BS_HOST_READY;
  103407. + sts.b_iso_out.rxsts = 0;
  103408. + sts.b_iso_out.l = 0;
  103409. + sts.b_iso_out.sp = 0;
  103410. + sts.b_iso_out.ioc = 0;
  103411. + sts.b_iso_out.pid = 0;
  103412. + sts.b_iso_out.framenum = 0;
  103413. +
  103414. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  103415. + i += dwc_ep->pkt_per_frm) {
  103416. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  103417. + data_per_desc =
  103418. + ((j + 1) * dwc_ep->maxpacket >
  103419. + dwc_ep->
  103420. + data_per_frame) ? dwc_ep->data_per_frame -
  103421. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103422. + data_per_desc +=
  103423. + (data_per_desc % 4) ? (4 -
  103424. + data_per_desc %
  103425. + 4) : 0;
  103426. + sts.b_iso_out.rxbytes = data_per_desc;
  103427. + dma_desc->buf = dma_ad;
  103428. + dma_desc->status.d32 = sts.d32;
  103429. +
  103430. + dma_ad += data_per_desc;
  103431. + dma_desc++;
  103432. + }
  103433. + }
  103434. +
  103435. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  103436. +
  103437. + data_per_desc =
  103438. + ((j + 1) * dwc_ep->maxpacket >
  103439. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  103440. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103441. + data_per_desc +=
  103442. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  103443. + sts.b_iso_out.rxbytes = data_per_desc;
  103444. +
  103445. + dma_desc->buf = dma_ad;
  103446. + dma_desc->status.d32 = sts.d32;
  103447. +
  103448. + dma_desc++;
  103449. + dma_ad += data_per_desc;
  103450. + }
  103451. +
  103452. + sts.b_iso_out.ioc = 1;
  103453. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  103454. +
  103455. + data_per_desc =
  103456. + ((j + 1) * dwc_ep->maxpacket >
  103457. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  103458. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  103459. + data_per_desc +=
  103460. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  103461. + sts.b_iso_out.rxbytes = data_per_desc;
  103462. +
  103463. + dma_desc->buf = dma_ad;
  103464. + dma_desc->status.d32 = sts.d32;
  103465. + } else {
  103466. +/** ISO IN EP */
  103467. +
  103468. + dma_desc =
  103469. + dwc_ep->iso_desc_addr +
  103470. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  103471. +
  103472. + sts.b_iso_in.bs = BS_HOST_READY;
  103473. + sts.b_iso_in.txsts = 0;
  103474. + sts.b_iso_in.sp = 0;
  103475. + sts.b_iso_in.ioc = 0;
  103476. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  103477. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  103478. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  103479. + sts.b_iso_in.l = 0;
  103480. +
  103481. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  103482. + dma_desc->buf = dma_ad;
  103483. + dma_desc->status.d32 = sts.d32;
  103484. +
  103485. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  103486. + dma_ad += dwc_ep->data_per_frame;
  103487. + dma_desc++;
  103488. + }
  103489. +
  103490. + sts.b_iso_in.ioc = 1;
  103491. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  103492. +
  103493. + dma_desc->buf = dma_ad;
  103494. + dma_desc->status.d32 = sts.d32;
  103495. +
  103496. + dwc_ep->next_frame =
  103497. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  103498. + }
  103499. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103500. +}
  103501. +
  103502. +/**
  103503. + * This function is to handle Iso EP transfer complete interrupt
  103504. + * in case Iso out packet was dropped
  103505. + *
  103506. + * @param core_if Programming view of DWC_otg controller.
  103507. + * @param dwc_ep The EP for wihich transfer complete was asserted
  103508. + *
  103509. + */
  103510. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  103511. + dwc_ep_t * dwc_ep)
  103512. +{
  103513. + uint32_t dma_addr;
  103514. + uint32_t drp_pkt;
  103515. + uint32_t drp_pkt_cnt;
  103516. + deptsiz_data_t deptsiz = {.d32 = 0 };
  103517. + depctl_data_t depctl = {.d32 = 0 };
  103518. + int i;
  103519. +
  103520. + deptsiz.d32 =
  103521. + DWC_READ_REG32(&core_if->dev_if->
  103522. + out_ep_regs[dwc_ep->num]->doeptsiz);
  103523. +
  103524. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  103525. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  103526. +
  103527. + /* Setting dropped packets status */
  103528. + for (i = 0; i < drp_pkt_cnt; ++i) {
  103529. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  103530. + drp_pkt++;
  103531. + deptsiz.b.pktcnt--;
  103532. + }
  103533. +
  103534. + if (deptsiz.b.pktcnt > 0) {
  103535. + deptsiz.b.xfersize =
  103536. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  103537. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  103538. + } else {
  103539. + deptsiz.b.xfersize = 0;
  103540. + deptsiz.b.pktcnt = 0;
  103541. + }
  103542. +
  103543. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  103544. + deptsiz.d32);
  103545. +
  103546. + if (deptsiz.b.pktcnt > 0) {
  103547. + if (dwc_ep->proc_buf_num) {
  103548. + dma_addr =
  103549. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  103550. + deptsiz.b.xfersize;
  103551. + } else {
  103552. + dma_addr =
  103553. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  103554. + deptsiz.b.xfersize;;
  103555. + }
  103556. +
  103557. + DWC_WRITE_REG32(&core_if->dev_if->
  103558. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  103559. +
  103560. + /** Re-enable endpoint, clear nak */
  103561. + depctl.d32 = 0;
  103562. + depctl.b.epena = 1;
  103563. + depctl.b.cnak = 1;
  103564. +
  103565. + DWC_MODIFY_REG32(&core_if->dev_if->
  103566. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  103567. + depctl.d32);
  103568. + return 0;
  103569. + } else {
  103570. + return 1;
  103571. + }
  103572. +}
  103573. +
  103574. +/**
  103575. + * This function sets iso packets information(PTI mode)
  103576. + *
  103577. + * @param core_if Programming view of DWC_otg controller.
  103578. + * @param ep The EP to start the transfer on.
  103579. + *
  103580. + */
  103581. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  103582. +{
  103583. + int i, j;
  103584. + dma_addr_t dma_ad;
  103585. + iso_pkt_info_t *packet_info = ep->pkt_info;
  103586. + uint32_t offset;
  103587. + uint32_t frame_data;
  103588. + deptsiz_data_t deptsiz;
  103589. +
  103590. + if (ep->proc_buf_num == 0) {
  103591. + /** Buffer 0 descriptors setup */
  103592. + dma_ad = ep->dma_addr0;
  103593. + } else {
  103594. + /** Buffer 1 descriptors setup */
  103595. + dma_ad = ep->dma_addr1;
  103596. + }
  103597. +
  103598. + if (ep->is_in) {
  103599. + deptsiz.d32 =
  103600. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  103601. + dieptsiz);
  103602. + } else {
  103603. + deptsiz.d32 =
  103604. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  103605. + doeptsiz);
  103606. + }
  103607. +
  103608. + if (!deptsiz.b.xfersize) {
  103609. + offset = 0;
  103610. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  103611. + frame_data = ep->data_per_frame;
  103612. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  103613. +
  103614. + /* Packet status - is not set as initially
  103615. + * it is set to 0 and if packet was sent
  103616. + successfully, status field will remain 0*/
  103617. +
  103618. + /* Bytes has been transfered */
  103619. + packet_info->length =
  103620. + (ep->maxpacket <
  103621. + frame_data) ? ep->maxpacket : frame_data;
  103622. +
  103623. + /* Received packet offset */
  103624. + packet_info->offset = offset;
  103625. + offset += packet_info->length;
  103626. + frame_data -= packet_info->length;
  103627. +
  103628. + packet_info++;
  103629. + }
  103630. + }
  103631. + return 1;
  103632. + } else {
  103633. + /* This is a workaround for in case of Transfer Complete with
  103634. + * PktDrpSts interrupts merging - in this case Transfer complete
  103635. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  103636. + * set and with DOEPTSIZ register non zero. Investigations showed,
  103637. + * that this happens when Out packet is dropped, but because of
  103638. + * interrupts merging during first interrupt handling PktDrpSts
  103639. + * bit is cleared and for next merged interrupts it is not reset.
  103640. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  103641. + */
  103642. + if (ep->is_in) {
  103643. + return 1;
  103644. + } else {
  103645. + return handle_iso_out_pkt_dropped(core_if, ep);
  103646. + }
  103647. + }
  103648. +}
  103649. +
  103650. +/**
  103651. + * This function is to handle Iso EP transfer complete interrupt
  103652. + *
  103653. + * @param pcd The PCD
  103654. + * @param ep The EP for which transfer complete was asserted
  103655. + *
  103656. + */
  103657. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  103658. +{
  103659. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  103660. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  103661. + uint8_t is_last = 0;
  103662. +
  103663. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  103664. + DWC_WARN("Next frame is not set!\n");
  103665. + return;
  103666. + }
  103667. +
  103668. + if (core_if->dma_enable) {
  103669. + if (core_if->dma_desc_enable) {
  103670. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  103671. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  103672. + is_last = 1;
  103673. + } else {
  103674. + if (core_if->pti_enh_enable) {
  103675. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  103676. + dwc_ep->proc_buf_num =
  103677. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103678. + dwc_otg_iso_ep_start_buf_transfer
  103679. + (core_if, dwc_ep);
  103680. + is_last = 1;
  103681. + }
  103682. + } else {
  103683. + set_current_pkt_info(core_if, dwc_ep);
  103684. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  103685. + is_last = 1;
  103686. + dwc_ep->cur_pkt = 0;
  103687. + dwc_ep->proc_buf_num =
  103688. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103689. + if (dwc_ep->proc_buf_num) {
  103690. + dwc_ep->cur_pkt_addr =
  103691. + dwc_ep->xfer_buff1;
  103692. + dwc_ep->cur_pkt_dma_addr =
  103693. + dwc_ep->dma_addr1;
  103694. + } else {
  103695. + dwc_ep->cur_pkt_addr =
  103696. + dwc_ep->xfer_buff0;
  103697. + dwc_ep->cur_pkt_dma_addr =
  103698. + dwc_ep->dma_addr0;
  103699. + }
  103700. +
  103701. + }
  103702. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  103703. + dwc_ep);
  103704. + }
  103705. + }
  103706. + } else {
  103707. + set_current_pkt_info(core_if, dwc_ep);
  103708. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  103709. + is_last = 1;
  103710. + dwc_ep->cur_pkt = 0;
  103711. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  103712. + if (dwc_ep->proc_buf_num) {
  103713. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  103714. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  103715. + } else {
  103716. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  103717. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  103718. + }
  103719. +
  103720. + }
  103721. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  103722. + }
  103723. + if (is_last)
  103724. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  103725. +}
  103726. +#endif /* DWC_EN_ISOC */
  103727. +
  103728. +/**
  103729. + * This function handle BNA interrupt for Non Isochronous EPs
  103730. + *
  103731. + */
  103732. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  103733. +{
  103734. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  103735. + volatile uint32_t *addr;
  103736. + depctl_data_t depctl = {.d32 = 0 };
  103737. + dwc_otg_pcd_t *pcd = ep->pcd;
  103738. + dwc_otg_dev_dma_desc_t *dma_desc;
  103739. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  103740. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  103741. + int i, start;
  103742. +
  103743. + if (!dwc_ep->desc_cnt)
  103744. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  103745. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  103746. +
  103747. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  103748. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  103749. + uint32_t doepdma;
  103750. + dwc_otg_dev_out_ep_regs_t *out_regs =
  103751. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  103752. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  103753. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  103754. + dma_desc = &(dwc_ep->desc_addr[start]);
  103755. + } else {
  103756. + start = 0;
  103757. + dma_desc = dwc_ep->desc_addr;
  103758. + }
  103759. +
  103760. +
  103761. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  103762. + sts.d32 = dma_desc->status.d32;
  103763. + sts.b.bs = BS_HOST_READY;
  103764. + dma_desc->status.d32 = sts.d32;
  103765. + }
  103766. +
  103767. + if (dwc_ep->is_in == 0) {
  103768. + addr =
  103769. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  103770. + doepctl;
  103771. + } else {
  103772. + addr =
  103773. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  103774. + }
  103775. + depctl.b.epena = 1;
  103776. + depctl.b.cnak = 1;
  103777. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  103778. +}
  103779. +
  103780. +/**
  103781. + * This function handles EP0 Control transfers.
  103782. + *
  103783. + * The state of the control transfers are tracked in
  103784. + * <code>ep0state</code>.
  103785. + */
  103786. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  103787. +{
  103788. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  103789. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  103790. + dev_dma_desc_sts_t desc_sts;
  103791. + deptsiz0_data_t deptsiz;
  103792. + uint32_t byte_count;
  103793. +
  103794. +#ifdef DEBUG_EP0
  103795. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  103796. + print_ep0_state(pcd);
  103797. +#endif
  103798. +
  103799. +// DWC_PRINTF("HANDLE EP0\n");
  103800. +
  103801. + switch (pcd->ep0state) {
  103802. + case EP0_DISCONNECT:
  103803. + break;
  103804. +
  103805. + case EP0_IDLE:
  103806. + pcd->request_config = 0;
  103807. +
  103808. + pcd_setup(pcd);
  103809. + break;
  103810. +
  103811. + case EP0_IN_DATA_PHASE:
  103812. +#ifdef DEBUG_EP0
  103813. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  103814. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  103815. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  103816. +#endif
  103817. +
  103818. + if (core_if->dma_enable != 0) {
  103819. + /*
  103820. + * For EP0 we can only program 1 packet at a time so we
  103821. + * need to do the make calculations after each complete.
  103822. + * Call write_packet to make the calculations, as in
  103823. + * slave mode, and use those values to determine if we
  103824. + * can complete.
  103825. + */
  103826. + if (core_if->dma_desc_enable == 0) {
  103827. + deptsiz.d32 =
  103828. + DWC_READ_REG32(&core_if->
  103829. + dev_if->in_ep_regs[0]->
  103830. + dieptsiz);
  103831. + byte_count =
  103832. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  103833. + } else {
  103834. + desc_sts =
  103835. + core_if->dev_if->in_desc_addr->status;
  103836. + byte_count =
  103837. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  103838. + }
  103839. + ep0->dwc_ep.xfer_count += byte_count;
  103840. + ep0->dwc_ep.xfer_buff += byte_count;
  103841. + ep0->dwc_ep.dma_addr += byte_count;
  103842. + }
  103843. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  103844. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103845. + &ep0->dwc_ep);
  103846. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  103847. + } else if (ep0->dwc_ep.sent_zlp) {
  103848. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103849. + &ep0->dwc_ep);
  103850. + ep0->dwc_ep.sent_zlp = 0;
  103851. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  103852. + } else {
  103853. + ep0_complete_request(ep0);
  103854. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  103855. + }
  103856. + break;
  103857. + case EP0_OUT_DATA_PHASE:
  103858. +#ifdef DEBUG_EP0
  103859. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  103860. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  103861. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  103862. +#endif
  103863. + if (core_if->dma_enable != 0) {
  103864. + if (core_if->dma_desc_enable == 0) {
  103865. + deptsiz.d32 =
  103866. + DWC_READ_REG32(&core_if->
  103867. + dev_if->out_ep_regs[0]->
  103868. + doeptsiz);
  103869. + byte_count =
  103870. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  103871. + } else {
  103872. + desc_sts =
  103873. + core_if->dev_if->out_desc_addr->status;
  103874. + byte_count =
  103875. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  103876. + }
  103877. + ep0->dwc_ep.xfer_count += byte_count;
  103878. + ep0->dwc_ep.xfer_buff += byte_count;
  103879. + ep0->dwc_ep.dma_addr += byte_count;
  103880. + }
  103881. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  103882. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103883. + &ep0->dwc_ep);
  103884. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  103885. + } else if (ep0->dwc_ep.sent_zlp) {
  103886. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  103887. + &ep0->dwc_ep);
  103888. + ep0->dwc_ep.sent_zlp = 0;
  103889. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  103890. + } else {
  103891. + ep0_complete_request(ep0);
  103892. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  103893. + }
  103894. + break;
  103895. +
  103896. + case EP0_IN_STATUS_PHASE:
  103897. + case EP0_OUT_STATUS_PHASE:
  103898. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  103899. + ep0_complete_request(ep0);
  103900. + pcd->ep0state = EP0_IDLE;
  103901. + ep0->stopped = 1;
  103902. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  103903. +
  103904. + /* Prepare for more SETUP Packets */
  103905. + if (core_if->dma_enable) {
  103906. + ep0_out_start(core_if, pcd);
  103907. + }
  103908. + break;
  103909. +
  103910. + case EP0_STALL:
  103911. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  103912. + break;
  103913. + }
  103914. +#ifdef DEBUG_EP0
  103915. + print_ep0_state(pcd);
  103916. +#endif
  103917. +}
  103918. +
  103919. +/**
  103920. + * Restart transfer
  103921. + */
  103922. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  103923. +{
  103924. + dwc_otg_core_if_t *core_if;
  103925. + dwc_otg_dev_if_t *dev_if;
  103926. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  103927. + dwc_otg_pcd_ep_t *ep;
  103928. +
  103929. + ep = get_in_ep(pcd, epnum);
  103930. +
  103931. +#ifdef DWC_EN_ISOC
  103932. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  103933. + return;
  103934. + }
  103935. +#endif /* DWC_EN_ISOC */
  103936. +
  103937. + core_if = GET_CORE_IF(pcd);
  103938. + dev_if = core_if->dev_if;
  103939. +
  103940. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  103941. +
  103942. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  103943. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  103944. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  103945. + /*
  103946. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  103947. + */
  103948. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  103949. + ep->dwc_ep.start_xfer_buff != 0) {
  103950. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  103951. + ep->dwc_ep.xfer_count = 0;
  103952. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  103953. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  103954. + } else {
  103955. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  103956. + /* convert packet size to dwords. */
  103957. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  103958. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  103959. + }
  103960. + ep->stopped = 0;
  103961. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  103962. + "xfer_len=%0x stopped=%d\n",
  103963. + ep->dwc_ep.xfer_buff,
  103964. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  103965. + ep->stopped);
  103966. + if (epnum == 0) {
  103967. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  103968. + } else {
  103969. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  103970. + }
  103971. + }
  103972. +}
  103973. +
  103974. +/*
  103975. + * This function create new nextep sequnce based on Learn Queue.
  103976. + *
  103977. + * @param core_if Programming view of DWC_otg controller
  103978. + */
  103979. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  103980. +{
  103981. + dwc_otg_device_global_regs_t *dev_global_regs =
  103982. + core_if->dev_if->dev_global_regs;
  103983. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  103984. + /* Number of Token Queue Registers */
  103985. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  103986. + dtknq1_data_t dtknqr1;
  103987. + uint32_t in_tkn_epnums[4];
  103988. + uint8_t seqnum[MAX_EPS_CHANNELS];
  103989. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  103990. + grstctl_t resetctl = {.d32 = 0 };
  103991. + uint8_t temp;
  103992. + int ndx = 0;
  103993. + int start = 0;
  103994. + int end = 0;
  103995. + int sort_done = 0;
  103996. + int i = 0;
  103997. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  103998. +
  103999. +
  104000. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  104001. +
  104002. + /* Read the DTKNQ Registers */
  104003. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  104004. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  104005. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  104006. + in_tkn_epnums[i]);
  104007. + if (addr == &dev_global_regs->dvbusdis) {
  104008. + addr = &dev_global_regs->dtknqr3_dthrctl;
  104009. + } else {
  104010. + ++addr;
  104011. + }
  104012. +
  104013. + }
  104014. +
  104015. + /* Copy the DTKNQR1 data to the bit field. */
  104016. + dtknqr1.d32 = in_tkn_epnums[0];
  104017. + if (dtknqr1.b.wrap_bit) {
  104018. + ndx = dtknqr1.b.intknwptr;
  104019. + end = ndx -1;
  104020. + if (end < 0)
  104021. + end = TOKEN_Q_DEPTH -1;
  104022. + } else {
  104023. + ndx = 0;
  104024. + end = dtknqr1.b.intknwptr -1;
  104025. + if (end < 0)
  104026. + end = 0;
  104027. + }
  104028. + start = ndx;
  104029. +
  104030. + /* Fill seqnum[] by initial values: EP number + 31 */
  104031. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  104032. + seqnum[i] = i +31;
  104033. + }
  104034. +
  104035. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  104036. + for (i=0; i < 6; i++)
  104037. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  104038. +
  104039. + if (TOKEN_Q_DEPTH > 6) {
  104040. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  104041. + for (i=6; i < 14; i++)
  104042. + intkn_seq[i] =
  104043. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  104044. + }
  104045. +
  104046. + if (TOKEN_Q_DEPTH > 14) {
  104047. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  104048. + for (i=14; i < 22; i++)
  104049. + intkn_seq[i] =
  104050. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  104051. + }
  104052. +
  104053. + if (TOKEN_Q_DEPTH > 22) {
  104054. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  104055. + for (i=22; i < 30; i++)
  104056. + intkn_seq[i] =
  104057. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  104058. + }
  104059. +
  104060. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  104061. + start, end);
  104062. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  104063. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  104064. +
  104065. + /* Update seqnum based on intkn_seq[] */
  104066. + i = 0;
  104067. + do {
  104068. + seqnum[intkn_seq[ndx]] = i;
  104069. + ndx++;
  104070. + i++;
  104071. + if (ndx == TOKEN_Q_DEPTH)
  104072. + ndx = 0;
  104073. + } while ( i < TOKEN_Q_DEPTH );
  104074. +
  104075. + /* Mark non active EP's in seqnum[] by 0xff */
  104076. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  104077. + if (core_if->nextep_seq[i] == 0xff )
  104078. + seqnum[i] = 0xff;
  104079. + }
  104080. +
  104081. + /* Sort seqnum[] */
  104082. + sort_done = 0;
  104083. + while (!sort_done) {
  104084. + sort_done = 1;
  104085. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  104086. + if (seqnum[i] > seqnum[i+1]) {
  104087. + temp = seqnum[i];
  104088. + seqnum[i] = seqnum[i+1];
  104089. + seqnum[i+1] = temp;
  104090. + sort_done = 0;
  104091. + }
  104092. + }
  104093. + }
  104094. +
  104095. + ndx = start + seqnum[0];
  104096. + if (ndx >= TOKEN_Q_DEPTH)
  104097. + ndx = ndx % TOKEN_Q_DEPTH;
  104098. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  104099. +
  104100. + /* Update seqnum[] by EP numbers */
  104101. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  104102. + ndx = start + i;
  104103. + if (seqnum[i] < 31) {
  104104. + ndx = start + seqnum[i];
  104105. + if (ndx >= TOKEN_Q_DEPTH)
  104106. + ndx = ndx % TOKEN_Q_DEPTH;
  104107. + seqnum[i] = intkn_seq[ndx];
  104108. + } else {
  104109. + if (seqnum[i] < 0xff) {
  104110. + seqnum[i] = seqnum[i] - 31;
  104111. + } else {
  104112. + break;
  104113. + }
  104114. + }
  104115. + }
  104116. +
  104117. + /* Update nextep_seq[] based on seqnum[] */
  104118. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  104119. + if (seqnum[i] != 0xff) {
  104120. + if (seqnum[i+1] != 0xff) {
  104121. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  104122. + } else {
  104123. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  104124. + break;
  104125. + }
  104126. + } else {
  104127. + break;
  104128. + }
  104129. + }
  104130. +
  104131. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  104132. + __func__, core_if->first_in_nextep_seq);
  104133. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  104134. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  104135. + }
  104136. +
  104137. + /* Flush the Learning Queue */
  104138. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  104139. + resetctl.b.intknqflsh = 1;
  104140. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  104141. +
  104142. +
  104143. +}
  104144. +
  104145. +/**
  104146. + * handle the IN EP disable interrupt.
  104147. + */
  104148. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  104149. + const uint32_t epnum)
  104150. +{
  104151. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104152. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  104153. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  104154. + dctl_data_t dctl = {.d32 = 0 };
  104155. + dwc_otg_pcd_ep_t *ep;
  104156. + dwc_ep_t *dwc_ep;
  104157. + gintmsk_data_t gintmsk_data;
  104158. + depctl_data_t depctl;
  104159. + uint32_t diepdma;
  104160. + uint32_t remain_to_transfer = 0;
  104161. + uint8_t i;
  104162. + uint32_t xfer_size;
  104163. +
  104164. + ep = get_in_ep(pcd, epnum);
  104165. + dwc_ep = &ep->dwc_ep;
  104166. +
  104167. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104168. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  104169. + complete_ep(ep);
  104170. + return;
  104171. + }
  104172. +
  104173. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  104174. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  104175. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  104176. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  104177. +
  104178. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  104179. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  104180. +
  104181. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  104182. + if (ep->stopped) {
  104183. + if (core_if->en_multiple_tx_fifo)
  104184. + /* Flush the Tx FIFO */
  104185. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  104186. + /* Clear the Global IN NP NAK */
  104187. + dctl.d32 = 0;
  104188. + dctl.b.cgnpinnak = 1;
  104189. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  104190. + /* Restart the transaction */
  104191. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  104192. + restart_transfer(pcd, epnum);
  104193. + }
  104194. + } else {
  104195. + /* Restart the transaction */
  104196. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  104197. + restart_transfer(pcd, epnum);
  104198. + }
  104199. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  104200. + }
  104201. + return;
  104202. + }
  104203. +
  104204. + if (core_if->start_predict > 2) { // NP IN EP
  104205. + core_if->start_predict--;
  104206. + return;
  104207. + }
  104208. +
  104209. + core_if->start_predict--;
  104210. +
  104211. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  104212. +
  104213. + predict_nextep_seq(core_if);
  104214. +
  104215. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  104216. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  104217. + depctl.d32 =
  104218. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104219. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  104220. + depctl.b.nextep = core_if->nextep_seq[i];
  104221. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  104222. + }
  104223. + }
  104224. + /* Flush Shared NP TxFIFO */
  104225. + dwc_otg_flush_tx_fifo(core_if, 0);
  104226. + /* Rewind buffers */
  104227. + if (!core_if->dma_desc_enable) {
  104228. + i = core_if->first_in_nextep_seq;
  104229. + do {
  104230. + ep = get_in_ep(pcd, i);
  104231. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  104232. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  104233. + if (xfer_size > ep->dwc_ep.maxxfer)
  104234. + xfer_size = ep->dwc_ep.maxxfer;
  104235. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104236. + if (dieptsiz.b.pktcnt != 0) {
  104237. + if (xfer_size == 0) {
  104238. + remain_to_transfer = 0;
  104239. + } else {
  104240. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  104241. + remain_to_transfer =
  104242. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  104243. + } else {
  104244. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  104245. + + (xfer_size % ep->dwc_ep.maxpacket);
  104246. + }
  104247. + }
  104248. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  104249. + dieptsiz.b.xfersize = remain_to_transfer;
  104250. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  104251. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  104252. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  104253. + }
  104254. + i = core_if->nextep_seq[i];
  104255. + } while (i != core_if->first_in_nextep_seq);
  104256. + } else { // dma_desc_enable
  104257. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  104258. + }
  104259. +
  104260. + /* Restart transfers in predicted sequences */
  104261. + i = core_if->first_in_nextep_seq;
  104262. + do {
  104263. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  104264. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104265. + if (dieptsiz.b.pktcnt != 0) {
  104266. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  104267. + depctl.b.epena = 1;
  104268. + depctl.b.cnak = 1;
  104269. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  104270. + }
  104271. + i = core_if->nextep_seq[i];
  104272. + } while (i != core_if->first_in_nextep_seq);
  104273. +
  104274. + /* Clear the global non-periodic IN NAK handshake */
  104275. + dctl.d32 = 0;
  104276. + dctl.b.cgnpinnak = 1;
  104277. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  104278. +
  104279. + /* Unmask EP Mismatch interrupt */
  104280. + gintmsk_data.d32 = 0;
  104281. + gintmsk_data.b.epmismatch = 1;
  104282. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  104283. +
  104284. + core_if->start_predict = 0;
  104285. +
  104286. + }
  104287. +}
  104288. +
  104289. +/**
  104290. + * Handler for the IN EP timeout handshake interrupt.
  104291. + */
  104292. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  104293. + const uint32_t epnum)
  104294. +{
  104295. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104296. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  104297. +
  104298. +#ifdef DEBUG
  104299. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  104300. + uint32_t num = 0;
  104301. +#endif
  104302. + dctl_data_t dctl = {.d32 = 0 };
  104303. + dwc_otg_pcd_ep_t *ep;
  104304. +
  104305. + gintmsk_data_t intr_mask = {.d32 = 0 };
  104306. +
  104307. + ep = get_in_ep(pcd, epnum);
  104308. +
  104309. + /* Disable the NP Tx Fifo Empty Interrrupt */
  104310. + if (!core_if->dma_enable) {
  104311. + intr_mask.b.nptxfempty = 1;
  104312. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  104313. + intr_mask.d32, 0);
  104314. + }
  104315. + /** @todo NGS Check EP type.
  104316. + * Implement for Periodic EPs */
  104317. + /*
  104318. + * Non-periodic EP
  104319. + */
  104320. + /* Enable the Global IN NAK Effective Interrupt */
  104321. + intr_mask.b.ginnakeff = 1;
  104322. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  104323. +
  104324. + /* Set Global IN NAK */
  104325. + dctl.b.sgnpinnak = 1;
  104326. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  104327. +
  104328. + ep->stopped = 1;
  104329. +
  104330. +#ifdef DEBUG
  104331. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  104332. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  104333. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  104334. +#endif
  104335. +
  104336. +#ifdef DISABLE_PERIODIC_EP
  104337. + /*
  104338. + * Set the NAK bit for this EP to
  104339. + * start the disable process.
  104340. + */
  104341. + diepctl.d32 = 0;
  104342. + diepctl.b.snak = 1;
  104343. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  104344. + diepctl.d32);
  104345. + ep->disabling = 1;
  104346. + ep->stopped = 1;
  104347. +#endif
  104348. +}
  104349. +
  104350. +/**
  104351. + * Handler for the IN EP NAK interrupt.
  104352. + */
  104353. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  104354. + const uint32_t epnum)
  104355. +{
  104356. + /** @todo implement ISR */
  104357. + dwc_otg_core_if_t *core_if;
  104358. + diepmsk_data_t intr_mask = {.d32 = 0 };
  104359. +
  104360. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  104361. + core_if = GET_CORE_IF(pcd);
  104362. + intr_mask.b.nak = 1;
  104363. +
  104364. + if (core_if->multiproc_int_enable) {
  104365. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  104366. + diepeachintmsk[epnum], intr_mask.d32, 0);
  104367. + } else {
  104368. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  104369. + intr_mask.d32, 0);
  104370. + }
  104371. +
  104372. + return 1;
  104373. +}
  104374. +
  104375. +/**
  104376. + * Handler for the OUT EP Babble interrupt.
  104377. + */
  104378. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  104379. + const uint32_t epnum)
  104380. +{
  104381. + /** @todo implement ISR */
  104382. + dwc_otg_core_if_t *core_if;
  104383. + doepmsk_data_t intr_mask = {.d32 = 0 };
  104384. +
  104385. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  104386. + "OUT EP Babble");
  104387. + core_if = GET_CORE_IF(pcd);
  104388. + intr_mask.b.babble = 1;
  104389. +
  104390. + if (core_if->multiproc_int_enable) {
  104391. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  104392. + doepeachintmsk[epnum], intr_mask.d32, 0);
  104393. + } else {
  104394. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  104395. + intr_mask.d32, 0);
  104396. + }
  104397. +
  104398. + return 1;
  104399. +}
  104400. +
  104401. +/**
  104402. + * Handler for the OUT EP NAK interrupt.
  104403. + */
  104404. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  104405. + const uint32_t epnum)
  104406. +{
  104407. + /** @todo implement ISR */
  104408. + dwc_otg_core_if_t *core_if;
  104409. + doepmsk_data_t intr_mask = {.d32 = 0 };
  104410. +
  104411. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  104412. + core_if = GET_CORE_IF(pcd);
  104413. + intr_mask.b.nak = 1;
  104414. +
  104415. + if (core_if->multiproc_int_enable) {
  104416. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  104417. + doepeachintmsk[epnum], intr_mask.d32, 0);
  104418. + } else {
  104419. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  104420. + intr_mask.d32, 0);
  104421. + }
  104422. +
  104423. + return 1;
  104424. +}
  104425. +
  104426. +/**
  104427. + * Handler for the OUT EP NYET interrupt.
  104428. + */
  104429. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  104430. + const uint32_t epnum)
  104431. +{
  104432. + /** @todo implement ISR */
  104433. + dwc_otg_core_if_t *core_if;
  104434. + doepmsk_data_t intr_mask = {.d32 = 0 };
  104435. +
  104436. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  104437. + core_if = GET_CORE_IF(pcd);
  104438. + intr_mask.b.nyet = 1;
  104439. +
  104440. + if (core_if->multiproc_int_enable) {
  104441. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  104442. + doepeachintmsk[epnum], intr_mask.d32, 0);
  104443. + } else {
  104444. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  104445. + intr_mask.d32, 0);
  104446. + }
  104447. +
  104448. + return 1;
  104449. +}
  104450. +
  104451. +/**
  104452. + * This interrupt indicates that an IN EP has a pending Interrupt.
  104453. + * The sequence for handling the IN EP interrupt is shown below:
  104454. + * -# Read the Device All Endpoint Interrupt register
  104455. + * -# Repeat the following for each IN EP interrupt bit set (from
  104456. + * LSB to MSB).
  104457. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  104458. + * -# If "Transfer Complete" call the request complete function
  104459. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  104460. + * -# If "AHB Error Interrupt" log error
  104461. + * -# If "Time-out Handshake" log error
  104462. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  104463. + * FIFO.
  104464. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  104465. + * Mismatch Interrupt)
  104466. + */
  104467. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  104468. +{
  104469. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  104470. +do { \
  104471. + diepint_data_t diepint = {.d32=0}; \
  104472. + diepint.b.__intr = 1; \
  104473. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  104474. + diepint.d32); \
  104475. +} while (0)
  104476. +
  104477. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104478. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  104479. + diepint_data_t diepint = {.d32 = 0 };
  104480. + depctl_data_t depctl = {.d32 = 0 };
  104481. + uint32_t ep_intr;
  104482. + uint32_t epnum = 0;
  104483. + dwc_otg_pcd_ep_t *ep;
  104484. + dwc_ep_t *dwc_ep;
  104485. + gintmsk_data_t intr_mask = {.d32 = 0 };
  104486. +
  104487. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  104488. +
  104489. + /* Read in the device interrupt bits */
  104490. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  104491. +
  104492. + /* Service the Device IN interrupts for each endpoint */
  104493. + while (ep_intr) {
  104494. + if (ep_intr & 0x1) {
  104495. + uint32_t empty_msk;
  104496. + /* Get EP pointer */
  104497. + ep = get_in_ep(pcd, epnum);
  104498. + dwc_ep = &ep->dwc_ep;
  104499. +
  104500. + depctl.d32 =
  104501. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  104502. + empty_msk =
  104503. + DWC_READ_REG32(&dev_if->
  104504. + dev_global_regs->dtknqr4_fifoemptymsk);
  104505. +
  104506. + DWC_DEBUGPL(DBG_PCDV,
  104507. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  104508. + epnum, empty_msk, depctl.d32);
  104509. +
  104510. + DWC_DEBUGPL(DBG_PCD,
  104511. + "EP%d-%s: type=%d, mps=%d\n",
  104512. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  104513. + dwc_ep->type, dwc_ep->maxpacket);
  104514. +
  104515. + diepint.d32 =
  104516. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  104517. +
  104518. + DWC_DEBUGPL(DBG_PCDV,
  104519. + "EP %d Interrupt Register - 0x%x\n", epnum,
  104520. + diepint.d32);
  104521. + /* Transfer complete */
  104522. + if (diepint.b.xfercompl) {
  104523. + /* Disable the NP Tx FIFO Empty
  104524. + * Interrupt */
  104525. + if (core_if->en_multiple_tx_fifo == 0) {
  104526. + intr_mask.b.nptxfempty = 1;
  104527. + DWC_MODIFY_REG32
  104528. + (&core_if->core_global_regs->gintmsk,
  104529. + intr_mask.d32, 0);
  104530. + } else {
  104531. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  104532. + uint32_t fifoemptymsk =
  104533. + 0x1 << dwc_ep->num;
  104534. + DWC_MODIFY_REG32(&core_if->
  104535. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  104536. + fifoemptymsk, 0);
  104537. + }
  104538. + /* Clear the bit in DIEPINTn for this interrupt */
  104539. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  104540. +
  104541. + /* Complete the transfer */
  104542. + if (epnum == 0) {
  104543. + handle_ep0(pcd);
  104544. + }
  104545. +#ifdef DWC_EN_ISOC
  104546. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104547. + if (!ep->stopped)
  104548. + complete_iso_ep(pcd, ep);
  104549. + }
  104550. +#endif /* DWC_EN_ISOC */
  104551. +#ifdef DWC_UTE_PER_IO
  104552. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  104553. + if (!ep->stopped)
  104554. + complete_xiso_ep(ep);
  104555. + }
  104556. +#endif /* DWC_UTE_PER_IO */
  104557. + else {
  104558. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  104559. + dwc_ep->bInterval > 1) {
  104560. + dwc_ep->frame_num += dwc_ep->bInterval;
  104561. + if (dwc_ep->frame_num > 0x3FFF)
  104562. + {
  104563. + dwc_ep->frm_overrun = 1;
  104564. + dwc_ep->frame_num &= 0x3FFF;
  104565. + } else
  104566. + dwc_ep->frm_overrun = 0;
  104567. + }
  104568. + complete_ep(ep);
  104569. + if(diepint.b.nak)
  104570. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  104571. + }
  104572. + }
  104573. + /* Endpoint disable */
  104574. + if (diepint.b.epdisabled) {
  104575. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  104576. + epnum);
  104577. + handle_in_ep_disable_intr(pcd, epnum);
  104578. +
  104579. + /* Clear the bit in DIEPINTn for this interrupt */
  104580. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  104581. + }
  104582. + /* AHB Error */
  104583. + if (diepint.b.ahberr) {
  104584. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  104585. + /* Clear the bit in DIEPINTn for this interrupt */
  104586. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  104587. + }
  104588. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  104589. + if (diepint.b.timeout) {
  104590. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  104591. + handle_in_ep_timeout_intr(pcd, epnum);
  104592. +
  104593. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  104594. + }
  104595. + /** IN Token received with TxF Empty */
  104596. + if (diepint.b.intktxfemp) {
  104597. + DWC_DEBUGPL(DBG_ANY,
  104598. + "EP%d IN TKN TxFifo Empty\n",
  104599. + epnum);
  104600. + if (!ep->stopped && epnum != 0) {
  104601. +
  104602. + diepmsk_data_t diepmsk = {.d32 = 0 };
  104603. + diepmsk.b.intktxfemp = 1;
  104604. +
  104605. + if (core_if->multiproc_int_enable) {
  104606. + DWC_MODIFY_REG32
  104607. + (&dev_if->dev_global_regs->diepeachintmsk
  104608. + [epnum], diepmsk.d32, 0);
  104609. + } else {
  104610. + DWC_MODIFY_REG32
  104611. + (&dev_if->dev_global_regs->diepmsk,
  104612. + diepmsk.d32, 0);
  104613. + }
  104614. + } else if (core_if->dma_desc_enable
  104615. + && epnum == 0
  104616. + && pcd->ep0state ==
  104617. + EP0_OUT_STATUS_PHASE) {
  104618. + // EP0 IN set STALL
  104619. + depctl.d32 =
  104620. + DWC_READ_REG32(&dev_if->in_ep_regs
  104621. + [epnum]->diepctl);
  104622. +
  104623. + /* set the disable and stall bits */
  104624. + if (depctl.b.epena) {
  104625. + depctl.b.epdis = 1;
  104626. + }
  104627. + depctl.b.stall = 1;
  104628. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  104629. + [epnum]->diepctl,
  104630. + depctl.d32);
  104631. + }
  104632. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  104633. + }
  104634. + /** IN Token Received with EP mismatch */
  104635. + if (diepint.b.intknepmis) {
  104636. + DWC_DEBUGPL(DBG_ANY,
  104637. + "EP%d IN TKN EP Mismatch\n", epnum);
  104638. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  104639. + }
  104640. + /** IN Endpoint NAK Effective */
  104641. + if (diepint.b.inepnakeff) {
  104642. + DWC_DEBUGPL(DBG_ANY,
  104643. + "EP%d IN EP NAK Effective\n",
  104644. + epnum);
  104645. + /* Periodic EP */
  104646. + if (ep->disabling) {
  104647. + depctl.d32 = 0;
  104648. + depctl.b.snak = 1;
  104649. + depctl.b.epdis = 1;
  104650. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  104651. + [epnum]->diepctl,
  104652. + depctl.d32,
  104653. + depctl.d32);
  104654. + }
  104655. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  104656. +
  104657. + }
  104658. +
  104659. + /** IN EP Tx FIFO Empty Intr */
  104660. + if (diepint.b.emptyintr) {
  104661. + DWC_DEBUGPL(DBG_ANY,
  104662. + "EP%d Tx FIFO Empty Intr \n",
  104663. + epnum);
  104664. + write_empty_tx_fifo(pcd, epnum);
  104665. +
  104666. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  104667. +
  104668. + }
  104669. +
  104670. + /** IN EP BNA Intr */
  104671. + if (diepint.b.bna) {
  104672. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  104673. + if (core_if->dma_desc_enable) {
  104674. +#ifdef DWC_EN_ISOC
  104675. + if (dwc_ep->type ==
  104676. + DWC_OTG_EP_TYPE_ISOC) {
  104677. + /*
  104678. + * This checking is performed to prevent first "false" BNA
  104679. + * handling occuring right after reconnect
  104680. + */
  104681. + if (dwc_ep->next_frame !=
  104682. + 0xffffffff)
  104683. + dwc_otg_pcd_handle_iso_bna(ep);
  104684. + } else
  104685. +#endif /* DWC_EN_ISOC */
  104686. + {
  104687. + dwc_otg_pcd_handle_noniso_bna(ep);
  104688. + }
  104689. + }
  104690. + }
  104691. + /* NAK Interrutp */
  104692. + if (diepint.b.nak) {
  104693. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  104694. + epnum);
  104695. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  104696. + depctl_data_t depctl;
  104697. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  104698. + ep->dwc_ep.frame_num = core_if->frame_num;
  104699. + if (ep->dwc_ep.bInterval > 1) {
  104700. + depctl.d32 = 0;
  104701. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  104702. + if (ep->dwc_ep.frame_num & 0x1) {
  104703. + depctl.b.setd1pid = 1;
  104704. + depctl.b.setd0pid = 0;
  104705. + } else {
  104706. + depctl.b.setd0pid = 1;
  104707. + depctl.b.setd1pid = 0;
  104708. + }
  104709. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  104710. + }
  104711. + start_next_request(ep);
  104712. + }
  104713. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  104714. + if (dwc_ep->frame_num > 0x3FFF) {
  104715. + dwc_ep->frm_overrun = 1;
  104716. + dwc_ep->frame_num &= 0x3FFF;
  104717. + } else
  104718. + dwc_ep->frm_overrun = 0;
  104719. + }
  104720. +
  104721. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  104722. + }
  104723. + }
  104724. + epnum++;
  104725. + ep_intr >>= 1;
  104726. + }
  104727. +
  104728. + return 1;
  104729. +#undef CLEAR_IN_EP_INTR
  104730. +}
  104731. +
  104732. +/**
  104733. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  104734. + * The sequence for handling the OUT EP interrupt is shown below:
  104735. + * -# Read the Device All Endpoint Interrupt register
  104736. + * -# Repeat the following for each OUT EP interrupt bit set (from
  104737. + * LSB to MSB).
  104738. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  104739. + * -# If "Transfer Complete" call the request complete function
  104740. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  104741. + * -# If "AHB Error Interrupt" log error
  104742. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  104743. + * Command Processing)
  104744. + */
  104745. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  104746. +{
  104747. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  104748. +do { \
  104749. + doepint_data_t doepint = {.d32=0}; \
  104750. + doepint.b.__intr = 1; \
  104751. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  104752. + doepint.d32); \
  104753. +} while (0)
  104754. +
  104755. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  104756. + uint32_t ep_intr;
  104757. + doepint_data_t doepint = {.d32 = 0 };
  104758. + uint32_t epnum = 0;
  104759. + dwc_otg_pcd_ep_t *ep;
  104760. + dwc_ep_t *dwc_ep;
  104761. + dctl_data_t dctl = {.d32 = 0 };
  104762. + gintmsk_data_t gintmsk = {.d32 = 0 };
  104763. +
  104764. +
  104765. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  104766. +
  104767. + /* Read in the device interrupt bits */
  104768. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  104769. +
  104770. + while (ep_intr) {
  104771. + if (ep_intr & 0x1) {
  104772. + /* Get EP pointer */
  104773. + ep = get_out_ep(pcd, epnum);
  104774. + dwc_ep = &ep->dwc_ep;
  104775. +
  104776. +#ifdef VERBOSE
  104777. + DWC_DEBUGPL(DBG_PCDV,
  104778. + "EP%d-%s: type=%d, mps=%d\n",
  104779. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  104780. + dwc_ep->type, dwc_ep->maxpacket);
  104781. +#endif
  104782. + doepint.d32 =
  104783. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  104784. + /* Moved this interrupt upper due to core deffect of asserting
  104785. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  104786. + if (doepint.b.stsphsercvd) {
  104787. + deptsiz0_data_t deptsiz;
  104788. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  104789. + deptsiz.d32 =
  104790. + DWC_READ_REG32(&core_if->dev_if->
  104791. + out_ep_regs[0]->doeptsiz);
  104792. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  104793. + && core_if->dma_enable
  104794. + && core_if->dma_desc_enable == 0
  104795. + && doepint.b.xfercompl
  104796. + && deptsiz.b.xfersize == 24) {
  104797. + CLEAR_OUT_EP_INTR(core_if, epnum,
  104798. + xfercompl);
  104799. + doepint.b.xfercompl = 0;
  104800. + ep0_out_start(core_if, pcd);
  104801. + }
  104802. + if ((core_if->dma_desc_enable) ||
  104803. + (core_if->dma_enable
  104804. + && core_if->snpsid >=
  104805. + OTG_CORE_REV_3_00a)) {
  104806. + do_setup_in_status_phase(pcd);
  104807. + }
  104808. + }
  104809. + /* Transfer complete */
  104810. + if (doepint.b.xfercompl) {
  104811. +
  104812. + if (epnum == 0) {
  104813. + /* Clear the bit in DOEPINTn for this interrupt */
  104814. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  104815. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  104816. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  104817. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  104818. + doepint.d32);
  104819. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  104820. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  104821. +
  104822. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  104823. + && core_if->dma_enable == 0) {
  104824. + doepint_data_t doepint;
  104825. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104826. + out_ep_regs[0]->doepint);
  104827. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  104828. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  104829. + goto exit_xfercompl;
  104830. + }
  104831. + }
  104832. + /* In case of DDMA look at SR bit to go to the Data Stage */
  104833. + if (core_if->dma_desc_enable) {
  104834. + dev_dma_desc_sts_t status = {.d32 = 0};
  104835. + if (pcd->ep0state == EP0_IDLE) {
  104836. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  104837. + dev_if->setup_desc_index]->status.d32;
  104838. + if(pcd->data_terminated) {
  104839. + pcd->data_terminated = 0;
  104840. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  104841. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  104842. + }
  104843. + if (status.b.sr) {
  104844. + if (doepint.b.setup) {
  104845. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  104846. + /* Already started data stage, clear setup */
  104847. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104848. + doepint.b.setup = 0;
  104849. + handle_ep0(pcd);
  104850. + /* Prepare for more setup packets */
  104851. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  104852. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  104853. + ep0_out_start(core_if, pcd);
  104854. + }
  104855. +
  104856. + goto exit_xfercompl;
  104857. + } else {
  104858. + /* Prepare for more setup packets */
  104859. + DWC_DEBUGPL(DBG_PCDV,
  104860. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  104861. + ep0_out_start(core_if, pcd);
  104862. + }
  104863. + }
  104864. + } else {
  104865. + dwc_otg_pcd_request_t *req;
  104866. + dev_dma_desc_sts_t status = {.d32 = 0};
  104867. + diepint_data_t diepint0;
  104868. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104869. + in_ep_regs[0]->diepint);
  104870. +
  104871. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  104872. + DWC_ERROR("EP0 is stalled/disconnected\n");
  104873. + }
  104874. +
  104875. + /* Clear IN xfercompl if set */
  104876. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  104877. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  104878. + DWC_WRITE_REG32(&core_if->dev_if->
  104879. + in_ep_regs[0]->diepint, diepint0.d32);
  104880. + }
  104881. +
  104882. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  104883. + dev_if->setup_desc_index]->status.d32;
  104884. +
  104885. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  104886. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  104887. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  104888. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  104889. + status.d32 = core_if->dev_if->
  104890. + out_desc_addr->status.d32;
  104891. +
  104892. + if (status.b.sr) {
  104893. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  104894. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  104895. + } else {
  104896. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  104897. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  104898. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  104899. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  104900. + /* Read arrived setup packet from req->buf */
  104901. + dwc_memcpy(&pcd->setup_pkt->req,
  104902. + req->buf + ep->dwc_ep.xfer_count, 8);
  104903. + }
  104904. + req->actual = ep->dwc_ep.xfer_count;
  104905. + dwc_otg_request_done(ep, req, -ECONNRESET);
  104906. + ep->dwc_ep.start_xfer_buff = 0;
  104907. + ep->dwc_ep.xfer_buff = 0;
  104908. + ep->dwc_ep.xfer_len = 0;
  104909. + }
  104910. + pcd->ep0state = EP0_IDLE;
  104911. + if (doepint.b.setup) {
  104912. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  104913. + /* Data stage started, clear setup */
  104914. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104915. + doepint.b.setup = 0;
  104916. + handle_ep0(pcd);
  104917. + /* Prepare for setup packets if ep0in was enabled*/
  104918. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  104919. + ep0_out_start(core_if, pcd);
  104920. + }
  104921. +
  104922. + goto exit_xfercompl;
  104923. + } else {
  104924. + /* Prepare for more setup packets */
  104925. + DWC_DEBUGPL(DBG_PCDV,
  104926. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  104927. + ep0_out_start(core_if, pcd);
  104928. + }
  104929. + }
  104930. + }
  104931. + }
  104932. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  104933. + && core_if->dma_desc_enable == 0) {
  104934. + doepint_data_t doepint_temp = {.d32 = 0};
  104935. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  104936. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  104937. + out_ep_regs[ep->dwc_ep.num]->doepint);
  104938. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104939. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  104940. + if (pcd->ep0state == EP0_IDLE) {
  104941. + if (doepint_temp.b.sr) {
  104942. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  104943. + }
  104944. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104945. + out_ep_regs[0]->doepint);
  104946. + if (doeptsize0.b.supcnt == 3) {
  104947. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  104948. + ep->dwc_ep.stp_rollover = 1;
  104949. + }
  104950. + if (doepint.b.setup) {
  104951. +retry:
  104952. + /* Already started data stage, clear setup */
  104953. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  104954. + doepint.b.setup = 0;
  104955. + handle_ep0(pcd);
  104956. + ep->dwc_ep.stp_rollover = 0;
  104957. + /* Prepare for more setup packets */
  104958. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  104959. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  104960. + ep0_out_start(core_if, pcd);
  104961. + }
  104962. + goto exit_xfercompl;
  104963. + } else {
  104964. + /* Prepare for more setup packets */
  104965. + DWC_DEBUGPL(DBG_ANY,
  104966. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  104967. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104968. + out_ep_regs[0]->doepint);
  104969. + if(doepint.b.setup)
  104970. + goto retry;
  104971. + ep0_out_start(core_if, pcd);
  104972. + }
  104973. + } else {
  104974. + dwc_otg_pcd_request_t *req;
  104975. + diepint_data_t diepint0 = {.d32 = 0};
  104976. + doepint_data_t doepint_temp = {.d32 = 0};
  104977. + depctl_data_t diepctl0;
  104978. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104979. + in_ep_regs[0]->diepint);
  104980. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  104981. + in_ep_regs[0]->diepctl);
  104982. +
  104983. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  104984. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  104985. + if (diepint0.b.xfercompl) {
  104986. + DWC_WRITE_REG32(&core_if->dev_if->
  104987. + in_ep_regs[0]->diepint, diepint0.d32);
  104988. + }
  104989. + if (diepctl0.b.epena) {
  104990. + diepint_data_t diepint = {.d32 = 0};
  104991. + diepctl0.b.snak = 1;
  104992. + DWC_WRITE_REG32(&core_if->dev_if->
  104993. + in_ep_regs[0]->diepctl, diepctl0.d32);
  104994. + do {
  104995. + dwc_udelay(10);
  104996. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  104997. + in_ep_regs[0]->diepint);
  104998. + } while (!diepint.b.inepnakeff);
  104999. + diepint.b.inepnakeff = 1;
  105000. + DWC_WRITE_REG32(&core_if->dev_if->
  105001. + in_ep_regs[0]->diepint, diepint.d32);
  105002. + diepctl0.d32 = 0;
  105003. + diepctl0.b.epdis = 1;
  105004. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  105005. + diepctl0.d32);
  105006. + do {
  105007. + dwc_udelay(10);
  105008. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  105009. + in_ep_regs[0]->diepint);
  105010. + } while (!diepint.b.epdisabled);
  105011. + diepint.b.epdisabled = 1;
  105012. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  105013. + diepint.d32);
  105014. + }
  105015. + }
  105016. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  105017. + out_ep_regs[ep->dwc_ep.num]->doepint);
  105018. + if (doepint_temp.b.sr) {
  105019. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  105020. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  105021. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  105022. + } else {
  105023. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  105024. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  105025. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  105026. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  105027. + /* Read arrived setup packet from req->buf */
  105028. + dwc_memcpy(&pcd->setup_pkt->req,
  105029. + req->buf + ep->dwc_ep.xfer_count, 8);
  105030. + }
  105031. + req->actual = ep->dwc_ep.xfer_count;
  105032. + dwc_otg_request_done(ep, req, -ECONNRESET);
  105033. + ep->dwc_ep.start_xfer_buff = 0;
  105034. + ep->dwc_ep.xfer_buff = 0;
  105035. + ep->dwc_ep.xfer_len = 0;
  105036. + }
  105037. + pcd->ep0state = EP0_IDLE;
  105038. + if (doepint.b.setup) {
  105039. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  105040. + /* Data stage started, clear setup */
  105041. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  105042. + doepint.b.setup = 0;
  105043. + handle_ep0(pcd);
  105044. + /* Prepare for setup packets if ep0in was enabled*/
  105045. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  105046. + ep0_out_start(core_if, pcd);
  105047. + }
  105048. + goto exit_xfercompl;
  105049. + } else {
  105050. + /* Prepare for more setup packets */
  105051. + DWC_DEBUGPL(DBG_PCDV,
  105052. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  105053. + ep0_out_start(core_if, pcd);
  105054. + }
  105055. + }
  105056. + }
  105057. + }
  105058. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  105059. + handle_ep0(pcd);
  105060. +exit_xfercompl:
  105061. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  105062. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  105063. + } else {
  105064. + if (core_if->dma_desc_enable == 0
  105065. + || pcd->ep0state != EP0_IDLE)
  105066. + handle_ep0(pcd);
  105067. + }
  105068. +#ifdef DWC_EN_ISOC
  105069. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  105070. + if (doepint.b.pktdrpsts == 0) {
  105071. + /* Clear the bit in DOEPINTn for this interrupt */
  105072. + CLEAR_OUT_EP_INTR(core_if,
  105073. + epnum,
  105074. + xfercompl);
  105075. + complete_iso_ep(pcd, ep);
  105076. + } else {
  105077. +
  105078. + doepint_data_t doepint = {.d32 = 0 };
  105079. + doepint.b.xfercompl = 1;
  105080. + doepint.b.pktdrpsts = 1;
  105081. + DWC_WRITE_REG32
  105082. + (&core_if->dev_if->out_ep_regs
  105083. + [epnum]->doepint,
  105084. + doepint.d32);
  105085. + if (handle_iso_out_pkt_dropped
  105086. + (core_if, dwc_ep)) {
  105087. + complete_iso_ep(pcd,
  105088. + ep);
  105089. + }
  105090. + }
  105091. +#endif /* DWC_EN_ISOC */
  105092. +#ifdef DWC_UTE_PER_IO
  105093. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  105094. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  105095. + if (!ep->stopped)
  105096. + complete_xiso_ep(ep);
  105097. +#endif /* DWC_UTE_PER_IO */
  105098. + } else {
  105099. + /* Clear the bit in DOEPINTn for this interrupt */
  105100. + CLEAR_OUT_EP_INTR(core_if, epnum,
  105101. + xfercompl);
  105102. +
  105103. + if (core_if->core_params->dev_out_nak) {
  105104. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  105105. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  105106. +#ifdef DEBUG
  105107. + print_memory_payload(pcd, dwc_ep);
  105108. +#endif
  105109. + }
  105110. + complete_ep(ep);
  105111. + }
  105112. +
  105113. + }
  105114. +
  105115. + /* Endpoint disable */
  105116. + if (doepint.b.epdisabled) {
  105117. +
  105118. + /* Clear the bit in DOEPINTn for this interrupt */
  105119. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  105120. + if (core_if->core_params->dev_out_nak) {
  105121. +#ifdef DEBUG
  105122. + print_memory_payload(pcd, dwc_ep);
  105123. +#endif
  105124. + /* In case of timeout condition */
  105125. + if (core_if->ep_xfer_info[epnum].state == 2) {
  105126. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  105127. + dev_global_regs->dctl);
  105128. + dctl.b.cgoutnak = 1;
  105129. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  105130. + dctl.d32);
  105131. + /* Unmask goutnakeff interrupt which was masked
  105132. + * during handle nak out interrupt */
  105133. + gintmsk.b.goutnakeff = 1;
  105134. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  105135. + 0, gintmsk.d32);
  105136. +
  105137. + complete_ep(ep);
  105138. + }
  105139. + }
  105140. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  105141. + {
  105142. + dctl_data_t dctl;
  105143. + gintmsk_data_t intr_mask = {.d32 = 0};
  105144. + dwc_otg_pcd_request_t *req = 0;
  105145. +
  105146. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  105147. + dev_global_regs->dctl);
  105148. + dctl.b.cgoutnak = 1;
  105149. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  105150. + dctl.d32);
  105151. +
  105152. + intr_mask.d32 = 0;
  105153. + intr_mask.b.incomplisoout = 1;
  105154. +
  105155. + /* Get any pending requests */
  105156. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  105157. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  105158. + if (!req) {
  105159. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  105160. + } else {
  105161. + dwc_otg_request_done(ep, req, 0);
  105162. + start_next_request(ep);
  105163. + }
  105164. + } else {
  105165. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  105166. + }
  105167. + }
  105168. + }
  105169. + /* AHB Error */
  105170. + if (doepint.b.ahberr) {
  105171. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  105172. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  105173. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  105174. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  105175. + }
  105176. + /* Setup Phase Done (contorl EPs) */
  105177. + if (doepint.b.setup) {
  105178. +#ifdef DEBUG_EP0
  105179. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  105180. +#endif
  105181. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  105182. +
  105183. + handle_ep0(pcd);
  105184. + }
  105185. +
  105186. + /** OUT EP BNA Intr */
  105187. + if (doepint.b.bna) {
  105188. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  105189. + if (core_if->dma_desc_enable) {
  105190. +#ifdef DWC_EN_ISOC
  105191. + if (dwc_ep->type ==
  105192. + DWC_OTG_EP_TYPE_ISOC) {
  105193. + /*
  105194. + * This checking is performed to prevent first "false" BNA
  105195. + * handling occuring right after reconnect
  105196. + */
  105197. + if (dwc_ep->next_frame !=
  105198. + 0xffffffff)
  105199. + dwc_otg_pcd_handle_iso_bna(ep);
  105200. + } else
  105201. +#endif /* DWC_EN_ISOC */
  105202. + {
  105203. + dwc_otg_pcd_handle_noniso_bna(ep);
  105204. + }
  105205. + }
  105206. + }
  105207. + /* Babble Interrupt */
  105208. + if (doepint.b.babble) {
  105209. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  105210. + epnum);
  105211. + handle_out_ep_babble_intr(pcd, epnum);
  105212. +
  105213. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  105214. + }
  105215. + if (doepint.b.outtknepdis) {
  105216. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  105217. + disabled\n",epnum);
  105218. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  105219. + doepmsk_data_t doepmsk = {.d32 = 0};
  105220. + ep->dwc_ep.frame_num = core_if->frame_num;
  105221. + if (ep->dwc_ep.bInterval > 1) {
  105222. + depctl_data_t depctl;
  105223. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  105224. + out_ep_regs[epnum]->doepctl);
  105225. + if (ep->dwc_ep.frame_num & 0x1) {
  105226. + depctl.b.setd1pid = 1;
  105227. + depctl.b.setd0pid = 0;
  105228. + } else {
  105229. + depctl.b.setd0pid = 1;
  105230. + depctl.b.setd1pid = 0;
  105231. + }
  105232. + DWC_WRITE_REG32(&core_if->dev_if->
  105233. + out_ep_regs[epnum]->doepctl, depctl.d32);
  105234. + }
  105235. + start_next_request(ep);
  105236. + doepmsk.b.outtknepdis = 1;
  105237. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  105238. + doepmsk.d32, 0);
  105239. + }
  105240. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  105241. + }
  105242. +
  105243. + /* NAK Interrutp */
  105244. + if (doepint.b.nak) {
  105245. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  105246. + handle_out_ep_nak_intr(pcd, epnum);
  105247. +
  105248. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  105249. + }
  105250. + /* NYET Interrutp */
  105251. + if (doepint.b.nyet) {
  105252. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  105253. + handle_out_ep_nyet_intr(pcd, epnum);
  105254. +
  105255. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  105256. + }
  105257. + }
  105258. +
  105259. + epnum++;
  105260. + ep_intr >>= 1;
  105261. + }
  105262. +
  105263. + return 1;
  105264. +
  105265. +#undef CLEAR_OUT_EP_INTR
  105266. +}
  105267. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  105268. +{
  105269. + int retval = 0;
  105270. + if(!frm_overrun && curr_fr >= trgt_fr)
  105271. + retval = 1;
  105272. + else if (frm_overrun
  105273. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  105274. + retval = 1;
  105275. + return retval;
  105276. +}
  105277. +/**
  105278. + * Incomplete ISO IN Transfer Interrupt.
  105279. + * This interrupt indicates one of the following conditions occurred
  105280. + * while transmitting an ISOC transaction.
  105281. + * - Corrupted IN Token for ISOC EP.
  105282. + * - Packet not complete in FIFO.
  105283. + * The follow actions will be taken:
  105284. + * -# Determine the EP
  105285. + * -# Set incomplete flag in dwc_ep structure
  105286. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  105287. + * Flush FIFO
  105288. + */
  105289. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  105290. +{
  105291. + gintsts_data_t gintsts;
  105292. +
  105293. +#ifdef DWC_EN_ISOC
  105294. + dwc_otg_dev_if_t *dev_if;
  105295. + deptsiz_data_t deptsiz = {.d32 = 0 };
  105296. + depctl_data_t depctl = {.d32 = 0 };
  105297. + dsts_data_t dsts = {.d32 = 0 };
  105298. + dwc_ep_t *dwc_ep;
  105299. + int i;
  105300. +
  105301. + dev_if = GET_CORE_IF(pcd)->dev_if;
  105302. +
  105303. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  105304. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  105305. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  105306. + deptsiz.d32 =
  105307. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  105308. + depctl.d32 =
  105309. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  105310. +
  105311. + if (depctl.b.epdis && deptsiz.d32) {
  105312. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  105313. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  105314. + dwc_ep->cur_pkt = 0;
  105315. + dwc_ep->proc_buf_num =
  105316. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  105317. +
  105318. + if (dwc_ep->proc_buf_num) {
  105319. + dwc_ep->cur_pkt_addr =
  105320. + dwc_ep->xfer_buff1;
  105321. + dwc_ep->cur_pkt_dma_addr =
  105322. + dwc_ep->dma_addr1;
  105323. + } else {
  105324. + dwc_ep->cur_pkt_addr =
  105325. + dwc_ep->xfer_buff0;
  105326. + dwc_ep->cur_pkt_dma_addr =
  105327. + dwc_ep->dma_addr0;
  105328. + }
  105329. +
  105330. + }
  105331. +
  105332. + dsts.d32 =
  105333. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  105334. + dev_global_regs->dsts);
  105335. + dwc_ep->next_frame = dsts.b.soffn;
  105336. +
  105337. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  105338. + (pcd),
  105339. + dwc_ep);
  105340. + }
  105341. + }
  105342. + }
  105343. +
  105344. +#else
  105345. + depctl_data_t depctl = {.d32 = 0 };
  105346. + dwc_ep_t *dwc_ep;
  105347. + dwc_otg_dev_if_t *dev_if;
  105348. + int i;
  105349. + dev_if = GET_CORE_IF(pcd)->dev_if;
  105350. +
  105351. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  105352. +
  105353. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  105354. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  105355. + depctl.d32 =
  105356. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  105357. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  105358. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  105359. + dwc_ep->frm_overrun))
  105360. + {
  105361. + depctl.d32 =
  105362. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  105363. + depctl.b.snak = 1;
  105364. + depctl.b.epdis = 1;
  105365. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  105366. + }
  105367. + }
  105368. + }
  105369. +
  105370. + /*intr_mask.b.incomplisoin = 1;
  105371. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  105372. + intr_mask.d32, 0); */
  105373. +#endif //DWC_EN_ISOC
  105374. +
  105375. + /* Clear interrupt */
  105376. + gintsts.d32 = 0;
  105377. + gintsts.b.incomplisoin = 1;
  105378. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105379. + gintsts.d32);
  105380. +
  105381. + return 1;
  105382. +}
  105383. +
  105384. +/**
  105385. + * Incomplete ISO OUT Transfer Interrupt.
  105386. + *
  105387. + * This interrupt indicates that the core has dropped an ISO OUT
  105388. + * packet. The following conditions can be the cause:
  105389. + * - FIFO Full, the entire packet would not fit in the FIFO.
  105390. + * - CRC Error
  105391. + * - Corrupted Token
  105392. + * The follow actions will be taken:
  105393. + * -# Determine the EP
  105394. + * -# Set incomplete flag in dwc_ep structure
  105395. + * -# Read any data from the FIFO
  105396. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  105397. + * re-enable EP.
  105398. + */
  105399. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  105400. +{
  105401. +
  105402. + gintsts_data_t gintsts;
  105403. +
  105404. +#ifdef DWC_EN_ISOC
  105405. + dwc_otg_dev_if_t *dev_if;
  105406. + deptsiz_data_t deptsiz = {.d32 = 0 };
  105407. + depctl_data_t depctl = {.d32 = 0 };
  105408. + dsts_data_t dsts = {.d32 = 0 };
  105409. + dwc_ep_t *dwc_ep;
  105410. + int i;
  105411. +
  105412. + dev_if = GET_CORE_IF(pcd)->dev_if;
  105413. +
  105414. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  105415. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  105416. + if (pcd->out_ep[i].dwc_ep.active &&
  105417. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  105418. + deptsiz.d32 =
  105419. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  105420. + depctl.d32 =
  105421. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  105422. +
  105423. + if (depctl.b.epdis && deptsiz.d32) {
  105424. + set_current_pkt_info(GET_CORE_IF(pcd),
  105425. + &pcd->out_ep[i].dwc_ep);
  105426. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  105427. + dwc_ep->cur_pkt = 0;
  105428. + dwc_ep->proc_buf_num =
  105429. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  105430. +
  105431. + if (dwc_ep->proc_buf_num) {
  105432. + dwc_ep->cur_pkt_addr =
  105433. + dwc_ep->xfer_buff1;
  105434. + dwc_ep->cur_pkt_dma_addr =
  105435. + dwc_ep->dma_addr1;
  105436. + } else {
  105437. + dwc_ep->cur_pkt_addr =
  105438. + dwc_ep->xfer_buff0;
  105439. + dwc_ep->cur_pkt_dma_addr =
  105440. + dwc_ep->dma_addr0;
  105441. + }
  105442. +
  105443. + }
  105444. +
  105445. + dsts.d32 =
  105446. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  105447. + dev_global_regs->dsts);
  105448. + dwc_ep->next_frame = dsts.b.soffn;
  105449. +
  105450. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  105451. + (pcd),
  105452. + dwc_ep);
  105453. + }
  105454. + }
  105455. + }
  105456. +#else
  105457. + /** @todo implement ISR */
  105458. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105459. + dwc_otg_core_if_t *core_if;
  105460. + deptsiz_data_t deptsiz = {.d32 = 0 };
  105461. + depctl_data_t depctl = {.d32 = 0 };
  105462. + dctl_data_t dctl = {.d32 = 0 };
  105463. + dwc_ep_t *dwc_ep = NULL;
  105464. + int i;
  105465. + core_if = GET_CORE_IF(pcd);
  105466. +
  105467. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  105468. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  105469. + depctl.d32 =
  105470. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  105471. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  105472. + core_if->dev_if->isoc_ep = dwc_ep;
  105473. + deptsiz.d32 =
  105474. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  105475. + break;
  105476. + }
  105477. + }
  105478. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  105479. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  105480. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  105481. +
  105482. + if (!intr_mask.b.goutnakeff) {
  105483. + /* Unmask it */
  105484. + intr_mask.b.goutnakeff = 1;
  105485. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  105486. + }
  105487. + if (!gintsts.b.goutnakeff) {
  105488. + dctl.b.sgoutnak = 1;
  105489. + }
  105490. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  105491. +
  105492. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  105493. + if (depctl.b.epena) {
  105494. + depctl.b.epdis = 1;
  105495. + depctl.b.snak = 1;
  105496. + }
  105497. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  105498. +
  105499. + intr_mask.d32 = 0;
  105500. + intr_mask.b.incomplisoout = 1;
  105501. +
  105502. +#endif /* DWC_EN_ISOC */
  105503. +
  105504. + /* Clear interrupt */
  105505. + gintsts.d32 = 0;
  105506. + gintsts.b.incomplisoout = 1;
  105507. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105508. + gintsts.d32);
  105509. +
  105510. + return 1;
  105511. +}
  105512. +
  105513. +/**
  105514. + * This function handles the Global IN NAK Effective interrupt.
  105515. + *
  105516. + */
  105517. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  105518. +{
  105519. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  105520. + depctl_data_t diepctl = {.d32 = 0 };
  105521. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105522. + gintsts_data_t gintsts;
  105523. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  105524. + int i;
  105525. +
  105526. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  105527. +
  105528. + /* Disable all active IN EPs */
  105529. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  105530. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  105531. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  105532. + if (core_if->start_predict > 0)
  105533. + core_if->start_predict++;
  105534. + diepctl.b.epdis = 1;
  105535. + diepctl.b.snak = 1;
  105536. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  105537. + }
  105538. + }
  105539. +
  105540. +
  105541. + /* Disable the Global IN NAK Effective Interrupt */
  105542. + intr_mask.b.ginnakeff = 1;
  105543. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  105544. + intr_mask.d32, 0);
  105545. +
  105546. + /* Clear interrupt */
  105547. + gintsts.d32 = 0;
  105548. + gintsts.b.ginnakeff = 1;
  105549. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105550. + gintsts.d32);
  105551. +
  105552. + return 1;
  105553. +}
  105554. +
  105555. +/**
  105556. + * OUT NAK Effective.
  105557. + *
  105558. + */
  105559. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  105560. +{
  105561. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  105562. + gintmsk_data_t intr_mask = {.d32 = 0 };
  105563. + gintsts_data_t gintsts;
  105564. + depctl_data_t doepctl;
  105565. + int i;
  105566. +
  105567. + /* Disable the Global OUT NAK Effective Interrupt */
  105568. + intr_mask.b.goutnakeff = 1;
  105569. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  105570. + intr_mask.d32, 0);
  105571. +
  105572. + /* If DEV OUT NAK enabled*/
  105573. + if (pcd->core_if->core_params->dev_out_nak) {
  105574. + /* Run over all out endpoints to determine the ep number on
  105575. + * which the timeout has happened
  105576. + */
  105577. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  105578. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  105579. + break;
  105580. + }
  105581. + if (i > dev_if->num_out_eps) {
  105582. + dctl_data_t dctl;
  105583. + dctl.d32 =
  105584. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  105585. + dctl.b.cgoutnak = 1;
  105586. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  105587. + dctl.d32);
  105588. + goto out;
  105589. + }
  105590. +
  105591. + /* Disable the endpoint */
  105592. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  105593. + if (doepctl.b.epena) {
  105594. + doepctl.b.epdis = 1;
  105595. + doepctl.b.snak = 1;
  105596. + }
  105597. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  105598. + return 1;
  105599. + }
  105600. + /* We come here from Incomplete ISO OUT handler */
  105601. + if (dev_if->isoc_ep) {
  105602. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  105603. + uint32_t epnum = dwc_ep->num;
  105604. + doepint_data_t doepint;
  105605. + doepint.d32 =
  105606. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  105607. + dev_if->isoc_ep = NULL;
  105608. + doepctl.d32 =
  105609. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  105610. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  105611. + if (doepctl.b.epena) {
  105612. + doepctl.b.epdis = 1;
  105613. + doepctl.b.snak = 1;
  105614. + }
  105615. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  105616. + doepctl.d32);
  105617. + return 1;
  105618. + } else
  105619. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  105620. + "Global OUT NAK Effective\n");
  105621. +
  105622. +out:
  105623. + /* Clear interrupt */
  105624. + gintsts.d32 = 0;
  105625. + gintsts.b.goutnakeff = 1;
  105626. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  105627. + gintsts.d32);
  105628. +
  105629. + return 1;
  105630. +}
  105631. +
  105632. +/**
  105633. + * PCD interrupt handler.
  105634. + *
  105635. + * The PCD handles the device interrupts. Many conditions can cause a
  105636. + * device interrupt. When an interrupt occurs, the device interrupt
  105637. + * service routine determines the cause of the interrupt and
  105638. + * dispatches handling to the appropriate function. These interrupt
  105639. + * handling functions are described below.
  105640. + *
  105641. + * All interrupt registers are processed from LSB to MSB.
  105642. + *
  105643. + */
  105644. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  105645. +{
  105646. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  105647. +#ifdef VERBOSE
  105648. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  105649. +#endif
  105650. + gintsts_data_t gintr_status;
  105651. + int32_t retval = 0;
  105652. +
  105653. + /* Exit from ISR if core is hibernated */
  105654. + if (core_if->hibernation_suspend == 1) {
  105655. + return retval;
  105656. + }
  105657. +#ifdef VERBOSE
  105658. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  105659. + __func__,
  105660. + DWC_READ_REG32(&global_regs->gintsts),
  105661. + DWC_READ_REG32(&global_regs->gintmsk));
  105662. +#endif
  105663. +
  105664. + if (dwc_otg_is_device_mode(core_if)) {
  105665. + DWC_SPINLOCK(pcd->lock);
  105666. +#ifdef VERBOSE
  105667. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  105668. + __func__,
  105669. + DWC_READ_REG32(&global_regs->gintsts),
  105670. + DWC_READ_REG32(&global_regs->gintmsk));
  105671. +#endif
  105672. +
  105673. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  105674. +
  105675. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  105676. + __func__, gintr_status.d32);
  105677. +
  105678. + if (gintr_status.b.sofintr) {
  105679. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  105680. + }
  105681. + if (gintr_status.b.rxstsqlvl) {
  105682. + retval |=
  105683. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  105684. + }
  105685. + if (gintr_status.b.nptxfempty) {
  105686. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  105687. + }
  105688. + if (gintr_status.b.goutnakeff) {
  105689. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  105690. + }
  105691. + if (gintr_status.b.i2cintr) {
  105692. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  105693. + }
  105694. + if (gintr_status.b.erlysuspend) {
  105695. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  105696. + }
  105697. + if (gintr_status.b.usbreset) {
  105698. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  105699. + }
  105700. + if (gintr_status.b.enumdone) {
  105701. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  105702. + }
  105703. + if (gintr_status.b.isooutdrop) {
  105704. + retval |=
  105705. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  105706. + (pcd);
  105707. + }
  105708. + if (gintr_status.b.eopframe) {
  105709. + retval |=
  105710. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  105711. + }
  105712. + if (gintr_status.b.inepint) {
  105713. + if (!core_if->multiproc_int_enable) {
  105714. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  105715. + }
  105716. + }
  105717. + if (gintr_status.b.outepintr) {
  105718. + if (!core_if->multiproc_int_enable) {
  105719. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  105720. + }
  105721. + }
  105722. + if (gintr_status.b.epmismatch) {
  105723. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  105724. + }
  105725. + if (gintr_status.b.fetsusp) {
  105726. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  105727. + }
  105728. + if (gintr_status.b.ginnakeff) {
  105729. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  105730. + }
  105731. + if (gintr_status.b.incomplisoin) {
  105732. + retval |=
  105733. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  105734. + }
  105735. + if (gintr_status.b.incomplisoout) {
  105736. + retval |=
  105737. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  105738. + }
  105739. +
  105740. + /* In MPI mode Device Endpoints interrupts are asserted
  105741. + * without setting outepintr and inepint bits set, so these
  105742. + * Interrupt handlers are called without checking these bit-fields
  105743. + */
  105744. + if (core_if->multiproc_int_enable) {
  105745. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  105746. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  105747. + }
  105748. +#ifdef VERBOSE
  105749. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  105750. + DWC_READ_REG32(&global_regs->gintsts));
  105751. +#endif
  105752. + DWC_SPINUNLOCK(pcd->lock);
  105753. + }
  105754. + return retval;
  105755. +}
  105756. +
  105757. +#endif /* DWC_HOST_ONLY */
  105758. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  105759. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  105760. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2015-03-09 10:39:33.218893718 +0100
  105761. @@ -0,0 +1,1360 @@
  105762. + /* ==========================================================================
  105763. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  105764. + * $Revision: #21 $
  105765. + * $Date: 2012/08/10 $
  105766. + * $Change: 2047372 $
  105767. + *
  105768. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  105769. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  105770. + * otherwise expressly agreed to in writing between Synopsys and you.
  105771. + *
  105772. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  105773. + * any End User Software License Agreement or Agreement for Licensed Product
  105774. + * with Synopsys or any supplement thereto. You are permitted to use and
  105775. + * redistribute this Software in source and binary forms, with or without
  105776. + * modification, provided that redistributions of source code must retain this
  105777. + * notice. You may not view, use, disclose, copy or distribute this file or
  105778. + * any information contained herein except pursuant to this license grant from
  105779. + * Synopsys. If you do not agree with this notice, including the disclaimer
  105780. + * below, then you are not authorized to use the Software.
  105781. + *
  105782. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  105783. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  105784. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  105785. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  105786. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  105787. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  105788. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  105789. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  105790. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  105791. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  105792. + * DAMAGE.
  105793. + * ========================================================================== */
  105794. +#ifndef DWC_HOST_ONLY
  105795. +
  105796. +/** @file
  105797. + * This file implements the Peripheral Controller Driver.
  105798. + *
  105799. + * The Peripheral Controller Driver (PCD) is responsible for
  105800. + * translating requests from the Function Driver into the appropriate
  105801. + * actions on the DWC_otg controller. It isolates the Function Driver
  105802. + * from the specifics of the controller by providing an API to the
  105803. + * Function Driver.
  105804. + *
  105805. + * The Peripheral Controller Driver for Linux will implement the
  105806. + * Gadget API, so that the existing Gadget drivers can be used.
  105807. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  105808. + *
  105809. + * The Linux Gadget API is defined in the header file
  105810. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  105811. + * defined in the structure <code>usb_ep_ops</code> and the USB
  105812. + * Controller API is defined in the structure
  105813. + * <code>usb_gadget_ops</code>.
  105814. + *
  105815. + */
  105816. +
  105817. +#include "dwc_otg_os_dep.h"
  105818. +#include "dwc_otg_pcd_if.h"
  105819. +#include "dwc_otg_pcd.h"
  105820. +#include "dwc_otg_driver.h"
  105821. +#include "dwc_otg_dbg.h"
  105822. +
  105823. +extern bool fiq_enable;
  105824. +
  105825. +static struct gadget_wrapper {
  105826. + dwc_otg_pcd_t *pcd;
  105827. +
  105828. + struct usb_gadget gadget;
  105829. + struct usb_gadget_driver *driver;
  105830. +
  105831. + struct usb_ep ep0;
  105832. + struct usb_ep in_ep[16];
  105833. + struct usb_ep out_ep[16];
  105834. +
  105835. +} *gadget_wrapper;
  105836. +
  105837. +/* Display the contents of the buffer */
  105838. +extern void dump_msg(const u8 * buf, unsigned int length);
  105839. +/**
  105840. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  105841. + * if the endpoint is not found
  105842. + */
  105843. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  105844. +{
  105845. + int i;
  105846. + if (pcd->ep0.priv == handle) {
  105847. + return &pcd->ep0;
  105848. + }
  105849. +
  105850. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  105851. + if (pcd->in_ep[i].priv == handle)
  105852. + return &pcd->in_ep[i];
  105853. + if (pcd->out_ep[i].priv == handle)
  105854. + return &pcd->out_ep[i];
  105855. + }
  105856. +
  105857. + return NULL;
  105858. +}
  105859. +
  105860. +/* USB Endpoint Operations */
  105861. +/*
  105862. + * The following sections briefly describe the behavior of the Gadget
  105863. + * API endpoint operations implemented in the DWC_otg driver
  105864. + * software. Detailed descriptions of the generic behavior of each of
  105865. + * these functions can be found in the Linux header file
  105866. + * include/linux/usb_gadget.h.
  105867. + *
  105868. + * The Gadget API provides wrapper functions for each of the function
  105869. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  105870. + * function, which then calls the underlying PCD function. The
  105871. + * following sections are named according to the wrapper
  105872. + * functions. Within each section, the corresponding DWC_otg PCD
  105873. + * function name is specified.
  105874. + *
  105875. + */
  105876. +
  105877. +/**
  105878. + * This function is called by the Gadget Driver for each EP to be
  105879. + * configured for the current configuration (SET_CONFIGURATION).
  105880. + *
  105881. + * This function initializes the dwc_otg_ep_t data structure, and then
  105882. + * calls dwc_otg_ep_activate.
  105883. + */
  105884. +static int ep_enable(struct usb_ep *usb_ep,
  105885. + const struct usb_endpoint_descriptor *ep_desc)
  105886. +{
  105887. + int retval;
  105888. +
  105889. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  105890. +
  105891. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  105892. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  105893. + return -EINVAL;
  105894. + }
  105895. + if (usb_ep == &gadget_wrapper->ep0) {
  105896. + DWC_WARN("%s, bad ep(0)\n", __func__);
  105897. + return -EINVAL;
  105898. + }
  105899. +
  105900. + /* Check FIFO size? */
  105901. + if (!ep_desc->wMaxPacketSize) {
  105902. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  105903. + return -ERANGE;
  105904. + }
  105905. +
  105906. + if (!gadget_wrapper->driver ||
  105907. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  105908. + DWC_WARN("%s, bogus device state\n", __func__);
  105909. + return -ESHUTDOWN;
  105910. + }
  105911. +
  105912. + /* Delete after check - MAS */
  105913. +#if 0
  105914. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  105915. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  105916. + nat = (nat >> 11) & 0x03;
  105917. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  105918. +#endif
  105919. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  105920. + (const uint8_t *)ep_desc,
  105921. + (void *)usb_ep);
  105922. + if (retval) {
  105923. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  105924. + return -EINVAL;
  105925. + }
  105926. +
  105927. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  105928. +
  105929. + return 0;
  105930. +}
  105931. +
  105932. +/**
  105933. + * This function is called when an EP is disabled due to disconnect or
  105934. + * change in configuration. Any pending requests will terminate with a
  105935. + * status of -ESHUTDOWN.
  105936. + *
  105937. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  105938. + * and then calls dwc_otg_ep_deactivate.
  105939. + */
  105940. +static int ep_disable(struct usb_ep *usb_ep)
  105941. +{
  105942. + int retval;
  105943. +
  105944. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  105945. + if (!usb_ep) {
  105946. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  105947. + usb_ep ? usb_ep->name : NULL);
  105948. + return -EINVAL;
  105949. + }
  105950. +
  105951. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  105952. + if (retval) {
  105953. + retval = -EINVAL;
  105954. + }
  105955. +
  105956. + return retval;
  105957. +}
  105958. +
  105959. +/**
  105960. + * This function allocates a request object to use with the specified
  105961. + * endpoint.
  105962. + *
  105963. + * @param ep The endpoint to be used with with the request
  105964. + * @param gfp_flags the GFP_* flags to use.
  105965. + */
  105966. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  105967. + gfp_t gfp_flags)
  105968. +{
  105969. + struct usb_request *usb_req;
  105970. +
  105971. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  105972. + if (0 == ep) {
  105973. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  105974. + return 0;
  105975. + }
  105976. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  105977. + if (0 == usb_req) {
  105978. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  105979. + return 0;
  105980. + }
  105981. + memset(usb_req, 0, sizeof(*usb_req));
  105982. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  105983. +
  105984. + return usb_req;
  105985. +}
  105986. +
  105987. +/**
  105988. + * This function frees a request object.
  105989. + *
  105990. + * @param ep The endpoint associated with the request
  105991. + * @param req The request being freed
  105992. + */
  105993. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  105994. +{
  105995. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  105996. +
  105997. + if (0 == ep || 0 == req) {
  105998. + DWC_WARN("%s() %s\n", __func__,
  105999. + "Invalid ep or req argument!\n");
  106000. + return;
  106001. + }
  106002. +
  106003. + kfree(req);
  106004. +}
  106005. +
  106006. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106007. +/**
  106008. + * This function allocates an I/O buffer to be used for a transfer
  106009. + * to/from the specified endpoint.
  106010. + *
  106011. + * @param usb_ep The endpoint to be used with with the request
  106012. + * @param bytes The desired number of bytes for the buffer
  106013. + * @param dma Pointer to the buffer's DMA address; must be valid
  106014. + * @param gfp_flags the GFP_* flags to use.
  106015. + * @return address of a new buffer or null is buffer could not be allocated.
  106016. + */
  106017. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  106018. + dma_addr_t * dma, gfp_t gfp_flags)
  106019. +{
  106020. + void *buf;
  106021. + dwc_otg_pcd_t *pcd = 0;
  106022. +
  106023. + pcd = gadget_wrapper->pcd;
  106024. +
  106025. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  106026. + dma, gfp_flags);
  106027. +
  106028. + /* Check dword alignment */
  106029. + if ((bytes & 0x3UL) != 0) {
  106030. + DWC_WARN("%s() Buffer size is not a multiple of"
  106031. + "DWORD size (%d)", __func__, bytes);
  106032. + }
  106033. +
  106034. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  106035. +
  106036. + /* Check dword alignment */
  106037. + if (((int)buf & 0x3UL) != 0) {
  106038. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  106039. + __func__, buf);
  106040. + }
  106041. +
  106042. + return buf;
  106043. +}
  106044. +
  106045. +/**
  106046. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  106047. + *
  106048. + * @param usb_ep the endpoint associated with the buffer
  106049. + * @param buf address of the buffer
  106050. + * @param dma The buffer's DMA address
  106051. + * @param bytes The number of bytes of the buffer
  106052. + */
  106053. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  106054. + dma_addr_t dma, unsigned bytes)
  106055. +{
  106056. + dwc_otg_pcd_t *pcd = 0;
  106057. +
  106058. + pcd = gadget_wrapper->pcd;
  106059. +
  106060. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  106061. +
  106062. + dma_free_coherent(NULL, bytes, buf, dma);
  106063. +}
  106064. +#endif
  106065. +
  106066. +/**
  106067. + * This function is used to submit an I/O Request to an EP.
  106068. + *
  106069. + * - When the request completes the request's completion callback
  106070. + * is called to return the request to the driver.
  106071. + * - An EP, except control EPs, may have multiple requests
  106072. + * pending.
  106073. + * - Once submitted the request cannot be examined or modified.
  106074. + * - Each request is turned into one or more packets.
  106075. + * - A BULK EP can queue any amount of data; the transfer is
  106076. + * packetized.
  106077. + * - Zero length Packets are specified with the request 'zero'
  106078. + * flag.
  106079. + */
  106080. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  106081. + gfp_t gfp_flags)
  106082. +{
  106083. + dwc_otg_pcd_t *pcd;
  106084. + struct dwc_otg_pcd_ep *ep = NULL;
  106085. + int retval = 0, is_isoc_ep = 0;
  106086. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  106087. +
  106088. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  106089. + __func__, usb_ep, usb_req, gfp_flags);
  106090. +
  106091. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  106092. + DWC_WARN("bad params\n");
  106093. + return -EINVAL;
  106094. + }
  106095. +
  106096. + if (!usb_ep) {
  106097. + DWC_WARN("bad ep\n");
  106098. + return -EINVAL;
  106099. + }
  106100. +
  106101. + pcd = gadget_wrapper->pcd;
  106102. + if (!gadget_wrapper->driver ||
  106103. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  106104. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  106105. + gadget_wrapper->gadget.speed);
  106106. + DWC_WARN("bogus device state\n");
  106107. + return -ESHUTDOWN;
  106108. + }
  106109. +
  106110. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  106111. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  106112. +
  106113. + usb_req->status = -EINPROGRESS;
  106114. + usb_req->actual = 0;
  106115. +
  106116. + ep = ep_from_handle(pcd, usb_ep);
  106117. + if (ep == NULL)
  106118. + is_isoc_ep = 0;
  106119. + else
  106120. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  106121. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106122. + dma_addr = usb_req->dma;
  106123. +#else
  106124. + if (GET_CORE_IF(pcd)->dma_enable) {
  106125. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  106126. + struct device *dev = NULL;
  106127. +
  106128. + if (otg_dev != NULL)
  106129. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  106130. +
  106131. + if (usb_req->length != 0 &&
  106132. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  106133. + dma_addr = dma_map_single(dev, usb_req->buf,
  106134. + usb_req->length,
  106135. + ep->dwc_ep.is_in ?
  106136. + DMA_TO_DEVICE:
  106137. + DMA_FROM_DEVICE);
  106138. + }
  106139. + }
  106140. +#endif
  106141. +
  106142. +#ifdef DWC_UTE_PER_IO
  106143. + if (is_isoc_ep == 1) {
  106144. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  106145. + usb_req->length, usb_req->zero, usb_req,
  106146. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  106147. + if (retval)
  106148. + return -EINVAL;
  106149. +
  106150. + return 0;
  106151. + }
  106152. +#endif
  106153. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  106154. + usb_req->length, usb_req->zero, usb_req,
  106155. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  106156. + if (retval) {
  106157. + return -EINVAL;
  106158. + }
  106159. +
  106160. + return 0;
  106161. +}
  106162. +
  106163. +/**
  106164. + * This function cancels an I/O request from an EP.
  106165. + */
  106166. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  106167. +{
  106168. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  106169. +
  106170. + if (!usb_ep || !usb_req) {
  106171. + DWC_WARN("bad argument\n");
  106172. + return -EINVAL;
  106173. + }
  106174. + if (!gadget_wrapper->driver ||
  106175. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  106176. + DWC_WARN("bogus device state\n");
  106177. + return -ESHUTDOWN;
  106178. + }
  106179. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  106180. + return -EINVAL;
  106181. + }
  106182. +
  106183. + return 0;
  106184. +}
  106185. +
  106186. +/**
  106187. + * usb_ep_set_halt stalls an endpoint.
  106188. + *
  106189. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  106190. + * toggle.
  106191. + *
  106192. + * Both of these functions are implemented with the same underlying
  106193. + * function. The behavior depends on the value argument.
  106194. + *
  106195. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  106196. + * @param[in] value
  106197. + * - 0 means clear_halt.
  106198. + * - 1 means set_halt,
  106199. + * - 2 means clear stall lock flag.
  106200. + * - 3 means set stall lock flag.
  106201. + */
  106202. +static int ep_halt(struct usb_ep *usb_ep, int value)
  106203. +{
  106204. + int retval = 0;
  106205. +
  106206. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  106207. +
  106208. + if (!usb_ep) {
  106209. + DWC_WARN("bad ep\n");
  106210. + return -EINVAL;
  106211. + }
  106212. +
  106213. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  106214. + if (retval == -DWC_E_AGAIN) {
  106215. + return -EAGAIN;
  106216. + } else if (retval) {
  106217. + retval = -EINVAL;
  106218. + }
  106219. +
  106220. + return retval;
  106221. +}
  106222. +
  106223. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  106224. +#if 0
  106225. +/**
  106226. + * ep_wedge: sets the halt feature and ignores clear requests
  106227. + *
  106228. + * @usb_ep: the endpoint being wedged
  106229. + *
  106230. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  106231. + * requests. If the gadget driver clears the halt status, it will
  106232. + * automatically unwedge the endpoint.
  106233. + *
  106234. + * Returns zero on success, else negative errno. *
  106235. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  106236. + */
  106237. +static int ep_wedge(struct usb_ep *usb_ep)
  106238. +{
  106239. + int retval = 0;
  106240. +
  106241. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  106242. +
  106243. + if (!usb_ep) {
  106244. + DWC_WARN("bad ep\n");
  106245. + return -EINVAL;
  106246. + }
  106247. +
  106248. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  106249. + if (retval == -DWC_E_AGAIN) {
  106250. + retval = -EAGAIN;
  106251. + } else if (retval) {
  106252. + retval = -EINVAL;
  106253. + }
  106254. +
  106255. + return retval;
  106256. +}
  106257. +#endif
  106258. +
  106259. +#ifdef DWC_EN_ISOC
  106260. +/**
  106261. + * This function is used to submit an ISOC Transfer Request to an EP.
  106262. + *
  106263. + * - Every time a sync period completes the request's completion callback
  106264. + * is called to provide data to the gadget driver.
  106265. + * - Once submitted the request cannot be modified.
  106266. + * - Each request is turned into periodic data packets untill ISO
  106267. + * Transfer is stopped..
  106268. + */
  106269. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  106270. + gfp_t gfp_flags)
  106271. +{
  106272. + int retval = 0;
  106273. +
  106274. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  106275. + DWC_WARN("bad params\n");
  106276. + return -EINVAL;
  106277. + }
  106278. +
  106279. + if (!usb_ep) {
  106280. + DWC_PRINTF("bad params\n");
  106281. + return -EINVAL;
  106282. + }
  106283. +
  106284. + req->status = -EINPROGRESS;
  106285. +
  106286. + retval =
  106287. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  106288. + req->buf1, req->dma0, req->dma1,
  106289. + req->sync_frame, req->data_pattern_frame,
  106290. + req->data_per_frame,
  106291. + req->
  106292. + flags & USB_REQ_ISO_ASAP ? -1 :
  106293. + req->start_frame, req->buf_proc_intrvl,
  106294. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  106295. +
  106296. + if (retval) {
  106297. + return -EINVAL;
  106298. + }
  106299. +
  106300. + return retval;
  106301. +}
  106302. +
  106303. +/**
  106304. + * This function stops ISO EP Periodic Data Transfer.
  106305. + */
  106306. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  106307. +{
  106308. + int retval = 0;
  106309. + if (!usb_ep) {
  106310. + DWC_WARN("bad ep\n");
  106311. + }
  106312. +
  106313. + if (!gadget_wrapper->driver ||
  106314. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  106315. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  106316. + gadget_wrapper->gadget.speed);
  106317. + DWC_WARN("bogus device state\n");
  106318. + }
  106319. +
  106320. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  106321. + if (retval) {
  106322. + retval = -EINVAL;
  106323. + }
  106324. +
  106325. + return retval;
  106326. +}
  106327. +
  106328. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  106329. + int packets, gfp_t gfp_flags)
  106330. +{
  106331. + struct usb_iso_request *pReq = NULL;
  106332. + uint32_t req_size;
  106333. +
  106334. + req_size = sizeof(struct usb_iso_request);
  106335. + req_size +=
  106336. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  106337. +
  106338. + pReq = kmalloc(req_size, gfp_flags);
  106339. + if (!pReq) {
  106340. + DWC_WARN("Can't allocate Iso Request\n");
  106341. + return 0;
  106342. + }
  106343. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  106344. +
  106345. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  106346. +
  106347. + return pReq;
  106348. +}
  106349. +
  106350. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  106351. +{
  106352. + kfree(req);
  106353. +}
  106354. +
  106355. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  106356. + .ep_ops = {
  106357. + .enable = ep_enable,
  106358. + .disable = ep_disable,
  106359. +
  106360. + .alloc_request = dwc_otg_pcd_alloc_request,
  106361. + .free_request = dwc_otg_pcd_free_request,
  106362. +
  106363. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106364. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  106365. + .free_buffer = dwc_otg_pcd_free_buffer,
  106366. +#endif
  106367. +
  106368. + .queue = ep_queue,
  106369. + .dequeue = ep_dequeue,
  106370. +
  106371. + .set_halt = ep_halt,
  106372. + .fifo_status = 0,
  106373. + .fifo_flush = 0,
  106374. + },
  106375. + .iso_ep_start = iso_ep_start,
  106376. + .iso_ep_stop = iso_ep_stop,
  106377. + .alloc_iso_request = alloc_iso_request,
  106378. + .free_iso_request = free_iso_request,
  106379. +};
  106380. +
  106381. +#else
  106382. +
  106383. + int (*enable) (struct usb_ep *ep,
  106384. + const struct usb_endpoint_descriptor *desc);
  106385. + int (*disable) (struct usb_ep *ep);
  106386. +
  106387. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  106388. + gfp_t gfp_flags);
  106389. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  106390. +
  106391. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  106392. + gfp_t gfp_flags);
  106393. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  106394. +
  106395. + int (*set_halt) (struct usb_ep *ep, int value);
  106396. + int (*set_wedge) (struct usb_ep *ep);
  106397. +
  106398. + int (*fifo_status) (struct usb_ep *ep);
  106399. + void (*fifo_flush) (struct usb_ep *ep);
  106400. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  106401. + .enable = ep_enable,
  106402. + .disable = ep_disable,
  106403. +
  106404. + .alloc_request = dwc_otg_pcd_alloc_request,
  106405. + .free_request = dwc_otg_pcd_free_request,
  106406. +
  106407. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  106408. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  106409. + .free_buffer = dwc_otg_pcd_free_buffer,
  106410. +#else
  106411. + /* .set_wedge = ep_wedge, */
  106412. + .set_wedge = NULL, /* uses set_halt instead */
  106413. +#endif
  106414. +
  106415. + .queue = ep_queue,
  106416. + .dequeue = ep_dequeue,
  106417. +
  106418. + .set_halt = ep_halt,
  106419. + .fifo_status = 0,
  106420. + .fifo_flush = 0,
  106421. +
  106422. +};
  106423. +
  106424. +#endif /* _EN_ISOC_ */
  106425. +/* Gadget Operations */
  106426. +/**
  106427. + * The following gadget operations will be implemented in the DWC_otg
  106428. + * PCD. Functions in the API that are not described below are not
  106429. + * implemented.
  106430. + *
  106431. + * The Gadget API provides wrapper functions for each of the function
  106432. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  106433. + * wrapper function, which then calls the underlying PCD function. The
  106434. + * following sections are named according to the wrapper functions
  106435. + * (except for ioctl, which doesn't have a wrapper function). Within
  106436. + * each section, the corresponding DWC_otg PCD function name is
  106437. + * specified.
  106438. + *
  106439. + */
  106440. +
  106441. +/**
  106442. + *Gets the USB Frame number of the last SOF.
  106443. + */
  106444. +static int get_frame_number(struct usb_gadget *gadget)
  106445. +{
  106446. + struct gadget_wrapper *d;
  106447. +
  106448. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  106449. +
  106450. + if (gadget == 0) {
  106451. + return -ENODEV;
  106452. + }
  106453. +
  106454. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106455. + return dwc_otg_pcd_get_frame_number(d->pcd);
  106456. +}
  106457. +
  106458. +#ifdef CONFIG_USB_DWC_OTG_LPM
  106459. +static int test_lpm_enabled(struct usb_gadget *gadget)
  106460. +{
  106461. + struct gadget_wrapper *d;
  106462. +
  106463. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106464. +
  106465. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  106466. +}
  106467. +#endif
  106468. +
  106469. +/**
  106470. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  106471. + * session is in progress. If a session is already in progress, but
  106472. + * the device is suspended, remote wakeup signaling is started.
  106473. + *
  106474. + */
  106475. +static int wakeup(struct usb_gadget *gadget)
  106476. +{
  106477. + struct gadget_wrapper *d;
  106478. +
  106479. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  106480. +
  106481. + if (gadget == 0) {
  106482. + return -ENODEV;
  106483. + } else {
  106484. + d = container_of(gadget, struct gadget_wrapper, gadget);
  106485. + }
  106486. + dwc_otg_pcd_wakeup(d->pcd);
  106487. + return 0;
  106488. +}
  106489. +
  106490. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  106491. + .get_frame = get_frame_number,
  106492. + .wakeup = wakeup,
  106493. +#ifdef CONFIG_USB_DWC_OTG_LPM
  106494. + .lpm_support = test_lpm_enabled,
  106495. +#endif
  106496. + // current versions must always be self-powered
  106497. +};
  106498. +
  106499. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  106500. +{
  106501. + int retval = -DWC_E_NOT_SUPPORTED;
  106502. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  106503. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  106504. + (struct usb_ctrlrequest
  106505. + *)bytes);
  106506. + }
  106507. +
  106508. + if (retval == -ENOTSUPP) {
  106509. + retval = -DWC_E_NOT_SUPPORTED;
  106510. + } else if (retval < 0) {
  106511. + retval = -DWC_E_INVALID;
  106512. + }
  106513. +
  106514. + return retval;
  106515. +}
  106516. +
  106517. +#ifdef DWC_EN_ISOC
  106518. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106519. + void *req_handle, int proc_buf_num)
  106520. +{
  106521. + int i, packet_count;
  106522. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  106523. + struct usb_iso_request *iso_req = req_handle;
  106524. +
  106525. + if (proc_buf_num) {
  106526. + iso_packet = iso_req->iso_packet_desc1;
  106527. + } else {
  106528. + iso_packet = iso_req->iso_packet_desc0;
  106529. + }
  106530. + packet_count =
  106531. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  106532. + for (i = 0; i < packet_count; ++i) {
  106533. + int status;
  106534. + int actual;
  106535. + int offset;
  106536. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  106537. + i, &status, &actual, &offset);
  106538. + switch (status) {
  106539. + case -DWC_E_NO_DATA:
  106540. + status = -ENODATA;
  106541. + break;
  106542. + default:
  106543. + if (status) {
  106544. + DWC_PRINTF("unknown status in isoc packet\n");
  106545. + }
  106546. +
  106547. + }
  106548. + iso_packet[i].status = status;
  106549. + iso_packet[i].offset = offset;
  106550. + iso_packet[i].actual_length = actual;
  106551. + }
  106552. +
  106553. + iso_req->status = 0;
  106554. + iso_req->process_buffer(ep_handle, iso_req);
  106555. +
  106556. + return 0;
  106557. +}
  106558. +#endif /* DWC_EN_ISOC */
  106559. +
  106560. +#ifdef DWC_UTE_PER_IO
  106561. +/**
  106562. + * Copy the contents of the extended request to the Linux usb_request's
  106563. + * extended part and call the gadget's completion.
  106564. + *
  106565. + * @param pcd Pointer to the pcd structure
  106566. + * @param ep_handle Void pointer to the usb_ep structure
  106567. + * @param req_handle Void pointer to the usb_request structure
  106568. + * @param status Request status returned from the portable logic
  106569. + * @param ereq_port Void pointer to the extended request structure
  106570. + * created in the the portable part that contains the
  106571. + * results of the processed iso packets.
  106572. + */
  106573. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106574. + void *req_handle, int32_t status, void *ereq_port)
  106575. +{
  106576. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  106577. + struct dwc_iso_xreq_port *ereqport = NULL;
  106578. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  106579. + int i;
  106580. + struct usb_request *req;
  106581. + //struct dwc_ute_iso_packet_descriptor *
  106582. + //int status = 0;
  106583. +
  106584. + req = (struct usb_request *)req_handle;
  106585. + ereqorg = &req->ext_req;
  106586. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  106587. + desc_org = ereqorg->per_io_frame_descs;
  106588. +
  106589. + if (req && req->complete) {
  106590. + /* Copy the request data from the portable logic to our request */
  106591. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  106592. + desc_org[i].actual_length =
  106593. + ereqport->per_io_frame_descs[i].actual_length;
  106594. + desc_org[i].status =
  106595. + ereqport->per_io_frame_descs[i].status;
  106596. + }
  106597. +
  106598. + switch (status) {
  106599. + case -DWC_E_SHUTDOWN:
  106600. + req->status = -ESHUTDOWN;
  106601. + break;
  106602. + case -DWC_E_RESTART:
  106603. + req->status = -ECONNRESET;
  106604. + break;
  106605. + case -DWC_E_INVALID:
  106606. + req->status = -EINVAL;
  106607. + break;
  106608. + case -DWC_E_TIMEOUT:
  106609. + req->status = -ETIMEDOUT;
  106610. + break;
  106611. + default:
  106612. + req->status = status;
  106613. + }
  106614. +
  106615. + /* And call the gadget's completion */
  106616. + req->complete(ep_handle, req);
  106617. + }
  106618. +
  106619. + return 0;
  106620. +}
  106621. +#endif /* DWC_UTE_PER_IO */
  106622. +
  106623. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  106624. + void *req_handle, int32_t status, uint32_t actual)
  106625. +{
  106626. + struct usb_request *req = (struct usb_request *)req_handle;
  106627. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  106628. + struct dwc_otg_pcd_ep *ep = NULL;
  106629. +#endif
  106630. +
  106631. + if (req && req->complete) {
  106632. + switch (status) {
  106633. + case -DWC_E_SHUTDOWN:
  106634. + req->status = -ESHUTDOWN;
  106635. + break;
  106636. + case -DWC_E_RESTART:
  106637. + req->status = -ECONNRESET;
  106638. + break;
  106639. + case -DWC_E_INVALID:
  106640. + req->status = -EINVAL;
  106641. + break;
  106642. + case -DWC_E_TIMEOUT:
  106643. + req->status = -ETIMEDOUT;
  106644. + break;
  106645. + default:
  106646. + req->status = status;
  106647. +
  106648. + }
  106649. +
  106650. + req->actual = actual;
  106651. + DWC_SPINUNLOCK(pcd->lock);
  106652. + req->complete(ep_handle, req);
  106653. + DWC_SPINLOCK(pcd->lock);
  106654. + }
  106655. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  106656. + ep = ep_from_handle(pcd, ep_handle);
  106657. + if (GET_CORE_IF(pcd)->dma_enable) {
  106658. + if (req->length != 0) {
  106659. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  106660. + struct device *dev = NULL;
  106661. +
  106662. + if (otg_dev != NULL)
  106663. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  106664. +
  106665. + dma_unmap_single(dev, req->dma, req->length,
  106666. + ep->dwc_ep.is_in ?
  106667. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  106668. + }
  106669. + }
  106670. +#endif
  106671. +
  106672. + return 0;
  106673. +}
  106674. +
  106675. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  106676. +{
  106677. + gadget_wrapper->gadget.speed = speed;
  106678. + return 0;
  106679. +}
  106680. +
  106681. +static int _disconnect(dwc_otg_pcd_t * pcd)
  106682. +{
  106683. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  106684. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  106685. + }
  106686. + return 0;
  106687. +}
  106688. +
  106689. +static int _resume(dwc_otg_pcd_t * pcd)
  106690. +{
  106691. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  106692. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  106693. + }
  106694. +
  106695. + return 0;
  106696. +}
  106697. +
  106698. +static int _suspend(dwc_otg_pcd_t * pcd)
  106699. +{
  106700. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  106701. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  106702. + }
  106703. + return 0;
  106704. +}
  106705. +
  106706. +/**
  106707. + * This function updates the otg values in the gadget structure.
  106708. + */
  106709. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  106710. +{
  106711. +
  106712. + if (!gadget_wrapper->gadget.is_otg)
  106713. + return 0;
  106714. +
  106715. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  106716. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  106717. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  106718. + return 0;
  106719. +}
  106720. +
  106721. +static int _reset(dwc_otg_pcd_t * pcd)
  106722. +{
  106723. + return 0;
  106724. +}
  106725. +
  106726. +#ifdef DWC_UTE_CFI
  106727. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  106728. +{
  106729. + int retval = -DWC_E_INVALID;
  106730. + if (gadget_wrapper->driver->cfi_feature_setup) {
  106731. + retval =
  106732. + gadget_wrapper->driver->
  106733. + cfi_feature_setup(&gadget_wrapper->gadget,
  106734. + (struct cfi_usb_ctrlrequest *)cfi_req);
  106735. + }
  106736. +
  106737. + return retval;
  106738. +}
  106739. +#endif
  106740. +
  106741. +static const struct dwc_otg_pcd_function_ops fops = {
  106742. + .complete = _complete,
  106743. +#ifdef DWC_EN_ISOC
  106744. + .isoc_complete = _isoc_complete,
  106745. +#endif
  106746. + .setup = _setup,
  106747. + .disconnect = _disconnect,
  106748. + .connect = _connect,
  106749. + .resume = _resume,
  106750. + .suspend = _suspend,
  106751. + .hnp_changed = _hnp_changed,
  106752. + .reset = _reset,
  106753. +#ifdef DWC_UTE_CFI
  106754. + .cfi_setup = _cfi_setup,
  106755. +#endif
  106756. +#ifdef DWC_UTE_PER_IO
  106757. + .xisoc_complete = _xisoc_complete,
  106758. +#endif
  106759. +};
  106760. +
  106761. +/**
  106762. + * This function is the top level PCD interrupt handler.
  106763. + */
  106764. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  106765. +{
  106766. + dwc_otg_pcd_t *pcd = dev;
  106767. + int32_t retval = IRQ_NONE;
  106768. +
  106769. + retval = dwc_otg_pcd_handle_intr(pcd);
  106770. + if (retval != 0) {
  106771. + S3C2410X_CLEAR_EINTPEND();
  106772. + }
  106773. + return IRQ_RETVAL(retval);
  106774. +}
  106775. +
  106776. +/**
  106777. + * This function initialized the usb_ep structures to there default
  106778. + * state.
  106779. + *
  106780. + * @param d Pointer on gadget_wrapper.
  106781. + */
  106782. +void gadget_add_eps(struct gadget_wrapper *d)
  106783. +{
  106784. + static const char *names[] = {
  106785. +
  106786. + "ep0",
  106787. + "ep1in",
  106788. + "ep2in",
  106789. + "ep3in",
  106790. + "ep4in",
  106791. + "ep5in",
  106792. + "ep6in",
  106793. + "ep7in",
  106794. + "ep8in",
  106795. + "ep9in",
  106796. + "ep10in",
  106797. + "ep11in",
  106798. + "ep12in",
  106799. + "ep13in",
  106800. + "ep14in",
  106801. + "ep15in",
  106802. + "ep1out",
  106803. + "ep2out",
  106804. + "ep3out",
  106805. + "ep4out",
  106806. + "ep5out",
  106807. + "ep6out",
  106808. + "ep7out",
  106809. + "ep8out",
  106810. + "ep9out",
  106811. + "ep10out",
  106812. + "ep11out",
  106813. + "ep12out",
  106814. + "ep13out",
  106815. + "ep14out",
  106816. + "ep15out"
  106817. + };
  106818. +
  106819. + int i;
  106820. + struct usb_ep *ep;
  106821. + int8_t dev_endpoints;
  106822. +
  106823. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  106824. +
  106825. + INIT_LIST_HEAD(&d->gadget.ep_list);
  106826. + d->gadget.ep0 = &d->ep0;
  106827. + d->gadget.speed = USB_SPEED_UNKNOWN;
  106828. +
  106829. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  106830. +
  106831. + /**
  106832. + * Initialize the EP0 structure.
  106833. + */
  106834. + ep = &d->ep0;
  106835. +
  106836. + /* Init the usb_ep structure. */
  106837. + ep->name = names[0];
  106838. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106839. +
  106840. + /**
  106841. + * @todo NGS: What should the max packet size be set to
  106842. + * here? Before EP type is set?
  106843. + */
  106844. + ep->maxpacket = MAX_PACKET_SIZE;
  106845. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  106846. +
  106847. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106848. +
  106849. + /**
  106850. + * Initialize the EP structures.
  106851. + */
  106852. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  106853. +
  106854. + for (i = 0; i < dev_endpoints; i++) {
  106855. + ep = &d->in_ep[i];
  106856. +
  106857. + /* Init the usb_ep structure. */
  106858. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  106859. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106860. +
  106861. + /**
  106862. + * @todo NGS: What should the max packet size be set to
  106863. + * here? Before EP type is set?
  106864. + */
  106865. + ep->maxpacket = MAX_PACKET_SIZE;
  106866. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106867. + }
  106868. +
  106869. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  106870. +
  106871. + for (i = 0; i < dev_endpoints; i++) {
  106872. + ep = &d->out_ep[i];
  106873. +
  106874. + /* Init the usb_ep structure. */
  106875. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  106876. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  106877. +
  106878. + /**
  106879. + * @todo NGS: What should the max packet size be set to
  106880. + * here? Before EP type is set?
  106881. + */
  106882. + ep->maxpacket = MAX_PACKET_SIZE;
  106883. +
  106884. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  106885. + }
  106886. +
  106887. + /* remove ep0 from the list. There is a ep0 pointer. */
  106888. + list_del_init(&d->ep0.ep_list);
  106889. +
  106890. + d->ep0.maxpacket = MAX_EP0_SIZE;
  106891. +}
  106892. +
  106893. +/**
  106894. + * This function releases the Gadget device.
  106895. + * required by device_unregister().
  106896. + *
  106897. + * @todo Should this do something? Should it free the PCD?
  106898. + */
  106899. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  106900. +{
  106901. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  106902. +}
  106903. +
  106904. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  106905. +{
  106906. + static char pcd_name[] = "dwc_otg_pcd";
  106907. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106908. + struct gadget_wrapper *d;
  106909. + int retval;
  106910. +
  106911. + d = DWC_ALLOC(sizeof(*d));
  106912. + if (d == NULL) {
  106913. + return NULL;
  106914. + }
  106915. +
  106916. + memset(d, 0, sizeof(*d));
  106917. +
  106918. + d->gadget.name = pcd_name;
  106919. + d->pcd = otg_dev->pcd;
  106920. +
  106921. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  106922. + strcpy(d->gadget.dev.bus_id, "gadget");
  106923. +#else
  106924. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  106925. +#endif
  106926. +
  106927. + d->gadget.dev.parent = &_dev->dev;
  106928. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  106929. + d->gadget.ops = &dwc_otg_pcd_ops;
  106930. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  106931. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  106932. +
  106933. + d->driver = 0;
  106934. + /* Register the gadget device */
  106935. + retval = device_register(&d->gadget.dev);
  106936. + if (retval != 0) {
  106937. + DWC_ERROR("device_register failed\n");
  106938. + DWC_FREE(d);
  106939. + return NULL;
  106940. + }
  106941. +
  106942. + return d;
  106943. +}
  106944. +
  106945. +static void free_wrapper(struct gadget_wrapper *d)
  106946. +{
  106947. + if (d->driver) {
  106948. + /* should have been done already by driver model core */
  106949. + DWC_WARN("driver '%s' is still registered\n",
  106950. + d->driver->driver.name);
  106951. + usb_gadget_unregister_driver(d->driver);
  106952. + }
  106953. +
  106954. + device_unregister(&d->gadget.dev);
  106955. + DWC_FREE(d);
  106956. +}
  106957. +
  106958. +/**
  106959. + * This function initialized the PCD portion of the driver.
  106960. + *
  106961. + */
  106962. +int pcd_init(dwc_bus_dev_t *_dev)
  106963. +{
  106964. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  106965. + int retval = 0;
  106966. +
  106967. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  106968. +
  106969. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  106970. +
  106971. + if (!otg_dev->pcd) {
  106972. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  106973. + return -ENOMEM;
  106974. + }
  106975. +
  106976. + otg_dev->pcd->otg_dev = otg_dev;
  106977. + gadget_wrapper = alloc_wrapper(_dev);
  106978. +
  106979. + /*
  106980. + * Initialize EP structures
  106981. + */
  106982. + gadget_add_eps(gadget_wrapper);
  106983. + /*
  106984. + * Setup interupt handler
  106985. + */
  106986. +#ifdef PLATFORM_INTERFACE
  106987. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  106988. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  106989. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  106990. + IRQF_SHARED, gadget_wrapper->gadget.name,
  106991. + otg_dev->pcd);
  106992. + if (retval != 0) {
  106993. + DWC_ERROR("request of irq%d failed\n",
  106994. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  106995. + free_wrapper(gadget_wrapper);
  106996. + return -EBUSY;
  106997. + }
  106998. +#else
  106999. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  107000. + _dev->irq);
  107001. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  107002. + IRQF_SHARED | IRQF_DISABLED,
  107003. + gadget_wrapper->gadget.name, otg_dev->pcd);
  107004. + if (retval != 0) {
  107005. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  107006. + free_wrapper(gadget_wrapper);
  107007. + return -EBUSY;
  107008. + }
  107009. +#endif
  107010. +
  107011. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  107012. +
  107013. + return retval;
  107014. +}
  107015. +
  107016. +/**
  107017. + * Cleanup the PCD.
  107018. + */
  107019. +void pcd_remove(dwc_bus_dev_t *_dev)
  107020. +{
  107021. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  107022. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  107023. +
  107024. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  107025. +
  107026. + /*
  107027. + * Free the IRQ
  107028. + */
  107029. +#ifdef PLATFORM_INTERFACE
  107030. + free_irq(platform_get_irq(_dev, 0), pcd);
  107031. +#else
  107032. + free_irq(_dev->irq, pcd);
  107033. +#endif
  107034. + dwc_otg_pcd_remove(otg_dev->pcd);
  107035. + free_wrapper(gadget_wrapper);
  107036. + otg_dev->pcd = 0;
  107037. +}
  107038. +
  107039. +/**
  107040. + * This function registers a gadget driver with the PCD.
  107041. + *
  107042. + * When a driver is successfully registered, it will receive control
  107043. + * requests including set_configuration(), which enables non-control
  107044. + * requests. then usb traffic follows until a disconnect is reported.
  107045. + * then a host may connect again, or the driver might get unbound.
  107046. + *
  107047. + * @param driver The driver being registered
  107048. + * @param bind The bind function of gadget driver
  107049. + */
  107050. +
  107051. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  107052. +{
  107053. + int retval;
  107054. +
  107055. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  107056. + driver->driver.name);
  107057. +
  107058. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  107059. + !driver->bind ||
  107060. + !driver->unbind || !driver->disconnect || !driver->setup) {
  107061. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  107062. + return -EINVAL;
  107063. + }
  107064. + if (gadget_wrapper == 0) {
  107065. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  107066. + return -ENODEV;
  107067. + }
  107068. + if (gadget_wrapper->driver != 0) {
  107069. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  107070. + return -EBUSY;
  107071. + }
  107072. +
  107073. + /* hook up the driver */
  107074. + gadget_wrapper->driver = driver;
  107075. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  107076. +
  107077. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  107078. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  107079. + if (retval) {
  107080. + DWC_ERROR("bind to driver %s --> error %d\n",
  107081. + driver->driver.name, retval);
  107082. + gadget_wrapper->driver = 0;
  107083. + gadget_wrapper->gadget.dev.driver = 0;
  107084. + return retval;
  107085. + }
  107086. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  107087. + driver->driver.name);
  107088. + return 0;
  107089. +}
  107090. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  107091. +
  107092. +/**
  107093. + * This function unregisters a gadget driver
  107094. + *
  107095. + * @param driver The driver being unregistered
  107096. + */
  107097. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  107098. +{
  107099. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  107100. +
  107101. + if (gadget_wrapper == 0) {
  107102. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  107103. + -ENODEV);
  107104. + return -ENODEV;
  107105. + }
  107106. + if (driver == 0 || driver != gadget_wrapper->driver) {
  107107. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  107108. + -EINVAL);
  107109. + return -EINVAL;
  107110. + }
  107111. +
  107112. + driver->unbind(&gadget_wrapper->gadget);
  107113. + gadget_wrapper->driver = 0;
  107114. +
  107115. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  107116. + return 0;
  107117. +}
  107118. +
  107119. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  107120. +
  107121. +#endif /* DWC_HOST_ONLY */
  107122. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  107123. --- linux-3.12.38/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  107124. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2015-03-09 10:39:33.222893718 +0100
  107125. @@ -0,0 +1,2550 @@
  107126. +/* ==========================================================================
  107127. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  107128. + * $Revision: #98 $
  107129. + * $Date: 2012/08/10 $
  107130. + * $Change: 2047372 $
  107131. + *
  107132. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  107133. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  107134. + * otherwise expressly agreed to in writing between Synopsys and you.
  107135. + *
  107136. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  107137. + * any End User Software License Agreement or Agreement for Licensed Product
  107138. + * with Synopsys or any supplement thereto. You are permitted to use and
  107139. + * redistribute this Software in source and binary forms, with or without
  107140. + * modification, provided that redistributions of source code must retain this
  107141. + * notice. You may not view, use, disclose, copy or distribute this file or
  107142. + * any information contained herein except pursuant to this license grant from
  107143. + * Synopsys. If you do not agree with this notice, including the disclaimer
  107144. + * below, then you are not authorized to use the Software.
  107145. + *
  107146. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  107147. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  107148. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  107149. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  107150. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  107151. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  107152. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  107153. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  107154. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  107155. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  107156. + * DAMAGE.
  107157. + * ========================================================================== */
  107158. +
  107159. +#ifndef __DWC_OTG_REGS_H__
  107160. +#define __DWC_OTG_REGS_H__
  107161. +
  107162. +#include "dwc_otg_core_if.h"
  107163. +
  107164. +/**
  107165. + * @file
  107166. + *
  107167. + * This file contains the data structures for accessing the DWC_otg core registers.
  107168. + *
  107169. + * The application interfaces with the HS OTG core by reading from and
  107170. + * writing to the Control and Status Register (CSR) space through the
  107171. + * AHB Slave interface. These registers are 32 bits wide, and the
  107172. + * addresses are 32-bit-block aligned.
  107173. + * CSRs are classified as follows:
  107174. + * - Core Global Registers
  107175. + * - Device Mode Registers
  107176. + * - Device Global Registers
  107177. + * - Device Endpoint Specific Registers
  107178. + * - Host Mode Registers
  107179. + * - Host Global Registers
  107180. + * - Host Port CSRs
  107181. + * - Host Channel Specific Registers
  107182. + *
  107183. + * Only the Core Global registers can be accessed in both Device and
  107184. + * Host modes. When the HS OTG core is operating in one mode, either
  107185. + * Device or Host, the application must not access registers from the
  107186. + * other mode. When the core switches from one mode to another, the
  107187. + * registers in the new mode of operation must be reprogrammed as they
  107188. + * would be after a power-on reset.
  107189. + */
  107190. +
  107191. +/****************************************************************************/
  107192. +/** DWC_otg Core registers .
  107193. + * The dwc_otg_core_global_regs structure defines the size
  107194. + * and relative field offsets for the Core Global registers.
  107195. + */
  107196. +typedef struct dwc_otg_core_global_regs {
  107197. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  107198. + volatile uint32_t gotgctl;
  107199. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  107200. + volatile uint32_t gotgint;
  107201. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  107202. + volatile uint32_t gahbcfg;
  107203. +
  107204. +#define DWC_GLBINTRMASK 0x0001
  107205. +#define DWC_DMAENABLE 0x0020
  107206. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  107207. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  107208. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  107209. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  107210. +
  107211. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  107212. + volatile uint32_t gusbcfg;
  107213. + /**Core Reset Register. <i>Offset: 010h</i> */
  107214. + volatile uint32_t grstctl;
  107215. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  107216. + volatile uint32_t gintsts;
  107217. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  107218. + volatile uint32_t gintmsk;
  107219. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  107220. + volatile uint32_t grxstsr;
  107221. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  107222. + volatile uint32_t grxstsp;
  107223. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  107224. + volatile uint32_t grxfsiz;
  107225. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  107226. + volatile uint32_t gnptxfsiz;
  107227. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  107228. + * Only). <i>Offset: 02Ch</i> */
  107229. + volatile uint32_t gnptxsts;
  107230. + /**I2C Access Register. <i>Offset: 030h</i> */
  107231. + volatile uint32_t gi2cctl;
  107232. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  107233. + volatile uint32_t gpvndctl;
  107234. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  107235. + volatile uint32_t ggpio;
  107236. + /**User ID Register. <i>Offset: 03Ch</i> */
  107237. + volatile uint32_t guid;
  107238. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  107239. + volatile uint32_t gsnpsid;
  107240. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  107241. + volatile uint32_t ghwcfg1;
  107242. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  107243. + volatile uint32_t ghwcfg2;
  107244. +#define DWC_SLAVE_ONLY_ARCH 0
  107245. +#define DWC_EXT_DMA_ARCH 1
  107246. +#define DWC_INT_DMA_ARCH 2
  107247. +
  107248. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  107249. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  107250. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  107251. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  107252. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  107253. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  107254. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  107255. +
  107256. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  107257. + volatile uint32_t ghwcfg3;
  107258. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  107259. + volatile uint32_t ghwcfg4;
  107260. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  107261. + volatile uint32_t glpmcfg;
  107262. + /** Global PowerDn Register <i>Offset: 058h</i> */
  107263. + volatile uint32_t gpwrdn;
  107264. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  107265. + volatile uint32_t gdfifocfg;
  107266. + /** ADP Control Register <i>Offset: 060h</i> */
  107267. + volatile uint32_t adpctl;
  107268. + /** Reserved <i>Offset: 064h-0FFh</i> */
  107269. + volatile uint32_t reserved39[39];
  107270. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  107271. + volatile uint32_t hptxfsiz;
  107272. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  107273. + otherwise Device Transmit FIFO#n Register.
  107274. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  107275. + volatile uint32_t dtxfsiz[15];
  107276. +} dwc_otg_core_global_regs_t;
  107277. +
  107278. +/**
  107279. + * This union represents the bit fields of the Core OTG Control
  107280. + * and Status Register (GOTGCTL). Set the bits using the bit
  107281. + * fields then write the <i>d32</i> value to the register.
  107282. + */
  107283. +typedef union gotgctl_data {
  107284. + /** raw register data */
  107285. + uint32_t d32;
  107286. + /** register bits */
  107287. + struct {
  107288. + unsigned sesreqscs:1;
  107289. + unsigned sesreq:1;
  107290. + unsigned vbvalidoven:1;
  107291. + unsigned vbvalidovval:1;
  107292. + unsigned avalidoven:1;
  107293. + unsigned avalidovval:1;
  107294. + unsigned bvalidoven:1;
  107295. + unsigned bvalidovval:1;
  107296. + unsigned hstnegscs:1;
  107297. + unsigned hnpreq:1;
  107298. + unsigned hstsethnpen:1;
  107299. + unsigned devhnpen:1;
  107300. + unsigned reserved12_15:4;
  107301. + unsigned conidsts:1;
  107302. + unsigned dbnctime:1;
  107303. + unsigned asesvld:1;
  107304. + unsigned bsesvld:1;
  107305. + unsigned otgver:1;
  107306. + unsigned reserved1:1;
  107307. + unsigned multvalidbc:5;
  107308. + unsigned chirpen:1;
  107309. + unsigned reserved28_31:4;
  107310. + } b;
  107311. +} gotgctl_data_t;
  107312. +
  107313. +/**
  107314. + * This union represents the bit fields of the Core OTG Interrupt Register
  107315. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  107316. + * value to the register.
  107317. + */
  107318. +typedef union gotgint_data {
  107319. + /** raw register data */
  107320. + uint32_t d32;
  107321. + /** register bits */
  107322. + struct {
  107323. + /** Current Mode */
  107324. + unsigned reserved0_1:2;
  107325. +
  107326. + /** Session End Detected */
  107327. + unsigned sesenddet:1;
  107328. +
  107329. + unsigned reserved3_7:5;
  107330. +
  107331. + /** Session Request Success Status Change */
  107332. + unsigned sesreqsucstschng:1;
  107333. + /** Host Negotiation Success Status Change */
  107334. + unsigned hstnegsucstschng:1;
  107335. +
  107336. + unsigned reserved10_16:7;
  107337. +
  107338. + /** Host Negotiation Detected */
  107339. + unsigned hstnegdet:1;
  107340. + /** A-Device Timeout Change */
  107341. + unsigned adevtoutchng:1;
  107342. + /** Debounce Done */
  107343. + unsigned debdone:1;
  107344. + /** Multi-Valued input changed */
  107345. + unsigned mvic:1;
  107346. +
  107347. + unsigned reserved31_21:11;
  107348. +
  107349. + } b;
  107350. +} gotgint_data_t;
  107351. +
  107352. +/**
  107353. + * This union represents the bit fields of the Core AHB Configuration
  107354. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  107355. + * write the <i>d32</i> value to the register.
  107356. + */
  107357. +typedef union gahbcfg_data {
  107358. + /** raw register data */
  107359. + uint32_t d32;
  107360. + /** register bits */
  107361. + struct {
  107362. + unsigned glblintrmsk:1;
  107363. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  107364. +
  107365. + unsigned hburstlen:4;
  107366. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  107367. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  107368. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  107369. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  107370. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  107371. +
  107372. + unsigned dmaenable:1;
  107373. +#define DWC_GAHBCFG_DMAENABLE 1
  107374. + unsigned reserved:1;
  107375. + unsigned nptxfemplvl_txfemplvl:1;
  107376. + unsigned ptxfemplvl:1;
  107377. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  107378. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  107379. + unsigned reserved9_20:12;
  107380. + unsigned remmemsupp:1;
  107381. + unsigned notialldmawrit:1;
  107382. + unsigned ahbsingle:1;
  107383. + unsigned reserved24_31:8;
  107384. + } b;
  107385. +} gahbcfg_data_t;
  107386. +
  107387. +/**
  107388. + * This union represents the bit fields of the Core USB Configuration
  107389. + * Register (GUSBCFG). Set the bits using the bit fields then write
  107390. + * the <i>d32</i> value to the register.
  107391. + */
  107392. +typedef union gusbcfg_data {
  107393. + /** raw register data */
  107394. + uint32_t d32;
  107395. + /** register bits */
  107396. + struct {
  107397. + unsigned toutcal:3;
  107398. + unsigned phyif:1;
  107399. + unsigned ulpi_utmi_sel:1;
  107400. + unsigned fsintf:1;
  107401. + unsigned physel:1;
  107402. + unsigned ddrsel:1;
  107403. + unsigned srpcap:1;
  107404. + unsigned hnpcap:1;
  107405. + unsigned usbtrdtim:4;
  107406. + unsigned reserved1:1;
  107407. + unsigned phylpwrclksel:1;
  107408. + unsigned otgutmifssel:1;
  107409. + unsigned ulpi_fsls:1;
  107410. + unsigned ulpi_auto_res:1;
  107411. + unsigned ulpi_clk_sus_m:1;
  107412. + unsigned ulpi_ext_vbus_drv:1;
  107413. + unsigned ulpi_int_vbus_indicator:1;
  107414. + unsigned term_sel_dl_pulse:1;
  107415. + unsigned indicator_complement:1;
  107416. + unsigned indicator_pass_through:1;
  107417. + unsigned ulpi_int_prot_dis:1;
  107418. + unsigned ic_usb_cap:1;
  107419. + unsigned ic_traffic_pull_remove:1;
  107420. + unsigned tx_end_delay:1;
  107421. + unsigned force_host_mode:1;
  107422. + unsigned force_dev_mode:1;
  107423. + unsigned reserved31:1;
  107424. + } b;
  107425. +} gusbcfg_data_t;
  107426. +
  107427. +/**
  107428. + * This union represents the bit fields of the Core Reset Register
  107429. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  107430. + * <i>d32</i> value to the register.
  107431. + */
  107432. +typedef union grstctl_data {
  107433. + /** raw register data */
  107434. + uint32_t d32;
  107435. + /** register bits */
  107436. + struct {
  107437. + /** Core Soft Reset (CSftRst) (Device and Host)
  107438. + *
  107439. + * The application can flush the control logic in the
  107440. + * entire core using this bit. This bit resets the
  107441. + * pipelines in the AHB Clock domain as well as the
  107442. + * PHY Clock domain.
  107443. + *
  107444. + * The state machines are reset to an IDLE state, the
  107445. + * control bits in the CSRs are cleared, all the
  107446. + * transmit FIFOs and the receive FIFO are flushed.
  107447. + *
  107448. + * The status mask bits that control the generation of
  107449. + * the interrupt, are cleared, to clear the
  107450. + * interrupt. The interrupt status bits are not
  107451. + * cleared, so the application can get the status of
  107452. + * any events that occurred in the core after it has
  107453. + * set this bit.
  107454. + *
  107455. + * Any transactions on the AHB are terminated as soon
  107456. + * as possible following the protocol. Any
  107457. + * transactions on the USB are terminated immediately.
  107458. + *
  107459. + * The configuration settings in the CSRs are
  107460. + * unchanged, so the software doesn't have to
  107461. + * reprogram these registers (Device
  107462. + * Configuration/Host Configuration/Core System
  107463. + * Configuration/Core PHY Configuration).
  107464. + *
  107465. + * The application can write to this bit, any time it
  107466. + * wants to reset the core. This is a self clearing
  107467. + * bit and the core clears this bit after all the
  107468. + * necessary logic is reset in the core, which may
  107469. + * take several clocks, depending on the current state
  107470. + * of the core.
  107471. + */
  107472. + unsigned csftrst:1;
  107473. + /** Hclk Soft Reset
  107474. + *
  107475. + * The application uses this bit to reset the control logic in
  107476. + * the AHB clock domain. Only AHB clock domain pipelines are
  107477. + * reset.
  107478. + */
  107479. + unsigned hsftrst:1;
  107480. + /** Host Frame Counter Reset (Host Only)<br>
  107481. + *
  107482. + * The application can reset the (micro)frame number
  107483. + * counter inside the core, using this bit. When the
  107484. + * (micro)frame counter is reset, the subsequent SOF
  107485. + * sent out by the core, will have a (micro)frame
  107486. + * number of 0.
  107487. + */
  107488. + unsigned hstfrm:1;
  107489. + /** In Token Sequence Learning Queue Flush
  107490. + * (INTknQFlsh) (Device Only)
  107491. + */
  107492. + unsigned intknqflsh:1;
  107493. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  107494. + *
  107495. + * The application can flush the entire Receive FIFO
  107496. + * using this bit. The application must first
  107497. + * ensure that the core is not in the middle of a
  107498. + * transaction. The application should write into
  107499. + * this bit, only after making sure that neither the
  107500. + * DMA engine is reading from the RxFIFO nor the MAC
  107501. + * is writing the data in to the FIFO. The
  107502. + * application should wait until the bit is cleared
  107503. + * before performing any other operations. This bit
  107504. + * will takes 8 clocks (slowest of PHY or AHB clock)
  107505. + * to clear.
  107506. + */
  107507. + unsigned rxfflsh:1;
  107508. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  107509. + *
  107510. + * This bit is used to selectively flush a single or
  107511. + * all transmit FIFOs. The application must first
  107512. + * ensure that the core is not in the middle of a
  107513. + * transaction. The application should write into
  107514. + * this bit, only after making sure that neither the
  107515. + * DMA engine is writing into the TxFIFO nor the MAC
  107516. + * is reading the data out of the FIFO. The
  107517. + * application should wait until the core clears this
  107518. + * bit, before performing any operations. This bit
  107519. + * will takes 8 clocks (slowest of PHY or AHB clock)
  107520. + * to clear.
  107521. + */
  107522. + unsigned txfflsh:1;
  107523. +
  107524. + /** TxFIFO Number (TxFNum) (Device and Host).
  107525. + *
  107526. + * This is the FIFO number which needs to be flushed,
  107527. + * using the TxFIFO Flush bit. This field should not
  107528. + * be changed until the TxFIFO Flush bit is cleared by
  107529. + * the core.
  107530. + * - 0x0 : Non Periodic TxFIFO Flush
  107531. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  107532. + * or Periodic TxFIFO in host mode
  107533. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  107534. + * - ...
  107535. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  107536. + * - 0x10: Flush all the Transmit NonPeriodic and
  107537. + * Transmit Periodic FIFOs in the core
  107538. + */
  107539. + unsigned txfnum:5;
  107540. + /** Reserved */
  107541. + unsigned reserved11_29:19;
  107542. + /** DMA Request Signal. Indicated DMA request is in
  107543. + * probress. Used for debug purpose. */
  107544. + unsigned dmareq:1;
  107545. + /** AHB Master Idle. Indicates the AHB Master State
  107546. + * Machine is in IDLE condition. */
  107547. + unsigned ahbidle:1;
  107548. + } b;
  107549. +} grstctl_t;
  107550. +
  107551. +/**
  107552. + * This union represents the bit fields of the Core Interrupt Mask
  107553. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  107554. + * write the <i>d32</i> value to the register.
  107555. + */
  107556. +typedef union gintmsk_data {
  107557. + /** raw register data */
  107558. + uint32_t d32;
  107559. + /** register bits */
  107560. + struct {
  107561. + unsigned reserved0:1;
  107562. + unsigned modemismatch:1;
  107563. + unsigned otgintr:1;
  107564. + unsigned sofintr:1;
  107565. + unsigned rxstsqlvl:1;
  107566. + unsigned nptxfempty:1;
  107567. + unsigned ginnakeff:1;
  107568. + unsigned goutnakeff:1;
  107569. + unsigned ulpickint:1;
  107570. + unsigned i2cintr:1;
  107571. + unsigned erlysuspend:1;
  107572. + unsigned usbsuspend:1;
  107573. + unsigned usbreset:1;
  107574. + unsigned enumdone:1;
  107575. + unsigned isooutdrop:1;
  107576. + unsigned eopframe:1;
  107577. + unsigned restoredone:1;
  107578. + unsigned epmismatch:1;
  107579. + unsigned inepintr:1;
  107580. + unsigned outepintr:1;
  107581. + unsigned incomplisoin:1;
  107582. + unsigned incomplisoout:1;
  107583. + unsigned fetsusp:1;
  107584. + unsigned resetdet:1;
  107585. + unsigned portintr:1;
  107586. + unsigned hcintr:1;
  107587. + unsigned ptxfempty:1;
  107588. + unsigned lpmtranrcvd:1;
  107589. + unsigned conidstschng:1;
  107590. + unsigned disconnect:1;
  107591. + unsigned sessreqintr:1;
  107592. + unsigned wkupintr:1;
  107593. + } b;
  107594. +} gintmsk_data_t;
  107595. +/**
  107596. + * This union represents the bit fields of the Core Interrupt Register
  107597. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  107598. + * <i>d32</i> value to the register.
  107599. + */
  107600. +typedef union gintsts_data {
  107601. + /** raw register data */
  107602. + uint32_t d32;
  107603. +#define DWC_SOF_INTR_MASK 0x0008
  107604. + /** register bits */
  107605. + struct {
  107606. +#define DWC_HOST_MODE 1
  107607. + unsigned curmode:1;
  107608. + unsigned modemismatch:1;
  107609. + unsigned otgintr:1;
  107610. + unsigned sofintr:1;
  107611. + unsigned rxstsqlvl:1;
  107612. + unsigned nptxfempty:1;
  107613. + unsigned ginnakeff:1;
  107614. + unsigned goutnakeff:1;
  107615. + unsigned ulpickint:1;
  107616. + unsigned i2cintr:1;
  107617. + unsigned erlysuspend:1;
  107618. + unsigned usbsuspend:1;
  107619. + unsigned usbreset:1;
  107620. + unsigned enumdone:1;
  107621. + unsigned isooutdrop:1;
  107622. + unsigned eopframe:1;
  107623. + unsigned restoredone:1;
  107624. + unsigned epmismatch:1;
  107625. + unsigned inepint:1;
  107626. + unsigned outepintr:1;
  107627. + unsigned incomplisoin:1;
  107628. + unsigned incomplisoout:1;
  107629. + unsigned fetsusp:1;
  107630. + unsigned resetdet:1;
  107631. + unsigned portintr:1;
  107632. + unsigned hcintr:1;
  107633. + unsigned ptxfempty:1;
  107634. + unsigned lpmtranrcvd:1;
  107635. + unsigned conidstschng:1;
  107636. + unsigned disconnect:1;
  107637. + unsigned sessreqintr:1;
  107638. + unsigned wkupintr:1;
  107639. + } b;
  107640. +} gintsts_data_t;
  107641. +
  107642. +/**
  107643. + * This union represents the bit fields in the Device Receive Status Read and
  107644. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  107645. + * element then read out the bits using the <i>b</i>it elements.
  107646. + */
  107647. +typedef union device_grxsts_data {
  107648. + /** raw register data */
  107649. + uint32_t d32;
  107650. + /** register bits */
  107651. + struct {
  107652. + unsigned epnum:4;
  107653. + unsigned bcnt:11;
  107654. + unsigned dpid:2;
  107655. +
  107656. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  107657. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  107658. +
  107659. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  107660. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  107661. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  107662. + unsigned pktsts:4;
  107663. + unsigned fn:4;
  107664. + unsigned reserved25_31:7;
  107665. + } b;
  107666. +} device_grxsts_data_t;
  107667. +
  107668. +/**
  107669. + * This union represents the bit fields in the Host Receive Status Read and
  107670. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  107671. + * element then read out the bits using the <i>b</i>it elements.
  107672. + */
  107673. +typedef union host_grxsts_data {
  107674. + /** raw register data */
  107675. + uint32_t d32;
  107676. + /** register bits */
  107677. + struct {
  107678. + unsigned chnum:4;
  107679. + unsigned bcnt:11;
  107680. + unsigned dpid:2;
  107681. +
  107682. + unsigned pktsts:4;
  107683. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  107684. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  107685. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  107686. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  107687. +
  107688. + unsigned reserved21_31:11;
  107689. + } b;
  107690. +} host_grxsts_data_t;
  107691. +
  107692. +/**
  107693. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  107694. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  107695. + * then read out the bits using the <i>b</i>it elements.
  107696. + */
  107697. +typedef union fifosize_data {
  107698. + /** raw register data */
  107699. + uint32_t d32;
  107700. + /** register bits */
  107701. + struct {
  107702. + unsigned startaddr:16;
  107703. + unsigned depth:16;
  107704. + } b;
  107705. +} fifosize_data_t;
  107706. +
  107707. +/**
  107708. + * This union represents the bit fields in the Non-Periodic Transmit
  107709. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  107710. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  107711. + * elements.
  107712. + */
  107713. +typedef union gnptxsts_data {
  107714. + /** raw register data */
  107715. + uint32_t d32;
  107716. + /** register bits */
  107717. + struct {
  107718. + unsigned nptxfspcavail:16;
  107719. + unsigned nptxqspcavail:8;
  107720. + /** Top of the Non-Periodic Transmit Request Queue
  107721. + * - bit 24 - Terminate (Last entry for the selected
  107722. + * channel/EP)
  107723. + * - bits 26:25 - Token Type
  107724. + * - 2'b00 - IN/OUT
  107725. + * - 2'b01 - Zero Length OUT
  107726. + * - 2'b10 - PING/Complete Split
  107727. + * - 2'b11 - Channel Halt
  107728. + * - bits 30:27 - Channel/EP Number
  107729. + */
  107730. + unsigned nptxqtop_terminate:1;
  107731. + unsigned nptxqtop_token:2;
  107732. + unsigned nptxqtop_chnep:4;
  107733. + unsigned reserved:1;
  107734. + } b;
  107735. +} gnptxsts_data_t;
  107736. +
  107737. +/**
  107738. + * This union represents the bit fields in the Transmit
  107739. + * FIFO Status Register (DTXFSTS). Read the register into the
  107740. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  107741. + * elements.
  107742. + */
  107743. +typedef union dtxfsts_data {
  107744. + /** raw register data */
  107745. + uint32_t d32;
  107746. + /** register bits */
  107747. + struct {
  107748. + unsigned txfspcavail:16;
  107749. + unsigned reserved:16;
  107750. + } b;
  107751. +} dtxfsts_data_t;
  107752. +
  107753. +/**
  107754. + * This union represents the bit fields in the I2C Control Register
  107755. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  107756. + * bits using the <i>b</i>it elements.
  107757. + */
  107758. +typedef union gi2cctl_data {
  107759. + /** raw register data */
  107760. + uint32_t d32;
  107761. + /** register bits */
  107762. + struct {
  107763. + unsigned rwdata:8;
  107764. + unsigned regaddr:8;
  107765. + unsigned addr:7;
  107766. + unsigned i2cen:1;
  107767. + unsigned ack:1;
  107768. + unsigned i2csuspctl:1;
  107769. + unsigned i2cdevaddr:2;
  107770. + unsigned i2cdatse0:1;
  107771. + unsigned reserved:1;
  107772. + unsigned rw:1;
  107773. + unsigned bsydne:1;
  107774. + } b;
  107775. +} gi2cctl_data_t;
  107776. +
  107777. +/**
  107778. + * This union represents the bit fields in the PHY Vendor Control Register
  107779. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  107780. + * bits using the <i>b</i>it elements.
  107781. + */
  107782. +typedef union gpvndctl_data {
  107783. + /** raw register data */
  107784. + uint32_t d32;
  107785. + /** register bits */
  107786. + struct {
  107787. + unsigned regdata:8;
  107788. + unsigned vctrl:8;
  107789. + unsigned regaddr16_21:6;
  107790. + unsigned regwr:1;
  107791. + unsigned reserved23_24:2;
  107792. + unsigned newregreq:1;
  107793. + unsigned vstsbsy:1;
  107794. + unsigned vstsdone:1;
  107795. + unsigned reserved28_30:3;
  107796. + unsigned disulpidrvr:1;
  107797. + } b;
  107798. +} gpvndctl_data_t;
  107799. +
  107800. +/**
  107801. + * This union represents the bit fields in the General Purpose
  107802. + * Input/Output Register (GGPIO).
  107803. + * Read the register into the <i>d32</i> element then read out the
  107804. + * bits using the <i>b</i>it elements.
  107805. + */
  107806. +typedef union ggpio_data {
  107807. + /** raw register data */
  107808. + uint32_t d32;
  107809. + /** register bits */
  107810. + struct {
  107811. + unsigned gpi:16;
  107812. + unsigned gpo:16;
  107813. + } b;
  107814. +} ggpio_data_t;
  107815. +
  107816. +/**
  107817. + * This union represents the bit fields in the User ID Register
  107818. + * (GUID). Read the register into the <i>d32</i> element then read out the
  107819. + * bits using the <i>b</i>it elements.
  107820. + */
  107821. +typedef union guid_data {
  107822. + /** raw register data */
  107823. + uint32_t d32;
  107824. + /** register bits */
  107825. + struct {
  107826. + unsigned rwdata:32;
  107827. + } b;
  107828. +} guid_data_t;
  107829. +
  107830. +/**
  107831. + * This union represents the bit fields in the Synopsys ID Register
  107832. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  107833. + * bits using the <i>b</i>it elements.
  107834. + */
  107835. +typedef union gsnpsid_data {
  107836. + /** raw register data */
  107837. + uint32_t d32;
  107838. + /** register bits */
  107839. + struct {
  107840. + unsigned rwdata:32;
  107841. + } b;
  107842. +} gsnpsid_data_t;
  107843. +
  107844. +/**
  107845. + * This union represents the bit fields in the User HW Config1
  107846. + * Register. Read the register into the <i>d32</i> element then read
  107847. + * out the bits using the <i>b</i>it elements.
  107848. + */
  107849. +typedef union hwcfg1_data {
  107850. + /** raw register data */
  107851. + uint32_t d32;
  107852. + /** register bits */
  107853. + struct {
  107854. + unsigned ep_dir0:2;
  107855. + unsigned ep_dir1:2;
  107856. + unsigned ep_dir2:2;
  107857. + unsigned ep_dir3:2;
  107858. + unsigned ep_dir4:2;
  107859. + unsigned ep_dir5:2;
  107860. + unsigned ep_dir6:2;
  107861. + unsigned ep_dir7:2;
  107862. + unsigned ep_dir8:2;
  107863. + unsigned ep_dir9:2;
  107864. + unsigned ep_dir10:2;
  107865. + unsigned ep_dir11:2;
  107866. + unsigned ep_dir12:2;
  107867. + unsigned ep_dir13:2;
  107868. + unsigned ep_dir14:2;
  107869. + unsigned ep_dir15:2;
  107870. + } b;
  107871. +} hwcfg1_data_t;
  107872. +
  107873. +/**
  107874. + * This union represents the bit fields in the User HW Config2
  107875. + * Register. Read the register into the <i>d32</i> element then read
  107876. + * out the bits using the <i>b</i>it elements.
  107877. + */
  107878. +typedef union hwcfg2_data {
  107879. + /** raw register data */
  107880. + uint32_t d32;
  107881. + /** register bits */
  107882. + struct {
  107883. + /* GHWCFG2 */
  107884. + unsigned op_mode:3;
  107885. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  107886. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  107887. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  107888. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  107889. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  107890. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  107891. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  107892. +
  107893. + unsigned architecture:2;
  107894. + unsigned point2point:1;
  107895. + unsigned hs_phy_type:2;
  107896. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  107897. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  107898. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  107899. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  107900. +
  107901. + unsigned fs_phy_type:2;
  107902. + unsigned num_dev_ep:4;
  107903. + unsigned num_host_chan:4;
  107904. + unsigned perio_ep_supported:1;
  107905. + unsigned dynamic_fifo:1;
  107906. + unsigned multi_proc_int:1;
  107907. + unsigned reserved21:1;
  107908. + unsigned nonperio_tx_q_depth:2;
  107909. + unsigned host_perio_tx_q_depth:2;
  107910. + unsigned dev_token_q_depth:5;
  107911. + unsigned otg_enable_ic_usb:1;
  107912. + } b;
  107913. +} hwcfg2_data_t;
  107914. +
  107915. +/**
  107916. + * This union represents the bit fields in the User HW Config3
  107917. + * Register. Read the register into the <i>d32</i> element then read
  107918. + * out the bits using the <i>b</i>it elements.
  107919. + */
  107920. +typedef union hwcfg3_data {
  107921. + /** raw register data */
  107922. + uint32_t d32;
  107923. + /** register bits */
  107924. + struct {
  107925. + /* GHWCFG3 */
  107926. + unsigned xfer_size_cntr_width:4;
  107927. + unsigned packet_size_cntr_width:3;
  107928. + unsigned otg_func:1;
  107929. + unsigned i2c:1;
  107930. + unsigned vendor_ctrl_if:1;
  107931. + unsigned optional_features:1;
  107932. + unsigned synch_reset_type:1;
  107933. + unsigned adp_supp:1;
  107934. + unsigned otg_enable_hsic:1;
  107935. + unsigned bc_support:1;
  107936. + unsigned otg_lpm_en:1;
  107937. + unsigned dfifo_depth:16;
  107938. + } b;
  107939. +} hwcfg3_data_t;
  107940. +
  107941. +/**
  107942. + * This union represents the bit fields in the User HW Config4
  107943. + * Register. Read the register into the <i>d32</i> element then read
  107944. + * out the bits using the <i>b</i>it elements.
  107945. + */
  107946. +typedef union hwcfg4_data {
  107947. + /** raw register data */
  107948. + uint32_t d32;
  107949. + /** register bits */
  107950. + struct {
  107951. + unsigned num_dev_perio_in_ep:4;
  107952. + unsigned power_optimiz:1;
  107953. + unsigned min_ahb_freq:1;
  107954. + unsigned hiber:1;
  107955. + unsigned xhiber:1;
  107956. + unsigned reserved:6;
  107957. + unsigned utmi_phy_data_width:2;
  107958. + unsigned num_dev_mode_ctrl_ep:4;
  107959. + unsigned iddig_filt_en:1;
  107960. + unsigned vbus_valid_filt_en:1;
  107961. + unsigned a_valid_filt_en:1;
  107962. + unsigned b_valid_filt_en:1;
  107963. + unsigned session_end_filt_en:1;
  107964. + unsigned ded_fifo_en:1;
  107965. + unsigned num_in_eps:4;
  107966. + unsigned desc_dma:1;
  107967. + unsigned desc_dma_dyn:1;
  107968. + } b;
  107969. +} hwcfg4_data_t;
  107970. +
  107971. +/**
  107972. + * This union represents the bit fields of the Core LPM Configuration
  107973. + * Register (GLPMCFG). Set the bits using bit fields then write
  107974. + * the <i>d32</i> value to the register.
  107975. + */
  107976. +typedef union glpmctl_data {
  107977. + /** raw register data */
  107978. + uint32_t d32;
  107979. + /** register bits */
  107980. + struct {
  107981. + /** LPM-Capable (LPMCap) (Device and Host)
  107982. + * The application uses this bit to control
  107983. + * the DWC_otg core LPM capabilities.
  107984. + */
  107985. + unsigned lpm_cap_en:1;
  107986. + /** LPM response programmed by application (AppL1Res) (Device)
  107987. + * Handshake response to LPM token pre-programmed
  107988. + * by device application software.
  107989. + */
  107990. + unsigned appl_resp:1;
  107991. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  107992. + * In Host mode this field indicates the value of HIRD
  107993. + * to be sent in an LPM transaction.
  107994. + * In Device mode this field is updated with the
  107995. + * Received LPM Token HIRD bmAttribute
  107996. + * when an ACK/NYET/STALL response is sent
  107997. + * to an LPM transaction.
  107998. + */
  107999. + unsigned hird:4;
  108000. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  108001. + * In Host mode this bit indicates the value of remote
  108002. + * wake up to be sent in wIndex field of LPM transaction.
  108003. + * In Device mode this field is updated with the
  108004. + * Received LPM Token bRemoteWake bmAttribute
  108005. + * when an ACK/NYET/STALL response is sent
  108006. + * to an LPM transaction.
  108007. + */
  108008. + unsigned rem_wkup_en:1;
  108009. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  108010. + * The application uses this bit to control
  108011. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  108012. + */
  108013. + unsigned en_utmi_sleep:1;
  108014. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  108015. + */
  108016. + unsigned hird_thres:5;
  108017. + /** LPM Response (CoreL1Res) (Device and Host)
  108018. + * In Host mode this bit contains handsake response to
  108019. + * LPM transaction.
  108020. + * In Device mode the response of the core to
  108021. + * LPM transaction received is reflected in these two bits.
  108022. + - 0x0 : ERROR (No handshake response)
  108023. + - 0x1 : STALL
  108024. + - 0x2 : NYET
  108025. + - 0x3 : ACK
  108026. + */
  108027. + unsigned lpm_resp:2;
  108028. + /** Port Sleep Status (SlpSts) (Device and Host)
  108029. + * This bit is set as long as a Sleep condition
  108030. + * is present on the USB bus.
  108031. + */
  108032. + unsigned prt_sleep_sts:1;
  108033. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  108034. + * Indicates that the application or host
  108035. + * can start resume from Sleep state.
  108036. + */
  108037. + unsigned sleep_state_resumeok:1;
  108038. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  108039. + * The channel number on which the LPM transaction
  108040. + * has to be applied while sending
  108041. + * an LPM transaction to the local device.
  108042. + */
  108043. + unsigned lpm_chan_index:4;
  108044. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  108045. + * Number host retries that would be performed
  108046. + * if the device response was not valid response.
  108047. + */
  108048. + unsigned retry_count:3;
  108049. + /** Send LPM Transaction (SndLPM) (Host)
  108050. + * When set by application software,
  108051. + * an LPM transaction containing two tokens
  108052. + * is sent.
  108053. + */
  108054. + unsigned send_lpm:1;
  108055. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  108056. + * Number of LPM Host Retries still remaining
  108057. + * to be transmitted for the current LPM sequence
  108058. + */
  108059. + unsigned retry_count_sts:3;
  108060. + unsigned reserved28_29:2;
  108061. + /** In host mode once this bit is set, the host
  108062. + * configures to drive the HSIC Idle state on the bus.
  108063. + * It then waits for the device to initiate the Connect sequence.
  108064. + * In device mode once this bit is set, the device waits for
  108065. + * the HSIC Idle line state on the bus. Upon receving the Idle
  108066. + * line state, it initiates the HSIC Connect sequence.
  108067. + */
  108068. + unsigned hsic_connect:1;
  108069. + /** This bit overrides and functionally inverts
  108070. + * the if_select_hsic input port signal.
  108071. + */
  108072. + unsigned inv_sel_hsic:1;
  108073. + } b;
  108074. +} glpmcfg_data_t;
  108075. +
  108076. +/**
  108077. + * This union represents the bit fields of the Core ADP Timer, Control and
  108078. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  108079. + * the <i>d32</i> value to the register.
  108080. + */
  108081. +typedef union adpctl_data {
  108082. + /** raw register data */
  108083. + uint32_t d32;
  108084. + /** register bits */
  108085. + struct {
  108086. + /** Probe Discharge (PRB_DSCHG)
  108087. + * These bits set the times for TADP_DSCHG.
  108088. + * These bits are defined as follows:
  108089. + * 2'b00 - 4 msec
  108090. + * 2'b01 - 8 msec
  108091. + * 2'b10 - 16 msec
  108092. + * 2'b11 - 32 msec
  108093. + */
  108094. + unsigned prb_dschg:2;
  108095. + /** Probe Delta (PRB_DELTA)
  108096. + * These bits set the resolution for RTIM value.
  108097. + * The bits are defined in units of 32 kHz clock cycles as follows:
  108098. + * 2'b00 - 1 cycles
  108099. + * 2'b01 - 2 cycles
  108100. + * 2'b10 - 3 cycles
  108101. + * 2'b11 - 4 cycles
  108102. + * For example if this value is chosen to 2'b01, it means that RTIM
  108103. + * increments for every 3(three) 32Khz clock cycles.
  108104. + */
  108105. + unsigned prb_delta:2;
  108106. + /** Probe Period (PRB_PER)
  108107. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  108108. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  108109. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  108110. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  108111. + * 2'b11 - Reserved
  108112. + */
  108113. + unsigned prb_per:2;
  108114. + /** These bits capture the latest time it took for VBUS to ramp from
  108115. + * VADP_SINK to VADP_PRB.
  108116. + * 0x000 - 1 cycles
  108117. + * 0x001 - 2 cycles
  108118. + * 0x002 - 3 cycles
  108119. + * etc
  108120. + * 0x7FF - 2048 cycles
  108121. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  108122. + */
  108123. + unsigned rtim:11;
  108124. + /** Enable Probe (EnaPrb)
  108125. + * When programmed to 1'b1, the core performs a probe operation.
  108126. + * This bit is valid only if OTG_Ver = 1'b1.
  108127. + */
  108128. + unsigned enaprb:1;
  108129. + /** Enable Sense (EnaSns)
  108130. + * When programmed to 1'b1, the core performs a Sense operation.
  108131. + * This bit is valid only if OTG_Ver = 1'b1.
  108132. + */
  108133. + unsigned enasns:1;
  108134. + /** ADP Reset (ADPRes)
  108135. + * When set, ADP controller is reset.
  108136. + * This bit is valid only if OTG_Ver = 1'b1.
  108137. + */
  108138. + unsigned adpres:1;
  108139. + /** ADP Enable (ADPEn)
  108140. + * When set, the core performs either ADP probing or sensing
  108141. + * based on EnaPrb or EnaSns.
  108142. + * This bit is valid only if OTG_Ver = 1'b1.
  108143. + */
  108144. + unsigned adpen:1;
  108145. + /** ADP Probe Interrupt (ADP_PRB_INT)
  108146. + * When this bit is set, it means that the VBUS
  108147. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  108148. + * This bit is valid only if OTG_Ver = 1'b1.
  108149. + */
  108150. + unsigned adp_prb_int:1;
  108151. + /**
  108152. + * ADP Sense Interrupt (ADP_SNS_INT)
  108153. + * When this bit is set, it means that the VBUS voltage is greater than
  108154. + * VADP_SNS value or VADP_SNS is reached.
  108155. + * This bit is valid only if OTG_Ver = 1'b1.
  108156. + */
  108157. + unsigned adp_sns_int:1;
  108158. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  108159. + * This bit is relevant only for an ADP probe.
  108160. + * When this bit is set, it means that the ramp time has
  108161. + * completed ie ADPCTL.RTIM has reached its terminal value
  108162. + * of 0x7FF. This is a debug feature that allows software
  108163. + * to read the ramp time after each cycle.
  108164. + * This bit is valid only if OTG_Ver = 1'b1.
  108165. + */
  108166. + unsigned adp_tmout_int:1;
  108167. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  108168. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  108169. + * This bit is valid only if OTG_Ver = 1'b1.
  108170. + */
  108171. + unsigned adp_prb_int_msk:1;
  108172. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  108173. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  108174. + * This bit is valid only if OTG_Ver = 1'b1.
  108175. + */
  108176. + unsigned adp_sns_int_msk:1;
  108177. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  108178. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  108179. + * This bit is valid only if OTG_Ver = 1'b1.
  108180. + */
  108181. + unsigned adp_tmout_int_msk:1;
  108182. + /** Access Request
  108183. + * 2'b00 - Read/Write Valid (updated by the core)
  108184. + * 2'b01 - Read
  108185. + * 2'b00 - Write
  108186. + * 2'b00 - Reserved
  108187. + */
  108188. + unsigned ar:2;
  108189. + /** Reserved */
  108190. + unsigned reserved29_31:3;
  108191. + } b;
  108192. +} adpctl_data_t;
  108193. +
  108194. +////////////////////////////////////////////
  108195. +// Device Registers
  108196. +/**
  108197. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  108198. + *
  108199. + * The following structures define the size and relative field offsets
  108200. + * for the Device Mode Registers.
  108201. + *
  108202. + * <i>These registers are visible only in Device mode and must not be
  108203. + * accessed in Host mode, as the results are unknown.</i>
  108204. + */
  108205. +typedef struct dwc_otg_dev_global_regs {
  108206. + /** Device Configuration Register. <i>Offset 800h</i> */
  108207. + volatile uint32_t dcfg;
  108208. + /** Device Control Register. <i>Offset: 804h</i> */
  108209. + volatile uint32_t dctl;
  108210. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  108211. + volatile uint32_t dsts;
  108212. + /** Reserved. <i>Offset: 80Ch</i> */
  108213. + uint32_t unused;
  108214. + /** Device IN Endpoint Common Interrupt Mask
  108215. + * Register. <i>Offset: 810h</i> */
  108216. + volatile uint32_t diepmsk;
  108217. + /** Device OUT Endpoint Common Interrupt Mask
  108218. + * Register. <i>Offset: 814h</i> */
  108219. + volatile uint32_t doepmsk;
  108220. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  108221. + volatile uint32_t daint;
  108222. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  108223. + * 81Ch</i> */
  108224. + volatile uint32_t daintmsk;
  108225. + /** Device IN Token Queue Read Register-1 (Read Only).
  108226. + * <i>Offset: 820h</i> */
  108227. + volatile uint32_t dtknqr1;
  108228. + /** Device IN Token Queue Read Register-2 (Read Only).
  108229. + * <i>Offset: 824h</i> */
  108230. + volatile uint32_t dtknqr2;
  108231. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  108232. + volatile uint32_t dvbusdis;
  108233. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  108234. + volatile uint32_t dvbuspulse;
  108235. + /** Device IN Token Queue Read Register-3 (Read Only). /
  108236. + * Device Thresholding control register (Read/Write)
  108237. + * <i>Offset: 830h</i> */
  108238. + volatile uint32_t dtknqr3_dthrctl;
  108239. + /** Device IN Token Queue Read Register-4 (Read Only). /
  108240. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  108241. + * <i>Offset: 834h</i> */
  108242. + volatile uint32_t dtknqr4_fifoemptymsk;
  108243. + /** Device Each Endpoint Interrupt Register (Read Only). /
  108244. + * <i>Offset: 838h</i> */
  108245. + volatile uint32_t deachint;
  108246. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  108247. + * <i>Offset: 83Ch</i> */
  108248. + volatile uint32_t deachintmsk;
  108249. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  108250. + * <i>Offset: 840h</i> */
  108251. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  108252. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  108253. + * <i>Offset: 880h</i> */
  108254. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  108255. +} dwc_otg_device_global_regs_t;
  108256. +
  108257. +/**
  108258. + * This union represents the bit fields in the Device Configuration
  108259. + * Register. Read the register into the <i>d32</i> member then
  108260. + * set/clear the bits using the <i>b</i>it elements. Write the
  108261. + * <i>d32</i> member to the dcfg register.
  108262. + */
  108263. +typedef union dcfg_data {
  108264. + /** raw register data */
  108265. + uint32_t d32;
  108266. + /** register bits */
  108267. + struct {
  108268. + /** Device Speed */
  108269. + unsigned devspd:2;
  108270. + /** Non Zero Length Status OUT Handshake */
  108271. + unsigned nzstsouthshk:1;
  108272. +#define DWC_DCFG_SEND_STALL 1
  108273. +
  108274. + unsigned ena32khzs:1;
  108275. + /** Device Addresses */
  108276. + unsigned devaddr:7;
  108277. + /** Periodic Frame Interval */
  108278. + unsigned perfrint:2;
  108279. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  108280. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  108281. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  108282. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  108283. +
  108284. + /** Enable Device OUT NAK for bulk in DDMA mode */
  108285. + unsigned endevoutnak:1;
  108286. +
  108287. + unsigned reserved14_17:4;
  108288. + /** In Endpoint Mis-match count */
  108289. + unsigned epmscnt:5;
  108290. + /** Enable Descriptor DMA in Device mode */
  108291. + unsigned descdma:1;
  108292. + unsigned perschintvl:2;
  108293. + unsigned resvalid:6;
  108294. + } b;
  108295. +} dcfg_data_t;
  108296. +
  108297. +/**
  108298. + * This union represents the bit fields in the Device Control
  108299. + * Register. Read the register into the <i>d32</i> member then
  108300. + * set/clear the bits using the <i>b</i>it elements.
  108301. + */
  108302. +typedef union dctl_data {
  108303. + /** raw register data */
  108304. + uint32_t d32;
  108305. + /** register bits */
  108306. + struct {
  108307. + /** Remote Wakeup */
  108308. + unsigned rmtwkupsig:1;
  108309. + /** Soft Disconnect */
  108310. + unsigned sftdiscon:1;
  108311. + /** Global Non-Periodic IN NAK Status */
  108312. + unsigned gnpinnaksts:1;
  108313. + /** Global OUT NAK Status */
  108314. + unsigned goutnaksts:1;
  108315. + /** Test Control */
  108316. + unsigned tstctl:3;
  108317. + /** Set Global Non-Periodic IN NAK */
  108318. + unsigned sgnpinnak:1;
  108319. + /** Clear Global Non-Periodic IN NAK */
  108320. + unsigned cgnpinnak:1;
  108321. + /** Set Global OUT NAK */
  108322. + unsigned sgoutnak:1;
  108323. + /** Clear Global OUT NAK */
  108324. + unsigned cgoutnak:1;
  108325. + /** Power-On Programming Done */
  108326. + unsigned pwronprgdone:1;
  108327. + /** Reserved */
  108328. + unsigned reserved:1;
  108329. + /** Global Multi Count */
  108330. + unsigned gmc:2;
  108331. + /** Ignore Frame Number for ISOC EPs */
  108332. + unsigned ifrmnum:1;
  108333. + /** NAK on Babble */
  108334. + unsigned nakonbble:1;
  108335. + /** Enable Continue on BNA */
  108336. + unsigned encontonbna:1;
  108337. +
  108338. + unsigned reserved18_31:14;
  108339. + } b;
  108340. +} dctl_data_t;
  108341. +
  108342. +/**
  108343. + * This union represents the bit fields in the Device Status
  108344. + * Register. Read the register into the <i>d32</i> member then
  108345. + * set/clear the bits using the <i>b</i>it elements.
  108346. + */
  108347. +typedef union dsts_data {
  108348. + /** raw register data */
  108349. + uint32_t d32;
  108350. + /** register bits */
  108351. + struct {
  108352. + /** Suspend Status */
  108353. + unsigned suspsts:1;
  108354. + /** Enumerated Speed */
  108355. + unsigned enumspd:2;
  108356. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  108357. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  108358. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  108359. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  108360. + /** Erratic Error */
  108361. + unsigned errticerr:1;
  108362. + unsigned reserved4_7:4;
  108363. + /** Frame or Microframe Number of the received SOF */
  108364. + unsigned soffn:14;
  108365. + unsigned reserved22_31:10;
  108366. + } b;
  108367. +} dsts_data_t;
  108368. +
  108369. +/**
  108370. + * This union represents the bit fields in the Device IN EP Interrupt
  108371. + * Register and the Device IN EP Common Mask Register.
  108372. + *
  108373. + * - Read the register into the <i>d32</i> member then set/clear the
  108374. + * bits using the <i>b</i>it elements.
  108375. + */
  108376. +typedef union diepint_data {
  108377. + /** raw register data */
  108378. + uint32_t d32;
  108379. + /** register bits */
  108380. + struct {
  108381. + /** Transfer complete mask */
  108382. + unsigned xfercompl:1;
  108383. + /** Endpoint disable mask */
  108384. + unsigned epdisabled:1;
  108385. + /** AHB Error mask */
  108386. + unsigned ahberr:1;
  108387. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  108388. + unsigned timeout:1;
  108389. + /** IN Token received with TxF Empty mask */
  108390. + unsigned intktxfemp:1;
  108391. + /** IN Token Received with EP mismatch mask */
  108392. + unsigned intknepmis:1;
  108393. + /** IN Endpoint NAK Effective mask */
  108394. + unsigned inepnakeff:1;
  108395. + /** Reserved */
  108396. + unsigned emptyintr:1;
  108397. +
  108398. + unsigned txfifoundrn:1;
  108399. +
  108400. + /** BNA Interrupt mask */
  108401. + unsigned bna:1;
  108402. +
  108403. + unsigned reserved10_12:3;
  108404. + /** BNA Interrupt mask */
  108405. + unsigned nak:1;
  108406. +
  108407. + unsigned reserved14_31:18;
  108408. + } b;
  108409. +} diepint_data_t;
  108410. +
  108411. +/**
  108412. + * This union represents the bit fields in the Device IN EP
  108413. + * Common/Dedicated Interrupt Mask Register.
  108414. + */
  108415. +typedef union diepint_data diepmsk_data_t;
  108416. +
  108417. +/**
  108418. + * This union represents the bit fields in the Device OUT EP Interrupt
  108419. + * Registerand Device OUT EP Common Interrupt Mask Register.
  108420. + *
  108421. + * - Read the register into the <i>d32</i> member then set/clear the
  108422. + * bits using the <i>b</i>it elements.
  108423. + */
  108424. +typedef union doepint_data {
  108425. + /** raw register data */
  108426. + uint32_t d32;
  108427. + /** register bits */
  108428. + struct {
  108429. + /** Transfer complete */
  108430. + unsigned xfercompl:1;
  108431. + /** Endpoint disable */
  108432. + unsigned epdisabled:1;
  108433. + /** AHB Error */
  108434. + unsigned ahberr:1;
  108435. + /** Setup Phase Done (contorl EPs) */
  108436. + unsigned setup:1;
  108437. + /** OUT Token Received when Endpoint Disabled */
  108438. + unsigned outtknepdis:1;
  108439. +
  108440. + unsigned stsphsercvd:1;
  108441. + /** Back-to-Back SETUP Packets Received */
  108442. + unsigned back2backsetup:1;
  108443. +
  108444. + unsigned reserved7:1;
  108445. + /** OUT packet Error */
  108446. + unsigned outpkterr:1;
  108447. + /** BNA Interrupt */
  108448. + unsigned bna:1;
  108449. +
  108450. + unsigned reserved10:1;
  108451. + /** Packet Drop Status */
  108452. + unsigned pktdrpsts:1;
  108453. + /** Babble Interrupt */
  108454. + unsigned babble:1;
  108455. + /** NAK Interrupt */
  108456. + unsigned nak:1;
  108457. + /** NYET Interrupt */
  108458. + unsigned nyet:1;
  108459. + /** Bit indicating setup packet received */
  108460. + unsigned sr:1;
  108461. +
  108462. + unsigned reserved16_31:16;
  108463. + } b;
  108464. +} doepint_data_t;
  108465. +
  108466. +/**
  108467. + * This union represents the bit fields in the Device OUT EP
  108468. + * Common/Dedicated Interrupt Mask Register.
  108469. + */
  108470. +typedef union doepint_data doepmsk_data_t;
  108471. +
  108472. +/**
  108473. + * This union represents the bit fields in the Device All EP Interrupt
  108474. + * and Mask Registers.
  108475. + * - Read the register into the <i>d32</i> member then set/clear the
  108476. + * bits using the <i>b</i>it elements.
  108477. + */
  108478. +typedef union daint_data {
  108479. + /** raw register data */
  108480. + uint32_t d32;
  108481. + /** register bits */
  108482. + struct {
  108483. + /** IN Endpoint bits */
  108484. + unsigned in:16;
  108485. + /** OUT Endpoint bits */
  108486. + unsigned out:16;
  108487. + } ep;
  108488. + struct {
  108489. + /** IN Endpoint bits */
  108490. + unsigned inep0:1;
  108491. + unsigned inep1:1;
  108492. + unsigned inep2:1;
  108493. + unsigned inep3:1;
  108494. + unsigned inep4:1;
  108495. + unsigned inep5:1;
  108496. + unsigned inep6:1;
  108497. + unsigned inep7:1;
  108498. + unsigned inep8:1;
  108499. + unsigned inep9:1;
  108500. + unsigned inep10:1;
  108501. + unsigned inep11:1;
  108502. + unsigned inep12:1;
  108503. + unsigned inep13:1;
  108504. + unsigned inep14:1;
  108505. + unsigned inep15:1;
  108506. + /** OUT Endpoint bits */
  108507. + unsigned outep0:1;
  108508. + unsigned outep1:1;
  108509. + unsigned outep2:1;
  108510. + unsigned outep3:1;
  108511. + unsigned outep4:1;
  108512. + unsigned outep5:1;
  108513. + unsigned outep6:1;
  108514. + unsigned outep7:1;
  108515. + unsigned outep8:1;
  108516. + unsigned outep9:1;
  108517. + unsigned outep10:1;
  108518. + unsigned outep11:1;
  108519. + unsigned outep12:1;
  108520. + unsigned outep13:1;
  108521. + unsigned outep14:1;
  108522. + unsigned outep15:1;
  108523. + } b;
  108524. +} daint_data_t;
  108525. +
  108526. +/**
  108527. + * This union represents the bit fields in the Device IN Token Queue
  108528. + * Read Registers.
  108529. + * - Read the register into the <i>d32</i> member.
  108530. + * - READ-ONLY Register
  108531. + */
  108532. +typedef union dtknq1_data {
  108533. + /** raw register data */
  108534. + uint32_t d32;
  108535. + /** register bits */
  108536. + struct {
  108537. + /** In Token Queue Write Pointer */
  108538. + unsigned intknwptr:5;
  108539. + /** Reserved */
  108540. + unsigned reserved05_06:2;
  108541. + /** write pointer has wrapped. */
  108542. + unsigned wrap_bit:1;
  108543. + /** EP Numbers of IN Tokens 0 ... 4 */
  108544. + unsigned epnums0_5:24;
  108545. + } b;
  108546. +} dtknq1_data_t;
  108547. +
  108548. +/**
  108549. + * This union represents Threshold control Register
  108550. + * - Read and write the register into the <i>d32</i> member.
  108551. + * - READ-WRITABLE Register
  108552. + */
  108553. +typedef union dthrctl_data {
  108554. + /** raw register data */
  108555. + uint32_t d32;
  108556. + /** register bits */
  108557. + struct {
  108558. + /** non ISO Tx Thr. Enable */
  108559. + unsigned non_iso_thr_en:1;
  108560. + /** ISO Tx Thr. Enable */
  108561. + unsigned iso_thr_en:1;
  108562. + /** Tx Thr. Length */
  108563. + unsigned tx_thr_len:9;
  108564. + /** AHB Threshold ratio */
  108565. + unsigned ahb_thr_ratio:2;
  108566. + /** Reserved */
  108567. + unsigned reserved13_15:3;
  108568. + /** Rx Thr. Enable */
  108569. + unsigned rx_thr_en:1;
  108570. + /** Rx Thr. Length */
  108571. + unsigned rx_thr_len:9;
  108572. + unsigned reserved26:1;
  108573. + /** Arbiter Parking Enable*/
  108574. + unsigned arbprken:1;
  108575. + /** Reserved */
  108576. + unsigned reserved28_31:4;
  108577. + } b;
  108578. +} dthrctl_data_t;
  108579. +
  108580. +/**
  108581. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  108582. + * 900h-AFCh</i>
  108583. + *
  108584. + * There will be one set of endpoint registers per logical endpoint
  108585. + * implemented.
  108586. + *
  108587. + * <i>These registers are visible only in Device mode and must not be
  108588. + * accessed in Host mode, as the results are unknown.</i>
  108589. + */
  108590. +typedef struct dwc_otg_dev_in_ep_regs {
  108591. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  108592. + * (ep_num * 20h) + 00h</i> */
  108593. + volatile uint32_t diepctl;
  108594. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  108595. + uint32_t reserved04;
  108596. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  108597. + * (ep_num * 20h) + 08h</i> */
  108598. + volatile uint32_t diepint;
  108599. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  108600. + uint32_t reserved0C;
  108601. + /** Device IN Endpoint Transfer Size
  108602. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  108603. + volatile uint32_t dieptsiz;
  108604. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  108605. + * (ep_num * 20h) + 14h</i> */
  108606. + volatile uint32_t diepdma;
  108607. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  108608. + * (ep_num * 20h) + 18h</i> */
  108609. + volatile uint32_t dtxfsts;
  108610. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  108611. + * (ep_num * 20h) + 1Ch</i> */
  108612. + volatile uint32_t diepdmab;
  108613. +} dwc_otg_dev_in_ep_regs_t;
  108614. +
  108615. +/**
  108616. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  108617. + * B00h-CFCh</i>
  108618. + *
  108619. + * There will be one set of endpoint registers per logical endpoint
  108620. + * implemented.
  108621. + *
  108622. + * <i>These registers are visible only in Device mode and must not be
  108623. + * accessed in Host mode, as the results are unknown.</i>
  108624. + */
  108625. +typedef struct dwc_otg_dev_out_ep_regs {
  108626. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  108627. + * (ep_num * 20h) + 00h</i> */
  108628. + volatile uint32_t doepctl;
  108629. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  108630. + uint32_t reserved04;
  108631. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  108632. + * (ep_num * 20h) + 08h</i> */
  108633. + volatile uint32_t doepint;
  108634. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  108635. + uint32_t reserved0C;
  108636. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  108637. + * B00h + (ep_num * 20h) + 10h</i> */
  108638. + volatile uint32_t doeptsiz;
  108639. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  108640. + * + (ep_num * 20h) + 14h</i> */
  108641. + volatile uint32_t doepdma;
  108642. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  108643. + uint32_t unused;
  108644. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  108645. + * + (ep_num * 20h) + 1Ch</i> */
  108646. + uint32_t doepdmab;
  108647. +} dwc_otg_dev_out_ep_regs_t;
  108648. +
  108649. +/**
  108650. + * This union represents the bit fields in the Device EP Control
  108651. + * Register. Read the register into the <i>d32</i> member then
  108652. + * set/clear the bits using the <i>b</i>it elements.
  108653. + */
  108654. +typedef union depctl_data {
  108655. + /** raw register data */
  108656. + uint32_t d32;
  108657. + /** register bits */
  108658. + struct {
  108659. + /** Maximum Packet Size
  108660. + * IN/OUT EPn
  108661. + * IN/OUT EP0 - 2 bits
  108662. + * 2'b00: 64 Bytes
  108663. + * 2'b01: 32
  108664. + * 2'b10: 16
  108665. + * 2'b11: 8 */
  108666. + unsigned mps:11;
  108667. +#define DWC_DEP0CTL_MPS_64 0
  108668. +#define DWC_DEP0CTL_MPS_32 1
  108669. +#define DWC_DEP0CTL_MPS_16 2
  108670. +#define DWC_DEP0CTL_MPS_8 3
  108671. +
  108672. + /** Next Endpoint
  108673. + * IN EPn/IN EP0
  108674. + * OUT EPn/OUT EP0 - reserved */
  108675. + unsigned nextep:4;
  108676. +
  108677. + /** USB Active Endpoint */
  108678. + unsigned usbactep:1;
  108679. +
  108680. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  108681. + * This field contains the PID of the packet going to
  108682. + * be received or transmitted on this endpoint. The
  108683. + * application should program the PID of the first
  108684. + * packet going to be received or transmitted on this
  108685. + * endpoint , after the endpoint is
  108686. + * activated. Application use the SetD1PID and
  108687. + * SetD0PID fields of this register to program either
  108688. + * D0 or D1 PID.
  108689. + *
  108690. + * The encoding for this field is
  108691. + * - 0: D0
  108692. + * - 1: D1
  108693. + */
  108694. + unsigned dpid:1;
  108695. +
  108696. + /** NAK Status */
  108697. + unsigned naksts:1;
  108698. +
  108699. + /** Endpoint Type
  108700. + * 2'b00: Control
  108701. + * 2'b01: Isochronous
  108702. + * 2'b10: Bulk
  108703. + * 2'b11: Interrupt */
  108704. + unsigned eptype:2;
  108705. +
  108706. + /** Snoop Mode
  108707. + * OUT EPn/OUT EP0
  108708. + * IN EPn/IN EP0 - reserved */
  108709. + unsigned snp:1;
  108710. +
  108711. + /** Stall Handshake */
  108712. + unsigned stall:1;
  108713. +
  108714. + /** Tx Fifo Number
  108715. + * IN EPn/IN EP0
  108716. + * OUT EPn/OUT EP0 - reserved */
  108717. + unsigned txfnum:4;
  108718. +
  108719. + /** Clear NAK */
  108720. + unsigned cnak:1;
  108721. + /** Set NAK */
  108722. + unsigned snak:1;
  108723. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  108724. + * Writing to this field sets the Endpoint DPID (DPID)
  108725. + * field in this register to DATA0. Set Even
  108726. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  108727. + * Writing to this field sets the Even/Odd
  108728. + * (micro)frame (EO_FrNum) field to even (micro)
  108729. + * frame.
  108730. + */
  108731. + unsigned setd0pid:1;
  108732. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  108733. + * Writing to this field sets the Endpoint DPID (DPID)
  108734. + * field in this register to DATA1 Set Odd
  108735. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  108736. + * Writing to this field sets the Even/Odd
  108737. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  108738. + */
  108739. + unsigned setd1pid:1;
  108740. +
  108741. + /** Endpoint Disable */
  108742. + unsigned epdis:1;
  108743. + /** Endpoint Enable */
  108744. + unsigned epena:1;
  108745. + } b;
  108746. +} depctl_data_t;
  108747. +
  108748. +/**
  108749. + * This union represents the bit fields in the Device EP Transfer
  108750. + * Size Register. Read the register into the <i>d32</i> member then
  108751. + * set/clear the bits using the <i>b</i>it elements.
  108752. + */
  108753. +typedef union deptsiz_data {
  108754. + /** raw register data */
  108755. + uint32_t d32;
  108756. + /** register bits */
  108757. + struct {
  108758. + /** Transfer size */
  108759. + unsigned xfersize:19;
  108760. +/** Max packet count for EP (pow(2,10)-1) */
  108761. +#define MAX_PKT_CNT 1023
  108762. + /** Packet Count */
  108763. + unsigned pktcnt:10;
  108764. + /** Multi Count - Periodic IN endpoints */
  108765. + unsigned mc:2;
  108766. + unsigned reserved:1;
  108767. + } b;
  108768. +} deptsiz_data_t;
  108769. +
  108770. +/**
  108771. + * This union represents the bit fields in the Device EP 0 Transfer
  108772. + * Size Register. Read the register into the <i>d32</i> member then
  108773. + * set/clear the bits using the <i>b</i>it elements.
  108774. + */
  108775. +typedef union deptsiz0_data {
  108776. + /** raw register data */
  108777. + uint32_t d32;
  108778. + /** register bits */
  108779. + struct {
  108780. + /** Transfer size */
  108781. + unsigned xfersize:7;
  108782. + /** Reserved */
  108783. + unsigned reserved7_18:12;
  108784. + /** Packet Count */
  108785. + unsigned pktcnt:2;
  108786. + /** Reserved */
  108787. + unsigned reserved21_28:8;
  108788. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  108789. + unsigned supcnt:2;
  108790. + unsigned reserved31;
  108791. + } b;
  108792. +} deptsiz0_data_t;
  108793. +
  108794. +/////////////////////////////////////////////////
  108795. +// DMA Descriptor Specific Structures
  108796. +//
  108797. +
  108798. +/** Buffer status definitions */
  108799. +
  108800. +#define BS_HOST_READY 0x0
  108801. +#define BS_DMA_BUSY 0x1
  108802. +#define BS_DMA_DONE 0x2
  108803. +#define BS_HOST_BUSY 0x3
  108804. +
  108805. +/** Receive/Transmit status definitions */
  108806. +
  108807. +#define RTS_SUCCESS 0x0
  108808. +#define RTS_BUFFLUSH 0x1
  108809. +#define RTS_RESERVED 0x2
  108810. +#define RTS_BUFERR 0x3
  108811. +
  108812. +/**
  108813. + * This union represents the bit fields in the DMA Descriptor
  108814. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  108815. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  108816. + * <i>b_iso_in</i> elements.
  108817. + */
  108818. +typedef union dev_dma_desc_sts {
  108819. + /** raw register data */
  108820. + uint32_t d32;
  108821. + /** quadlet bits */
  108822. + struct {
  108823. + /** Received number of bytes */
  108824. + unsigned bytes:16;
  108825. + /** NAK bit - only for OUT EPs */
  108826. + unsigned nak:1;
  108827. + unsigned reserved17_22:6;
  108828. + /** Multiple Transfer - only for OUT EPs */
  108829. + unsigned mtrf:1;
  108830. + /** Setup Packet received - only for OUT EPs */
  108831. + unsigned sr:1;
  108832. + /** Interrupt On Complete */
  108833. + unsigned ioc:1;
  108834. + /** Short Packet */
  108835. + unsigned sp:1;
  108836. + /** Last */
  108837. + unsigned l:1;
  108838. + /** Receive Status */
  108839. + unsigned sts:2;
  108840. + /** Buffer Status */
  108841. + unsigned bs:2;
  108842. + } b;
  108843. +
  108844. +//#ifdef DWC_EN_ISOC
  108845. + /** iso out quadlet bits */
  108846. + struct {
  108847. + /** Received number of bytes */
  108848. + unsigned rxbytes:11;
  108849. +
  108850. + unsigned reserved11:1;
  108851. + /** Frame Number */
  108852. + unsigned framenum:11;
  108853. + /** Received ISO Data PID */
  108854. + unsigned pid:2;
  108855. + /** Interrupt On Complete */
  108856. + unsigned ioc:1;
  108857. + /** Short Packet */
  108858. + unsigned sp:1;
  108859. + /** Last */
  108860. + unsigned l:1;
  108861. + /** Receive Status */
  108862. + unsigned rxsts:2;
  108863. + /** Buffer Status */
  108864. + unsigned bs:2;
  108865. + } b_iso_out;
  108866. +
  108867. + /** iso in quadlet bits */
  108868. + struct {
  108869. + /** Transmited number of bytes */
  108870. + unsigned txbytes:12;
  108871. + /** Frame Number */
  108872. + unsigned framenum:11;
  108873. + /** Transmited ISO Data PID */
  108874. + unsigned pid:2;
  108875. + /** Interrupt On Complete */
  108876. + unsigned ioc:1;
  108877. + /** Short Packet */
  108878. + unsigned sp:1;
  108879. + /** Last */
  108880. + unsigned l:1;
  108881. + /** Transmit Status */
  108882. + unsigned txsts:2;
  108883. + /** Buffer Status */
  108884. + unsigned bs:2;
  108885. + } b_iso_in;
  108886. +//#endif /* DWC_EN_ISOC */
  108887. +} dev_dma_desc_sts_t;
  108888. +
  108889. +/**
  108890. + * DMA Descriptor structure
  108891. + *
  108892. + * DMA Descriptor structure contains two quadlets:
  108893. + * Status quadlet and Data buffer pointer.
  108894. + */
  108895. +typedef struct dwc_otg_dev_dma_desc {
  108896. + /** DMA Descriptor status quadlet */
  108897. + dev_dma_desc_sts_t status;
  108898. + /** DMA Descriptor data buffer pointer */
  108899. + uint32_t buf;
  108900. +} dwc_otg_dev_dma_desc_t;
  108901. +
  108902. +/**
  108903. + * The dwc_otg_dev_if structure contains information needed to manage
  108904. + * the DWC_otg controller acting in device mode. It represents the
  108905. + * programming view of the device-specific aspects of the controller.
  108906. + */
  108907. +typedef struct dwc_otg_dev_if {
  108908. + /** Pointer to device Global registers.
  108909. + * Device Global Registers starting at offset 800h
  108910. + */
  108911. + dwc_otg_device_global_regs_t *dev_global_regs;
  108912. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  108913. +
  108914. + /**
  108915. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  108916. + */
  108917. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  108918. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  108919. +#define DWC_EP_REG_OFFSET 0x20
  108920. +
  108921. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  108922. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  108923. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  108924. +
  108925. + /* Device configuration information */
  108926. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  108927. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  108928. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  108929. +
  108930. + /** Size of periodic FIFOs (Bytes) */
  108931. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  108932. +
  108933. + /** Size of Tx FIFOs (Bytes) */
  108934. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  108935. +
  108936. + /** Thresholding enable flags and length varaiables **/
  108937. + uint16_t rx_thr_en;
  108938. + uint16_t iso_tx_thr_en;
  108939. + uint16_t non_iso_tx_thr_en;
  108940. +
  108941. + uint16_t rx_thr_length;
  108942. + uint16_t tx_thr_length;
  108943. +
  108944. + /**
  108945. + * Pointers to the DMA Descriptors for EP0 Control
  108946. + * transfers (virtual and physical)
  108947. + */
  108948. +
  108949. + /** 2 descriptors for SETUP packets */
  108950. + dwc_dma_t dma_setup_desc_addr[2];
  108951. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  108952. +
  108953. + /** Pointer to Descriptor with latest SETUP packet */
  108954. + dwc_otg_dev_dma_desc_t *psetup;
  108955. +
  108956. + /** Index of current SETUP handler descriptor */
  108957. + uint32_t setup_desc_index;
  108958. +
  108959. + /** Descriptor for Data In or Status In phases */
  108960. + dwc_dma_t dma_in_desc_addr;
  108961. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  108962. +
  108963. + /** Descriptor for Data Out or Status Out phases */
  108964. + dwc_dma_t dma_out_desc_addr;
  108965. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  108966. +
  108967. + /** Setup Packet Detected - if set clear NAK when queueing */
  108968. + uint32_t spd;
  108969. + /** Isoc ep pointer on which incomplete happens */
  108970. + void *isoc_ep;
  108971. +
  108972. +} dwc_otg_dev_if_t;
  108973. +
  108974. +/////////////////////////////////////////////////
  108975. +// Host Mode Register Structures
  108976. +//
  108977. +/**
  108978. + * The Host Global Registers structure defines the size and relative
  108979. + * field offsets for the Host Mode Global Registers. Host Global
  108980. + * Registers offsets 400h-7FFh.
  108981. +*/
  108982. +typedef struct dwc_otg_host_global_regs {
  108983. + /** Host Configuration Register. <i>Offset: 400h</i> */
  108984. + volatile uint32_t hcfg;
  108985. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  108986. + volatile uint32_t hfir;
  108987. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  108988. + volatile uint32_t hfnum;
  108989. + /** Reserved. <i>Offset: 40Ch</i> */
  108990. + uint32_t reserved40C;
  108991. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  108992. + volatile uint32_t hptxsts;
  108993. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  108994. + volatile uint32_t haint;
  108995. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  108996. + volatile uint32_t haintmsk;
  108997. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  108998. + volatile uint32_t hflbaddr;
  108999. +} dwc_otg_host_global_regs_t;
  109000. +
  109001. +/**
  109002. + * This union represents the bit fields in the Host Configuration Register.
  109003. + * Read the register into the <i>d32</i> member then set/clear the bits using
  109004. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  109005. + */
  109006. +typedef union hcfg_data {
  109007. + /** raw register data */
  109008. + uint32_t d32;
  109009. +
  109010. + /** register bits */
  109011. + struct {
  109012. + /** FS/LS Phy Clock Select */
  109013. + unsigned fslspclksel:2;
  109014. +#define DWC_HCFG_30_60_MHZ 0
  109015. +#define DWC_HCFG_48_MHZ 1
  109016. +#define DWC_HCFG_6_MHZ 2
  109017. +
  109018. + /** FS/LS Only Support */
  109019. + unsigned fslssupp:1;
  109020. + unsigned reserved3_6:4;
  109021. + /** Enable 32-KHz Suspend Mode */
  109022. + unsigned ena32khzs:1;
  109023. + /** Resume Validation Periiod */
  109024. + unsigned resvalid:8;
  109025. + unsigned reserved16_22:7;
  109026. + /** Enable Scatter/gather DMA in Host mode */
  109027. + unsigned descdma:1;
  109028. + /** Frame List Entries */
  109029. + unsigned frlisten:2;
  109030. + /** Enable Periodic Scheduling */
  109031. + unsigned perschedena:1;
  109032. + unsigned reserved27_30:4;
  109033. + unsigned modechtimen:1;
  109034. + } b;
  109035. +} hcfg_data_t;
  109036. +
  109037. +/**
  109038. + * This union represents the bit fields in the Host Frame Remaing/Number
  109039. + * Register.
  109040. + */
  109041. +typedef union hfir_data {
  109042. + /** raw register data */
  109043. + uint32_t d32;
  109044. +
  109045. + /** register bits */
  109046. + struct {
  109047. + unsigned frint:16;
  109048. + unsigned hfirrldctrl:1;
  109049. + unsigned reserved:15;
  109050. + } b;
  109051. +} hfir_data_t;
  109052. +
  109053. +/**
  109054. + * This union represents the bit fields in the Host Frame Remaing/Number
  109055. + * Register.
  109056. + */
  109057. +typedef union hfnum_data {
  109058. + /** raw register data */
  109059. + uint32_t d32;
  109060. +
  109061. + /** register bits */
  109062. + struct {
  109063. + unsigned frnum:16;
  109064. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  109065. + unsigned frrem:16;
  109066. + } b;
  109067. +} hfnum_data_t;
  109068. +
  109069. +typedef union hptxsts_data {
  109070. + /** raw register data */
  109071. + uint32_t d32;
  109072. +
  109073. + /** register bits */
  109074. + struct {
  109075. + unsigned ptxfspcavail:16;
  109076. + unsigned ptxqspcavail:8;
  109077. + /** Top of the Periodic Transmit Request Queue
  109078. + * - bit 24 - Terminate (last entry for the selected channel)
  109079. + * - bits 26:25 - Token Type
  109080. + * - 2'b00 - Zero length
  109081. + * - 2'b01 - Ping
  109082. + * - 2'b10 - Disable
  109083. + * - bits 30:27 - Channel Number
  109084. + * - bit 31 - Odd/even microframe
  109085. + */
  109086. + unsigned ptxqtop_terminate:1;
  109087. + unsigned ptxqtop_token:2;
  109088. + unsigned ptxqtop_chnum:4;
  109089. + unsigned ptxqtop_odd:1;
  109090. + } b;
  109091. +} hptxsts_data_t;
  109092. +
  109093. +/**
  109094. + * This union represents the bit fields in the Host Port Control and Status
  109095. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109096. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  109097. + * hprt0 register.
  109098. + */
  109099. +typedef union hprt0_data {
  109100. + /** raw register data */
  109101. + uint32_t d32;
  109102. + /** register bits */
  109103. + struct {
  109104. + unsigned prtconnsts:1;
  109105. + unsigned prtconndet:1;
  109106. + unsigned prtena:1;
  109107. + unsigned prtenchng:1;
  109108. + unsigned prtovrcurract:1;
  109109. + unsigned prtovrcurrchng:1;
  109110. + unsigned prtres:1;
  109111. + unsigned prtsusp:1;
  109112. + unsigned prtrst:1;
  109113. + unsigned reserved9:1;
  109114. + unsigned prtlnsts:2;
  109115. + unsigned prtpwr:1;
  109116. + unsigned prttstctl:4;
  109117. + unsigned prtspd:2;
  109118. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  109119. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  109120. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  109121. + unsigned reserved19_31:13;
  109122. + } b;
  109123. +} hprt0_data_t;
  109124. +
  109125. +/**
  109126. + * This union represents the bit fields in the Host All Interrupt
  109127. + * Register.
  109128. + */
  109129. +typedef union haint_data {
  109130. + /** raw register data */
  109131. + uint32_t d32;
  109132. + /** register bits */
  109133. + struct {
  109134. + unsigned ch0:1;
  109135. + unsigned ch1:1;
  109136. + unsigned ch2:1;
  109137. + unsigned ch3:1;
  109138. + unsigned ch4:1;
  109139. + unsigned ch5:1;
  109140. + unsigned ch6:1;
  109141. + unsigned ch7:1;
  109142. + unsigned ch8:1;
  109143. + unsigned ch9:1;
  109144. + unsigned ch10:1;
  109145. + unsigned ch11:1;
  109146. + unsigned ch12:1;
  109147. + unsigned ch13:1;
  109148. + unsigned ch14:1;
  109149. + unsigned ch15:1;
  109150. + unsigned reserved:16;
  109151. + } b;
  109152. +
  109153. + struct {
  109154. + unsigned chint:16;
  109155. + unsigned reserved:16;
  109156. + } b2;
  109157. +} haint_data_t;
  109158. +
  109159. +/**
  109160. + * This union represents the bit fields in the Host All Interrupt
  109161. + * Register.
  109162. + */
  109163. +typedef union haintmsk_data {
  109164. + /** raw register data */
  109165. + uint32_t d32;
  109166. + /** register bits */
  109167. + struct {
  109168. + unsigned ch0:1;
  109169. + unsigned ch1:1;
  109170. + unsigned ch2:1;
  109171. + unsigned ch3:1;
  109172. + unsigned ch4:1;
  109173. + unsigned ch5:1;
  109174. + unsigned ch6:1;
  109175. + unsigned ch7:1;
  109176. + unsigned ch8:1;
  109177. + unsigned ch9:1;
  109178. + unsigned ch10:1;
  109179. + unsigned ch11:1;
  109180. + unsigned ch12:1;
  109181. + unsigned ch13:1;
  109182. + unsigned ch14:1;
  109183. + unsigned ch15:1;
  109184. + unsigned reserved:16;
  109185. + } b;
  109186. +
  109187. + struct {
  109188. + unsigned chint:16;
  109189. + unsigned reserved:16;
  109190. + } b2;
  109191. +} haintmsk_data_t;
  109192. +
  109193. +/**
  109194. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  109195. + */
  109196. +typedef struct dwc_otg_hc_regs {
  109197. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  109198. + volatile uint32_t hcchar;
  109199. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  109200. + volatile uint32_t hcsplt;
  109201. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  109202. + volatile uint32_t hcint;
  109203. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  109204. + volatile uint32_t hcintmsk;
  109205. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  109206. + volatile uint32_t hctsiz;
  109207. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  109208. + volatile uint32_t hcdma;
  109209. + volatile uint32_t reserved;
  109210. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  109211. + volatile uint32_t hcdmab;
  109212. +} dwc_otg_hc_regs_t;
  109213. +
  109214. +/**
  109215. + * This union represents the bit fields in the Host Channel Characteristics
  109216. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109217. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  109218. + * hcchar register.
  109219. + */
  109220. +typedef union hcchar_data {
  109221. + /** raw register data */
  109222. + uint32_t d32;
  109223. +
  109224. + /** register bits */
  109225. + struct {
  109226. + /** Maximum packet size in bytes */
  109227. + unsigned mps:11;
  109228. +
  109229. + /** Endpoint number */
  109230. + unsigned epnum:4;
  109231. +
  109232. + /** 0: OUT, 1: IN */
  109233. + unsigned epdir:1;
  109234. +
  109235. + unsigned reserved:1;
  109236. +
  109237. + /** 0: Full/high speed device, 1: Low speed device */
  109238. + unsigned lspddev:1;
  109239. +
  109240. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  109241. + unsigned eptype:2;
  109242. +
  109243. + /** Packets per frame for periodic transfers. 0 is reserved. */
  109244. + unsigned multicnt:2;
  109245. +
  109246. + /** Device address */
  109247. + unsigned devaddr:7;
  109248. +
  109249. + /**
  109250. + * Frame to transmit periodic transaction.
  109251. + * 0: even, 1: odd
  109252. + */
  109253. + unsigned oddfrm:1;
  109254. +
  109255. + /** Channel disable */
  109256. + unsigned chdis:1;
  109257. +
  109258. + /** Channel enable */
  109259. + unsigned chen:1;
  109260. + } b;
  109261. +} hcchar_data_t;
  109262. +
  109263. +typedef union hcsplt_data {
  109264. + /** raw register data */
  109265. + uint32_t d32;
  109266. +
  109267. + /** register bits */
  109268. + struct {
  109269. + /** Port Address */
  109270. + unsigned prtaddr:7;
  109271. +
  109272. + /** Hub Address */
  109273. + unsigned hubaddr:7;
  109274. +
  109275. + /** Transaction Position */
  109276. + unsigned xactpos:2;
  109277. +#define DWC_HCSPLIT_XACTPOS_MID 0
  109278. +#define DWC_HCSPLIT_XACTPOS_END 1
  109279. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  109280. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  109281. +
  109282. + /** Do Complete Split */
  109283. + unsigned compsplt:1;
  109284. +
  109285. + /** Reserved */
  109286. + unsigned reserved:14;
  109287. +
  109288. + /** Split Enble */
  109289. + unsigned spltena:1;
  109290. + } b;
  109291. +} hcsplt_data_t;
  109292. +
  109293. +/**
  109294. + * This union represents the bit fields in the Host All Interrupt
  109295. + * Register.
  109296. + */
  109297. +typedef union hcint_data {
  109298. + /** raw register data */
  109299. + uint32_t d32;
  109300. + /** register bits */
  109301. + struct {
  109302. + /** Transfer Complete */
  109303. + unsigned xfercomp:1;
  109304. + /** Channel Halted */
  109305. + unsigned chhltd:1;
  109306. + /** AHB Error */
  109307. + unsigned ahberr:1;
  109308. + /** STALL Response Received */
  109309. + unsigned stall:1;
  109310. + /** NAK Response Received */
  109311. + unsigned nak:1;
  109312. + /** ACK Response Received */
  109313. + unsigned ack:1;
  109314. + /** NYET Response Received */
  109315. + unsigned nyet:1;
  109316. + /** Transaction Err */
  109317. + unsigned xacterr:1;
  109318. + /** Babble Error */
  109319. + unsigned bblerr:1;
  109320. + /** Frame Overrun */
  109321. + unsigned frmovrun:1;
  109322. + /** Data Toggle Error */
  109323. + unsigned datatglerr:1;
  109324. + /** Buffer Not Available (only for DDMA mode) */
  109325. + unsigned bna:1;
  109326. + /** Exessive transaction error (only for DDMA mode) */
  109327. + unsigned xcs_xact:1;
  109328. + /** Frame List Rollover interrupt */
  109329. + unsigned frm_list_roll:1;
  109330. + /** Reserved */
  109331. + unsigned reserved14_31:18;
  109332. + } b;
  109333. +} hcint_data_t;
  109334. +
  109335. +/**
  109336. + * This union represents the bit fields in the Host Channel Interrupt Mask
  109337. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109338. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  109339. + * hcintmsk register.
  109340. + */
  109341. +typedef union hcintmsk_data {
  109342. + /** raw register data */
  109343. + uint32_t d32;
  109344. +
  109345. + /** register bits */
  109346. + struct {
  109347. + unsigned xfercompl:1;
  109348. + unsigned chhltd:1;
  109349. + unsigned ahberr:1;
  109350. + unsigned stall:1;
  109351. + unsigned nak:1;
  109352. + unsigned ack:1;
  109353. + unsigned nyet:1;
  109354. + unsigned xacterr:1;
  109355. + unsigned bblerr:1;
  109356. + unsigned frmovrun:1;
  109357. + unsigned datatglerr:1;
  109358. + unsigned bna:1;
  109359. + unsigned xcs_xact:1;
  109360. + unsigned frm_list_roll:1;
  109361. + unsigned reserved14_31:18;
  109362. + } b;
  109363. +} hcintmsk_data_t;
  109364. +
  109365. +/**
  109366. + * This union represents the bit fields in the Host Channel Transfer Size
  109367. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109368. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  109369. + * hcchar register.
  109370. + */
  109371. +
  109372. +typedef union hctsiz_data {
  109373. + /** raw register data */
  109374. + uint32_t d32;
  109375. +
  109376. + /** register bits */
  109377. + struct {
  109378. + /** Total transfer size in bytes */
  109379. + unsigned xfersize:19;
  109380. +
  109381. + /** Data packets to transfer */
  109382. + unsigned pktcnt:10;
  109383. +
  109384. + /**
  109385. + * Packet ID for next data packet
  109386. + * 0: DATA0
  109387. + * 1: DATA2
  109388. + * 2: DATA1
  109389. + * 3: MDATA (non-Control), SETUP (Control)
  109390. + */
  109391. + unsigned pid:2;
  109392. +#define DWC_HCTSIZ_DATA0 0
  109393. +#define DWC_HCTSIZ_DATA1 2
  109394. +#define DWC_HCTSIZ_DATA2 1
  109395. +#define DWC_HCTSIZ_MDATA 3
  109396. +#define DWC_HCTSIZ_SETUP 3
  109397. +
  109398. + /** Do PING protocol when 1 */
  109399. + unsigned dopng:1;
  109400. + } b;
  109401. +
  109402. + /** register bits */
  109403. + struct {
  109404. + /** Scheduling information */
  109405. + unsigned schinfo:8;
  109406. +
  109407. + /** Number of transfer descriptors.
  109408. + * Max value:
  109409. + * 64 in general,
  109410. + * 256 only for HS isochronous endpoint.
  109411. + */
  109412. + unsigned ntd:8;
  109413. +
  109414. + /** Data packets to transfer */
  109415. + unsigned reserved16_28:13;
  109416. +
  109417. + /**
  109418. + * Packet ID for next data packet
  109419. + * 0: DATA0
  109420. + * 1: DATA2
  109421. + * 2: DATA1
  109422. + * 3: MDATA (non-Control)
  109423. + */
  109424. + unsigned pid:2;
  109425. +
  109426. + /** Do PING protocol when 1 */
  109427. + unsigned dopng:1;
  109428. + } b_ddma;
  109429. +} hctsiz_data_t;
  109430. +
  109431. +/**
  109432. + * This union represents the bit fields in the Host DMA Address
  109433. + * Register used in Descriptor DMA mode.
  109434. + */
  109435. +typedef union hcdma_data {
  109436. + /** raw register data */
  109437. + uint32_t d32;
  109438. + /** register bits */
  109439. + struct {
  109440. + unsigned reserved0_2:3;
  109441. + /** Current Transfer Descriptor. Not used for ISOC */
  109442. + unsigned ctd:8;
  109443. + /** Start Address of Descriptor List */
  109444. + unsigned dma_addr:21;
  109445. + } b;
  109446. +} hcdma_data_t;
  109447. +
  109448. +/**
  109449. + * This union represents the bit fields in the DMA Descriptor
  109450. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  109451. + * set/clear the bits using the <i>b</i>it elements.
  109452. + */
  109453. +typedef union host_dma_desc_sts {
  109454. + /** raw register data */
  109455. + uint32_t d32;
  109456. + /** quadlet bits */
  109457. +
  109458. + /* for non-isochronous */
  109459. + struct {
  109460. + /** Number of bytes */
  109461. + unsigned n_bytes:17;
  109462. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  109463. + unsigned qtd_offset:6;
  109464. + /**
  109465. + * Set to request the core to jump to alternate QTD if
  109466. + * Short Packet received - only for IN EPs
  109467. + */
  109468. + unsigned a_qtd:1;
  109469. + /**
  109470. + * Setup Packet bit. When set indicates that buffer contains
  109471. + * setup packet.
  109472. + */
  109473. + unsigned sup:1;
  109474. + /** Interrupt On Complete */
  109475. + unsigned ioc:1;
  109476. + /** End of List */
  109477. + unsigned eol:1;
  109478. + unsigned reserved27:1;
  109479. + /** Rx/Tx Status */
  109480. + unsigned sts:2;
  109481. +#define DMA_DESC_STS_PKTERR 1
  109482. + unsigned reserved30:1;
  109483. + /** Active Bit */
  109484. + unsigned a:1;
  109485. + } b;
  109486. + /* for isochronous */
  109487. + struct {
  109488. + /** Number of bytes */
  109489. + unsigned n_bytes:12;
  109490. + unsigned reserved12_24:13;
  109491. + /** Interrupt On Complete */
  109492. + unsigned ioc:1;
  109493. + unsigned reserved26_27:2;
  109494. + /** Rx/Tx Status */
  109495. + unsigned sts:2;
  109496. + unsigned reserved30:1;
  109497. + /** Active Bit */
  109498. + unsigned a:1;
  109499. + } b_isoc;
  109500. +} host_dma_desc_sts_t;
  109501. +
  109502. +#define MAX_DMA_DESC_SIZE 131071
  109503. +#define MAX_DMA_DESC_NUM_GENERIC 64
  109504. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  109505. +#define MAX_FRLIST_EN_NUM 64
  109506. +/**
  109507. + * Host-mode DMA Descriptor structure
  109508. + *
  109509. + * DMA Descriptor structure contains two quadlets:
  109510. + * Status quadlet and Data buffer pointer.
  109511. + */
  109512. +typedef struct dwc_otg_host_dma_desc {
  109513. + /** DMA Descriptor status quadlet */
  109514. + host_dma_desc_sts_t status;
  109515. + /** DMA Descriptor data buffer pointer */
  109516. + uint32_t buf;
  109517. +} dwc_otg_host_dma_desc_t;
  109518. +
  109519. +/** OTG Host Interface Structure.
  109520. + *
  109521. + * The OTG Host Interface Structure structure contains information
  109522. + * needed to manage the DWC_otg controller acting in host mode. It
  109523. + * represents the programming view of the host-specific aspects of the
  109524. + * controller.
  109525. + */
  109526. +typedef struct dwc_otg_host_if {
  109527. + /** Host Global Registers starting at offset 400h.*/
  109528. + dwc_otg_host_global_regs_t *host_global_regs;
  109529. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  109530. +
  109531. + /** Host Port 0 Control and Status Register */
  109532. + volatile uint32_t *hprt0;
  109533. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  109534. +
  109535. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  109536. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  109537. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  109538. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  109539. +
  109540. + /* Host configuration information */
  109541. + /** Number of Host Channels (range: 1-16) */
  109542. + uint8_t num_host_channels;
  109543. + /** Periodic EPs supported (0: no, 1: yes) */
  109544. + uint8_t perio_eps_supported;
  109545. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  109546. + uint16_t perio_tx_fifo_size;
  109547. +
  109548. +} dwc_otg_host_if_t;
  109549. +
  109550. +/**
  109551. + * This union represents the bit fields in the Power and Clock Gating Control
  109552. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109553. + * bits using the <i>b</i>it elements.
  109554. + */
  109555. +typedef union pcgcctl_data {
  109556. + /** raw register data */
  109557. + uint32_t d32;
  109558. +
  109559. + /** register bits */
  109560. + struct {
  109561. + /** Stop Pclk */
  109562. + unsigned stoppclk:1;
  109563. + /** Gate Hclk */
  109564. + unsigned gatehclk:1;
  109565. + /** Power Clamp */
  109566. + unsigned pwrclmp:1;
  109567. + /** Reset Power Down Modules */
  109568. + unsigned rstpdwnmodule:1;
  109569. + /** Reserved */
  109570. + unsigned reserved:1;
  109571. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  109572. + unsigned enbl_sleep_gating:1;
  109573. + /** PHY In Sleep (PhySleep) */
  109574. + unsigned phy_in_sleep:1;
  109575. + /** Deep Sleep*/
  109576. + unsigned deep_sleep:1;
  109577. + unsigned resetaftsusp:1;
  109578. + unsigned restoremode:1;
  109579. + unsigned enbl_extnd_hiber:1;
  109580. + unsigned extnd_hiber_pwrclmp:1;
  109581. + unsigned extnd_hiber_switch:1;
  109582. + unsigned ess_reg_restored:1;
  109583. + unsigned prt_clk_sel:2;
  109584. + unsigned port_power:1;
  109585. + unsigned max_xcvrselect:2;
  109586. + unsigned max_termsel:1;
  109587. + unsigned mac_dev_addr:7;
  109588. + unsigned p2hd_dev_enum_spd:2;
  109589. + unsigned p2hd_prt_spd:2;
  109590. + unsigned if_dev_mode:1;
  109591. + } b;
  109592. +} pcgcctl_data_t;
  109593. +
  109594. +/**
  109595. + * This union represents the bit fields in the Global Data FIFO Software
  109596. + * Configuration Register. Read the register into the <i>d32</i> member then
  109597. + * set/clear the bits using the <i>b</i>it elements.
  109598. + */
  109599. +typedef union gdfifocfg_data {
  109600. + /* raw register data */
  109601. + uint32_t d32;
  109602. + /** register bits */
  109603. + struct {
  109604. + /** OTG Data FIFO depth */
  109605. + unsigned gdfifocfg:16;
  109606. + /** Start address of EP info controller */
  109607. + unsigned epinfobase:16;
  109608. + } b;
  109609. +} gdfifocfg_data_t;
  109610. +
  109611. +/**
  109612. + * This union represents the bit fields in the Global Power Down Register
  109613. + * Register. Read the register into the <i>d32</i> member then set/clear the
  109614. + * bits using the <i>b</i>it elements.
  109615. + */
  109616. +typedef union gpwrdn_data {
  109617. + /* raw register data */
  109618. + uint32_t d32;
  109619. +
  109620. + /** register bits */
  109621. + struct {
  109622. + /** PMU Interrupt Select */
  109623. + unsigned pmuintsel:1;
  109624. + /** PMU Active */
  109625. + unsigned pmuactv:1;
  109626. + /** Restore */
  109627. + unsigned restore:1;
  109628. + /** Power Down Clamp */
  109629. + unsigned pwrdnclmp:1;
  109630. + /** Power Down Reset */
  109631. + unsigned pwrdnrstn:1;
  109632. + /** Power Down Switch */
  109633. + unsigned pwrdnswtch:1;
  109634. + /** Disable VBUS */
  109635. + unsigned dis_vbus:1;
  109636. + /** Line State Change */
  109637. + unsigned lnstschng:1;
  109638. + /** Line state change mask */
  109639. + unsigned lnstchng_msk:1;
  109640. + /** Reset Detected */
  109641. + unsigned rst_det:1;
  109642. + /** Reset Detect mask */
  109643. + unsigned rst_det_msk:1;
  109644. + /** Disconnect Detected */
  109645. + unsigned disconn_det:1;
  109646. + /** Disconnect Detect mask */
  109647. + unsigned disconn_det_msk:1;
  109648. + /** Connect Detected*/
  109649. + unsigned connect_det:1;
  109650. + /** Connect Detected Mask*/
  109651. + unsigned connect_det_msk:1;
  109652. + /** SRP Detected */
  109653. + unsigned srp_det:1;
  109654. + /** SRP Detect mask */
  109655. + unsigned srp_det_msk:1;
  109656. + /** Status Change Interrupt */
  109657. + unsigned sts_chngint:1;
  109658. + /** Status Change Interrupt Mask */
  109659. + unsigned sts_chngint_msk:1;
  109660. + /** Line State */
  109661. + unsigned linestate:2;
  109662. + /** Indicates current mode(status of IDDIG signal) */
  109663. + unsigned idsts:1;
  109664. + /** B Session Valid signal status*/
  109665. + unsigned bsessvld:1;
  109666. + /** ADP Event Detected */
  109667. + unsigned adp_int:1;
  109668. + /** Multi Valued ID pin */
  109669. + unsigned mult_val_id_bc:5;
  109670. + /** Reserved 24_31 */
  109671. + unsigned reserved29_31:3;
  109672. + } b;
  109673. +} gpwrdn_data_t;
  109674. +
  109675. +#endif
  109676. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  109677. --- linux-3.12.38/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  109678. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2015-03-09 10:39:33.214893718 +0100
  109679. @@ -0,0 +1,82 @@
  109680. +#
  109681. +# Makefile for DWC_otg Highspeed USB controller driver
  109682. +#
  109683. +
  109684. +ifneq ($(KERNELRELEASE),)
  109685. +
  109686. +# Use the BUS_INTERFACE variable to compile the software for either
  109687. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  109688. +ifeq ($(BUS_INTERFACE),)
  109689. +# BUS_INTERFACE = -DPCI_INTERFACE
  109690. +# BUS_INTERFACE = -DLM_INTERFACE
  109691. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  109692. +endif
  109693. +
  109694. +#ccflags-y += -DDEBUG
  109695. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  109696. +
  109697. +# Use one of the following flags to compile the software in host-only or
  109698. +# device-only mode.
  109699. +#ccflags-y += -DDWC_HOST_ONLY
  109700. +#ccflags-y += -DDWC_DEVICE_ONLY
  109701. +
  109702. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  109703. +#ccflags-y += -DDWC_EN_ISOC
  109704. +ccflags-y += -I$(obj)/../dwc_common_port
  109705. +#ccflags-y += -I$(PORTLIB)
  109706. +ccflags-y += -DDWC_LINUX
  109707. +ccflags-y += $(CFI)
  109708. +ccflags-y += $(BUS_INTERFACE)
  109709. +#ccflags-y += -DDWC_DEV_SRPCAP
  109710. +
  109711. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  109712. +
  109713. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  109714. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  109715. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  109716. +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
  109717. +dwc_otg-objs += dwc_otg_adp.o
  109718. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  109719. +dwc_otg-objs += dwc_otg_fiq_stub.o
  109720. +ifneq ($(CFI),)
  109721. +dwc_otg-objs += dwc_otg_cfi.o
  109722. +endif
  109723. +
  109724. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  109725. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  109726. +
  109727. +ifneq ($(kernrel3),2.6.20)
  109728. +ccflags-y += $(CPPFLAGS)
  109729. +endif
  109730. +
  109731. +else
  109732. +
  109733. +PWD := $(shell pwd)
  109734. +PORTLIB := $(PWD)/../dwc_common_port
  109735. +
  109736. +# Command paths
  109737. +CTAGS := $(CTAGS)
  109738. +DOXYGEN := $(DOXYGEN)
  109739. +
  109740. +default: portlib
  109741. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  109742. +
  109743. +install: default
  109744. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  109745. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  109746. +
  109747. +portlib:
  109748. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  109749. + cp $(PORTLIB)/Module.symvers $(PWD)/
  109750. +
  109751. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  109752. + $(DOXYGEN) doc/doxygen.cfg
  109753. +
  109754. +tags: $(wildcard *.[hc])
  109755. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  109756. +
  109757. +
  109758. +clean:
  109759. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  109760. +
  109761. +endif
  109762. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  109763. --- linux-3.12.38/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  109764. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2015-03-09 10:39:33.222893718 +0100
  109765. @@ -0,0 +1,337 @@
  109766. +package dwc_otg_test;
  109767. +
  109768. +use strict;
  109769. +use Exporter ();
  109770. +
  109771. +use vars qw(@ISA @EXPORT
  109772. +$sysfsdir $paramdir $errors $params
  109773. +);
  109774. +
  109775. +@ISA = qw(Exporter);
  109776. +
  109777. +#
  109778. +# Globals
  109779. +#
  109780. +$sysfsdir = "/sys/devices/lm0";
  109781. +$paramdir = "/sys/module/dwc_otg";
  109782. +$errors = 0;
  109783. +
  109784. +$params = [
  109785. + {
  109786. + NAME => "otg_cap",
  109787. + DEFAULT => 0,
  109788. + ENUM => [],
  109789. + LOW => 0,
  109790. + HIGH => 2
  109791. + },
  109792. + {
  109793. + NAME => "dma_enable",
  109794. + DEFAULT => 0,
  109795. + ENUM => [],
  109796. + LOW => 0,
  109797. + HIGH => 1
  109798. + },
  109799. + {
  109800. + NAME => "dma_burst_size",
  109801. + DEFAULT => 32,
  109802. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  109803. + LOW => 1,
  109804. + HIGH => 256
  109805. + },
  109806. + {
  109807. + NAME => "host_speed",
  109808. + DEFAULT => 0,
  109809. + ENUM => [],
  109810. + LOW => 0,
  109811. + HIGH => 1
  109812. + },
  109813. + {
  109814. + NAME => "host_support_fs_ls_low_power",
  109815. + DEFAULT => 0,
  109816. + ENUM => [],
  109817. + LOW => 0,
  109818. + HIGH => 1
  109819. + },
  109820. + {
  109821. + NAME => "host_ls_low_power_phy_clk",
  109822. + DEFAULT => 0,
  109823. + ENUM => [],
  109824. + LOW => 0,
  109825. + HIGH => 1
  109826. + },
  109827. + {
  109828. + NAME => "dev_speed",
  109829. + DEFAULT => 0,
  109830. + ENUM => [],
  109831. + LOW => 0,
  109832. + HIGH => 1
  109833. + },
  109834. + {
  109835. + NAME => "enable_dynamic_fifo",
  109836. + DEFAULT => 1,
  109837. + ENUM => [],
  109838. + LOW => 0,
  109839. + HIGH => 1
  109840. + },
  109841. + {
  109842. + NAME => "data_fifo_size",
  109843. + DEFAULT => 8192,
  109844. + ENUM => [],
  109845. + LOW => 32,
  109846. + HIGH => 32768
  109847. + },
  109848. + {
  109849. + NAME => "dev_rx_fifo_size",
  109850. + DEFAULT => 1064,
  109851. + ENUM => [],
  109852. + LOW => 16,
  109853. + HIGH => 32768
  109854. + },
  109855. + {
  109856. + NAME => "dev_nperio_tx_fifo_size",
  109857. + DEFAULT => 1024,
  109858. + ENUM => [],
  109859. + LOW => 16,
  109860. + HIGH => 32768
  109861. + },
  109862. + {
  109863. + NAME => "dev_perio_tx_fifo_size_1",
  109864. + DEFAULT => 256,
  109865. + ENUM => [],
  109866. + LOW => 4,
  109867. + HIGH => 768
  109868. + },
  109869. + {
  109870. + NAME => "dev_perio_tx_fifo_size_2",
  109871. + DEFAULT => 256,
  109872. + ENUM => [],
  109873. + LOW => 4,
  109874. + HIGH => 768
  109875. + },
  109876. + {
  109877. + NAME => "dev_perio_tx_fifo_size_3",
  109878. + DEFAULT => 256,
  109879. + ENUM => [],
  109880. + LOW => 4,
  109881. + HIGH => 768
  109882. + },
  109883. + {
  109884. + NAME => "dev_perio_tx_fifo_size_4",
  109885. + DEFAULT => 256,
  109886. + ENUM => [],
  109887. + LOW => 4,
  109888. + HIGH => 768
  109889. + },
  109890. + {
  109891. + NAME => "dev_perio_tx_fifo_size_5",
  109892. + DEFAULT => 256,
  109893. + ENUM => [],
  109894. + LOW => 4,
  109895. + HIGH => 768
  109896. + },
  109897. + {
  109898. + NAME => "dev_perio_tx_fifo_size_6",
  109899. + DEFAULT => 256,
  109900. + ENUM => [],
  109901. + LOW => 4,
  109902. + HIGH => 768
  109903. + },
  109904. + {
  109905. + NAME => "dev_perio_tx_fifo_size_7",
  109906. + DEFAULT => 256,
  109907. + ENUM => [],
  109908. + LOW => 4,
  109909. + HIGH => 768
  109910. + },
  109911. + {
  109912. + NAME => "dev_perio_tx_fifo_size_8",
  109913. + DEFAULT => 256,
  109914. + ENUM => [],
  109915. + LOW => 4,
  109916. + HIGH => 768
  109917. + },
  109918. + {
  109919. + NAME => "dev_perio_tx_fifo_size_9",
  109920. + DEFAULT => 256,
  109921. + ENUM => [],
  109922. + LOW => 4,
  109923. + HIGH => 768
  109924. + },
  109925. + {
  109926. + NAME => "dev_perio_tx_fifo_size_10",
  109927. + DEFAULT => 256,
  109928. + ENUM => [],
  109929. + LOW => 4,
  109930. + HIGH => 768
  109931. + },
  109932. + {
  109933. + NAME => "dev_perio_tx_fifo_size_11",
  109934. + DEFAULT => 256,
  109935. + ENUM => [],
  109936. + LOW => 4,
  109937. + HIGH => 768
  109938. + },
  109939. + {
  109940. + NAME => "dev_perio_tx_fifo_size_12",
  109941. + DEFAULT => 256,
  109942. + ENUM => [],
  109943. + LOW => 4,
  109944. + HIGH => 768
  109945. + },
  109946. + {
  109947. + NAME => "dev_perio_tx_fifo_size_13",
  109948. + DEFAULT => 256,
  109949. + ENUM => [],
  109950. + LOW => 4,
  109951. + HIGH => 768
  109952. + },
  109953. + {
  109954. + NAME => "dev_perio_tx_fifo_size_14",
  109955. + DEFAULT => 256,
  109956. + ENUM => [],
  109957. + LOW => 4,
  109958. + HIGH => 768
  109959. + },
  109960. + {
  109961. + NAME => "dev_perio_tx_fifo_size_15",
  109962. + DEFAULT => 256,
  109963. + ENUM => [],
  109964. + LOW => 4,
  109965. + HIGH => 768
  109966. + },
  109967. + {
  109968. + NAME => "host_rx_fifo_size",
  109969. + DEFAULT => 1024,
  109970. + ENUM => [],
  109971. + LOW => 16,
  109972. + HIGH => 32768
  109973. + },
  109974. + {
  109975. + NAME => "host_nperio_tx_fifo_size",
  109976. + DEFAULT => 1024,
  109977. + ENUM => [],
  109978. + LOW => 16,
  109979. + HIGH => 32768
  109980. + },
  109981. + {
  109982. + NAME => "host_perio_tx_fifo_size",
  109983. + DEFAULT => 1024,
  109984. + ENUM => [],
  109985. + LOW => 16,
  109986. + HIGH => 32768
  109987. + },
  109988. + {
  109989. + NAME => "max_transfer_size",
  109990. + DEFAULT => 65535,
  109991. + ENUM => [],
  109992. + LOW => 2047,
  109993. + HIGH => 65535
  109994. + },
  109995. + {
  109996. + NAME => "max_packet_count",
  109997. + DEFAULT => 511,
  109998. + ENUM => [],
  109999. + LOW => 15,
  110000. + HIGH => 511
  110001. + },
  110002. + {
  110003. + NAME => "host_channels",
  110004. + DEFAULT => 12,
  110005. + ENUM => [],
  110006. + LOW => 1,
  110007. + HIGH => 16
  110008. + },
  110009. + {
  110010. + NAME => "dev_endpoints",
  110011. + DEFAULT => 6,
  110012. + ENUM => [],
  110013. + LOW => 1,
  110014. + HIGH => 15
  110015. + },
  110016. + {
  110017. + NAME => "phy_type",
  110018. + DEFAULT => 1,
  110019. + ENUM => [],
  110020. + LOW => 0,
  110021. + HIGH => 2
  110022. + },
  110023. + {
  110024. + NAME => "phy_utmi_width",
  110025. + DEFAULT => 16,
  110026. + ENUM => [8, 16],
  110027. + LOW => 8,
  110028. + HIGH => 16
  110029. + },
  110030. + {
  110031. + NAME => "phy_ulpi_ddr",
  110032. + DEFAULT => 0,
  110033. + ENUM => [],
  110034. + LOW => 0,
  110035. + HIGH => 1
  110036. + },
  110037. + ];
  110038. +
  110039. +
  110040. +#
  110041. +#
  110042. +sub check_arch {
  110043. + $_ = `uname -m`;
  110044. + chomp;
  110045. + unless (m/armv4tl/) {
  110046. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  110047. + return 0;
  110048. + }
  110049. + return 1;
  110050. +}
  110051. +
  110052. +#
  110053. +#
  110054. +sub load_module {
  110055. + my $params = shift;
  110056. + print "\nRemoving Module\n";
  110057. + system "rmmod dwc_otg";
  110058. + print "Loading Module\n";
  110059. + if ($params ne "") {
  110060. + print "Module Parameters: $params\n";
  110061. + }
  110062. + if (system("modprobe dwc_otg $params")) {
  110063. + warn "Unable to load module\n";
  110064. + return 0;
  110065. + }
  110066. + return 1;
  110067. +}
  110068. +
  110069. +#
  110070. +#
  110071. +sub test_status {
  110072. + my $arg = shift;
  110073. +
  110074. + print "\n";
  110075. +
  110076. + if (defined $arg) {
  110077. + warn "WARNING: $arg\n";
  110078. + }
  110079. +
  110080. + if ($errors > 0) {
  110081. + warn "TEST FAILED with $errors errors\n";
  110082. + return 0;
  110083. + } else {
  110084. + print "TEST PASSED\n";
  110085. + return 0 if (defined $arg);
  110086. + }
  110087. + return 1;
  110088. +}
  110089. +
  110090. +#
  110091. +#
  110092. +@EXPORT = qw(
  110093. +$sysfsdir
  110094. +$paramdir
  110095. +$params
  110096. +$errors
  110097. +check_arch
  110098. +load_module
  110099. +test_status
  110100. +);
  110101. +
  110102. +1;
  110103. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  110104. --- linux-3.12.38/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  110105. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2015-03-09 10:39:33.222893718 +0100
  110106. @@ -0,0 +1,16 @@
  110107. +
  110108. +PERL=/usr/bin/perl
  110109. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  110110. +
  110111. +.PHONY : test
  110112. +test : perl_tests
  110113. +
  110114. +perl_tests :
  110115. + @echo
  110116. + @echo Running perl tests
  110117. + @for test in $(PL_TESTS); do \
  110118. + if $(PERL) ./$$test ; then \
  110119. + echo "=======> $$test, PASSED" ; \
  110120. + else echo "=======> $$test, FAILED" ; \
  110121. + fi \
  110122. + done
  110123. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  110124. --- linux-3.12.38/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  110125. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2015-03-09 10:39:33.222893718 +0100
  110126. @@ -0,0 +1,133 @@
  110127. +#!/usr/bin/perl -w
  110128. +#
  110129. +# Run this program on the integrator.
  110130. +#
  110131. +# - Tests module parameter default values.
  110132. +# - Tests setting of valid module parameter values via modprobe.
  110133. +# - Tests invalid module parameter values.
  110134. +# -----------------------------------------------------------------------------
  110135. +use strict;
  110136. +use dwc_otg_test;
  110137. +
  110138. +check_arch() or die;
  110139. +
  110140. +#
  110141. +#
  110142. +sub test {
  110143. + my ($param,$expected) = @_;
  110144. + my $value = get($param);
  110145. +
  110146. + if ($value == $expected) {
  110147. + print "$param = $value, okay\n";
  110148. + }
  110149. +
  110150. + else {
  110151. + warn "ERROR: value of $param != $expected, $value\n";
  110152. + $errors ++;
  110153. + }
  110154. +}
  110155. +
  110156. +#
  110157. +#
  110158. +sub get {
  110159. + my $param = shift;
  110160. + my $tmp = `cat $paramdir/$param`;
  110161. + chomp $tmp;
  110162. + return $tmp;
  110163. +}
  110164. +
  110165. +#
  110166. +#
  110167. +sub test_main {
  110168. +
  110169. + print "\nTesting Module Parameters\n";
  110170. +
  110171. + load_module("") or die;
  110172. +
  110173. + # Test initial values
  110174. + print "\nTesting Default Values\n";
  110175. + foreach (@{$params}) {
  110176. + test ($_->{NAME}, $_->{DEFAULT});
  110177. + }
  110178. +
  110179. + # Test low value
  110180. + print "\nTesting Low Value\n";
  110181. + my $cmd_params = "";
  110182. + foreach (@{$params}) {
  110183. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  110184. + }
  110185. + load_module($cmd_params) or die;
  110186. +
  110187. + foreach (@{$params}) {
  110188. + test ($_->{NAME}, $_->{LOW});
  110189. + }
  110190. +
  110191. + # Test high value
  110192. + print "\nTesting High Value\n";
  110193. + $cmd_params = "";
  110194. + foreach (@{$params}) {
  110195. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  110196. + }
  110197. + load_module($cmd_params) or die;
  110198. +
  110199. + foreach (@{$params}) {
  110200. + test ($_->{NAME}, $_->{HIGH});
  110201. + }
  110202. +
  110203. + # Test Enum
  110204. + print "\nTesting Enumerated\n";
  110205. + foreach (@{$params}) {
  110206. + if (defined $_->{ENUM}) {
  110207. + my $value;
  110208. + foreach $value (@{$_->{ENUM}}) {
  110209. + $cmd_params = "$_->{NAME}=$value";
  110210. + load_module($cmd_params) or die;
  110211. + test ($_->{NAME}, $value);
  110212. + }
  110213. + }
  110214. + }
  110215. +
  110216. + # Test Invalid Values
  110217. + print "\nTesting Invalid Values\n";
  110218. + $cmd_params = "";
  110219. + foreach (@{$params}) {
  110220. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  110221. + }
  110222. + load_module($cmd_params) or die;
  110223. +
  110224. + foreach (@{$params}) {
  110225. + test ($_->{NAME}, $_->{DEFAULT});
  110226. + }
  110227. +
  110228. + $cmd_params = "";
  110229. + foreach (@{$params}) {
  110230. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  110231. + }
  110232. + load_module($cmd_params) or die;
  110233. +
  110234. + foreach (@{$params}) {
  110235. + test ($_->{NAME}, $_->{DEFAULT});
  110236. + }
  110237. +
  110238. + print "\nTesting Enumerated\n";
  110239. + foreach (@{$params}) {
  110240. + if (defined $_->{ENUM}) {
  110241. + my $value;
  110242. + foreach $value (@{$_->{ENUM}}) {
  110243. + $value = $value + 1;
  110244. + $cmd_params = "$_->{NAME}=$value";
  110245. + load_module($cmd_params) or die;
  110246. + test ($_->{NAME}, $_->{DEFAULT});
  110247. + $value = $value - 2;
  110248. + $cmd_params = "$_->{NAME}=$value";
  110249. + load_module($cmd_params) or die;
  110250. + test ($_->{NAME}, $_->{DEFAULT});
  110251. + }
  110252. + }
  110253. + }
  110254. +
  110255. + test_status() or die;
  110256. +}
  110257. +
  110258. +test_main();
  110259. +0;
  110260. diff -Nur linux-3.12.38/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  110261. --- linux-3.12.38/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  110262. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2015-03-09 10:39:33.222893718 +0100
  110263. @@ -0,0 +1,193 @@
  110264. +#!/usr/bin/perl -w
  110265. +#
  110266. +# Run this program on the integrator
  110267. +# - Tests select sysfs attributes.
  110268. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  110269. +# -----------------------------------------------------------------------------
  110270. +use strict;
  110271. +use dwc_otg_test;
  110272. +
  110273. +check_arch() or die;
  110274. +
  110275. +#
  110276. +#
  110277. +sub test {
  110278. + my ($attr,$expected) = @_;
  110279. + my $string = get($attr);
  110280. +
  110281. + if ($string eq $expected) {
  110282. + printf("$attr = $string, okay\n");
  110283. + }
  110284. + else {
  110285. + warn "ERROR: value of $attr != $expected, $string\n";
  110286. + $errors ++;
  110287. + }
  110288. +}
  110289. +
  110290. +#
  110291. +#
  110292. +sub set {
  110293. + my ($reg, $value) = @_;
  110294. + system "echo $value > $sysfsdir/$reg";
  110295. +}
  110296. +
  110297. +#
  110298. +#
  110299. +sub get {
  110300. + my $attr = shift;
  110301. + my $string = `cat $sysfsdir/$attr`;
  110302. + chomp $string;
  110303. + if ($string =~ m/\s\=\s/) {
  110304. + my $tmp;
  110305. + ($tmp, $string) = split /\s=\s/, $string;
  110306. + }
  110307. + return $string;
  110308. +}
  110309. +
  110310. +#
  110311. +#
  110312. +sub test_main {
  110313. + print("\nTesting Sysfs Attributes\n");
  110314. +
  110315. + load_module("") or die;
  110316. +
  110317. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  110318. + print("\nTesting Default Values\n");
  110319. +
  110320. + test("regoffset", "0xffffffff");
  110321. + test("regvalue", "invalid offset");
  110322. + test("guid", "0x12345678"); # this will fail if it has been changed
  110323. + test("gsnpsid", "0x4f54200a");
  110324. +
  110325. + # Test operation of regoffset/regvalue
  110326. + print("\nTesting regoffset\n");
  110327. + set('regoffset', '5a5a5a5a');
  110328. + test("regoffset", "0xffffffff");
  110329. +
  110330. + set('regoffset', '0');
  110331. + test("regoffset", "0x00000000");
  110332. +
  110333. + set('regoffset', '40000');
  110334. + test("regoffset", "0x00000000");
  110335. +
  110336. + set('regoffset', '3ffff');
  110337. + test("regoffset", "0x0003ffff");
  110338. +
  110339. + set('regoffset', '1');
  110340. + test("regoffset", "0x00000001");
  110341. +
  110342. + print("\nTesting regvalue\n");
  110343. + set('regoffset', '3c');
  110344. + test("regvalue", "0x12345678");
  110345. + set('regvalue', '5a5a5a5a');
  110346. + test("regvalue", "0x5a5a5a5a");
  110347. + set('regvalue','a5a5a5a5');
  110348. + test("regvalue", "0xa5a5a5a5");
  110349. + set('guid','12345678');
  110350. +
  110351. + # Test HNP Capable
  110352. + print("\nTesting HNP Capable bit\n");
  110353. + set('hnpcapable', '1');
  110354. + test("hnpcapable", "0x1");
  110355. + set('hnpcapable','0');
  110356. + test("hnpcapable", "0x0");
  110357. +
  110358. + set('regoffset','0c');
  110359. +
  110360. + my $old = get('gusbcfg');
  110361. + print("setting hnpcapable\n");
  110362. + set('hnpcapable', '1');
  110363. + test("hnpcapable", "0x1");
  110364. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  110365. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  110366. +
  110367. + $old = get('gusbcfg');
  110368. + print("clearing hnpcapable\n");
  110369. + set('hnpcapable', '0');
  110370. + test("hnpcapable", "0x0");
  110371. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  110372. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  110373. +
  110374. + # Test SRP Capable
  110375. + print("\nTesting SRP Capable bit\n");
  110376. + set('srpcapable', '1');
  110377. + test("srpcapable", "0x1");
  110378. + set('srpcapable','0');
  110379. + test("srpcapable", "0x0");
  110380. +
  110381. + set('regoffset','0c');
  110382. +
  110383. + $old = get('gusbcfg');
  110384. + print("setting srpcapable\n");
  110385. + set('srpcapable', '1');
  110386. + test("srpcapable", "0x1");
  110387. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  110388. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  110389. +
  110390. + $old = get('gusbcfg');
  110391. + print("clearing srpcapable\n");
  110392. + set('srpcapable', '0');
  110393. + test("srpcapable", "0x0");
  110394. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  110395. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  110396. +
  110397. + # Test GGPIO
  110398. + print("\nTesting GGPIO\n");
  110399. + set('ggpio','5a5a5a5a');
  110400. + test('ggpio','0x5a5a0000');
  110401. + set('ggpio','a5a5a5a5');
  110402. + test('ggpio','0xa5a50000');
  110403. + set('ggpio','11110000');
  110404. + test('ggpio','0x11110000');
  110405. + set('ggpio','00001111');
  110406. + test('ggpio','0x00000000');
  110407. +
  110408. + # Test DEVSPEED
  110409. + print("\nTesting DEVSPEED\n");
  110410. + set('regoffset','800');
  110411. + $old = get('regvalue');
  110412. + set('devspeed','0');
  110413. + test('devspeed','0x0');
  110414. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  110415. + set('devspeed','1');
  110416. + test('devspeed','0x1');
  110417. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  110418. + set('devspeed','2');
  110419. + test('devspeed','0x2');
  110420. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  110421. + set('devspeed','3');
  110422. + test('devspeed','0x3');
  110423. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  110424. + set('devspeed','4');
  110425. + test('devspeed','0x0');
  110426. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  110427. + set('devspeed','5');
  110428. + test('devspeed','0x1');
  110429. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  110430. +
  110431. +
  110432. + # mode Returns the current mode:0 for device mode1 for host mode Read
  110433. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  110434. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  110435. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  110436. + # bussuspend Suspend the USB bus. Read/Write
  110437. + # busconnected Get the connection status of the bus Read
  110438. +
  110439. + # gotgctl Get or set the Core Control Status Register. Read/Write
  110440. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  110441. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  110442. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  110443. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  110444. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  110445. + ## guid Get or set the value of the User ID Register Read/Write
  110446. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  110447. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  110448. + # enumspeed Gets the device enumeration Speed. Read
  110449. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  110450. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  110451. +
  110452. + test_status("TEST NYI") or die;
  110453. +}
  110454. +
  110455. +test_main();
  110456. +0;
  110457. diff -Nur linux-3.12.38/drivers/usb/host/ehci-sched.c linux-rpi/drivers/usb/host/ehci-sched.c
  110458. --- linux-3.12.38/drivers/usb/host/ehci-sched.c 2015-02-16 16:15:42.000000000 +0100
  110459. +++ linux-rpi/drivers/usb/host/ehci-sched.c 2015-03-10 17:26:51.306216687 +0100
  110460. @@ -1384,10 +1384,6 @@
  110461. now = ehci_read_frame_index(ehci) & (mod - 1);
  110462. - /* If needed, initialize last_iso_frame so that this URB will be seen */
  110463. - if (ehci->isoc_count == 0)
  110464. - ehci->last_iso_frame = now >> 3;
  110465. -
  110466. /* Typical case: reuse current schedule, stream is still active.
  110467. * Hopefully there are no gaps from the host falling behind
  110468. * (irq delays etc). If there are, the behavior depends on
  110469. @@ -1497,6 +1493,10 @@
  110470. urb->start_frame = stream->next_uframe;
  110471. if (!stream->highspeed)
  110472. urb->start_frame >>= 3;
  110473. +
  110474. + /* Make sure scan_isoc() sees these */
  110475. + if (ehci->isoc_count == 0)
  110476. + ehci->last_iso_frame = now >> 3;
  110477. return 0;
  110478. fail:
  110479. diff -Nur linux-3.12.38/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  110480. --- linux-3.12.38/drivers/usb/host/Kconfig 2015-02-16 16:15:42.000000000 +0100
  110481. +++ linux-rpi/drivers/usb/host/Kconfig 2015-03-10 17:26:51.302216687 +0100
  110482. @@ -650,6 +650,19 @@
  110483. To compile this driver a module, choose M here: the module
  110484. will be called "hwa-hc".
  110485. +config USB_DWCOTG
  110486. + tristate "Synopsis DWC host support"
  110487. + depends on USB
  110488. + help
  110489. + The Synopsis DWC controller is a dual-role
  110490. + host/peripheral/OTG ("On The Go") USB controllers.
  110491. +
  110492. + Enable this option to support this IP in host controller mode.
  110493. + If unsure, say N.
  110494. +
  110495. + To compile this driver as a module, choose M here: the
  110496. + modules built will be called dwc_otg and dwc_common_port.
  110497. +
  110498. config USB_IMX21_HCD
  110499. tristate "i.MX21 HCD support"
  110500. depends on ARM && ARCH_MXC
  110501. diff -Nur linux-3.12.38/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  110502. --- linux-3.12.38/drivers/usb/host/Makefile 2015-02-16 16:15:42.000000000 +0100
  110503. +++ linux-rpi/drivers/usb/host/Makefile 2015-03-10 17:26:51.302216687 +0100
  110504. @@ -56,6 +56,8 @@
  110505. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  110506. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  110507. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  110508. +
  110509. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  110510. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  110511. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  110512. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  110513. diff -Nur linux-3.12.38/drivers/usb/host/pci-quirks.c linux-rpi/drivers/usb/host/pci-quirks.c
  110514. --- linux-3.12.38/drivers/usb/host/pci-quirks.c 2015-02-16 16:15:42.000000000 +0100
  110515. +++ linux-rpi/drivers/usb/host/pci-quirks.c 2015-03-10 17:26:51.314216687 +0100
  110516. @@ -560,8 +560,7 @@
  110517. {
  110518. void __iomem *base;
  110519. u32 control;
  110520. - u32 fminterval = 0;
  110521. - bool no_fminterval = false;
  110522. + u32 fminterval;
  110523. int cnt;
  110524. if (!mmio_resource_enabled(pdev, 0))
  110525. @@ -571,13 +570,6 @@
  110526. if (base == NULL)
  110527. return;
  110528. - /*
  110529. - * ULi M5237 OHCI controller locks the whole system when accessing
  110530. - * the OHCI_FMINTERVAL offset.
  110531. - */
  110532. - if (pdev->vendor == PCI_VENDOR_ID_AL && pdev->device == 0x5237)
  110533. - no_fminterval = true;
  110534. -
  110535. control = readl(base + OHCI_CONTROL);
  110536. /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
  110537. @@ -616,9 +608,7 @@
  110538. }
  110539. /* software reset of the controller, preserving HcFmInterval */
  110540. - if (!no_fminterval)
  110541. - fminterval = readl(base + OHCI_FMINTERVAL);
  110542. -
  110543. + fminterval = readl(base + OHCI_FMINTERVAL);
  110544. writel(OHCI_HCR, base + OHCI_CMDSTATUS);
  110545. /* reset requires max 10 us delay */
  110546. @@ -627,9 +617,7 @@
  110547. break;
  110548. udelay(1);
  110549. }
  110550. -
  110551. - if (!no_fminterval)
  110552. - writel(fminterval, base + OHCI_FMINTERVAL);
  110553. + writel(fminterval, base + OHCI_FMINTERVAL);
  110554. /* Now the controller is safely in SUSPEND and nothing can wake it up */
  110555. iounmap(base);
  110556. diff -Nur linux-3.12.38/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  110557. --- linux-3.12.38/drivers/usb/Makefile 2015-02-16 16:15:42.000000000 +0100
  110558. +++ linux-rpi/drivers/usb/Makefile 2015-03-10 17:26:51.278216688 +0100
  110559. @@ -23,6 +23,7 @@
  110560. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  110561. obj-$(CONFIG_USB_HWA_HCD) += host/
  110562. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  110563. +obj-$(CONFIG_USB_DWCOTG) += host/
  110564. obj-$(CONFIG_USB_IMX21_HCD) += host/
  110565. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  110566. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  110567. diff -Nur linux-3.12.38/drivers/usb/misc/adutux.c linux-rpi/drivers/usb/misc/adutux.c
  110568. --- linux-3.12.38/drivers/usb/misc/adutux.c 2015-02-16 16:15:42.000000000 +0100
  110569. +++ linux-rpi/drivers/usb/misc/adutux.c 2015-03-10 17:26:51.318216687 +0100
  110570. @@ -815,10 +815,15 @@
  110571. usb_set_intfdata(interface, NULL);
  110572. /* if the device is not opened, then we clean up right now */
  110573. + dev_dbg(&dev->udev->dev, "%s : open count %d\n",
  110574. + __func__, dev->open_count);
  110575. if (!dev->open_count)
  110576. adu_delete(dev);
  110577. mutex_unlock(&adutux_mutex);
  110578. +
  110579. + dev_info(&interface->dev, "ADU device adutux%d now disconnected\n",
  110580. + (minor - ADU_MINOR_BASE));
  110581. }
  110582. /* usb specific object needed to register this driver with the usb subsystem */
  110583. diff -Nur linux-3.12.38/drivers/usb/musb/musb_cppi41.c linux-rpi/drivers/usb/musb/musb_cppi41.c
  110584. --- linux-3.12.38/drivers/usb/musb/musb_cppi41.c 2015-02-16 16:15:42.000000000 +0100
  110585. +++ linux-rpi/drivers/usb/musb/musb_cppi41.c 2015-03-10 17:26:51.322216687 +0100
  110586. @@ -586,9 +586,9 @@
  110587. ret = of_property_read_string_index(np, "dma-names", i, &str);
  110588. if (ret)
  110589. goto err;
  110590. - if (strstarts(str, "tx"))
  110591. + if (!strncmp(str, "tx", 2))
  110592. is_tx = 1;
  110593. - else if (strstarts(str, "rx"))
  110594. + else if (!strncmp(str, "rx", 2))
  110595. is_tx = 0;
  110596. else {
  110597. dev_err(dev, "Wrong dmatype %s\n", str);
  110598. diff -Nur linux-3.12.38/drivers/usb/musb/musb_debugfs.c linux-rpi/drivers/usb/musb/musb_debugfs.c
  110599. --- linux-3.12.38/drivers/usb/musb/musb_debugfs.c 2015-02-16 16:15:42.000000000 +0100
  110600. +++ linux-rpi/drivers/usb/musb/musb_debugfs.c 2015-03-09 10:39:33.242893718 +0100
  110601. @@ -194,30 +194,30 @@
  110602. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  110603. return -EFAULT;
  110604. - if (strstarts(buf, "force host"))
  110605. + if (!strncmp(buf, "force host", 9))
  110606. test = MUSB_TEST_FORCE_HOST;
  110607. - if (strstarts(buf, "fifo access"))
  110608. + if (!strncmp(buf, "fifo access", 11))
  110609. test = MUSB_TEST_FIFO_ACCESS;
  110610. - if (strstarts(buf, "force full-speed"))
  110611. + if (!strncmp(buf, "force full-speed", 15))
  110612. test = MUSB_TEST_FORCE_FS;
  110613. - if (strstarts(buf, "force high-speed"))
  110614. + if (!strncmp(buf, "force high-speed", 15))
  110615. test = MUSB_TEST_FORCE_HS;
  110616. - if (strstarts(buf, "test packet")) {
  110617. + if (!strncmp(buf, "test packet", 10)) {
  110618. test = MUSB_TEST_PACKET;
  110619. musb_load_testpacket(musb);
  110620. }
  110621. - if (strstarts(buf, "test K"))
  110622. + if (!strncmp(buf, "test K", 6))
  110623. test = MUSB_TEST_K;
  110624. - if (strstarts(buf, "test J"))
  110625. + if (!strncmp(buf, "test J", 6))
  110626. test = MUSB_TEST_J;
  110627. - if (strstarts(buf, "test SE0 NAK"))
  110628. + if (!strncmp(buf, "test SE0 NAK", 12))
  110629. test = MUSB_TEST_SE0_NAK;
  110630. musb_writeb(musb->mregs, MUSB_TESTMODE, test);
  110631. diff -Nur linux-3.12.38/drivers/usb/musb/musb_host.c linux-rpi/drivers/usb/musb/musb_host.c
  110632. --- linux-3.12.38/drivers/usb/musb/musb_host.c 2015-02-16 16:15:42.000000000 +0100
  110633. +++ linux-rpi/drivers/usb/musb/musb_host.c 2015-03-10 17:26:51.322216687 +0100
  110634. @@ -2631,6 +2631,7 @@
  110635. if (musb->port_mode == MUSB_PORT_MODE_GADGET)
  110636. return;
  110637. usb_remove_hcd(musb->hcd);
  110638. + musb->hcd = NULL;
  110639. }
  110640. void musb_host_free(struct musb *musb)
  110641. diff -Nur linux-3.12.38/drivers/usb/serial/console.c linux-rpi/drivers/usb/serial/console.c
  110642. --- linux-3.12.38/drivers/usb/serial/console.c 2015-02-16 16:15:42.000000000 +0100
  110643. +++ linux-rpi/drivers/usb/serial/console.c 2015-03-10 17:26:51.330216687 +0100
  110644. @@ -47,8 +47,6 @@
  110645. * ------------------------------------------------------------
  110646. */
  110647. -static const struct tty_operations usb_console_fake_tty_ops = {
  110648. -};
  110649. /*
  110650. * The parsing of the command line works exactly like the
  110651. @@ -141,18 +139,14 @@
  110652. goto reset_open_count;
  110653. }
  110654. kref_init(&tty->kref);
  110655. + tty_port_tty_set(&port->port, tty);
  110656. tty->driver = usb_serial_tty_driver;
  110657. tty->index = co->index;
  110658. - init_ldsem(&tty->ldisc_sem);
  110659. - INIT_LIST_HEAD(&tty->tty_files);
  110660. - kref_get(&tty->driver->kref);
  110661. - tty->ops = &usb_console_fake_tty_ops;
  110662. if (tty_init_termios(tty)) {
  110663. retval = -ENOMEM;
  110664. dev_err(&port->dev, "no more memory\n");
  110665. - goto put_tty;
  110666. + goto free_tty;
  110667. }
  110668. - tty_port_tty_set(&port->port, tty);
  110669. }
  110670. /* only call the device specific open if this
  110671. @@ -170,7 +164,7 @@
  110672. serial->type->set_termios(tty, port, &dummy);
  110673. tty_port_tty_set(&port->port, NULL);
  110674. - tty_kref_put(tty);
  110675. + kfree(tty);
  110676. }
  110677. set_bit(ASYNCB_INITIALIZED, &port->port.flags);
  110678. }
  110679. @@ -186,8 +180,8 @@
  110680. fail:
  110681. tty_port_tty_set(&port->port, NULL);
  110682. - put_tty:
  110683. - tty_kref_put(tty);
  110684. + free_tty:
  110685. + kfree(tty);
  110686. reset_open_count:
  110687. port->port.count = 0;
  110688. usb_autopm_put_interface(serial->interface);
  110689. diff -Nur linux-3.12.38/drivers/usb/serial/cp210x.c linux-rpi/drivers/usb/serial/cp210x.c
  110690. --- linux-3.12.38/drivers/usb/serial/cp210x.c 2015-02-16 16:15:42.000000000 +0100
  110691. +++ linux-rpi/drivers/usb/serial/cp210x.c 2015-03-10 17:26:51.330216687 +0100
  110692. @@ -120,12 +120,10 @@
  110693. { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */
  110694. { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */
  110695. { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */
  110696. - { USB_DEVICE(0x10C4, 0x8856) }, /* CEL EM357 ZigBee USB Stick - LR */
  110697. - { USB_DEVICE(0x10C4, 0x8857) }, /* CEL EM357 ZigBee USB Stick */
  110698. + { USB_DEVICE(0x10C4, 0x8875) }, /* CEL MeshConnect USB Stick */
  110699. { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */
  110700. { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
  110701. { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
  110702. - { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
  110703. { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
  110704. { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
  110705. { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */
  110706. diff -Nur linux-3.12.38/drivers/usb/serial/keyspan.c linux-rpi/drivers/usb/serial/keyspan.c
  110707. --- linux-3.12.38/drivers/usb/serial/keyspan.c 2015-02-16 16:15:42.000000000 +0100
  110708. +++ linux-rpi/drivers/usb/serial/keyspan.c 2015-03-10 17:26:51.334216687 +0100
  110709. @@ -422,8 +422,6 @@
  110710. }
  110711. port = serial->port[msg->port];
  110712. p_priv = usb_get_serial_port_data(port);
  110713. - if (!p_priv)
  110714. - goto resubmit;
  110715. /* Update handshaking pin state information */
  110716. old_dcd_state = p_priv->dcd_state;
  110717. @@ -434,7 +432,7 @@
  110718. if (old_dcd_state != p_priv->dcd_state)
  110719. tty_port_tty_hangup(&port->port, true);
  110720. -resubmit:
  110721. +
  110722. /* Resubmit urb so we continue receiving */
  110723. err = usb_submit_urb(urb, GFP_ATOMIC);
  110724. if (err != 0)
  110725. @@ -544,8 +542,6 @@
  110726. }
  110727. port = serial->port[msg->port];
  110728. p_priv = usb_get_serial_port_data(port);
  110729. - if (!p_priv)
  110730. - goto resubmit;
  110731. /* Update handshaking pin state information */
  110732. old_dcd_state = p_priv->dcd_state;
  110733. @@ -556,7 +552,7 @@
  110734. if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
  110735. tty_port_tty_hangup(&port->port, true);
  110736. -resubmit:
  110737. +
  110738. /* Resubmit urb so we continue receiving */
  110739. err = usb_submit_urb(urb, GFP_ATOMIC);
  110740. if (err != 0)
  110741. @@ -629,8 +625,6 @@
  110742. }
  110743. port = serial->port[msg->portNumber];
  110744. p_priv = usb_get_serial_port_data(port);
  110745. - if (!p_priv)
  110746. - goto resubmit;
  110747. /* Update handshaking pin state information */
  110748. old_dcd_state = p_priv->dcd_state;
  110749. @@ -641,7 +635,7 @@
  110750. if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
  110751. tty_port_tty_hangup(&port->port, true);
  110752. -resubmit:
  110753. +
  110754. /* Resubmit urb so we continue receiving */
  110755. err = usb_submit_urb(urb, GFP_ATOMIC);
  110756. if (err != 0)
  110757. @@ -879,8 +873,6 @@
  110758. port = serial->port[0];
  110759. p_priv = usb_get_serial_port_data(port);
  110760. - if (!p_priv)
  110761. - goto resubmit;
  110762. /* Update handshaking pin state information */
  110763. old_dcd_state = p_priv->dcd_state;
  110764. @@ -891,7 +883,7 @@
  110765. if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
  110766. tty_port_tty_hangup(&port->port, true);
  110767. -resubmit:
  110768. +
  110769. /* Resubmit urb so we continue receiving */
  110770. err = usb_submit_urb(urb, GFP_ATOMIC);
  110771. if (err != 0)
  110772. @@ -952,8 +944,6 @@
  110773. port = serial->port[msg->port];
  110774. p_priv = usb_get_serial_port_data(port);
  110775. - if (!p_priv)
  110776. - goto resubmit;
  110777. /* Update handshaking pin state information */
  110778. old_dcd_state = p_priv->dcd_state;
  110779. @@ -962,7 +952,7 @@
  110780. if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
  110781. tty_port_tty_hangup(&port->port, true);
  110782. -resubmit:
  110783. +
  110784. /* Resubmit urb so we continue receiving */
  110785. err = usb_submit_urb(urb, GFP_ATOMIC);
  110786. if (err != 0)
  110787. diff -Nur linux-3.12.38/drivers/vfio/pci/vfio_pci.c linux-rpi/drivers/vfio/pci/vfio_pci.c
  110788. --- linux-3.12.38/drivers/vfio/pci/vfio_pci.c 2015-02-16 16:15:42.000000000 +0100
  110789. +++ linux-rpi/drivers/vfio/pci/vfio_pci.c 2015-03-10 17:26:51.342216687 +0100
  110790. @@ -821,11 +821,13 @@
  110791. static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  110792. {
  110793. + u8 type;
  110794. struct vfio_pci_device *vdev;
  110795. struct iommu_group *group;
  110796. int ret;
  110797. - if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL)
  110798. + pci_read_config_byte(pdev, PCI_HEADER_TYPE, &type);
  110799. + if ((type & PCI_HEADER_TYPE) != PCI_HEADER_TYPE_NORMAL)
  110800. return -EINVAL;
  110801. group = iommu_group_get(&pdev->dev);
  110802. diff -Nur linux-3.12.38/drivers/vhost/scsi.c linux-rpi/drivers/vhost/scsi.c
  110803. --- linux-3.12.38/drivers/vhost/scsi.c 2015-02-16 16:15:42.000000000 +0100
  110804. +++ linux-rpi/drivers/vhost/scsi.c 2015-03-10 17:26:51.342216687 +0100
  110805. @@ -861,23 +861,6 @@
  110806. return 0;
  110807. }
  110808. -static int vhost_scsi_to_tcm_attr(int attr)
  110809. -{
  110810. - switch (attr) {
  110811. - case VIRTIO_SCSI_S_SIMPLE:
  110812. - return MSG_SIMPLE_TAG;
  110813. - case VIRTIO_SCSI_S_ORDERED:
  110814. - return MSG_ORDERED_TAG;
  110815. - case VIRTIO_SCSI_S_HEAD:
  110816. - return MSG_HEAD_TAG;
  110817. - case VIRTIO_SCSI_S_ACA:
  110818. - return MSG_ACA_TAG;
  110819. - default:
  110820. - break;
  110821. - }
  110822. - return MSG_SIMPLE_TAG;
  110823. -}
  110824. -
  110825. static void tcm_vhost_submission_work(struct work_struct *work)
  110826. {
  110827. struct tcm_vhost_cmd *cmd =
  110828. @@ -904,9 +887,9 @@
  110829. rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess,
  110830. cmd->tvc_cdb, &cmd->tvc_sense_buf[0],
  110831. cmd->tvc_lun, cmd->tvc_exp_data_len,
  110832. - vhost_scsi_to_tcm_attr(cmd->tvc_task_attr),
  110833. - cmd->tvc_data_direction, TARGET_SCF_ACK_KREF,
  110834. - sg_ptr, cmd->tvc_sgl_count, sg_bidi_ptr, sg_no_bidi);
  110835. + cmd->tvc_task_attr, cmd->tvc_data_direction,
  110836. + TARGET_SCF_ACK_KREF, sg_ptr, cmd->tvc_sgl_count,
  110837. + sg_bidi_ptr, sg_no_bidi);
  110838. if (rc < 0) {
  110839. transport_send_check_condition_and_sense(se_cmd,
  110840. TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
  110841. diff -Nur linux-3.12.38/drivers/video/bcm2708_fb.c linux-rpi/drivers/video/bcm2708_fb.c
  110842. --- linux-3.12.38/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  110843. +++ linux-rpi/drivers/video/bcm2708_fb.c 2015-03-10 17:26:51.354216687 +0100
  110844. @@ -0,0 +1,818 @@
  110845. +/*
  110846. + * linux/drivers/video/bcm2708_fb.c
  110847. + *
  110848. + * Copyright (C) 2010 Broadcom
  110849. + *
  110850. + * This file is subject to the terms and conditions of the GNU General Public
  110851. + * License. See the file COPYING in the main directory of this archive
  110852. + * for more details.
  110853. + *
  110854. + * Broadcom simple framebuffer driver
  110855. + *
  110856. + * This file is derived from cirrusfb.c
  110857. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  110858. + *
  110859. + */
  110860. +#include <linux/module.h>
  110861. +#include <linux/kernel.h>
  110862. +#include <linux/errno.h>
  110863. +#include <linux/string.h>
  110864. +#include <linux/slab.h>
  110865. +#include <linux/mm.h>
  110866. +#include <linux/fb.h>
  110867. +#include <linux/init.h>
  110868. +#include <linux/interrupt.h>
  110869. +#include <linux/ioport.h>
  110870. +#include <linux/list.h>
  110871. +#include <linux/platform_device.h>
  110872. +#include <linux/clk.h>
  110873. +#include <linux/printk.h>
  110874. +#include <linux/console.h>
  110875. +#include <linux/debugfs.h>
  110876. +
  110877. +#include <mach/dma.h>
  110878. +#include <mach/platform.h>
  110879. +#include <mach/vcio.h>
  110880. +
  110881. +#include <asm/sizes.h>
  110882. +#include <linux/io.h>
  110883. +#include <linux/dma-mapping.h>
  110884. +
  110885. +//#define BCM2708_FB_DEBUG
  110886. +#define MODULE_NAME "bcm2708_fb"
  110887. +
  110888. +#ifdef BCM2708_FB_DEBUG
  110889. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  110890. +#else
  110891. +#define print_debug(fmt,...)
  110892. +#endif
  110893. +
  110894. +/* This is limited to 16 characters when displayed by X startup */
  110895. +static const char *bcm2708_name = "BCM2708 FB";
  110896. +
  110897. +#define DRIVER_NAME "bcm2708_fb"
  110898. +
  110899. +static int fbwidth = 800; /* module parameter */
  110900. +static int fbheight = 480; /* module parameter */
  110901. +static int fbdepth = 16; /* module parameter */
  110902. +static int fbswap = 0; /* module parameter */
  110903. +
  110904. +static u32 dma_busy_wait_threshold = 1<<15;
  110905. +module_param(dma_busy_wait_threshold, int, 0644);
  110906. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  110907. +
  110908. +/* this data structure describes each frame buffer device we find */
  110909. +
  110910. +struct fbinfo_s {
  110911. + u32 xres, yres, xres_virtual, yres_virtual;
  110912. + u32 pitch, bpp;
  110913. + u32 xoffset, yoffset;
  110914. + u32 base;
  110915. + u32 screen_size;
  110916. + u16 cmap[256];
  110917. +};
  110918. +
  110919. +struct bcm2708_fb_stats {
  110920. + struct debugfs_regset32 regset;
  110921. + u32 dma_copies;
  110922. + u32 dma_irqs;
  110923. +};
  110924. +
  110925. +struct bcm2708_fb {
  110926. + struct fb_info fb;
  110927. + struct platform_device *dev;
  110928. + struct fbinfo_s *info;
  110929. + dma_addr_t dma;
  110930. + u32 cmap[16];
  110931. + int dma_chan;
  110932. + int dma_irq;
  110933. + void __iomem *dma_chan_base;
  110934. + void *cb_base; /* DMA control blocks */
  110935. + dma_addr_t cb_handle;
  110936. + struct dentry *debugfs_dir;
  110937. + wait_queue_head_t dma_waitq;
  110938. + struct bcm2708_fb_stats stats;
  110939. + unsigned long fb_bus_address;
  110940. +};
  110941. +
  110942. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  110943. +
  110944. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  110945. +{
  110946. + debugfs_remove_recursive(fb->debugfs_dir);
  110947. + fb->debugfs_dir = NULL;
  110948. +}
  110949. +
  110950. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  110951. +{
  110952. + static struct debugfs_reg32 stats_registers[] = {
  110953. + {
  110954. + "dma_copies",
  110955. + offsetof(struct bcm2708_fb_stats, dma_copies)
  110956. + },
  110957. + {
  110958. + "dma_irqs",
  110959. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  110960. + },
  110961. + };
  110962. +
  110963. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  110964. + if (!fb->debugfs_dir) {
  110965. + pr_warn("%s: could not create debugfs entry\n",
  110966. + __func__);
  110967. + return -EFAULT;
  110968. + }
  110969. +
  110970. + fb->stats.regset.regs = stats_registers;
  110971. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  110972. + fb->stats.regset.base = &fb->stats;
  110973. +
  110974. + if (!debugfs_create_regset32(
  110975. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  110976. + pr_warn("%s: could not create statistics registers\n",
  110977. + __func__);
  110978. + goto fail;
  110979. + }
  110980. + return 0;
  110981. +
  110982. +fail:
  110983. + bcm2708_fb_debugfs_deinit(fb);
  110984. + return -EFAULT;
  110985. +}
  110986. +
  110987. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  110988. +{
  110989. + int ret = 0;
  110990. +
  110991. + memset(&var->transp, 0, sizeof(var->transp));
  110992. +
  110993. + var->red.msb_right = 0;
  110994. + var->green.msb_right = 0;
  110995. + var->blue.msb_right = 0;
  110996. +
  110997. + switch (var->bits_per_pixel) {
  110998. + case 1:
  110999. + case 2:
  111000. + case 4:
  111001. + case 8:
  111002. + var->red.length = var->bits_per_pixel;
  111003. + var->red.offset = 0;
  111004. + var->green.length = var->bits_per_pixel;
  111005. + var->green.offset = 0;
  111006. + var->blue.length = var->bits_per_pixel;
  111007. + var->blue.offset = 0;
  111008. + break;
  111009. + case 16:
  111010. + var->red.length = 5;
  111011. + var->blue.length = 5;
  111012. + /*
  111013. + * Green length can be 5 or 6 depending whether
  111014. + * we're operating in RGB555 or RGB565 mode.
  111015. + */
  111016. + if (var->green.length != 5 && var->green.length != 6)
  111017. + var->green.length = 6;
  111018. + break;
  111019. + case 24:
  111020. + var->red.length = 8;
  111021. + var->blue.length = 8;
  111022. + var->green.length = 8;
  111023. + break;
  111024. + case 32:
  111025. + var->red.length = 8;
  111026. + var->green.length = 8;
  111027. + var->blue.length = 8;
  111028. + var->transp.length = 8;
  111029. + break;
  111030. + default:
  111031. + ret = -EINVAL;
  111032. + break;
  111033. + }
  111034. +
  111035. + /*
  111036. + * >= 16bpp displays have separate colour component bitfields
  111037. + * encoded in the pixel data. Calculate their position from
  111038. + * the bitfield length defined above.
  111039. + */
  111040. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  111041. + var->blue.offset = 0;
  111042. + var->green.offset = var->blue.offset + var->blue.length;
  111043. + var->red.offset = var->green.offset + var->green.length;
  111044. + var->transp.offset = var->red.offset + var->red.length;
  111045. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  111046. + var->red.offset = 0;
  111047. + var->green.offset = var->red.offset + var->red.length;
  111048. + var->blue.offset = var->green.offset + var->green.length;
  111049. + var->transp.offset = var->blue.offset + var->blue.length;
  111050. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  111051. + var->blue.offset = 0;
  111052. + var->green.offset = var->blue.offset + var->blue.length;
  111053. + var->red.offset = var->green.offset + var->green.length;
  111054. + var->transp.offset = var->red.offset + var->red.length;
  111055. + }
  111056. +
  111057. + return ret;
  111058. +}
  111059. +
  111060. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  111061. + struct fb_info *info)
  111062. +{
  111063. + /* info input, var output */
  111064. + int yres;
  111065. +
  111066. + /* info input, var output */
  111067. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  111068. + info->var.xres, info->var.yres, info->var.xres_virtual,
  111069. + info->var.yres_virtual, (int)info->screen_size,
  111070. + info->var.bits_per_pixel);
  111071. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  111072. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  111073. + var->bits_per_pixel);
  111074. +
  111075. + if (!var->bits_per_pixel)
  111076. + var->bits_per_pixel = 16;
  111077. +
  111078. + if (bcm2708_fb_set_bitfields(var) != 0) {
  111079. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  111080. + var->bits_per_pixel);
  111081. + return -EINVAL;
  111082. + }
  111083. +
  111084. +
  111085. + if (var->xres_virtual < var->xres)
  111086. + var->xres_virtual = var->xres;
  111087. + /* use highest possible virtual resolution */
  111088. + if (var->yres_virtual == -1) {
  111089. + var->yres_virtual = 480;
  111090. +
  111091. + pr_err
  111092. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  111093. + var->xres_virtual, var->yres_virtual);
  111094. + }
  111095. + if (var->yres_virtual < var->yres)
  111096. + var->yres_virtual = var->yres;
  111097. +
  111098. + if (var->xoffset < 0)
  111099. + var->xoffset = 0;
  111100. + if (var->yoffset < 0)
  111101. + var->yoffset = 0;
  111102. +
  111103. + /* truncate xoffset and yoffset to maximum if too high */
  111104. + if (var->xoffset > var->xres_virtual - var->xres)
  111105. + var->xoffset = var->xres_virtual - var->xres - 1;
  111106. + if (var->yoffset > var->yres_virtual - var->yres)
  111107. + var->yoffset = var->yres_virtual - var->yres - 1;
  111108. +
  111109. + yres = var->yres;
  111110. + if (var->vmode & FB_VMODE_DOUBLE)
  111111. + yres *= 2;
  111112. + else if (var->vmode & FB_VMODE_INTERLACED)
  111113. + yres = (yres + 1) / 2;
  111114. +
  111115. + return 0;
  111116. +}
  111117. +
  111118. +static int bcm2708_fb_set_par(struct fb_info *info)
  111119. +{
  111120. + uint32_t val = 0;
  111121. + struct bcm2708_fb *fb = to_bcm2708(info);
  111122. + volatile struct fbinfo_s *fbinfo = fb->info;
  111123. + fbinfo->xres = info->var.xres;
  111124. + fbinfo->yres = info->var.yres;
  111125. + fbinfo->xres_virtual = info->var.xres_virtual;
  111126. + fbinfo->yres_virtual = info->var.yres_virtual;
  111127. + fbinfo->bpp = info->var.bits_per_pixel;
  111128. + fbinfo->xoffset = info->var.xoffset;
  111129. + fbinfo->yoffset = info->var.yoffset;
  111130. + fbinfo->base = 0; /* filled in by VC */
  111131. + fbinfo->pitch = 0; /* filled in by VC */
  111132. +
  111133. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  111134. + info->var.xres, info->var.yres, info->var.xres_virtual,
  111135. + info->var.yres_virtual, (int)info->screen_size,
  111136. + info->var.bits_per_pixel);
  111137. +
  111138. + /* ensure last write to fbinfo is visible to GPU */
  111139. + wmb();
  111140. +
  111141. + /* inform vc about new framebuffer */
  111142. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  111143. +
  111144. + /* TODO: replace fb driver with vchiq version */
  111145. + /* wait for response */
  111146. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  111147. +
  111148. + /* ensure GPU writes are visible to us */
  111149. + rmb();
  111150. +
  111151. + if (val == 0) {
  111152. + fb->fb.fix.line_length = fbinfo->pitch;
  111153. +
  111154. + if (info->var.bits_per_pixel <= 8)
  111155. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  111156. + else
  111157. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  111158. +
  111159. + fb->fb_bus_address = fbinfo->base;
  111160. + fbinfo->base &= ~0xc0000000;
  111161. + fb->fb.fix.smem_start = fbinfo->base;
  111162. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  111163. + fb->fb.screen_size = fbinfo->screen_size;
  111164. + if (fb->fb.screen_base)
  111165. + iounmap(fb->fb.screen_base);
  111166. + fb->fb.screen_base =
  111167. + (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
  111168. + if (!fb->fb.screen_base) {
  111169. + /* the console may currently be locked */
  111170. + console_trylock();
  111171. + console_unlock();
  111172. +
  111173. + BUG(); /* what can we do here */
  111174. + }
  111175. + }
  111176. + print_debug
  111177. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  111178. + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
  111179. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  111180. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  111181. +
  111182. + return val;
  111183. +}
  111184. +
  111185. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  111186. +{
  111187. + unsigned int mask = (1 << bf->length) - 1;
  111188. +
  111189. + return (val >> (16 - bf->length) & mask) << bf->offset;
  111190. +}
  111191. +
  111192. +
  111193. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  111194. + unsigned int green, unsigned int blue,
  111195. + unsigned int transp, struct fb_info *info)
  111196. +{
  111197. + struct bcm2708_fb *fb = to_bcm2708(info);
  111198. +
  111199. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  111200. + if (fb->fb.var.bits_per_pixel <= 8) {
  111201. + if (regno < 256) {
  111202. + /* blue [0:4], green [5:10], red [11:15] */
  111203. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  111204. + ((green >> (16-6)) & 0x3f) << 5 |
  111205. + ((blue >> (16-5)) & 0x1f) << 0;
  111206. + }
  111207. + /* 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 */
  111208. + /* So just call it for what looks like the last colour in a list for now. */
  111209. + if (regno == 15 || regno == 255)
  111210. + bcm2708_fb_set_par(info);
  111211. + } else if (regno < 16) {
  111212. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  111213. + convert_bitfield(blue, &fb->fb.var.blue) |
  111214. + convert_bitfield(green, &fb->fb.var.green) |
  111215. + convert_bitfield(red, &fb->fb.var.red);
  111216. + }
  111217. + return regno > 255;
  111218. +}
  111219. +
  111220. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  111221. +{
  111222. + s32 result = -1;
  111223. + u32 p[7];
  111224. + if ( (blank_mode == FB_BLANK_NORMAL) ||
  111225. + (blank_mode == FB_BLANK_UNBLANK)) {
  111226. +
  111227. + p[0] = 28; // size = sizeof u32 * length of p
  111228. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  111229. + p[2] = VCMSG_SET_BLANK_SCREEN; // (the tag id)
  111230. + p[3] = 4; // (size of the response buffer)
  111231. + p[4] = 4; // (size of the request data)
  111232. + p[5] = blank_mode;
  111233. + p[6] = VCMSG_PROPERTY_END; // end tag
  111234. +
  111235. + bcm_mailbox_property(&p, p[0]);
  111236. +
  111237. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  111238. + result = 0;
  111239. + else
  111240. + pr_err("bcm2708_fb_blank(%d) returns=%d p[1]=0x%x\n", blank_mode, p[5], p[1]);
  111241. + }
  111242. + return result;
  111243. +}
  111244. +
  111245. +static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  111246. +{
  111247. + s32 result = -1;
  111248. + info->var.xoffset = var->xoffset;
  111249. + info->var.yoffset = var->yoffset;
  111250. + result = bcm2708_fb_set_par(info);
  111251. + if (result != 0)
  111252. + pr_err("bcm2708_fb_pan_display(%d,%d) returns=%d\n", var->xoffset, var->yoffset, result);
  111253. + return result;
  111254. +}
  111255. +
  111256. +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  111257. +{
  111258. + s32 result = -1;
  111259. + u32 p[7];
  111260. + if (cmd == FBIO_WAITFORVSYNC) {
  111261. + p[0] = 28; // size = sizeof u32 * length of p
  111262. + p[1] = VCMSG_PROCESS_REQUEST; // process request
  111263. + p[2] = VCMSG_SET_VSYNC; // (the tag id)
  111264. + p[3] = 4; // (size of the response buffer)
  111265. + p[4] = 4; // (size of the request data)
  111266. + p[5] = 0; // dummy
  111267. + p[6] = VCMSG_PROPERTY_END; // end tag
  111268. +
  111269. + bcm_mailbox_property(&p, p[0]);
  111270. +
  111271. + pr_info("bcm2708_fb_ioctl %x,%lx returns=%d p[1]=0x%x\n", cmd, arg, p[5], p[1]);
  111272. +
  111273. + if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
  111274. + result = 0;
  111275. + }
  111276. + return result;
  111277. +}
  111278. +static void bcm2708_fb_fillrect(struct fb_info *info,
  111279. + const struct fb_fillrect *rect)
  111280. +{
  111281. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  111282. + cfb_fillrect(info, rect);
  111283. +}
  111284. +
  111285. +/* A helper function for configuring dma control block */
  111286. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  111287. + int burst_size,
  111288. + dma_addr_t dst,
  111289. + int dst_stride,
  111290. + dma_addr_t src,
  111291. + int src_stride,
  111292. + int w,
  111293. + int h)
  111294. +{
  111295. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  111296. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  111297. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  111298. + cb->dst = dst;
  111299. + cb->src = src;
  111300. + /*
  111301. + * This is not really obvious from the DMA documentation,
  111302. + * but the top 16 bits must be programmmed to "height -1"
  111303. + * and not "height" in 2D mode.
  111304. + */
  111305. + cb->length = ((h - 1) << 16) | w;
  111306. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  111307. + cb->pad[0] = 0;
  111308. + cb->pad[1] = 0;
  111309. +}
  111310. +
  111311. +static void bcm2708_fb_copyarea(struct fb_info *info,
  111312. + const struct fb_copyarea *region)
  111313. +{
  111314. + struct bcm2708_fb *fb = to_bcm2708(info);
  111315. + struct bcm2708_dma_cb *cb = fb->cb_base;
  111316. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  111317. + /* Channel 0 supports larger bursts and is a bit faster */
  111318. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  111319. + int pixels = region->width * region->height;
  111320. +
  111321. + /* Fallback to cfb_copyarea() if we don't like something */
  111322. + if (in_atomic() ||
  111323. + bytes_per_pixel > 4 ||
  111324. + info->var.xres * info->var.yres > 1920 * 1200 ||
  111325. + region->width <= 0 || region->width > info->var.xres ||
  111326. + region->height <= 0 || region->height > info->var.yres ||
  111327. + region->sx < 0 || region->sx >= info->var.xres ||
  111328. + region->sy < 0 || region->sy >= info->var.yres ||
  111329. + region->dx < 0 || region->dx >= info->var.xres ||
  111330. + region->dy < 0 || region->dy >= info->var.yres ||
  111331. + region->sx + region->width > info->var.xres ||
  111332. + region->dx + region->width > info->var.xres ||
  111333. + region->sy + region->height > info->var.yres ||
  111334. + region->dy + region->height > info->var.yres) {
  111335. + cfb_copyarea(info, region);
  111336. + return;
  111337. + }
  111338. +
  111339. + if (region->dy == region->sy && region->dx > region->sx) {
  111340. + /*
  111341. + * A difficult case of overlapped copy. Because DMA can't
  111342. + * copy individual scanlines in backwards direction, we need
  111343. + * two-pass processing. We do it by programming a chain of dma
  111344. + * control blocks in the first 16K part of the buffer and use
  111345. + * the remaining 48K as the intermediate temporary scratch
  111346. + * buffer. The buffer size is sufficient to handle up to
  111347. + * 1920x1200 resolution at 32bpp pixel depth.
  111348. + */
  111349. + int y;
  111350. + dma_addr_t control_block_pa = fb->cb_handle;
  111351. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  111352. + int scanline_size = bytes_per_pixel * region->width;
  111353. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  111354. +
  111355. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  111356. + dma_addr_t src =
  111357. + fb->fb_bus_address +
  111358. + bytes_per_pixel * region->sx +
  111359. + (region->sy + y) * fb->fb.fix.line_length;
  111360. + dma_addr_t dst =
  111361. + fb->fb_bus_address +
  111362. + bytes_per_pixel * region->dx +
  111363. + (region->dy + y) * fb->fb.fix.line_length;
  111364. +
  111365. + if (region->height - y < scanlines_per_cb)
  111366. + scanlines_per_cb = region->height - y;
  111367. +
  111368. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  111369. + src, fb->fb.fix.line_length,
  111370. + scanline_size, scanlines_per_cb);
  111371. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  111372. + cb->next = control_block_pa;
  111373. + cb++;
  111374. +
  111375. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  111376. + scratchbuf, scanline_size,
  111377. + scanline_size, scanlines_per_cb);
  111378. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  111379. + cb->next = control_block_pa;
  111380. + cb++;
  111381. + }
  111382. + /* move the pointer back to the last dma control block */
  111383. + cb--;
  111384. + } else {
  111385. + /* A single dma control block is enough. */
  111386. + int sy, dy, stride;
  111387. + if (region->dy <= region->sy) {
  111388. + /* processing from top to bottom */
  111389. + dy = region->dy;
  111390. + sy = region->sy;
  111391. + stride = fb->fb.fix.line_length;
  111392. + } else {
  111393. + /* processing from bottom to top */
  111394. + dy = region->dy + region->height - 1;
  111395. + sy = region->sy + region->height - 1;
  111396. + stride = -fb->fb.fix.line_length;
  111397. + }
  111398. + set_dma_cb(cb, burst_size,
  111399. + fb->fb_bus_address + dy * fb->fb.fix.line_length +
  111400. + bytes_per_pixel * region->dx,
  111401. + stride,
  111402. + fb->fb_bus_address + sy * fb->fb.fix.line_length +
  111403. + bytes_per_pixel * region->sx,
  111404. + stride,
  111405. + region->width * bytes_per_pixel,
  111406. + region->height);
  111407. + }
  111408. +
  111409. + /* end of dma control blocks chain */
  111410. + cb->next = 0;
  111411. +
  111412. +
  111413. + if (pixels < dma_busy_wait_threshold) {
  111414. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  111415. + bcm_dma_wait_idle(fb->dma_chan_base);
  111416. + } else {
  111417. + void __iomem *dma_chan = fb->dma_chan_base;
  111418. + cb->info |= BCM2708_DMA_INT_EN;
  111419. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  111420. + while (bcm_dma_is_busy(dma_chan)) {
  111421. + wait_event_interruptible(
  111422. + fb->dma_waitq,
  111423. + !bcm_dma_is_busy(dma_chan));
  111424. + }
  111425. + fb->stats.dma_irqs++;
  111426. + }
  111427. + fb->stats.dma_copies++;
  111428. +}
  111429. +
  111430. +static void bcm2708_fb_imageblit(struct fb_info *info,
  111431. + const struct fb_image *image)
  111432. +{
  111433. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  111434. + cfb_imageblit(info, image);
  111435. +}
  111436. +
  111437. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  111438. +{
  111439. + struct bcm2708_fb *fb = cxt;
  111440. +
  111441. + /* FIXME: should read status register to check if this is
  111442. + * actually interrupting us or not, in case this interrupt
  111443. + * ever becomes shared amongst several DMA channels
  111444. + *
  111445. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  111446. + */
  111447. +
  111448. + /* acknowledge the interrupt */
  111449. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  111450. +
  111451. + wake_up(&fb->dma_waitq);
  111452. + return IRQ_HANDLED;
  111453. +}
  111454. +
  111455. +static struct fb_ops bcm2708_fb_ops = {
  111456. + .owner = THIS_MODULE,
  111457. + .fb_check_var = bcm2708_fb_check_var,
  111458. + .fb_set_par = bcm2708_fb_set_par,
  111459. + .fb_setcolreg = bcm2708_fb_setcolreg,
  111460. + .fb_blank = bcm2708_fb_blank,
  111461. + .fb_fillrect = bcm2708_fb_fillrect,
  111462. + .fb_copyarea = bcm2708_fb_copyarea,
  111463. + .fb_imageblit = bcm2708_fb_imageblit,
  111464. + .fb_pan_display = bcm2708_fb_pan_display,
  111465. + .fb_ioctl = bcm2708_ioctl,
  111466. +};
  111467. +
  111468. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  111469. +{
  111470. + int ret;
  111471. + dma_addr_t dma;
  111472. + void *mem;
  111473. +
  111474. + mem =
  111475. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  111476. + GFP_KERNEL);
  111477. +
  111478. + if (NULL == mem) {
  111479. + pr_err(": unable to allocate fbinfo buffer\n");
  111480. + ret = -ENOMEM;
  111481. + } else {
  111482. + fb->info = (struct fbinfo_s *)mem;
  111483. + fb->dma = dma;
  111484. + }
  111485. + fb->fb.fbops = &bcm2708_fb_ops;
  111486. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  111487. + fb->fb.pseudo_palette = fb->cmap;
  111488. +
  111489. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  111490. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  111491. + fb->fb.fix.type_aux = 0;
  111492. + fb->fb.fix.xpanstep = 1;
  111493. + fb->fb.fix.ypanstep = 1;
  111494. + fb->fb.fix.ywrapstep = 0;
  111495. + fb->fb.fix.accel = FB_ACCEL_NONE;
  111496. +
  111497. + fb->fb.var.xres = fbwidth;
  111498. + fb->fb.var.yres = fbheight;
  111499. + fb->fb.var.xres_virtual = fbwidth;
  111500. + fb->fb.var.yres_virtual = fbheight;
  111501. + fb->fb.var.bits_per_pixel = fbdepth;
  111502. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  111503. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  111504. + fb->fb.var.nonstd = 0;
  111505. + fb->fb.var.height = -1; /* height of picture in mm */
  111506. + fb->fb.var.width = -1; /* width of picture in mm */
  111507. + fb->fb.var.accel_flags = 0;
  111508. +
  111509. + fb->fb.monspecs.hfmin = 0;
  111510. + fb->fb.monspecs.hfmax = 100000;
  111511. + fb->fb.monspecs.vfmin = 0;
  111512. + fb->fb.monspecs.vfmax = 400;
  111513. + fb->fb.monspecs.dclkmin = 1000000;
  111514. + fb->fb.monspecs.dclkmax = 100000000;
  111515. +
  111516. + bcm2708_fb_set_bitfields(&fb->fb.var);
  111517. + init_waitqueue_head(&fb->dma_waitq);
  111518. +
  111519. + /*
  111520. + * Allocate colourmap.
  111521. + */
  111522. +
  111523. + fb_set_var(&fb->fb, &fb->fb.var);
  111524. + bcm2708_fb_set_par(&fb->fb);
  111525. +
  111526. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  111527. + fbheight, fbdepth, fbswap);
  111528. +
  111529. + ret = register_framebuffer(&fb->fb);
  111530. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  111531. + if (ret == 0)
  111532. + goto out;
  111533. +
  111534. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  111535. +out:
  111536. + return ret;
  111537. +}
  111538. +
  111539. +static int bcm2708_fb_probe(struct platform_device *dev)
  111540. +{
  111541. + struct bcm2708_fb *fb;
  111542. + int ret;
  111543. +
  111544. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  111545. + if (!fb) {
  111546. + dev_err(&dev->dev,
  111547. + "could not allocate new bcm2708_fb struct\n");
  111548. + ret = -ENOMEM;
  111549. + goto free_region;
  111550. + }
  111551. +
  111552. + bcm2708_fb_debugfs_init(fb);
  111553. +
  111554. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  111555. + &fb->cb_handle, GFP_KERNEL);
  111556. + if (!fb->cb_base) {
  111557. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  111558. + ret = -ENOMEM;
  111559. + goto free_fb;
  111560. + }
  111561. +
  111562. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  111563. + fb->cb_handle);
  111564. +
  111565. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  111566. + &fb->dma_chan_base, &fb->dma_irq);
  111567. + if (ret < 0) {
  111568. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  111569. + goto free_cb;
  111570. + }
  111571. + fb->dma_chan = ret;
  111572. +
  111573. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  111574. + 0, "bcm2708_fb dma", fb);
  111575. + if (ret) {
  111576. + pr_err("%s: failed to request DMA irq\n", __func__);
  111577. + goto free_dma_chan;
  111578. + }
  111579. +
  111580. +
  111581. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  111582. + fb->dma_chan, fb->dma_chan_base);
  111583. +
  111584. + fb->dev = dev;
  111585. +
  111586. + ret = bcm2708_fb_register(fb);
  111587. + if (ret == 0) {
  111588. + platform_set_drvdata(dev, fb);
  111589. + goto out;
  111590. + }
  111591. +
  111592. +free_dma_chan:
  111593. + bcm_dma_chan_free(fb->dma_chan);
  111594. +free_cb:
  111595. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  111596. +free_fb:
  111597. + kfree(fb);
  111598. +free_region:
  111599. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  111600. +out:
  111601. + return ret;
  111602. +}
  111603. +
  111604. +static int bcm2708_fb_remove(struct platform_device *dev)
  111605. +{
  111606. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  111607. +
  111608. + platform_set_drvdata(dev, NULL);
  111609. +
  111610. + if (fb->fb.screen_base)
  111611. + iounmap(fb->fb.screen_base);
  111612. + unregister_framebuffer(&fb->fb);
  111613. +
  111614. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  111615. + bcm_dma_chan_free(fb->dma_chan);
  111616. +
  111617. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  111618. + fb->dma);
  111619. + bcm2708_fb_debugfs_deinit(fb);
  111620. +
  111621. + free_irq(fb->dma_irq, fb);
  111622. +
  111623. + kfree(fb);
  111624. +
  111625. + return 0;
  111626. +}
  111627. +
  111628. +static struct platform_driver bcm2708_fb_driver = {
  111629. + .probe = bcm2708_fb_probe,
  111630. + .remove = bcm2708_fb_remove,
  111631. + .driver = {
  111632. + .name = DRIVER_NAME,
  111633. + .owner = THIS_MODULE,
  111634. + },
  111635. +};
  111636. +
  111637. +static int __init bcm2708_fb_init(void)
  111638. +{
  111639. + return platform_driver_register(&bcm2708_fb_driver);
  111640. +}
  111641. +
  111642. +module_init(bcm2708_fb_init);
  111643. +
  111644. +static void __exit bcm2708_fb_exit(void)
  111645. +{
  111646. + platform_driver_unregister(&bcm2708_fb_driver);
  111647. +}
  111648. +
  111649. +module_exit(bcm2708_fb_exit);
  111650. +
  111651. +module_param(fbwidth, int, 0644);
  111652. +module_param(fbheight, int, 0644);
  111653. +module_param(fbdepth, int, 0644);
  111654. +module_param(fbswap, int, 0644);
  111655. +
  111656. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  111657. +MODULE_LICENSE("GPL");
  111658. +
  111659. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  111660. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  111661. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  111662. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  111663. diff -Nur linux-3.12.38/drivers/video/cfbimgblt.c linux-rpi/drivers/video/cfbimgblt.c
  111664. --- linux-3.12.38/drivers/video/cfbimgblt.c 2015-02-16 16:15:42.000000000 +0100
  111665. +++ linux-rpi/drivers/video/cfbimgblt.c 2015-03-10 17:26:51.354216687 +0100
  111666. @@ -28,6 +28,11 @@
  111667. *
  111668. * Also need to add code to deal with cards endians that are different than
  111669. * the native cpu endians. I also need to deal with MSB position in the word.
  111670. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  111671. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  111672. + * significantly faster than the previous implementation.
  111673. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  111674. + * divides.
  111675. */
  111676. #include <linux/module.h>
  111677. #include <linux/string.h>
  111678. @@ -262,6 +267,133 @@
  111679. }
  111680. }
  111681. +/*
  111682. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  111683. + * into the code, main loop unrolled.
  111684. + */
  111685. +
  111686. +static inline void fast_imageblit16(const struct fb_image *image,
  111687. + struct fb_info *p, u8 __iomem * dst1,
  111688. + u32 fgcolor, u32 bgcolor)
  111689. +{
  111690. + u32 fgx = fgcolor, bgx = bgcolor;
  111691. + u32 spitch = (image->width + 7) / 8;
  111692. + u32 end_mask, eorx;
  111693. + const char *s = image->data, *src;
  111694. + u32 __iomem *dst;
  111695. + const u32 *tab = NULL;
  111696. + int i, j, k;
  111697. +
  111698. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  111699. +
  111700. + fgx <<= 16;
  111701. + bgx <<= 16;
  111702. + fgx |= fgcolor;
  111703. + bgx |= bgcolor;
  111704. +
  111705. + eorx = fgx ^ bgx;
  111706. + k = image->width / 2;
  111707. +
  111708. + for (i = image->height; i--;) {
  111709. + dst = (u32 __iomem *) dst1;
  111710. + src = s;
  111711. +
  111712. + j = k;
  111713. + while (j >= 4) {
  111714. + u8 bits = *src;
  111715. + end_mask = tab[(bits >> 6) & 3];
  111716. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111717. + end_mask = tab[(bits >> 4) & 3];
  111718. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111719. + end_mask = tab[(bits >> 2) & 3];
  111720. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111721. + end_mask = tab[bits & 3];
  111722. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111723. + src++;
  111724. + j -= 4;
  111725. + }
  111726. + if (j != 0) {
  111727. + u8 bits = *src;
  111728. + end_mask = tab[(bits >> 6) & 3];
  111729. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111730. + if (j >= 2) {
  111731. + end_mask = tab[(bits >> 4) & 3];
  111732. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111733. + if (j == 3) {
  111734. + end_mask = tab[(bits >> 2) & 3];
  111735. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  111736. + }
  111737. + }
  111738. + }
  111739. + dst1 += p->fix.line_length;
  111740. + s += spitch;
  111741. + }
  111742. +}
  111743. +
  111744. +/*
  111745. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  111746. + * into the code, main loop unrolled.
  111747. + */
  111748. +
  111749. +static inline void fast_imageblit32(const struct fb_image *image,
  111750. + struct fb_info *p, u8 __iomem * dst1,
  111751. + u32 fgcolor, u32 bgcolor)
  111752. +{
  111753. + u32 fgx = fgcolor, bgx = bgcolor;
  111754. + u32 spitch = (image->width + 7) / 8;
  111755. + u32 end_mask, eorx;
  111756. + const char *s = image->data, *src;
  111757. + u32 __iomem *dst;
  111758. + const u32 *tab = NULL;
  111759. + int i, j, k;
  111760. +
  111761. + tab = cfb_tab32;
  111762. +
  111763. + eorx = fgx ^ bgx;
  111764. + k = image->width;
  111765. +
  111766. + for (i = image->height; i--;) {
  111767. + dst = (u32 __iomem *) dst1;
  111768. + src = s;
  111769. +
  111770. + j = k;
  111771. + while (j >= 8) {
  111772. + u8 bits = *src;
  111773. + end_mask = tab[(bits >> 7) & 1];
  111774. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111775. + end_mask = tab[(bits >> 6) & 1];
  111776. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111777. + end_mask = tab[(bits >> 5) & 1];
  111778. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111779. + end_mask = tab[(bits >> 4) & 1];
  111780. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111781. + end_mask = tab[(bits >> 3) & 1];
  111782. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111783. + end_mask = tab[(bits >> 2) & 1];
  111784. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111785. + end_mask = tab[(bits >> 1) & 1];
  111786. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111787. + end_mask = tab[bits & 1];
  111788. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111789. + src++;
  111790. + j -= 8;
  111791. + }
  111792. + if (j != 0) {
  111793. + u32 bits = (u32) * src;
  111794. + while (j > 1) {
  111795. + end_mask = tab[(bits >> 7) & 1];
  111796. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  111797. + bits <<= 1;
  111798. + j--;
  111799. + }
  111800. + end_mask = tab[(bits >> 7) & 1];
  111801. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  111802. + }
  111803. + dst1 += p->fix.line_length;
  111804. + s += spitch;
  111805. + }
  111806. +}
  111807. +
  111808. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  111809. {
  111810. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  111811. @@ -294,11 +426,21 @@
  111812. bgcolor = image->bg_color;
  111813. }
  111814. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  111815. - ((width & (32/bpp-1)) == 0) &&
  111816. - bpp >= 8 && bpp <= 32)
  111817. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  111818. - else
  111819. + if (!start_index && !pitch_index) {
  111820. + if (bpp == 32)
  111821. + fast_imageblit32(image, p, dst1, fgcolor,
  111822. + bgcolor);
  111823. + else if (bpp == 16 && (width & 1) == 0)
  111824. + fast_imageblit16(image, p, dst1, fgcolor,
  111825. + bgcolor);
  111826. + else if (bpp == 8 && (width & 3) == 0)
  111827. + fast_imageblit(image, p, dst1, fgcolor,
  111828. + bgcolor);
  111829. + else
  111830. + slow_imageblit(image, p, dst1, fgcolor,
  111831. + bgcolor,
  111832. + start_index, pitch_index);
  111833. + } else
  111834. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  111835. start_index, pitch_index);
  111836. } else
  111837. diff -Nur linux-3.12.38/drivers/video/fbmem.c linux-rpi/drivers/video/fbmem.c
  111838. --- linux-3.12.38/drivers/video/fbmem.c 2015-02-16 16:15:42.000000000 +0100
  111839. +++ linux-rpi/drivers/video/fbmem.c 2015-03-10 17:26:51.358216687 +0100
  111840. @@ -1083,6 +1083,25 @@
  111841. }
  111842. EXPORT_SYMBOL(fb_blank);
  111843. +static int fb_copyarea_user(struct fb_info *info,
  111844. + struct fb_copyarea *copy)
  111845. +{
  111846. + int ret = 0;
  111847. + if (!lock_fb_info(info))
  111848. + return -ENODEV;
  111849. + if (copy->dx + copy->width > info->var.xres ||
  111850. + copy->sx + copy->width > info->var.xres ||
  111851. + copy->dy + copy->height > info->var.yres ||
  111852. + copy->sy + copy->height > info->var.yres) {
  111853. + ret = -EINVAL;
  111854. + goto out;
  111855. + }
  111856. + info->fbops->fb_copyarea(info, copy);
  111857. +out:
  111858. + unlock_fb_info(info);
  111859. + return ret;
  111860. +}
  111861. +
  111862. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  111863. unsigned long arg)
  111864. {
  111865. @@ -1093,6 +1112,7 @@
  111866. struct fb_cmap cmap_from;
  111867. struct fb_cmap_user cmap;
  111868. struct fb_event event;
  111869. + struct fb_copyarea copy;
  111870. void __user *argp = (void __user *)arg;
  111871. long ret = 0;
  111872. @@ -1210,6 +1230,15 @@
  111873. unlock_fb_info(info);
  111874. console_unlock();
  111875. break;
  111876. + case FBIOCOPYAREA:
  111877. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  111878. + /* only provide this ioctl if it is accelerated */
  111879. + if (copy_from_user(&copy, argp, sizeof(copy)))
  111880. + return -EFAULT;
  111881. + ret = fb_copyarea_user(info, &copy);
  111882. + break;
  111883. + }
  111884. + /* fall through */
  111885. default:
  111886. if (!lock_fb_info(info))
  111887. return -ENODEV;
  111888. @@ -1364,6 +1393,7 @@
  111889. case FBIOPAN_DISPLAY:
  111890. case FBIOGET_CON2FBMAP:
  111891. case FBIOPUT_CON2FBMAP:
  111892. + case FBIOCOPYAREA:
  111893. arg = (unsigned long) compat_ptr(arg);
  111894. case FBIOBLANK:
  111895. ret = do_fb_ioctl(info, cmd, arg);
  111896. diff -Nur linux-3.12.38/drivers/video/Kconfig linux-rpi/drivers/video/Kconfig
  111897. --- linux-3.12.38/drivers/video/Kconfig 2015-02-16 16:15:42.000000000 +0100
  111898. +++ linux-rpi/drivers/video/Kconfig 2015-03-10 17:26:51.346216687 +0100
  111899. @@ -310,6 +310,20 @@
  111900. help
  111901. Support the Permedia2 FIFO disconnect feature.
  111902. +config FB_BCM2708
  111903. + tristate "BCM2708 framebuffer support"
  111904. + depends on FB && ARM
  111905. + select FB_CFB_FILLRECT
  111906. + select FB_CFB_COPYAREA
  111907. + select FB_CFB_IMAGEBLIT
  111908. + help
  111909. + This framebuffer device driver is for the BCM2708 framebuffer.
  111910. +
  111911. + If you want to compile this as a module (=code which can be
  111912. + inserted into and removed from the running kernel), say M
  111913. + here and read <file:Documentation/kbuild/modules.txt>. The module
  111914. + will be called bcm2708_fb.
  111915. +
  111916. config FB_ARMCLCD
  111917. tristate "ARM PrimeCell PL110 support"
  111918. depends on FB && ARM && ARM_AMBA
  111919. diff -Nur linux-3.12.38/drivers/video/logo/logo.c linux-rpi/drivers/video/logo/logo.c
  111920. --- linux-3.12.38/drivers/video/logo/logo.c 2015-02-16 16:15:42.000000000 +0100
  111921. +++ linux-rpi/drivers/video/logo/logo.c 2015-03-10 17:26:51.362216687 +0100
  111922. @@ -25,21 +25,6 @@
  111923. module_param(nologo, bool, 0);
  111924. MODULE_PARM_DESC(nologo, "Disables startup logo");
  111925. -/*
  111926. - * Logos are located in the initdata, and will be freed in kernel_init.
  111927. - * Use late_init to mark the logos as freed to prevent any further use.
  111928. - */
  111929. -
  111930. -static bool logos_freed;
  111931. -
  111932. -static int __init fb_logo_late_init(void)
  111933. -{
  111934. - logos_freed = true;
  111935. - return 0;
  111936. -}
  111937. -
  111938. -late_initcall(fb_logo_late_init);
  111939. -
  111940. /* logo's are marked __initdata. Use __init_refok to tell
  111941. * modpost that it is intended that this function uses data
  111942. * marked __initdata.
  111943. @@ -48,7 +33,7 @@
  111944. {
  111945. const struct linux_logo *logo = NULL;
  111946. - if (nologo || logos_freed)
  111947. + if (nologo)
  111948. return NULL;
  111949. if (depth >= 1) {
  111950. diff -Nur linux-3.12.38/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  111951. --- linux-3.12.38/drivers/video/logo/logo_linux_clut224.ppm 2015-02-16 16:15:42.000000000 +0100
  111952. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2015-03-09 10:39:33.534893716 +0100
  111953. @@ -1,1604 +1,883 @@
  111954. P3
  111955. -# Standard 224-color Linux logo
  111956. -80 80
  111957. +63 80
  111958. 255
  111959. - 0 0 0 0 0 0 0 0 0 0 0 0
  111960. - 0 0 0 0 0 0 0 0 0 0 0 0
  111961. - 0 0 0 0 0 0 0 0 0 0 0 0
  111962. - 0 0 0 0 0 0 0 0 0 0 0 0
  111963. - 0 0 0 0 0 0 0 0 0 0 0 0
  111964. - 0 0 0 0 0 0 0 0 0 0 0 0
  111965. - 0 0 0 0 0 0 0 0 0 0 0 0
  111966. - 0 0 0 0 0 0 0 0 0 0 0 0
  111967. - 0 0 0 0 0 0 0 0 0 0 0 0
  111968. - 6 6 6 6 6 6 10 10 10 10 10 10
  111969. - 10 10 10 6 6 6 6 6 6 6 6 6
  111970. - 0 0 0 0 0 0 0 0 0 0 0 0
  111971. - 0 0 0 0 0 0 0 0 0 0 0 0
  111972. - 0 0 0 0 0 0 0 0 0 0 0 0
  111973. - 0 0 0 0 0 0 0 0 0 0 0 0
  111974. - 0 0 0 0 0 0 0 0 0 0 0 0
  111975. - 0 0 0 0 0 0 0 0 0 0 0 0
  111976. - 0 0 0 0 0 0 0 0 0 0 0 0
  111977. - 0 0 0 0 0 0 0 0 0 0 0 0
  111978. - 0 0 0 0 0 0 0 0 0 0 0 0
  111979. - 0 0 0 0 0 0 0 0 0 0 0 0
  111980. - 0 0 0 0 0 0 0 0 0 0 0 0
  111981. - 0 0 0 0 0 0 0 0 0 0 0 0
  111982. - 0 0 0 0 0 0 0 0 0 0 0 0
  111983. - 0 0 0 0 0 0 0 0 0 0 0 0
  111984. - 0 0 0 0 0 0 0 0 0 0 0 0
  111985. - 0 0 0 0 0 0 0 0 0 0 0 0
  111986. - 0 0 0 0 0 0 0 0 0 0 0 0
  111987. - 0 0 0 6 6 6 10 10 10 14 14 14
  111988. - 22 22 22 26 26 26 30 30 30 34 34 34
  111989. - 30 30 30 30 30 30 26 26 26 18 18 18
  111990. - 14 14 14 10 10 10 6 6 6 0 0 0
  111991. - 0 0 0 0 0 0 0 0 0 0 0 0
  111992. - 0 0 0 0 0 0 0 0 0 0 0 0
  111993. - 0 0 0 0 0 0 0 0 0 0 0 0
  111994. - 0 0 0 0 0 0 0 0 0 0 0 0
  111995. - 0 0 0 0 0 0 0 0 0 0 0 0
  111996. - 0 0 0 0 0 0 0 0 0 0 0 0
  111997. - 0 0 0 0 0 0 0 0 0 0 0 0
  111998. - 0 0 0 0 0 0 0 0 0 0 0 0
  111999. - 0 0 0 0 0 0 0 0 0 0 0 0
  112000. - 0 0 0 0 0 1 0 0 1 0 0 0
  112001. - 0 0 0 0 0 0 0 0 0 0 0 0
  112002. - 0 0 0 0 0 0 0 0 0 0 0 0
  112003. - 0 0 0 0 0 0 0 0 0 0 0 0
  112004. - 0 0 0 0 0 0 0 0 0 0 0 0
  112005. - 0 0 0 0 0 0 0 0 0 0 0 0
  112006. - 0 0 0 0 0 0 0 0 0 0 0 0
  112007. - 6 6 6 14 14 14 26 26 26 42 42 42
  112008. - 54 54 54 66 66 66 78 78 78 78 78 78
  112009. - 78 78 78 74 74 74 66 66 66 54 54 54
  112010. - 42 42 42 26 26 26 18 18 18 10 10 10
  112011. - 6 6 6 0 0 0 0 0 0 0 0 0
  112012. - 0 0 0 0 0 0 0 0 0 0 0 0
  112013. - 0 0 0 0 0 0 0 0 0 0 0 0
  112014. - 0 0 0 0 0 0 0 0 0 0 0 0
  112015. - 0 0 0 0 0 0 0 0 0 0 0 0
  112016. - 0 0 0 0 0 0 0 0 0 0 0 0
  112017. - 0 0 0 0 0 0 0 0 0 0 0 0
  112018. - 0 0 0 0 0 0 0 0 0 0 0 0
  112019. - 0 0 0 0 0 0 0 0 0 0 0 0
  112020. - 0 0 1 0 0 0 0 0 0 0 0 0
  112021. - 0 0 0 0 0 0 0 0 0 0 0 0
  112022. - 0 0 0 0 0 0 0 0 0 0 0 0
  112023. - 0 0 0 0 0 0 0 0 0 0 0 0
  112024. - 0 0 0 0 0 0 0 0 0 0 0 0
  112025. - 0 0 0 0 0 0 0 0 0 0 0 0
  112026. - 0 0 0 0 0 0 0 0 0 10 10 10
  112027. - 22 22 22 42 42 42 66 66 66 86 86 86
  112028. - 66 66 66 38 38 38 38 38 38 22 22 22
  112029. - 26 26 26 34 34 34 54 54 54 66 66 66
  112030. - 86 86 86 70 70 70 46 46 46 26 26 26
  112031. - 14 14 14 6 6 6 0 0 0 0 0 0
  112032. - 0 0 0 0 0 0 0 0 0 0 0 0
  112033. - 0 0 0 0 0 0 0 0 0 0 0 0
  112034. - 0 0 0 0 0 0 0 0 0 0 0 0
  112035. - 0 0 0 0 0 0 0 0 0 0 0 0
  112036. - 0 0 0 0 0 0 0 0 0 0 0 0
  112037. - 0 0 0 0 0 0 0 0 0 0 0 0
  112038. - 0 0 0 0 0 0 0 0 0 0 0 0
  112039. - 0 0 0 0 0 0 0 0 0 0 0 0
  112040. - 0 0 1 0 0 1 0 0 1 0 0 0
  112041. - 0 0 0 0 0 0 0 0 0 0 0 0
  112042. - 0 0 0 0 0 0 0 0 0 0 0 0
  112043. - 0 0 0 0 0 0 0 0 0 0 0 0
  112044. - 0 0 0 0 0 0 0 0 0 0 0 0
  112045. - 0 0 0 0 0 0 0 0 0 0 0 0
  112046. - 0 0 0 0 0 0 10 10 10 26 26 26
  112047. - 50 50 50 82 82 82 58 58 58 6 6 6
  112048. - 2 2 6 2 2 6 2 2 6 2 2 6
  112049. - 2 2 6 2 2 6 2 2 6 2 2 6
  112050. - 6 6 6 54 54 54 86 86 86 66 66 66
  112051. - 38 38 38 18 18 18 6 6 6 0 0 0
  112052. - 0 0 0 0 0 0 0 0 0 0 0 0
  112053. - 0 0 0 0 0 0 0 0 0 0 0 0
  112054. - 0 0 0 0 0 0 0 0 0 0 0 0
  112055. - 0 0 0 0 0 0 0 0 0 0 0 0
  112056. - 0 0 0 0 0 0 0 0 0 0 0 0
  112057. - 0 0 0 0 0 0 0 0 0 0 0 0
  112058. - 0 0 0 0 0 0 0 0 0 0 0 0
  112059. - 0 0 0 0 0 0 0 0 0 0 0 0
  112060. - 0 0 0 0 0 0 0 0 0 0 0 0
  112061. - 0 0 0 0 0 0 0 0 0 0 0 0
  112062. - 0 0 0 0 0 0 0 0 0 0 0 0
  112063. - 0 0 0 0 0 0 0 0 0 0 0 0
  112064. - 0 0 0 0 0 0 0 0 0 0 0 0
  112065. - 0 0 0 0 0 0 0 0 0 0 0 0
  112066. - 0 0 0 6 6 6 22 22 22 50 50 50
  112067. - 78 78 78 34 34 34 2 2 6 2 2 6
  112068. - 2 2 6 2 2 6 2 2 6 2 2 6
  112069. - 2 2 6 2 2 6 2 2 6 2 2 6
  112070. - 2 2 6 2 2 6 6 6 6 70 70 70
  112071. - 78 78 78 46 46 46 22 22 22 6 6 6
  112072. - 0 0 0 0 0 0 0 0 0 0 0 0
  112073. - 0 0 0 0 0 0 0 0 0 0 0 0
  112074. - 0 0 0 0 0 0 0 0 0 0 0 0
  112075. - 0 0 0 0 0 0 0 0 0 0 0 0
  112076. - 0 0 0 0 0 0 0 0 0 0 0 0
  112077. - 0 0 0 0 0 0 0 0 0 0 0 0
  112078. - 0 0 0 0 0 0 0 0 0 0 0 0
  112079. - 0 0 0 0 0 0 0 0 0 0 0 0
  112080. - 0 0 1 0 0 1 0 0 1 0 0 0
  112081. - 0 0 0 0 0 0 0 0 0 0 0 0
  112082. - 0 0 0 0 0 0 0 0 0 0 0 0
  112083. - 0 0 0 0 0 0 0 0 0 0 0 0
  112084. - 0 0 0 0 0 0 0 0 0 0 0 0
  112085. - 0 0 0 0 0 0 0 0 0 0 0 0
  112086. - 6 6 6 18 18 18 42 42 42 82 82 82
  112087. - 26 26 26 2 2 6 2 2 6 2 2 6
  112088. - 2 2 6 2 2 6 2 2 6 2 2 6
  112089. - 2 2 6 2 2 6 2 2 6 14 14 14
  112090. - 46 46 46 34 34 34 6 6 6 2 2 6
  112091. - 42 42 42 78 78 78 42 42 42 18 18 18
  112092. - 6 6 6 0 0 0 0 0 0 0 0 0
  112093. - 0 0 0 0 0 0 0 0 0 0 0 0
  112094. - 0 0 0 0 0 0 0 0 0 0 0 0
  112095. - 0 0 0 0 0 0 0 0 0 0 0 0
  112096. - 0 0 0 0 0 0 0 0 0 0 0 0
  112097. - 0 0 0 0 0 0 0 0 0 0 0 0
  112098. - 0 0 0 0 0 0 0 0 0 0 0 0
  112099. - 0 0 0 0 0 0 0 0 0 0 0 0
  112100. - 0 0 1 0 0 0 0 0 1 0 0 0
  112101. - 0 0 0 0 0 0 0 0 0 0 0 0
  112102. - 0 0 0 0 0 0 0 0 0 0 0 0
  112103. - 0 0 0 0 0 0 0 0 0 0 0 0
  112104. - 0 0 0 0 0 0 0 0 0 0 0 0
  112105. - 0 0 0 0 0 0 0 0 0 0 0 0
  112106. - 10 10 10 30 30 30 66 66 66 58 58 58
  112107. - 2 2 6 2 2 6 2 2 6 2 2 6
  112108. - 2 2 6 2 2 6 2 2 6 2 2 6
  112109. - 2 2 6 2 2 6 2 2 6 26 26 26
  112110. - 86 86 86 101 101 101 46 46 46 10 10 10
  112111. - 2 2 6 58 58 58 70 70 70 34 34 34
  112112. - 10 10 10 0 0 0 0 0 0 0 0 0
  112113. - 0 0 0 0 0 0 0 0 0 0 0 0
  112114. - 0 0 0 0 0 0 0 0 0 0 0 0
  112115. - 0 0 0 0 0 0 0 0 0 0 0 0
  112116. - 0 0 0 0 0 0 0 0 0 0 0 0
  112117. - 0 0 0 0 0 0 0 0 0 0 0 0
  112118. - 0 0 0 0 0 0 0 0 0 0 0 0
  112119. - 0 0 0 0 0 0 0 0 0 0 0 0
  112120. - 0 0 1 0 0 1 0 0 1 0 0 0
  112121. - 0 0 0 0 0 0 0 0 0 0 0 0
  112122. - 0 0 0 0 0 0 0 0 0 0 0 0
  112123. - 0 0 0 0 0 0 0 0 0 0 0 0
  112124. - 0 0 0 0 0 0 0 0 0 0 0 0
  112125. - 0 0 0 0 0 0 0 0 0 0 0 0
  112126. - 14 14 14 42 42 42 86 86 86 10 10 10
  112127. - 2 2 6 2 2 6 2 2 6 2 2 6
  112128. - 2 2 6 2 2 6 2 2 6 2 2 6
  112129. - 2 2 6 2 2 6 2 2 6 30 30 30
  112130. - 94 94 94 94 94 94 58 58 58 26 26 26
  112131. - 2 2 6 6 6 6 78 78 78 54 54 54
  112132. - 22 22 22 6 6 6 0 0 0 0 0 0
  112133. - 0 0 0 0 0 0 0 0 0 0 0 0
  112134. - 0 0 0 0 0 0 0 0 0 0 0 0
  112135. - 0 0 0 0 0 0 0 0 0 0 0 0
  112136. - 0 0 0 0 0 0 0 0 0 0 0 0
  112137. - 0 0 0 0 0 0 0 0 0 0 0 0
  112138. - 0 0 0 0 0 0 0 0 0 0 0 0
  112139. - 0 0 0 0 0 0 0 0 0 0 0 0
  112140. - 0 0 0 0 0 0 0 0 0 0 0 0
  112141. - 0 0 0 0 0 0 0 0 0 0 0 0
  112142. - 0 0 0 0 0 0 0 0 0 0 0 0
  112143. - 0 0 0 0 0 0 0 0 0 0 0 0
  112144. - 0 0 0 0 0 0 0 0 0 0 0 0
  112145. - 0 0 0 0 0 0 0 0 0 6 6 6
  112146. - 22 22 22 62 62 62 62 62 62 2 2 6
  112147. - 2 2 6 2 2 6 2 2 6 2 2 6
  112148. - 2 2 6 2 2 6 2 2 6 2 2 6
  112149. - 2 2 6 2 2 6 2 2 6 26 26 26
  112150. - 54 54 54 38 38 38 18 18 18 10 10 10
  112151. - 2 2 6 2 2 6 34 34 34 82 82 82
  112152. - 38 38 38 14 14 14 0 0 0 0 0 0
  112153. - 0 0 0 0 0 0 0 0 0 0 0 0
  112154. - 0 0 0 0 0 0 0 0 0 0 0 0
  112155. - 0 0 0 0 0 0 0 0 0 0 0 0
  112156. - 0 0 0 0 0 0 0 0 0 0 0 0
  112157. - 0 0 0 0 0 0 0 0 0 0 0 0
  112158. - 0 0 0 0 0 0 0 0 0 0 0 0
  112159. - 0 0 0 0 0 0 0 0 0 0 0 0
  112160. - 0 0 0 0 0 1 0 0 1 0 0 0
  112161. - 0 0 0 0 0 0 0 0 0 0 0 0
  112162. - 0 0 0 0 0 0 0 0 0 0 0 0
  112163. - 0 0 0 0 0 0 0 0 0 0 0 0
  112164. - 0 0 0 0 0 0 0 0 0 0 0 0
  112165. - 0 0 0 0 0 0 0 0 0 6 6 6
  112166. - 30 30 30 78 78 78 30 30 30 2 2 6
  112167. - 2 2 6 2 2 6 2 2 6 2 2 6
  112168. - 2 2 6 2 2 6 2 2 6 2 2 6
  112169. - 2 2 6 2 2 6 2 2 6 10 10 10
  112170. - 10 10 10 2 2 6 2 2 6 2 2 6
  112171. - 2 2 6 2 2 6 2 2 6 78 78 78
  112172. - 50 50 50 18 18 18 6 6 6 0 0 0
  112173. - 0 0 0 0 0 0 0 0 0 0 0 0
  112174. - 0 0 0 0 0 0 0 0 0 0 0 0
  112175. - 0 0 0 0 0 0 0 0 0 0 0 0
  112176. - 0 0 0 0 0 0 0 0 0 0 0 0
  112177. - 0 0 0 0 0 0 0 0 0 0 0 0
  112178. - 0 0 0 0 0 0 0 0 0 0 0 0
  112179. - 0 0 0 0 0 0 0 0 0 0 0 0
  112180. - 0 0 1 0 0 0 0 0 0 0 0 0
  112181. - 0 0 0 0 0 0 0 0 0 0 0 0
  112182. - 0 0 0 0 0 0 0 0 0 0 0 0
  112183. - 0 0 0 0 0 0 0 0 0 0 0 0
  112184. - 0 0 0 0 0 0 0 0 0 0 0 0
  112185. - 0 0 0 0 0 0 0 0 0 10 10 10
  112186. - 38 38 38 86 86 86 14 14 14 2 2 6
  112187. - 2 2 6 2 2 6 2 2 6 2 2 6
  112188. - 2 2 6 2 2 6 2 2 6 2 2 6
  112189. - 2 2 6 2 2 6 2 2 6 2 2 6
  112190. - 2 2 6 2 2 6 2 2 6 2 2 6
  112191. - 2 2 6 2 2 6 2 2 6 54 54 54
  112192. - 66 66 66 26 26 26 6 6 6 0 0 0
  112193. - 0 0 0 0 0 0 0 0 0 0 0 0
  112194. - 0 0 0 0 0 0 0 0 0 0 0 0
  112195. - 0 0 0 0 0 0 0 0 0 0 0 0
  112196. - 0 0 0 0 0 0 0 0 0 0 0 0
  112197. - 0 0 0 0 0 0 0 0 0 0 0 0
  112198. - 0 0 0 0 0 0 0 0 0 0 0 0
  112199. - 0 0 0 0 0 0 0 0 0 0 0 0
  112200. - 0 0 0 0 0 1 0 0 1 0 0 0
  112201. - 0 0 0 0 0 0 0 0 0 0 0 0
  112202. - 0 0 0 0 0 0 0 0 0 0 0 0
  112203. - 0 0 0 0 0 0 0 0 0 0 0 0
  112204. - 0 0 0 0 0 0 0 0 0 0 0 0
  112205. - 0 0 0 0 0 0 0 0 0 14 14 14
  112206. - 42 42 42 82 82 82 2 2 6 2 2 6
  112207. - 2 2 6 6 6 6 10 10 10 2 2 6
  112208. - 2 2 6 2 2 6 2 2 6 2 2 6
  112209. - 2 2 6 2 2 6 2 2 6 6 6 6
  112210. - 14 14 14 10 10 10 2 2 6 2 2 6
  112211. - 2 2 6 2 2 6 2 2 6 18 18 18
  112212. - 82 82 82 34 34 34 10 10 10 0 0 0
  112213. - 0 0 0 0 0 0 0 0 0 0 0 0
  112214. - 0 0 0 0 0 0 0 0 0 0 0 0
  112215. - 0 0 0 0 0 0 0 0 0 0 0 0
  112216. - 0 0 0 0 0 0 0 0 0 0 0 0
  112217. - 0 0 0 0 0 0 0 0 0 0 0 0
  112218. - 0 0 0 0 0 0 0 0 0 0 0 0
  112219. - 0 0 0 0 0 0 0 0 0 0 0 0
  112220. - 0 0 1 0 0 0 0 0 0 0 0 0
  112221. - 0 0 0 0 0 0 0 0 0 0 0 0
  112222. - 0 0 0 0 0 0 0 0 0 0 0 0
  112223. - 0 0 0 0 0 0 0 0 0 0 0 0
  112224. - 0 0 0 0 0 0 0 0 0 0 0 0
  112225. - 0 0 0 0 0 0 0 0 0 14 14 14
  112226. - 46 46 46 86 86 86 2 2 6 2 2 6
  112227. - 6 6 6 6 6 6 22 22 22 34 34 34
  112228. - 6 6 6 2 2 6 2 2 6 2 2 6
  112229. - 2 2 6 2 2 6 18 18 18 34 34 34
  112230. - 10 10 10 50 50 50 22 22 22 2 2 6
  112231. - 2 2 6 2 2 6 2 2 6 10 10 10
  112232. - 86 86 86 42 42 42 14 14 14 0 0 0
  112233. - 0 0 0 0 0 0 0 0 0 0 0 0
  112234. - 0 0 0 0 0 0 0 0 0 0 0 0
  112235. - 0 0 0 0 0 0 0 0 0 0 0 0
  112236. - 0 0 0 0 0 0 0 0 0 0 0 0
  112237. - 0 0 0 0 0 0 0 0 0 0 0 0
  112238. - 0 0 0 0 0 0 0 0 0 0 0 0
  112239. - 0 0 0 0 0 0 0 0 0 0 0 0
  112240. - 0 0 1 0 0 1 0 0 1 0 0 0
  112241. - 0 0 0 0 0 0 0 0 0 0 0 0
  112242. - 0 0 0 0 0 0 0 0 0 0 0 0
  112243. - 0 0 0 0 0 0 0 0 0 0 0 0
  112244. - 0 0 0 0 0 0 0 0 0 0 0 0
  112245. - 0 0 0 0 0 0 0 0 0 14 14 14
  112246. - 46 46 46 86 86 86 2 2 6 2 2 6
  112247. - 38 38 38 116 116 116 94 94 94 22 22 22
  112248. - 22 22 22 2 2 6 2 2 6 2 2 6
  112249. - 14 14 14 86 86 86 138 138 138 162 162 162
  112250. -154 154 154 38 38 38 26 26 26 6 6 6
  112251. - 2 2 6 2 2 6 2 2 6 2 2 6
  112252. - 86 86 86 46 46 46 14 14 14 0 0 0
  112253. - 0 0 0 0 0 0 0 0 0 0 0 0
  112254. - 0 0 0 0 0 0 0 0 0 0 0 0
  112255. - 0 0 0 0 0 0 0 0 0 0 0 0
  112256. - 0 0 0 0 0 0 0 0 0 0 0 0
  112257. - 0 0 0 0 0 0 0 0 0 0 0 0
  112258. - 0 0 0 0 0 0 0 0 0 0 0 0
  112259. - 0 0 0 0 0 0 0 0 0 0 0 0
  112260. - 0 0 0 0 0 0 0 0 0 0 0 0
  112261. - 0 0 0 0 0 0 0 0 0 0 0 0
  112262. - 0 0 0 0 0 0 0 0 0 0 0 0
  112263. - 0 0 0 0 0 0 0 0 0 0 0 0
  112264. - 0 0 0 0 0 0 0 0 0 0 0 0
  112265. - 0 0 0 0 0 0 0 0 0 14 14 14
  112266. - 46 46 46 86 86 86 2 2 6 14 14 14
  112267. -134 134 134 198 198 198 195 195 195 116 116 116
  112268. - 10 10 10 2 2 6 2 2 6 6 6 6
  112269. -101 98 89 187 187 187 210 210 210 218 218 218
  112270. -214 214 214 134 134 134 14 14 14 6 6 6
  112271. - 2 2 6 2 2 6 2 2 6 2 2 6
  112272. - 86 86 86 50 50 50 18 18 18 6 6 6
  112273. - 0 0 0 0 0 0 0 0 0 0 0 0
  112274. - 0 0 0 0 0 0 0 0 0 0 0 0
  112275. - 0 0 0 0 0 0 0 0 0 0 0 0
  112276. - 0 0 0 0 0 0 0 0 0 0 0 0
  112277. - 0 0 0 0 0 0 0 0 0 0 0 0
  112278. - 0 0 0 0 0 0 0 0 0 0 0 0
  112279. - 0 0 0 0 0 0 0 0 1 0 0 0
  112280. - 0 0 1 0 0 1 0 0 1 0 0 0
  112281. - 0 0 0 0 0 0 0 0 0 0 0 0
  112282. - 0 0 0 0 0 0 0 0 0 0 0 0
  112283. - 0 0 0 0 0 0 0 0 0 0 0 0
  112284. - 0 0 0 0 0 0 0 0 0 0 0 0
  112285. - 0 0 0 0 0 0 0 0 0 14 14 14
  112286. - 46 46 46 86 86 86 2 2 6 54 54 54
  112287. -218 218 218 195 195 195 226 226 226 246 246 246
  112288. - 58 58 58 2 2 6 2 2 6 30 30 30
  112289. -210 210 210 253 253 253 174 174 174 123 123 123
  112290. -221 221 221 234 234 234 74 74 74 2 2 6
  112291. - 2 2 6 2 2 6 2 2 6 2 2 6
  112292. - 70 70 70 58 58 58 22 22 22 6 6 6
  112293. - 0 0 0 0 0 0 0 0 0 0 0 0
  112294. - 0 0 0 0 0 0 0 0 0 0 0 0
  112295. - 0 0 0 0 0 0 0 0 0 0 0 0
  112296. - 0 0 0 0 0 0 0 0 0 0 0 0
  112297. - 0 0 0 0 0 0 0 0 0 0 0 0
  112298. - 0 0 0 0 0 0 0 0 0 0 0 0
  112299. - 0 0 0 0 0 0 0 0 0 0 0 0
  112300. - 0 0 0 0 0 0 0 0 0 0 0 0
  112301. - 0 0 0 0 0 0 0 0 0 0 0 0
  112302. - 0 0 0 0 0 0 0 0 0 0 0 0
  112303. - 0 0 0 0 0 0 0 0 0 0 0 0
  112304. - 0 0 0 0 0 0 0 0 0 0 0 0
  112305. - 0 0 0 0 0 0 0 0 0 14 14 14
  112306. - 46 46 46 82 82 82 2 2 6 106 106 106
  112307. -170 170 170 26 26 26 86 86 86 226 226 226
  112308. -123 123 123 10 10 10 14 14 14 46 46 46
  112309. -231 231 231 190 190 190 6 6 6 70 70 70
  112310. - 90 90 90 238 238 238 158 158 158 2 2 6
  112311. - 2 2 6 2 2 6 2 2 6 2 2 6
  112312. - 70 70 70 58 58 58 22 22 22 6 6 6
  112313. - 0 0 0 0 0 0 0 0 0 0 0 0
  112314. - 0 0 0 0 0 0 0 0 0 0 0 0
  112315. - 0 0 0 0 0 0 0 0 0 0 0 0
  112316. - 0 0 0 0 0 0 0 0 0 0 0 0
  112317. - 0 0 0 0 0 0 0 0 0 0 0 0
  112318. - 0 0 0 0 0 0 0 0 0 0 0 0
  112319. - 0 0 0 0 0 0 0 0 1 0 0 0
  112320. - 0 0 1 0 0 1 0 0 1 0 0 0
  112321. - 0 0 0 0 0 0 0 0 0 0 0 0
  112322. - 0 0 0 0 0 0 0 0 0 0 0 0
  112323. - 0 0 0 0 0 0 0 0 0 0 0 0
  112324. - 0 0 0 0 0 0 0 0 0 0 0 0
  112325. - 0 0 0 0 0 0 0 0 0 14 14 14
  112326. - 42 42 42 86 86 86 6 6 6 116 116 116
  112327. -106 106 106 6 6 6 70 70 70 149 149 149
  112328. -128 128 128 18 18 18 38 38 38 54 54 54
  112329. -221 221 221 106 106 106 2 2 6 14 14 14
  112330. - 46 46 46 190 190 190 198 198 198 2 2 6
  112331. - 2 2 6 2 2 6 2 2 6 2 2 6
  112332. - 74 74 74 62 62 62 22 22 22 6 6 6
  112333. - 0 0 0 0 0 0 0 0 0 0 0 0
  112334. - 0 0 0 0 0 0 0 0 0 0 0 0
  112335. - 0 0 0 0 0 0 0 0 0 0 0 0
  112336. - 0 0 0 0 0 0 0 0 0 0 0 0
  112337. - 0 0 0 0 0 0 0 0 0 0 0 0
  112338. - 0 0 0 0 0 0 0 0 0 0 0 0
  112339. - 0 0 0 0 0 0 0 0 1 0 0 0
  112340. - 0 0 1 0 0 0 0 0 1 0 0 0
  112341. - 0 0 0 0 0 0 0 0 0 0 0 0
  112342. - 0 0 0 0 0 0 0 0 0 0 0 0
  112343. - 0 0 0 0 0 0 0 0 0 0 0 0
  112344. - 0 0 0 0 0 0 0 0 0 0 0 0
  112345. - 0 0 0 0 0 0 0 0 0 14 14 14
  112346. - 42 42 42 94 94 94 14 14 14 101 101 101
  112347. -128 128 128 2 2 6 18 18 18 116 116 116
  112348. -118 98 46 121 92 8 121 92 8 98 78 10
  112349. -162 162 162 106 106 106 2 2 6 2 2 6
  112350. - 2 2 6 195 195 195 195 195 195 6 6 6
  112351. - 2 2 6 2 2 6 2 2 6 2 2 6
  112352. - 74 74 74 62 62 62 22 22 22 6 6 6
  112353. - 0 0 0 0 0 0 0 0 0 0 0 0
  112354. - 0 0 0 0 0 0 0 0 0 0 0 0
  112355. - 0 0 0 0 0 0 0 0 0 0 0 0
  112356. - 0 0 0 0 0 0 0 0 0 0 0 0
  112357. - 0 0 0 0 0 0 0 0 0 0 0 0
  112358. - 0 0 0 0 0 0 0 0 0 0 0 0
  112359. - 0 0 0 0 0 0 0 0 1 0 0 1
  112360. - 0 0 1 0 0 0 0 0 1 0 0 0
  112361. - 0 0 0 0 0 0 0 0 0 0 0 0
  112362. - 0 0 0 0 0 0 0 0 0 0 0 0
  112363. - 0 0 0 0 0 0 0 0 0 0 0 0
  112364. - 0 0 0 0 0 0 0 0 0 0 0 0
  112365. - 0 0 0 0 0 0 0 0 0 10 10 10
  112366. - 38 38 38 90 90 90 14 14 14 58 58 58
  112367. -210 210 210 26 26 26 54 38 6 154 114 10
  112368. -226 170 11 236 186 11 225 175 15 184 144 12
  112369. -215 174 15 175 146 61 37 26 9 2 2 6
  112370. - 70 70 70 246 246 246 138 138 138 2 2 6
  112371. - 2 2 6 2 2 6 2 2 6 2 2 6
  112372. - 70 70 70 66 66 66 26 26 26 6 6 6
  112373. - 0 0 0 0 0 0 0 0 0 0 0 0
  112374. - 0 0 0 0 0 0 0 0 0 0 0 0
  112375. - 0 0 0 0 0 0 0 0 0 0 0 0
  112376. - 0 0 0 0 0 0 0 0 0 0 0 0
  112377. - 0 0 0 0 0 0 0 0 0 0 0 0
  112378. - 0 0 0 0 0 0 0 0 0 0 0 0
  112379. - 0 0 0 0 0 0 0 0 0 0 0 0
  112380. - 0 0 0 0 0 0 0 0 0 0 0 0
  112381. - 0 0 0 0 0 0 0 0 0 0 0 0
  112382. - 0 0 0 0 0 0 0 0 0 0 0 0
  112383. - 0 0 0 0 0 0 0 0 0 0 0 0
  112384. - 0 0 0 0 0 0 0 0 0 0 0 0
  112385. - 0 0 0 0 0 0 0 0 0 10 10 10
  112386. - 38 38 38 86 86 86 14 14 14 10 10 10
  112387. -195 195 195 188 164 115 192 133 9 225 175 15
  112388. -239 182 13 234 190 10 232 195 16 232 200 30
  112389. -245 207 45 241 208 19 232 195 16 184 144 12
  112390. -218 194 134 211 206 186 42 42 42 2 2 6
  112391. - 2 2 6 2 2 6 2 2 6 2 2 6
  112392. - 50 50 50 74 74 74 30 30 30 6 6 6
  112393. - 0 0 0 0 0 0 0 0 0 0 0 0
  112394. - 0 0 0 0 0 0 0 0 0 0 0 0
  112395. - 0 0 0 0 0 0 0 0 0 0 0 0
  112396. - 0 0 0 0 0 0 0 0 0 0 0 0
  112397. - 0 0 0 0 0 0 0 0 0 0 0 0
  112398. - 0 0 0 0 0 0 0 0 0 0 0 0
  112399. - 0 0 0 0 0 0 0 0 0 0 0 0
  112400. - 0 0 0 0 0 0 0 0 0 0 0 0
  112401. - 0 0 0 0 0 0 0 0 0 0 0 0
  112402. - 0 0 0 0 0 0 0 0 0 0 0 0
  112403. - 0 0 0 0 0 0 0 0 0 0 0 0
  112404. - 0 0 0 0 0 0 0 0 0 0 0 0
  112405. - 0 0 0 0 0 0 0 0 0 10 10 10
  112406. - 34 34 34 86 86 86 14 14 14 2 2 6
  112407. -121 87 25 192 133 9 219 162 10 239 182 13
  112408. -236 186 11 232 195 16 241 208 19 244 214 54
  112409. -246 218 60 246 218 38 246 215 20 241 208 19
  112410. -241 208 19 226 184 13 121 87 25 2 2 6
  112411. - 2 2 6 2 2 6 2 2 6 2 2 6
  112412. - 50 50 50 82 82 82 34 34 34 10 10 10
  112413. - 0 0 0 0 0 0 0 0 0 0 0 0
  112414. - 0 0 0 0 0 0 0 0 0 0 0 0
  112415. - 0 0 0 0 0 0 0 0 0 0 0 0
  112416. - 0 0 0 0 0 0 0 0 0 0 0 0
  112417. - 0 0 0 0 0 0 0 0 0 0 0 0
  112418. - 0 0 0 0 0 0 0 0 0 0 0 0
  112419. - 0 0 0 0 0 0 0 0 0 0 0 0
  112420. - 0 0 0 0 0 0 0 0 0 0 0 0
  112421. - 0 0 0 0 0 0 0 0 0 0 0 0
  112422. - 0 0 0 0 0 0 0 0 0 0 0 0
  112423. - 0 0 0 0 0 0 0 0 0 0 0 0
  112424. - 0 0 0 0 0 0 0 0 0 0 0 0
  112425. - 0 0 0 0 0 0 0 0 0 10 10 10
  112426. - 34 34 34 82 82 82 30 30 30 61 42 6
  112427. -180 123 7 206 145 10 230 174 11 239 182 13
  112428. -234 190 10 238 202 15 241 208 19 246 218 74
  112429. -246 218 38 246 215 20 246 215 20 246 215 20
  112430. -226 184 13 215 174 15 184 144 12 6 6 6
  112431. - 2 2 6 2 2 6 2 2 6 2 2 6
  112432. - 26 26 26 94 94 94 42 42 42 14 14 14
  112433. - 0 0 0 0 0 0 0 0 0 0 0 0
  112434. - 0 0 0 0 0 0 0 0 0 0 0 0
  112435. - 0 0 0 0 0 0 0 0 0 0 0 0
  112436. - 0 0 0 0 0 0 0 0 0 0 0 0
  112437. - 0 0 0 0 0 0 0 0 0 0 0 0
  112438. - 0 0 0 0 0 0 0 0 0 0 0 0
  112439. - 0 0 0 0 0 0 0 0 0 0 0 0
  112440. - 0 0 0 0 0 0 0 0 0 0 0 0
  112441. - 0 0 0 0 0 0 0 0 0 0 0 0
  112442. - 0 0 0 0 0 0 0 0 0 0 0 0
  112443. - 0 0 0 0 0 0 0 0 0 0 0 0
  112444. - 0 0 0 0 0 0 0 0 0 0 0 0
  112445. - 0 0 0 0 0 0 0 0 0 10 10 10
  112446. - 30 30 30 78 78 78 50 50 50 104 69 6
  112447. -192 133 9 216 158 10 236 178 12 236 186 11
  112448. -232 195 16 241 208 19 244 214 54 245 215 43
  112449. -246 215 20 246 215 20 241 208 19 198 155 10
  112450. -200 144 11 216 158 10 156 118 10 2 2 6
  112451. - 2 2 6 2 2 6 2 2 6 2 2 6
  112452. - 6 6 6 90 90 90 54 54 54 18 18 18
  112453. - 6 6 6 0 0 0 0 0 0 0 0 0
  112454. - 0 0 0 0 0 0 0 0 0 0 0 0
  112455. - 0 0 0 0 0 0 0 0 0 0 0 0
  112456. - 0 0 0 0 0 0 0 0 0 0 0 0
  112457. - 0 0 0 0 0 0 0 0 0 0 0 0
  112458. - 0 0 0 0 0 0 0 0 0 0 0 0
  112459. - 0 0 0 0 0 0 0 0 0 0 0 0
  112460. - 0 0 0 0 0 0 0 0 0 0 0 0
  112461. - 0 0 0 0 0 0 0 0 0 0 0 0
  112462. - 0 0 0 0 0 0 0 0 0 0 0 0
  112463. - 0 0 0 0 0 0 0 0 0 0 0 0
  112464. - 0 0 0 0 0 0 0 0 0 0 0 0
  112465. - 0 0 0 0 0 0 0 0 0 10 10 10
  112466. - 30 30 30 78 78 78 46 46 46 22 22 22
  112467. -137 92 6 210 162 10 239 182 13 238 190 10
  112468. -238 202 15 241 208 19 246 215 20 246 215 20
  112469. -241 208 19 203 166 17 185 133 11 210 150 10
  112470. -216 158 10 210 150 10 102 78 10 2 2 6
  112471. - 6 6 6 54 54 54 14 14 14 2 2 6
  112472. - 2 2 6 62 62 62 74 74 74 30 30 30
  112473. - 10 10 10 0 0 0 0 0 0 0 0 0
  112474. - 0 0 0 0 0 0 0 0 0 0 0 0
  112475. - 0 0 0 0 0 0 0 0 0 0 0 0
  112476. - 0 0 0 0 0 0 0 0 0 0 0 0
  112477. - 0 0 0 0 0 0 0 0 0 0 0 0
  112478. - 0 0 0 0 0 0 0 0 0 0 0 0
  112479. - 0 0 0 0 0 0 0 0 0 0 0 0
  112480. - 0 0 0 0 0 0 0 0 0 0 0 0
  112481. - 0 0 0 0 0 0 0 0 0 0 0 0
  112482. - 0 0 0 0 0 0 0 0 0 0 0 0
  112483. - 0 0 0 0 0 0 0 0 0 0 0 0
  112484. - 0 0 0 0 0 0 0 0 0 0 0 0
  112485. - 0 0 0 0 0 0 0 0 0 10 10 10
  112486. - 34 34 34 78 78 78 50 50 50 6 6 6
  112487. - 94 70 30 139 102 15 190 146 13 226 184 13
  112488. -232 200 30 232 195 16 215 174 15 190 146 13
  112489. -168 122 10 192 133 9 210 150 10 213 154 11
  112490. -202 150 34 182 157 106 101 98 89 2 2 6
  112491. - 2 2 6 78 78 78 116 116 116 58 58 58
  112492. - 2 2 6 22 22 22 90 90 90 46 46 46
  112493. - 18 18 18 6 6 6 0 0 0 0 0 0
  112494. - 0 0 0 0 0 0 0 0 0 0 0 0
  112495. - 0 0 0 0 0 0 0 0 0 0 0 0
  112496. - 0 0 0 0 0 0 0 0 0 0 0 0
  112497. - 0 0 0 0 0 0 0 0 0 0 0 0
  112498. - 0 0 0 0 0 0 0 0 0 0 0 0
  112499. - 0 0 0 0 0 0 0 0 0 0 0 0
  112500. - 0 0 0 0 0 0 0 0 0 0 0 0
  112501. - 0 0 0 0 0 0 0 0 0 0 0 0
  112502. - 0 0 0 0 0 0 0 0 0 0 0 0
  112503. - 0 0 0 0 0 0 0 0 0 0 0 0
  112504. - 0 0 0 0 0 0 0 0 0 0 0 0
  112505. - 0 0 0 0 0 0 0 0 0 10 10 10
  112506. - 38 38 38 86 86 86 50 50 50 6 6 6
  112507. -128 128 128 174 154 114 156 107 11 168 122 10
  112508. -198 155 10 184 144 12 197 138 11 200 144 11
  112509. -206 145 10 206 145 10 197 138 11 188 164 115
  112510. -195 195 195 198 198 198 174 174 174 14 14 14
  112511. - 2 2 6 22 22 22 116 116 116 116 116 116
  112512. - 22 22 22 2 2 6 74 74 74 70 70 70
  112513. - 30 30 30 10 10 10 0 0 0 0 0 0
  112514. - 0 0 0 0 0 0 0 0 0 0 0 0
  112515. - 0 0 0 0 0 0 0 0 0 0 0 0
  112516. - 0 0 0 0 0 0 0 0 0 0 0 0
  112517. - 0 0 0 0 0 0 0 0 0 0 0 0
  112518. - 0 0 0 0 0 0 0 0 0 0 0 0
  112519. - 0 0 0 0 0 0 0 0 0 0 0 0
  112520. - 0 0 0 0 0 0 0 0 0 0 0 0
  112521. - 0 0 0 0 0 0 0 0 0 0 0 0
  112522. - 0 0 0 0 0 0 0 0 0 0 0 0
  112523. - 0 0 0 0 0 0 0 0 0 0 0 0
  112524. - 0 0 0 0 0 0 0 0 0 0 0 0
  112525. - 0 0 0 0 0 0 6 6 6 18 18 18
  112526. - 50 50 50 101 101 101 26 26 26 10 10 10
  112527. -138 138 138 190 190 190 174 154 114 156 107 11
  112528. -197 138 11 200 144 11 197 138 11 192 133 9
  112529. -180 123 7 190 142 34 190 178 144 187 187 187
  112530. -202 202 202 221 221 221 214 214 214 66 66 66
  112531. - 2 2 6 2 2 6 50 50 50 62 62 62
  112532. - 6 6 6 2 2 6 10 10 10 90 90 90
  112533. - 50 50 50 18 18 18 6 6 6 0 0 0
  112534. - 0 0 0 0 0 0 0 0 0 0 0 0
  112535. - 0 0 0 0 0 0 0 0 0 0 0 0
  112536. - 0 0 0 0 0 0 0 0 0 0 0 0
  112537. - 0 0 0 0 0 0 0 0 0 0 0 0
  112538. - 0 0 0 0 0 0 0 0 0 0 0 0
  112539. - 0 0 0 0 0 0 0 0 0 0 0 0
  112540. - 0 0 0 0 0 0 0 0 0 0 0 0
  112541. - 0 0 0 0 0 0 0 0 0 0 0 0
  112542. - 0 0 0 0 0 0 0 0 0 0 0 0
  112543. - 0 0 0 0 0 0 0 0 0 0 0 0
  112544. - 0 0 0 0 0 0 0 0 0 0 0 0
  112545. - 0 0 0 0 0 0 10 10 10 34 34 34
  112546. - 74 74 74 74 74 74 2 2 6 6 6 6
  112547. -144 144 144 198 198 198 190 190 190 178 166 146
  112548. -154 121 60 156 107 11 156 107 11 168 124 44
  112549. -174 154 114 187 187 187 190 190 190 210 210 210
  112550. -246 246 246 253 253 253 253 253 253 182 182 182
  112551. - 6 6 6 2 2 6 2 2 6 2 2 6
  112552. - 2 2 6 2 2 6 2 2 6 62 62 62
  112553. - 74 74 74 34 34 34 14 14 14 0 0 0
  112554. - 0 0 0 0 0 0 0 0 0 0 0 0
  112555. - 0 0 0 0 0 0 0 0 0 0 0 0
  112556. - 0 0 0 0 0 0 0 0 0 0 0 0
  112557. - 0 0 0 0 0 0 0 0 0 0 0 0
  112558. - 0 0 0 0 0 0 0 0 0 0 0 0
  112559. - 0 0 0 0 0 0 0 0 0 0 0 0
  112560. - 0 0 0 0 0 0 0 0 0 0 0 0
  112561. - 0 0 0 0 0 0 0 0 0 0 0 0
  112562. - 0 0 0 0 0 0 0 0 0 0 0 0
  112563. - 0 0 0 0 0 0 0 0 0 0 0 0
  112564. - 0 0 0 0 0 0 0 0 0 0 0 0
  112565. - 0 0 0 10 10 10 22 22 22 54 54 54
  112566. - 94 94 94 18 18 18 2 2 6 46 46 46
  112567. -234 234 234 221 221 221 190 190 190 190 190 190
  112568. -190 190 190 187 187 187 187 187 187 190 190 190
  112569. -190 190 190 195 195 195 214 214 214 242 242 242
  112570. -253 253 253 253 253 253 253 253 253 253 253 253
  112571. - 82 82 82 2 2 6 2 2 6 2 2 6
  112572. - 2 2 6 2 2 6 2 2 6 14 14 14
  112573. - 86 86 86 54 54 54 22 22 22 6 6 6
  112574. - 0 0 0 0 0 0 0 0 0 0 0 0
  112575. - 0 0 0 0 0 0 0 0 0 0 0 0
  112576. - 0 0 0 0 0 0 0 0 0 0 0 0
  112577. - 0 0 0 0 0 0 0 0 0 0 0 0
  112578. - 0 0 0 0 0 0 0 0 0 0 0 0
  112579. - 0 0 0 0 0 0 0 0 0 0 0 0
  112580. - 0 0 0 0 0 0 0 0 0 0 0 0
  112581. - 0 0 0 0 0 0 0 0 0 0 0 0
  112582. - 0 0 0 0 0 0 0 0 0 0 0 0
  112583. - 0 0 0 0 0 0 0 0 0 0 0 0
  112584. - 0 0 0 0 0 0 0 0 0 0 0 0
  112585. - 6 6 6 18 18 18 46 46 46 90 90 90
  112586. - 46 46 46 18 18 18 6 6 6 182 182 182
  112587. -253 253 253 246 246 246 206 206 206 190 190 190
  112588. -190 190 190 190 190 190 190 190 190 190 190 190
  112589. -206 206 206 231 231 231 250 250 250 253 253 253
  112590. -253 253 253 253 253 253 253 253 253 253 253 253
  112591. -202 202 202 14 14 14 2 2 6 2 2 6
  112592. - 2 2 6 2 2 6 2 2 6 2 2 6
  112593. - 42 42 42 86 86 86 42 42 42 18 18 18
  112594. - 6 6 6 0 0 0 0 0 0 0 0 0
  112595. - 0 0 0 0 0 0 0 0 0 0 0 0
  112596. - 0 0 0 0 0 0 0 0 0 0 0 0
  112597. - 0 0 0 0 0 0 0 0 0 0 0 0
  112598. - 0 0 0 0 0 0 0 0 0 0 0 0
  112599. - 0 0 0 0 0 0 0 0 0 0 0 0
  112600. - 0 0 0 0 0 0 0 0 0 0 0 0
  112601. - 0 0 0 0 0 0 0 0 0 0 0 0
  112602. - 0 0 0 0 0 0 0 0 0 0 0 0
  112603. - 0 0 0 0 0 0 0 0 0 0 0 0
  112604. - 0 0 0 0 0 0 0 0 0 6 6 6
  112605. - 14 14 14 38 38 38 74 74 74 66 66 66
  112606. - 2 2 6 6 6 6 90 90 90 250 250 250
  112607. -253 253 253 253 253 253 238 238 238 198 198 198
  112608. -190 190 190 190 190 190 195 195 195 221 221 221
  112609. -246 246 246 253 253 253 253 253 253 253 253 253
  112610. -253 253 253 253 253 253 253 253 253 253 253 253
  112611. -253 253 253 82 82 82 2 2 6 2 2 6
  112612. - 2 2 6 2 2 6 2 2 6 2 2 6
  112613. - 2 2 6 78 78 78 70 70 70 34 34 34
  112614. - 14 14 14 6 6 6 0 0 0 0 0 0
  112615. - 0 0 0 0 0 0 0 0 0 0 0 0
  112616. - 0 0 0 0 0 0 0 0 0 0 0 0
  112617. - 0 0 0 0 0 0 0 0 0 0 0 0
  112618. - 0 0 0 0 0 0 0 0 0 0 0 0
  112619. - 0 0 0 0 0 0 0 0 0 0 0 0
  112620. - 0 0 0 0 0 0 0 0 0 0 0 0
  112621. - 0 0 0 0 0 0 0 0 0 0 0 0
  112622. - 0 0 0 0 0 0 0 0 0 0 0 0
  112623. - 0 0 0 0 0 0 0 0 0 0 0 0
  112624. - 0 0 0 0 0 0 0 0 0 14 14 14
  112625. - 34 34 34 66 66 66 78 78 78 6 6 6
  112626. - 2 2 6 18 18 18 218 218 218 253 253 253
  112627. -253 253 253 253 253 253 253 253 253 246 246 246
  112628. -226 226 226 231 231 231 246 246 246 253 253 253
  112629. -253 253 253 253 253 253 253 253 253 253 253 253
  112630. -253 253 253 253 253 253 253 253 253 253 253 253
  112631. -253 253 253 178 178 178 2 2 6 2 2 6
  112632. - 2 2 6 2 2 6 2 2 6 2 2 6
  112633. - 2 2 6 18 18 18 90 90 90 62 62 62
  112634. - 30 30 30 10 10 10 0 0 0 0 0 0
  112635. - 0 0 0 0 0 0 0 0 0 0 0 0
  112636. - 0 0 0 0 0 0 0 0 0 0 0 0
  112637. - 0 0 0 0 0 0 0 0 0 0 0 0
  112638. - 0 0 0 0 0 0 0 0 0 0 0 0
  112639. - 0 0 0 0 0 0 0 0 0 0 0 0
  112640. - 0 0 0 0 0 0 0 0 0 0 0 0
  112641. - 0 0 0 0 0 0 0 0 0 0 0 0
  112642. - 0 0 0 0 0 0 0 0 0 0 0 0
  112643. - 0 0 0 0 0 0 0 0 0 0 0 0
  112644. - 0 0 0 0 0 0 10 10 10 26 26 26
  112645. - 58 58 58 90 90 90 18 18 18 2 2 6
  112646. - 2 2 6 110 110 110 253 253 253 253 253 253
  112647. -253 253 253 253 253 253 253 253 253 253 253 253
  112648. -250 250 250 253 253 253 253 253 253 253 253 253
  112649. -253 253 253 253 253 253 253 253 253 253 253 253
  112650. -253 253 253 253 253 253 253 253 253 253 253 253
  112651. -253 253 253 231 231 231 18 18 18 2 2 6
  112652. - 2 2 6 2 2 6 2 2 6 2 2 6
  112653. - 2 2 6 2 2 6 18 18 18 94 94 94
  112654. - 54 54 54 26 26 26 10 10 10 0 0 0
  112655. - 0 0 0 0 0 0 0 0 0 0 0 0
  112656. - 0 0 0 0 0 0 0 0 0 0 0 0
  112657. - 0 0 0 0 0 0 0 0 0 0 0 0
  112658. - 0 0 0 0 0 0 0 0 0 0 0 0
  112659. - 0 0 0 0 0 0 0 0 0 0 0 0
  112660. - 0 0 0 0 0 0 0 0 0 0 0 0
  112661. - 0 0 0 0 0 0 0 0 0 0 0 0
  112662. - 0 0 0 0 0 0 0 0 0 0 0 0
  112663. - 0 0 0 0 0 0 0 0 0 0 0 0
  112664. - 0 0 0 6 6 6 22 22 22 50 50 50
  112665. - 90 90 90 26 26 26 2 2 6 2 2 6
  112666. - 14 14 14 195 195 195 250 250 250 253 253 253
  112667. -253 253 253 253 253 253 253 253 253 253 253 253
  112668. -253 253 253 253 253 253 253 253 253 253 253 253
  112669. -253 253 253 253 253 253 253 253 253 253 253 253
  112670. -253 253 253 253 253 253 253 253 253 253 253 253
  112671. -250 250 250 242 242 242 54 54 54 2 2 6
  112672. - 2 2 6 2 2 6 2 2 6 2 2 6
  112673. - 2 2 6 2 2 6 2 2 6 38 38 38
  112674. - 86 86 86 50 50 50 22 22 22 6 6 6
  112675. - 0 0 0 0 0 0 0 0 0 0 0 0
  112676. - 0 0 0 0 0 0 0 0 0 0 0 0
  112677. - 0 0 0 0 0 0 0 0 0 0 0 0
  112678. - 0 0 0 0 0 0 0 0 0 0 0 0
  112679. - 0 0 0 0 0 0 0 0 0 0 0 0
  112680. - 0 0 0 0 0 0 0 0 0 0 0 0
  112681. - 0 0 0 0 0 0 0 0 0 0 0 0
  112682. - 0 0 0 0 0 0 0 0 0 0 0 0
  112683. - 0 0 0 0 0 0 0 0 0 0 0 0
  112684. - 6 6 6 14 14 14 38 38 38 82 82 82
  112685. - 34 34 34 2 2 6 2 2 6 2 2 6
  112686. - 42 42 42 195 195 195 246 246 246 253 253 253
  112687. -253 253 253 253 253 253 253 253 253 250 250 250
  112688. -242 242 242 242 242 242 250 250 250 253 253 253
  112689. -253 253 253 253 253 253 253 253 253 253 253 253
  112690. -253 253 253 250 250 250 246 246 246 238 238 238
  112691. -226 226 226 231 231 231 101 101 101 6 6 6
  112692. - 2 2 6 2 2 6 2 2 6 2 2 6
  112693. - 2 2 6 2 2 6 2 2 6 2 2 6
  112694. - 38 38 38 82 82 82 42 42 42 14 14 14
  112695. - 6 6 6 0 0 0 0 0 0 0 0 0
  112696. - 0 0 0 0 0 0 0 0 0 0 0 0
  112697. - 0 0 0 0 0 0 0 0 0 0 0 0
  112698. - 0 0 0 0 0 0 0 0 0 0 0 0
  112699. - 0 0 0 0 0 0 0 0 0 0 0 0
  112700. - 0 0 0 0 0 0 0 0 0 0 0 0
  112701. - 0 0 0 0 0 0 0 0 0 0 0 0
  112702. - 0 0 0 0 0 0 0 0 0 0 0 0
  112703. - 0 0 0 0 0 0 0 0 0 0 0 0
  112704. - 10 10 10 26 26 26 62 62 62 66 66 66
  112705. - 2 2 6 2 2 6 2 2 6 6 6 6
  112706. - 70 70 70 170 170 170 206 206 206 234 234 234
  112707. -246 246 246 250 250 250 250 250 250 238 238 238
  112708. -226 226 226 231 231 231 238 238 238 250 250 250
  112709. -250 250 250 250 250 250 246 246 246 231 231 231
  112710. -214 214 214 206 206 206 202 202 202 202 202 202
  112711. -198 198 198 202 202 202 182 182 182 18 18 18
  112712. - 2 2 6 2 2 6 2 2 6 2 2 6
  112713. - 2 2 6 2 2 6 2 2 6 2 2 6
  112714. - 2 2 6 62 62 62 66 66 66 30 30 30
  112715. - 10 10 10 0 0 0 0 0 0 0 0 0
  112716. - 0 0 0 0 0 0 0 0 0 0 0 0
  112717. - 0 0 0 0 0 0 0 0 0 0 0 0
  112718. - 0 0 0 0 0 0 0 0 0 0 0 0
  112719. - 0 0 0 0 0 0 0 0 0 0 0 0
  112720. - 0 0 0 0 0 0 0 0 0 0 0 0
  112721. - 0 0 0 0 0 0 0 0 0 0 0 0
  112722. - 0 0 0 0 0 0 0 0 0 0 0 0
  112723. - 0 0 0 0 0 0 0 0 0 0 0 0
  112724. - 14 14 14 42 42 42 82 82 82 18 18 18
  112725. - 2 2 6 2 2 6 2 2 6 10 10 10
  112726. - 94 94 94 182 182 182 218 218 218 242 242 242
  112727. -250 250 250 253 253 253 253 253 253 250 250 250
  112728. -234 234 234 253 253 253 253 253 253 253 253 253
  112729. -253 253 253 253 253 253 253 253 253 246 246 246
  112730. -238 238 238 226 226 226 210 210 210 202 202 202
  112731. -195 195 195 195 195 195 210 210 210 158 158 158
  112732. - 6 6 6 14 14 14 50 50 50 14 14 14
  112733. - 2 2 6 2 2 6 2 2 6 2 2 6
  112734. - 2 2 6 6 6 6 86 86 86 46 46 46
  112735. - 18 18 18 6 6 6 0 0 0 0 0 0
  112736. - 0 0 0 0 0 0 0 0 0 0 0 0
  112737. - 0 0 0 0 0 0 0 0 0 0 0 0
  112738. - 0 0 0 0 0 0 0 0 0 0 0 0
  112739. - 0 0 0 0 0 0 0 0 0 0 0 0
  112740. - 0 0 0 0 0 0 0 0 0 0 0 0
  112741. - 0 0 0 0 0 0 0 0 0 0 0 0
  112742. - 0 0 0 0 0 0 0 0 0 0 0 0
  112743. - 0 0 0 0 0 0 0 0 0 6 6 6
  112744. - 22 22 22 54 54 54 70 70 70 2 2 6
  112745. - 2 2 6 10 10 10 2 2 6 22 22 22
  112746. -166 166 166 231 231 231 250 250 250 253 253 253
  112747. -253 253 253 253 253 253 253 253 253 250 250 250
  112748. -242 242 242 253 253 253 253 253 253 253 253 253
  112749. -253 253 253 253 253 253 253 253 253 253 253 253
  112750. -253 253 253 253 253 253 253 253 253 246 246 246
  112751. -231 231 231 206 206 206 198 198 198 226 226 226
  112752. - 94 94 94 2 2 6 6 6 6 38 38 38
  112753. - 30 30 30 2 2 6 2 2 6 2 2 6
  112754. - 2 2 6 2 2 6 62 62 62 66 66 66
  112755. - 26 26 26 10 10 10 0 0 0 0 0 0
  112756. - 0 0 0 0 0 0 0 0 0 0 0 0
  112757. - 0 0 0 0 0 0 0 0 0 0 0 0
  112758. - 0 0 0 0 0 0 0 0 0 0 0 0
  112759. - 0 0 0 0 0 0 0 0 0 0 0 0
  112760. - 0 0 0 0 0 0 0 0 0 0 0 0
  112761. - 0 0 0 0 0 0 0 0 0 0 0 0
  112762. - 0 0 0 0 0 0 0 0 0 0 0 0
  112763. - 0 0 0 0 0 0 0 0 0 10 10 10
  112764. - 30 30 30 74 74 74 50 50 50 2 2 6
  112765. - 26 26 26 26 26 26 2 2 6 106 106 106
  112766. -238 238 238 253 253 253 253 253 253 253 253 253
  112767. -253 253 253 253 253 253 253 253 253 253 253 253
  112768. -253 253 253 253 253 253 253 253 253 253 253 253
  112769. -253 253 253 253 253 253 253 253 253 253 253 253
  112770. -253 253 253 253 253 253 253 253 253 253 253 253
  112771. -253 253 253 246 246 246 218 218 218 202 202 202
  112772. -210 210 210 14 14 14 2 2 6 2 2 6
  112773. - 30 30 30 22 22 22 2 2 6 2 2 6
  112774. - 2 2 6 2 2 6 18 18 18 86 86 86
  112775. - 42 42 42 14 14 14 0 0 0 0 0 0
  112776. - 0 0 0 0 0 0 0 0 0 0 0 0
  112777. - 0 0 0 0 0 0 0 0 0 0 0 0
  112778. - 0 0 0 0 0 0 0 0 0 0 0 0
  112779. - 0 0 0 0 0 0 0 0 0 0 0 0
  112780. - 0 0 0 0 0 0 0 0 0 0 0 0
  112781. - 0 0 0 0 0 0 0 0 0 0 0 0
  112782. - 0 0 0 0 0 0 0 0 0 0 0 0
  112783. - 0 0 0 0 0 0 0 0 0 14 14 14
  112784. - 42 42 42 90 90 90 22 22 22 2 2 6
  112785. - 42 42 42 2 2 6 18 18 18 218 218 218
  112786. -253 253 253 253 253 253 253 253 253 253 253 253
  112787. -253 253 253 253 253 253 253 253 253 253 253 253
  112788. -253 253 253 253 253 253 253 253 253 253 253 253
  112789. -253 253 253 253 253 253 253 253 253 253 253 253
  112790. -253 253 253 253 253 253 253 253 253 253 253 253
  112791. -253 253 253 253 253 253 250 250 250 221 221 221
  112792. -218 218 218 101 101 101 2 2 6 14 14 14
  112793. - 18 18 18 38 38 38 10 10 10 2 2 6
  112794. - 2 2 6 2 2 6 2 2 6 78 78 78
  112795. - 58 58 58 22 22 22 6 6 6 0 0 0
  112796. - 0 0 0 0 0 0 0 0 0 0 0 0
  112797. - 0 0 0 0 0 0 0 0 0 0 0 0
  112798. - 0 0 0 0 0 0 0 0 0 0 0 0
  112799. - 0 0 0 0 0 0 0 0 0 0 0 0
  112800. - 0 0 0 0 0 0 0 0 0 0 0 0
  112801. - 0 0 0 0 0 0 0 0 0 0 0 0
  112802. - 0 0 0 0 0 0 0 0 0 0 0 0
  112803. - 0 0 0 0 0 0 6 6 6 18 18 18
  112804. - 54 54 54 82 82 82 2 2 6 26 26 26
  112805. - 22 22 22 2 2 6 123 123 123 253 253 253
  112806. -253 253 253 253 253 253 253 253 253 253 253 253
  112807. -253 253 253 253 253 253 253 253 253 253 253 253
  112808. -253 253 253 253 253 253 253 253 253 253 253 253
  112809. -253 253 253 253 253 253 253 253 253 253 253 253
  112810. -253 253 253 253 253 253 253 253 253 253 253 253
  112811. -253 253 253 253 253 253 253 253 253 250 250 250
  112812. -238 238 238 198 198 198 6 6 6 38 38 38
  112813. - 58 58 58 26 26 26 38 38 38 2 2 6
  112814. - 2 2 6 2 2 6 2 2 6 46 46 46
  112815. - 78 78 78 30 30 30 10 10 10 0 0 0
  112816. - 0 0 0 0 0 0 0 0 0 0 0 0
  112817. - 0 0 0 0 0 0 0 0 0 0 0 0
  112818. - 0 0 0 0 0 0 0 0 0 0 0 0
  112819. - 0 0 0 0 0 0 0 0 0 0 0 0
  112820. - 0 0 0 0 0 0 0 0 0 0 0 0
  112821. - 0 0 0 0 0 0 0 0 0 0 0 0
  112822. - 0 0 0 0 0 0 0 0 0 0 0 0
  112823. - 0 0 0 0 0 0 10 10 10 30 30 30
  112824. - 74 74 74 58 58 58 2 2 6 42 42 42
  112825. - 2 2 6 22 22 22 231 231 231 253 253 253
  112826. -253 253 253 253 253 253 253 253 253 253 253 253
  112827. -253 253 253 253 253 253 253 253 253 250 250 250
  112828. -253 253 253 253 253 253 253 253 253 253 253 253
  112829. -253 253 253 253 253 253 253 253 253 253 253 253
  112830. -253 253 253 253 253 253 253 253 253 253 253 253
  112831. -253 253 253 253 253 253 253 253 253 253 253 253
  112832. -253 253 253 246 246 246 46 46 46 38 38 38
  112833. - 42 42 42 14 14 14 38 38 38 14 14 14
  112834. - 2 2 6 2 2 6 2 2 6 6 6 6
  112835. - 86 86 86 46 46 46 14 14 14 0 0 0
  112836. - 0 0 0 0 0 0 0 0 0 0 0 0
  112837. - 0 0 0 0 0 0 0 0 0 0 0 0
  112838. - 0 0 0 0 0 0 0 0 0 0 0 0
  112839. - 0 0 0 0 0 0 0 0 0 0 0 0
  112840. - 0 0 0 0 0 0 0 0 0 0 0 0
  112841. - 0 0 0 0 0 0 0 0 0 0 0 0
  112842. - 0 0 0 0 0 0 0 0 0 0 0 0
  112843. - 0 0 0 6 6 6 14 14 14 42 42 42
  112844. - 90 90 90 18 18 18 18 18 18 26 26 26
  112845. - 2 2 6 116 116 116 253 253 253 253 253 253
  112846. -253 253 253 253 253 253 253 253 253 253 253 253
  112847. -253 253 253 253 253 253 250 250 250 238 238 238
  112848. -253 253 253 253 253 253 253 253 253 253 253 253
  112849. -253 253 253 253 253 253 253 253 253 253 253 253
  112850. -253 253 253 253 253 253 253 253 253 253 253 253
  112851. -253 253 253 253 253 253 253 253 253 253 253 253
  112852. -253 253 253 253 253 253 94 94 94 6 6 6
  112853. - 2 2 6 2 2 6 10 10 10 34 34 34
  112854. - 2 2 6 2 2 6 2 2 6 2 2 6
  112855. - 74 74 74 58 58 58 22 22 22 6 6 6
  112856. - 0 0 0 0 0 0 0 0 0 0 0 0
  112857. - 0 0 0 0 0 0 0 0 0 0 0 0
  112858. - 0 0 0 0 0 0 0 0 0 0 0 0
  112859. - 0 0 0 0 0 0 0 0 0 0 0 0
  112860. - 0 0 0 0 0 0 0 0 0 0 0 0
  112861. - 0 0 0 0 0 0 0 0 0 0 0 0
  112862. - 0 0 0 0 0 0 0 0 0 0 0 0
  112863. - 0 0 0 10 10 10 26 26 26 66 66 66
  112864. - 82 82 82 2 2 6 38 38 38 6 6 6
  112865. - 14 14 14 210 210 210 253 253 253 253 253 253
  112866. -253 253 253 253 253 253 253 253 253 253 253 253
  112867. -253 253 253 253 253 253 246 246 246 242 242 242
  112868. -253 253 253 253 253 253 253 253 253 253 253 253
  112869. -253 253 253 253 253 253 253 253 253 253 253 253
  112870. -253 253 253 253 253 253 253 253 253 253 253 253
  112871. -253 253 253 253 253 253 253 253 253 253 253 253
  112872. -253 253 253 253 253 253 144 144 144 2 2 6
  112873. - 2 2 6 2 2 6 2 2 6 46 46 46
  112874. - 2 2 6 2 2 6 2 2 6 2 2 6
  112875. - 42 42 42 74 74 74 30 30 30 10 10 10
  112876. - 0 0 0 0 0 0 0 0 0 0 0 0
  112877. - 0 0 0 0 0 0 0 0 0 0 0 0
  112878. - 0 0 0 0 0 0 0 0 0 0 0 0
  112879. - 0 0 0 0 0 0 0 0 0 0 0 0
  112880. - 0 0 0 0 0 0 0 0 0 0 0 0
  112881. - 0 0 0 0 0 0 0 0 0 0 0 0
  112882. - 0 0 0 0 0 0 0 0 0 0 0 0
  112883. - 6 6 6 14 14 14 42 42 42 90 90 90
  112884. - 26 26 26 6 6 6 42 42 42 2 2 6
  112885. - 74 74 74 250 250 250 253 253 253 253 253 253
  112886. -253 253 253 253 253 253 253 253 253 253 253 253
  112887. -253 253 253 253 253 253 242 242 242 242 242 242
  112888. -253 253 253 253 253 253 253 253 253 253 253 253
  112889. -253 253 253 253 253 253 253 253 253 253 253 253
  112890. -253 253 253 253 253 253 253 253 253 253 253 253
  112891. -253 253 253 253 253 253 253 253 253 253 253 253
  112892. -253 253 253 253 253 253 182 182 182 2 2 6
  112893. - 2 2 6 2 2 6 2 2 6 46 46 46
  112894. - 2 2 6 2 2 6 2 2 6 2 2 6
  112895. - 10 10 10 86 86 86 38 38 38 10 10 10
  112896. - 0 0 0 0 0 0 0 0 0 0 0 0
  112897. - 0 0 0 0 0 0 0 0 0 0 0 0
  112898. - 0 0 0 0 0 0 0 0 0 0 0 0
  112899. - 0 0 0 0 0 0 0 0 0 0 0 0
  112900. - 0 0 0 0 0 0 0 0 0 0 0 0
  112901. - 0 0 0 0 0 0 0 0 0 0 0 0
  112902. - 0 0 0 0 0 0 0 0 0 0 0 0
  112903. - 10 10 10 26 26 26 66 66 66 82 82 82
  112904. - 2 2 6 22 22 22 18 18 18 2 2 6
  112905. -149 149 149 253 253 253 253 253 253 253 253 253
  112906. -253 253 253 253 253 253 253 253 253 253 253 253
  112907. -253 253 253 253 253 253 234 234 234 242 242 242
  112908. -253 253 253 253 253 253 253 253 253 253 253 253
  112909. -253 253 253 253 253 253 253 253 253 253 253 253
  112910. -253 253 253 253 253 253 253 253 253 253 253 253
  112911. -253 253 253 253 253 253 253 253 253 253 253 253
  112912. -253 253 253 253 253 253 206 206 206 2 2 6
  112913. - 2 2 6 2 2 6 2 2 6 38 38 38
  112914. - 2 2 6 2 2 6 2 2 6 2 2 6
  112915. - 6 6 6 86 86 86 46 46 46 14 14 14
  112916. - 0 0 0 0 0 0 0 0 0 0 0 0
  112917. - 0 0 0 0 0 0 0 0 0 0 0 0
  112918. - 0 0 0 0 0 0 0 0 0 0 0 0
  112919. - 0 0 0 0 0 0 0 0 0 0 0 0
  112920. - 0 0 0 0 0 0 0 0 0 0 0 0
  112921. - 0 0 0 0 0 0 0 0 0 0 0 0
  112922. - 0 0 0 0 0 0 0 0 0 6 6 6
  112923. - 18 18 18 46 46 46 86 86 86 18 18 18
  112924. - 2 2 6 34 34 34 10 10 10 6 6 6
  112925. -210 210 210 253 253 253 253 253 253 253 253 253
  112926. -253 253 253 253 253 253 253 253 253 253 253 253
  112927. -253 253 253 253 253 253 234 234 234 242 242 242
  112928. -253 253 253 253 253 253 253 253 253 253 253 253
  112929. -253 253 253 253 253 253 253 253 253 253 253 253
  112930. -253 253 253 253 253 253 253 253 253 253 253 253
  112931. -253 253 253 253 253 253 253 253 253 253 253 253
  112932. -253 253 253 253 253 253 221 221 221 6 6 6
  112933. - 2 2 6 2 2 6 6 6 6 30 30 30
  112934. - 2 2 6 2 2 6 2 2 6 2 2 6
  112935. - 2 2 6 82 82 82 54 54 54 18 18 18
  112936. - 6 6 6 0 0 0 0 0 0 0 0 0
  112937. - 0 0 0 0 0 0 0 0 0 0 0 0
  112938. - 0 0 0 0 0 0 0 0 0 0 0 0
  112939. - 0 0 0 0 0 0 0 0 0 0 0 0
  112940. - 0 0 0 0 0 0 0 0 0 0 0 0
  112941. - 0 0 0 0 0 0 0 0 0 0 0 0
  112942. - 0 0 0 0 0 0 0 0 0 10 10 10
  112943. - 26 26 26 66 66 66 62 62 62 2 2 6
  112944. - 2 2 6 38 38 38 10 10 10 26 26 26
  112945. -238 238 238 253 253 253 253 253 253 253 253 253
  112946. -253 253 253 253 253 253 253 253 253 253 253 253
  112947. -253 253 253 253 253 253 231 231 231 238 238 238
  112948. -253 253 253 253 253 253 253 253 253 253 253 253
  112949. -253 253 253 253 253 253 253 253 253 253 253 253
  112950. -253 253 253 253 253 253 253 253 253 253 253 253
  112951. -253 253 253 253 253 253 253 253 253 253 253 253
  112952. -253 253 253 253 253 253 231 231 231 6 6 6
  112953. - 2 2 6 2 2 6 10 10 10 30 30 30
  112954. - 2 2 6 2 2 6 2 2 6 2 2 6
  112955. - 2 2 6 66 66 66 58 58 58 22 22 22
  112956. - 6 6 6 0 0 0 0 0 0 0 0 0
  112957. - 0 0 0 0 0 0 0 0 0 0 0 0
  112958. - 0 0 0 0 0 0 0 0 0 0 0 0
  112959. - 0 0 0 0 0 0 0 0 0 0 0 0
  112960. - 0 0 0 0 0 0 0 0 0 0 0 0
  112961. - 0 0 0 0 0 0 0 0 0 0 0 0
  112962. - 0 0 0 0 0 0 0 0 0 10 10 10
  112963. - 38 38 38 78 78 78 6 6 6 2 2 6
  112964. - 2 2 6 46 46 46 14 14 14 42 42 42
  112965. -246 246 246 253 253 253 253 253 253 253 253 253
  112966. -253 253 253 253 253 253 253 253 253 253 253 253
  112967. -253 253 253 253 253 253 231 231 231 242 242 242
  112968. -253 253 253 253 253 253 253 253 253 253 253 253
  112969. -253 253 253 253 253 253 253 253 253 253 253 253
  112970. -253 253 253 253 253 253 253 253 253 253 253 253
  112971. -253 253 253 253 253 253 253 253 253 253 253 253
  112972. -253 253 253 253 253 253 234 234 234 10 10 10
  112973. - 2 2 6 2 2 6 22 22 22 14 14 14
  112974. - 2 2 6 2 2 6 2 2 6 2 2 6
  112975. - 2 2 6 66 66 66 62 62 62 22 22 22
  112976. - 6 6 6 0 0 0 0 0 0 0 0 0
  112977. - 0 0 0 0 0 0 0 0 0 0 0 0
  112978. - 0 0 0 0 0 0 0 0 0 0 0 0
  112979. - 0 0 0 0 0 0 0 0 0 0 0 0
  112980. - 0 0 0 0 0 0 0 0 0 0 0 0
  112981. - 0 0 0 0 0 0 0 0 0 0 0 0
  112982. - 0 0 0 0 0 0 6 6 6 18 18 18
  112983. - 50 50 50 74 74 74 2 2 6 2 2 6
  112984. - 14 14 14 70 70 70 34 34 34 62 62 62
  112985. -250 250 250 253 253 253 253 253 253 253 253 253
  112986. -253 253 253 253 253 253 253 253 253 253 253 253
  112987. -253 253 253 253 253 253 231 231 231 246 246 246
  112988. -253 253 253 253 253 253 253 253 253 253 253 253
  112989. -253 253 253 253 253 253 253 253 253 253 253 253
  112990. -253 253 253 253 253 253 253 253 253 253 253 253
  112991. -253 253 253 253 253 253 253 253 253 253 253 253
  112992. -253 253 253 253 253 253 234 234 234 14 14 14
  112993. - 2 2 6 2 2 6 30 30 30 2 2 6
  112994. - 2 2 6 2 2 6 2 2 6 2 2 6
  112995. - 2 2 6 66 66 66 62 62 62 22 22 22
  112996. - 6 6 6 0 0 0 0 0 0 0 0 0
  112997. - 0 0 0 0 0 0 0 0 0 0 0 0
  112998. - 0 0 0 0 0 0 0 0 0 0 0 0
  112999. - 0 0 0 0 0 0 0 0 0 0 0 0
  113000. - 0 0 0 0 0 0 0 0 0 0 0 0
  113001. - 0 0 0 0 0 0 0 0 0 0 0 0
  113002. - 0 0 0 0 0 0 6 6 6 18 18 18
  113003. - 54 54 54 62 62 62 2 2 6 2 2 6
  113004. - 2 2 6 30 30 30 46 46 46 70 70 70
  113005. -250 250 250 253 253 253 253 253 253 253 253 253
  113006. -253 253 253 253 253 253 253 253 253 253 253 253
  113007. -253 253 253 253 253 253 231 231 231 246 246 246
  113008. -253 253 253 253 253 253 253 253 253 253 253 253
  113009. -253 253 253 253 253 253 253 253 253 253 253 253
  113010. -253 253 253 253 253 253 253 253 253 253 253 253
  113011. -253 253 253 253 253 253 253 253 253 253 253 253
  113012. -253 253 253 253 253 253 226 226 226 10 10 10
  113013. - 2 2 6 6 6 6 30 30 30 2 2 6
  113014. - 2 2 6 2 2 6 2 2 6 2 2 6
  113015. - 2 2 6 66 66 66 58 58 58 22 22 22
  113016. - 6 6 6 0 0 0 0 0 0 0 0 0
  113017. - 0 0 0 0 0 0 0 0 0 0 0 0
  113018. - 0 0 0 0 0 0 0 0 0 0 0 0
  113019. - 0 0 0 0 0 0 0 0 0 0 0 0
  113020. - 0 0 0 0 0 0 0 0 0 0 0 0
  113021. - 0 0 0 0 0 0 0 0 0 0 0 0
  113022. - 0 0 0 0 0 0 6 6 6 22 22 22
  113023. - 58 58 58 62 62 62 2 2 6 2 2 6
  113024. - 2 2 6 2 2 6 30 30 30 78 78 78
  113025. -250 250 250 253 253 253 253 253 253 253 253 253
  113026. -253 253 253 253 253 253 253 253 253 253 253 253
  113027. -253 253 253 253 253 253 231 231 231 246 246 246
  113028. -253 253 253 253 253 253 253 253 253 253 253 253
  113029. -253 253 253 253 253 253 253 253 253 253 253 253
  113030. -253 253 253 253 253 253 253 253 253 253 253 253
  113031. -253 253 253 253 253 253 253 253 253 253 253 253
  113032. -253 253 253 253 253 253 206 206 206 2 2 6
  113033. - 22 22 22 34 34 34 18 14 6 22 22 22
  113034. - 26 26 26 18 18 18 6 6 6 2 2 6
  113035. - 2 2 6 82 82 82 54 54 54 18 18 18
  113036. - 6 6 6 0 0 0 0 0 0 0 0 0
  113037. - 0 0 0 0 0 0 0 0 0 0 0 0
  113038. - 0 0 0 0 0 0 0 0 0 0 0 0
  113039. - 0 0 0 0 0 0 0 0 0 0 0 0
  113040. - 0 0 0 0 0 0 0 0 0 0 0 0
  113041. - 0 0 0 0 0 0 0 0 0 0 0 0
  113042. - 0 0 0 0 0 0 6 6 6 26 26 26
  113043. - 62 62 62 106 106 106 74 54 14 185 133 11
  113044. -210 162 10 121 92 8 6 6 6 62 62 62
  113045. -238 238 238 253 253 253 253 253 253 253 253 253
  113046. -253 253 253 253 253 253 253 253 253 253 253 253
  113047. -253 253 253 253 253 253 231 231 231 246 246 246
  113048. -253 253 253 253 253 253 253 253 253 253 253 253
  113049. -253 253 253 253 253 253 253 253 253 253 253 253
  113050. -253 253 253 253 253 253 253 253 253 253 253 253
  113051. -253 253 253 253 253 253 253 253 253 253 253 253
  113052. -253 253 253 253 253 253 158 158 158 18 18 18
  113053. - 14 14 14 2 2 6 2 2 6 2 2 6
  113054. - 6 6 6 18 18 18 66 66 66 38 38 38
  113055. - 6 6 6 94 94 94 50 50 50 18 18 18
  113056. - 6 6 6 0 0 0 0 0 0 0 0 0
  113057. - 0 0 0 0 0 0 0 0 0 0 0 0
  113058. - 0 0 0 0 0 0 0 0 0 0 0 0
  113059. - 0 0 0 0 0 0 0 0 0 0 0 0
  113060. - 0 0 0 0 0 0 0 0 0 0 0 0
  113061. - 0 0 0 0 0 0 0 0 0 6 6 6
  113062. - 10 10 10 10 10 10 18 18 18 38 38 38
  113063. - 78 78 78 142 134 106 216 158 10 242 186 14
  113064. -246 190 14 246 190 14 156 118 10 10 10 10
  113065. - 90 90 90 238 238 238 253 253 253 253 253 253
  113066. -253 253 253 253 253 253 253 253 253 253 253 253
  113067. -253 253 253 253 253 253 231 231 231 250 250 250
  113068. -253 253 253 253 253 253 253 253 253 253 253 253
  113069. -253 253 253 253 253 253 253 253 253 253 253 253
  113070. -253 253 253 253 253 253 253 253 253 253 253 253
  113071. -253 253 253 253 253 253 253 253 253 246 230 190
  113072. -238 204 91 238 204 91 181 142 44 37 26 9
  113073. - 2 2 6 2 2 6 2 2 6 2 2 6
  113074. - 2 2 6 2 2 6 38 38 38 46 46 46
  113075. - 26 26 26 106 106 106 54 54 54 18 18 18
  113076. - 6 6 6 0 0 0 0 0 0 0 0 0
  113077. - 0 0 0 0 0 0 0 0 0 0 0 0
  113078. - 0 0 0 0 0 0 0 0 0 0 0 0
  113079. - 0 0 0 0 0 0 0 0 0 0 0 0
  113080. - 0 0 0 0 0 0 0 0 0 0 0 0
  113081. - 0 0 0 6 6 6 14 14 14 22 22 22
  113082. - 30 30 30 38 38 38 50 50 50 70 70 70
  113083. -106 106 106 190 142 34 226 170 11 242 186 14
  113084. -246 190 14 246 190 14 246 190 14 154 114 10
  113085. - 6 6 6 74 74 74 226 226 226 253 253 253
  113086. -253 253 253 253 253 253 253 253 253 253 253 253
  113087. -253 253 253 253 253 253 231 231 231 250 250 250
  113088. -253 253 253 253 253 253 253 253 253 253 253 253
  113089. -253 253 253 253 253 253 253 253 253 253 253 253
  113090. -253 253 253 253 253 253 253 253 253 253 253 253
  113091. -253 253 253 253 253 253 253 253 253 228 184 62
  113092. -241 196 14 241 208 19 232 195 16 38 30 10
  113093. - 2 2 6 2 2 6 2 2 6 2 2 6
  113094. - 2 2 6 6 6 6 30 30 30 26 26 26
  113095. -203 166 17 154 142 90 66 66 66 26 26 26
  113096. - 6 6 6 0 0 0 0 0 0 0 0 0
  113097. - 0 0 0 0 0 0 0 0 0 0 0 0
  113098. - 0 0 0 0 0 0 0 0 0 0 0 0
  113099. - 0 0 0 0 0 0 0 0 0 0 0 0
  113100. - 0 0 0 0 0 0 0 0 0 0 0 0
  113101. - 6 6 6 18 18 18 38 38 38 58 58 58
  113102. - 78 78 78 86 86 86 101 101 101 123 123 123
  113103. -175 146 61 210 150 10 234 174 13 246 186 14
  113104. -246 190 14 246 190 14 246 190 14 238 190 10
  113105. -102 78 10 2 2 6 46 46 46 198 198 198
  113106. -253 253 253 253 253 253 253 253 253 253 253 253
  113107. -253 253 253 253 253 253 234 234 234 242 242 242
  113108. -253 253 253 253 253 253 253 253 253 253 253 253
  113109. -253 253 253 253 253 253 253 253 253 253 253 253
  113110. -253 253 253 253 253 253 253 253 253 253 253 253
  113111. -253 253 253 253 253 253 253 253 253 224 178 62
  113112. -242 186 14 241 196 14 210 166 10 22 18 6
  113113. - 2 2 6 2 2 6 2 2 6 2 2 6
  113114. - 2 2 6 2 2 6 6 6 6 121 92 8
  113115. -238 202 15 232 195 16 82 82 82 34 34 34
  113116. - 10 10 10 0 0 0 0 0 0 0 0 0
  113117. - 0 0 0 0 0 0 0 0 0 0 0 0
  113118. - 0 0 0 0 0 0 0 0 0 0 0 0
  113119. - 0 0 0 0 0 0 0 0 0 0 0 0
  113120. - 0 0 0 0 0 0 0 0 0 0 0 0
  113121. - 14 14 14 38 38 38 70 70 70 154 122 46
  113122. -190 142 34 200 144 11 197 138 11 197 138 11
  113123. -213 154 11 226 170 11 242 186 14 246 190 14
  113124. -246 190 14 246 190 14 246 190 14 246 190 14
  113125. -225 175 15 46 32 6 2 2 6 22 22 22
  113126. -158 158 158 250 250 250 253 253 253 253 253 253
  113127. -253 253 253 253 253 253 253 253 253 253 253 253
  113128. -253 253 253 253 253 253 253 253 253 253 253 253
  113129. -253 253 253 253 253 253 253 253 253 253 253 253
  113130. -253 253 253 253 253 253 253 253 253 253 253 253
  113131. -253 253 253 250 250 250 242 242 242 224 178 62
  113132. -239 182 13 236 186 11 213 154 11 46 32 6
  113133. - 2 2 6 2 2 6 2 2 6 2 2 6
  113134. - 2 2 6 2 2 6 61 42 6 225 175 15
  113135. -238 190 10 236 186 11 112 100 78 42 42 42
  113136. - 14 14 14 0 0 0 0 0 0 0 0 0
  113137. - 0 0 0 0 0 0 0 0 0 0 0 0
  113138. - 0 0 0 0 0 0 0 0 0 0 0 0
  113139. - 0 0 0 0 0 0 0 0 0 0 0 0
  113140. - 0 0 0 0 0 0 0 0 0 6 6 6
  113141. - 22 22 22 54 54 54 154 122 46 213 154 11
  113142. -226 170 11 230 174 11 226 170 11 226 170 11
  113143. -236 178 12 242 186 14 246 190 14 246 190 14
  113144. -246 190 14 246 190 14 246 190 14 246 190 14
  113145. -241 196 14 184 144 12 10 10 10 2 2 6
  113146. - 6 6 6 116 116 116 242 242 242 253 253 253
  113147. -253 253 253 253 253 253 253 253 253 253 253 253
  113148. -253 253 253 253 253 253 253 253 253 253 253 253
  113149. -253 253 253 253 253 253 253 253 253 253 253 253
  113150. -253 253 253 253 253 253 253 253 253 253 253 253
  113151. -253 253 253 231 231 231 198 198 198 214 170 54
  113152. -236 178 12 236 178 12 210 150 10 137 92 6
  113153. - 18 14 6 2 2 6 2 2 6 2 2 6
  113154. - 6 6 6 70 47 6 200 144 11 236 178 12
  113155. -239 182 13 239 182 13 124 112 88 58 58 58
  113156. - 22 22 22 6 6 6 0 0 0 0 0 0
  113157. - 0 0 0 0 0 0 0 0 0 0 0 0
  113158. - 0 0 0 0 0 0 0 0 0 0 0 0
  113159. - 0 0 0 0 0 0 0 0 0 0 0 0
  113160. - 0 0 0 0 0 0 0 0 0 10 10 10
  113161. - 30 30 30 70 70 70 180 133 36 226 170 11
  113162. -239 182 13 242 186 14 242 186 14 246 186 14
  113163. -246 190 14 246 190 14 246 190 14 246 190 14
  113164. -246 190 14 246 190 14 246 190 14 246 190 14
  113165. -246 190 14 232 195 16 98 70 6 2 2 6
  113166. - 2 2 6 2 2 6 66 66 66 221 221 221
  113167. -253 253 253 253 253 253 253 253 253 253 253 253
  113168. -253 253 253 253 253 253 253 253 253 253 253 253
  113169. -253 253 253 253 253 253 253 253 253 253 253 253
  113170. -253 253 253 253 253 253 253 253 253 253 253 253
  113171. -253 253 253 206 206 206 198 198 198 214 166 58
  113172. -230 174 11 230 174 11 216 158 10 192 133 9
  113173. -163 110 8 116 81 8 102 78 10 116 81 8
  113174. -167 114 7 197 138 11 226 170 11 239 182 13
  113175. -242 186 14 242 186 14 162 146 94 78 78 78
  113176. - 34 34 34 14 14 14 6 6 6 0 0 0
  113177. - 0 0 0 0 0 0 0 0 0 0 0 0
  113178. - 0 0 0 0 0 0 0 0 0 0 0 0
  113179. - 0 0 0 0 0 0 0 0 0 0 0 0
  113180. - 0 0 0 0 0 0 0 0 0 6 6 6
  113181. - 30 30 30 78 78 78 190 142 34 226 170 11
  113182. -239 182 13 246 190 14 246 190 14 246 190 14
  113183. -246 190 14 246 190 14 246 190 14 246 190 14
  113184. -246 190 14 246 190 14 246 190 14 246 190 14
  113185. -246 190 14 241 196 14 203 166 17 22 18 6
  113186. - 2 2 6 2 2 6 2 2 6 38 38 38
  113187. -218 218 218 253 253 253 253 253 253 253 253 253
  113188. -253 253 253 253 253 253 253 253 253 253 253 253
  113189. -253 253 253 253 253 253 253 253 253 253 253 253
  113190. -253 253 253 253 253 253 253 253 253 253 253 253
  113191. -250 250 250 206 206 206 198 198 198 202 162 69
  113192. -226 170 11 236 178 12 224 166 10 210 150 10
  113193. -200 144 11 197 138 11 192 133 9 197 138 11
  113194. -210 150 10 226 170 11 242 186 14 246 190 14
  113195. -246 190 14 246 186 14 225 175 15 124 112 88
  113196. - 62 62 62 30 30 30 14 14 14 6 6 6
  113197. - 0 0 0 0 0 0 0 0 0 0 0 0
  113198. - 0 0 0 0 0 0 0 0 0 0 0 0
  113199. - 0 0 0 0 0 0 0 0 0 0 0 0
  113200. - 0 0 0 0 0 0 0 0 0 10 10 10
  113201. - 30 30 30 78 78 78 174 135 50 224 166 10
  113202. -239 182 13 246 190 14 246 190 14 246 190 14
  113203. -246 190 14 246 190 14 246 190 14 246 190 14
  113204. -246 190 14 246 190 14 246 190 14 246 190 14
  113205. -246 190 14 246 190 14 241 196 14 139 102 15
  113206. - 2 2 6 2 2 6 2 2 6 2 2 6
  113207. - 78 78 78 250 250 250 253 253 253 253 253 253
  113208. -253 253 253 253 253 253 253 253 253 253 253 253
  113209. -253 253 253 253 253 253 253 253 253 253 253 253
  113210. -253 253 253 253 253 253 253 253 253 253 253 253
  113211. -250 250 250 214 214 214 198 198 198 190 150 46
  113212. -219 162 10 236 178 12 234 174 13 224 166 10
  113213. -216 158 10 213 154 11 213 154 11 216 158 10
  113214. -226 170 11 239 182 13 246 190 14 246 190 14
  113215. -246 190 14 246 190 14 242 186 14 206 162 42
  113216. -101 101 101 58 58 58 30 30 30 14 14 14
  113217. - 6 6 6 0 0 0 0 0 0 0 0 0
  113218. - 0 0 0 0 0 0 0 0 0 0 0 0
  113219. - 0 0 0 0 0 0 0 0 0 0 0 0
  113220. - 0 0 0 0 0 0 0 0 0 10 10 10
  113221. - 30 30 30 74 74 74 174 135 50 216 158 10
  113222. -236 178 12 246 190 14 246 190 14 246 190 14
  113223. -246 190 14 246 190 14 246 190 14 246 190 14
  113224. -246 190 14 246 190 14 246 190 14 246 190 14
  113225. -246 190 14 246 190 14 241 196 14 226 184 13
  113226. - 61 42 6 2 2 6 2 2 6 2 2 6
  113227. - 22 22 22 238 238 238 253 253 253 253 253 253
  113228. -253 253 253 253 253 253 253 253 253 253 253 253
  113229. -253 253 253 253 253 253 253 253 253 253 253 253
  113230. -253 253 253 253 253 253 253 253 253 253 253 253
  113231. -253 253 253 226 226 226 187 187 187 180 133 36
  113232. -216 158 10 236 178 12 239 182 13 236 178 12
  113233. -230 174 11 226 170 11 226 170 11 230 174 11
  113234. -236 178 12 242 186 14 246 190 14 246 190 14
  113235. -246 190 14 246 190 14 246 186 14 239 182 13
  113236. -206 162 42 106 106 106 66 66 66 34 34 34
  113237. - 14 14 14 6 6 6 0 0 0 0 0 0
  113238. - 0 0 0 0 0 0 0 0 0 0 0 0
  113239. - 0 0 0 0 0 0 0 0 0 0 0 0
  113240. - 0 0 0 0 0 0 0 0 0 6 6 6
  113241. - 26 26 26 70 70 70 163 133 67 213 154 11
  113242. -236 178 12 246 190 14 246 190 14 246 190 14
  113243. -246 190 14 246 190 14 246 190 14 246 190 14
  113244. -246 190 14 246 190 14 246 190 14 246 190 14
  113245. -246 190 14 246 190 14 246 190 14 241 196 14
  113246. -190 146 13 18 14 6 2 2 6 2 2 6
  113247. - 46 46 46 246 246 246 253 253 253 253 253 253
  113248. -253 253 253 253 253 253 253 253 253 253 253 253
  113249. -253 253 253 253 253 253 253 253 253 253 253 253
  113250. -253 253 253 253 253 253 253 253 253 253 253 253
  113251. -253 253 253 221 221 221 86 86 86 156 107 11
  113252. -216 158 10 236 178 12 242 186 14 246 186 14
  113253. -242 186 14 239 182 13 239 182 13 242 186 14
  113254. -242 186 14 246 186 14 246 190 14 246 190 14
  113255. -246 190 14 246 190 14 246 190 14 246 190 14
  113256. -242 186 14 225 175 15 142 122 72 66 66 66
  113257. - 30 30 30 10 10 10 0 0 0 0 0 0
  113258. - 0 0 0 0 0 0 0 0 0 0 0 0
  113259. - 0 0 0 0 0 0 0 0 0 0 0 0
  113260. - 0 0 0 0 0 0 0 0 0 6 6 6
  113261. - 26 26 26 70 70 70 163 133 67 210 150 10
  113262. -236 178 12 246 190 14 246 190 14 246 190 14
  113263. -246 190 14 246 190 14 246 190 14 246 190 14
  113264. -246 190 14 246 190 14 246 190 14 246 190 14
  113265. -246 190 14 246 190 14 246 190 14 246 190 14
  113266. -232 195 16 121 92 8 34 34 34 106 106 106
  113267. -221 221 221 253 253 253 253 253 253 253 253 253
  113268. -253 253 253 253 253 253 253 253 253 253 253 253
  113269. -253 253 253 253 253 253 253 253 253 253 253 253
  113270. -253 253 253 253 253 253 253 253 253 253 253 253
  113271. -242 242 242 82 82 82 18 14 6 163 110 8
  113272. -216 158 10 236 178 12 242 186 14 246 190 14
  113273. -246 190 14 246 190 14 246 190 14 246 190 14
  113274. -246 190 14 246 190 14 246 190 14 246 190 14
  113275. -246 190 14 246 190 14 246 190 14 246 190 14
  113276. -246 190 14 246 190 14 242 186 14 163 133 67
  113277. - 46 46 46 18 18 18 6 6 6 0 0 0
  113278. - 0 0 0 0 0 0 0 0 0 0 0 0
  113279. - 0 0 0 0 0 0 0 0 0 0 0 0
  113280. - 0 0 0 0 0 0 0 0 0 10 10 10
  113281. - 30 30 30 78 78 78 163 133 67 210 150 10
  113282. -236 178 12 246 186 14 246 190 14 246 190 14
  113283. -246 190 14 246 190 14 246 190 14 246 190 14
  113284. -246 190 14 246 190 14 246 190 14 246 190 14
  113285. -246 190 14 246 190 14 246 190 14 246 190 14
  113286. -241 196 14 215 174 15 190 178 144 253 253 253
  113287. -253 253 253 253 253 253 253 253 253 253 253 253
  113288. -253 253 253 253 253 253 253 253 253 253 253 253
  113289. -253 253 253 253 253 253 253 253 253 253 253 253
  113290. -253 253 253 253 253 253 253 253 253 218 218 218
  113291. - 58 58 58 2 2 6 22 18 6 167 114 7
  113292. -216 158 10 236 178 12 246 186 14 246 190 14
  113293. -246 190 14 246 190 14 246 190 14 246 190 14
  113294. -246 190 14 246 190 14 246 190 14 246 190 14
  113295. -246 190 14 246 190 14 246 190 14 246 190 14
  113296. -246 190 14 246 186 14 242 186 14 190 150 46
  113297. - 54 54 54 22 22 22 6 6 6 0 0 0
  113298. - 0 0 0 0 0 0 0 0 0 0 0 0
  113299. - 0 0 0 0 0 0 0 0 0 0 0 0
  113300. - 0 0 0 0 0 0 0 0 0 14 14 14
  113301. - 38 38 38 86 86 86 180 133 36 213 154 11
  113302. -236 178 12 246 186 14 246 190 14 246 190 14
  113303. -246 190 14 246 190 14 246 190 14 246 190 14
  113304. -246 190 14 246 190 14 246 190 14 246 190 14
  113305. -246 190 14 246 190 14 246 190 14 246 190 14
  113306. -246 190 14 232 195 16 190 146 13 214 214 214
  113307. -253 253 253 253 253 253 253 253 253 253 253 253
  113308. -253 253 253 253 253 253 253 253 253 253 253 253
  113309. -253 253 253 253 253 253 253 253 253 253 253 253
  113310. -253 253 253 250 250 250 170 170 170 26 26 26
  113311. - 2 2 6 2 2 6 37 26 9 163 110 8
  113312. -219 162 10 239 182 13 246 186 14 246 190 14
  113313. -246 190 14 246 190 14 246 190 14 246 190 14
  113314. -246 190 14 246 190 14 246 190 14 246 190 14
  113315. -246 190 14 246 190 14 246 190 14 246 190 14
  113316. -246 186 14 236 178 12 224 166 10 142 122 72
  113317. - 46 46 46 18 18 18 6 6 6 0 0 0
  113318. - 0 0 0 0 0 0 0 0 0 0 0 0
  113319. - 0 0 0 0 0 0 0 0 0 0 0 0
  113320. - 0 0 0 0 0 0 6 6 6 18 18 18
  113321. - 50 50 50 109 106 95 192 133 9 224 166 10
  113322. -242 186 14 246 190 14 246 190 14 246 190 14
  113323. -246 190 14 246 190 14 246 190 14 246 190 14
  113324. -246 190 14 246 190 14 246 190 14 246 190 14
  113325. -246 190 14 246 190 14 246 190 14 246 190 14
  113326. -242 186 14 226 184 13 210 162 10 142 110 46
  113327. -226 226 226 253 253 253 253 253 253 253 253 253
  113328. -253 253 253 253 253 253 253 253 253 253 253 253
  113329. -253 253 253 253 253 253 253 253 253 253 253 253
  113330. -198 198 198 66 66 66 2 2 6 2 2 6
  113331. - 2 2 6 2 2 6 50 34 6 156 107 11
  113332. -219 162 10 239 182 13 246 186 14 246 190 14
  113333. -246 190 14 246 190 14 246 190 14 246 190 14
  113334. -246 190 14 246 190 14 246 190 14 246 190 14
  113335. -246 190 14 246 190 14 246 190 14 242 186 14
  113336. -234 174 13 213 154 11 154 122 46 66 66 66
  113337. - 30 30 30 10 10 10 0 0 0 0 0 0
  113338. - 0 0 0 0 0 0 0 0 0 0 0 0
  113339. - 0 0 0 0 0 0 0 0 0 0 0 0
  113340. - 0 0 0 0 0 0 6 6 6 22 22 22
  113341. - 58 58 58 154 121 60 206 145 10 234 174 13
  113342. -242 186 14 246 186 14 246 190 14 246 190 14
  113343. -246 190 14 246 190 14 246 190 14 246 190 14
  113344. -246 190 14 246 190 14 246 190 14 246 190 14
  113345. -246 190 14 246 190 14 246 190 14 246 190 14
  113346. -246 186 14 236 178 12 210 162 10 163 110 8
  113347. - 61 42 6 138 138 138 218 218 218 250 250 250
  113348. -253 253 253 253 253 253 253 253 253 250 250 250
  113349. -242 242 242 210 210 210 144 144 144 66 66 66
  113350. - 6 6 6 2 2 6 2 2 6 2 2 6
  113351. - 2 2 6 2 2 6 61 42 6 163 110 8
  113352. -216 158 10 236 178 12 246 190 14 246 190 14
  113353. -246 190 14 246 190 14 246 190 14 246 190 14
  113354. -246 190 14 246 190 14 246 190 14 246 190 14
  113355. -246 190 14 239 182 13 230 174 11 216 158 10
  113356. -190 142 34 124 112 88 70 70 70 38 38 38
  113357. - 18 18 18 6 6 6 0 0 0 0 0 0
  113358. - 0 0 0 0 0 0 0 0 0 0 0 0
  113359. - 0 0 0 0 0 0 0 0 0 0 0 0
  113360. - 0 0 0 0 0 0 6 6 6 22 22 22
  113361. - 62 62 62 168 124 44 206 145 10 224 166 10
  113362. -236 178 12 239 182 13 242 186 14 242 186 14
  113363. -246 186 14 246 190 14 246 190 14 246 190 14
  113364. -246 190 14 246 190 14 246 190 14 246 190 14
  113365. -246 190 14 246 190 14 246 190 14 246 190 14
  113366. -246 190 14 236 178 12 216 158 10 175 118 6
  113367. - 80 54 7 2 2 6 6 6 6 30 30 30
  113368. - 54 54 54 62 62 62 50 50 50 38 38 38
  113369. - 14 14 14 2 2 6 2 2 6 2 2 6
  113370. - 2 2 6 2 2 6 2 2 6 2 2 6
  113371. - 2 2 6 6 6 6 80 54 7 167 114 7
  113372. -213 154 11 236 178 12 246 190 14 246 190 14
  113373. -246 190 14 246 190 14 246 190 14 246 190 14
  113374. -246 190 14 242 186 14 239 182 13 239 182 13
  113375. -230 174 11 210 150 10 174 135 50 124 112 88
  113376. - 82 82 82 54 54 54 34 34 34 18 18 18
  113377. - 6 6 6 0 0 0 0 0 0 0 0 0
  113378. - 0 0 0 0 0 0 0 0 0 0 0 0
  113379. - 0 0 0 0 0 0 0 0 0 0 0 0
  113380. - 0 0 0 0 0 0 6 6 6 18 18 18
  113381. - 50 50 50 158 118 36 192 133 9 200 144 11
  113382. -216 158 10 219 162 10 224 166 10 226 170 11
  113383. -230 174 11 236 178 12 239 182 13 239 182 13
  113384. -242 186 14 246 186 14 246 190 14 246 190 14
  113385. -246 190 14 246 190 14 246 190 14 246 190 14
  113386. -246 186 14 230 174 11 210 150 10 163 110 8
  113387. -104 69 6 10 10 10 2 2 6 2 2 6
  113388. - 2 2 6 2 2 6 2 2 6 2 2 6
  113389. - 2 2 6 2 2 6 2 2 6 2 2 6
  113390. - 2 2 6 2 2 6 2 2 6 2 2 6
  113391. - 2 2 6 6 6 6 91 60 6 167 114 7
  113392. -206 145 10 230 174 11 242 186 14 246 190 14
  113393. -246 190 14 246 190 14 246 186 14 242 186 14
  113394. -239 182 13 230 174 11 224 166 10 213 154 11
  113395. -180 133 36 124 112 88 86 86 86 58 58 58
  113396. - 38 38 38 22 22 22 10 10 10 6 6 6
  113397. - 0 0 0 0 0 0 0 0 0 0 0 0
  113398. - 0 0 0 0 0 0 0 0 0 0 0 0
  113399. - 0 0 0 0 0 0 0 0 0 0 0 0
  113400. - 0 0 0 0 0 0 0 0 0 14 14 14
  113401. - 34 34 34 70 70 70 138 110 50 158 118 36
  113402. -167 114 7 180 123 7 192 133 9 197 138 11
  113403. -200 144 11 206 145 10 213 154 11 219 162 10
  113404. -224 166 10 230 174 11 239 182 13 242 186 14
  113405. -246 186 14 246 186 14 246 186 14 246 186 14
  113406. -239 182 13 216 158 10 185 133 11 152 99 6
  113407. -104 69 6 18 14 6 2 2 6 2 2 6
  113408. - 2 2 6 2 2 6 2 2 6 2 2 6
  113409. - 2 2 6 2 2 6 2 2 6 2 2 6
  113410. - 2 2 6 2 2 6 2 2 6 2 2 6
  113411. - 2 2 6 6 6 6 80 54 7 152 99 6
  113412. -192 133 9 219 162 10 236 178 12 239 182 13
  113413. -246 186 14 242 186 14 239 182 13 236 178 12
  113414. -224 166 10 206 145 10 192 133 9 154 121 60
  113415. - 94 94 94 62 62 62 42 42 42 22 22 22
  113416. - 14 14 14 6 6 6 0 0 0 0 0 0
  113417. - 0 0 0 0 0 0 0 0 0 0 0 0
  113418. - 0 0 0 0 0 0 0 0 0 0 0 0
  113419. - 0 0 0 0 0 0 0 0 0 0 0 0
  113420. - 0 0 0 0 0 0 0 0 0 6 6 6
  113421. - 18 18 18 34 34 34 58 58 58 78 78 78
  113422. -101 98 89 124 112 88 142 110 46 156 107 11
  113423. -163 110 8 167 114 7 175 118 6 180 123 7
  113424. -185 133 11 197 138 11 210 150 10 219 162 10
  113425. -226 170 11 236 178 12 236 178 12 234 174 13
  113426. -219 162 10 197 138 11 163 110 8 130 83 6
  113427. - 91 60 6 10 10 10 2 2 6 2 2 6
  113428. - 18 18 18 38 38 38 38 38 38 38 38 38
  113429. - 38 38 38 38 38 38 38 38 38 38 38 38
  113430. - 38 38 38 38 38 38 26 26 26 2 2 6
  113431. - 2 2 6 6 6 6 70 47 6 137 92 6
  113432. -175 118 6 200 144 11 219 162 10 230 174 11
  113433. -234 174 13 230 174 11 219 162 10 210 150 10
  113434. -192 133 9 163 110 8 124 112 88 82 82 82
  113435. - 50 50 50 30 30 30 14 14 14 6 6 6
  113436. - 0 0 0 0 0 0 0 0 0 0 0 0
  113437. - 0 0 0 0 0 0 0 0 0 0 0 0
  113438. - 0 0 0 0 0 0 0 0 0 0 0 0
  113439. - 0 0 0 0 0 0 0 0 0 0 0 0
  113440. - 0 0 0 0 0 0 0 0 0 0 0 0
  113441. - 6 6 6 14 14 14 22 22 22 34 34 34
  113442. - 42 42 42 58 58 58 74 74 74 86 86 86
  113443. -101 98 89 122 102 70 130 98 46 121 87 25
  113444. -137 92 6 152 99 6 163 110 8 180 123 7
  113445. -185 133 11 197 138 11 206 145 10 200 144 11
  113446. -180 123 7 156 107 11 130 83 6 104 69 6
  113447. - 50 34 6 54 54 54 110 110 110 101 98 89
  113448. - 86 86 86 82 82 82 78 78 78 78 78 78
  113449. - 78 78 78 78 78 78 78 78 78 78 78 78
  113450. - 78 78 78 82 82 82 86 86 86 94 94 94
  113451. -106 106 106 101 101 101 86 66 34 124 80 6
  113452. -156 107 11 180 123 7 192 133 9 200 144 11
  113453. -206 145 10 200 144 11 192 133 9 175 118 6
  113454. -139 102 15 109 106 95 70 70 70 42 42 42
  113455. - 22 22 22 10 10 10 0 0 0 0 0 0
  113456. - 0 0 0 0 0 0 0 0 0 0 0 0
  113457. - 0 0 0 0 0 0 0 0 0 0 0 0
  113458. - 0 0 0 0 0 0 0 0 0 0 0 0
  113459. - 0 0 0 0 0 0 0 0 0 0 0 0
  113460. - 0 0 0 0 0 0 0 0 0 0 0 0
  113461. - 0 0 0 0 0 0 6 6 6 10 10 10
  113462. - 14 14 14 22 22 22 30 30 30 38 38 38
  113463. - 50 50 50 62 62 62 74 74 74 90 90 90
  113464. -101 98 89 112 100 78 121 87 25 124 80 6
  113465. -137 92 6 152 99 6 152 99 6 152 99 6
  113466. -138 86 6 124 80 6 98 70 6 86 66 30
  113467. -101 98 89 82 82 82 58 58 58 46 46 46
  113468. - 38 38 38 34 34 34 34 34 34 34 34 34
  113469. - 34 34 34 34 34 34 34 34 34 34 34 34
  113470. - 34 34 34 34 34 34 38 38 38 42 42 42
  113471. - 54 54 54 82 82 82 94 86 76 91 60 6
  113472. -134 86 6 156 107 11 167 114 7 175 118 6
  113473. -175 118 6 167 114 7 152 99 6 121 87 25
  113474. -101 98 89 62 62 62 34 34 34 18 18 18
  113475. - 6 6 6 0 0 0 0 0 0 0 0 0
  113476. - 0 0 0 0 0 0 0 0 0 0 0 0
  113477. - 0 0 0 0 0 0 0 0 0 0 0 0
  113478. - 0 0 0 0 0 0 0 0 0 0 0 0
  113479. - 0 0 0 0 0 0 0 0 0 0 0 0
  113480. - 0 0 0 0 0 0 0 0 0 0 0 0
  113481. - 0 0 0 0 0 0 0 0 0 0 0 0
  113482. - 0 0 0 6 6 6 6 6 6 10 10 10
  113483. - 18 18 18 22 22 22 30 30 30 42 42 42
  113484. - 50 50 50 66 66 66 86 86 86 101 98 89
  113485. -106 86 58 98 70 6 104 69 6 104 69 6
  113486. -104 69 6 91 60 6 82 62 34 90 90 90
  113487. - 62 62 62 38 38 38 22 22 22 14 14 14
  113488. - 10 10 10 10 10 10 10 10 10 10 10 10
  113489. - 10 10 10 10 10 10 6 6 6 10 10 10
  113490. - 10 10 10 10 10 10 10 10 10 14 14 14
  113491. - 22 22 22 42 42 42 70 70 70 89 81 66
  113492. - 80 54 7 104 69 6 124 80 6 137 92 6
  113493. -134 86 6 116 81 8 100 82 52 86 86 86
  113494. - 58 58 58 30 30 30 14 14 14 6 6 6
  113495. - 0 0 0 0 0 0 0 0 0 0 0 0
  113496. - 0 0 0 0 0 0 0 0 0 0 0 0
  113497. - 0 0 0 0 0 0 0 0 0 0 0 0
  113498. - 0 0 0 0 0 0 0 0 0 0 0 0
  113499. - 0 0 0 0 0 0 0 0 0 0 0 0
  113500. - 0 0 0 0 0 0 0 0 0 0 0 0
  113501. - 0 0 0 0 0 0 0 0 0 0 0 0
  113502. - 0 0 0 0 0 0 0 0 0 0 0 0
  113503. - 0 0 0 6 6 6 10 10 10 14 14 14
  113504. - 18 18 18 26 26 26 38 38 38 54 54 54
  113505. - 70 70 70 86 86 86 94 86 76 89 81 66
  113506. - 89 81 66 86 86 86 74 74 74 50 50 50
  113507. - 30 30 30 14 14 14 6 6 6 0 0 0
  113508. - 0 0 0 0 0 0 0 0 0 0 0 0
  113509. - 0 0 0 0 0 0 0 0 0 0 0 0
  113510. - 0 0 0 0 0 0 0 0 0 0 0 0
  113511. - 6 6 6 18 18 18 34 34 34 58 58 58
  113512. - 82 82 82 89 81 66 89 81 66 89 81 66
  113513. - 94 86 66 94 86 76 74 74 74 50 50 50
  113514. - 26 26 26 14 14 14 6 6 6 0 0 0
  113515. - 0 0 0 0 0 0 0 0 0 0 0 0
  113516. - 0 0 0 0 0 0 0 0 0 0 0 0
  113517. - 0 0 0 0 0 0 0 0 0 0 0 0
  113518. - 0 0 0 0 0 0 0 0 0 0 0 0
  113519. - 0 0 0 0 0 0 0 0 0 0 0 0
  113520. - 0 0 0 0 0 0 0 0 0 0 0 0
  113521. - 0 0 0 0 0 0 0 0 0 0 0 0
  113522. - 0 0 0 0 0 0 0 0 0 0 0 0
  113523. - 0 0 0 0 0 0 0 0 0 0 0 0
  113524. - 6 6 6 6 6 6 14 14 14 18 18 18
  113525. - 30 30 30 38 38 38 46 46 46 54 54 54
  113526. - 50 50 50 42 42 42 30 30 30 18 18 18
  113527. - 10 10 10 0 0 0 0 0 0 0 0 0
  113528. - 0 0 0 0 0 0 0 0 0 0 0 0
  113529. - 0 0 0 0 0 0 0 0 0 0 0 0
  113530. - 0 0 0 0 0 0 0 0 0 0 0 0
  113531. - 0 0 0 6 6 6 14 14 14 26 26 26
  113532. - 38 38 38 50 50 50 58 58 58 58 58 58
  113533. - 54 54 54 42 42 42 30 30 30 18 18 18
  113534. - 10 10 10 0 0 0 0 0 0 0 0 0
  113535. - 0 0 0 0 0 0 0 0 0 0 0 0
  113536. - 0 0 0 0 0 0 0 0 0 0 0 0
  113537. - 0 0 0 0 0 0 0 0 0 0 0 0
  113538. - 0 0 0 0 0 0 0 0 0 0 0 0
  113539. - 0 0 0 0 0 0 0 0 0 0 0 0
  113540. - 0 0 0 0 0 0 0 0 0 0 0 0
  113541. - 0 0 0 0 0 0 0 0 0 0 0 0
  113542. - 0 0 0 0 0 0 0 0 0 0 0 0
  113543. - 0 0 0 0 0 0 0 0 0 0 0 0
  113544. - 0 0 0 0 0 0 0 0 0 6 6 6
  113545. - 6 6 6 10 10 10 14 14 14 18 18 18
  113546. - 18 18 18 14 14 14 10 10 10 6 6 6
  113547. - 0 0 0 0 0 0 0 0 0 0 0 0
  113548. - 0 0 0 0 0 0 0 0 0 0 0 0
  113549. - 0 0 0 0 0 0 0 0 0 0 0 0
  113550. - 0 0 0 0 0 0 0 0 0 0 0 0
  113551. - 0 0 0 0 0 0 0 0 0 6 6 6
  113552. - 14 14 14 18 18 18 22 22 22 22 22 22
  113553. - 18 18 18 14 14 14 10 10 10 6 6 6
  113554. - 0 0 0 0 0 0 0 0 0 0 0 0
  113555. - 0 0 0 0 0 0 0 0 0 0 0 0
  113556. - 0 0 0 0 0 0 0 0 0 0 0 0
  113557. - 0 0 0 0 0 0 0 0 0 0 0 0
  113558. - 0 0 0 0 0 0 0 0 0 0 0 0
  113559. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113560. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113561. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113562. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113564. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113565. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113566. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113567. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113568. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113569. +0 0 0 0 0 0 0 0 0
  113570. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113571. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113572. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  113573. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113574. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113575. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113576. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113577. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  113578. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113579. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113580. +0 0 0 0 0 0 0 0 0
  113581. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113582. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  113583. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  113584. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  113585. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113586. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113587. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  113588. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  113589. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  113590. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113591. +0 0 0 0 0 0 0 0 0
  113592. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113593. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  113594. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  113595. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  113596. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113597. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113598. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  113599. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  113600. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  113601. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  113602. +0 0 0 0 0 0 0 0 0
  113603. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  113604. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  113605. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  113606. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  113607. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  113608. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113609. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  113610. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  113611. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  113612. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  113613. +0 0 0 0 0 0 0 0 0
  113614. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  113615. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  113616. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113617. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  113618. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  113619. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  113620. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  113621. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113622. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  113623. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  113624. +0 0 0 0 0 0 0 0 0
  113625. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113626. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  113627. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  113628. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113629. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  113630. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  113631. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  113632. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113633. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  113634. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  113635. +0 0 0 0 0 0 0 0 0
  113636. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  113637. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  113638. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  113639. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113640. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  113641. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  113642. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113643. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  113644. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  113645. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  113646. +0 0 0 0 0 0 0 0 0
  113647. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  113648. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113649. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  113650. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113651. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  113652. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  113653. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113654. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  113655. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  113656. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  113657. +0 0 0 0 0 0 0 0 0
  113658. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113659. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  113660. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  113661. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  113662. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  113663. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  113664. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113665. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  113666. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  113667. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  113668. +0 0 0 0 0 0 0 0 0
  113669. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  113670. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  113671. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  113672. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  113673. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  113674. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  113675. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  113676. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  113677. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  113678. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  113679. +0 0 0 0 0 0 0 0 0
  113680. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113681. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  113682. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  113683. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  113684. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  113685. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  113686. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  113687. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  113688. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113689. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  113690. +0 0 0 0 0 0 0 0 0
  113691. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113692. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  113693. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113694. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  113695. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  113696. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  113697. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  113698. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  113699. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113700. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  113701. +0 0 0 0 0 0 0 0 0
  113702. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113703. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  113704. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113705. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  113706. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  113707. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  113708. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  113709. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  113710. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113711. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  113712. +0 0 0 0 0 0 0 0 0
  113713. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113714. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  113715. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113716. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  113717. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  113718. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  113719. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  113720. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113721. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113722. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  113723. +0 0 0 0 0 0 0 0 0
  113724. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113725. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  113726. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113727. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  113728. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  113729. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  113730. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  113731. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113732. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  113733. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  113734. +0 0 0 0 0 0 0 0 0
  113735. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113736. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  113737. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113738. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  113739. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  113740. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  113741. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  113742. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113743. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  113744. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  113745. +0 0 0 0 0 0 0 0 0
  113746. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113747. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  113748. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113749. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113750. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  113751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113752. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  113753. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113754. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  113755. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113756. +0 0 0 0 0 0 0 0 0
  113757. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113758. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  113759. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  113760. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113761. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  113762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113763. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  113764. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113765. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  113766. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113767. +0 0 0 0 0 0 0 0 0
  113768. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113769. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  113770. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  113771. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  113772. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  113773. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113774. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  113775. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  113776. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  113777. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113778. +0 0 0 0 0 0 0 0 0
  113779. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113781. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  113782. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  113783. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113784. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113785. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  113786. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  113787. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  113788. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113789. +0 0 0 0 0 0 0 0 0
  113790. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113792. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  113793. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  113794. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113795. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113796. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  113797. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  113798. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  113799. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113800. +0 0 0 0 0 0 0 0 0
  113801. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113802. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113803. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  113804. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  113805. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  113806. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  113807. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113808. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  113809. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113810. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113811. +0 0 0 0 0 0 0 0 0
  113812. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113813. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113814. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  113815. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  113816. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  113817. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  113818. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  113819. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113820. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113821. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113822. +0 0 0 0 0 0 0 0 0
  113823. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113824. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113825. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  113826. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  113827. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  113828. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  113829. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  113830. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  113831. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113832. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113833. +0 0 0 0 0 0 0 0 0
  113834. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113835. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113836. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  113837. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  113838. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  113839. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113840. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  113841. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  113842. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  113843. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113844. +0 0 0 0 0 0 0 0 0
  113845. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113846. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  113847. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  113848. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  113849. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113850. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113851. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  113852. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  113853. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  113854. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113855. +0 0 0 0 0 0 0 0 0
  113856. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113857. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  113858. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113859. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  113860. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113861. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113862. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  113863. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  113864. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  113865. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113866. +0 0 0 0 0 0 0 0 0
  113867. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113868. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  113869. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113870. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  113871. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113872. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113873. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  113874. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  113875. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  113876. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113877. +0 0 0 0 0 0 0 0 0
  113878. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113879. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  113880. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  113881. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  113882. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  113883. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113884. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  113885. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  113886. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  113887. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113888. +0 0 0 0 0 0 0 0 0
  113889. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113890. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  113891. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  113892. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113893. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  113894. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  113895. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  113896. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  113897. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  113898. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113899. +0 0 0 0 0 0 0 0 0
  113900. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113901. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  113902. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  113903. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113904. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  113905. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  113906. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  113907. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  113908. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  113909. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113910. +0 0 0 0 0 0 0 0 0
  113911. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113912. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  113913. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  113914. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  113915. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  113916. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  113917. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  113918. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  113919. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  113920. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113921. +0 0 0 0 0 0 0 0 0
  113922. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113923. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  113924. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  113925. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  113926. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  113927. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  113928. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  113929. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  113930. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  113931. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113932. +0 0 0 0 0 0 0 0 0
  113933. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113934. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  113935. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  113936. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  113937. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  113938. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  113939. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  113940. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  113941. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  113942. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113943. +0 0 0 0 0 0 0 0 0
  113944. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113945. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  113946. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  113947. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113948. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  113949. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  113950. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113951. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  113952. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  113953. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113954. +0 0 0 0 0 0 0 0 0
  113955. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113956. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113957. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  113958. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113959. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  113960. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  113961. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113962. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  113963. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113965. +0 0 0 0 0 0 0 0 0
  113966. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113967. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  113968. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  113969. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113970. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  113971. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  113972. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113973. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  113974. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  113975. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  113976. +0 0 0 0 0 0 0 0 0
  113977. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  113978. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  113979. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  113980. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113981. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  113982. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  113983. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113984. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113985. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  113986. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  113987. +0 0 0 0 0 0 0 0 0
  113988. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  113989. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  113990. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  113991. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113992. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  113993. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  113994. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113995. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  113996. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  113997. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  113998. +0 0 0 0 0 0 0 0 0
  113999. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  114000. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  114001. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  114002. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114003. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  114004. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  114005. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114006. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114007. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  114008. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  114009. +0 0 0 0 0 0 0 0 0
  114010. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  114011. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  114012. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  114013. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114014. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  114015. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  114016. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114017. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114018. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  114019. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  114020. +0 0 0 0 0 0 0 0 0
  114021. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  114022. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  114023. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  114024. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114025. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  114026. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  114027. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114028. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114029. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  114030. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  114031. +0 0 0 0 0 0 0 0 0
  114032. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  114033. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  114034. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  114035. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114036. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  114037. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  114038. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114039. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114040. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  114041. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  114042. +0 0 0 0 0 0 0 0 0
  114043. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  114044. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  114045. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  114046. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114047. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  114048. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  114049. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114050. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114051. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  114052. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  114053. +0 0 0 0 0 0 0 0 0
  114054. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  114055. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  114056. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  114057. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114058. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  114059. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  114060. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114061. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114062. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  114063. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  114064. +0 0 0 0 0 0 0 0 0
  114065. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  114066. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  114067. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  114068. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114069. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  114070. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  114071. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114072. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114073. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  114074. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  114075. +0 0 0 0 0 0 0 0 0
  114076. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  114077. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  114078. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  114079. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114080. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  114081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  114082. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  114083. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  114084. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  114085. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  114086. +0 0 0 0 0 0 0 0 0
  114087. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  114088. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  114089. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  114090. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114091. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  114092. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114093. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  114094. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  114095. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  114096. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  114097. +0 0 0 0 0 0 0 0 0
  114098. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  114099. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  114100. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  114101. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  114102. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  114103. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  114104. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  114105. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  114106. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  114107. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  114108. +0 0 0 0 0 0 0 0 0
  114109. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  114110. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  114111. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  114112. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  114113. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  114114. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  114115. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  114116. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  114117. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  114118. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  114119. +0 0 0 0 0 0 0 0 0
  114120. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  114121. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  114122. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  114123. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  114124. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  114125. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  114126. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  114127. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114128. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  114129. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  114130. +0 0 0 0 0 0 0 0 0
  114131. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  114132. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  114133. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114134. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114135. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  114136. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114137. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  114138. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114139. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  114140. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  114141. +0 0 0 0 0 0 0 0 0
  114142. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  114143. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  114144. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  114145. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  114146. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  114147. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114148. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  114149. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  114150. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  114151. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  114152. +0 0 0 0 0 0 0 0 0
  114153. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114154. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  114155. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  114156. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  114157. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114158. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114159. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  114160. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  114161. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  114162. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114163. +0 0 0 0 0 0 0 0 0
  114164. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114165. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  114166. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  114167. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  114168. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114169. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114170. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  114171. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  114172. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  114173. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  114174. +0 0 0 0 0 0 0 0 0
  114175. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114176. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  114177. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  114178. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  114179. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114180. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114181. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  114182. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  114183. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  114184. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  114185. +0 0 0 0 0 0 0 0 0
  114186. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114187. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  114188. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  114189. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  114190. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114191. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114192. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  114193. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  114194. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114195. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  114196. +0 0 0 0 0 0 0 0 0
  114197. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114198. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  114199. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  114200. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  114201. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114202. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114203. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  114204. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  114205. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114206. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  114207. +0 0 0 0 0 0 0 0 0
  114208. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114209. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  114210. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114211. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  114212. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114213. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114214. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  114215. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  114216. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114217. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  114218. +0 0 0 0 0 0 0 0 0
  114219. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114220. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  114221. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114222. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  114223. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114224. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114225. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  114226. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  114227. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  114228. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  114229. +0 0 0 0 0 0 0 0 0
  114230. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114231. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  114232. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114233. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  114234. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114235. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114236. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  114237. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  114238. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  114239. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  114240. +0 0 0 0 0 0 0 0 0
  114241. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114242. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  114243. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114244. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  114245. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  114246. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114247. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  114248. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  114249. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  114250. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114251. +0 0 0 0 0 0 0 0 0
  114252. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114253. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  114254. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114255. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  114256. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  114257. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114258. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  114259. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114260. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  114261. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114262. +0 0 0 0 0 0 0 0 0
  114263. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114264. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  114265. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114266. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  114267. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  114268. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  114269. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  114270. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114271. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  114272. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114273. +0 0 0 0 0 0 0 0 0
  114274. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114275. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  114276. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114277. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  114278. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  114279. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  114280. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  114281. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114282. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  114283. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114284. +0 0 0 0 0 0 0 0 0
  114285. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114286. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  114287. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  114288. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  114289. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  114290. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  114291. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  114292. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114293. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  114294. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114295. +0 0 0 0 0 0 0 0 0
  114296. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114297. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  114298. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  114299. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  114300. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114301. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114302. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  114303. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  114304. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  114305. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114306. +0 0 0 0 0 0 0 0 0
  114307. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114309. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  114310. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  114311. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  114312. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  114313. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  114314. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  114315. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  114316. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114317. +0 0 0 0 0 0 0 0 0
  114318. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114319. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114320. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  114321. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  114322. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  114323. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  114324. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  114325. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  114326. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114327. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114328. +0 0 0 0 0 0 0 0 0
  114329. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114330. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114331. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114332. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  114333. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  114334. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  114335. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  114336. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114337. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114338. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114339. +0 0 0 0 0 0 0 0 0
  114340. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114341. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114342. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114343. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  114344. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114345. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114346. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  114347. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114348. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114349. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114350. +0 0 0 0 0 0 0 0 0
  114351. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114352. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114353. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114354. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  114355. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114356. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114357. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  114358. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114359. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114360. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114361. +0 0 0 0 0 0 0 0 0
  114362. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114363. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114364. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114365. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  114366. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114367. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114368. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  114369. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114370. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114371. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114372. +0 0 0 0 0 0 0 0 0
  114373. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114374. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114375. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114376. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  114377. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  114378. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  114379. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  114380. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114381. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114382. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114383. +0 0 0 0 0 0 0 0 0
  114384. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114385. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114386. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114387. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114388. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  114389. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  114390. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  114391. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114392. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114393. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114394. +0 0 0 0 0 0 0 0 0
  114395. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114396. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114397. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114398. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114399. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  114400. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  114401. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114402. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114403. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114404. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114405. +0 0 0 0 0 0 0 0 0
  114406. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114407. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114408. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114409. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114410. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  114411. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  114412. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114413. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114414. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114415. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114416. +0 0 0 0 0 0 0 0 0
  114417. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114418. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114419. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114420. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114421. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114422. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114423. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114424. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114425. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114426. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114427. +0 0 0 0 0 0 0 0 0
  114428. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114429. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114430. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114431. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114432. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114433. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114434. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114435. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114436. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114437. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  114438. +0 0 0 0 0 0 0 0 0
  114439. diff -Nur linux-3.12.38/drivers/video/Makefile linux-rpi/drivers/video/Makefile
  114440. --- linux-3.12.38/drivers/video/Makefile 2015-02-16 16:15:42.000000000 +0100
  114441. +++ linux-rpi/drivers/video/Makefile 2015-03-10 17:26:51.346216687 +0100
  114442. @@ -100,6 +100,7 @@
  114443. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  114444. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  114445. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  114446. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  114447. obj-$(CONFIG_FB_68328) += 68328fb.o
  114448. obj-$(CONFIG_FB_GBE) += gbefb.o
  114449. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  114450. diff -Nur linux-3.12.38/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  114451. --- linux-3.12.38/drivers/w1/masters/w1-gpio.c 2015-02-16 16:15:42.000000000 +0100
  114452. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2015-03-10 17:26:51.410216687 +0100
  114453. @@ -22,6 +22,15 @@
  114454. #include "../w1.h"
  114455. #include "../w1_int.h"
  114456. +static int w1_gpio_pullup = -1;
  114457. +static int w1_gpio_pullup_orig = -1;
  114458. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  114459. +MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
  114460. +static int w1_gpio_pin = -1;
  114461. +static int w1_gpio_pin_orig = -1;
  114462. +module_param_named(gpiopin, w1_gpio_pin, int, 0);
  114463. +MODULE_PARM_DESC(gpiopin, "GPIO pin number");
  114464. +
  114465. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  114466. {
  114467. struct w1_gpio_platform_data *pdata = data;
  114468. @@ -46,6 +55,16 @@
  114469. return gpio_get_value(pdata->pin) ? 1 : 0;
  114470. }
  114471. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  114472. +{
  114473. + struct w1_gpio_platform_data *pdata = data;
  114474. +
  114475. + if (on)
  114476. + gpio_direction_output(pdata->pin, 1);
  114477. + else
  114478. + gpio_direction_input(pdata->pin);
  114479. +}
  114480. +
  114481. #if defined(CONFIG_OF)
  114482. static struct of_device_id w1_gpio_dt_ids[] = {
  114483. { .compatible = "w1-gpio" },
  114484. @@ -76,14 +95,16 @@
  114485. static int w1_gpio_probe(struct platform_device *pdev)
  114486. {
  114487. struct w1_bus_master *master;
  114488. - struct w1_gpio_platform_data *pdata;
  114489. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  114490. int err;
  114491. - if (of_have_populated_dt()) {
  114492. - err = w1_gpio_probe_dt(pdev);
  114493. - if (err < 0) {
  114494. - dev_err(&pdev->dev, "Failed to parse DT\n");
  114495. - return err;
  114496. + if(pdata == NULL) {
  114497. + if (of_have_populated_dt()) {
  114498. + err = w1_gpio_probe_dt(pdev);
  114499. + if (err < 0) {
  114500. + dev_err(&pdev->dev, "Failed to parse DT\n");
  114501. + return err;
  114502. + }
  114503. }
  114504. }
  114505. @@ -100,6 +121,19 @@
  114506. return -ENOMEM;
  114507. }
  114508. + w1_gpio_pin_orig = pdata->pin;
  114509. + w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
  114510. +
  114511. + if(gpio_is_valid(w1_gpio_pin)) {
  114512. + pdata->pin = w1_gpio_pin;
  114513. + pdata->ext_pullup_enable_pin = -1;
  114514. + }
  114515. + if(gpio_is_valid(w1_gpio_pullup)) {
  114516. + pdata->ext_pullup_enable_pin = w1_gpio_pullup;
  114517. + }
  114518. +
  114519. + dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
  114520. +
  114521. err = gpio_request(pdata->pin, "w1");
  114522. if (err) {
  114523. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  114524. @@ -127,6 +161,14 @@
  114525. master->write_bit = w1_gpio_write_bit_dir;
  114526. }
  114527. + if (gpio_is_valid(w1_gpio_pullup)) {
  114528. + if (pdata->is_open_drain)
  114529. + printk(KERN_ERR "w1-gpio 'pullup' option "
  114530. + "doesn't work with open drain GPIO\n");
  114531. + else
  114532. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  114533. + }
  114534. +
  114535. err = w1_add_master_device(master);
  114536. if (err) {
  114537. dev_err(&pdev->dev, "w1_add_master device failed\n");
  114538. @@ -167,8 +209,14 @@
  114539. w1_remove_master_device(master);
  114540. gpio_free(pdata->pin);
  114541. + if (gpio_is_valid(pdata->ext_pullup_enable_pin))
  114542. + gpio_free(pdata->ext_pullup_enable_pin);
  114543. +
  114544. kfree(master);
  114545. + pdata->pin = w1_gpio_pin_orig;
  114546. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
  114547. +
  114548. return 0;
  114549. }
  114550. diff -Nur linux-3.12.38/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  114551. --- linux-3.12.38/drivers/w1/w1.h 2015-02-16 16:15:42.000000000 +0100
  114552. +++ linux-rpi/drivers/w1/w1.h 2015-03-10 17:26:51.410216687 +0100
  114553. @@ -148,6 +148,12 @@
  114554. */
  114555. u8 (*set_pullup)(void *, int);
  114556. + /**
  114557. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  114558. + * @return -1=Error, 0=completed
  114559. + */
  114560. + void (*bitbang_pullup) (void *, u8);
  114561. +
  114562. /** Really nice hardware can handles the different types of ROM search
  114563. * w1_master* is passed to the slave found callback.
  114564. */
  114565. diff -Nur linux-3.12.38/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  114566. --- linux-3.12.38/drivers/w1/w1_int.c 2015-02-16 16:15:42.000000000 +0100
  114567. +++ linux-rpi/drivers/w1/w1_int.c 2015-03-10 17:26:51.410216687 +0100
  114568. @@ -130,6 +130,20 @@
  114569. master->set_pullup = NULL;
  114570. }
  114571. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  114572. + * and takes care of timing itself */
  114573. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  114574. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  114575. + "write_byte or touch_bit, disabling\n");
  114576. + master->set_pullup = NULL;
  114577. + }
  114578. +
  114579. + if (master->set_pullup && master->bitbang_pullup) {
  114580. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  114581. + "be set when bitbang_pullup is used, disabling\n");
  114582. + master->set_pullup = NULL;
  114583. + }
  114584. +
  114585. /* Lock until the device is added (or not) to w1_masters. */
  114586. mutex_lock(&w1_mlock);
  114587. /* Search for the first available id (starting at 1). */
  114588. diff -Nur linux-3.12.38/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  114589. --- linux-3.12.38/drivers/w1/w1_io.c 2015-02-16 16:15:42.000000000 +0100
  114590. +++ linux-rpi/drivers/w1/w1_io.c 2015-03-10 17:26:51.410216687 +0100
  114591. @@ -127,10 +127,22 @@
  114592. static void w1_post_write(struct w1_master *dev)
  114593. {
  114594. if (dev->pullup_duration) {
  114595. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  114596. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  114597. - else
  114598. + if (dev->enable_pullup) {
  114599. + if (dev->bus_master->set_pullup) {
  114600. + dev->bus_master->set_pullup(dev->
  114601. + bus_master->data,
  114602. + 0);
  114603. + } else if (dev->bus_master->bitbang_pullup) {
  114604. + dev->bus_master->
  114605. + bitbang_pullup(dev->bus_master->data, 1);
  114606. msleep(dev->pullup_duration);
  114607. + dev->bus_master->
  114608. + bitbang_pullup(dev->bus_master->data, 0);
  114609. + }
  114610. + } else {
  114611. + msleep(dev->pullup_duration);
  114612. + }
  114613. +
  114614. dev->pullup_duration = 0;
  114615. }
  114616. }
  114617. diff -Nur linux-3.12.38/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  114618. --- linux-3.12.38/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  114619. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2015-03-10 17:26:51.410216687 +0100
  114620. @@ -0,0 +1,384 @@
  114621. +/*
  114622. + * Broadcom BCM2708 watchdog driver.
  114623. + *
  114624. + * (c) Copyright 2010 Broadcom Europe Ltd
  114625. + *
  114626. + * This program is free software; you can redistribute it and/or
  114627. + * modify it under the terms of the GNU General Public License
  114628. + * as published by the Free Software Foundation; either version
  114629. + * 2 of the License, or (at your option) any later version.
  114630. + *
  114631. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  114632. + */
  114633. +
  114634. +#include <linux/interrupt.h>
  114635. +#include <linux/module.h>
  114636. +#include <linux/moduleparam.h>
  114637. +#include <linux/types.h>
  114638. +#include <linux/miscdevice.h>
  114639. +#include <linux/watchdog.h>
  114640. +#include <linux/fs.h>
  114641. +#include <linux/ioport.h>
  114642. +#include <linux/notifier.h>
  114643. +#include <linux/reboot.h>
  114644. +#include <linux/init.h>
  114645. +#include <linux/io.h>
  114646. +#include <linux/uaccess.h>
  114647. +#include <mach/platform.h>
  114648. +
  114649. +#include <asm/system.h>
  114650. +
  114651. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  114652. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  114653. +
  114654. +static unsigned long wdog_is_open;
  114655. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  114656. +static char expect_close;
  114657. +
  114658. +/*
  114659. + * Module parameters
  114660. + */
  114661. +
  114662. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  114663. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  114664. +
  114665. +module_param(heartbeat, int, 0);
  114666. +MODULE_PARM_DESC(heartbeat,
  114667. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  114668. + __MODULE_STRING(WD_TIMO) ")");
  114669. +
  114670. +static int nowayout = WATCHDOG_NOWAYOUT;
  114671. +module_param(nowayout, int, 0);
  114672. +MODULE_PARM_DESC(nowayout,
  114673. + "Watchdog cannot be stopped once started (default="
  114674. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  114675. +
  114676. +static DEFINE_SPINLOCK(wdog_lock);
  114677. +
  114678. +/**
  114679. + * Start the watchdog driver.
  114680. + */
  114681. +
  114682. +static int wdog_start(unsigned long timeout)
  114683. +{
  114684. + uint32_t cur;
  114685. + unsigned long flags;
  114686. + spin_lock_irqsave(&wdog_lock, flags);
  114687. +
  114688. + /* enable the watchdog */
  114689. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  114690. + __io_address(PM_WDOG));
  114691. + cur = ioread32(__io_address(PM_RSTC));
  114692. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  114693. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  114694. +
  114695. + spin_unlock_irqrestore(&wdog_lock, flags);
  114696. + return 0;
  114697. +}
  114698. +
  114699. +/**
  114700. + * Stop the watchdog driver.
  114701. + */
  114702. +
  114703. +static int wdog_stop(void)
  114704. +{
  114705. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  114706. + printk(KERN_INFO "watchdog stopped\n");
  114707. + return 0;
  114708. +}
  114709. +
  114710. +/**
  114711. + * Reload counter one with the watchdog heartbeat. We don't bother
  114712. + * reloading the cascade counter.
  114713. + */
  114714. +
  114715. +static void wdog_ping(void)
  114716. +{
  114717. + wdog_start(wdog_ticks);
  114718. +}
  114719. +
  114720. +/**
  114721. + * @t: the new heartbeat value that needs to be set.
  114722. + *
  114723. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  114724. + * value is incorrect we keep the old value and return -EINVAL. If
  114725. + * successful we return 0.
  114726. + */
  114727. +
  114728. +static int wdog_set_heartbeat(int t)
  114729. +{
  114730. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  114731. + return -EINVAL;
  114732. +
  114733. + heartbeat = t;
  114734. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  114735. + return 0;
  114736. +}
  114737. +
  114738. +/**
  114739. + * @file: file handle to the watchdog
  114740. + * @buf: buffer to write (unused as data does not matter here
  114741. + * @count: count of bytes
  114742. + * @ppos: pointer to the position to write. No seeks allowed
  114743. + *
  114744. + * A write to a watchdog device is defined as a keepalive signal.
  114745. + *
  114746. + * if 'nowayout' is set then normally a close() is ignored. But
  114747. + * if you write 'V' first then the close() will stop the timer.
  114748. + */
  114749. +
  114750. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  114751. + size_t count, loff_t *ppos)
  114752. +{
  114753. + if (count) {
  114754. + if (!nowayout) {
  114755. + size_t i;
  114756. +
  114757. + /* In case it was set long ago */
  114758. + expect_close = 0;
  114759. +
  114760. + for (i = 0; i != count; i++) {
  114761. + char c;
  114762. + if (get_user(c, buf + i))
  114763. + return -EFAULT;
  114764. + if (c == 'V')
  114765. + expect_close = 42;
  114766. + }
  114767. + }
  114768. + wdog_ping();
  114769. + }
  114770. + return count;
  114771. +}
  114772. +
  114773. +static int wdog_get_status(void)
  114774. +{
  114775. + unsigned long flags;
  114776. + int status = 0;
  114777. + spin_lock_irqsave(&wdog_lock, flags);
  114778. + /* FIXME: readback reset reason */
  114779. + spin_unlock_irqrestore(&wdog_lock, flags);
  114780. + return status;
  114781. +}
  114782. +
  114783. +static uint32_t wdog_get_remaining(void)
  114784. +{
  114785. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  114786. + return ret & PM_WDOG_TIME_SET;
  114787. +}
  114788. +
  114789. +/**
  114790. + * @file: file handle to the device
  114791. + * @cmd: watchdog command
  114792. + * @arg: argument pointer
  114793. + *
  114794. + * The watchdog API defines a common set of functions for all watchdogs
  114795. + * according to their available features. We only actually usefully support
  114796. + * querying capabilities and current status.
  114797. + */
  114798. +
  114799. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  114800. +{
  114801. + void __user *argp = (void __user *)arg;
  114802. + int __user *p = argp;
  114803. + int new_heartbeat;
  114804. + int status;
  114805. + int options;
  114806. + uint32_t remaining;
  114807. +
  114808. + struct watchdog_info ident = {
  114809. + .options = WDIOF_SETTIMEOUT|
  114810. + WDIOF_MAGICCLOSE|
  114811. + WDIOF_KEEPALIVEPING,
  114812. + .firmware_version = 1,
  114813. + .identity = "BCM2708",
  114814. + };
  114815. +
  114816. + switch (cmd) {
  114817. + case WDIOC_GETSUPPORT:
  114818. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  114819. + case WDIOC_GETSTATUS:
  114820. + status = wdog_get_status();
  114821. + return put_user(status, p);
  114822. + case WDIOC_GETBOOTSTATUS:
  114823. + return put_user(0, p);
  114824. + case WDIOC_KEEPALIVE:
  114825. + wdog_ping();
  114826. + return 0;
  114827. + case WDIOC_SETTIMEOUT:
  114828. + if (get_user(new_heartbeat, p))
  114829. + return -EFAULT;
  114830. + if (wdog_set_heartbeat(new_heartbeat))
  114831. + return -EINVAL;
  114832. + wdog_ping();
  114833. + /* Fall */
  114834. + case WDIOC_GETTIMEOUT:
  114835. + return put_user(heartbeat, p);
  114836. + case WDIOC_GETTIMELEFT:
  114837. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  114838. + return put_user(remaining, p);
  114839. + case WDIOC_SETOPTIONS:
  114840. + if (get_user(options, p))
  114841. + return -EFAULT;
  114842. + if (options & WDIOS_DISABLECARD)
  114843. + wdog_stop();
  114844. + if (options & WDIOS_ENABLECARD)
  114845. + wdog_start(wdog_ticks);
  114846. + return 0;
  114847. + default:
  114848. + return -ENOTTY;
  114849. + }
  114850. +}
  114851. +
  114852. +/**
  114853. + * @inode: inode of device
  114854. + * @file: file handle to device
  114855. + *
  114856. + * The watchdog device has been opened. The watchdog device is single
  114857. + * open and on opening we load the counters.
  114858. + */
  114859. +
  114860. +static int wdog_open(struct inode *inode, struct file *file)
  114861. +{
  114862. + if (test_and_set_bit(0, &wdog_is_open))
  114863. + return -EBUSY;
  114864. + /*
  114865. + * Activate
  114866. + */
  114867. + wdog_start(wdog_ticks);
  114868. + return nonseekable_open(inode, file);
  114869. +}
  114870. +
  114871. +/**
  114872. + * @inode: inode to board
  114873. + * @file: file handle to board
  114874. + *
  114875. + * The watchdog has a configurable API. There is a religious dispute
  114876. + * between people who want their watchdog to be able to shut down and
  114877. + * those who want to be sure if the watchdog manager dies the machine
  114878. + * reboots. In the former case we disable the counters, in the latter
  114879. + * case you have to open it again very soon.
  114880. + */
  114881. +
  114882. +static int wdog_release(struct inode *inode, struct file *file)
  114883. +{
  114884. + if (expect_close == 42) {
  114885. + wdog_stop();
  114886. + } else {
  114887. + printk(KERN_CRIT
  114888. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  114889. + wdog_ping();
  114890. + }
  114891. + clear_bit(0, &wdog_is_open);
  114892. + expect_close = 0;
  114893. + return 0;
  114894. +}
  114895. +
  114896. +/**
  114897. + * @this: our notifier block
  114898. + * @code: the event being reported
  114899. + * @unused: unused
  114900. + *
  114901. + * Our notifier is called on system shutdowns. Turn the watchdog
  114902. + * off so that it does not fire during the next reboot.
  114903. + */
  114904. +
  114905. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  114906. + void *unused)
  114907. +{
  114908. + if (code == SYS_DOWN || code == SYS_HALT)
  114909. + wdog_stop();
  114910. + return NOTIFY_DONE;
  114911. +}
  114912. +
  114913. +/*
  114914. + * Kernel Interfaces
  114915. + */
  114916. +
  114917. +
  114918. +static const struct file_operations wdog_fops = {
  114919. + .owner = THIS_MODULE,
  114920. + .llseek = no_llseek,
  114921. + .write = wdog_write,
  114922. + .unlocked_ioctl = wdog_ioctl,
  114923. + .open = wdog_open,
  114924. + .release = wdog_release,
  114925. +};
  114926. +
  114927. +static struct miscdevice wdog_miscdev = {
  114928. + .minor = WATCHDOG_MINOR,
  114929. + .name = "watchdog",
  114930. + .fops = &wdog_fops,
  114931. +};
  114932. +
  114933. +/*
  114934. + * The WDT card needs to learn about soft shutdowns in order to
  114935. + * turn the timebomb registers off.
  114936. + */
  114937. +
  114938. +static struct notifier_block wdog_notifier = {
  114939. + .notifier_call = wdog_notify_sys,
  114940. +};
  114941. +
  114942. +/**
  114943. + * cleanup_module:
  114944. + *
  114945. + * Unload the watchdog. You cannot do this with any file handles open.
  114946. + * If your watchdog is set to continue ticking on close and you unload
  114947. + * it, well it keeps ticking. We won't get the interrupt but the board
  114948. + * will not touch PC memory so all is fine. You just have to load a new
  114949. + * module in 60 seconds or reboot.
  114950. + */
  114951. +
  114952. +static void __exit wdog_exit(void)
  114953. +{
  114954. + misc_deregister(&wdog_miscdev);
  114955. + unregister_reboot_notifier(&wdog_notifier);
  114956. +}
  114957. +
  114958. +static int __init wdog_init(void)
  114959. +{
  114960. + int ret;
  114961. +
  114962. + /* Check that the heartbeat value is within it's range;
  114963. + if not reset to the default */
  114964. + if (wdog_set_heartbeat(heartbeat)) {
  114965. + wdog_set_heartbeat(WD_TIMO);
  114966. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  114967. + "0 < heartbeat < %d, using %d\n",
  114968. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  114969. + WD_TIMO);
  114970. + }
  114971. +
  114972. + ret = register_reboot_notifier(&wdog_notifier);
  114973. + if (ret) {
  114974. + printk(KERN_ERR
  114975. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  114976. + goto out_reboot;
  114977. + }
  114978. +
  114979. + ret = misc_register(&wdog_miscdev);
  114980. + if (ret) {
  114981. + printk(KERN_ERR
  114982. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  114983. + WATCHDOG_MINOR, ret);
  114984. + goto out_misc;
  114985. + }
  114986. +
  114987. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  114988. + heartbeat, nowayout);
  114989. + return 0;
  114990. +
  114991. +out_misc:
  114992. + unregister_reboot_notifier(&wdog_notifier);
  114993. +out_reboot:
  114994. + return ret;
  114995. +}
  114996. +
  114997. +module_init(wdog_init);
  114998. +module_exit(wdog_exit);
  114999. +
  115000. +MODULE_AUTHOR("Luke Diamand");
  115001. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  115002. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  115003. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  115004. +MODULE_LICENSE("GPL");
  115005. diff -Nur linux-3.12.38/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  115006. --- linux-3.12.38/drivers/watchdog/Kconfig 2015-02-16 16:15:42.000000000 +0100
  115007. +++ linux-rpi/drivers/watchdog/Kconfig 2015-03-10 17:26:51.410216687 +0100
  115008. @@ -392,6 +392,12 @@
  115009. To compile this driver as a module, choose M here: the
  115010. module will be called retu_wdt.
  115011. +config BCM2708_WDT
  115012. + tristate "BCM2708 Watchdog"
  115013. + depends on ARCH_BCM2708
  115014. + help
  115015. + Enables BCM2708 watchdog support.
  115016. +
  115017. # AVR32 Architecture
  115018. config AT32AP700X_WDT
  115019. diff -Nur linux-3.12.38/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  115020. --- linux-3.12.38/drivers/watchdog/Makefile 2015-02-16 16:15:42.000000000 +0100
  115021. +++ linux-rpi/drivers/watchdog/Makefile 2015-03-10 17:26:51.410216687 +0100
  115022. @@ -54,6 +54,7 @@
  115023. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  115024. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  115025. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  115026. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  115027. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  115028. # AVR32 Architecture
  115029. diff -Nur linux-3.12.38/fs/affs/amigaffs.c linux-rpi/fs/affs/amigaffs.c
  115030. --- linux-3.12.38/fs/affs/amigaffs.c 2015-02-16 16:15:42.000000000 +0100
  115031. +++ linux-rpi/fs/affs/amigaffs.c 2015-03-10 17:26:51.426216687 +0100
  115032. @@ -126,7 +126,7 @@
  115033. {
  115034. struct dentry *dentry;
  115035. spin_lock(&inode->i_lock);
  115036. - hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
  115037. + hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  115038. if (entry_ino == (u32)(long)dentry->d_fsdata) {
  115039. dentry->d_fsdata = (void *)inode->i_ino;
  115040. break;
  115041. diff -Nur linux-3.12.38/fs/autofs4/expire.c linux-rpi/fs/autofs4/expire.c
  115042. --- linux-3.12.38/fs/autofs4/expire.c 2015-02-16 16:15:42.000000000 +0100
  115043. +++ linux-rpi/fs/autofs4/expire.c 2015-03-10 17:26:51.426216687 +0100
  115044. @@ -91,7 +91,7 @@
  115045. spin_lock(&root->d_lock);
  115046. if (prev)
  115047. - next = prev->d_child.next;
  115048. + next = prev->d_u.d_child.next;
  115049. else {
  115050. prev = dget_dlock(root);
  115051. next = prev->d_subdirs.next;
  115052. @@ -105,13 +105,13 @@
  115053. return NULL;
  115054. }
  115055. - q = list_entry(next, struct dentry, d_child);
  115056. + q = list_entry(next, struct dentry, d_u.d_child);
  115057. spin_lock_nested(&q->d_lock, DENTRY_D_LOCK_NESTED);
  115058. /* Already gone or negative dentry (under construction) - try next */
  115059. if (!d_count(q) || !simple_positive(q)) {
  115060. spin_unlock(&q->d_lock);
  115061. - next = q->d_child.next;
  115062. + next = q->d_u.d_child.next;
  115063. goto cont;
  115064. }
  115065. dget_dlock(q);
  115066. @@ -161,13 +161,13 @@
  115067. goto relock;
  115068. }
  115069. spin_unlock(&p->d_lock);
  115070. - next = p->d_child.next;
  115071. + next = p->d_u.d_child.next;
  115072. p = parent;
  115073. if (next != &parent->d_subdirs)
  115074. break;
  115075. }
  115076. }
  115077. - ret = list_entry(next, struct dentry, d_child);
  115078. + ret = list_entry(next, struct dentry, d_u.d_child);
  115079. spin_lock_nested(&ret->d_lock, DENTRY_D_LOCK_NESTED);
  115080. /* Negative dentry - try next */
  115081. @@ -447,7 +447,7 @@
  115082. spin_lock(&sbi->lookup_lock);
  115083. spin_lock(&expired->d_parent->d_lock);
  115084. spin_lock_nested(&expired->d_lock, DENTRY_D_LOCK_NESTED);
  115085. - list_move(&expired->d_parent->d_subdirs, &expired->d_child);
  115086. + list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
  115087. spin_unlock(&expired->d_lock);
  115088. spin_unlock(&expired->d_parent->d_lock);
  115089. spin_unlock(&sbi->lookup_lock);
  115090. diff -Nur linux-3.12.38/fs/autofs4/root.c linux-rpi/fs/autofs4/root.c
  115091. --- linux-3.12.38/fs/autofs4/root.c 2015-02-16 16:15:42.000000000 +0100
  115092. +++ linux-rpi/fs/autofs4/root.c 2015-03-10 17:26:51.426216687 +0100
  115093. @@ -655,7 +655,7 @@
  115094. /* only consider parents below dentrys in the root */
  115095. if (IS_ROOT(parent->d_parent))
  115096. return;
  115097. - d_child = &dentry->d_child;
  115098. + d_child = &dentry->d_u.d_child;
  115099. /* Set parent managed if it's becoming empty */
  115100. if (d_child->next == &parent->d_subdirs &&
  115101. d_child->prev == &parent->d_subdirs)
  115102. diff -Nur linux-3.12.38/fs/ceph/addr.c linux-rpi/fs/ceph/addr.c
  115103. --- linux-3.12.38/fs/ceph/addr.c 2015-02-16 16:15:42.000000000 +0100
  115104. +++ linux-rpi/fs/ceph/addr.c 2015-03-10 17:26:51.446216687 +0100
  115105. @@ -672,7 +672,7 @@
  115106. int rc = 0;
  115107. unsigned wsize = 1 << inode->i_blkbits;
  115108. struct ceph_osd_request *req = NULL;
  115109. - int do_sync = 0;
  115110. + int do_sync;
  115111. u64 truncate_size, snap_size;
  115112. u32 truncate_seq;
  115113. diff -Nur linux-3.12.38/fs/ceph/dir.c linux-rpi/fs/ceph/dir.c
  115114. --- linux-3.12.38/fs/ceph/dir.c 2015-02-16 16:15:42.000000000 +0100
  115115. +++ linux-rpi/fs/ceph/dir.c 2015-03-10 17:26:51.446216687 +0100
  115116. @@ -103,7 +103,7 @@
  115117. /*
  115118. * When possible, we try to satisfy a readdir by peeking at the
  115119. * dcache. We make this work by carefully ordering dentries on
  115120. - * d_child when we initially get results back from the MDS, and
  115121. + * d_u.d_child when we initially get results back from the MDS, and
  115122. * falling back to a "normal" sync readdir if any dentries in the dir
  115123. * are dropped.
  115124. *
  115125. @@ -138,11 +138,11 @@
  115126. p = parent->d_subdirs.prev;
  115127. dout(" initial p %p/%p\n", p->prev, p->next);
  115128. } else {
  115129. - p = last->d_child.prev;
  115130. + p = last->d_u.d_child.prev;
  115131. }
  115132. more:
  115133. - dentry = list_entry(p, struct dentry, d_child);
  115134. + dentry = list_entry(p, struct dentry, d_u.d_child);
  115135. di = ceph_dentry(dentry);
  115136. while (1) {
  115137. dout(" p %p/%p %s d_subdirs %p/%p\n", p->prev, p->next,
  115138. @@ -164,7 +164,7 @@
  115139. !dentry->d_inode ? " null" : "");
  115140. spin_unlock(&dentry->d_lock);
  115141. p = p->prev;
  115142. - dentry = list_entry(p, struct dentry, d_child);
  115143. + dentry = list_entry(p, struct dentry, d_u.d_child);
  115144. di = ceph_dentry(dentry);
  115145. }
  115146. diff -Nur linux-3.12.38/fs/ceph/inode.c linux-rpi/fs/ceph/inode.c
  115147. --- linux-3.12.38/fs/ceph/inode.c 2015-02-16 16:15:42.000000000 +0100
  115148. +++ linux-rpi/fs/ceph/inode.c 2015-03-10 17:26:51.446216687 +0100
  115149. @@ -880,9 +880,9 @@
  115150. spin_lock(&dir->d_lock);
  115151. spin_lock_nested(&dn->d_lock, DENTRY_D_LOCK_NESTED);
  115152. - list_move(&dn->d_child, &dir->d_subdirs);
  115153. + list_move(&dn->d_u.d_child, &dir->d_subdirs);
  115154. dout("set_dentry_offset %p %lld (%p %p)\n", dn, di->offset,
  115155. - dn->d_child.prev, dn->d_child.next);
  115156. + dn->d_u.d_child.prev, dn->d_u.d_child.next);
  115157. spin_unlock(&dn->d_lock);
  115158. spin_unlock(&dir->d_lock);
  115159. }
  115160. @@ -1309,7 +1309,7 @@
  115161. /* reorder parent's d_subdirs */
  115162. spin_lock(&parent->d_lock);
  115163. spin_lock_nested(&dn->d_lock, DENTRY_D_LOCK_NESTED);
  115164. - list_move(&dn->d_child, &parent->d_subdirs);
  115165. + list_move(&dn->d_u.d_child, &parent->d_subdirs);
  115166. spin_unlock(&dn->d_lock);
  115167. spin_unlock(&parent->d_lock);
  115168. }
  115169. diff -Nur linux-3.12.38/fs/cifs/file.c linux-rpi/fs/cifs/file.c
  115170. --- linux-3.12.38/fs/cifs/file.c 2015-02-16 16:15:42.000000000 +0100
  115171. +++ linux-rpi/fs/cifs/file.c 2015-03-10 17:26:51.450216686 +0100
  115172. @@ -366,7 +366,6 @@
  115173. struct cifsLockInfo *li, *tmp;
  115174. struct cifs_fid fid;
  115175. struct cifs_pending_open open;
  115176. - bool oplock_break_cancelled;
  115177. spin_lock(&cifs_file_list_lock);
  115178. if (--cifs_file->count > 0) {
  115179. @@ -398,7 +397,7 @@
  115180. }
  115181. spin_unlock(&cifs_file_list_lock);
  115182. - oplock_break_cancelled = cancel_work_sync(&cifs_file->oplock_break);
  115183. + cancel_work_sync(&cifs_file->oplock_break);
  115184. if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
  115185. struct TCP_Server_Info *server = tcon->ses->server;
  115186. @@ -410,9 +409,6 @@
  115187. _free_xid(xid);
  115188. }
  115189. - if (oplock_break_cancelled)
  115190. - cifs_done_oplock_break(cifsi);
  115191. -
  115192. cifs_del_pending_open(&open);
  115193. /*
  115194. diff -Nur linux-3.12.38/fs/cifs/inode.c linux-rpi/fs/cifs/inode.c
  115195. --- linux-3.12.38/fs/cifs/inode.c 2015-02-16 16:15:42.000000000 +0100
  115196. +++ linux-rpi/fs/cifs/inode.c 2015-03-10 17:26:51.450216686 +0100
  115197. @@ -874,7 +874,7 @@
  115198. struct dentry *dentry;
  115199. spin_lock(&inode->i_lock);
  115200. - hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
  115201. + hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  115202. if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
  115203. spin_unlock(&inode->i_lock);
  115204. return true;
  115205. diff -Nur linux-3.12.38/fs/coda/cache.c linux-rpi/fs/coda/cache.c
  115206. --- linux-3.12.38/fs/coda/cache.c 2015-02-16 16:15:42.000000000 +0100
  115207. +++ linux-rpi/fs/coda/cache.c 2015-03-10 17:26:51.454216686 +0100
  115208. @@ -92,7 +92,7 @@
  115209. struct dentry *de;
  115210. spin_lock(&parent->d_lock);
  115211. - list_for_each_entry(de, &parent->d_subdirs, d_child) {
  115212. + list_for_each_entry(de, &parent->d_subdirs, d_u.d_child) {
  115213. /* don't know what to do with negative dentries */
  115214. if (de->d_inode )
  115215. coda_flag_inode(de->d_inode, flag);
  115216. diff -Nur linux-3.12.38/fs/dcache.c linux-rpi/fs/dcache.c
  115217. --- linux-3.12.38/fs/dcache.c 2015-02-16 16:15:42.000000000 +0100
  115218. +++ linux-rpi/fs/dcache.c 2015-03-10 17:26:51.458216686 +0100
  115219. @@ -44,7 +44,7 @@
  115220. /*
  115221. * Usage:
  115222. * dcache->d_inode->i_lock protects:
  115223. - * - i_dentry, d_u.d_alias, d_inode of aliases
  115224. + * - i_dentry, d_alias, d_inode of aliases
  115225. * dcache_hash_bucket lock protects:
  115226. * - the dcache hash table
  115227. * s_anon bl list spinlock protects:
  115228. @@ -59,7 +59,7 @@
  115229. * - d_unhashed()
  115230. * - d_parent and d_subdirs
  115231. * - childrens' d_child and d_parent
  115232. - * - d_u.d_alias, d_inode
  115233. + * - d_alias, d_inode
  115234. *
  115235. * Ordering:
  115236. * dentry->d_inode->i_lock
  115237. @@ -268,6 +268,7 @@
  115238. {
  115239. struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu);
  115240. + WARN_ON(!hlist_unhashed(&dentry->d_alias));
  115241. if (dname_external(dentry))
  115242. kfree(dentry->d_name.name);
  115243. kmem_cache_free(dentry_cache, dentry);
  115244. @@ -275,7 +276,6 @@
  115245. static void dentry_free(struct dentry *dentry)
  115246. {
  115247. - WARN_ON(!hlist_unhashed(&dentry->d_u.d_alias));
  115248. /* if dentry was never visible to RCU, immediate free is OK */
  115249. if (!(dentry->d_flags & DCACHE_RCUACCESS))
  115250. __d_free(&dentry->d_u.d_rcu);
  115251. @@ -309,7 +309,7 @@
  115252. struct inode *inode = dentry->d_inode;
  115253. if (inode) {
  115254. dentry->d_inode = NULL;
  115255. - hlist_del_init(&dentry->d_u.d_alias);
  115256. + hlist_del_init(&dentry->d_alias);
  115257. spin_unlock(&dentry->d_lock);
  115258. spin_unlock(&inode->i_lock);
  115259. if (!inode->i_nlink)
  115260. @@ -333,7 +333,7 @@
  115261. {
  115262. struct inode *inode = dentry->d_inode;
  115263. dentry->d_inode = NULL;
  115264. - hlist_del_init(&dentry->d_u.d_alias);
  115265. + hlist_del_init(&dentry->d_alias);
  115266. dentry_rcuwalk_barrier(dentry);
  115267. spin_unlock(&dentry->d_lock);
  115268. spin_unlock(&inode->i_lock);
  115269. @@ -488,7 +488,7 @@
  115270. }
  115271. /* if it was on the hash then remove it */
  115272. __d_drop(dentry);
  115273. - __list_del_entry(&dentry->d_child);
  115274. + list_del(&dentry->d_u.d_child);
  115275. /*
  115276. * Inform d_walk() that we are no longer attached to the
  115277. * dentry tree
  115278. @@ -772,7 +772,7 @@
  115279. again:
  115280. discon_alias = NULL;
  115281. - hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
  115282. + hlist_for_each_entry(alias, &inode->i_dentry, d_alias) {
  115283. spin_lock(&alias->d_lock);
  115284. if (S_ISDIR(inode->i_mode) || !d_unhashed(alias)) {
  115285. if (IS_ROOT(alias) &&
  115286. @@ -825,7 +825,7 @@
  115287. struct dentry *dentry;
  115288. restart:
  115289. spin_lock(&inode->i_lock);
  115290. - hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
  115291. + hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  115292. spin_lock(&dentry->d_lock);
  115293. if (!dentry->d_lockref.count) {
  115294. /*
  115295. @@ -1110,7 +1110,7 @@
  115296. resume:
  115297. while (next != &this_parent->d_subdirs) {
  115298. struct list_head *tmp = next;
  115299. - struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
  115300. + struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child);
  115301. next = tmp->next;
  115302. spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
  115303. @@ -1142,31 +1142,33 @@
  115304. /*
  115305. * All done at this level ... ascend and resume the search.
  115306. */
  115307. - rcu_read_lock();
  115308. -ascend:
  115309. if (this_parent != parent) {
  115310. struct dentry *child = this_parent;
  115311. this_parent = child->d_parent;
  115312. + rcu_read_lock();
  115313. spin_unlock(&child->d_lock);
  115314. spin_lock(&this_parent->d_lock);
  115315. - /* might go back up the wrong parent if we have had a rename. */
  115316. - if (need_seqretry(&rename_lock, seq))
  115317. + /*
  115318. + * might go back up the wrong parent if we have had a rename
  115319. + * or deletion
  115320. + */
  115321. + if (this_parent != child->d_parent ||
  115322. + (child->d_flags & DCACHE_DENTRY_KILLED) ||
  115323. + need_seqretry(&rename_lock, seq)) {
  115324. + spin_unlock(&this_parent->d_lock);
  115325. + rcu_read_unlock();
  115326. goto rename_retry;
  115327. - next = child->d_child.next;
  115328. - while (unlikely(child->d_flags & DCACHE_DENTRY_KILLED)) {
  115329. - if (next == &this_parent->d_subdirs)
  115330. - goto ascend;
  115331. - child = list_entry(next, struct dentry, d_child);
  115332. - next = next->next;
  115333. }
  115334. rcu_read_unlock();
  115335. + next = child->d_u.d_child.next;
  115336. goto resume;
  115337. }
  115338. - if (need_seqretry(&rename_lock, seq))
  115339. + if (need_seqretry(&rename_lock, seq)) {
  115340. + spin_unlock(&this_parent->d_lock);
  115341. goto rename_retry;
  115342. - rcu_read_unlock();
  115343. + }
  115344. if (finish)
  115345. finish(data);
  115346. @@ -1176,9 +1178,6 @@
  115347. return;
  115348. rename_retry:
  115349. - spin_unlock(&this_parent->d_lock);
  115350. - rcu_read_unlock();
  115351. - BUG_ON(seq & 1);
  115352. if (!retry)
  115353. return;
  115354. seq = 1;
  115355. @@ -1498,8 +1497,8 @@
  115356. INIT_HLIST_BL_NODE(&dentry->d_hash);
  115357. INIT_LIST_HEAD(&dentry->d_lru);
  115358. INIT_LIST_HEAD(&dentry->d_subdirs);
  115359. - INIT_HLIST_NODE(&dentry->d_u.d_alias);
  115360. - INIT_LIST_HEAD(&dentry->d_child);
  115361. + INIT_HLIST_NODE(&dentry->d_alias);
  115362. + INIT_LIST_HEAD(&dentry->d_u.d_child);
  115363. d_set_d_op(dentry, dentry->d_sb->s_d_op);
  115364. this_cpu_inc(nr_dentry);
  115365. @@ -1529,7 +1528,7 @@
  115366. */
  115367. __dget_dlock(parent);
  115368. dentry->d_parent = parent;
  115369. - list_add(&dentry->d_child, &parent->d_subdirs);
  115370. + list_add(&dentry->d_u.d_child, &parent->d_subdirs);
  115371. spin_unlock(&parent->d_lock);
  115372. return dentry;
  115373. @@ -1589,7 +1588,7 @@
  115374. if (inode) {
  115375. if (unlikely(IS_AUTOMOUNT(inode)))
  115376. dentry->d_flags |= DCACHE_NEED_AUTOMOUNT;
  115377. - hlist_add_head(&dentry->d_u.d_alias, &inode->i_dentry);
  115378. + hlist_add_head(&dentry->d_alias, &inode->i_dentry);
  115379. }
  115380. dentry->d_inode = inode;
  115381. dentry_rcuwalk_barrier(dentry);
  115382. @@ -1614,7 +1613,7 @@
  115383. void d_instantiate(struct dentry *entry, struct inode * inode)
  115384. {
  115385. - BUG_ON(!hlist_unhashed(&entry->d_u.d_alias));
  115386. + BUG_ON(!hlist_unhashed(&entry->d_alias));
  115387. if (inode)
  115388. spin_lock(&inode->i_lock);
  115389. __d_instantiate(entry, inode);
  115390. @@ -1653,7 +1652,7 @@
  115391. return NULL;
  115392. }
  115393. - hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
  115394. + hlist_for_each_entry(alias, &inode->i_dentry, d_alias) {
  115395. /*
  115396. * Don't need alias->d_lock here, because aliases with
  115397. * d_parent == entry->d_parent are not subject to name or
  115398. @@ -1679,7 +1678,7 @@
  115399. {
  115400. struct dentry *result;
  115401. - BUG_ON(!hlist_unhashed(&entry->d_u.d_alias));
  115402. + BUG_ON(!hlist_unhashed(&entry->d_alias));
  115403. if (inode)
  115404. spin_lock(&inode->i_lock);
  115405. @@ -1722,7 +1721,7 @@
  115406. if (hlist_empty(&inode->i_dentry))
  115407. return NULL;
  115408. - alias = hlist_entry(inode->i_dentry.first, struct dentry, d_u.d_alias);
  115409. + alias = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
  115410. __dget(alias);
  115411. return alias;
  115412. }
  115413. @@ -1796,7 +1795,7 @@
  115414. spin_lock(&tmp->d_lock);
  115415. tmp->d_inode = inode;
  115416. tmp->d_flags |= DCACHE_DISCONNECTED;
  115417. - hlist_add_head(&tmp->d_u.d_alias, &inode->i_dentry);
  115418. + hlist_add_head(&tmp->d_alias, &inode->i_dentry);
  115419. hlist_bl_lock(&tmp->d_sb->s_anon);
  115420. hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon);
  115421. hlist_bl_unlock(&tmp->d_sb->s_anon);
  115422. @@ -2239,7 +2238,7 @@
  115423. struct dentry *child;
  115424. spin_lock(&dparent->d_lock);
  115425. - list_for_each_entry(child, &dparent->d_subdirs, d_child) {
  115426. + list_for_each_entry(child, &dparent->d_subdirs, d_u.d_child) {
  115427. if (dentry == child) {
  115428. spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
  115429. __dget_dlock(dentry);
  115430. @@ -2486,8 +2485,8 @@
  115431. /* Unhash the target: dput() will then get rid of it */
  115432. __d_drop(target);
  115433. - list_del(&dentry->d_child);
  115434. - list_del(&target->d_child);
  115435. + list_del(&dentry->d_u.d_child);
  115436. + list_del(&target->d_u.d_child);
  115437. /* Switch the names.. */
  115438. switch_names(dentry, target);
  115439. @@ -2497,15 +2496,15 @@
  115440. if (IS_ROOT(dentry)) {
  115441. dentry->d_parent = target->d_parent;
  115442. target->d_parent = target;
  115443. - INIT_LIST_HEAD(&target->d_child);
  115444. + INIT_LIST_HEAD(&target->d_u.d_child);
  115445. } else {
  115446. swap(dentry->d_parent, target->d_parent);
  115447. /* And add them back to the (new) parent lists */
  115448. - list_add(&target->d_child, &target->d_parent->d_subdirs);
  115449. + list_add(&target->d_u.d_child, &target->d_parent->d_subdirs);
  115450. }
  115451. - list_add(&dentry->d_child, &dentry->d_parent->d_subdirs);
  115452. + list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs);
  115453. write_seqcount_end(&target->d_seq);
  115454. write_seqcount_end(&dentry->d_seq);
  115455. @@ -2612,9 +2611,9 @@
  115456. swap(dentry->d_name.hash, anon->d_name.hash);
  115457. dentry->d_parent = dentry;
  115458. - list_del_init(&dentry->d_child);
  115459. + list_del_init(&dentry->d_u.d_child);
  115460. anon->d_parent = dparent;
  115461. - list_move(&anon->d_child, &dparent->d_subdirs);
  115462. + list_move(&anon->d_u.d_child, &dparent->d_subdirs);
  115463. write_seqcount_end(&dentry->d_seq);
  115464. write_seqcount_end(&anon->d_seq);
  115465. @@ -3242,7 +3241,7 @@
  115466. {
  115467. inode_dec_link_count(inode);
  115468. BUG_ON(dentry->d_name.name != dentry->d_iname ||
  115469. - !hlist_unhashed(&dentry->d_u.d_alias) ||
  115470. + !hlist_unhashed(&dentry->d_alias) ||
  115471. !d_unlinked(dentry));
  115472. spin_lock(&dentry->d_parent->d_lock);
  115473. spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
  115474. diff -Nur linux-3.12.38/fs/debugfs/inode.c linux-rpi/fs/debugfs/inode.c
  115475. --- linux-3.12.38/fs/debugfs/inode.c 2015-02-16 16:15:42.000000000 +0100
  115476. +++ linux-rpi/fs/debugfs/inode.c 2015-03-10 17:26:51.458216686 +0100
  115477. @@ -549,10 +549,10 @@
  115478. /*
  115479. * The parent->d_subdirs is protected by the d_lock. Outside that
  115480. * lock, the child can be unlinked and set to be freed which can
  115481. - * use the d_child as the rcu head and corrupt this list.
  115482. + * use the d_u.d_child as the rcu head and corrupt this list.
  115483. */
  115484. spin_lock(&parent->d_lock);
  115485. - list_for_each_entry(child, &parent->d_subdirs, d_child) {
  115486. + list_for_each_entry(child, &parent->d_subdirs, d_u.d_child) {
  115487. if (!debugfs_positive(child))
  115488. continue;
  115489. diff -Nur linux-3.12.38/fs/exportfs/expfs.c linux-rpi/fs/exportfs/expfs.c
  115490. --- linux-3.12.38/fs/exportfs/expfs.c 2015-02-16 16:15:42.000000000 +0100
  115491. +++ linux-rpi/fs/exportfs/expfs.c 2015-03-10 17:26:51.462216686 +0100
  115492. @@ -50,7 +50,7 @@
  115493. inode = result->d_inode;
  115494. spin_lock(&inode->i_lock);
  115495. - hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
  115496. + hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  115497. dget(dentry);
  115498. spin_unlock(&inode->i_lock);
  115499. if (toput)
  115500. diff -Nur linux-3.12.38/fs/ext4/file.c linux-rpi/fs/ext4/file.c
  115501. --- linux-3.12.38/fs/ext4/file.c 2015-02-16 16:15:42.000000000 +0100
  115502. +++ linux-rpi/fs/ext4/file.c 2015-03-10 17:26:51.470216686 +0100
  115503. @@ -100,7 +100,7 @@
  115504. struct blk_plug plug;
  115505. int unaligned_aio = 0;
  115506. ssize_t ret;
  115507. - int *overwrite = iocb->private;
  115508. + int overwrite = 0;
  115509. size_t length = iov_length(iov, nr_segs);
  115510. if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
  115511. @@ -118,6 +118,8 @@
  115512. mutex_lock(&inode->i_mutex);
  115513. blk_start_plug(&plug);
  115514. + iocb->private = &overwrite;
  115515. +
  115516. /* check whether we do a DIO overwrite or not */
  115517. if (ext4_should_dioread_nolock(inode) && !unaligned_aio &&
  115518. !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
  115519. @@ -141,7 +143,7 @@
  115520. * So we should check these two conditions.
  115521. */
  115522. if (err == len && (map.m_flags & EXT4_MAP_MAPPED))
  115523. - *overwrite = 1;
  115524. + overwrite = 1;
  115525. }
  115526. ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
  115527. @@ -168,7 +170,6 @@
  115528. {
  115529. struct inode *inode = file_inode(iocb->ki_filp);
  115530. ssize_t ret;
  115531. - int overwrite = 0;
  115532. /*
  115533. * If we have encountered a bitmap-format file, the size limit
  115534. @@ -189,7 +190,6 @@
  115535. }
  115536. }
  115537. - iocb->private = &overwrite;
  115538. if (unlikely(iocb->ki_filp->f_flags & O_DIRECT))
  115539. ret = ext4_file_dio_write(iocb, iov, nr_segs, pos);
  115540. else
  115541. diff -Nur linux-3.12.38/fs/fs-writeback.c linux-rpi/fs/fs-writeback.c
  115542. --- linux-3.12.38/fs/fs-writeback.c 2015-02-16 16:15:42.000000000 +0100
  115543. +++ linux-rpi/fs/fs-writeback.c 2015-03-10 17:26:51.478216686 +0100
  115544. @@ -475,28 +475,12 @@
  115545. * write_inode()
  115546. */
  115547. spin_lock(&inode->i_lock);
  115548. -
  115549. + /* Clear I_DIRTY_PAGES if we've written out all dirty pages */
  115550. + if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
  115551. + inode->i_state &= ~I_DIRTY_PAGES;
  115552. dirty = inode->i_state & I_DIRTY;
  115553. - inode->i_state &= ~I_DIRTY;
  115554. -
  115555. - /*
  115556. - * Paired with smp_mb() in __mark_inode_dirty(). This allows
  115557. - * __mark_inode_dirty() to test i_state without grabbing i_lock -
  115558. - * either they see the I_DIRTY bits cleared or we see the dirtied
  115559. - * inode.
  115560. - *
  115561. - * I_DIRTY_PAGES is always cleared together above even if @mapping
  115562. - * still has dirty pages. The flag is reinstated after smp_mb() if
  115563. - * necessary. This guarantees that either __mark_inode_dirty()
  115564. - * sees clear I_DIRTY_PAGES or we see PAGECACHE_TAG_DIRTY.
  115565. - */
  115566. - smp_mb();
  115567. -
  115568. - if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
  115569. - inode->i_state |= I_DIRTY_PAGES;
  115570. -
  115571. + inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
  115572. spin_unlock(&inode->i_lock);
  115573. -
  115574. /* Don't write the inode if only I_DIRTY_PAGES was set */
  115575. if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
  115576. int err = write_inode(inode, wbc);
  115577. @@ -1160,11 +1144,12 @@
  115578. }
  115579. /*
  115580. - * Paired with smp_mb() in __writeback_single_inode() for the
  115581. - * following lockless i_state test. See there for details.
  115582. + * make sure that changes are seen by all cpus before we test i_state
  115583. + * -- mikulas
  115584. */
  115585. smp_mb();
  115586. + /* avoid the locking if we can */
  115587. if ((inode->i_state & flags) == flags)
  115588. return;
  115589. diff -Nur linux-3.12.38/fs/libfs.c linux-rpi/fs/libfs.c
  115590. --- linux-3.12.38/fs/libfs.c 2015-02-16 16:15:42.000000000 +0100
  115591. +++ linux-rpi/fs/libfs.c 2015-03-10 17:26:51.498216686 +0100
  115592. @@ -105,18 +105,18 @@
  115593. spin_lock(&dentry->d_lock);
  115594. /* d_lock not required for cursor */
  115595. - list_del(&cursor->d_child);
  115596. + list_del(&cursor->d_u.d_child);
  115597. p = dentry->d_subdirs.next;
  115598. while (n && p != &dentry->d_subdirs) {
  115599. struct dentry *next;
  115600. - next = list_entry(p, struct dentry, d_child);
  115601. + next = list_entry(p, struct dentry, d_u.d_child);
  115602. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  115603. if (simple_positive(next))
  115604. n--;
  115605. spin_unlock(&next->d_lock);
  115606. p = p->next;
  115607. }
  115608. - list_add_tail(&cursor->d_child, p);
  115609. + list_add_tail(&cursor->d_u.d_child, p);
  115610. spin_unlock(&dentry->d_lock);
  115611. }
  115612. }
  115613. @@ -140,7 +140,7 @@
  115614. {
  115615. struct dentry *dentry = file->f_path.dentry;
  115616. struct dentry *cursor = file->private_data;
  115617. - struct list_head *p, *q = &cursor->d_child;
  115618. + struct list_head *p, *q = &cursor->d_u.d_child;
  115619. if (!dir_emit_dots(file, ctx))
  115620. return 0;
  115621. @@ -149,7 +149,7 @@
  115622. list_move(q, &dentry->d_subdirs);
  115623. for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
  115624. - struct dentry *next = list_entry(p, struct dentry, d_child);
  115625. + struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
  115626. spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
  115627. if (!simple_positive(next)) {
  115628. spin_unlock(&next->d_lock);
  115629. @@ -270,7 +270,7 @@
  115630. int ret = 0;
  115631. spin_lock(&dentry->d_lock);
  115632. - list_for_each_entry(child, &dentry->d_subdirs, d_child) {
  115633. + list_for_each_entry(child, &dentry->d_subdirs, d_u.d_child) {
  115634. spin_lock_nested(&child->d_lock, DENTRY_D_LOCK_NESTED);
  115635. if (simple_positive(child)) {
  115636. spin_unlock(&child->d_lock);
  115637. diff -Nur linux-3.12.38/fs/lockd/svc.c linux-rpi/fs/lockd/svc.c
  115638. --- linux-3.12.38/fs/lockd/svc.c 2015-02-16 16:15:42.000000000 +0100
  115639. +++ linux-rpi/fs/lockd/svc.c 2015-03-10 17:26:51.498216686 +0100
  115640. @@ -137,6 +137,10 @@
  115641. dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n");
  115642. + if (!nlm_timeout)
  115643. + nlm_timeout = LOCKD_DFLT_TIMEO;
  115644. + nlmsvc_timeout = nlm_timeout * HZ;
  115645. +
  115646. /*
  115647. * The main request loop. We don't terminate until the last
  115648. * NFS mount or NFS daemon has gone away.
  115649. @@ -342,10 +346,6 @@
  115650. printk(KERN_WARNING
  115651. "lockd_up: no pid, %d users??\n", nlmsvc_users);
  115652. - if (!nlm_timeout)
  115653. - nlm_timeout = LOCKD_DFLT_TIMEO;
  115654. - nlmsvc_timeout = nlm_timeout * HZ;
  115655. -
  115656. serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL);
  115657. if (!serv) {
  115658. printk(KERN_WARNING "lockd_up: create service failed\n");
  115659. diff -Nur linux-3.12.38/fs/ncpfs/dir.c linux-rpi/fs/ncpfs/dir.c
  115660. --- linux-3.12.38/fs/ncpfs/dir.c 2015-02-16 16:15:42.000000000 +0100
  115661. +++ linux-rpi/fs/ncpfs/dir.c 2015-03-10 17:26:51.498216686 +0100
  115662. @@ -407,7 +407,7 @@
  115663. spin_lock(&parent->d_lock);
  115664. next = parent->d_subdirs.next;
  115665. while (next != &parent->d_subdirs) {
  115666. - dent = list_entry(next, struct dentry, d_child);
  115667. + dent = list_entry(next, struct dentry, d_u.d_child);
  115668. if ((unsigned long)dent->d_fsdata == fpos) {
  115669. if (dent->d_inode)
  115670. dget(dent);
  115671. diff -Nur linux-3.12.38/fs/ncpfs/ncplib_kernel.h linux-rpi/fs/ncpfs/ncplib_kernel.h
  115672. --- linux-3.12.38/fs/ncpfs/ncplib_kernel.h 2015-02-16 16:15:42.000000000 +0100
  115673. +++ linux-rpi/fs/ncpfs/ncplib_kernel.h 2015-03-10 17:26:51.502216686 +0100
  115674. @@ -194,7 +194,7 @@
  115675. spin_lock(&parent->d_lock);
  115676. next = parent->d_subdirs.next;
  115677. while (next != &parent->d_subdirs) {
  115678. - dentry = list_entry(next, struct dentry, d_child);
  115679. + dentry = list_entry(next, struct dentry, d_u.d_child);
  115680. if (dentry->d_fsdata == NULL)
  115681. ncp_age_dentry(server, dentry);
  115682. @@ -216,7 +216,7 @@
  115683. spin_lock(&parent->d_lock);
  115684. next = parent->d_subdirs.next;
  115685. while (next != &parent->d_subdirs) {
  115686. - dentry = list_entry(next, struct dentry, d_child);
  115687. + dentry = list_entry(next, struct dentry, d_u.d_child);
  115688. dentry->d_fsdata = NULL;
  115689. ncp_age_dentry(server, dentry);
  115690. next = next->next;
  115691. diff -Nur linux-3.12.38/fs/nfs/direct.c linux-rpi/fs/nfs/direct.c
  115692. --- linux-3.12.38/fs/nfs/direct.c 2015-02-16 16:15:42.000000000 +0100
  115693. +++ linux-rpi/fs/nfs/direct.c 2015-03-10 17:26:51.502216686 +0100
  115694. @@ -123,12 +123,6 @@
  115695. */
  115696. ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs)
  115697. {
  115698. - struct inode *inode = iocb->ki_filp->f_mapping->host;
  115699. -
  115700. - /* we only support swap file calling nfs_direct_IO */
  115701. - if (!IS_SWAPFILE(inode))
  115702. - return 0;
  115703. -
  115704. #ifndef CONFIG_NFS_SWAP
  115705. dprintk("NFS: nfs_direct_IO (%s) off/no(%Ld/%lu) EINVAL\n",
  115706. iocb->ki_filp->f_path.dentry->d_name.name,
  115707. diff -Nur linux-3.12.38/fs/nfs/getroot.c linux-rpi/fs/nfs/getroot.c
  115708. --- linux-3.12.38/fs/nfs/getroot.c 2015-02-16 16:15:42.000000000 +0100
  115709. +++ linux-rpi/fs/nfs/getroot.c 2015-03-10 17:26:51.502216686 +0100
  115710. @@ -58,7 +58,7 @@
  115711. */
  115712. spin_lock(&sb->s_root->d_inode->i_lock);
  115713. spin_lock(&sb->s_root->d_lock);
  115714. - hlist_del_init(&sb->s_root->d_u.d_alias);
  115715. + hlist_del_init(&sb->s_root->d_alias);
  115716. spin_unlock(&sb->s_root->d_lock);
  115717. spin_unlock(&sb->s_root->d_inode->i_lock);
  115718. }
  115719. diff -Nur linux-3.12.38/fs/nfs/nfs4client.c linux-rpi/fs/nfs/nfs4client.c
  115720. --- linux-3.12.38/fs/nfs/nfs4client.c 2015-02-16 16:15:42.000000000 +0100
  115721. +++ linux-rpi/fs/nfs/nfs4client.c 2015-03-10 17:26:51.506216686 +0100
  115722. @@ -561,14 +561,20 @@
  115723. }
  115724. /*
  115725. - * Returns true if the server major ids match
  115726. + * Returns true if the server owners match
  115727. */
  115728. static bool
  115729. -nfs4_check_clientid_trunking(struct nfs_client *a, struct nfs_client *b)
  115730. +nfs4_match_serverowners(struct nfs_client *a, struct nfs_client *b)
  115731. {
  115732. struct nfs41_server_owner *o1 = a->cl_serverowner;
  115733. struct nfs41_server_owner *o2 = b->cl_serverowner;
  115734. + if (o1->minor_id != o2->minor_id) {
  115735. + dprintk("NFS: --> %s server owner minor IDs do not match\n",
  115736. + __func__);
  115737. + return false;
  115738. + }
  115739. +
  115740. if (o1->major_id_sz != o2->major_id_sz)
  115741. goto out_major_mismatch;
  115742. if (memcmp(o1->major_id, o2->major_id, o1->major_id_sz) != 0)
  115743. @@ -629,7 +635,7 @@
  115744. prev = pos;
  115745. status = nfs_wait_client_init_complete(pos);
  115746. - if (pos->cl_cons_state == NFS_CS_SESSION_INITING) {
  115747. + if (status == 0) {
  115748. nfs4_schedule_lease_recovery(pos);
  115749. status = nfs4_wait_clnt_recover(pos);
  115750. }
  115751. @@ -644,12 +650,7 @@
  115752. if (!nfs4_match_clientids(pos, new))
  115753. continue;
  115754. - /*
  115755. - * Note that session trunking is just a special subcase of
  115756. - * client id trunking. In either case, we want to fall back
  115757. - * to using the existing nfs_client.
  115758. - */
  115759. - if (!nfs4_check_clientid_trunking(pos, new))
  115760. + if (!nfs4_match_serverowners(pos, new))
  115761. continue;
  115762. atomic_inc(&pos->cl_count);
  115763. diff -Nur linux-3.12.38/fs/nfsd/nfs4state.c linux-rpi/fs/nfsd/nfs4state.c
  115764. --- linux-3.12.38/fs/nfsd/nfs4state.c 2015-02-16 16:15:42.000000000 +0100
  115765. +++ linux-rpi/fs/nfsd/nfs4state.c 2015-03-10 17:26:51.514216686 +0100
  115766. @@ -1197,14 +1197,15 @@
  115767. return 0;
  115768. }
  115769. -static int
  115770. +static long long
  115771. compare_blob(const struct xdr_netobj *o1, const struct xdr_netobj *o2)
  115772. {
  115773. - if (o1->len < o2->len)
  115774. - return -1;
  115775. - if (o1->len > o2->len)
  115776. - return 1;
  115777. - return memcmp(o1->data, o2->data, o1->len);
  115778. + long long res;
  115779. +
  115780. + res = o1->len - o2->len;
  115781. + if (res)
  115782. + return res;
  115783. + return (long long)memcmp(o1->data, o2->data, o1->len);
  115784. }
  115785. static int same_name(const char *n1, const char *n2)
  115786. @@ -1388,7 +1389,7 @@
  115787. static struct nfs4_client *
  115788. find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root)
  115789. {
  115790. - int cmp;
  115791. + long long cmp;
  115792. struct rb_node *node = root->rb_node;
  115793. struct nfs4_client *clp;
  115794. diff -Nur linux-3.12.38/fs/nfsd/nfs4xdr.c linux-rpi/fs/nfsd/nfs4xdr.c
  115795. --- linux-3.12.38/fs/nfsd/nfs4xdr.c 2015-02-16 16:15:42.000000000 +0100
  115796. +++ linux-rpi/fs/nfsd/nfs4xdr.c 2015-03-10 17:26:51.514216686 +0100
  115797. @@ -1786,9 +1786,6 @@
  115798. }
  115799. else
  115800. end++;
  115801. - if (found_esc)
  115802. - end = next;
  115803. -
  115804. str = end;
  115805. }
  115806. *pp = p;
  115807. diff -Nur linux-3.12.38/fs/nilfs2/inode.c linux-rpi/fs/nilfs2/inode.c
  115808. --- linux-3.12.38/fs/nilfs2/inode.c 2015-02-16 16:15:42.000000000 +0100
  115809. +++ linux-rpi/fs/nilfs2/inode.c 2015-03-10 17:26:51.514216686 +0100
  115810. @@ -49,8 +49,6 @@
  115811. int for_gc;
  115812. };
  115813. -static int nilfs_iget_test(struct inode *inode, void *opaque);
  115814. -
  115815. void nilfs_inode_add_blocks(struct inode *inode, int n)
  115816. {
  115817. struct nilfs_root *root = NILFS_I(inode)->i_root;
  115818. @@ -349,17 +347,6 @@
  115819. .is_partially_uptodate = block_is_partially_uptodate,
  115820. };
  115821. -static int nilfs_insert_inode_locked(struct inode *inode,
  115822. - struct nilfs_root *root,
  115823. - unsigned long ino)
  115824. -{
  115825. - struct nilfs_iget_args args = {
  115826. - .ino = ino, .root = root, .cno = 0, .for_gc = 0
  115827. - };
  115828. -
  115829. - return insert_inode_locked4(inode, ino, nilfs_iget_test, &args);
  115830. -}
  115831. -
  115832. struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)
  115833. {
  115834. struct super_block *sb = dir->i_sb;
  115835. @@ -395,7 +382,7 @@
  115836. if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
  115837. err = nilfs_bmap_read(ii->i_bmap, NULL);
  115838. if (err < 0)
  115839. - goto failed_after_creation;
  115840. + goto failed_bmap;
  115841. set_bit(NILFS_I_BMAP, &ii->i_state);
  115842. /* No lock is needed; iget() ensures it. */
  115843. @@ -411,24 +398,21 @@
  115844. spin_lock(&nilfs->ns_next_gen_lock);
  115845. inode->i_generation = nilfs->ns_next_generation++;
  115846. spin_unlock(&nilfs->ns_next_gen_lock);
  115847. - if (nilfs_insert_inode_locked(inode, root, ino) < 0) {
  115848. - err = -EIO;
  115849. - goto failed_after_creation;
  115850. - }
  115851. + insert_inode_hash(inode);
  115852. err = nilfs_init_acl(inode, dir);
  115853. if (unlikely(err))
  115854. - goto failed_after_creation; /* never occur. When supporting
  115855. + goto failed_acl; /* never occur. When supporting
  115856. nilfs_init_acl(), proper cancellation of
  115857. above jobs should be considered */
  115858. return inode;
  115859. - failed_after_creation:
  115860. + failed_acl:
  115861. + failed_bmap:
  115862. clear_nlink(inode);
  115863. - unlock_new_inode(inode);
  115864. iput(inode); /* raw_inode will be deleted through
  115865. - nilfs_evict_inode() */
  115866. + generic_delete_inode() */
  115867. goto failed;
  115868. failed_ifile_create_inode:
  115869. @@ -476,8 +460,8 @@
  115870. inode->i_atime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec);
  115871. inode->i_ctime.tv_nsec = le32_to_cpu(raw_inode->i_ctime_nsec);
  115872. inode->i_mtime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec);
  115873. - if (inode->i_nlink == 0)
  115874. - return -ESTALE; /* this inode is deleted */
  115875. + if (inode->i_nlink == 0 && inode->i_mode == 0)
  115876. + return -EINVAL; /* this inode is deleted */
  115877. inode->i_blocks = le64_to_cpu(raw_inode->i_blocks);
  115878. ii->i_flags = le32_to_cpu(raw_inode->i_flags);
  115879. diff -Nur linux-3.12.38/fs/nilfs2/namei.c linux-rpi/fs/nilfs2/namei.c
  115880. --- linux-3.12.38/fs/nilfs2/namei.c 2015-02-16 16:15:42.000000000 +0100
  115881. +++ linux-rpi/fs/nilfs2/namei.c 2015-03-10 17:26:51.514216686 +0100
  115882. @@ -51,11 +51,9 @@
  115883. int err = nilfs_add_link(dentry, inode);
  115884. if (!err) {
  115885. d_instantiate(dentry, inode);
  115886. - unlock_new_inode(inode);
  115887. return 0;
  115888. }
  115889. inode_dec_link_count(inode);
  115890. - unlock_new_inode(inode);
  115891. iput(inode);
  115892. return err;
  115893. }
  115894. @@ -184,7 +182,6 @@
  115895. out_fail:
  115896. drop_nlink(inode);
  115897. nilfs_mark_inode_dirty(inode);
  115898. - unlock_new_inode(inode);
  115899. iput(inode);
  115900. goto out;
  115901. }
  115902. @@ -204,15 +201,11 @@
  115903. inode_inc_link_count(inode);
  115904. ihold(inode);
  115905. - err = nilfs_add_link(dentry, inode);
  115906. - if (!err) {
  115907. - d_instantiate(dentry, inode);
  115908. + err = nilfs_add_nondir(dentry, inode);
  115909. + if (!err)
  115910. err = nilfs_transaction_commit(dir->i_sb);
  115911. - } else {
  115912. - inode_dec_link_count(inode);
  115913. - iput(inode);
  115914. + else
  115915. nilfs_transaction_abort(dir->i_sb);
  115916. - }
  115917. return err;
  115918. }
  115919. @@ -250,7 +243,6 @@
  115920. nilfs_mark_inode_dirty(inode);
  115921. d_instantiate(dentry, inode);
  115922. - unlock_new_inode(inode);
  115923. out:
  115924. if (!err)
  115925. err = nilfs_transaction_commit(dir->i_sb);
  115926. @@ -263,7 +255,6 @@
  115927. drop_nlink(inode);
  115928. drop_nlink(inode);
  115929. nilfs_mark_inode_dirty(inode);
  115930. - unlock_new_inode(inode);
  115931. iput(inode);
  115932. out_dir:
  115933. drop_nlink(dir);
  115934. diff -Nur linux-3.12.38/fs/nilfs2/nilfs.h linux-rpi/fs/nilfs2/nilfs.h
  115935. --- linux-3.12.38/fs/nilfs2/nilfs.h 2015-02-16 16:15:42.000000000 +0100
  115936. +++ linux-rpi/fs/nilfs2/nilfs.h 2015-03-10 17:26:51.514216686 +0100
  115937. @@ -141,6 +141,7 @@
  115938. * @ti_save: Backup of journal_info field of task_struct
  115939. * @ti_flags: Flags
  115940. * @ti_count: Nest level
  115941. + * @ti_garbage: List of inode to be put when releasing semaphore
  115942. */
  115943. struct nilfs_transaction_info {
  115944. u32 ti_magic;
  115945. @@ -149,6 +150,7 @@
  115946. one of other filesystems has a bug. */
  115947. unsigned short ti_flags;
  115948. unsigned short ti_count;
  115949. + struct list_head ti_garbage;
  115950. };
  115951. /* ti_magic */
  115952. diff -Nur linux-3.12.38/fs/nilfs2/segment.c linux-rpi/fs/nilfs2/segment.c
  115953. --- linux-3.12.38/fs/nilfs2/segment.c 2015-02-16 16:15:42.000000000 +0100
  115954. +++ linux-rpi/fs/nilfs2/segment.c 2015-03-10 17:26:51.514216686 +0100
  115955. @@ -305,6 +305,7 @@
  115956. ti->ti_count = 0;
  115957. ti->ti_save = cur_ti;
  115958. ti->ti_magic = NILFS_TI_MAGIC;
  115959. + INIT_LIST_HEAD(&ti->ti_garbage);
  115960. current->journal_info = ti;
  115961. for (;;) {
  115962. @@ -331,6 +332,8 @@
  115963. up_write(&nilfs->ns_segctor_sem);
  115964. current->journal_info = ti->ti_save;
  115965. + if (!list_empty(&ti->ti_garbage))
  115966. + nilfs_dispose_list(nilfs, &ti->ti_garbage, 0);
  115967. }
  115968. static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci,
  115969. @@ -743,15 +746,6 @@
  115970. }
  115971. }
  115972. -static void nilfs_iput_work_func(struct work_struct *work)
  115973. -{
  115974. - struct nilfs_sc_info *sci = container_of(work, struct nilfs_sc_info,
  115975. - sc_iput_work);
  115976. - struct the_nilfs *nilfs = sci->sc_super->s_fs_info;
  115977. -
  115978. - nilfs_dispose_list(nilfs, &sci->sc_iput_queue, 0);
  115979. -}
  115980. -
  115981. static int nilfs_test_metadata_dirty(struct the_nilfs *nilfs,
  115982. struct nilfs_root *root)
  115983. {
  115984. @@ -1906,8 +1900,8 @@
  115985. static void nilfs_segctor_drop_written_files(struct nilfs_sc_info *sci,
  115986. struct the_nilfs *nilfs)
  115987. {
  115988. + struct nilfs_transaction_info *ti = current->journal_info;
  115989. struct nilfs_inode_info *ii, *n;
  115990. - int defer_iput = false;
  115991. spin_lock(&nilfs->ns_inode_lock);
  115992. list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) {
  115993. @@ -1918,24 +1912,9 @@
  115994. clear_bit(NILFS_I_BUSY, &ii->i_state);
  115995. brelse(ii->i_bh);
  115996. ii->i_bh = NULL;
  115997. - list_del_init(&ii->i_dirty);
  115998. - if (!ii->vfs_inode.i_nlink) {
  115999. - /*
  116000. - * Defer calling iput() to avoid a deadlock
  116001. - * over I_SYNC flag for inodes with i_nlink == 0
  116002. - */
  116003. - list_add_tail(&ii->i_dirty, &sci->sc_iput_queue);
  116004. - defer_iput = true;
  116005. - } else {
  116006. - spin_unlock(&nilfs->ns_inode_lock);
  116007. - iput(&ii->vfs_inode);
  116008. - spin_lock(&nilfs->ns_inode_lock);
  116009. - }
  116010. + list_move_tail(&ii->i_dirty, &ti->ti_garbage);
  116011. }
  116012. spin_unlock(&nilfs->ns_inode_lock);
  116013. -
  116014. - if (defer_iput)
  116015. - schedule_work(&sci->sc_iput_work);
  116016. }
  116017. /*
  116018. @@ -2604,8 +2583,6 @@
  116019. INIT_LIST_HEAD(&sci->sc_segbufs);
  116020. INIT_LIST_HEAD(&sci->sc_write_logs);
  116021. INIT_LIST_HEAD(&sci->sc_gc_inodes);
  116022. - INIT_LIST_HEAD(&sci->sc_iput_queue);
  116023. - INIT_WORK(&sci->sc_iput_work, nilfs_iput_work_func);
  116024. init_timer(&sci->sc_timer);
  116025. sci->sc_interval = HZ * NILFS_SC_DEFAULT_TIMEOUT;
  116026. @@ -2632,8 +2609,6 @@
  116027. ret = nilfs_segctor_construct(sci, SC_LSEG_SR);
  116028. nilfs_transaction_unlock(sci->sc_super);
  116029. - flush_work(&sci->sc_iput_work);
  116030. -
  116031. } while (ret && retrycount-- > 0);
  116032. }
  116033. @@ -2658,9 +2633,6 @@
  116034. || sci->sc_seq_request != sci->sc_seq_done);
  116035. spin_unlock(&sci->sc_state_lock);
  116036. - if (flush_work(&sci->sc_iput_work))
  116037. - flag = true;
  116038. -
  116039. if (flag || !nilfs_segctor_confirm(sci))
  116040. nilfs_segctor_write_out(sci);
  116041. @@ -2670,12 +2642,6 @@
  116042. nilfs_dispose_list(nilfs, &sci->sc_dirty_files, 1);
  116043. }
  116044. - if (!list_empty(&sci->sc_iput_queue)) {
  116045. - nilfs_warning(sci->sc_super, __func__,
  116046. - "iput queue is not empty\n");
  116047. - nilfs_dispose_list(nilfs, &sci->sc_iput_queue, 1);
  116048. - }
  116049. -
  116050. WARN_ON(!list_empty(&sci->sc_segbufs));
  116051. WARN_ON(!list_empty(&sci->sc_write_logs));
  116052. diff -Nur linux-3.12.38/fs/nilfs2/segment.h linux-rpi/fs/nilfs2/segment.h
  116053. --- linux-3.12.38/fs/nilfs2/segment.h 2015-02-16 16:15:42.000000000 +0100
  116054. +++ linux-rpi/fs/nilfs2/segment.h 2015-03-10 17:26:51.514216686 +0100
  116055. @@ -26,7 +26,6 @@
  116056. #include <linux/types.h>
  116057. #include <linux/fs.h>
  116058. #include <linux/buffer_head.h>
  116059. -#include <linux/workqueue.h>
  116060. #include <linux/nilfs2_fs.h>
  116061. #include "nilfs.h"
  116062. @@ -93,8 +92,6 @@
  116063. * @sc_nblk_inc: Block count of current generation
  116064. * @sc_dirty_files: List of files to be written
  116065. * @sc_gc_inodes: List of GC inodes having blocks to be written
  116066. - * @sc_iput_queue: list of inodes for which iput should be done
  116067. - * @sc_iput_work: work struct to defer iput call
  116068. * @sc_freesegs: array of segment numbers to be freed
  116069. * @sc_nfreesegs: number of segments on @sc_freesegs
  116070. * @sc_dsync_inode: inode whose data pages are written for a sync operation
  116071. @@ -138,8 +135,6 @@
  116072. struct list_head sc_dirty_files;
  116073. struct list_head sc_gc_inodes;
  116074. - struct list_head sc_iput_queue;
  116075. - struct work_struct sc_iput_work;
  116076. __u64 *sc_freesegs;
  116077. size_t sc_nfreesegs;
  116078. diff -Nur linux-3.12.38/fs/notify/fsnotify.c linux-rpi/fs/notify/fsnotify.c
  116079. --- linux-3.12.38/fs/notify/fsnotify.c 2015-02-16 16:15:42.000000000 +0100
  116080. +++ linux-rpi/fs/notify/fsnotify.c 2015-03-10 17:26:51.530216686 +0100
  116081. @@ -63,14 +63,14 @@
  116082. spin_lock(&inode->i_lock);
  116083. /* run all of the dentries associated with this inode. Since this is a
  116084. * directory, there damn well better only be one item on this list */
  116085. - hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
  116086. + hlist_for_each_entry(alias, &inode->i_dentry, d_alias) {
  116087. struct dentry *child;
  116088. /* run all of the children of the original inode and fix their
  116089. * d_flags to indicate parental interest (their parent is the
  116090. * original inode) */
  116091. spin_lock(&alias->d_lock);
  116092. - list_for_each_entry(child, &alias->d_subdirs, d_child) {
  116093. + list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) {
  116094. if (!child->d_inode)
  116095. continue;
  116096. diff -Nur linux-3.12.38/fs/notify/inode_mark.c linux-rpi/fs/notify/inode_mark.c
  116097. --- linux-3.12.38/fs/notify/inode_mark.c 2015-02-16 16:15:42.000000000 +0100
  116098. +++ linux-rpi/fs/notify/inode_mark.c 2015-03-10 17:26:51.530216686 +0100
  116099. @@ -288,25 +288,20 @@
  116100. spin_unlock(&inode->i_lock);
  116101. /* In case the dropping of a reference would nuke next_i. */
  116102. - while (&next_i->i_sb_list != list) {
  116103. + if ((&next_i->i_sb_list != list) &&
  116104. + atomic_read(&next_i->i_count)) {
  116105. spin_lock(&next_i->i_lock);
  116106. - if (!(next_i->i_state & (I_FREEING | I_WILL_FREE)) &&
  116107. - atomic_read(&next_i->i_count)) {
  116108. + if (!(next_i->i_state & (I_FREEING | I_WILL_FREE))) {
  116109. __iget(next_i);
  116110. need_iput = next_i;
  116111. - spin_unlock(&next_i->i_lock);
  116112. - break;
  116113. }
  116114. spin_unlock(&next_i->i_lock);
  116115. - next_i = list_entry(next_i->i_sb_list.next,
  116116. - struct inode, i_sb_list);
  116117. }
  116118. /*
  116119. - * We can safely drop inode_sb_list_lock here because either
  116120. - * we actually hold references on both inode and next_i or
  116121. - * end of list. Also no new inodes will be added since the
  116122. - * umount has begun.
  116123. + * We can safely drop inode_sb_list_lock here because we hold
  116124. + * references on both inode and next_i. Also no new inodes
  116125. + * will be added since the umount has begun.
  116126. */
  116127. spin_unlock(&inode_sb_list_lock);
  116128. diff -Nur linux-3.12.38/fs/ocfs2/aops.c linux-rpi/fs/ocfs2/aops.c
  116129. --- linux-3.12.38/fs/ocfs2/aops.c 2015-02-16 16:15:42.000000000 +0100
  116130. +++ linux-rpi/fs/ocfs2/aops.c 2015-03-10 17:26:51.534216686 +0100
  116131. @@ -912,7 +912,7 @@
  116132. }
  116133. }
  116134. -static void ocfs2_unlock_pages(struct ocfs2_write_ctxt *wc)
  116135. +static void ocfs2_free_write_ctxt(struct ocfs2_write_ctxt *wc)
  116136. {
  116137. int i;
  116138. @@ -933,11 +933,7 @@
  116139. page_cache_release(wc->w_target_page);
  116140. }
  116141. ocfs2_unlock_and_free_pages(wc->w_pages, wc->w_num_pages);
  116142. -}
  116143. -static void ocfs2_free_write_ctxt(struct ocfs2_write_ctxt *wc)
  116144. -{
  116145. - ocfs2_unlock_pages(wc);
  116146. brelse(wc->w_di_bh);
  116147. kfree(wc);
  116148. }
  116149. @@ -2059,19 +2055,11 @@
  116150. di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
  116151. ocfs2_journal_dirty(handle, wc->w_di_bh);
  116152. - /* unlock pages before dealloc since it needs acquiring j_trans_barrier
  116153. - * lock, or it will cause a deadlock since journal commit threads holds
  116154. - * this lock and will ask for the page lock when flushing the data.
  116155. - * put it here to preserve the unlock order.
  116156. - */
  116157. - ocfs2_unlock_pages(wc);
  116158. -
  116159. ocfs2_commit_trans(osb, handle);
  116160. ocfs2_run_deallocs(osb, &wc->w_dealloc);
  116161. - brelse(wc->w_di_bh);
  116162. - kfree(wc);
  116163. + ocfs2_free_write_ctxt(wc);
  116164. return copied;
  116165. }
  116166. diff -Nur linux-3.12.38/fs/ocfs2/dcache.c linux-rpi/fs/ocfs2/dcache.c
  116167. --- linux-3.12.38/fs/ocfs2/dcache.c 2015-02-16 16:15:42.000000000 +0100
  116168. +++ linux-rpi/fs/ocfs2/dcache.c 2015-03-10 17:26:51.534216686 +0100
  116169. @@ -172,7 +172,7 @@
  116170. struct dentry *dentry;
  116171. spin_lock(&inode->i_lock);
  116172. - hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
  116173. + hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
  116174. spin_lock(&dentry->d_lock);
  116175. if (ocfs2_match_dentry(dentry, parent_blkno, skip_unhashed)) {
  116176. trace_ocfs2_find_local_alias(dentry->d_name.len,
  116177. diff -Nur linux-3.12.38/fs/ocfs2/file.c linux-rpi/fs/ocfs2/file.c
  116178. --- linux-3.12.38/fs/ocfs2/file.c 2015-02-16 16:15:42.000000000 +0100
  116179. +++ linux-rpi/fs/ocfs2/file.c 2015-03-10 17:26:51.538216686 +0100
  116180. @@ -2376,7 +2376,9 @@
  116181. if (ret < 0)
  116182. written = ret;
  116183. - if (!ret) {
  116184. + if (!ret && ((old_size != i_size_read(inode)) ||
  116185. + (old_clusters != OCFS2_I(inode)->ip_clusters) ||
  116186. + has_refcount)) {
  116187. ret = jbd2_journal_force_commit(osb->journal->j_journal);
  116188. if (ret < 0)
  116189. written = ret;
  116190. diff -Nur linux-3.12.38/fs/proc/stat.c linux-rpi/fs/proc/stat.c
  116191. --- linux-3.12.38/fs/proc/stat.c 2015-02-16 16:15:42.000000000 +0100
  116192. +++ linux-rpi/fs/proc/stat.c 2015-03-10 17:26:51.546216686 +0100
  116193. @@ -159,7 +159,7 @@
  116194. /* sum again ? it could be updated? */
  116195. for_each_irq_nr(j)
  116196. - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
  116197. + seq_put_decimal_ull(p, ' ', kstat_irqs(j));
  116198. seq_printf(p,
  116199. "\nctxt %llu\n"
  116200. diff -Nur linux-3.12.38/fs/pstore/ram.c linux-rpi/fs/pstore/ram.c
  116201. --- linux-3.12.38/fs/pstore/ram.c 2015-02-16 16:15:42.000000000 +0100
  116202. +++ linux-rpi/fs/pstore/ram.c 2015-03-10 17:26:51.546216686 +0100
  116203. @@ -61,11 +61,6 @@
  116204. MODULE_PARM_DESC(mem_size,
  116205. "size of reserved RAM used to store oops/panic logs");
  116206. -static unsigned int mem_type;
  116207. -module_param(mem_type, uint, 0600);
  116208. -MODULE_PARM_DESC(mem_type,
  116209. - "set to 1 to try to use unbuffered memory (default 0)");
  116210. -
  116211. static int dump_oops = 1;
  116212. module_param(dump_oops, int, 0600);
  116213. MODULE_PARM_DESC(dump_oops,
  116214. @@ -84,7 +79,6 @@
  116215. struct persistent_ram_zone *fprz;
  116216. phys_addr_t phys_addr;
  116217. unsigned long size;
  116218. - unsigned int memtype;
  116219. size_t record_size;
  116220. size_t console_size;
  116221. size_t ftrace_size;
  116222. @@ -92,7 +86,6 @@
  116223. struct persistent_ram_ecc_info ecc_info;
  116224. unsigned int max_dump_cnt;
  116225. unsigned int dump_write_cnt;
  116226. - /* _read_cnt need clear on ramoops_pstore_open */
  116227. unsigned int dump_read_cnt;
  116228. unsigned int console_read_cnt;
  116229. unsigned int ftrace_read_cnt;
  116230. @@ -108,7 +101,6 @@
  116231. cxt->dump_read_cnt = 0;
  116232. cxt->console_read_cnt = 0;
  116233. - cxt->ftrace_read_cnt = 0;
  116234. return 0;
  116235. }
  116236. @@ -125,15 +117,13 @@
  116237. return NULL;
  116238. prz = przs[i];
  116239. - if (!prz)
  116240. - return NULL;
  116241. - /* Update old/shadowed buffer. */
  116242. - if (update)
  116243. + if (update) {
  116244. + /* Update old/shadowed buffer. */
  116245. persistent_ram_save_old(prz);
  116246. -
  116247. - if (!persistent_ram_old_size(prz))
  116248. - return NULL;
  116249. + if (!persistent_ram_old_size(prz))
  116250. + return NULL;
  116251. + }
  116252. *typep = type;
  116253. *id = i;
  116254. @@ -363,8 +353,7 @@
  116255. size_t sz = cxt->record_size;
  116256. cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
  116257. - &cxt->ecc_info,
  116258. - cxt->memtype);
  116259. + &cxt->ecc_info);
  116260. if (IS_ERR(cxt->przs[i])) {
  116261. err = PTR_ERR(cxt->przs[i]);
  116262. dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
  116263. @@ -394,7 +383,7 @@
  116264. return -ENOMEM;
  116265. }
  116266. - *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, cxt->memtype);
  116267. + *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info);
  116268. if (IS_ERR(*prz)) {
  116269. int err = PTR_ERR(*prz);
  116270. @@ -439,9 +428,9 @@
  116271. if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size))
  116272. pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
  116273. + cxt->dump_read_cnt = 0;
  116274. cxt->size = pdata->mem_size;
  116275. cxt->phys_addr = pdata->mem_address;
  116276. - cxt->memtype = pdata->mem_type;
  116277. cxt->record_size = pdata->record_size;
  116278. cxt->console_size = pdata->console_size;
  116279. cxt->ftrace_size = pdata->ftrace_size;
  116280. @@ -572,7 +561,6 @@
  116281. dummy_data->mem_size = mem_size;
  116282. dummy_data->mem_address = mem_address;
  116283. - dummy_data->mem_type = 0;
  116284. dummy_data->record_size = record_size;
  116285. dummy_data->console_size = ramoops_console_size;
  116286. dummy_data->ftrace_size = ramoops_ftrace_size;
  116287. diff -Nur linux-3.12.38/fs/pstore/ram_core.c linux-rpi/fs/pstore/ram_core.c
  116288. --- linux-3.12.38/fs/pstore/ram_core.c 2015-02-16 16:15:42.000000000 +0100
  116289. +++ linux-rpi/fs/pstore/ram_core.c 2015-03-10 17:26:51.546216686 +0100
  116290. @@ -380,8 +380,7 @@
  116291. persistent_ram_update_header_ecc(prz);
  116292. }
  116293. -static void *persistent_ram_vmap(phys_addr_t start, size_t size,
  116294. - unsigned int memtype)
  116295. +static void *persistent_ram_vmap(phys_addr_t start, size_t size)
  116296. {
  116297. struct page **pages;
  116298. phys_addr_t page_start;
  116299. @@ -393,10 +392,7 @@
  116300. page_start = start - offset_in_page(start);
  116301. page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
  116302. - if (memtype)
  116303. - prot = pgprot_noncached(PAGE_KERNEL);
  116304. - else
  116305. - prot = pgprot_writecombine(PAGE_KERNEL);
  116306. + prot = pgprot_noncached(PAGE_KERNEL);
  116307. pages = kmalloc(sizeof(struct page *) * page_count, GFP_KERNEL);
  116308. if (!pages) {
  116309. @@ -415,11 +411,8 @@
  116310. return vaddr;
  116311. }
  116312. -static void *persistent_ram_iomap(phys_addr_t start, size_t size,
  116313. - unsigned int memtype)
  116314. +static void *persistent_ram_iomap(phys_addr_t start, size_t size)
  116315. {
  116316. - void *va;
  116317. -
  116318. if (!request_mem_region(start, size, "persistent_ram")) {
  116319. pr_err("request mem region (0x%llx@0x%llx) failed\n",
  116320. (unsigned long long)size, (unsigned long long)start);
  116321. @@ -429,24 +422,19 @@
  116322. buffer_start_add = buffer_start_add_locked;
  116323. buffer_size_add = buffer_size_add_locked;
  116324. - if (memtype)
  116325. - va = ioremap(start, size);
  116326. - else
  116327. - va = ioremap_wc(start, size);
  116328. -
  116329. - return va;
  116330. + return ioremap(start, size);
  116331. }
  116332. static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
  116333. - struct persistent_ram_zone *prz, int memtype)
  116334. + struct persistent_ram_zone *prz)
  116335. {
  116336. prz->paddr = start;
  116337. prz->size = size;
  116338. if (pfn_valid(start >> PAGE_SHIFT))
  116339. - prz->vaddr = persistent_ram_vmap(start, size, memtype);
  116340. + prz->vaddr = persistent_ram_vmap(start, size);
  116341. else
  116342. - prz->vaddr = persistent_ram_iomap(start, size, memtype);
  116343. + prz->vaddr = persistent_ram_iomap(start, size);
  116344. if (!prz->vaddr) {
  116345. pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
  116346. @@ -514,8 +502,7 @@
  116347. }
  116348. struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
  116349. - u32 sig, struct persistent_ram_ecc_info *ecc_info,
  116350. - unsigned int memtype)
  116351. + u32 sig, struct persistent_ram_ecc_info *ecc_info)
  116352. {
  116353. struct persistent_ram_zone *prz;
  116354. int ret = -ENOMEM;
  116355. @@ -526,7 +513,7 @@
  116356. goto err;
  116357. }
  116358. - ret = persistent_ram_buffer_map(start, size, prz, memtype);
  116359. + ret = persistent_ram_buffer_map(start, size, prz);
  116360. if (ret)
  116361. goto err;
  116362. diff -Nur linux-3.12.38/fs/udf/dir.c linux-rpi/fs/udf/dir.c
  116363. --- linux-3.12.38/fs/udf/dir.c 2015-02-16 16:15:42.000000000 +0100
  116364. +++ linux-rpi/fs/udf/dir.c 2015-03-10 17:26:51.562216686 +0100
  116365. @@ -167,8 +167,7 @@
  116366. continue;
  116367. }
  116368. - flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
  116369. - UDF_NAME_LEN);
  116370. + flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
  116371. if (!flen)
  116372. continue;
  116373. diff -Nur linux-3.12.38/fs/udf/inode.c linux-rpi/fs/udf/inode.c
  116374. --- linux-3.12.38/fs/udf/inode.c 2015-02-16 16:15:42.000000000 +0100
  116375. +++ linux-rpi/fs/udf/inode.c 2015-03-10 17:26:51.562216686 +0100
  116376. @@ -1495,24 +1495,6 @@
  116377. iinfo->i_checkpoint = le32_to_cpu(efe->checkpoint);
  116378. }
  116379. - /* Sanity checks for files in ICB so that we don't get confused later */
  116380. - if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  116381. - /*
  116382. - * For file in ICB data is stored in allocation descriptor
  116383. - * so sizes should match
  116384. - */
  116385. - if (iinfo->i_lenAlloc != inode->i_size) {
  116386. - make_bad_inode(inode);
  116387. - return;
  116388. - }
  116389. - /* File in ICB has to fit in there... */
  116390. - if (inode->i_size > inode->i_sb->s_blocksize -
  116391. - udf_file_entry_alloc_offset(inode)) {
  116392. - make_bad_inode(inode);
  116393. - return;
  116394. - }
  116395. - }
  116396. -
  116397. switch (fe->icbTag.fileType) {
  116398. case ICBTAG_FILE_TYPE_DIRECTORY:
  116399. inode->i_op = &udf_dir_inode_operations;
  116400. diff -Nur linux-3.12.38/fs/udf/namei.c linux-rpi/fs/udf/namei.c
  116401. --- linux-3.12.38/fs/udf/namei.c 2015-02-16 16:15:42.000000000 +0100
  116402. +++ linux-rpi/fs/udf/namei.c 2015-03-10 17:26:51.562216686 +0100
  116403. @@ -233,8 +233,7 @@
  116404. if (!lfi)
  116405. continue;
  116406. - flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
  116407. - UDF_NAME_LEN);
  116408. + flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
  116409. if (flen && udf_match(flen, fname, child->len, child->name))
  116410. goto out_ok;
  116411. }
  116412. diff -Nur linux-3.12.38/fs/udf/symlink.c linux-rpi/fs/udf/symlink.c
  116413. --- linux-3.12.38/fs/udf/symlink.c 2015-02-16 16:15:42.000000000 +0100
  116414. +++ linux-rpi/fs/udf/symlink.c 2015-03-10 17:26:51.562216686 +0100
  116415. @@ -30,73 +30,49 @@
  116416. #include <linux/buffer_head.h>
  116417. #include "udf_i.h"
  116418. -static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
  116419. - int fromlen, unsigned char *to, int tolen)
  116420. +static void udf_pc_to_char(struct super_block *sb, unsigned char *from,
  116421. + int fromlen, unsigned char *to)
  116422. {
  116423. struct pathComponent *pc;
  116424. int elen = 0;
  116425. - int comp_len;
  116426. unsigned char *p = to;
  116427. - /* Reserve one byte for terminating \0 */
  116428. - tolen--;
  116429. while (elen < fromlen) {
  116430. pc = (struct pathComponent *)(from + elen);
  116431. - elen += sizeof(struct pathComponent);
  116432. switch (pc->componentType) {
  116433. case 1:
  116434. /*
  116435. * Symlink points to some place which should be agreed
  116436. * upon between originator and receiver of the media. Ignore.
  116437. */
  116438. - if (pc->lengthComponentIdent > 0) {
  116439. - elen += pc->lengthComponentIdent;
  116440. + if (pc->lengthComponentIdent > 0)
  116441. break;
  116442. - }
  116443. /* Fall through */
  116444. case 2:
  116445. - if (tolen == 0)
  116446. - return -ENAMETOOLONG;
  116447. p = to;
  116448. *p++ = '/';
  116449. - tolen--;
  116450. break;
  116451. case 3:
  116452. - if (tolen < 3)
  116453. - return -ENAMETOOLONG;
  116454. memcpy(p, "../", 3);
  116455. p += 3;
  116456. - tolen -= 3;
  116457. break;
  116458. case 4:
  116459. - if (tolen < 2)
  116460. - return -ENAMETOOLONG;
  116461. memcpy(p, "./", 2);
  116462. p += 2;
  116463. - tolen -= 2;
  116464. /* that would be . - just ignore */
  116465. break;
  116466. case 5:
  116467. - elen += pc->lengthComponentIdent;
  116468. - if (elen > fromlen)
  116469. - return -EIO;
  116470. - comp_len = udf_get_filename(sb, pc->componentIdent,
  116471. - pc->lengthComponentIdent,
  116472. - p, tolen);
  116473. - p += comp_len;
  116474. - tolen -= comp_len;
  116475. - if (tolen == 0)
  116476. - return -ENAMETOOLONG;
  116477. + p += udf_get_filename(sb, pc->componentIdent, p,
  116478. + pc->lengthComponentIdent);
  116479. *p++ = '/';
  116480. - tolen--;
  116481. break;
  116482. }
  116483. + elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
  116484. }
  116485. if (p > to + 1)
  116486. p[-1] = '\0';
  116487. else
  116488. p[0] = '\0';
  116489. - return 0;
  116490. }
  116491. static int udf_symlink_filler(struct file *file, struct page *page)
  116492. @@ -132,10 +108,8 @@
  116493. symlink = bh->b_data;
  116494. }
  116495. - err = udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p, PAGE_SIZE);
  116496. + udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
  116497. brelse(bh);
  116498. - if (err)
  116499. - goto out_unlock_inode;
  116500. up_read(&iinfo->i_data_sem);
  116501. SetPageUptodate(page);
  116502. diff -Nur linux-3.12.38/fs/udf/udfdecl.h linux-rpi/fs/udf/udfdecl.h
  116503. --- linux-3.12.38/fs/udf/udfdecl.h 2015-02-16 16:15:42.000000000 +0100
  116504. +++ linux-rpi/fs/udf/udfdecl.h 2015-03-10 17:26:51.562216686 +0100
  116505. @@ -201,8 +201,7 @@
  116506. }
  116507. /* unicode.c */
  116508. -extern int udf_get_filename(struct super_block *, uint8_t *, int, uint8_t *,
  116509. - int);
  116510. +extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int);
  116511. extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *,
  116512. int);
  116513. extern int udf_build_ustr(struct ustr *, dstring *, int);
  116514. diff -Nur linux-3.12.38/fs/udf/unicode.c linux-rpi/fs/udf/unicode.c
  116515. --- linux-3.12.38/fs/udf/unicode.c 2015-02-16 16:15:42.000000000 +0100
  116516. +++ linux-rpi/fs/udf/unicode.c 2015-03-10 17:26:51.562216686 +0100
  116517. @@ -28,8 +28,7 @@
  116518. #include "udf_sb.h"
  116519. -static int udf_translate_to_linux(uint8_t *, int, uint8_t *, int, uint8_t *,
  116520. - int);
  116521. +static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int);
  116522. static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
  116523. {
  116524. @@ -334,8 +333,8 @@
  116525. return u_len + 1;
  116526. }
  116527. -int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
  116528. - uint8_t *dname, int dlen)
  116529. +int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
  116530. + int flen)
  116531. {
  116532. struct ustr *filename, *unifilename;
  116533. int len = 0;
  116534. @@ -348,7 +347,7 @@
  116535. if (!unifilename)
  116536. goto out1;
  116537. - if (udf_build_ustr_exact(unifilename, sname, slen))
  116538. + if (udf_build_ustr_exact(unifilename, sname, flen))
  116539. goto out2;
  116540. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
  116541. @@ -367,8 +366,7 @@
  116542. } else
  116543. goto out2;
  116544. - len = udf_translate_to_linux(dname, dlen,
  116545. - filename->u_name, filename->u_len,
  116546. + len = udf_translate_to_linux(dname, filename->u_name, filename->u_len,
  116547. unifilename->u_name, unifilename->u_len);
  116548. out2:
  116549. kfree(unifilename);
  116550. @@ -405,12 +403,10 @@
  116551. #define EXT_MARK '.'
  116552. #define CRC_MARK '#'
  116553. #define EXT_SIZE 5
  116554. -/* Number of chars we need to store generated CRC to make filename unique */
  116555. -#define CRC_LEN 5
  116556. -static int udf_translate_to_linux(uint8_t *newName, int newLen,
  116557. - uint8_t *udfName, int udfLen,
  116558. - uint8_t *fidName, int fidNameLen)
  116559. +static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
  116560. + int udfLen, uint8_t *fidName,
  116561. + int fidNameLen)
  116562. {
  116563. int index, newIndex = 0, needsCRC = 0;
  116564. int extIndex = 0, newExtIndex = 0, hasExt = 0;
  116565. @@ -444,7 +440,7 @@
  116566. newExtIndex = newIndex;
  116567. }
  116568. }
  116569. - if (newIndex < newLen)
  116570. + if (newIndex < 256)
  116571. newName[newIndex++] = curr;
  116572. else
  116573. needsCRC = 1;
  116574. @@ -472,13 +468,13 @@
  116575. }
  116576. ext[localExtIndex++] = curr;
  116577. }
  116578. - maxFilenameLen = newLen - CRC_LEN - localExtIndex;
  116579. + maxFilenameLen = 250 - localExtIndex;
  116580. if (newIndex > maxFilenameLen)
  116581. newIndex = maxFilenameLen;
  116582. else
  116583. newIndex = newExtIndex;
  116584. - } else if (newIndex > newLen - CRC_LEN)
  116585. - newIndex = newLen - CRC_LEN;
  116586. + } else if (newIndex > 250)
  116587. + newIndex = 250;
  116588. newName[newIndex++] = CRC_MARK;
  116589. valueCRC = crc_itu_t(0, fidName, fidNameLen);
  116590. newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
  116591. diff -Nur linux-3.12.38/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  116592. --- linux-3.12.38/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  116593. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2015-03-09 10:39:35.806893702 +0100
  116594. @@ -0,0 +1,29 @@
  116595. +/*****************************************************************************
  116596. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  116597. +*
  116598. +* Unless you and Broadcom execute a separate written software license
  116599. +* agreement governing use of this software, this software is licensed to you
  116600. +* under the terms of the GNU General Public License version 2, available at
  116601. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  116602. +*
  116603. +* Notwithstanding the above, under no circumstances may you combine this
  116604. +* software in any way with any other Broadcom software provided under a
  116605. +* license other than the GPL, without Broadcom's express prior written
  116606. +* consent.
  116607. +*****************************************************************************/
  116608. +
  116609. +#if !defined( VC_CMA_H )
  116610. +#define VC_CMA_H
  116611. +
  116612. +#include <linux/ioctl.h>
  116613. +
  116614. +#define VC_CMA_IOC_MAGIC 0xc5
  116615. +
  116616. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  116617. +
  116618. +#ifdef __KERNEL__
  116619. +extern void __init vc_cma_early_init(void);
  116620. +extern void __init vc_cma_reserve(void);
  116621. +#endif
  116622. +
  116623. +#endif /* VC_CMA_H */
  116624. diff -Nur linux-3.12.38/include/linux/compat.h linux-rpi/include/linux/compat.h
  116625. --- linux-3.12.38/include/linux/compat.h 2015-02-16 16:15:42.000000000 +0100
  116626. +++ linux-rpi/include/linux/compat.h 2015-03-10 17:26:51.594216686 +0100
  116627. @@ -318,7 +318,7 @@
  116628. asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
  116629. compat_ssize_t msgsz, int msgflg);
  116630. asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
  116631. - compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
  116632. + compat_ssize_t msgsz, long msgtyp, int msgflg);
  116633. long compat_sys_msgctl(int first, int second, void __user *uptr);
  116634. long compat_sys_shmctl(int first, int second, void __user *uptr);
  116635. long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
  116636. diff -Nur linux-3.12.38/include/linux/crypto.h linux-rpi/include/linux/crypto.h
  116637. --- linux-3.12.38/include/linux/crypto.h 2015-02-16 16:15:42.000000000 +0100
  116638. +++ linux-rpi/include/linux/crypto.h 2015-03-10 17:26:51.594216686 +0100
  116639. @@ -26,19 +26,6 @@
  116640. #include <linux/uaccess.h>
  116641. /*
  116642. - * Autoloaded crypto modules should only use a prefixed name to avoid allowing
  116643. - * arbitrary modules to be loaded. Loading from userspace may still need the
  116644. - * unprefixed names, so retains those aliases as well.
  116645. - * This uses __MODULE_INFO directly instead of MODULE_ALIAS because pre-4.3
  116646. - * gcc (e.g. avr32 toolchain) uses __LINE__ for uniqueness, and this macro
  116647. - * expands twice on the same line. Instead, use a separate base name for the
  116648. - * alias.
  116649. - */
  116650. -#define MODULE_ALIAS_CRYPTO(name) \
  116651. - __MODULE_INFO(alias, alias_userspace, name); \
  116652. - __MODULE_INFO(alias, alias_crypto, "crypto-" name)
  116653. -
  116654. -/*
  116655. * Algorithm masks and types.
  116656. */
  116657. #define CRYPTO_ALG_TYPE_MASK 0x0000000f
  116658. diff -Nur linux-3.12.38/include/linux/dcache.h linux-rpi/include/linux/dcache.h
  116659. --- linux-3.12.38/include/linux/dcache.h 2015-02-16 16:15:42.000000000 +0100
  116660. +++ linux-rpi/include/linux/dcache.h 2015-03-10 17:26:51.594216686 +0100
  116661. @@ -122,15 +122,15 @@
  116662. void *d_fsdata; /* fs-specific data */
  116663. struct list_head d_lru; /* LRU list */
  116664. - struct list_head d_child; /* child of parent list */
  116665. - struct list_head d_subdirs; /* our children */
  116666. /*
  116667. - * d_alias and d_rcu can share memory
  116668. + * d_child and d_rcu can share memory
  116669. */
  116670. union {
  116671. - struct hlist_node d_alias; /* inode alias list */
  116672. + struct list_head d_child; /* child of parent list */
  116673. struct rcu_head d_rcu;
  116674. } d_u;
  116675. + struct list_head d_subdirs; /* our children */
  116676. + struct hlist_node d_alias; /* inode alias list */
  116677. };
  116678. /*
  116679. diff -Nur linux-3.12.38/include/linux/kernel_stat.h linux-rpi/include/linux/kernel_stat.h
  116680. --- linux-3.12.38/include/linux/kernel_stat.h 2015-02-16 16:15:42.000000000 +0100
  116681. +++ linux-rpi/include/linux/kernel_stat.h 2015-03-10 17:26:51.606216686 +0100
  116682. @@ -74,7 +74,6 @@
  116683. * Number of interrupts per specific IRQ source, since bootup
  116684. */
  116685. extern unsigned int kstat_irqs(unsigned int irq);
  116686. -extern unsigned int kstat_irqs_usr(unsigned int irq);
  116687. /*
  116688. * Number of interrupts per cpu, since bootup
  116689. diff -Nur linux-3.12.38/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  116690. --- linux-3.12.38/include/linux/mmc/host.h 2015-02-16 16:15:42.000000000 +0100
  116691. +++ linux-rpi/include/linux/mmc/host.h 2015-03-10 17:26:51.618216685 +0100
  116692. @@ -281,6 +281,7 @@
  116693. MMC_CAP2_PACKED_WR)
  116694. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  116695. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  116696. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  116697. mmc_pm_flag_t pm_caps; /* supported pm features */
  116698. diff -Nur linux-3.12.38/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  116699. --- linux-3.12.38/include/linux/mmc/sdhci.h 2015-02-16 16:15:42.000000000 +0100
  116700. +++ linux-rpi/include/linux/mmc/sdhci.h 2015-03-10 17:26:51.618216685 +0100
  116701. @@ -98,12 +98,9 @@
  116702. #define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4)
  116703. /* Controller has a non-standard host control register */
  116704. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  116705. -/* Controller does not support HS200 */
  116706. -#define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
  116707. -/* Controller does not support DDR50 */
  116708. -#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
  116709. int irq; /* Device IRQ */
  116710. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  116711. void __iomem *ioaddr; /* Mapped address */
  116712. const struct sdhci_ops *ops; /* Low level hw interface */
  116713. @@ -135,6 +132,7 @@
  116714. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  116715. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  116716. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  116717. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  116718. unsigned int version; /* SDHCI spec. version */
  116719. @@ -150,6 +148,7 @@
  116720. struct mmc_request *mrq; /* Current request */
  116721. struct mmc_command *cmd; /* Current command */
  116722. + int last_cmdop; /* Opcode of last cmd sent */
  116723. struct mmc_data *data; /* Current data request */
  116724. unsigned int data_early:1; /* Data finished before cmd */
  116725. diff -Nur linux-3.12.38/include/linux/mm.h linux-rpi/include/linux/mm.h
  116726. --- linux-3.12.38/include/linux/mm.h 2015-02-16 16:15:42.000000000 +0100
  116727. +++ linux-rpi/include/linux/mm.h 2015-03-10 17:26:51.618216685 +0100
  116728. @@ -1642,7 +1642,7 @@
  116729. #if VM_GROWSUP
  116730. extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
  116731. #else
  116732. - #define expand_upwards(vma, address) (0)
  116733. + #define expand_upwards(vma, address) do { } while (0)
  116734. #endif
  116735. /* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
  116736. diff -Nur linux-3.12.38/include/linux/pagemap.h linux-rpi/include/linux/pagemap.h
  116737. --- linux-3.12.38/include/linux/pagemap.h 2015-02-16 16:15:42.000000000 +0100
  116738. +++ linux-rpi/include/linux/pagemap.h 2015-03-10 17:26:51.622216685 +0100
  116739. @@ -256,7 +256,7 @@
  116740. #define FGP_NOWAIT 0x00000020
  116741. struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
  116742. - int fgp_flags, gfp_t cache_gfp_mask);
  116743. + int fgp_flags, gfp_t cache_gfp_mask, gfp_t radix_gfp_mask);
  116744. /**
  116745. * find_get_page - find and get a page reference
  116746. @@ -271,13 +271,13 @@
  116747. static inline struct page *find_get_page(struct address_space *mapping,
  116748. pgoff_t offset)
  116749. {
  116750. - return pagecache_get_page(mapping, offset, 0, 0);
  116751. + return pagecache_get_page(mapping, offset, 0, 0, 0);
  116752. }
  116753. static inline struct page *find_get_page_flags(struct address_space *mapping,
  116754. pgoff_t offset, int fgp_flags)
  116755. {
  116756. - return pagecache_get_page(mapping, offset, fgp_flags, 0);
  116757. + return pagecache_get_page(mapping, offset, fgp_flags, 0, 0);
  116758. }
  116759. /**
  116760. @@ -297,7 +297,7 @@
  116761. static inline struct page *find_lock_page(struct address_space *mapping,
  116762. pgoff_t offset)
  116763. {
  116764. - return pagecache_get_page(mapping, offset, FGP_LOCK, 0);
  116765. + return pagecache_get_page(mapping, offset, FGP_LOCK, 0, 0);
  116766. }
  116767. /**
  116768. @@ -324,7 +324,7 @@
  116769. {
  116770. return pagecache_get_page(mapping, offset,
  116771. FGP_LOCK|FGP_ACCESSED|FGP_CREAT,
  116772. - gfp_mask);
  116773. + gfp_mask, gfp_mask & GFP_RECLAIM_MASK);
  116774. }
  116775. /**
  116776. @@ -345,7 +345,8 @@
  116777. {
  116778. return pagecache_get_page(mapping, index,
  116779. FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
  116780. - mapping_gfp_mask(mapping));
  116781. + mapping_gfp_mask(mapping),
  116782. + GFP_NOFS);
  116783. }
  116784. struct page *find_get_entry(struct address_space *mapping, pgoff_t offset);
  116785. diff -Nur linux-3.12.38/include/linux/platform_data/bcm2708.h linux-rpi/include/linux/platform_data/bcm2708.h
  116786. --- linux-3.12.38/include/linux/platform_data/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  116787. +++ linux-rpi/include/linux/platform_data/bcm2708.h 2015-03-09 10:39:36.394893698 +0100
  116788. @@ -0,0 +1,23 @@
  116789. +/*
  116790. + * include/linux/platform_data/bcm2708.h
  116791. + *
  116792. + * This program is free software; you can redistribute it and/or modify
  116793. + * it under the terms of the GNU General Public License version 2 as
  116794. + * published by the Free Software Foundation.
  116795. + *
  116796. + * (C) 2014 Julian Scheel <julian@jusst.de>
  116797. + *
  116798. + */
  116799. +#ifndef __BCM2708_H_
  116800. +#define __BCM2708_H_
  116801. +
  116802. +typedef enum {
  116803. + BCM2708_PULL_OFF,
  116804. + BCM2708_PULL_UP,
  116805. + BCM2708_PULL_DOWN
  116806. +} bcm2708_gpio_pull_t;
  116807. +
  116808. +extern int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
  116809. + bcm2708_gpio_pull_t value);
  116810. +
  116811. +#endif
  116812. diff -Nur linux-3.12.38/include/linux/pstore_ram.h linux-rpi/include/linux/pstore_ram.h
  116813. --- linux-3.12.38/include/linux/pstore_ram.h 2015-02-16 16:15:42.000000000 +0100
  116814. +++ linux-rpi/include/linux/pstore_ram.h 2015-03-10 17:26:51.630216685 +0100
  116815. @@ -53,8 +53,7 @@
  116816. };
  116817. struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
  116818. - u32 sig, struct persistent_ram_ecc_info *ecc_info,
  116819. - unsigned int memtype);
  116820. + u32 sig, struct persistent_ram_ecc_info *ecc_info);
  116821. void persistent_ram_free(struct persistent_ram_zone *prz);
  116822. void persistent_ram_zap(struct persistent_ram_zone *prz);
  116823. @@ -77,7 +76,6 @@
  116824. struct ramoops_platform_data {
  116825. unsigned long mem_size;
  116826. unsigned long mem_address;
  116827. - unsigned int mem_type;
  116828. unsigned long record_size;
  116829. unsigned long console_size;
  116830. unsigned long ftrace_size;
  116831. diff -Nur linux-3.12.38/include/linux/time.h linux-rpi/include/linux/time.h
  116832. --- linux-3.12.38/include/linux/time.h 2015-02-16 16:15:42.000000000 +0100
  116833. +++ linux-rpi/include/linux/time.h 2015-03-10 17:26:51.638216685 +0100
  116834. @@ -173,19 +173,6 @@
  116835. extern void monotonic_to_bootbased(struct timespec *ts);
  116836. extern void get_monotonic_boottime(struct timespec *ts);
  116837. -static inline bool timeval_valid(const struct timeval *tv)
  116838. -{
  116839. - /* Dates before 1970 are bogus */
  116840. - if (tv->tv_sec < 0)
  116841. - return false;
  116842. -
  116843. - /* Can't have more microseconds then a second */
  116844. - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
  116845. - return false;
  116846. -
  116847. - return true;
  116848. -}
  116849. -
  116850. extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
  116851. extern int timekeeping_valid_for_hres(void);
  116852. extern u64 timekeeping_max_deferment(void);
  116853. diff -Nur linux-3.12.38/include/linux/vmstat.h linux-rpi/include/linux/vmstat.h
  116854. --- linux-3.12.38/include/linux/vmstat.h 2015-02-16 16:15:42.000000000 +0100
  116855. +++ linux-rpi/include/linux/vmstat.h 2015-03-10 17:26:51.642216685 +0100
  116856. @@ -239,7 +239,11 @@
  116857. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  116858. {
  116859. atomic_long_dec(&zone->vm_stat[item]);
  116860. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&zone->vm_stat[item]) < 0))
  116861. + atomic_long_set(&zone->vm_stat[item], 0);
  116862. atomic_long_dec(&vm_stat[item]);
  116863. + if (item == NR_FILE_DIRTY && unlikely(atomic_long_read(&vm_stat[item]) < 0))
  116864. + atomic_long_set(&vm_stat[item], 0);
  116865. }
  116866. static inline void __dec_zone_page_state(struct page *page,
  116867. diff -Nur linux-3.12.38/include/net/ip.h linux-rpi/include/net/ip.h
  116868. --- linux-3.12.38/include/net/ip.h 2015-02-16 16:15:42.000000000 +0100
  116869. +++ linux-rpi/include/net/ip.h 2015-03-10 17:26:51.650216685 +0100
  116870. @@ -37,12 +37,11 @@
  116871. struct ip_options opt; /* Compiled IP options */
  116872. unsigned char flags;
  116873. -#define IPSKB_FORWARDED BIT(0)
  116874. -#define IPSKB_XFRM_TUNNEL_SIZE BIT(1)
  116875. -#define IPSKB_XFRM_TRANSFORMED BIT(2)
  116876. -#define IPSKB_FRAG_COMPLETE BIT(3)
  116877. -#define IPSKB_REROUTED BIT(4)
  116878. -#define IPSKB_DOREDIRECT BIT(5)
  116879. +#define IPSKB_FORWARDED 1
  116880. +#define IPSKB_XFRM_TUNNEL_SIZE 2
  116881. +#define IPSKB_XFRM_TRANSFORMED 4
  116882. +#define IPSKB_FRAG_COMPLETE 8
  116883. +#define IPSKB_REROUTED 16
  116884. u16 frag_max_size;
  116885. };
  116886. @@ -163,7 +162,7 @@
  116887. return (arg->flags & IP_REPLY_ARG_NOSRCCHECK) ? FLOWI_FLAG_ANYSRC : 0;
  116888. }
  116889. -void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, __be32 daddr,
  116890. +void ip_send_unicast_reply(struct net *net, struct sk_buff *skb, __be32 daddr,
  116891. __be32 saddr, const struct ip_reply_arg *arg,
  116892. unsigned int len);
  116893. diff -Nur linux-3.12.38/include/net/netns/ipv4.h linux-rpi/include/net/netns/ipv4.h
  116894. --- linux-3.12.38/include/net/netns/ipv4.h 2015-02-16 16:15:42.000000000 +0100
  116895. +++ linux-rpi/include/net/netns/ipv4.h 2015-03-10 17:26:51.654216685 +0100
  116896. @@ -43,7 +43,6 @@
  116897. struct inet_peer_base *peers;
  116898. struct tcpm_hash_bucket *tcp_metrics_hash;
  116899. unsigned int tcp_metrics_hash_log;
  116900. - struct sock * __percpu *tcp_sk;
  116901. struct netns_frags frags;
  116902. #ifdef CONFIG_NETFILTER
  116903. struct xt_table *iptable_filter;
  116904. diff -Nur linux-3.12.38/include/sound/ak4113.h linux-rpi/include/sound/ak4113.h
  116905. --- linux-3.12.38/include/sound/ak4113.h 2015-02-16 16:15:42.000000000 +0100
  116906. +++ linux-rpi/include/sound/ak4113.h 2015-03-10 17:26:51.662216685 +0100
  116907. @@ -286,7 +286,7 @@
  116908. ak4113_write_t *write;
  116909. ak4113_read_t *read;
  116910. void *private_data;
  116911. - atomic_t wq_processing;
  116912. + unsigned int init:1;
  116913. spinlock_t lock;
  116914. unsigned char regmap[AK4113_WRITABLE_REGS];
  116915. struct snd_kcontrol *kctls[AK4113_CONTROLS];
  116916. diff -Nur linux-3.12.38/include/sound/ak4114.h linux-rpi/include/sound/ak4114.h
  116917. --- linux-3.12.38/include/sound/ak4114.h 2015-02-16 16:15:42.000000000 +0100
  116918. +++ linux-rpi/include/sound/ak4114.h 2015-03-10 17:26:51.662216685 +0100
  116919. @@ -168,7 +168,7 @@
  116920. ak4114_write_t * write;
  116921. ak4114_read_t * read;
  116922. void * private_data;
  116923. - atomic_t wq_processing;
  116924. + unsigned int init: 1;
  116925. spinlock_t lock;
  116926. unsigned char regmap[7];
  116927. unsigned char txcsb[5];
  116928. diff -Nur linux-3.12.38/include/sound/soc-dai.h linux-rpi/include/sound/soc-dai.h
  116929. --- linux-3.12.38/include/sound/soc-dai.h 2015-02-16 16:15:42.000000000 +0100
  116930. +++ linux-rpi/include/sound/soc-dai.h 2015-03-10 17:26:51.666216685 +0100
  116931. @@ -105,6 +105,8 @@
  116932. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  116933. int pll_id, int source, unsigned int freq_in, unsigned int freq_out);
  116934. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
  116935. +
  116936. /* Digital Audio interface formatting */
  116937. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
  116938. @@ -131,6 +133,7 @@
  116939. int (*set_pll)(struct snd_soc_dai *dai, int pll_id, int source,
  116940. unsigned int freq_in, unsigned int freq_out);
  116941. int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
  116942. + int (*set_bclk_ratio)(struct snd_soc_dai *dai, unsigned int ratio);
  116943. /*
  116944. * DAI format configuration
  116945. diff -Nur linux-3.12.38/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  116946. --- linux-3.12.38/include/uapi/linux/fb.h 2015-02-16 16:15:42.000000000 +0100
  116947. +++ linux-rpi/include/uapi/linux/fb.h 2015-03-09 10:39:36.978893695 +0100
  116948. @@ -34,6 +34,11 @@
  116949. #define FBIOPUT_MODEINFO 0x4617
  116950. #define FBIOGET_DISPINFO 0x4618
  116951. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  116952. +/*
  116953. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  116954. + * be concurrently added to the mainline kernel
  116955. + */
  116956. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  116957. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  116958. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  116959. diff -Nur linux-3.12.38/include/uapi/linux/in6.h linux-rpi/include/uapi/linux/in6.h
  116960. --- linux-3.12.38/include/uapi/linux/in6.h 2015-02-16 16:15:42.000000000 +0100
  116961. +++ linux-rpi/include/uapi/linux/in6.h 2015-03-10 17:26:51.670216685 +0100
  116962. @@ -156,7 +156,7 @@
  116963. /*
  116964. * IPV6 socket options
  116965. */
  116966. -#if __UAPI_DEF_IPV6_OPTIONS
  116967. +
  116968. #define IPV6_ADDRFORM 1
  116969. #define IPV6_2292PKTINFO 2
  116970. #define IPV6_2292HOPOPTS 3
  116971. @@ -195,7 +195,6 @@
  116972. #define IPV6_IPSEC_POLICY 34
  116973. #define IPV6_XFRM_POLICY 35
  116974. -#endif
  116975. /*
  116976. * Multicast:
  116977. diff -Nur linux-3.12.38/include/uapi/linux/libc-compat.h linux-rpi/include/uapi/linux/libc-compat.h
  116978. --- linux-3.12.38/include/uapi/linux/libc-compat.h 2015-02-16 16:15:42.000000000 +0100
  116979. +++ linux-rpi/include/uapi/linux/libc-compat.h 2015-03-10 17:26:51.674216685 +0100
  116980. @@ -69,7 +69,6 @@
  116981. #define __UAPI_DEF_SOCKADDR_IN6 0
  116982. #define __UAPI_DEF_IPV6_MREQ 0
  116983. #define __UAPI_DEF_IPPROTO_V6 0
  116984. -#define __UAPI_DEF_IPV6_OPTIONS 0
  116985. #else
  116986. @@ -83,7 +82,6 @@
  116987. #define __UAPI_DEF_SOCKADDR_IN6 1
  116988. #define __UAPI_DEF_IPV6_MREQ 1
  116989. #define __UAPI_DEF_IPPROTO_V6 1
  116990. -#define __UAPI_DEF_IPV6_OPTIONS 1
  116991. #endif /* _NETINET_IN_H */
  116992. @@ -105,7 +103,6 @@
  116993. #define __UAPI_DEF_SOCKADDR_IN6 1
  116994. #define __UAPI_DEF_IPV6_MREQ 1
  116995. #define __UAPI_DEF_IPPROTO_V6 1
  116996. -#define __UAPI_DEF_IPV6_OPTIONS 1
  116997. /* Definitions for xattr.h */
  116998. #define __UAPI_DEF_XATTR 1
  116999. diff -Nur linux-3.12.38/ipc/compat.c linux-rpi/ipc/compat.c
  117000. --- linux-3.12.38/ipc/compat.c 2015-02-16 16:15:42.000000000 +0100
  117001. +++ linux-rpi/ipc/compat.c 2015-03-10 17:26:51.682216685 +0100
  117002. @@ -381,7 +381,7 @@
  117003. uptr = compat_ptr(ipck.msgp);
  117004. fifth = ipck.msgtyp;
  117005. }
  117006. - return do_msgrcv(first, uptr, second, (s32)fifth, third,
  117007. + return do_msgrcv(first, uptr, second, fifth, third,
  117008. compat_do_msg_fill);
  117009. }
  117010. case MSGGET:
  117011. @@ -430,9 +430,9 @@
  117012. }
  117013. COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
  117014. - compat_ssize_t, msgsz, compat_long_t, msgtyp, int, msgflg)
  117015. + compat_ssize_t, msgsz, long, msgtyp, int, msgflg)
  117016. {
  117017. - return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, (long)msgtyp,
  117018. + return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, msgtyp,
  117019. msgflg, compat_do_msg_fill);
  117020. }
  117021. diff -Nur linux-3.12.38/ipc/sem.c linux-rpi/ipc/sem.c
  117022. --- linux-3.12.38/ipc/sem.c 2015-02-16 16:15:42.000000000 +0100
  117023. +++ linux-rpi/ipc/sem.c 2015-03-10 17:26:51.682216685 +0100
  117024. @@ -326,17 +326,10 @@
  117025. /* Then check that the global lock is free */
  117026. if (!spin_is_locked(&sma->sem_perm.lock)) {
  117027. - /*
  117028. - * The ipc object lock check must be visible on all
  117029. - * cores before rechecking the complex count. Otherwise
  117030. - * we can race with another thread that does:
  117031. - * complex_count++;
  117032. - * spin_unlock(sem_perm.lock);
  117033. - */
  117034. - smp_rmb();
  117035. + /* spin_is_locked() is not a memory barrier */
  117036. + smp_mb();
  117037. - /*
  117038. - * Now repeat the test of complex_count:
  117039. + /* Now repeat the test of complex_count:
  117040. * It can't change anymore until we drop sem->lock.
  117041. * Thus: if is now 0, then it will stay 0.
  117042. */
  117043. diff -Nur linux-3.12.38/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  117044. --- linux-3.12.38/kernel/cgroup.c 2015-02-16 16:15:42.000000000 +0100
  117045. +++ linux-rpi/kernel/cgroup.c 2015-03-10 17:26:51.686216685 +0100
  117046. @@ -1012,7 +1012,7 @@
  117047. parent = dentry->d_parent;
  117048. spin_lock(&parent->d_lock);
  117049. spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
  117050. - list_del_init(&dentry->d_child);
  117051. + list_del_init(&dentry->d_u.d_child);
  117052. spin_unlock(&dentry->d_lock);
  117053. spin_unlock(&parent->d_lock);
  117054. remove_dir(dentry);
  117055. @@ -5558,6 +5558,33 @@
  117056. }
  117057. __setup("cgroup_disable=", cgroup_disable);
  117058. +static int __init cgroup_enable(char *str)
  117059. +{
  117060. + struct cgroup_subsys *ss;
  117061. + char *token;
  117062. + int i;
  117063. +
  117064. + while ((token = strsep(&str, ",")) != NULL) {
  117065. + if (!*token)
  117066. + continue;
  117067. +
  117068. + /*
  117069. + * cgroup_disable, being at boot time, can't know about
  117070. + * module subsystems, so we don't worry about them.
  117071. + */
  117072. + for_each_builtin_subsys(ss, i) {
  117073. + if (!strcmp(token, ss->name)) {
  117074. + ss->disabled = 0;
  117075. + printk(KERN_INFO "Disabling %s control group"
  117076. + " subsystem\n", ss->name);
  117077. + break;
  117078. + }
  117079. + }
  117080. + }
  117081. + return 1;
  117082. +}
  117083. +__setup("cgroup_enable=", cgroup_enable);
  117084. +
  117085. /*
  117086. * Functons for CSS ID.
  117087. */
  117088. diff -Nur linux-3.12.38/kernel/events/core.c linux-rpi/kernel/events/core.c
  117089. --- linux-3.12.38/kernel/events/core.c 2015-02-16 16:15:42.000000000 +0100
  117090. +++ linux-rpi/kernel/events/core.c 2015-03-10 17:26:51.690216685 +0100
  117091. @@ -7167,11 +7167,11 @@
  117092. if (move_group) {
  117093. synchronize_rcu();
  117094. - perf_install_in_context(ctx, group_leader, group_leader->cpu);
  117095. + perf_install_in_context(ctx, group_leader, event->cpu);
  117096. get_ctx(ctx);
  117097. list_for_each_entry(sibling, &group_leader->sibling_list,
  117098. group_entry) {
  117099. - perf_install_in_context(ctx, sibling, sibling->cpu);
  117100. + perf_install_in_context(ctx, sibling, event->cpu);
  117101. get_ctx(ctx);
  117102. }
  117103. }
  117104. diff -Nur linux-3.12.38/kernel/irq/internals.h linux-rpi/kernel/irq/internals.h
  117105. --- linux-3.12.38/kernel/irq/internals.h 2015-02-16 16:15:42.000000000 +0100
  117106. +++ linux-rpi/kernel/irq/internals.h 2015-03-10 17:26:51.690216685 +0100
  117107. @@ -74,14 +74,6 @@
  117108. extern void mask_irq(struct irq_desc *desc);
  117109. extern void unmask_irq(struct irq_desc *desc);
  117110. -#ifdef CONFIG_SPARSE_IRQ
  117111. -extern void irq_lock_sparse(void);
  117112. -extern void irq_unlock_sparse(void);
  117113. -#else
  117114. -static inline void irq_lock_sparse(void) { }
  117115. -static inline void irq_unlock_sparse(void) { }
  117116. -#endif
  117117. -
  117118. extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
  117119. irqreturn_t handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action);
  117120. diff -Nur linux-3.12.38/kernel/irq/irqdesc.c linux-rpi/kernel/irq/irqdesc.c
  117121. --- linux-3.12.38/kernel/irq/irqdesc.c 2015-02-16 16:15:42.000000000 +0100
  117122. +++ linux-rpi/kernel/irq/irqdesc.c 2015-03-10 17:26:51.694216685 +0100
  117123. @@ -131,16 +131,6 @@
  117124. static inline void free_masks(struct irq_desc *desc) { }
  117125. #endif
  117126. -void irq_lock_sparse(void)
  117127. -{
  117128. - mutex_lock(&sparse_irq_lock);
  117129. -}
  117130. -
  117131. -void irq_unlock_sparse(void)
  117132. -{
  117133. - mutex_unlock(&sparse_irq_lock);
  117134. -}
  117135. -
  117136. static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
  117137. {
  117138. struct irq_desc *desc;
  117139. @@ -177,12 +167,6 @@
  117140. unregister_irq_proc(irq, desc);
  117141. - /*
  117142. - * sparse_irq_lock protects also show_interrupts() and
  117143. - * kstat_irq_usr(). Once we deleted the descriptor from the
  117144. - * sparse tree we can free it. Access in proc will fail to
  117145. - * lookup the descriptor.
  117146. - */
  117147. mutex_lock(&sparse_irq_lock);
  117148. delete_irq_desc(irq);
  117149. mutex_unlock(&sparse_irq_lock);
  117150. @@ -505,15 +489,6 @@
  117151. raw_spin_unlock_irqrestore(&desc->lock, flags);
  117152. }
  117153. -/**
  117154. - * kstat_irqs_cpu - Get the statistics for an interrupt on a cpu
  117155. - * @irq: The interrupt number
  117156. - * @cpu: The cpu number
  117157. - *
  117158. - * Returns the sum of interrupt counts on @cpu since boot for
  117159. - * @irq. The caller must ensure that the interrupt is not removed
  117160. - * concurrently.
  117161. - */
  117162. unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  117163. {
  117164. struct irq_desc *desc = irq_to_desc(irq);
  117165. @@ -522,14 +497,6 @@
  117166. *per_cpu_ptr(desc->kstat_irqs, cpu) : 0;
  117167. }
  117168. -/**
  117169. - * kstat_irqs - Get the statistics for an interrupt
  117170. - * @irq: The interrupt number
  117171. - *
  117172. - * Returns the sum of interrupt counts on all cpus since boot for
  117173. - * @irq. The caller must ensure that the interrupt is not removed
  117174. - * concurrently.
  117175. - */
  117176. unsigned int kstat_irqs(unsigned int irq)
  117177. {
  117178. struct irq_desc *desc = irq_to_desc(irq);
  117179. @@ -542,22 +509,3 @@
  117180. sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
  117181. return sum;
  117182. }
  117183. -
  117184. -/**
  117185. - * kstat_irqs_usr - Get the statistics for an interrupt
  117186. - * @irq: The interrupt number
  117187. - *
  117188. - * Returns the sum of interrupt counts on all cpus since boot for
  117189. - * @irq. Contrary to kstat_irqs() this can be called from any
  117190. - * preemptible context. It's protected against concurrent removal of
  117191. - * an interrupt descriptor when sparse irqs are enabled.
  117192. - */
  117193. -unsigned int kstat_irqs_usr(unsigned int irq)
  117194. -{
  117195. - int sum;
  117196. -
  117197. - irq_lock_sparse();
  117198. - sum = kstat_irqs(irq);
  117199. - irq_unlock_sparse();
  117200. - return sum;
  117201. -}
  117202. diff -Nur linux-3.12.38/kernel/irq/proc.c linux-rpi/kernel/irq/proc.c
  117203. --- linux-3.12.38/kernel/irq/proc.c 2015-02-16 16:15:42.000000000 +0100
  117204. +++ linux-rpi/kernel/irq/proc.c 2015-03-10 17:26:51.694216685 +0100
  117205. @@ -15,23 +15,6 @@
  117206. #include "internals.h"
  117207. -/*
  117208. - * Access rules:
  117209. - *
  117210. - * procfs protects read/write of /proc/irq/N/ files against a
  117211. - * concurrent free of the interrupt descriptor. remove_proc_entry()
  117212. - * immediately prevents new read/writes to happen and waits for
  117213. - * already running read/write functions to complete.
  117214. - *
  117215. - * We remove the proc entries first and then delete the interrupt
  117216. - * descriptor from the radix tree and free it. So it is guaranteed
  117217. - * that irq_to_desc(N) is valid as long as the read/writes are
  117218. - * permitted by procfs.
  117219. - *
  117220. - * The read from /proc/interrupts is a different problem because there
  117221. - * is no protection. So the lookup and the access to irqdesc
  117222. - * information must be protected by sparse_irq_lock.
  117223. - */
  117224. static struct proc_dir_entry *root_irq_dir;
  117225. #ifdef CONFIG_SMP
  117226. @@ -454,10 +437,9 @@
  117227. seq_putc(p, '\n');
  117228. }
  117229. - irq_lock_sparse();
  117230. desc = irq_to_desc(i);
  117231. if (!desc)
  117232. - goto outsparse;
  117233. + return 0;
  117234. raw_spin_lock_irqsave(&desc->lock, flags);
  117235. for_each_online_cpu(j)
  117236. @@ -497,8 +479,6 @@
  117237. seq_putc(p, '\n');
  117238. out:
  117239. raw_spin_unlock_irqrestore(&desc->lock, flags);
  117240. -outsparse:
  117241. - irq_unlock_sparse();
  117242. return 0;
  117243. }
  117244. #endif
  117245. diff -Nur linux-3.12.38/kernel/smpboot.c linux-rpi/kernel/smpboot.c
  117246. --- linux-3.12.38/kernel/smpboot.c 2015-02-16 16:15:42.000000000 +0100
  117247. +++ linux-rpi/kernel/smpboot.c 2015-03-10 17:26:51.706216685 +0100
  117248. @@ -279,7 +279,6 @@
  117249. unsigned int cpu;
  117250. int ret = 0;
  117251. - get_online_cpus();
  117252. mutex_lock(&smpboot_threads_lock);
  117253. for_each_online_cpu(cpu) {
  117254. ret = __smpboot_create_thread(plug_thread, cpu);
  117255. @@ -292,7 +291,6 @@
  117256. list_add(&plug_thread->list, &hotplug_threads);
  117257. out:
  117258. mutex_unlock(&smpboot_threads_lock);
  117259. - put_online_cpus();
  117260. return ret;
  117261. }
  117262. EXPORT_SYMBOL_GPL(smpboot_register_percpu_thread);
  117263. diff -Nur linux-3.12.38/kernel/time/ntp.c linux-rpi/kernel/time/ntp.c
  117264. --- linux-3.12.38/kernel/time/ntp.c 2015-02-16 16:15:42.000000000 +0100
  117265. +++ linux-rpi/kernel/time/ntp.c 2015-03-10 17:26:51.706216685 +0100
  117266. @@ -631,13 +631,6 @@
  117267. if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
  117268. return -EPERM;
  117269. - if (txc->modes & ADJ_FREQUENCY) {
  117270. - if (LONG_MIN / PPM_SCALE > txc->freq)
  117271. - return -EINVAL;
  117272. - if (LONG_MAX / PPM_SCALE < txc->freq)
  117273. - return -EINVAL;
  117274. - }
  117275. -
  117276. return 0;
  117277. }
  117278. diff -Nur linux-3.12.38/kernel/time/tick-sched.c linux-rpi/kernel/time/tick-sched.c
  117279. --- linux-3.12.38/kernel/time/tick-sched.c 2015-02-16 16:15:42.000000000 +0100
  117280. +++ linux-rpi/kernel/time/tick-sched.c 2015-03-10 17:26:51.710216685 +0100
  117281. @@ -806,6 +806,7 @@
  117282. local_irq_enable();
  117283. }
  117284. +EXPORT_SYMBOL_GPL(tick_nohz_idle_enter);
  117285. /**
  117286. * tick_nohz_irq_exit - update next tick event from interrupt exit
  117287. @@ -933,6 +934,7 @@
  117288. local_irq_enable();
  117289. }
  117290. +EXPORT_SYMBOL_GPL(tick_nohz_idle_exit);
  117291. static int tick_nohz_reprogram(struct tick_sched *ts, ktime_t now)
  117292. {
  117293. diff -Nur linux-3.12.38/kernel/time.c linux-rpi/kernel/time.c
  117294. --- linux-3.12.38/kernel/time.c 2015-02-16 16:15:42.000000000 +0100
  117295. +++ linux-rpi/kernel/time.c 2015-03-10 17:26:51.706216685 +0100
  117296. @@ -195,10 +195,6 @@
  117297. if (tv) {
  117298. if (copy_from_user(&user_tv, tv, sizeof(*tv)))
  117299. return -EFAULT;
  117300. -
  117301. - if (!timeval_valid(&user_tv))
  117302. - return -EINVAL;
  117303. -
  117304. new_ts.tv_sec = user_tv.tv_sec;
  117305. new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC;
  117306. }
  117307. diff -Nur linux-3.12.38/kernel/trace/trace.c linux-rpi/kernel/trace/trace.c
  117308. --- linux-3.12.38/kernel/trace/trace.c 2015-02-16 16:15:42.000000000 +0100
  117309. +++ linux-rpi/kernel/trace/trace.c 2015-03-10 17:26:51.710216685 +0100
  117310. @@ -6063,7 +6063,7 @@
  117311. int ret;
  117312. /* Paranoid: Make sure the parent is the "instances" directory */
  117313. - parent = hlist_entry(inode->i_dentry.first, struct dentry, d_u.d_alias);
  117314. + parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
  117315. if (WARN_ON_ONCE(parent != trace_instance_dir))
  117316. return -ENOENT;
  117317. @@ -6090,7 +6090,7 @@
  117318. int ret;
  117319. /* Paranoid: Make sure the parent is the "instances" directory */
  117320. - parent = hlist_entry(inode->i_dentry.first, struct dentry, d_u.d_alias);
  117321. + parent = hlist_entry(inode->i_dentry.first, struct dentry, d_alias);
  117322. if (WARN_ON_ONCE(parent != trace_instance_dir))
  117323. return -ENOENT;
  117324. diff -Nur linux-3.12.38/kernel/trace/trace_events.c linux-rpi/kernel/trace/trace_events.c
  117325. --- linux-3.12.38/kernel/trace/trace_events.c 2015-02-16 16:15:42.000000000 +0100
  117326. +++ linux-rpi/kernel/trace/trace_events.c 2015-03-10 17:26:51.710216685 +0100
  117327. @@ -427,7 +427,7 @@
  117328. if (dir) {
  117329. spin_lock(&dir->d_lock); /* probably unneeded */
  117330. - list_for_each_entry(child, &dir->d_subdirs, d_child) {
  117331. + list_for_each_entry(child, &dir->d_subdirs, d_u.d_child) {
  117332. if (child->d_inode) /* probably unneeded */
  117333. child->d_inode->i_private = NULL;
  117334. }
  117335. diff -Nur linux-3.12.38/kernel/workqueue.c linux-rpi/kernel/workqueue.c
  117336. --- linux-3.12.38/kernel/workqueue.c 2015-02-16 16:15:42.000000000 +0100
  117337. +++ linux-rpi/kernel/workqueue.c 2015-03-10 17:26:51.714216685 +0100
  117338. @@ -1954,13 +1954,17 @@
  117339. * spin_lock_irq(pool->lock) which may be released and regrabbed
  117340. * multiple times. Does GFP_KERNEL allocations. Called only from
  117341. * manager.
  117342. + *
  117343. + * Return:
  117344. + * %false if no action was taken and pool->lock stayed locked, %true
  117345. + * otherwise.
  117346. */
  117347. -static void maybe_create_worker(struct worker_pool *pool)
  117348. +static bool maybe_create_worker(struct worker_pool *pool)
  117349. __releases(&pool->lock)
  117350. __acquires(&pool->lock)
  117351. {
  117352. if (!need_to_create_worker(pool))
  117353. - return;
  117354. + return false;
  117355. restart:
  117356. spin_unlock_irq(&pool->lock);
  117357. @@ -1977,7 +1981,7 @@
  117358. start_worker(worker);
  117359. if (WARN_ON_ONCE(need_to_create_worker(pool)))
  117360. goto restart;
  117361. - return;
  117362. + return true;
  117363. }
  117364. if (!need_to_create_worker(pool))
  117365. @@ -1994,7 +1998,7 @@
  117366. spin_lock_irq(&pool->lock);
  117367. if (need_to_create_worker(pool))
  117368. goto restart;
  117369. - return;
  117370. + return true;
  117371. }
  117372. /**
  117373. @@ -2007,9 +2011,15 @@
  117374. * LOCKING:
  117375. * spin_lock_irq(pool->lock) which may be released and regrabbed
  117376. * multiple times. Called only from manager.
  117377. + *
  117378. + * Return:
  117379. + * %false if no action was taken and pool->lock stayed locked, %true
  117380. + * otherwise.
  117381. */
  117382. -static void maybe_destroy_workers(struct worker_pool *pool)
  117383. +static bool maybe_destroy_workers(struct worker_pool *pool)
  117384. {
  117385. + bool ret = false;
  117386. +
  117387. while (too_many_workers(pool)) {
  117388. struct worker *worker;
  117389. unsigned long expires;
  117390. @@ -2023,7 +2033,10 @@
  117391. }
  117392. destroy_worker(worker);
  117393. + ret = true;
  117394. }
  117395. +
  117396. + return ret;
  117397. }
  117398. /**
  117399. @@ -2043,14 +2056,16 @@
  117400. * multiple times. Does GFP_KERNEL allocations.
  117401. *
  117402. * Return:
  117403. - * %false if the pool doesn't need management and the caller can safely
  117404. - * start processing works, %true if management function was performed and
  117405. - * the conditions that the caller verified before calling the function may
  117406. - * no longer be true.
  117407. + * %false if the pool don't need management and the caller can safely start
  117408. + * processing works, %true indicates that the function released pool->lock
  117409. + * and reacquired it to perform some management function and that the
  117410. + * conditions that the caller verified while holding the lock before
  117411. + * calling the function might no longer be true.
  117412. */
  117413. static bool manage_workers(struct worker *worker)
  117414. {
  117415. struct worker_pool *pool = worker->pool;
  117416. + bool ret = false;
  117417. /*
  117418. * Managership is governed by two mutexes - manager_arb and
  117419. @@ -2074,7 +2089,7 @@
  117420. * manager_mutex.
  117421. */
  117422. if (!mutex_trylock(&pool->manager_arb))
  117423. - return false;
  117424. + return ret;
  117425. /*
  117426. * With manager arbitration won, manager_mutex would be free in
  117427. @@ -2084,6 +2099,7 @@
  117428. spin_unlock_irq(&pool->lock);
  117429. mutex_lock(&pool->manager_mutex);
  117430. spin_lock_irq(&pool->lock);
  117431. + ret = true;
  117432. }
  117433. pool->flags &= ~POOL_MANAGE_WORKERS;
  117434. @@ -2092,12 +2108,12 @@
  117435. * Destroy and then create so that may_start_working() is true
  117436. * on return.
  117437. */
  117438. - maybe_destroy_workers(pool);
  117439. - maybe_create_worker(pool);
  117440. + ret |= maybe_destroy_workers(pool);
  117441. + ret |= maybe_create_worker(pool);
  117442. mutex_unlock(&pool->manager_mutex);
  117443. mutex_unlock(&pool->manager_arb);
  117444. - return true;
  117445. + return ret;
  117446. }
  117447. /**
  117448. diff -Nur linux-3.12.38/lib/checksum.c linux-rpi/lib/checksum.c
  117449. --- linux-3.12.38/lib/checksum.c 2015-02-16 16:15:42.000000000 +0100
  117450. +++ linux-rpi/lib/checksum.c 2015-03-10 17:26:51.718216685 +0100
  117451. @@ -181,15 +181,6 @@
  117452. EXPORT_SYMBOL(csum_partial_copy);
  117453. #ifndef csum_tcpudp_nofold
  117454. -static inline u32 from64to32(u64 x)
  117455. -{
  117456. - /* add up 32-bit and 32-bit for 32+c bit */
  117457. - x = (x & 0xffffffff) + (x >> 32);
  117458. - /* add up carry.. */
  117459. - x = (x & 0xffffffff) + (x >> 32);
  117460. - return (u32)x;
  117461. -}
  117462. -
  117463. __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
  117464. unsigned short len,
  117465. unsigned short proto,
  117466. @@ -204,7 +195,8 @@
  117467. #else
  117468. s += (proto + len) << 8;
  117469. #endif
  117470. - return (__force __wsum)from64to32(s);
  117471. + s += (s >> 32);
  117472. + return (__force __wsum)s;
  117473. }
  117474. EXPORT_SYMBOL(csum_tcpudp_nofold);
  117475. #endif
  117476. diff -Nur linux-3.12.38/lib/decompress_bunzip2.c linux-rpi/lib/decompress_bunzip2.c
  117477. --- linux-3.12.38/lib/decompress_bunzip2.c 2015-02-16 16:15:42.000000000 +0100
  117478. +++ linux-rpi/lib/decompress_bunzip2.c 2015-03-10 17:26:51.718216685 +0100
  117479. @@ -184,7 +184,7 @@
  117480. if (get_bits(bd, 1))
  117481. return RETVAL_OBSOLETE_INPUT;
  117482. origPtr = get_bits(bd, 24);
  117483. - if (origPtr >= dbufSize)
  117484. + if (origPtr > dbufSize)
  117485. return RETVAL_DATA_ERROR;
  117486. /* mapping table: if some byte values are never used (encoding things
  117487. like ascii text), the compression code removes the gaps to have fewer
  117488. diff -Nur linux-3.12.38/mm/filemap.c linux-rpi/mm/filemap.c
  117489. --- linux-3.12.38/mm/filemap.c 2015-02-16 16:15:42.000000000 +0100
  117490. +++ linux-rpi/mm/filemap.c 2015-03-10 17:26:51.722216685 +0100
  117491. @@ -897,7 +897,7 @@
  117492. * @mapping: the address_space to search
  117493. * @offset: the page index
  117494. * @fgp_flags: PCG flags
  117495. - * @gfp_mask: gfp mask to use for the page cache data page allocation
  117496. + * @gfp_mask: gfp mask to use if a page is to be allocated
  117497. *
  117498. * Looks up the page cache slot at @mapping & @offset.
  117499. *
  117500. @@ -916,7 +916,7 @@
  117501. * If there is a page cache page, it is returned with an increased refcount.
  117502. */
  117503. struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
  117504. - int fgp_flags, gfp_t gfp_mask)
  117505. + int fgp_flags, gfp_t cache_gfp_mask, gfp_t radix_gfp_mask)
  117506. {
  117507. struct page *page;
  117508. @@ -953,11 +953,13 @@
  117509. if (!page && (fgp_flags & FGP_CREAT)) {
  117510. int err;
  117511. if ((fgp_flags & FGP_WRITE) && mapping_cap_account_dirty(mapping))
  117512. - gfp_mask |= __GFP_WRITE;
  117513. - if (fgp_flags & FGP_NOFS)
  117514. - gfp_mask &= ~__GFP_FS;
  117515. + cache_gfp_mask |= __GFP_WRITE;
  117516. + if (fgp_flags & FGP_NOFS) {
  117517. + cache_gfp_mask &= ~__GFP_FS;
  117518. + radix_gfp_mask &= ~__GFP_FS;
  117519. + }
  117520. - page = __page_cache_alloc(gfp_mask);
  117521. + page = __page_cache_alloc(cache_gfp_mask);
  117522. if (!page)
  117523. return NULL;
  117524. @@ -968,8 +970,7 @@
  117525. if (fgp_flags & FGP_ACCESSED)
  117526. init_page_accessed(page);
  117527. - err = add_to_page_cache_lru(page, mapping, offset,
  117528. - gfp_mask & GFP_RECLAIM_MASK);
  117529. + err = add_to_page_cache_lru(page, mapping, offset, radix_gfp_mask);
  117530. if (unlikely(err)) {
  117531. page_cache_release(page);
  117532. page = NULL;
  117533. @@ -2461,7 +2462,8 @@
  117534. fgp_flags |= FGP_NOFS;
  117535. page = pagecache_get_page(mapping, index, fgp_flags,
  117536. - mapping_gfp_mask(mapping));
  117537. + mapping_gfp_mask(mapping),
  117538. + GFP_KERNEL);
  117539. if (page)
  117540. wait_for_stable_page(page);
  117541. diff -Nur linux-3.12.38/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  117542. --- linux-3.12.38/mm/memcontrol.c 2015-02-16 16:15:42.000000000 +0100
  117543. +++ linux-rpi/mm/memcontrol.c 2015-03-10 17:26:51.726216685 +0100
  117544. @@ -7066,6 +7066,7 @@
  117545. .base_cftypes = mem_cgroup_files,
  117546. .early_init = 0,
  117547. .use_id = 1,
  117548. + .disabled = 1,
  117549. };
  117550. #ifdef CONFIG_MEMCG_SWAP
  117551. diff -Nur linux-3.12.38/mm/memory.c linux-rpi/mm/memory.c
  117552. --- linux-3.12.38/mm/memory.c 2015-02-16 16:15:42.000000000 +0100
  117553. +++ linux-rpi/mm/memory.c 2015-03-10 17:26:51.730216685 +0100
  117554. @@ -3194,7 +3194,7 @@
  117555. if (prev && prev->vm_end == address)
  117556. return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
  117557. - return expand_downwards(vma, address - PAGE_SIZE);
  117558. + expand_downwards(vma, address - PAGE_SIZE);
  117559. }
  117560. if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
  117561. struct vm_area_struct *next = vma->vm_next;
  117562. @@ -3203,7 +3203,7 @@
  117563. if (next && next->vm_start == address + PAGE_SIZE)
  117564. return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
  117565. - return expand_upwards(vma, address + PAGE_SIZE);
  117566. + expand_upwards(vma, address + PAGE_SIZE);
  117567. }
  117568. return 0;
  117569. }
  117570. diff -Nur linux-3.12.38/mm/mmap.c linux-rpi/mm/mmap.c
  117571. --- linux-3.12.38/mm/mmap.c 2015-02-16 16:15:42.000000000 +0100
  117572. +++ linux-rpi/mm/mmap.c 2015-03-10 17:26:51.730216685 +0100
  117573. @@ -2049,17 +2049,14 @@
  117574. {
  117575. struct mm_struct *mm = vma->vm_mm;
  117576. struct rlimit *rlim = current->signal->rlim;
  117577. - unsigned long new_start, actual_size;
  117578. + unsigned long new_start;
  117579. /* address space limit tests */
  117580. if (!may_expand_vm(mm, grow))
  117581. return -ENOMEM;
  117582. /* Stack limit test */
  117583. - actual_size = size;
  117584. - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
  117585. - actual_size -= PAGE_SIZE;
  117586. - if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
  117587. + if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
  117588. return -ENOMEM;
  117589. /* mlock limit tests */
  117590. diff -Nur linux-3.12.38/mm/pagewalk.c linux-rpi/mm/pagewalk.c
  117591. --- linux-3.12.38/mm/pagewalk.c 2015-02-16 16:15:42.000000000 +0100
  117592. +++ linux-rpi/mm/pagewalk.c 2015-03-10 17:26:51.734216685 +0100
  117593. @@ -199,10 +199,7 @@
  117594. */
  117595. if ((vma->vm_start <= addr) &&
  117596. (vma->vm_flags & VM_PFNMAP)) {
  117597. - if (walk->pte_hole)
  117598. - err = walk->pte_hole(addr, next, walk);
  117599. - if (err)
  117600. - break;
  117601. + next = vma->vm_end;
  117602. pgd = pgd_offset(walk->mm, next);
  117603. continue;
  117604. }
  117605. diff -Nur linux-3.12.38/mm/vmscan.c linux-rpi/mm/vmscan.c
  117606. --- linux-3.12.38/mm/vmscan.c 2015-02-16 16:15:42.000000000 +0100
  117607. +++ linux-rpi/mm/vmscan.c 2015-03-10 17:26:51.738216685 +0100
  117608. @@ -2868,20 +2868,18 @@
  117609. return false;
  117610. /*
  117611. - * The throttled processes are normally woken up in balance_pgdat() as
  117612. - * soon as pfmemalloc_watermark_ok() is true. But there is a potential
  117613. - * race between when kswapd checks the watermarks and a process gets
  117614. - * throttled. There is also a potential race if processes get
  117615. - * throttled, kswapd wakes, a large process exits thereby balancing the
  117616. - * zones, which causes kswapd to exit balance_pgdat() before reaching
  117617. - * the wake up checks. If kswapd is going to sleep, no process should
  117618. - * be sleeping on pfmemalloc_wait, so wake them now if necessary. If
  117619. - * the wake up is premature, processes will wake kswapd and get
  117620. - * throttled again. The difference from wake ups in balance_pgdat() is
  117621. - * that here we are under prepare_to_wait().
  117622. + * There is a potential race between when kswapd checks its watermarks
  117623. + * and a process gets throttled. There is also a potential race if
  117624. + * processes get throttled, kswapd wakes, a large process exits therby
  117625. + * balancing the zones that causes kswapd to miss a wakeup. If kswapd
  117626. + * is going to sleep, no process should be sleeping on pfmemalloc_wait
  117627. + * so wake them now if necessary. If necessary, processes will wake
  117628. + * kswapd and get throttled again
  117629. */
  117630. - if (waitqueue_active(&pgdat->pfmemalloc_wait))
  117631. - wake_up_all(&pgdat->pfmemalloc_wait);
  117632. + if (waitqueue_active(&pgdat->pfmemalloc_wait)) {
  117633. + wake_up(&pgdat->pfmemalloc_wait);
  117634. + return false;
  117635. + }
  117636. return pgdat_balanced(pgdat, order, classzone_idx);
  117637. }
  117638. diff -Nur linux-3.12.38/net/core/dev.c linux-rpi/net/core/dev.c
  117639. --- linux-3.12.38/net/core/dev.c 2015-02-16 16:15:42.000000000 +0100
  117640. +++ linux-rpi/net/core/dev.c 2015-03-10 17:26:51.758216685 +0100
  117641. @@ -1698,7 +1698,6 @@
  117642. skb_scrub_packet(skb, true);
  117643. skb->protocol = eth_type_trans(skb, dev);
  117644. - skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
  117645. return netif_rx(skb);
  117646. }
  117647. @@ -2505,14 +2504,11 @@
  117648. if (skb_shinfo(skb)->gso_segs > dev->gso_max_segs)
  117649. features &= ~NETIF_F_GSO_MASK;
  117650. - if (!vlan_tx_tag_present(skb)) {
  117651. - if (unlikely(protocol == htons(ETH_P_8021Q) ||
  117652. - protocol == htons(ETH_P_8021AD))) {
  117653. - struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
  117654. - protocol = veh->h_vlan_encapsulated_proto;
  117655. - } else {
  117656. - return harmonize_features(skb, dev, features);
  117657. - }
  117658. + if (protocol == htons(ETH_P_8021Q) || protocol == htons(ETH_P_8021AD)) {
  117659. + struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
  117660. + protocol = veh->h_vlan_encapsulated_proto;
  117661. + } else if (!vlan_tx_tag_present(skb)) {
  117662. + return harmonize_features(skb, dev, features);
  117663. }
  117664. features = netdev_intersect_features(features,
  117665. @@ -6405,20 +6401,10 @@
  117666. oldsd->output_queue = NULL;
  117667. oldsd->output_queue_tailp = &oldsd->output_queue;
  117668. }
  117669. - /* Append NAPI poll list from offline CPU, with one exception :
  117670. - * process_backlog() must be called by cpu owning percpu backlog.
  117671. - * We properly handle process_queue & input_pkt_queue later.
  117672. - */
  117673. - while (!list_empty(&oldsd->poll_list)) {
  117674. - struct napi_struct *napi = list_first_entry(&oldsd->poll_list,
  117675. - struct napi_struct,
  117676. - poll_list);
  117677. -
  117678. - list_del_init(&napi->poll_list);
  117679. - if (napi->poll == process_backlog)
  117680. - napi->state = 0;
  117681. - else
  117682. - ____napi_schedule(sd, napi);
  117683. + /* Append NAPI poll list from offline CPU. */
  117684. + if (!list_empty(&oldsd->poll_list)) {
  117685. + list_splice_init(&oldsd->poll_list, &sd->poll_list);
  117686. + raise_softirq_irqoff(NET_RX_SOFTIRQ);
  117687. }
  117688. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  117689. @@ -6429,7 +6415,7 @@
  117690. netif_rx(skb);
  117691. input_queue_head_incr(oldsd);
  117692. }
  117693. - while ((skb = skb_dequeue(&oldsd->input_pkt_queue))) {
  117694. + while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) {
  117695. netif_rx(skb);
  117696. input_queue_head_incr(oldsd);
  117697. }
  117698. diff -Nur linux-3.12.38/net/core/rtnetlink.c linux-rpi/net/core/rtnetlink.c
  117699. --- linux-3.12.38/net/core/rtnetlink.c 2015-02-16 16:15:42.000000000 +0100
  117700. +++ linux-rpi/net/core/rtnetlink.c 2015-03-10 17:26:51.762216685 +0100
  117701. @@ -2542,16 +2542,12 @@
  117702. goto errout;
  117703. }
  117704. - if (!skb->len)
  117705. - goto errout;
  117706. -
  117707. rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
  117708. return 0;
  117709. errout:
  117710. WARN_ON(err == -EMSGSIZE);
  117711. kfree_skb(skb);
  117712. - if (err)
  117713. - rtnl_set_sk_err(net, RTNLGRP_LINK, err);
  117714. + rtnl_set_sk_err(net, RTNLGRP_LINK, err);
  117715. return err;
  117716. }
  117717. diff -Nur linux-3.12.38/net/core/skbuff.c linux-rpi/net/core/skbuff.c
  117718. --- linux-3.12.38/net/core/skbuff.c 2015-02-16 16:15:42.000000000 +0100
  117719. +++ linux-rpi/net/core/skbuff.c 2015-03-10 17:26:51.762216685 +0100
  117720. @@ -3523,7 +3523,6 @@
  117721. skb->local_df = 0;
  117722. skb_dst_drop(skb);
  117723. skb->mark = 0;
  117724. - skb_init_secmark(skb);
  117725. secpath_reset(skb);
  117726. nf_reset(skb);
  117727. nf_reset_trace(skb);
  117728. diff -Nur linux-3.12.38/net/ipv4/ip_forward.c linux-rpi/net/ipv4/ip_forward.c
  117729. --- linux-3.12.38/net/ipv4/ip_forward.c 2015-02-16 16:15:42.000000000 +0100
  117730. +++ linux-rpi/net/ipv4/ip_forward.c 2015-03-10 17:26:51.770216685 +0100
  117731. @@ -175,8 +175,7 @@
  117732. * We now generate an ICMP HOST REDIRECT giving the route
  117733. * we calculated.
  117734. */
  117735. - if (IPCB(skb)->flags & IPSKB_DOREDIRECT && !opt->srr &&
  117736. - !skb_sec_path(skb))
  117737. + if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb))
  117738. ip_rt_send_redirect(skb);
  117739. skb->priority = rt_tos2priority(iph->tos);
  117740. diff -Nur linux-3.12.38/net/ipv4/ip_output.c linux-rpi/net/ipv4/ip_output.c
  117741. --- linux-3.12.38/net/ipv4/ip_output.c 2015-02-16 16:15:42.000000000 +0100
  117742. +++ linux-rpi/net/ipv4/ip_output.c 2015-03-10 17:26:51.770216685 +0100
  117743. @@ -1451,8 +1451,23 @@
  117744. /*
  117745. * Generic function to send a packet as reply to another packet.
  117746. * Used to send some TCP resets/acks so far.
  117747. + *
  117748. + * Use a fake percpu inet socket to avoid false sharing and contention.
  117749. */
  117750. -void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb, __be32 daddr,
  117751. +static DEFINE_PER_CPU(struct inet_sock, unicast_sock) = {
  117752. + .sk = {
  117753. + .__sk_common = {
  117754. + .skc_refcnt = ATOMIC_INIT(1),
  117755. + },
  117756. + .sk_wmem_alloc = ATOMIC_INIT(1),
  117757. + .sk_allocation = GFP_ATOMIC,
  117758. + .sk_flags = (1UL << SOCK_USE_WRITE_QUEUE),
  117759. + },
  117760. + .pmtudisc = IP_PMTUDISC_WANT,
  117761. + .uc_ttl = -1,
  117762. +};
  117763. +
  117764. +void ip_send_unicast_reply(struct net *net, struct sk_buff *skb, __be32 daddr,
  117765. __be32 saddr, const struct ip_reply_arg *arg,
  117766. unsigned int len)
  117767. {
  117768. @@ -1460,8 +1475,9 @@
  117769. struct ipcm_cookie ipc;
  117770. struct flowi4 fl4;
  117771. struct rtable *rt = skb_rtable(skb);
  117772. - struct net *net = sock_net(sk);
  117773. struct sk_buff *nskb;
  117774. + struct sock *sk;
  117775. + struct inet_sock *inet;
  117776. int err;
  117777. if (ip_options_echo(&replyopts.opt.opt, skb))
  117778. @@ -1489,11 +1505,15 @@
  117779. if (IS_ERR(rt))
  117780. return;
  117781. - inet_sk(sk)->tos = arg->tos;
  117782. + inet = &get_cpu_var(unicast_sock);
  117783. + inet->tos = arg->tos;
  117784. + sk = &inet->sk;
  117785. sk->sk_priority = skb->priority;
  117786. sk->sk_protocol = ip_hdr(skb)->protocol;
  117787. sk->sk_bound_dev_if = arg->bound_dev_if;
  117788. + sock_net_set(sk, net);
  117789. + __skb_queue_head_init(&sk->sk_write_queue);
  117790. sk->sk_sndbuf = sysctl_wmem_default;
  117791. err = ip_append_data(sk, &fl4, ip_reply_glue_bits, arg->iov->iov_base,
  117792. len, 0, &ipc, &rt, MSG_DONTWAIT);
  117793. @@ -1509,10 +1529,13 @@
  117794. arg->csumoffset) = csum_fold(csum_add(nskb->csum,
  117795. arg->csum));
  117796. nskb->ip_summed = CHECKSUM_NONE;
  117797. + skb_orphan(nskb);
  117798. skb_set_queue_mapping(nskb, skb_get_queue_mapping(skb));
  117799. ip_push_pending_frames(sk, &fl4);
  117800. }
  117801. out:
  117802. + put_cpu_var(unicast_sock);
  117803. +
  117804. ip_rt_put(rt);
  117805. }
  117806. diff -Nur linux-3.12.38/net/ipv4/ip_sockglue.c linux-rpi/net/ipv4/ip_sockglue.c
  117807. --- linux-3.12.38/net/ipv4/ip_sockglue.c 2015-02-16 16:15:42.000000000 +0100
  117808. +++ linux-rpi/net/ipv4/ip_sockglue.c 2015-03-10 17:26:51.770216685 +0100
  117809. @@ -410,11 +410,15 @@
  117810. memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
  117811. sin = &errhdr.offender;
  117812. - memset(sin, 0, sizeof(*sin));
  117813. + sin->sin_family = AF_UNSPEC;
  117814. if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP) {
  117815. + struct inet_sock *inet = inet_sk(sk);
  117816. +
  117817. sin->sin_family = AF_INET;
  117818. sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
  117819. - if (inet_sk(sk)->cmsg_flags)
  117820. + sin->sin_port = 0;
  117821. + memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
  117822. + if (inet->cmsg_flags)
  117823. ip_cmsg_recv(msg, skb);
  117824. }
  117825. diff -Nur linux-3.12.38/net/ipv4/ping.c linux-rpi/net/ipv4/ping.c
  117826. --- linux-3.12.38/net/ipv4/ping.c 2015-02-16 16:15:42.000000000 +0100
  117827. +++ linux-rpi/net/ipv4/ping.c 2015-03-10 17:26:51.774216685 +0100
  117828. @@ -959,11 +959,8 @@
  117829. sk = ping_lookup(net, skb, ntohs(icmph->un.echo.id));
  117830. if (sk != NULL) {
  117831. - struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
  117832. -
  117833. pr_debug("rcv on socket %p\n", sk);
  117834. - if (skb2)
  117835. - ping_queue_rcv_skb(sk, skb2);
  117836. + ping_queue_rcv_skb(sk, skb_get(skb));
  117837. sock_put(sk);
  117838. return;
  117839. }
  117840. diff -Nur linux-3.12.38/net/ipv4/route.c linux-rpi/net/ipv4/route.c
  117841. --- linux-3.12.38/net/ipv4/route.c 2015-02-16 16:15:42.000000000 +0100
  117842. +++ linux-rpi/net/ipv4/route.c 2015-03-10 17:26:51.774216685 +0100
  117843. @@ -1561,10 +1561,11 @@
  117844. do_cache = res->fi && !itag;
  117845. if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
  117846. - skb->protocol == htons(ETH_P_IP) &&
  117847. (IN_DEV_SHARED_MEDIA(out_dev) ||
  117848. - inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
  117849. - IPCB(skb)->flags |= IPSKB_DOREDIRECT;
  117850. + inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res)))) {
  117851. + flags |= RTCF_DOREDIRECT;
  117852. + do_cache = false;
  117853. + }
  117854. if (skb->protocol != htons(ETH_P_IP)) {
  117855. /* Not IP (i.e. ARP). Do not create route, if it is
  117856. @@ -2306,8 +2307,6 @@
  117857. r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
  117858. if (rt->rt_flags & RTCF_NOTIFY)
  117859. r->rtm_flags |= RTM_F_NOTIFY;
  117860. - if (IPCB(skb)->flags & IPSKB_DOREDIRECT)
  117861. - r->rtm_flags |= RTCF_DOREDIRECT;
  117862. if (nla_put_be32(skb, RTA_DST, dst))
  117863. goto nla_put_failure;
  117864. diff -Nur linux-3.12.38/net/ipv4/tcp_ipv4.c linux-rpi/net/ipv4/tcp_ipv4.c
  117865. --- linux-3.12.38/net/ipv4/tcp_ipv4.c 2015-02-16 16:15:42.000000000 +0100
  117866. +++ linux-rpi/net/ipv4/tcp_ipv4.c 2015-03-10 17:26:51.778216684 +0100
  117867. @@ -690,8 +690,7 @@
  117868. net = dev_net(skb_dst(skb)->dev);
  117869. arg.tos = ip_hdr(skb)->tos;
  117870. - ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
  117871. - skb, ip_hdr(skb)->saddr,
  117872. + ip_send_unicast_reply(net, skb, ip_hdr(skb)->saddr,
  117873. ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len);
  117874. TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS);
  117875. @@ -774,8 +773,7 @@
  117876. if (oif)
  117877. arg.bound_dev_if = oif;
  117878. arg.tos = tos;
  117879. - ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
  117880. - skb, ip_hdr(skb)->saddr,
  117881. + ip_send_unicast_reply(net, skb, ip_hdr(skb)->saddr,
  117882. ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len);
  117883. TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS);
  117884. @@ -2830,39 +2828,14 @@
  117885. };
  117886. EXPORT_SYMBOL(tcp_prot);
  117887. -static void __net_exit tcp_sk_exit(struct net *net)
  117888. -{
  117889. - int cpu;
  117890. -
  117891. - for_each_possible_cpu(cpu)
  117892. - inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.tcp_sk, cpu));
  117893. - free_percpu(net->ipv4.tcp_sk);
  117894. -}
  117895. -
  117896. static int __net_init tcp_sk_init(struct net *net)
  117897. {
  117898. - int res, cpu;
  117899. -
  117900. - net->ipv4.tcp_sk = alloc_percpu(struct sock *);
  117901. - if (!net->ipv4.tcp_sk)
  117902. - return -ENOMEM;
  117903. -
  117904. - for_each_possible_cpu(cpu) {
  117905. - struct sock *sk;
  117906. -
  117907. - res = inet_ctl_sock_create(&sk, PF_INET, SOCK_RAW,
  117908. - IPPROTO_TCP, net);
  117909. - if (res)
  117910. - goto fail;
  117911. - *per_cpu_ptr(net->ipv4.tcp_sk, cpu) = sk;
  117912. - }
  117913. net->ipv4.sysctl_tcp_ecn = 2;
  117914. return 0;
  117915. +}
  117916. -fail:
  117917. - tcp_sk_exit(net);
  117918. -
  117919. - return res;
  117920. +static void __net_exit tcp_sk_exit(struct net *net)
  117921. +{
  117922. }
  117923. static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)
  117924. diff -Nur linux-3.12.38/net/ipv4/tcp_output.c linux-rpi/net/ipv4/tcp_output.c
  117925. --- linux-3.12.38/net/ipv4/tcp_output.c 2015-02-16 16:15:42.000000000 +0100
  117926. +++ linux-rpi/net/ipv4/tcp_output.c 2015-03-10 17:26:51.778216684 +0100
  117927. @@ -1871,7 +1871,7 @@
  117928. if (unlikely(!tcp_snd_wnd_test(tp, skb, mss_now)))
  117929. break;
  117930. - if (tso_segs == 1 || !sk->sk_gso_max_segs) {
  117931. + if (tso_segs == 1) {
  117932. if (unlikely(!tcp_nagle_test(tp, skb, mss_now,
  117933. (tcp_skb_is_last(sk, skb) ?
  117934. nonagle : TCP_NAGLE_PUSH))))
  117935. @@ -1908,7 +1908,7 @@
  117936. }
  117937. limit = mss_now;
  117938. - if (tso_segs > 1 && sk->sk_gso_max_segs && !tcp_urg_mode(tp))
  117939. + if (tso_segs > 1 && !tcp_urg_mode(tp))
  117940. limit = tcp_mss_split_point(sk, skb, mss_now,
  117941. min_t(unsigned int,
  117942. cwnd_quota,
  117943. diff -Nur linux-3.12.38/net/ipv4/udp_diag.c linux-rpi/net/ipv4/udp_diag.c
  117944. --- linux-3.12.38/net/ipv4/udp_diag.c 2015-02-16 16:15:42.000000000 +0100
  117945. +++ linux-rpi/net/ipv4/udp_diag.c 2015-03-10 17:26:51.782216684 +0100
  117946. @@ -99,13 +99,11 @@
  117947. s_slot = cb->args[0];
  117948. num = s_num = cb->args[1];
  117949. - for (slot = s_slot; slot <= table->mask; s_num = 0, slot++) {
  117950. + for (slot = s_slot; slot <= table->mask; num = s_num = 0, slot++) {
  117951. struct sock *sk;
  117952. struct hlist_nulls_node *node;
  117953. struct udp_hslot *hslot = &table->hash[slot];
  117954. - num = 0;
  117955. -
  117956. if (hlist_nulls_empty(&hslot->head))
  117957. continue;
  117958. diff -Nur linux-3.12.38/net/ipv6/datagram.c linux-rpi/net/ipv6/datagram.c
  117959. --- linux-3.12.38/net/ipv6/datagram.c 2015-02-16 16:15:42.000000000 +0100
  117960. +++ linux-rpi/net/ipv6/datagram.c 2015-03-10 17:26:51.782216684 +0100
  117961. @@ -374,10 +374,11 @@
  117962. memcpy(&errhdr.ee, &serr->ee, sizeof(struct sock_extended_err));
  117963. sin = &errhdr.offender;
  117964. - memset(sin, 0, sizeof(*sin));
  117965. -
  117966. + sin->sin6_family = AF_UNSPEC;
  117967. if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
  117968. sin->sin6_family = AF_INET6;
  117969. + sin->sin6_flowinfo = 0;
  117970. + sin->sin6_port = 0;
  117971. if (skb->protocol == htons(ETH_P_IPV6)) {
  117972. sin->sin6_addr = ipv6_hdr(skb)->saddr;
  117973. if (np->rxopt.all)
  117974. @@ -386,9 +387,12 @@
  117975. ipv6_iface_scope_id(&sin->sin6_addr,
  117976. IP6CB(skb)->iif);
  117977. } else {
  117978. + struct inet_sock *inet = inet_sk(sk);
  117979. +
  117980. ipv6_addr_set_v4mapped(ip_hdr(skb)->saddr,
  117981. &sin->sin6_addr);
  117982. - if (inet_sk(sk)->cmsg_flags)
  117983. + sin->sin6_scope_id = 0;
  117984. + if (inet->cmsg_flags)
  117985. ip_cmsg_recv(msg, skb);
  117986. }
  117987. }
  117988. diff -Nur linux-3.12.38/net/ipv6/ip6_fib.c linux-rpi/net/ipv6/ip6_fib.c
  117989. --- linux-3.12.38/net/ipv6/ip6_fib.c 2015-02-16 16:15:42.000000000 +0100
  117990. +++ linux-rpi/net/ipv6/ip6_fib.c 2015-03-10 17:26:51.782216684 +0100
  117991. @@ -638,29 +638,6 @@
  117992. RTF_GATEWAY;
  117993. }
  117994. -static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
  117995. - struct net *net)
  117996. -{
  117997. - if (atomic_read(&rt->rt6i_ref) != 1) {
  117998. - /* This route is used as dummy address holder in some split
  117999. - * nodes. It is not leaked, but it still holds other resources,
  118000. - * which must be released in time. So, scan ascendant nodes
  118001. - * and replace dummy references to this route with references
  118002. - * to still alive ones.
  118003. - */
  118004. - while (fn) {
  118005. - if (!(fn->fn_flags & RTN_RTINFO) && fn->leaf == rt) {
  118006. - fn->leaf = fib6_find_prefix(net, fn);
  118007. - atomic_inc(&fn->leaf->rt6i_ref);
  118008. - rt6_release(rt);
  118009. - }
  118010. - fn = fn->parent;
  118011. - }
  118012. - /* No more references are possible at this point. */
  118013. - BUG_ON(atomic_read(&rt->rt6i_ref) != 1);
  118014. - }
  118015. -}
  118016. -
  118017. /*
  118018. * Insert routing information in a node.
  118019. */
  118020. @@ -798,12 +775,11 @@
  118021. rt->dst.rt6_next = iter->dst.rt6_next;
  118022. atomic_inc(&rt->rt6i_ref);
  118023. inet6_rt_notify(RTM_NEWROUTE, rt, info);
  118024. + rt6_release(iter);
  118025. if (!(fn->fn_flags & RTN_RTINFO)) {
  118026. info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
  118027. fn->fn_flags |= RTN_RTINFO;
  118028. }
  118029. - fib6_purge_rt(iter, fn, info->nl_net);
  118030. - rt6_release(iter);
  118031. }
  118032. return 0;
  118033. @@ -1308,7 +1284,24 @@
  118034. fn = fib6_repair_tree(net, fn);
  118035. }
  118036. - fib6_purge_rt(rt, fn, net);
  118037. + if (atomic_read(&rt->rt6i_ref) != 1) {
  118038. + /* This route is used as dummy address holder in some split
  118039. + * nodes. It is not leaked, but it still holds other resources,
  118040. + * which must be released in time. So, scan ascendant nodes
  118041. + * and replace dummy references to this route with references
  118042. + * to still alive ones.
  118043. + */
  118044. + while (fn) {
  118045. + if (!(fn->fn_flags & RTN_RTINFO) && fn->leaf == rt) {
  118046. + fn->leaf = fib6_find_prefix(net, fn);
  118047. + atomic_inc(&fn->leaf->rt6i_ref);
  118048. + rt6_release(rt);
  118049. + }
  118050. + fn = fn->parent;
  118051. + }
  118052. + /* No more references are possible at this point. */
  118053. + BUG_ON(atomic_read(&rt->rt6i_ref) != 1);
  118054. + }
  118055. inet6_rt_notify(RTM_DELROUTE, rt, info);
  118056. rt6_release(rt);
  118057. diff -Nur linux-3.12.38/net/ipv6/route.c linux-rpi/net/ipv6/route.c
  118058. --- linux-3.12.38/net/ipv6/route.c 2015-02-16 16:15:42.000000000 +0100
  118059. +++ linux-rpi/net/ipv6/route.c 2015-03-10 17:26:51.786216684 +0100
  118060. @@ -1144,9 +1144,12 @@
  118061. struct net *net = dev_net(dst->dev);
  118062. rt6->rt6i_flags |= RTF_MODIFIED;
  118063. - if (mtu < IPV6_MIN_MTU)
  118064. + if (mtu < IPV6_MIN_MTU) {
  118065. + u32 features = dst_metric(dst, RTAX_FEATURES);
  118066. mtu = IPV6_MIN_MTU;
  118067. -
  118068. + features |= RTAX_FEATURE_ALLFRAG;
  118069. + dst_metric_set(dst, RTAX_FEATURES, features);
  118070. + }
  118071. dst_metric_set(dst, RTAX_MTU, mtu);
  118072. rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
  118073. }
  118074. diff -Nur linux-3.12.38/net/mac80211/rx.c linux-rpi/net/mac80211/rx.c
  118075. --- linux-3.12.38/net/mac80211/rx.c 2015-02-16 16:15:42.000000000 +0100
  118076. +++ linux-rpi/net/mac80211/rx.c 2015-03-10 17:26:51.802216684 +0100
  118077. @@ -261,7 +261,7 @@
  118078. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  118079. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  118080. else if (rate)
  118081. - channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
  118082. + channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  118083. else
  118084. channel_flags |= IEEE80211_CHAN_2GHZ;
  118085. put_unaligned_le16(channel_flags, pos);
  118086. diff -Nur linux-3.12.38/net/netfilter/ipset/ip_set_core.c linux-rpi/net/netfilter/ipset/ip_set_core.c
  118087. --- linux-3.12.38/net/netfilter/ipset/ip_set_core.c 2015-02-16 16:15:42.000000000 +0100
  118088. +++ linux-rpi/net/netfilter/ipset/ip_set_core.c 2015-03-10 17:26:51.806216684 +0100
  118089. @@ -1753,12 +1753,6 @@
  118090. if (*op < IP_SET_OP_VERSION) {
  118091. /* Check the version at the beginning of operations */
  118092. struct ip_set_req_version *req_version = data;
  118093. -
  118094. - if (*len < sizeof(struct ip_set_req_version)) {
  118095. - ret = -EINVAL;
  118096. - goto done;
  118097. - }
  118098. -
  118099. if (req_version->version != IPSET_PROTOCOL) {
  118100. ret = -EPROTO;
  118101. goto done;
  118102. diff -Nur linux-3.12.38/net/netfilter/ipvs/ip_vs_ftp.c linux-rpi/net/netfilter/ipvs/ip_vs_ftp.c
  118103. --- linux-3.12.38/net/netfilter/ipvs/ip_vs_ftp.c 2015-02-16 16:15:42.000000000 +0100
  118104. +++ linux-rpi/net/netfilter/ipvs/ip_vs_ftp.c 2015-03-10 17:26:51.806216684 +0100
  118105. @@ -183,8 +183,6 @@
  118106. struct nf_conn *ct;
  118107. struct net *net;
  118108. - *diff = 0;
  118109. -
  118110. #ifdef CONFIG_IP_VS_IPV6
  118111. /* This application helper doesn't work with IPv6 yet,
  118112. * so turn this into a no-op for IPv6 packets
  118113. @@ -193,6 +191,8 @@
  118114. return 1;
  118115. #endif
  118116. + *diff = 0;
  118117. +
  118118. /* Only useful for established sessions */
  118119. if (cp->state != IP_VS_TCP_S_ESTABLISHED)
  118120. return 1;
  118121. @@ -321,9 +321,6 @@
  118122. struct ip_vs_conn *n_cp;
  118123. struct net *net;
  118124. - /* no diff required for incoming packets */
  118125. - *diff = 0;
  118126. -
  118127. #ifdef CONFIG_IP_VS_IPV6
  118128. /* This application helper doesn't work with IPv6 yet,
  118129. * so turn this into a no-op for IPv6 packets
  118130. @@ -332,6 +329,9 @@
  118131. return 1;
  118132. #endif
  118133. + /* no diff required for incoming packets */
  118134. + *diff = 0;
  118135. +
  118136. /* Only useful for established sessions */
  118137. if (cp->state != IP_VS_TCP_S_ESTABLISHED)
  118138. return 1;
  118139. diff -Nur linux-3.12.38/net/netfilter/ipvs/ip_vs_nfct.c linux-rpi/net/netfilter/ipvs/ip_vs_nfct.c
  118140. --- linux-3.12.38/net/netfilter/ipvs/ip_vs_nfct.c 2015-02-16 16:15:42.000000000 +0100
  118141. +++ linux-rpi/net/netfilter/ipvs/ip_vs_nfct.c 2015-03-10 17:26:51.806216684 +0100
  118142. @@ -63,7 +63,6 @@
  118143. #include <net/ip_vs.h>
  118144. #include <net/netfilter/nf_conntrack_core.h>
  118145. #include <net/netfilter/nf_conntrack_expect.h>
  118146. -#include <net/netfilter/nf_conntrack_seqadj.h>
  118147. #include <net/netfilter/nf_conntrack_helper.h>
  118148. #include <net/netfilter/nf_conntrack_zones.h>
  118149. @@ -98,11 +97,6 @@
  118150. if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL)
  118151. return;
  118152. - /* Applications may adjust TCP seqs */
  118153. - if (cp->app && nf_ct_protonum(ct) == IPPROTO_TCP &&
  118154. - !nfct_seqadj(ct) && !nfct_seqadj_ext_add(ct))
  118155. - return;
  118156. -
  118157. /*
  118158. * The connection is not yet in the hashtable, so we update it.
  118159. * CIP->VIP will remain the same, so leave the tuple in
  118160. diff -Nur linux-3.12.38/net/netlink/af_netlink.c linux-rpi/net/netlink/af_netlink.c
  118161. --- linux-3.12.38/net/netlink/af_netlink.c 2015-02-16 16:15:42.000000000 +0100
  118162. +++ linux-rpi/net/netlink/af_netlink.c 2015-03-10 17:26:51.814216684 +0100
  118163. @@ -502,14 +502,14 @@
  118164. return err;
  118165. }
  118166. -static void netlink_frame_flush_dcache(const struct nl_mmap_hdr *hdr, unsigned int nm_len)
  118167. +static void netlink_frame_flush_dcache(const struct nl_mmap_hdr *hdr)
  118168. {
  118169. #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 1
  118170. struct page *p_start, *p_end;
  118171. /* First page is flushed through netlink_{get,set}_status */
  118172. p_start = pgvec_to_page(hdr + PAGE_SIZE);
  118173. - p_end = pgvec_to_page((void *)hdr + NL_MMAP_HDRLEN + nm_len - 1);
  118174. + p_end = pgvec_to_page((void *)hdr + NL_MMAP_HDRLEN + hdr->nm_len - 1);
  118175. while (p_start <= p_end) {
  118176. flush_dcache_page(p_start);
  118177. p_start++;
  118178. @@ -527,9 +527,9 @@
  118179. static void netlink_set_status(struct nl_mmap_hdr *hdr,
  118180. enum nl_mmap_status status)
  118181. {
  118182. - smp_mb();
  118183. hdr->nm_status = status;
  118184. flush_dcache_page(pgvec_to_page(hdr));
  118185. + smp_wmb();
  118186. }
  118187. static struct nl_mmap_hdr *
  118188. @@ -691,16 +691,24 @@
  118189. struct nl_mmap_hdr *hdr;
  118190. struct sk_buff *skb;
  118191. unsigned int maxlen;
  118192. + bool excl = true;
  118193. int err = 0, len = 0;
  118194. + /* Netlink messages are validated by the receiver before processing.
  118195. + * In order to avoid userspace changing the contents of the message
  118196. + * after validation, the socket and the ring may only be used by a
  118197. + * single process, otherwise we fall back to copying.
  118198. + */
  118199. + if (atomic_long_read(&sk->sk_socket->file->f_count) > 1 ||
  118200. + atomic_read(&nlk->mapped) > 1)
  118201. + excl = false;
  118202. +
  118203. mutex_lock(&nlk->pg_vec_lock);
  118204. ring = &nlk->tx_ring;
  118205. maxlen = ring->frame_size - NL_MMAP_HDRLEN;
  118206. do {
  118207. - unsigned int nm_len;
  118208. -
  118209. hdr = netlink_current_frame(ring, NL_MMAP_STATUS_VALID);
  118210. if (hdr == NULL) {
  118211. if (!(msg->msg_flags & MSG_DONTWAIT) &&
  118212. @@ -708,23 +716,35 @@
  118213. schedule();
  118214. continue;
  118215. }
  118216. -
  118217. - nm_len = ACCESS_ONCE(hdr->nm_len);
  118218. - if (nm_len > maxlen) {
  118219. + if (hdr->nm_len > maxlen) {
  118220. err = -EINVAL;
  118221. goto out;
  118222. }
  118223. - netlink_frame_flush_dcache(hdr, nm_len);
  118224. + netlink_frame_flush_dcache(hdr);
  118225. - skb = alloc_skb(nm_len, GFP_KERNEL);
  118226. - if (skb == NULL) {
  118227. - err = -ENOBUFS;
  118228. - goto out;
  118229. + if (likely(dst_portid == 0 && dst_group == 0 && excl)) {
  118230. + skb = alloc_skb_head(GFP_KERNEL);
  118231. + if (skb == NULL) {
  118232. + err = -ENOBUFS;
  118233. + goto out;
  118234. + }
  118235. + sock_hold(sk);
  118236. + netlink_ring_setup_skb(skb, sk, ring, hdr);
  118237. + NETLINK_CB(skb).flags |= NETLINK_SKB_TX;
  118238. + __skb_put(skb, hdr->nm_len);
  118239. + netlink_set_status(hdr, NL_MMAP_STATUS_RESERVED);
  118240. + atomic_inc(&ring->pending);
  118241. + } else {
  118242. + skb = alloc_skb(hdr->nm_len, GFP_KERNEL);
  118243. + if (skb == NULL) {
  118244. + err = -ENOBUFS;
  118245. + goto out;
  118246. + }
  118247. + __skb_put(skb, hdr->nm_len);
  118248. + memcpy(skb->data, (void *)hdr + NL_MMAP_HDRLEN, hdr->nm_len);
  118249. + netlink_set_status(hdr, NL_MMAP_STATUS_UNUSED);
  118250. }
  118251. - __skb_put(skb, nm_len);
  118252. - memcpy(skb->data, (void *)hdr + NL_MMAP_HDRLEN, nm_len);
  118253. - netlink_set_status(hdr, NL_MMAP_STATUS_UNUSED);
  118254. netlink_increment_head(ring);
  118255. @@ -770,7 +790,7 @@
  118256. hdr->nm_pid = NETLINK_CB(skb).creds.pid;
  118257. hdr->nm_uid = from_kuid(sk_user_ns(sk), NETLINK_CB(skb).creds.uid);
  118258. hdr->nm_gid = from_kgid(sk_user_ns(sk), NETLINK_CB(skb).creds.gid);
  118259. - netlink_frame_flush_dcache(hdr, hdr->nm_len);
  118260. + netlink_frame_flush_dcache(hdr);
  118261. netlink_set_status(hdr, NL_MMAP_STATUS_VALID);
  118262. NETLINK_CB(skb).flags |= NETLINK_SKB_DELIVERED;
  118263. diff -Nur linux-3.12.38/net/sctp/associola.c linux-rpi/net/sctp/associola.c
  118264. --- linux-3.12.38/net/sctp/associola.c 2015-02-16 16:15:42.000000000 +0100
  118265. +++ linux-rpi/net/sctp/associola.c 2015-03-10 17:26:51.830216684 +0100
  118266. @@ -1282,6 +1282,7 @@
  118267. asoc->peer.peer_hmacs = new->peer.peer_hmacs;
  118268. new->peer.peer_hmacs = NULL;
  118269. + sctp_auth_key_put(asoc->asoc_shared_key);
  118270. sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
  118271. }
  118272. diff -Nur linux-3.12.38/net/sctp/sm_make_chunk.c linux-rpi/net/sctp/sm_make_chunk.c
  118273. --- linux-3.12.38/net/sctp/sm_make_chunk.c 2015-02-16 16:15:42.000000000 +0100
  118274. +++ linux-rpi/net/sctp/sm_make_chunk.c 2015-03-10 17:26:51.834216684 +0100
  118275. @@ -2621,7 +2621,7 @@
  118276. addr_param = param.v + sizeof(sctp_addip_param_t);
  118277. - af = sctp_get_af_specific(param_type2af(addr_param->p.type));
  118278. + af = sctp_get_af_specific(param_type2af(param.p->type));
  118279. if (af == NULL)
  118280. break;
  118281. diff -Nur linux-3.12.38/net/socket.c linux-rpi/net/socket.c
  118282. --- linux-3.12.38/net/socket.c 2015-02-16 16:15:42.000000000 +0100
  118283. +++ linux-rpi/net/socket.c 2015-03-10 17:26:51.834216684 +0100
  118284. @@ -885,6 +885,9 @@
  118285. static struct sock_iocb *alloc_sock_iocb(struct kiocb *iocb,
  118286. struct sock_iocb *siocb)
  118287. {
  118288. + if (!is_sync_kiocb(iocb))
  118289. + BUG();
  118290. +
  118291. siocb->kiocb = iocb;
  118292. iocb->private = siocb;
  118293. return siocb;
  118294. diff -Nur linux-3.12.38/net/sunrpc/clnt.c linux-rpi/net/sunrpc/clnt.c
  118295. --- linux-3.12.38/net/sunrpc/clnt.c 2015-02-16 16:15:42.000000000 +0100
  118296. +++ linux-rpi/net/sunrpc/clnt.c 2015-03-10 17:26:51.838216684 +0100
  118297. @@ -1637,12 +1637,10 @@
  118298. return;
  118299. case -ECONNREFUSED: /* connection problems */
  118300. case -ECONNRESET:
  118301. - case -ECONNABORTED:
  118302. case -ENOTCONN:
  118303. case -EHOSTDOWN:
  118304. case -EHOSTUNREACH:
  118305. case -ENETUNREACH:
  118306. - case -ENOBUFS:
  118307. case -EPIPE:
  118308. dprintk("RPC: %5u remote rpcbind unreachable: %d\n",
  118309. task->tk_pid, task->tk_status);
  118310. @@ -1701,25 +1699,20 @@
  118311. dprint_status(task);
  118312. trace_rpc_connect_status(task, status);
  118313. - task->tk_status = 0;
  118314. switch (status) {
  118315. + /* if soft mounted, test if we've timed out */
  118316. + case -ETIMEDOUT:
  118317. + task->tk_action = call_timeout;
  118318. + return;
  118319. case -ECONNREFUSED:
  118320. case -ECONNRESET:
  118321. - case -ECONNABORTED:
  118322. case -ENETUNREACH:
  118323. - case -EHOSTUNREACH:
  118324. - case -ENOBUFS:
  118325. - case -EPIPE:
  118326. if (RPC_IS_SOFTCONN(task))
  118327. break;
  118328. /* retry with existing socket, after a delay */
  118329. - rpc_delay(task, 3*HZ);
  118330. - case -EAGAIN:
  118331. - /* Check for timeouts before looping back to call_bind */
  118332. - case -ETIMEDOUT:
  118333. - task->tk_action = call_timeout;
  118334. - return;
  118335. case 0:
  118336. + case -EAGAIN:
  118337. + task->tk_status = 0;
  118338. clnt->cl_stats->netreconn++;
  118339. task->tk_action = call_transmit;
  118340. return;
  118341. @@ -1811,9 +1804,7 @@
  118342. break;
  118343. }
  118344. case -ECONNRESET:
  118345. - case -ECONNABORTED:
  118346. case -ENOTCONN:
  118347. - case -ENOBUFS:
  118348. case -EPIPE:
  118349. rpc_task_force_reencode(task);
  118350. }
  118351. @@ -1922,11 +1913,9 @@
  118352. xprt_conditional_disconnect(req->rq_xprt,
  118353. req->rq_connect_cookie);
  118354. break;
  118355. - case -ECONNREFUSED:
  118356. case -ECONNRESET:
  118357. - case -ECONNABORTED:
  118358. + case -ECONNREFUSED:
  118359. rpc_force_rebind(clnt);
  118360. - case -ENOBUFS:
  118361. rpc_delay(task, 3*HZ);
  118362. case -EPIPE:
  118363. case -ENOTCONN:
  118364. diff -Nur linux-3.12.38/net/sunrpc/sched.c linux-rpi/net/sunrpc/sched.c
  118365. --- linux-3.12.38/net/sunrpc/sched.c 2015-02-16 16:15:42.000000000 +0100
  118366. +++ linux-rpi/net/sunrpc/sched.c 2015-03-10 17:26:51.838216684 +0100
  118367. @@ -831,8 +831,7 @@
  118368. * @size: requested byte size
  118369. *
  118370. * To prevent rpciod from hanging, this allocator never sleeps,
  118371. - * returning NULL and suppressing warning if the request cannot be serviced
  118372. - * immediately.
  118373. + * returning NULL if the request cannot be serviced immediately.
  118374. * The caller can arrange to sleep in a way that is safe for rpciod.
  118375. *
  118376. * Most requests are 'small' (under 2KiB) and can be serviced from a
  118377. @@ -845,7 +844,7 @@
  118378. void *rpc_malloc(struct rpc_task *task, size_t size)
  118379. {
  118380. struct rpc_buffer *buf;
  118381. - gfp_t gfp = GFP_NOWAIT | __GFP_NOWARN;
  118382. + gfp_t gfp = GFP_NOWAIT;
  118383. if (RPC_IS_SWAPPER(task))
  118384. gfp |= __GFP_MEMALLOC;
  118385. diff -Nur linux-3.12.38/net/sunrpc/xprt.c linux-rpi/net/sunrpc/xprt.c
  118386. --- linux-3.12.38/net/sunrpc/xprt.c 2015-02-16 16:15:42.000000000 +0100
  118387. +++ linux-rpi/net/sunrpc/xprt.c 2015-03-10 17:26:51.838216684 +0100
  118388. @@ -745,12 +745,6 @@
  118389. }
  118390. switch (task->tk_status) {
  118391. - case -ECONNREFUSED:
  118392. - case -ECONNRESET:
  118393. - case -ECONNABORTED:
  118394. - case -ENETUNREACH:
  118395. - case -EHOSTUNREACH:
  118396. - case -EPIPE:
  118397. case -EAGAIN:
  118398. dprintk("RPC: %5u xprt_connect_status: retrying\n", task->tk_pid);
  118399. break;
  118400. diff -Nur linux-3.12.38/net/sunrpc/xprtsock.c linux-rpi/net/sunrpc/xprtsock.c
  118401. --- linux-3.12.38/net/sunrpc/xprtsock.c 2015-02-16 16:15:42.000000000 +0100
  118402. +++ linux-rpi/net/sunrpc/xprtsock.c 2015-03-10 17:26:51.842216684 +0100
  118403. @@ -588,7 +588,6 @@
  118404. }
  118405. switch (status) {
  118406. - case -ENOBUFS:
  118407. case -EAGAIN:
  118408. status = xs_nospace(task);
  118409. break;
  118410. @@ -656,7 +655,6 @@
  118411. dprintk("RPC: sendmsg returned unrecognized error %d\n",
  118412. -status);
  118413. case -ENETUNREACH:
  118414. - case -ENOBUFS:
  118415. case -EPIPE:
  118416. case -ECONNREFUSED:
  118417. /* When the server has died, an ICMP port unreachable message
  118418. @@ -754,7 +752,6 @@
  118419. status = -ENOTCONN;
  118420. /* Should we call xs_close() here? */
  118421. break;
  118422. - case -ENOBUFS:
  118423. case -EAGAIN:
  118424. status = xs_nospace(task);
  118425. break;
  118426. @@ -1931,7 +1928,6 @@
  118427. dprintk("RPC: xprt %p connected to %s\n",
  118428. xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
  118429. xprt_set_connected(xprt);
  118430. - case -ENOBUFS:
  118431. break;
  118432. case -ENOENT:
  118433. dprintk("RPC: xprt %p: socket %s does not exist\n",
  118434. @@ -2255,7 +2251,6 @@
  118435. case -ECONNREFUSED:
  118436. case -ECONNRESET:
  118437. case -ENETUNREACH:
  118438. - case -ENOBUFS:
  118439. /* retry with existing socket, after a delay */
  118440. goto out;
  118441. }
  118442. diff -Nur linux-3.12.38/net/wireless/nl80211.c linux-rpi/net/wireless/nl80211.c
  118443. --- linux-3.12.38/net/wireless/nl80211.c 2015-02-16 16:15:42.000000000 +0100
  118444. +++ linux-rpi/net/wireless/nl80211.c 2015-03-10 17:26:51.850216684 +0100
  118445. @@ -2659,9 +2659,6 @@
  118446. if (!rdev->ops->get_key)
  118447. return -EOPNOTSUPP;
  118448. - if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  118449. - return -ENOENT;
  118450. -
  118451. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  118452. if (!msg)
  118453. return -ENOMEM;
  118454. @@ -2681,6 +2678,10 @@
  118455. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
  118456. goto nla_put_failure;
  118457. + if (pairwise && mac_addr &&
  118458. + !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  118459. + return -ENOENT;
  118460. +
  118461. err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
  118462. get_key_callback);
  118463. @@ -2851,7 +2852,7 @@
  118464. wdev_lock(dev->ieee80211_ptr);
  118465. err = nl80211_key_allowed(dev->ieee80211_ptr);
  118466. - if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
  118467. + if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
  118468. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  118469. err = -ENOENT;
  118470. diff -Nur linux-3.12.38/net/wireless/reg.c linux-rpi/net/wireless/reg.c
  118471. --- linux-3.12.38/net/wireless/reg.c 2015-02-16 16:15:42.000000000 +0100
  118472. +++ linux-rpi/net/wireless/reg.c 2015-03-10 17:26:51.850216684 +0100
  118473. @@ -1432,7 +1432,7 @@
  118474. __regulatory_hint(struct wiphy *wiphy,
  118475. struct regulatory_request *pending_request)
  118476. {
  118477. - const struct ieee80211_regdomain *regd, *tmp;
  118478. + const struct ieee80211_regdomain *regd;
  118479. bool intersect = false;
  118480. enum reg_request_treatment treatment;
  118481. struct regulatory_request *lr;
  118482. @@ -1448,9 +1448,7 @@
  118483. kfree(pending_request);
  118484. return PTR_ERR(regd);
  118485. }
  118486. - tmp = get_wiphy_regdom(wiphy);
  118487. rcu_assign_pointer(wiphy->regd, regd);
  118488. - rcu_free_regdom(tmp);
  118489. }
  118490. intersect = true;
  118491. break;
  118492. @@ -1470,9 +1468,7 @@
  118493. return REG_REQ_IGNORE;
  118494. }
  118495. treatment = REG_REQ_ALREADY_SET;
  118496. - tmp = get_wiphy_regdom(wiphy);
  118497. rcu_assign_pointer(wiphy->regd, regd);
  118498. - rcu_free_regdom(tmp);
  118499. goto new_request;
  118500. }
  118501. kfree(pending_request);
  118502. diff -Nur linux-3.12.38/scripts/kconfig/menu.c linux-rpi/scripts/kconfig/menu.c
  118503. --- linux-3.12.38/scripts/kconfig/menu.c 2015-02-16 16:15:42.000000000 +0100
  118504. +++ linux-rpi/scripts/kconfig/menu.c 2015-03-10 17:26:51.858216684 +0100
  118505. @@ -544,7 +544,7 @@
  118506. {
  118507. int i, j;
  118508. struct menu *submenu[8], *menu, *location = NULL;
  118509. - struct jump_key *jump = NULL;
  118510. + struct jump_key *jump;
  118511. str_printf(r, _("Prompt: %s\n"), _(prop->text));
  118512. menu = prop->menu->parent;
  118513. @@ -582,8 +582,8 @@
  118514. str_printf(r, _(" Location:\n"));
  118515. for (j = 4; --i >= 0; j += 2) {
  118516. menu = submenu[i];
  118517. - if (jump && menu == location)
  118518. - jump->offset = strlen(r->s);
  118519. + if (head && location && menu == location)
  118520. + jump->offset = r->len - 1;
  118521. str_printf(r, "%*c-> %s", j, ' ',
  118522. _(menu_get_prompt(menu)));
  118523. if (menu->sym) {
  118524. diff -Nur linux-3.12.38/scripts/kernel-doc linux-rpi/scripts/kernel-doc
  118525. --- linux-3.12.38/scripts/kernel-doc 2015-02-16 16:15:42.000000000 +0100
  118526. +++ linux-rpi/scripts/kernel-doc 2015-03-10 17:26:51.862216684 +0100
  118527. @@ -1750,7 +1750,7 @@
  118528. # strip kmemcheck_bitfield_{begin,end}.*;
  118529. $members =~ s/kmemcheck_bitfield_.*?;//gos;
  118530. # strip attributes
  118531. - $members =~ s/__aligned\s*\([^;]*\)//gos;
  118532. + $members =~ s/__aligned\s*\(.+\)//gos;
  118533. create_parameterlist($members, ';', $file);
  118534. check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
  118535. diff -Nur linux-3.12.38/scripts/recordmcount.pl linux-rpi/scripts/recordmcount.pl
  118536. --- linux-3.12.38/scripts/recordmcount.pl 2015-02-16 16:15:42.000000000 +0100
  118537. +++ linux-rpi/scripts/recordmcount.pl 2015-03-10 17:26:51.862216684 +0100
  118538. @@ -262,6 +262,7 @@
  118539. # force flags for this arch
  118540. $ld .= " -m shlelf_linux";
  118541. $objcopy .= " -O elf32-sh-linux";
  118542. + $cc .= " -m32";
  118543. } elsif ($arch eq "powerpc") {
  118544. $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)";
  118545. diff -Nur linux-3.12.38/security/keys/gc.c linux-rpi/security/keys/gc.c
  118546. --- linux-3.12.38/security/keys/gc.c 2015-02-16 16:15:42.000000000 +0100
  118547. +++ linux-rpi/security/keys/gc.c 2015-03-10 17:26:51.866216684 +0100
  118548. @@ -201,12 +201,12 @@
  118549. if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags))
  118550. atomic_dec(&key->user->nikeys);
  118551. + key_user_put(key->user);
  118552. +
  118553. /* now throw away the key memory */
  118554. if (key->type->destroy)
  118555. key->type->destroy(key);
  118556. - key_user_put(key->user);
  118557. -
  118558. kfree(key->description);
  118559. #ifdef KEY_DEBUGGING
  118560. diff -Nur linux-3.12.38/security/selinux/selinuxfs.c linux-rpi/security/selinux/selinuxfs.c
  118561. --- linux-3.12.38/security/selinux/selinuxfs.c 2015-02-16 16:15:42.000000000 +0100
  118562. +++ linux-rpi/security/selinux/selinuxfs.c 2015-03-10 17:26:51.870216684 +0100
  118563. @@ -1190,7 +1190,7 @@
  118564. spin_lock(&de->d_lock);
  118565. node = de->d_subdirs.next;
  118566. while (node != &de->d_subdirs) {
  118567. - struct dentry *d = list_entry(node, struct dentry, d_child);
  118568. + struct dentry *d = list_entry(node, struct dentry, d_u.d_child);
  118569. spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
  118570. list_del_init(node);
  118571. @@ -1664,12 +1664,12 @@
  118572. list_for_each(class_node, &class_dir->d_subdirs) {
  118573. struct dentry *class_subdir = list_entry(class_node,
  118574. - struct dentry, d_child);
  118575. + struct dentry, d_u.d_child);
  118576. struct list_head *class_subdir_node;
  118577. list_for_each(class_subdir_node, &class_subdir->d_subdirs) {
  118578. struct dentry *d = list_entry(class_subdir_node,
  118579. - struct dentry, d_child);
  118580. + struct dentry, d_u.d_child);
  118581. if (d->d_inode)
  118582. if (d->d_inode->i_mode & S_IFDIR)
  118583. diff -Nur linux-3.12.38/security/selinux/ss/policydb.c linux-rpi/security/selinux/ss/policydb.c
  118584. --- linux-3.12.38/security/selinux/ss/policydb.c 2015-02-16 16:15:42.000000000 +0100
  118585. +++ linux-rpi/security/selinux/ss/policydb.c 2015-03-10 17:26:51.870216684 +0100
  118586. @@ -3215,8 +3215,9 @@
  118587. static int range_write(struct policydb *p, void *fp)
  118588. {
  118589. + size_t nel;
  118590. __le32 buf[1];
  118591. - int rc, nel;
  118592. + int rc;
  118593. struct policy_data pd;
  118594. pd.p = p;
  118595. diff -Nur linux-3.12.38/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  118596. --- linux-3.12.38/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  118597. +++ linux-rpi/sound/arm/bcm2835.c 2015-03-10 17:26:51.874216684 +0100
  118598. @@ -0,0 +1,420 @@
  118599. +/*****************************************************************************
  118600. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  118601. +*
  118602. +* Unless you and Broadcom execute a separate written software license
  118603. +* agreement governing use of this software, this software is licensed to you
  118604. +* under the terms of the GNU General Public License version 2, available at
  118605. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  118606. +*
  118607. +* Notwithstanding the above, under no circumstances may you combine this
  118608. +* software in any way with any other Broadcom software provided under a
  118609. +* license other than the GPL, without Broadcom's express prior written
  118610. +* consent.
  118611. +*****************************************************************************/
  118612. +
  118613. +#include <linux/platform_device.h>
  118614. +
  118615. +#include <linux/init.h>
  118616. +#include <linux/slab.h>
  118617. +#include <linux/module.h>
  118618. +
  118619. +#include "bcm2835.h"
  118620. +
  118621. +/* module parameters (see "Module Parameters") */
  118622. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  118623. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  118624. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  118625. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  118626. +
  118627. +/* HACKY global pointers needed for successive probes to work : ssp
  118628. + * But compared against the changes we will have to do in VC audio_ipc code
  118629. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  118630. + * four devices in a thread, this gets things done quickly and should be easier
  118631. + * to debug if we run into issues
  118632. + */
  118633. +
  118634. +static struct snd_card *g_card = NULL;
  118635. +static bcm2835_chip_t *g_chip = NULL;
  118636. +
  118637. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  118638. +{
  118639. + kfree(chip);
  118640. + return 0;
  118641. +}
  118642. +
  118643. +/* component-destructor
  118644. + * (see "Management of Cards and Components")
  118645. + */
  118646. +static int snd_bcm2835_dev_free(struct snd_device *device)
  118647. +{
  118648. + return snd_bcm2835_free(device->device_data);
  118649. +}
  118650. +
  118651. +/* chip-specific constructor
  118652. + * (see "Management of Cards and Components")
  118653. + */
  118654. +static int snd_bcm2835_create(struct snd_card *card,
  118655. + struct platform_device *pdev,
  118656. + bcm2835_chip_t ** rchip)
  118657. +{
  118658. + bcm2835_chip_t *chip;
  118659. + int err;
  118660. + static struct snd_device_ops ops = {
  118661. + .dev_free = snd_bcm2835_dev_free,
  118662. + };
  118663. +
  118664. + *rchip = NULL;
  118665. +
  118666. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  118667. + if (chip == NULL)
  118668. + return -ENOMEM;
  118669. +
  118670. + chip->card = card;
  118671. +
  118672. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  118673. + if (err < 0) {
  118674. + snd_bcm2835_free(chip);
  118675. + return err;
  118676. + }
  118677. +
  118678. + *rchip = chip;
  118679. + return 0;
  118680. +}
  118681. +
  118682. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  118683. +{
  118684. + static int dev;
  118685. + bcm2835_chip_t *chip;
  118686. + struct snd_card *card;
  118687. + int err;
  118688. +
  118689. + if (dev >= MAX_SUBSTREAMS)
  118690. + return -ENODEV;
  118691. +
  118692. + if (!enable[dev]) {
  118693. + dev++;
  118694. + return -ENOENT;
  118695. + }
  118696. +
  118697. + if (dev > 0)
  118698. + goto add_register_map;
  118699. +
  118700. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  118701. + if (err < 0)
  118702. + goto out;
  118703. +
  118704. + snd_card_set_dev(g_card, &pdev->dev);
  118705. + strcpy(g_card->driver, "bcm2835");
  118706. + strcpy(g_card->shortname, "bcm2835 ALSA");
  118707. + sprintf(g_card->longname, "%s", g_card->shortname);
  118708. +
  118709. + err = snd_bcm2835_create(g_card, pdev, &chip);
  118710. + if (err < 0) {
  118711. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  118712. + goto out_bcm2835_create;
  118713. + }
  118714. +
  118715. + g_chip = chip;
  118716. + err = snd_bcm2835_new_pcm(chip);
  118717. + if (err < 0) {
  118718. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  118719. + goto out_bcm2835_new_pcm;
  118720. + }
  118721. +
  118722. + err = snd_bcm2835_new_spdif_pcm(chip);
  118723. + if (err < 0) {
  118724. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  118725. + goto out_bcm2835_new_spdif;
  118726. + }
  118727. +
  118728. + err = snd_bcm2835_new_ctl(chip);
  118729. + if (err < 0) {
  118730. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  118731. + goto out_bcm2835_new_ctl;
  118732. + }
  118733. +
  118734. +add_register_map:
  118735. + card = g_card;
  118736. + chip = g_chip;
  118737. +
  118738. + BUG_ON(!(card && chip));
  118739. +
  118740. + chip->avail_substreams |= (1 << dev);
  118741. + chip->pdev[dev] = pdev;
  118742. +
  118743. + if (dev == 0) {
  118744. + err = snd_card_register(card);
  118745. + if (err < 0) {
  118746. + dev_err(&pdev->dev,
  118747. + "Failed to register bcm2835 ALSA card \n");
  118748. + goto out_card_register;
  118749. + }
  118750. + platform_set_drvdata(pdev, card);
  118751. + audio_info("bcm2835 ALSA card created!\n");
  118752. + } else {
  118753. + audio_info("bcm2835 ALSA chip created!\n");
  118754. + platform_set_drvdata(pdev, (void *)dev);
  118755. + }
  118756. +
  118757. + dev++;
  118758. +
  118759. + return 0;
  118760. +
  118761. +out_card_register:
  118762. +out_bcm2835_new_ctl:
  118763. +out_bcm2835_new_spdif:
  118764. +out_bcm2835_new_pcm:
  118765. +out_bcm2835_create:
  118766. + BUG_ON(!g_card);
  118767. + if (snd_card_free(g_card))
  118768. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  118769. + g_card = NULL;
  118770. +out:
  118771. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  118772. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  118773. + return err;
  118774. +}
  118775. +
  118776. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  118777. +{
  118778. + uint32_t idx;
  118779. + void *drv_data;
  118780. +
  118781. + drv_data = platform_get_drvdata(pdev);
  118782. +
  118783. + if (drv_data == (void *)g_card) {
  118784. + /* This is the card device */
  118785. + snd_card_free((struct snd_card *)drv_data);
  118786. + g_card = NULL;
  118787. + g_chip = NULL;
  118788. + } else {
  118789. + idx = (uint32_t) drv_data;
  118790. + if (g_card != NULL) {
  118791. + BUG_ON(!g_chip);
  118792. + /* We pass chip device numbers in audio ipc devices
  118793. + * other than the one we registered our card with
  118794. + */
  118795. + idx = (uint32_t) drv_data;
  118796. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  118797. + g_chip->avail_substreams &= ~(1 << idx);
  118798. + /* There should be atleast one substream registered
  118799. + * after we are done here, as it wil be removed when
  118800. + * the *remove* is called for the card device
  118801. + */
  118802. + BUG_ON(!g_chip->avail_substreams);
  118803. + }
  118804. + }
  118805. +
  118806. + platform_set_drvdata(pdev, NULL);
  118807. +
  118808. + return 0;
  118809. +}
  118810. +
  118811. +#ifdef CONFIG_PM
  118812. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  118813. + pm_message_t state)
  118814. +{
  118815. + return 0;
  118816. +}
  118817. +
  118818. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  118819. +{
  118820. + return 0;
  118821. +}
  118822. +
  118823. +#endif
  118824. +
  118825. +static struct platform_driver bcm2835_alsa0_driver = {
  118826. + .probe = snd_bcm2835_alsa_probe,
  118827. + .remove = snd_bcm2835_alsa_remove,
  118828. +#ifdef CONFIG_PM
  118829. + .suspend = snd_bcm2835_alsa_suspend,
  118830. + .resume = snd_bcm2835_alsa_resume,
  118831. +#endif
  118832. + .driver = {
  118833. + .name = "bcm2835_AUD0",
  118834. + .owner = THIS_MODULE,
  118835. + },
  118836. +};
  118837. +
  118838. +static struct platform_driver bcm2835_alsa1_driver = {
  118839. + .probe = snd_bcm2835_alsa_probe,
  118840. + .remove = snd_bcm2835_alsa_remove,
  118841. +#ifdef CONFIG_PM
  118842. + .suspend = snd_bcm2835_alsa_suspend,
  118843. + .resume = snd_bcm2835_alsa_resume,
  118844. +#endif
  118845. + .driver = {
  118846. + .name = "bcm2835_AUD1",
  118847. + .owner = THIS_MODULE,
  118848. + },
  118849. +};
  118850. +
  118851. +static struct platform_driver bcm2835_alsa2_driver = {
  118852. + .probe = snd_bcm2835_alsa_probe,
  118853. + .remove = snd_bcm2835_alsa_remove,
  118854. +#ifdef CONFIG_PM
  118855. + .suspend = snd_bcm2835_alsa_suspend,
  118856. + .resume = snd_bcm2835_alsa_resume,
  118857. +#endif
  118858. + .driver = {
  118859. + .name = "bcm2835_AUD2",
  118860. + .owner = THIS_MODULE,
  118861. + },
  118862. +};
  118863. +
  118864. +static struct platform_driver bcm2835_alsa3_driver = {
  118865. + .probe = snd_bcm2835_alsa_probe,
  118866. + .remove = snd_bcm2835_alsa_remove,
  118867. +#ifdef CONFIG_PM
  118868. + .suspend = snd_bcm2835_alsa_suspend,
  118869. + .resume = snd_bcm2835_alsa_resume,
  118870. +#endif
  118871. + .driver = {
  118872. + .name = "bcm2835_AUD3",
  118873. + .owner = THIS_MODULE,
  118874. + },
  118875. +};
  118876. +
  118877. +static struct platform_driver bcm2835_alsa4_driver = {
  118878. + .probe = snd_bcm2835_alsa_probe,
  118879. + .remove = snd_bcm2835_alsa_remove,
  118880. +#ifdef CONFIG_PM
  118881. + .suspend = snd_bcm2835_alsa_suspend,
  118882. + .resume = snd_bcm2835_alsa_resume,
  118883. +#endif
  118884. + .driver = {
  118885. + .name = "bcm2835_AUD4",
  118886. + .owner = THIS_MODULE,
  118887. + },
  118888. +};
  118889. +
  118890. +static struct platform_driver bcm2835_alsa5_driver = {
  118891. + .probe = snd_bcm2835_alsa_probe,
  118892. + .remove = snd_bcm2835_alsa_remove,
  118893. +#ifdef CONFIG_PM
  118894. + .suspend = snd_bcm2835_alsa_suspend,
  118895. + .resume = snd_bcm2835_alsa_resume,
  118896. +#endif
  118897. + .driver = {
  118898. + .name = "bcm2835_AUD5",
  118899. + .owner = THIS_MODULE,
  118900. + },
  118901. +};
  118902. +
  118903. +static struct platform_driver bcm2835_alsa6_driver = {
  118904. + .probe = snd_bcm2835_alsa_probe,
  118905. + .remove = snd_bcm2835_alsa_remove,
  118906. +#ifdef CONFIG_PM
  118907. + .suspend = snd_bcm2835_alsa_suspend,
  118908. + .resume = snd_bcm2835_alsa_resume,
  118909. +#endif
  118910. + .driver = {
  118911. + .name = "bcm2835_AUD6",
  118912. + .owner = THIS_MODULE,
  118913. + },
  118914. +};
  118915. +
  118916. +static struct platform_driver bcm2835_alsa7_driver = {
  118917. + .probe = snd_bcm2835_alsa_probe,
  118918. + .remove = snd_bcm2835_alsa_remove,
  118919. +#ifdef CONFIG_PM
  118920. + .suspend = snd_bcm2835_alsa_suspend,
  118921. + .resume = snd_bcm2835_alsa_resume,
  118922. +#endif
  118923. + .driver = {
  118924. + .name = "bcm2835_AUD7",
  118925. + .owner = THIS_MODULE,
  118926. + },
  118927. +};
  118928. +
  118929. +static int bcm2835_alsa_device_init(void)
  118930. +{
  118931. + int err;
  118932. + err = platform_driver_register(&bcm2835_alsa0_driver);
  118933. + if (err) {
  118934. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118935. + goto out;
  118936. + }
  118937. +
  118938. + err = platform_driver_register(&bcm2835_alsa1_driver);
  118939. + if (err) {
  118940. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118941. + goto unregister_0;
  118942. + }
  118943. +
  118944. + err = platform_driver_register(&bcm2835_alsa2_driver);
  118945. + if (err) {
  118946. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118947. + goto unregister_1;
  118948. + }
  118949. +
  118950. + err = platform_driver_register(&bcm2835_alsa3_driver);
  118951. + if (err) {
  118952. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118953. + goto unregister_2;
  118954. + }
  118955. +
  118956. + err = platform_driver_register(&bcm2835_alsa4_driver);
  118957. + if (err) {
  118958. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118959. + goto unregister_3;
  118960. + }
  118961. +
  118962. + err = platform_driver_register(&bcm2835_alsa5_driver);
  118963. + if (err) {
  118964. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118965. + goto unregister_4;
  118966. + }
  118967. +
  118968. + err = platform_driver_register(&bcm2835_alsa6_driver);
  118969. + if (err) {
  118970. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118971. + goto unregister_5;
  118972. + }
  118973. +
  118974. + err = platform_driver_register(&bcm2835_alsa7_driver);
  118975. + if (err) {
  118976. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  118977. + goto unregister_6;
  118978. + }
  118979. +
  118980. + return 0;
  118981. +
  118982. +unregister_6:
  118983. + platform_driver_unregister(&bcm2835_alsa6_driver);
  118984. +unregister_5:
  118985. + platform_driver_unregister(&bcm2835_alsa5_driver);
  118986. +unregister_4:
  118987. + platform_driver_unregister(&bcm2835_alsa4_driver);
  118988. +unregister_3:
  118989. + platform_driver_unregister(&bcm2835_alsa3_driver);
  118990. +unregister_2:
  118991. + platform_driver_unregister(&bcm2835_alsa2_driver);
  118992. +unregister_1:
  118993. + platform_driver_unregister(&bcm2835_alsa1_driver);
  118994. +unregister_0:
  118995. + platform_driver_unregister(&bcm2835_alsa0_driver);
  118996. +out:
  118997. + return err;
  118998. +}
  118999. +
  119000. +static void bcm2835_alsa_device_exit(void)
  119001. +{
  119002. + platform_driver_unregister(&bcm2835_alsa0_driver);
  119003. + platform_driver_unregister(&bcm2835_alsa1_driver);
  119004. + platform_driver_unregister(&bcm2835_alsa2_driver);
  119005. + platform_driver_unregister(&bcm2835_alsa3_driver);
  119006. + platform_driver_unregister(&bcm2835_alsa4_driver);
  119007. + platform_driver_unregister(&bcm2835_alsa5_driver);
  119008. + platform_driver_unregister(&bcm2835_alsa6_driver);
  119009. + platform_driver_unregister(&bcm2835_alsa7_driver);
  119010. +}
  119011. +
  119012. +late_initcall(bcm2835_alsa_device_init);
  119013. +module_exit(bcm2835_alsa_device_exit);
  119014. +
  119015. +MODULE_AUTHOR("Dom Cobley");
  119016. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  119017. +MODULE_LICENSE("GPL");
  119018. +MODULE_ALIAS("platform:bcm2835_alsa");
  119019. diff -Nur linux-3.12.38/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  119020. --- linux-3.12.38/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  119021. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2015-03-09 10:39:38.302893687 +0100
  119022. @@ -0,0 +1,323 @@
  119023. +/*****************************************************************************
  119024. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119025. +*
  119026. +* Unless you and Broadcom execute a separate written software license
  119027. +* agreement governing use of this software, this software is licensed to you
  119028. +* under the terms of the GNU General Public License version 2, available at
  119029. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119030. +*
  119031. +* Notwithstanding the above, under no circumstances may you combine this
  119032. +* software in any way with any other Broadcom software provided under a
  119033. +* license other than the GPL, without Broadcom's express prior written
  119034. +* consent.
  119035. +*****************************************************************************/
  119036. +
  119037. +#include <linux/platform_device.h>
  119038. +#include <linux/init.h>
  119039. +#include <linux/io.h>
  119040. +#include <linux/jiffies.h>
  119041. +#include <linux/slab.h>
  119042. +#include <linux/time.h>
  119043. +#include <linux/wait.h>
  119044. +#include <linux/delay.h>
  119045. +#include <linux/moduleparam.h>
  119046. +#include <linux/sched.h>
  119047. +
  119048. +#include <sound/core.h>
  119049. +#include <sound/control.h>
  119050. +#include <sound/pcm.h>
  119051. +#include <sound/pcm_params.h>
  119052. +#include <sound/rawmidi.h>
  119053. +#include <sound/initval.h>
  119054. +#include <sound/tlv.h>
  119055. +#include <sound/asoundef.h>
  119056. +
  119057. +#include "bcm2835.h"
  119058. +
  119059. +/* volume maximum and minimum in terms of 0.01dB */
  119060. +#define CTRL_VOL_MAX 400
  119061. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  119062. +
  119063. +
  119064. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  119065. + struct snd_ctl_elem_info *uinfo)
  119066. +{
  119067. + audio_info(" ... IN\n");
  119068. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  119069. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  119070. + uinfo->count = 1;
  119071. + uinfo->value.integer.min = CTRL_VOL_MIN;
  119072. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  119073. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  119074. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  119075. + uinfo->count = 1;
  119076. + uinfo->value.integer.min = 0;
  119077. + uinfo->value.integer.max = 1;
  119078. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  119079. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  119080. + uinfo->count = 1;
  119081. + uinfo->value.integer.min = 0;
  119082. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  119083. + }
  119084. + audio_info(" ... OUT\n");
  119085. + return 0;
  119086. +}
  119087. +
  119088. +/* toggles mute on or off depending on the value of nmute, and returns
  119089. + * 1 if the mute value was changed, otherwise 0
  119090. + */
  119091. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  119092. +{
  119093. + /* if settings are ok, just return 0 */
  119094. + if(chip->mute == nmute)
  119095. + return 0;
  119096. +
  119097. + /* if the sound is muted then we need to unmute */
  119098. + if(chip->mute == CTRL_VOL_MUTE)
  119099. + {
  119100. + chip->volume = chip->old_volume; /* copy the old volume back */
  119101. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  119102. + }
  119103. + else /* otherwise we mute */
  119104. + {
  119105. + chip->old_volume = chip->volume;
  119106. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  119107. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  119108. + }
  119109. +
  119110. + chip->mute = nmute;
  119111. + return 1;
  119112. +}
  119113. +
  119114. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  119115. + struct snd_ctl_elem_value *ucontrol)
  119116. +{
  119117. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119118. +
  119119. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  119120. +
  119121. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  119122. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  119123. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  119124. + ucontrol->value.integer.value[0] = chip->mute;
  119125. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  119126. + ucontrol->value.integer.value[0] = chip->dest;
  119127. +
  119128. + return 0;
  119129. +}
  119130. +
  119131. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  119132. + struct snd_ctl_elem_value *ucontrol)
  119133. +{
  119134. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119135. + int changed = 0;
  119136. +
  119137. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  119138. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  119139. + if (chip->mute == CTRL_VOL_MUTE) {
  119140. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  119141. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  119142. + }
  119143. + if (changed
  119144. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  119145. +
  119146. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  119147. + changed = 1;
  119148. + }
  119149. +
  119150. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  119151. + /* Now implemented */
  119152. + audio_info(" Mute attempted\n");
  119153. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  119154. +
  119155. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  119156. + if (ucontrol->value.integer.value[0] != chip->dest) {
  119157. + chip->dest = ucontrol->value.integer.value[0];
  119158. + changed = 1;
  119159. + }
  119160. + }
  119161. +
  119162. + if (changed) {
  119163. + if (bcm2835_audio_set_ctls(chip))
  119164. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  119165. + }
  119166. +
  119167. + return changed;
  119168. +}
  119169. +
  119170. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  119171. +
  119172. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  119173. + {
  119174. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119175. + .name = "PCM Playback Volume",
  119176. + .index = 0,
  119177. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  119178. + .private_value = PCM_PLAYBACK_VOLUME,
  119179. + .info = snd_bcm2835_ctl_info,
  119180. + .get = snd_bcm2835_ctl_get,
  119181. + .put = snd_bcm2835_ctl_put,
  119182. + .count = 1,
  119183. + .tlv = {.p = snd_bcm2835_db_scale}
  119184. + },
  119185. + {
  119186. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119187. + .name = "PCM Playback Switch",
  119188. + .index = 0,
  119189. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  119190. + .private_value = PCM_PLAYBACK_MUTE,
  119191. + .info = snd_bcm2835_ctl_info,
  119192. + .get = snd_bcm2835_ctl_get,
  119193. + .put = snd_bcm2835_ctl_put,
  119194. + .count = 1,
  119195. + },
  119196. + {
  119197. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  119198. + .name = "PCM Playback Route",
  119199. + .index = 0,
  119200. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  119201. + .private_value = PCM_PLAYBACK_DEVICE,
  119202. + .info = snd_bcm2835_ctl_info,
  119203. + .get = snd_bcm2835_ctl_get,
  119204. + .put = snd_bcm2835_ctl_put,
  119205. + .count = 1,
  119206. + },
  119207. +};
  119208. +
  119209. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  119210. + struct snd_ctl_elem_info *uinfo)
  119211. +{
  119212. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119213. + uinfo->count = 1;
  119214. + return 0;
  119215. +}
  119216. +
  119217. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  119218. + struct snd_ctl_elem_value *ucontrol)
  119219. +{
  119220. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119221. + int i;
  119222. +
  119223. + for (i = 0; i < 4; i++)
  119224. + ucontrol->value.iec958.status[i] =
  119225. + (chip->spdif_status >> (i * 8)) && 0xff;
  119226. +
  119227. + return 0;
  119228. +}
  119229. +
  119230. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  119231. + struct snd_ctl_elem_value *ucontrol)
  119232. +{
  119233. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119234. + unsigned int val = 0;
  119235. + int i, change;
  119236. +
  119237. + for (i = 0; i < 4; i++)
  119238. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  119239. +
  119240. + change = val != chip->spdif_status;
  119241. + chip->spdif_status = val;
  119242. +
  119243. + return change;
  119244. +}
  119245. +
  119246. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  119247. + struct snd_ctl_elem_info *uinfo)
  119248. +{
  119249. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119250. + uinfo->count = 1;
  119251. + return 0;
  119252. +}
  119253. +
  119254. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  119255. + struct snd_ctl_elem_value *ucontrol)
  119256. +{
  119257. + /* bcm2835 supports only consumer mode and sets all other format flags
  119258. + * automatically. So the only thing left is signalling non-audio
  119259. + * content */
  119260. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  119261. + return 0;
  119262. +}
  119263. +
  119264. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  119265. + struct snd_ctl_elem_info *uinfo)
  119266. +{
  119267. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  119268. + uinfo->count = 1;
  119269. + return 0;
  119270. +}
  119271. +
  119272. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  119273. + struct snd_ctl_elem_value *ucontrol)
  119274. +{
  119275. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119276. + int i;
  119277. +
  119278. + for (i = 0; i < 4; i++)
  119279. + ucontrol->value.iec958.status[i] =
  119280. + (chip->spdif_status >> (i * 8)) & 0xff;
  119281. + return 0;
  119282. +}
  119283. +
  119284. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  119285. + struct snd_ctl_elem_value *ucontrol)
  119286. +{
  119287. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  119288. + unsigned int val = 0;
  119289. + int i, change;
  119290. +
  119291. + for (i = 0; i < 4; i++)
  119292. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  119293. + change = val != chip->spdif_status;
  119294. + chip->spdif_status = val;
  119295. +
  119296. + return change;
  119297. +}
  119298. +
  119299. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  119300. + {
  119301. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119302. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  119303. + .info = snd_bcm2835_spdif_default_info,
  119304. + .get = snd_bcm2835_spdif_default_get,
  119305. + .put = snd_bcm2835_spdif_default_put
  119306. + },
  119307. + {
  119308. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  119309. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119310. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  119311. + .info = snd_bcm2835_spdif_mask_info,
  119312. + .get = snd_bcm2835_spdif_mask_get,
  119313. + },
  119314. + {
  119315. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  119316. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  119317. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  119318. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  119319. + .info = snd_bcm2835_spdif_stream_info,
  119320. + .get = snd_bcm2835_spdif_stream_get,
  119321. + .put = snd_bcm2835_spdif_stream_put,
  119322. + },
  119323. +};
  119324. +
  119325. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  119326. +{
  119327. + int err;
  119328. + unsigned int idx;
  119329. +
  119330. + strcpy(chip->card->mixername, "Broadcom Mixer");
  119331. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  119332. + err =
  119333. + snd_ctl_add(chip->card,
  119334. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  119335. + if (err < 0)
  119336. + return err;
  119337. + }
  119338. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  119339. + err = snd_ctl_add(chip->card,
  119340. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  119341. + if (err < 0)
  119342. + return err;
  119343. + }
  119344. + return 0;
  119345. +}
  119346. diff -Nur linux-3.12.38/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  119347. --- linux-3.12.38/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  119348. +++ linux-rpi/sound/arm/bcm2835.h 2015-03-09 10:39:38.302893687 +0100
  119349. @@ -0,0 +1,167 @@
  119350. +/*****************************************************************************
  119351. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119352. +*
  119353. +* Unless you and Broadcom execute a separate written software license
  119354. +* agreement governing use of this software, this software is licensed to you
  119355. +* under the terms of the GNU General Public License version 2, available at
  119356. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119357. +*
  119358. +* Notwithstanding the above, under no circumstances may you combine this
  119359. +* software in any way with any other Broadcom software provided under a
  119360. +* license other than the GPL, without Broadcom's express prior written
  119361. +* consent.
  119362. +*****************************************************************************/
  119363. +
  119364. +#ifndef __SOUND_ARM_BCM2835_H
  119365. +#define __SOUND_ARM_BCM2835_H
  119366. +
  119367. +#include <linux/device.h>
  119368. +#include <linux/list.h>
  119369. +#include <linux/interrupt.h>
  119370. +#include <linux/wait.h>
  119371. +#include <sound/core.h>
  119372. +#include <sound/initval.h>
  119373. +#include <sound/pcm.h>
  119374. +#include <sound/pcm_params.h>
  119375. +#include <sound/pcm-indirect.h>
  119376. +#include <linux/workqueue.h>
  119377. +
  119378. +/*
  119379. +#define AUDIO_DEBUG_ENABLE
  119380. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  119381. +*/
  119382. +
  119383. +/* Debug macros */
  119384. +
  119385. +#ifdef AUDIO_DEBUG_ENABLE
  119386. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  119387. +
  119388. +#define audio_debug(fmt, arg...) \
  119389. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  119390. +
  119391. +#define audio_info(fmt, arg...) \
  119392. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  119393. +
  119394. +#else
  119395. +
  119396. +#define audio_debug(fmt, arg...)
  119397. +
  119398. +#define audio_info(fmt, arg...)
  119399. +
  119400. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  119401. +
  119402. +#else
  119403. +
  119404. +#define audio_debug(fmt, arg...)
  119405. +
  119406. +#define audio_info(fmt, arg...)
  119407. +
  119408. +#endif /* AUDIO_DEBUG_ENABLE */
  119409. +
  119410. +#define audio_error(fmt, arg...) \
  119411. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  119412. +
  119413. +#define audio_warning(fmt, arg...) \
  119414. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  119415. +
  119416. +#define audio_alert(fmt, arg...) \
  119417. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  119418. +
  119419. +#define MAX_SUBSTREAMS (8)
  119420. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  119421. +enum {
  119422. + CTRL_VOL_MUTE,
  119423. + CTRL_VOL_UNMUTE
  119424. +};
  119425. +
  119426. +/* macros for alsa2chip and chip2alsa, instead of functions */
  119427. +
  119428. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  119429. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  119430. +
  119431. +/* Some constants for values .. */
  119432. +typedef enum {
  119433. + AUDIO_DEST_AUTO = 0,
  119434. + AUDIO_DEST_HEADPHONES = 1,
  119435. + AUDIO_DEST_HDMI = 2,
  119436. + AUDIO_DEST_MAX,
  119437. +} SND_BCM2835_ROUTE_T;
  119438. +
  119439. +typedef enum {
  119440. + PCM_PLAYBACK_VOLUME,
  119441. + PCM_PLAYBACK_MUTE,
  119442. + PCM_PLAYBACK_DEVICE,
  119443. +} SND_BCM2835_CTRL_T;
  119444. +
  119445. +/* definition of the chip-specific record */
  119446. +typedef struct bcm2835_chip {
  119447. + struct snd_card *card;
  119448. + struct snd_pcm *pcm;
  119449. + struct snd_pcm *pcm_spdif;
  119450. + /* Bitmat for valid reg_base and irq numbers */
  119451. + uint32_t avail_substreams;
  119452. + struct platform_device *pdev[MAX_SUBSTREAMS];
  119453. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  119454. +
  119455. + int volume;
  119456. + int old_volume; /* stores the volume value whist muted */
  119457. + int dest;
  119458. + int mute;
  119459. +
  119460. + unsigned int opened;
  119461. + unsigned int spdif_status;
  119462. + struct mutex audio_mutex;
  119463. +} bcm2835_chip_t;
  119464. +
  119465. +typedef struct bcm2835_alsa_stream {
  119466. + bcm2835_chip_t *chip;
  119467. + struct snd_pcm_substream *substream;
  119468. + struct snd_pcm_indirect pcm_indirect;
  119469. +
  119470. + struct semaphore buffers_update_sem;
  119471. + struct semaphore control_sem;
  119472. + spinlock_t lock;
  119473. + volatile uint32_t control;
  119474. + volatile uint32_t status;
  119475. +
  119476. + int open;
  119477. + int running;
  119478. + int draining;
  119479. +
  119480. + int channels;
  119481. + int params_rate;
  119482. + int pcm_format_width;
  119483. +
  119484. + unsigned int pos;
  119485. + unsigned int buffer_size;
  119486. + unsigned int period_size;
  119487. +
  119488. + uint32_t enable_fifo_irq;
  119489. + irq_handler_t fifo_irq_handler;
  119490. +
  119491. + atomic_t retrieved;
  119492. + struct opaque_AUDIO_INSTANCE_T *instance;
  119493. + struct workqueue_struct *my_wq;
  119494. + int idx;
  119495. +} bcm2835_alsa_stream_t;
  119496. +
  119497. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  119498. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  119499. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  119500. +
  119501. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  119502. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  119503. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  119504. + uint32_t channels, uint32_t samplerate,
  119505. + uint32_t bps);
  119506. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  119507. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  119508. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  119509. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  119510. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  119511. + void *src);
  119512. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  119513. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  119514. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  119515. +
  119516. +#endif /* __SOUND_ARM_BCM2835_H */
  119517. diff -Nur linux-3.12.38/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  119518. --- linux-3.12.38/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  119519. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2015-03-09 10:39:38.302893687 +0100
  119520. @@ -0,0 +1,552 @@
  119521. +/*****************************************************************************
  119522. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  119523. +*
  119524. +* Unless you and Broadcom execute a separate written software license
  119525. +* agreement governing use of this software, this software is licensed to you
  119526. +* under the terms of the GNU General Public License version 2, available at
  119527. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  119528. +*
  119529. +* Notwithstanding the above, under no circumstances may you combine this
  119530. +* software in any way with any other Broadcom software provided under a
  119531. +* license other than the GPL, without Broadcom's express prior written
  119532. +* consent.
  119533. +*****************************************************************************/
  119534. +
  119535. +#include <linux/interrupt.h>
  119536. +#include <linux/slab.h>
  119537. +
  119538. +#include <sound/asoundef.h>
  119539. +
  119540. +#include "bcm2835.h"
  119541. +
  119542. +/* hardware definition */
  119543. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  119544. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  119545. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  119546. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  119547. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  119548. + .rate_min = 8000,
  119549. + .rate_max = 48000,
  119550. + .channels_min = 1,
  119551. + .channels_max = 2,
  119552. + .buffer_bytes_max = 128 * 1024,
  119553. + .period_bytes_min = 1 * 1024,
  119554. + .period_bytes_max = 128 * 1024,
  119555. + .periods_min = 1,
  119556. + .periods_max = 128,
  119557. +};
  119558. +
  119559. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  119560. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  119561. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  119562. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  119563. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  119564. + SNDRV_PCM_RATE_48000,
  119565. + .rate_min = 44100,
  119566. + .rate_max = 48000,
  119567. + .channels_min = 2,
  119568. + .channels_max = 2,
  119569. + .buffer_bytes_max = 128 * 1024,
  119570. + .period_bytes_min = 1 * 1024,
  119571. + .period_bytes_max = 128 * 1024,
  119572. + .periods_min = 1,
  119573. + .periods_max = 128,
  119574. +};
  119575. +
  119576. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  119577. +{
  119578. + audio_info("Freeing up alsa stream here ..\n");
  119579. + if (runtime->private_data)
  119580. + kfree(runtime->private_data);
  119581. + runtime->private_data = NULL;
  119582. +}
  119583. +
  119584. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  119585. +{
  119586. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  119587. + uint32_t consumed = 0;
  119588. + int new_period = 0;
  119589. +
  119590. + audio_info(" .. IN\n");
  119591. +
  119592. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  119593. + alsa_stream ? alsa_stream->substream : 0);
  119594. +
  119595. + if (alsa_stream->open)
  119596. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  119597. +
  119598. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  119599. + * each iteration are the buffers that have been played out already
  119600. + */
  119601. +
  119602. + if (alsa_stream->period_size) {
  119603. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  119604. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  119605. + new_period = 1;
  119606. + }
  119607. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  119608. + alsa_stream->pos,
  119609. + consumed,
  119610. + alsa_stream->buffer_size,
  119611. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  119612. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  119613. + new_period);
  119614. + if (alsa_stream->buffer_size) {
  119615. + alsa_stream->pos += consumed &~ (1<<30);
  119616. + alsa_stream->pos %= alsa_stream->buffer_size;
  119617. + }
  119618. +
  119619. + if (alsa_stream->substream) {
  119620. + if (new_period)
  119621. + snd_pcm_period_elapsed(alsa_stream->substream);
  119622. + } else {
  119623. + audio_warning(" unexpected NULL substream\n");
  119624. + }
  119625. + audio_info(" .. OUT\n");
  119626. +
  119627. + return IRQ_HANDLED;
  119628. +}
  119629. +
  119630. +/* open callback */
  119631. +static int snd_bcm2835_playback_open_generic(
  119632. + struct snd_pcm_substream *substream, int spdif)
  119633. +{
  119634. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  119635. + struct snd_pcm_runtime *runtime = substream->runtime;
  119636. + bcm2835_alsa_stream_t *alsa_stream;
  119637. + int idx;
  119638. + int err;
  119639. +
  119640. + audio_info(" .. IN (%d)\n", substream->number);
  119641. +
  119642. + if(mutex_lock_interruptible(&chip->audio_mutex))
  119643. + {
  119644. + audio_error("Interrupted whilst waiting for lock\n");
  119645. + return -EINTR;
  119646. + }
  119647. + audio_info("Alsa open (%d)\n", substream->number);
  119648. + idx = substream->number;
  119649. +
  119650. + if (spdif && chip->opened != 0)
  119651. + return -EBUSY;
  119652. + else if (!spdif && (chip->opened & (1 << idx)))
  119653. + return -EBUSY;
  119654. +
  119655. + if (idx > MAX_SUBSTREAMS) {
  119656. + audio_error
  119657. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  119658. + idx, MAX_SUBSTREAMS);
  119659. + err = -ENODEV;
  119660. + goto out;
  119661. + }
  119662. +
  119663. + /* Check if we are ready */
  119664. + if (!(chip->avail_substreams & (1 << idx))) {
  119665. + /* We are not ready yet */
  119666. + audio_error("substream(%d) device is not ready yet\n", idx);
  119667. + err = -EAGAIN;
  119668. + goto out;
  119669. + }
  119670. +
  119671. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  119672. + if (alsa_stream == NULL) {
  119673. + err = -ENOMEM;
  119674. + goto out;
  119675. + }
  119676. +
  119677. + /* Initialise alsa_stream */
  119678. + alsa_stream->chip = chip;
  119679. + alsa_stream->substream = substream;
  119680. + alsa_stream->idx = idx;
  119681. +
  119682. + sema_init(&alsa_stream->buffers_update_sem, 0);
  119683. + sema_init(&alsa_stream->control_sem, 0);
  119684. + spin_lock_init(&alsa_stream->lock);
  119685. +
  119686. + /* Enabled in start trigger, called on each "fifo irq" after that */
  119687. + alsa_stream->enable_fifo_irq = 0;
  119688. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  119689. +
  119690. + err = bcm2835_audio_open(alsa_stream);
  119691. + if (err != 0) {
  119692. + kfree(alsa_stream);
  119693. + return err;
  119694. + }
  119695. + runtime->private_data = alsa_stream;
  119696. + runtime->private_free = snd_bcm2835_playback_free;
  119697. + if (spdif) {
  119698. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  119699. + } else {
  119700. + /* clear spdif status, as we are not in spdif mode */
  119701. + chip->spdif_status = 0;
  119702. + runtime->hw = snd_bcm2835_playback_hw;
  119703. + }
  119704. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  119705. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  119706. + 16);
  119707. +
  119708. + chip->alsa_stream[idx] = alsa_stream;
  119709. +
  119710. + chip->opened |= (1 << idx);
  119711. + alsa_stream->open = 1;
  119712. + alsa_stream->draining = 1;
  119713. +
  119714. +out:
  119715. + mutex_unlock(&chip->audio_mutex);
  119716. +
  119717. + audio_info(" .. OUT =%d\n", err);
  119718. +
  119719. + return err;
  119720. +}
  119721. +
  119722. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  119723. +{
  119724. + return snd_bcm2835_playback_open_generic(substream, 0);
  119725. +}
  119726. +
  119727. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  119728. +{
  119729. + return snd_bcm2835_playback_open_generic(substream, 1);
  119730. +}
  119731. +
  119732. +/* close callback */
  119733. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  119734. +{
  119735. + /* the hardware-specific codes will be here */
  119736. +
  119737. + bcm2835_chip_t *chip;
  119738. + struct snd_pcm_runtime *runtime;
  119739. + bcm2835_alsa_stream_t *alsa_stream;
  119740. +
  119741. + audio_info(" .. IN\n");
  119742. +
  119743. + chip = snd_pcm_substream_chip(substream);
  119744. + if(mutex_lock_interruptible(&chip->audio_mutex))
  119745. + {
  119746. + audio_error("Interrupted whilst waiting for lock\n");
  119747. + return -EINTR;
  119748. + }
  119749. + runtime = substream->runtime;
  119750. + alsa_stream = runtime->private_data;
  119751. +
  119752. + audio_info("Alsa close\n");
  119753. +
  119754. + /*
  119755. + * Call stop if it's still running. This happens when app
  119756. + * is force killed and we don't get a stop trigger.
  119757. + */
  119758. + if (alsa_stream->running) {
  119759. + int err;
  119760. + err = bcm2835_audio_stop(alsa_stream);
  119761. + alsa_stream->running = 0;
  119762. + if (err != 0)
  119763. + audio_error(" Failed to STOP alsa device\n");
  119764. + }
  119765. +
  119766. + alsa_stream->period_size = 0;
  119767. + alsa_stream->buffer_size = 0;
  119768. +
  119769. + if (alsa_stream->open) {
  119770. + alsa_stream->open = 0;
  119771. + bcm2835_audio_close(alsa_stream);
  119772. + }
  119773. + if (alsa_stream->chip)
  119774. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  119775. + /*
  119776. + * Do not free up alsa_stream here, it will be freed up by
  119777. + * runtime->private_free callback we registered in *_open above
  119778. + */
  119779. +
  119780. + chip->opened &= ~(1 << substream->number);
  119781. +
  119782. + mutex_unlock(&chip->audio_mutex);
  119783. + audio_info(" .. OUT\n");
  119784. +
  119785. + return 0;
  119786. +}
  119787. +
  119788. +/* hw_params callback */
  119789. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  119790. + struct snd_pcm_hw_params *params)
  119791. +{
  119792. + struct snd_pcm_runtime *runtime = substream->runtime;
  119793. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119794. + int err;
  119795. +
  119796. + audio_info(" .. IN\n");
  119797. +
  119798. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  119799. + if (err < 0) {
  119800. + audio_error
  119801. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  119802. + return err;
  119803. + }
  119804. +
  119805. + alsa_stream->channels = params_channels(params);
  119806. + alsa_stream->params_rate = params_rate(params);
  119807. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  119808. + audio_info(" .. OUT\n");
  119809. +
  119810. + return err;
  119811. +}
  119812. +
  119813. +/* hw_free callback */
  119814. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  119815. +{
  119816. + audio_info(" .. IN\n");
  119817. + return snd_pcm_lib_free_pages(substream);
  119818. +}
  119819. +
  119820. +/* prepare callback */
  119821. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  119822. +{
  119823. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  119824. + struct snd_pcm_runtime *runtime = substream->runtime;
  119825. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119826. + int channels;
  119827. + int err;
  119828. +
  119829. + audio_info(" .. IN\n");
  119830. +
  119831. + /* notify the vchiq that it should enter spdif passthrough mode by
  119832. + * setting channels=0 (see
  119833. + * https://github.com/raspberrypi/linux/issues/528) */
  119834. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  119835. + channels = 0;
  119836. + else
  119837. + channels = alsa_stream->channels;
  119838. +
  119839. + err = bcm2835_audio_set_params(alsa_stream, channels,
  119840. + alsa_stream->params_rate,
  119841. + alsa_stream->pcm_format_width);
  119842. + if (err < 0) {
  119843. + audio_error(" error setting hw params\n");
  119844. + }
  119845. +
  119846. + bcm2835_audio_setup(alsa_stream);
  119847. +
  119848. + /* in preparation of the stream, set the controls (volume level) of the stream */
  119849. + bcm2835_audio_set_ctls(alsa_stream->chip);
  119850. +
  119851. +
  119852. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  119853. +
  119854. + alsa_stream->pcm_indirect.hw_buffer_size =
  119855. + alsa_stream->pcm_indirect.sw_buffer_size =
  119856. + snd_pcm_lib_buffer_bytes(substream);
  119857. +
  119858. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  119859. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  119860. + alsa_stream->pos = 0;
  119861. +
  119862. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  119863. + alsa_stream->buffer_size, alsa_stream->period_size,
  119864. + alsa_stream->pos, runtime->frame_bits);
  119865. +
  119866. + audio_info(" .. OUT\n");
  119867. + return 0;
  119868. +}
  119869. +
  119870. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  119871. + struct snd_pcm_indirect *rec, size_t bytes)
  119872. +{
  119873. + struct snd_pcm_runtime *runtime = substream->runtime;
  119874. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119875. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  119876. + int err;
  119877. +
  119878. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  119879. + if (err)
  119880. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  119881. +
  119882. +}
  119883. +
  119884. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  119885. +{
  119886. + struct snd_pcm_runtime *runtime = substream->runtime;
  119887. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119888. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  119889. +
  119890. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  119891. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  119892. + snd_bcm2835_pcm_transfer);
  119893. + return 0;
  119894. +}
  119895. +
  119896. +/* trigger callback */
  119897. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  119898. +{
  119899. + struct snd_pcm_runtime *runtime = substream->runtime;
  119900. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119901. + int err = 0;
  119902. +
  119903. + audio_info(" .. IN\n");
  119904. +
  119905. + switch (cmd) {
  119906. + case SNDRV_PCM_TRIGGER_START:
  119907. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  119908. + alsa_stream->running);
  119909. + if (!alsa_stream->running) {
  119910. + err = bcm2835_audio_start(alsa_stream);
  119911. + if (err == 0) {
  119912. + alsa_stream->pcm_indirect.hw_io =
  119913. + alsa_stream->pcm_indirect.hw_data =
  119914. + bytes_to_frames(runtime,
  119915. + alsa_stream->pos);
  119916. + substream->ops->ack(substream);
  119917. + alsa_stream->running = 1;
  119918. + alsa_stream->draining = 1;
  119919. + } else {
  119920. + audio_error(" Failed to START alsa device (%d)\n", err);
  119921. + }
  119922. + }
  119923. + break;
  119924. + case SNDRV_PCM_TRIGGER_STOP:
  119925. + audio_debug
  119926. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  119927. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  119928. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  119929. + audio_info("DRAINING\n");
  119930. + alsa_stream->draining = 1;
  119931. + } else {
  119932. + audio_info("DROPPING\n");
  119933. + alsa_stream->draining = 0;
  119934. + }
  119935. + if (alsa_stream->running) {
  119936. + err = bcm2835_audio_stop(alsa_stream);
  119937. + if (err != 0)
  119938. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  119939. + alsa_stream->running = 0;
  119940. + }
  119941. + break;
  119942. + default:
  119943. + err = -EINVAL;
  119944. + }
  119945. +
  119946. + audio_info(" .. OUT\n");
  119947. + return err;
  119948. +}
  119949. +
  119950. +/* pointer callback */
  119951. +static snd_pcm_uframes_t
  119952. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  119953. +{
  119954. + struct snd_pcm_runtime *runtime = substream->runtime;
  119955. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  119956. +
  119957. + audio_info(" .. IN\n");
  119958. +
  119959. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  119960. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  119961. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  119962. + alsa_stream->pos);
  119963. +
  119964. + audio_info(" .. OUT\n");
  119965. + return snd_pcm_indirect_playback_pointer(substream,
  119966. + &alsa_stream->pcm_indirect,
  119967. + alsa_stream->pos);
  119968. +}
  119969. +
  119970. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  119971. + unsigned int cmd, void *arg)
  119972. +{
  119973. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  119974. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  119975. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  119976. + return ret;
  119977. +}
  119978. +
  119979. +/* operators */
  119980. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  119981. + .open = snd_bcm2835_playback_open,
  119982. + .close = snd_bcm2835_playback_close,
  119983. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  119984. + .hw_params = snd_bcm2835_pcm_hw_params,
  119985. + .hw_free = snd_bcm2835_pcm_hw_free,
  119986. + .prepare = snd_bcm2835_pcm_prepare,
  119987. + .trigger = snd_bcm2835_pcm_trigger,
  119988. + .pointer = snd_bcm2835_pcm_pointer,
  119989. + .ack = snd_bcm2835_pcm_ack,
  119990. +};
  119991. +
  119992. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  119993. + .open = snd_bcm2835_playback_spdif_open,
  119994. + .close = snd_bcm2835_playback_close,
  119995. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  119996. + .hw_params = snd_bcm2835_pcm_hw_params,
  119997. + .hw_free = snd_bcm2835_pcm_hw_free,
  119998. + .prepare = snd_bcm2835_pcm_prepare,
  119999. + .trigger = snd_bcm2835_pcm_trigger,
  120000. + .pointer = snd_bcm2835_pcm_pointer,
  120001. + .ack = snd_bcm2835_pcm_ack,
  120002. +};
  120003. +
  120004. +/* create a pcm device */
  120005. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  120006. +{
  120007. + struct snd_pcm *pcm;
  120008. + int err;
  120009. +
  120010. + audio_info(" .. IN\n");
  120011. + mutex_init(&chip->audio_mutex);
  120012. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120013. + {
  120014. + audio_error("Interrupted whilst waiting for lock\n");
  120015. + return -EINTR;
  120016. + }
  120017. + err =
  120018. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  120019. + if (err < 0)
  120020. + return err;
  120021. + pcm->private_data = chip;
  120022. + strcpy(pcm->name, "bcm2835 ALSA");
  120023. + chip->pcm = pcm;
  120024. + chip->dest = AUDIO_DEST_AUTO;
  120025. + chip->volume = alsa2chip(0);
  120026. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  120027. + /* set operators */
  120028. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  120029. + &snd_bcm2835_playback_ops);
  120030. +
  120031. + /* pre-allocation of buffers */
  120032. + /* NOTE: this may fail */
  120033. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  120034. + snd_dma_continuous_data
  120035. + (GFP_KERNEL), 64 * 1024,
  120036. + 64 * 1024);
  120037. +
  120038. + mutex_unlock(&chip->audio_mutex);
  120039. + audio_info(" .. OUT\n");
  120040. +
  120041. + return 0;
  120042. +}
  120043. +
  120044. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  120045. +{
  120046. + struct snd_pcm *pcm;
  120047. + int err;
  120048. +
  120049. + audio_info(" .. IN\n");
  120050. + if(mutex_lock_interruptible(&chip->audio_mutex))
  120051. + {
  120052. + audio_error("Interrupted whilst waiting for lock\n");
  120053. + return -EINTR;
  120054. + }
  120055. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  120056. + if (err < 0)
  120057. + return err;
  120058. +
  120059. + pcm->private_data = chip;
  120060. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  120061. + chip->pcm_spdif = pcm;
  120062. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  120063. + &snd_bcm2835_playback_spdif_ops);
  120064. +
  120065. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  120066. + snd_dma_continuous_data (GFP_KERNEL),
  120067. + 64 * 1024, 64 * 1024);
  120068. + mutex_unlock(&chip->audio_mutex);
  120069. + audio_info(" .. OUT\n");
  120070. +
  120071. + return 0;
  120072. +}
  120073. diff -Nur linux-3.12.38/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  120074. --- linux-3.12.38/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  120075. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2015-03-10 17:26:51.874216684 +0100
  120076. @@ -0,0 +1,901 @@
  120077. +/*****************************************************************************
  120078. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  120079. +*
  120080. +* Unless you and Broadcom execute a separate written software license
  120081. +* agreement governing use of this software, this software is licensed to you
  120082. +* under the terms of the GNU General Public License version 2, available at
  120083. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  120084. +*
  120085. +* Notwithstanding the above, under no circumstances may you combine this
  120086. +* software in any way with any other Broadcom software provided under a
  120087. +* license other than the GPL, without Broadcom's express prior written
  120088. +* consent.
  120089. +*****************************************************************************/
  120090. +
  120091. +#include <linux/device.h>
  120092. +#include <sound/core.h>
  120093. +#include <sound/initval.h>
  120094. +#include <sound/pcm.h>
  120095. +#include <linux/io.h>
  120096. +#include <linux/interrupt.h>
  120097. +#include <linux/fs.h>
  120098. +#include <linux/file.h>
  120099. +#include <linux/mm.h>
  120100. +#include <linux/syscalls.h>
  120101. +#include <asm/uaccess.h>
  120102. +#include <linux/slab.h>
  120103. +#include <linux/delay.h>
  120104. +#include <linux/atomic.h>
  120105. +#include <linux/module.h>
  120106. +#include <linux/completion.h>
  120107. +
  120108. +#include "bcm2835.h"
  120109. +
  120110. +/* ---- Include Files -------------------------------------------------------- */
  120111. +
  120112. +#include "interface/vchi/vchi.h"
  120113. +#include "vc_vchi_audioserv_defs.h"
  120114. +
  120115. +/* ---- Private Constants and Types ------------------------------------------ */
  120116. +
  120117. +#define BCM2835_AUDIO_STOP 0
  120118. +#define BCM2835_AUDIO_START 1
  120119. +#define BCM2835_AUDIO_WRITE 2
  120120. +
  120121. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  120122. +#ifdef AUDIO_DEBUG_ENABLE
  120123. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120124. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120125. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120126. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120127. +#else
  120128. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  120129. + #define LOG_WARN( fmt, arg... )
  120130. + #define LOG_INFO( fmt, arg... )
  120131. + #define LOG_DBG( fmt, arg... )
  120132. +#endif
  120133. +
  120134. +typedef struct opaque_AUDIO_INSTANCE_T {
  120135. + uint32_t num_connections;
  120136. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  120137. + struct completion msg_avail_comp;
  120138. + struct mutex vchi_mutex;
  120139. + bcm2835_alsa_stream_t *alsa_stream;
  120140. + int32_t result;
  120141. + short peer_version;
  120142. +} AUDIO_INSTANCE_T;
  120143. +
  120144. +bool force_bulk = false;
  120145. +
  120146. +/* ---- Private Variables ---------------------------------------------------- */
  120147. +
  120148. +/* ---- Private Function Prototypes ------------------------------------------ */
  120149. +
  120150. +/* ---- Private Functions ---------------------------------------------------- */
  120151. +
  120152. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  120153. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  120154. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  120155. + uint32_t count, void *src);
  120156. +
  120157. +typedef struct {
  120158. + struct work_struct my_work;
  120159. + bcm2835_alsa_stream_t *alsa_stream;
  120160. + int cmd;
  120161. + void *src;
  120162. + uint32_t count;
  120163. +} my_work_t;
  120164. +
  120165. +static void my_wq_function(struct work_struct *work)
  120166. +{
  120167. + my_work_t *w = (my_work_t *) work;
  120168. + int ret = -9;
  120169. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  120170. + switch (w->cmd) {
  120171. + case BCM2835_AUDIO_START:
  120172. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  120173. + break;
  120174. + case BCM2835_AUDIO_STOP:
  120175. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  120176. + break;
  120177. + case BCM2835_AUDIO_WRITE:
  120178. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  120179. + w->src);
  120180. + break;
  120181. + default:
  120182. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  120183. + break;
  120184. + }
  120185. + kfree((void *)work);
  120186. + LOG_DBG(" .. OUT %d\n", ret);
  120187. +}
  120188. +
  120189. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  120190. +{
  120191. + int ret = -1;
  120192. + LOG_DBG(" .. IN\n");
  120193. + if (alsa_stream->my_wq) {
  120194. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120195. + /*--- Queue some work (item 1) ---*/
  120196. + if (work) {
  120197. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120198. + work->alsa_stream = alsa_stream;
  120199. + work->cmd = BCM2835_AUDIO_START;
  120200. + if (queue_work
  120201. + (alsa_stream->my_wq, (struct work_struct *)work))
  120202. + ret = 0;
  120203. + } else
  120204. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120205. + }
  120206. + LOG_DBG(" .. OUT %d\n", ret);
  120207. + return ret;
  120208. +}
  120209. +
  120210. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  120211. +{
  120212. + int ret = -1;
  120213. + LOG_DBG(" .. IN\n");
  120214. + if (alsa_stream->my_wq) {
  120215. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120216. + /*--- Queue some work (item 1) ---*/
  120217. + if (work) {
  120218. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120219. + work->alsa_stream = alsa_stream;
  120220. + work->cmd = BCM2835_AUDIO_STOP;
  120221. + if (queue_work
  120222. + (alsa_stream->my_wq, (struct work_struct *)work))
  120223. + ret = 0;
  120224. + } else
  120225. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120226. + }
  120227. + LOG_DBG(" .. OUT %d\n", ret);
  120228. + return ret;
  120229. +}
  120230. +
  120231. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  120232. + uint32_t count, void *src)
  120233. +{
  120234. + int ret = -1;
  120235. + LOG_DBG(" .. IN\n");
  120236. + if (alsa_stream->my_wq) {
  120237. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  120238. + /*--- Queue some work (item 1) ---*/
  120239. + if (work) {
  120240. + INIT_WORK((struct work_struct *)work, my_wq_function);
  120241. + work->alsa_stream = alsa_stream;
  120242. + work->cmd = BCM2835_AUDIO_WRITE;
  120243. + work->src = src;
  120244. + work->count = count;
  120245. + if (queue_work
  120246. + (alsa_stream->my_wq, (struct work_struct *)work))
  120247. + ret = 0;
  120248. + } else
  120249. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  120250. + }
  120251. + LOG_DBG(" .. OUT %d\n", ret);
  120252. + return ret;
  120253. +}
  120254. +
  120255. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  120256. +{
  120257. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  120258. + return;
  120259. +}
  120260. +
  120261. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  120262. +{
  120263. + if (alsa_stream->my_wq) {
  120264. + flush_workqueue(alsa_stream->my_wq);
  120265. + destroy_workqueue(alsa_stream->my_wq);
  120266. + alsa_stream->my_wq = NULL;
  120267. + }
  120268. + return;
  120269. +}
  120270. +
  120271. +static void audio_vchi_callback(void *param,
  120272. + const VCHI_CALLBACK_REASON_T reason,
  120273. + void *msg_handle)
  120274. +{
  120275. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  120276. + int32_t status;
  120277. + int32_t msg_len;
  120278. + VC_AUDIO_MSG_T m;
  120279. + LOG_DBG(" .. IN instance=%p, handle=%p, alsa=%p, reason=%d, handle=%p\n",
  120280. + instance, instance ? instance->vchi_handle[0] : NULL, instance ? instance->alsa_stream : NULL, reason, msg_handle);
  120281. +
  120282. + if (reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  120283. + return;
  120284. + }
  120285. + if (!instance) {
  120286. + LOG_ERR(" .. instance is null\n");
  120287. + BUG();
  120288. + return;
  120289. + }
  120290. + if (!instance->vchi_handle[0]) {
  120291. + LOG_ERR(" .. instance->vchi_handle[0] is null\n");
  120292. + BUG();
  120293. + return;
  120294. + }
  120295. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  120296. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  120297. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  120298. + LOG_DBG
  120299. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  120300. + instance, m.u.result.success);
  120301. + instance->result = m.u.result.success;
  120302. + complete(&instance->msg_avail_comp);
  120303. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  120304. + bcm2835_alsa_stream_t *alsa_stream = instance->alsa_stream;
  120305. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  120306. + LOG_DBG
  120307. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  120308. + instance, m.u.complete.count);
  120309. + if (alsa_stream && callback) {
  120310. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  120311. + callback(0, alsa_stream);
  120312. + } else {
  120313. + LOG_ERR(" .. unexpected alsa_stream=%p, callback=%p\n",
  120314. + alsa_stream, callback);
  120315. + }
  120316. + } else {
  120317. + LOG_ERR(" .. unexpected m.type=%d\n", m.type);
  120318. + }
  120319. + LOG_DBG(" .. OUT\n");
  120320. +}
  120321. +
  120322. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  120323. + VCHI_CONNECTION_T **
  120324. + vchi_connections,
  120325. + uint32_t num_connections)
  120326. +{
  120327. + uint32_t i;
  120328. + AUDIO_INSTANCE_T *instance;
  120329. + int status;
  120330. +
  120331. + LOG_DBG("%s: start", __func__);
  120332. +
  120333. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  120334. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  120335. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  120336. +
  120337. + return NULL;
  120338. + }
  120339. + /* Allocate memory for this instance */
  120340. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  120341. + if (!instance)
  120342. + return NULL;
  120343. +
  120344. + instance->num_connections = num_connections;
  120345. +
  120346. + /* Create a lock for exclusive, serialized VCHI connection access */
  120347. + mutex_init(&instance->vchi_mutex);
  120348. + /* Open the VCHI service connections */
  120349. + for (i = 0; i < num_connections; i++) {
  120350. + SERVICE_CREATION_T params = {
  120351. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  120352. + VC_AUDIO_SERVER_NAME, // 4cc service code
  120353. + vchi_connections[i], // passed in fn pointers
  120354. + 0, // rx fifo size (unused)
  120355. + 0, // tx fifo size (unused)
  120356. + audio_vchi_callback, // service callback
  120357. + instance, // service callback parameter
  120358. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  120359. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  120360. + 0 // want crc check on bulk transfers
  120361. + };
  120362. +
  120363. + LOG_DBG("%s: about to open %i\n", __func__, i);
  120364. + status = vchi_service_open(vchi_instance, &params,
  120365. + &instance->vchi_handle[i]);
  120366. + LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
  120367. + if (status) {
  120368. + LOG_ERR
  120369. + ("%s: failed to open VCHI service connection (status=%d)\n",
  120370. + __func__, status);
  120371. +
  120372. + goto err_close_services;
  120373. + }
  120374. + /* Finished with the service for now */
  120375. + vchi_service_release(instance->vchi_handle[i]);
  120376. + }
  120377. +
  120378. + LOG_DBG("%s: okay\n", __func__);
  120379. + return instance;
  120380. +
  120381. +err_close_services:
  120382. + for (i = 0; i < instance->num_connections; i++) {
  120383. + LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
  120384. + if (instance->vchi_handle[i])
  120385. + vchi_service_close(instance->vchi_handle[i]);
  120386. + }
  120387. +
  120388. + kfree(instance);
  120389. + LOG_ERR("%s: error\n", __func__);
  120390. +
  120391. + return NULL;
  120392. +}
  120393. +
  120394. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  120395. +{
  120396. + uint32_t i;
  120397. +
  120398. + LOG_DBG(" .. IN\n");
  120399. +
  120400. + if (instance == NULL) {
  120401. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  120402. +
  120403. + return -1;
  120404. + }
  120405. +
  120406. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  120407. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120408. + {
  120409. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120410. + return -EINTR;
  120411. + }
  120412. +
  120413. + /* Close all VCHI service connections */
  120414. + for (i = 0; i < instance->num_connections; i++) {
  120415. + int32_t success;
  120416. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  120417. + vchi_service_use(instance->vchi_handle[i]);
  120418. +
  120419. + success = vchi_service_close(instance->vchi_handle[i]);
  120420. + if (success != 0) {
  120421. + LOG_ERR
  120422. + ("%s: failed to close VCHI service connection (status=%d)\n",
  120423. + __func__, success);
  120424. + }
  120425. + }
  120426. +
  120427. + mutex_unlock(&instance->vchi_mutex);
  120428. +
  120429. + kfree(instance);
  120430. +
  120431. + LOG_DBG(" .. OUT\n");
  120432. +
  120433. + return 0;
  120434. +}
  120435. +
  120436. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  120437. +{
  120438. + static VCHI_INSTANCE_T vchi_instance;
  120439. + static VCHI_CONNECTION_T *vchi_connection;
  120440. + static int initted;
  120441. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120442. + int ret;
  120443. + LOG_DBG(" .. IN\n");
  120444. +
  120445. + LOG_INFO("%s: start\n", __func__);
  120446. + BUG_ON(instance);
  120447. + if (instance) {
  120448. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  120449. + __func__, instance);
  120450. + instance->alsa_stream = alsa_stream;
  120451. + alsa_stream->instance = instance;
  120452. + ret = 0; // xxx todo -1;
  120453. + goto err_free_mem;
  120454. + }
  120455. +
  120456. + /* Initialize and create a VCHI connection */
  120457. + if (!initted) {
  120458. + ret = vchi_initialise(&vchi_instance);
  120459. + if (ret != 0) {
  120460. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  120461. + __func__, ret);
  120462. +
  120463. + ret = -EIO;
  120464. + goto err_free_mem;
  120465. + }
  120466. + ret = vchi_connect(NULL, 0, vchi_instance);
  120467. + if (ret != 0) {
  120468. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  120469. + __func__, ret);
  120470. +
  120471. + ret = -EIO;
  120472. + goto err_free_mem;
  120473. + }
  120474. + initted = 1;
  120475. + }
  120476. +
  120477. + /* Initialize an instance of the audio service */
  120478. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  120479. +
  120480. + if (instance == NULL) {
  120481. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  120482. +
  120483. + ret = -EPERM;
  120484. + goto err_free_mem;
  120485. + }
  120486. +
  120487. + instance->alsa_stream = alsa_stream;
  120488. + alsa_stream->instance = instance;
  120489. +
  120490. + LOG_DBG(" success !\n");
  120491. +err_free_mem:
  120492. + LOG_DBG(" .. OUT\n");
  120493. +
  120494. + return ret;
  120495. +}
  120496. +
  120497. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  120498. +{
  120499. + AUDIO_INSTANCE_T *instance;
  120500. + VC_AUDIO_MSG_T m;
  120501. + int32_t success;
  120502. + int ret;
  120503. + LOG_DBG(" .. IN\n");
  120504. +
  120505. + my_workqueue_init(alsa_stream);
  120506. +
  120507. + ret = bcm2835_audio_open_connection(alsa_stream);
  120508. + if (ret != 0) {
  120509. + ret = -1;
  120510. + goto exit;
  120511. + }
  120512. + instance = alsa_stream->instance;
  120513. + LOG_DBG(" instance (%p)\n", instance);
  120514. +
  120515. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120516. + {
  120517. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120518. + return -EINTR;
  120519. + }
  120520. + vchi_service_use(instance->vchi_handle[0]);
  120521. +
  120522. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  120523. +
  120524. + /* Send the message to the videocore */
  120525. + success = vchi_msg_queue(instance->vchi_handle[0],
  120526. + &m, sizeof m,
  120527. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120528. +
  120529. + if (success != 0) {
  120530. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120531. + __func__, success);
  120532. +
  120533. + ret = -1;
  120534. + goto unlock;
  120535. + }
  120536. +
  120537. + ret = 0;
  120538. +
  120539. +unlock:
  120540. + vchi_service_release(instance->vchi_handle[0]);
  120541. + mutex_unlock(&instance->vchi_mutex);
  120542. +exit:
  120543. + LOG_DBG(" .. OUT\n");
  120544. + return ret;
  120545. +}
  120546. +
  120547. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  120548. + bcm2835_chip_t * chip)
  120549. +{
  120550. + VC_AUDIO_MSG_T m;
  120551. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120552. + int32_t success;
  120553. + int ret;
  120554. + LOG_DBG(" .. IN\n");
  120555. +
  120556. + LOG_INFO
  120557. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  120558. +
  120559. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120560. + {
  120561. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120562. + return -EINTR;
  120563. + }
  120564. + vchi_service_use(instance->vchi_handle[0]);
  120565. +
  120566. + instance->result = -1;
  120567. +
  120568. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  120569. + m.u.control.dest = chip->dest;
  120570. + m.u.control.volume = chip->volume;
  120571. +
  120572. + /* Create the message available completion */
  120573. + init_completion(&instance->msg_avail_comp);
  120574. +
  120575. + /* Send the message to the videocore */
  120576. + success = vchi_msg_queue(instance->vchi_handle[0],
  120577. + &m, sizeof m,
  120578. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120579. +
  120580. + if (success != 0) {
  120581. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120582. + __func__, success);
  120583. +
  120584. + ret = -1;
  120585. + goto unlock;
  120586. + }
  120587. +
  120588. + /* We are expecting a reply from the videocore */
  120589. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  120590. + if (ret) {
  120591. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  120592. + __func__, success);
  120593. + goto unlock;
  120594. + }
  120595. +
  120596. + if (instance->result != 0) {
  120597. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  120598. +
  120599. + ret = -1;
  120600. + goto unlock;
  120601. + }
  120602. +
  120603. + ret = 0;
  120604. +
  120605. +unlock:
  120606. + vchi_service_release(instance->vchi_handle[0]);
  120607. + mutex_unlock(&instance->vchi_mutex);
  120608. +
  120609. + LOG_DBG(" .. OUT\n");
  120610. + return ret;
  120611. +}
  120612. +
  120613. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  120614. +{
  120615. + int i;
  120616. + int ret = 0;
  120617. + LOG_DBG(" .. IN\n");
  120618. + LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  120619. +
  120620. + /* change ctls for all substreams */
  120621. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  120622. + if (chip->avail_substreams & (1 << i)) {
  120623. + if (!chip->alsa_stream[i])
  120624. + {
  120625. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  120626. + ret = 0;
  120627. + }
  120628. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  120629. + (chip->alsa_stream[i], chip) != 0)
  120630. + {
  120631. + LOG_ERR("Couldn't set the controls for stream %d\n", i);
  120632. + ret = -1;
  120633. + }
  120634. + else LOG_DBG(" Controls set for stream %d\n", i);
  120635. + }
  120636. + }
  120637. + LOG_DBG(" .. OUT ret=%d\n", ret);
  120638. + return ret;
  120639. +}
  120640. +
  120641. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  120642. + uint32_t channels, uint32_t samplerate,
  120643. + uint32_t bps)
  120644. +{
  120645. + VC_AUDIO_MSG_T m;
  120646. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120647. + int32_t success;
  120648. + int ret;
  120649. + LOG_DBG(" .. IN\n");
  120650. +
  120651. + LOG_INFO
  120652. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  120653. + channels, samplerate, bps);
  120654. +
  120655. + /* resend ctls - alsa_stream may not have been open when first send */
  120656. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  120657. + if (ret != 0) {
  120658. + LOG_ERR(" Alsa controls not supported\n");
  120659. + return -EINVAL;
  120660. + }
  120661. +
  120662. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120663. + {
  120664. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120665. + return -EINTR;
  120666. + }
  120667. + vchi_service_use(instance->vchi_handle[0]);
  120668. +
  120669. + instance->result = -1;
  120670. +
  120671. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  120672. + m.u.config.channels = channels;
  120673. + m.u.config.samplerate = samplerate;
  120674. + m.u.config.bps = bps;
  120675. +
  120676. + /* Create the message available completion */
  120677. + init_completion(&instance->msg_avail_comp);
  120678. +
  120679. + /* Send the message to the videocore */
  120680. + success = vchi_msg_queue(instance->vchi_handle[0],
  120681. + &m, sizeof m,
  120682. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120683. +
  120684. + if (success != 0) {
  120685. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120686. + __func__, success);
  120687. +
  120688. + ret = -1;
  120689. + goto unlock;
  120690. + }
  120691. +
  120692. + /* We are expecting a reply from the videocore */
  120693. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  120694. + if (ret) {
  120695. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  120696. + __func__, success);
  120697. + goto unlock;
  120698. + }
  120699. +
  120700. + if (instance->result != 0) {
  120701. + LOG_ERR("%s: result=%d", __func__, instance->result);
  120702. +
  120703. + ret = -1;
  120704. + goto unlock;
  120705. + }
  120706. +
  120707. + ret = 0;
  120708. +
  120709. +unlock:
  120710. + vchi_service_release(instance->vchi_handle[0]);
  120711. + mutex_unlock(&instance->vchi_mutex);
  120712. +
  120713. + LOG_DBG(" .. OUT\n");
  120714. + return ret;
  120715. +}
  120716. +
  120717. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  120718. +{
  120719. + LOG_DBG(" .. IN\n");
  120720. +
  120721. + LOG_DBG(" .. OUT\n");
  120722. +
  120723. + return 0;
  120724. +}
  120725. +
  120726. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  120727. +{
  120728. + VC_AUDIO_MSG_T m;
  120729. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120730. + int32_t success;
  120731. + int ret;
  120732. + LOG_DBG(" .. IN\n");
  120733. +
  120734. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120735. + {
  120736. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120737. + return -EINTR;
  120738. + }
  120739. + vchi_service_use(instance->vchi_handle[0]);
  120740. +
  120741. + m.type = VC_AUDIO_MSG_TYPE_START;
  120742. +
  120743. + /* Send the message to the videocore */
  120744. + success = vchi_msg_queue(instance->vchi_handle[0],
  120745. + &m, sizeof m,
  120746. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120747. +
  120748. + if (success != 0) {
  120749. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120750. + __func__, success);
  120751. +
  120752. + ret = -1;
  120753. + goto unlock;
  120754. + }
  120755. +
  120756. + ret = 0;
  120757. +
  120758. +unlock:
  120759. + vchi_service_release(instance->vchi_handle[0]);
  120760. + mutex_unlock(&instance->vchi_mutex);
  120761. + LOG_DBG(" .. OUT\n");
  120762. + return ret;
  120763. +}
  120764. +
  120765. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  120766. +{
  120767. + VC_AUDIO_MSG_T m;
  120768. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120769. + int32_t success;
  120770. + int ret;
  120771. + LOG_DBG(" .. IN\n");
  120772. +
  120773. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120774. + {
  120775. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120776. + return -EINTR;
  120777. + }
  120778. + vchi_service_use(instance->vchi_handle[0]);
  120779. +
  120780. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  120781. + m.u.stop.draining = alsa_stream->draining;
  120782. +
  120783. + /* Send the message to the videocore */
  120784. + success = vchi_msg_queue(instance->vchi_handle[0],
  120785. + &m, sizeof m,
  120786. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120787. +
  120788. + if (success != 0) {
  120789. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120790. + __func__, success);
  120791. +
  120792. + ret = -1;
  120793. + goto unlock;
  120794. + }
  120795. +
  120796. + ret = 0;
  120797. +
  120798. +unlock:
  120799. + vchi_service_release(instance->vchi_handle[0]);
  120800. + mutex_unlock(&instance->vchi_mutex);
  120801. + LOG_DBG(" .. OUT\n");
  120802. + return ret;
  120803. +}
  120804. +
  120805. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  120806. +{
  120807. + VC_AUDIO_MSG_T m;
  120808. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120809. + int32_t success;
  120810. + int ret;
  120811. + LOG_DBG(" .. IN\n");
  120812. +
  120813. + my_workqueue_quit(alsa_stream);
  120814. +
  120815. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120816. + {
  120817. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120818. + return -EINTR;
  120819. + }
  120820. + vchi_service_use(instance->vchi_handle[0]);
  120821. +
  120822. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  120823. +
  120824. + /* Create the message available completion */
  120825. + init_completion(&instance->msg_avail_comp);
  120826. +
  120827. + /* Send the message to the videocore */
  120828. + success = vchi_msg_queue(instance->vchi_handle[0],
  120829. + &m, sizeof m,
  120830. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120831. +
  120832. + if (success != 0) {
  120833. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120834. + __func__, success);
  120835. + ret = -1;
  120836. + goto unlock;
  120837. + }
  120838. +
  120839. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  120840. + if (ret) {
  120841. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  120842. + __func__, success);
  120843. + goto unlock;
  120844. + }
  120845. + if (instance->result != 0) {
  120846. + LOG_ERR("%s: failed result (status=%d)\n",
  120847. + __func__, instance->result);
  120848. +
  120849. + ret = -1;
  120850. + goto unlock;
  120851. + }
  120852. +
  120853. + ret = 0;
  120854. +
  120855. +unlock:
  120856. + vchi_service_release(instance->vchi_handle[0]);
  120857. + mutex_unlock(&instance->vchi_mutex);
  120858. +
  120859. + /* Stop the audio service */
  120860. + if (instance) {
  120861. + vc_vchi_audio_deinit(instance);
  120862. + alsa_stream->instance = NULL;
  120863. + }
  120864. + LOG_DBG(" .. OUT\n");
  120865. + return ret;
  120866. +}
  120867. +
  120868. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  120869. + uint32_t count, void *src)
  120870. +{
  120871. + VC_AUDIO_MSG_T m;
  120872. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  120873. + int32_t success;
  120874. + int ret;
  120875. +
  120876. + LOG_DBG(" .. IN\n");
  120877. +
  120878. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  120879. +
  120880. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  120881. + {
  120882. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  120883. + return -EINTR;
  120884. + }
  120885. + vchi_service_use(instance->vchi_handle[0]);
  120886. +
  120887. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  120888. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  120889. + }
  120890. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  120891. + m.u.write.count = count;
  120892. + // old version uses bulk, new version uses control
  120893. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  120894. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  120895. + m.u.write.cookie = alsa_stream;
  120896. + m.u.write.silence = src == NULL;
  120897. +
  120898. + /* Send the message to the videocore */
  120899. + success = vchi_msg_queue(instance->vchi_handle[0],
  120900. + &m, sizeof m,
  120901. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120902. +
  120903. + if (success != 0) {
  120904. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  120905. + __func__, success);
  120906. +
  120907. + ret = -1;
  120908. + goto unlock;
  120909. + }
  120910. + if (!m.u.write.silence) {
  120911. + if (m.u.write.max_packet == 0) {
  120912. + /* Send the message to the videocore */
  120913. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  120914. + src, count,
  120915. + 0 *
  120916. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  120917. + +
  120918. + 1 *
  120919. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  120920. + NULL);
  120921. + } else {
  120922. + while (count > 0) {
  120923. + int bytes = min((int)m.u.write.max_packet, (int)count);
  120924. + success = vchi_msg_queue(instance->vchi_handle[0],
  120925. + src, bytes,
  120926. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  120927. + src = (char *)src + bytes;
  120928. + count -= bytes;
  120929. + }
  120930. + }
  120931. + if (success != 0) {
  120932. + LOG_ERR
  120933. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
  120934. + __func__, success);
  120935. +
  120936. + ret = -1;
  120937. + goto unlock;
  120938. + }
  120939. + }
  120940. + ret = 0;
  120941. +
  120942. +unlock:
  120943. + vchi_service_release(instance->vchi_handle[0]);
  120944. + mutex_unlock(&instance->vchi_mutex);
  120945. + LOG_DBG(" .. OUT\n");
  120946. + return ret;
  120947. +}
  120948. +
  120949. +/**
  120950. + * Returns all buffers from arm->vc
  120951. + */
  120952. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  120953. +{
  120954. + LOG_DBG(" .. IN\n");
  120955. + LOG_DBG(" .. OUT\n");
  120956. + return;
  120957. +}
  120958. +
  120959. +/**
  120960. + * Forces VC to flush(drop) its filled playback buffers and
  120961. + * return them the us. (VC->ARM)
  120962. + */
  120963. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  120964. +{
  120965. + LOG_DBG(" .. IN\n");
  120966. + LOG_DBG(" .. OUT\n");
  120967. +}
  120968. +
  120969. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  120970. +{
  120971. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  120972. + atomic_sub(count, &alsa_stream->retrieved);
  120973. + return count;
  120974. +}
  120975. +
  120976. +module_param(force_bulk, bool, 0444);
  120977. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  120978. diff -Nur linux-3.12.38/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  120979. --- linux-3.12.38/sound/arm/Kconfig 2015-02-16 16:15:42.000000000 +0100
  120980. +++ linux-rpi/sound/arm/Kconfig 2015-03-10 17:26:51.874216684 +0100
  120981. @@ -39,5 +39,12 @@
  120982. Say Y or M if you want to support any AC97 codec attached to
  120983. the PXA2xx AC97 interface.
  120984. +config SND_BCM2835
  120985. + tristate "BCM2835 ALSA driver"
  120986. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  120987. + select SND_PCM
  120988. + help
  120989. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  120990. +
  120991. endif # SND_ARM
  120992. diff -Nur linux-3.12.38/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  120993. --- linux-3.12.38/sound/arm/Makefile 2015-02-16 16:15:42.000000000 +0100
  120994. +++ linux-rpi/sound/arm/Makefile 2015-03-09 10:39:38.302893687 +0100
  120995. @@ -14,3 +14,8 @@
  120996. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  120997. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  120998. +
  120999. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  121000. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  121001. +
  121002. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  121003. diff -Nur linux-3.12.38/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  121004. --- linux-3.12.38/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  121005. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2015-03-09 10:39:38.302893687 +0100
  121006. @@ -0,0 +1,116 @@
  121007. +/*****************************************************************************
  121008. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  121009. +*
  121010. +* Unless you and Broadcom execute a separate written software license
  121011. +* agreement governing use of this software, this software is licensed to you
  121012. +* under the terms of the GNU General Public License version 2, available at
  121013. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  121014. +*
  121015. +* Notwithstanding the above, under no circumstances may you combine this
  121016. +* software in any way with any other Broadcom software provided under a
  121017. +* license other than the GPL, without Broadcom's express prior written
  121018. +* consent.
  121019. +*****************************************************************************/
  121020. +
  121021. +#ifndef _VC_AUDIO_DEFS_H_
  121022. +#define _VC_AUDIO_DEFS_H_
  121023. +
  121024. +#define VC_AUDIOSERV_MIN_VER 1
  121025. +#define VC_AUDIOSERV_VER 2
  121026. +
  121027. +// FourCC code used for VCHI connection
  121028. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  121029. +
  121030. +// Maximum message length
  121031. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  121032. +
  121033. +// List of screens that are currently supported
  121034. +// All message types supported for HOST->VC direction
  121035. +typedef enum {
  121036. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  121037. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  121038. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  121039. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  121040. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  121041. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  121042. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  121043. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  121044. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  121045. + VC_AUDIO_MSG_TYPE_MAX
  121046. +} VC_AUDIO_MSG_TYPE;
  121047. +
  121048. +// configure the audio
  121049. +typedef struct {
  121050. + uint32_t channels;
  121051. + uint32_t samplerate;
  121052. + uint32_t bps;
  121053. +
  121054. +} VC_AUDIO_CONFIG_T;
  121055. +
  121056. +typedef struct {
  121057. + uint32_t volume;
  121058. + uint32_t dest;
  121059. +
  121060. +} VC_AUDIO_CONTROL_T;
  121061. +
  121062. +// audio
  121063. +typedef struct {
  121064. + uint32_t dummy;
  121065. +
  121066. +} VC_AUDIO_OPEN_T;
  121067. +
  121068. +// audio
  121069. +typedef struct {
  121070. + uint32_t dummy;
  121071. +
  121072. +} VC_AUDIO_CLOSE_T;
  121073. +// audio
  121074. +typedef struct {
  121075. + uint32_t dummy;
  121076. +
  121077. +} VC_AUDIO_START_T;
  121078. +// audio
  121079. +typedef struct {
  121080. + uint32_t draining;
  121081. +
  121082. +} VC_AUDIO_STOP_T;
  121083. +
  121084. +// configure the write audio samples
  121085. +typedef struct {
  121086. + uint32_t count; // in bytes
  121087. + void *callback;
  121088. + void *cookie;
  121089. + uint16_t silence;
  121090. + uint16_t max_packet;
  121091. +} VC_AUDIO_WRITE_T;
  121092. +
  121093. +// Generic result for a request (VC->HOST)
  121094. +typedef struct {
  121095. + int32_t success; // Success value
  121096. +
  121097. +} VC_AUDIO_RESULT_T;
  121098. +
  121099. +// Generic result for a request (VC->HOST)
  121100. +typedef struct {
  121101. + int32_t count; // Success value
  121102. + void *callback;
  121103. + void *cookie;
  121104. +} VC_AUDIO_COMPLETE_T;
  121105. +
  121106. +// Message header for all messages in HOST->VC direction
  121107. +typedef struct {
  121108. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  121109. + union {
  121110. + VC_AUDIO_CONFIG_T config;
  121111. + VC_AUDIO_CONTROL_T control;
  121112. + VC_AUDIO_OPEN_T open;
  121113. + VC_AUDIO_CLOSE_T close;
  121114. + VC_AUDIO_START_T start;
  121115. + VC_AUDIO_STOP_T stop;
  121116. + VC_AUDIO_WRITE_T write;
  121117. + VC_AUDIO_RESULT_T result;
  121118. + VC_AUDIO_COMPLETE_T complete;
  121119. + } u;
  121120. +} VC_AUDIO_MSG_T;
  121121. +
  121122. +#endif // _VC_AUDIO_DEFS_H_
  121123. diff -Nur linux-3.12.38/sound/core/seq/seq_dummy.c linux-rpi/sound/core/seq/seq_dummy.c
  121124. --- linux-3.12.38/sound/core/seq/seq_dummy.c 2015-02-16 16:15:42.000000000 +0100
  121125. +++ linux-rpi/sound/core/seq/seq_dummy.c 2015-03-10 17:26:51.878216684 +0100
  121126. @@ -82,6 +82,36 @@
  121127. static int my_client = -1;
  121128. /*
  121129. + * unuse callback - send ALL_SOUNDS_OFF and RESET_CONTROLLERS events
  121130. + * to subscribers.
  121131. + * Note: this callback is called only after all subscribers are removed.
  121132. + */
  121133. +static int
  121134. +dummy_unuse(void *private_data, struct snd_seq_port_subscribe *info)
  121135. +{
  121136. + struct snd_seq_dummy_port *p;
  121137. + int i;
  121138. + struct snd_seq_event ev;
  121139. +
  121140. + p = private_data;
  121141. + memset(&ev, 0, sizeof(ev));
  121142. + if (p->duplex)
  121143. + ev.source.port = p->connect;
  121144. + else
  121145. + ev.source.port = p->port;
  121146. + ev.dest.client = SNDRV_SEQ_ADDRESS_SUBSCRIBERS;
  121147. + ev.type = SNDRV_SEQ_EVENT_CONTROLLER;
  121148. + for (i = 0; i < 16; i++) {
  121149. + ev.data.control.channel = i;
  121150. + ev.data.control.param = MIDI_CTL_ALL_SOUNDS_OFF;
  121151. + snd_seq_kernel_client_dispatch(p->client, &ev, 0, 0);
  121152. + ev.data.control.param = MIDI_CTL_RESET_CONTROLLERS;
  121153. + snd_seq_kernel_client_dispatch(p->client, &ev, 0, 0);
  121154. + }
  121155. + return 0;
  121156. +}
  121157. +
  121158. +/*
  121159. * event input callback - just redirect events to subscribers
  121160. */
  121161. static int
  121162. @@ -145,6 +175,7 @@
  121163. | SNDRV_SEQ_PORT_TYPE_PORT;
  121164. memset(&pcb, 0, sizeof(pcb));
  121165. pcb.owner = THIS_MODULE;
  121166. + pcb.unuse = dummy_unuse;
  121167. pcb.event_input = dummy_input;
  121168. pcb.private_free = dummy_free;
  121169. pcb.private_data = rec;
  121170. diff -Nur linux-3.12.38/sound/i2c/other/ak4113.c linux-rpi/sound/i2c/other/ak4113.c
  121171. --- linux-3.12.38/sound/i2c/other/ak4113.c 2015-02-16 16:15:42.000000000 +0100
  121172. +++ linux-rpi/sound/i2c/other/ak4113.c 2015-03-10 17:26:51.882216684 +0100
  121173. @@ -56,7 +56,8 @@
  121174. static void snd_ak4113_free(struct ak4113 *chip)
  121175. {
  121176. - atomic_inc(&chip->wq_processing); /* don't schedule new work */
  121177. + chip->init = 1; /* don't schedule new work */
  121178. + mb();
  121179. cancel_delayed_work_sync(&chip->work);
  121180. kfree(chip);
  121181. }
  121182. @@ -88,7 +89,6 @@
  121183. chip->write = write;
  121184. chip->private_data = private_data;
  121185. INIT_DELAYED_WORK(&chip->work, ak4113_stats);
  121186. - atomic_set(&chip->wq_processing, 0);
  121187. for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
  121188. chip->regmap[reg] = pgm[reg];
  121189. @@ -139,11 +139,13 @@
  121190. void snd_ak4113_reinit(struct ak4113 *chip)
  121191. {
  121192. - if (atomic_inc_return(&chip->wq_processing) == 1)
  121193. - cancel_delayed_work_sync(&chip->work);
  121194. + chip->init = 1;
  121195. + mb();
  121196. + flush_delayed_work(&chip->work);
  121197. ak4113_init_regs(chip);
  121198. /* bring up statistics / event queing */
  121199. - if (atomic_dec_and_test(&chip->wq_processing))
  121200. + chip->init = 0;
  121201. + if (chip->kctls[0])
  121202. schedule_delayed_work(&chip->work, HZ / 10);
  121203. }
  121204. EXPORT_SYMBOL_GPL(snd_ak4113_reinit);
  121205. @@ -630,9 +632,8 @@
  121206. {
  121207. struct ak4113 *chip = container_of(work, struct ak4113, work.work);
  121208. - if (atomic_inc_return(&chip->wq_processing) == 1)
  121209. + if (!chip->init)
  121210. snd_ak4113_check_rate_and_errors(chip, chip->check_flags);
  121211. - if (atomic_dec_and_test(&chip->wq_processing))
  121212. - schedule_delayed_work(&chip->work, HZ / 10);
  121213. + schedule_delayed_work(&chip->work, HZ / 10);
  121214. }
  121215. diff -Nur linux-3.12.38/sound/i2c/other/ak4114.c linux-rpi/sound/i2c/other/ak4114.c
  121216. --- linux-3.12.38/sound/i2c/other/ak4114.c 2015-02-16 16:15:42.000000000 +0100
  121217. +++ linux-rpi/sound/i2c/other/ak4114.c 2015-03-10 17:26:51.882216684 +0100
  121218. @@ -66,7 +66,8 @@
  121219. static void snd_ak4114_free(struct ak4114 *chip)
  121220. {
  121221. - atomic_inc(&chip->wq_processing); /* don't schedule new work */
  121222. + chip->init = 1; /* don't schedule new work */
  121223. + mb();
  121224. cancel_delayed_work_sync(&chip->work);
  121225. kfree(chip);
  121226. }
  121227. @@ -99,7 +100,6 @@
  121228. chip->write = write;
  121229. chip->private_data = private_data;
  121230. INIT_DELAYED_WORK(&chip->work, ak4114_stats);
  121231. - atomic_set(&chip->wq_processing, 0);
  121232. for (reg = 0; reg < 7; reg++)
  121233. chip->regmap[reg] = pgm[reg];
  121234. @@ -152,11 +152,13 @@
  121235. void snd_ak4114_reinit(struct ak4114 *chip)
  121236. {
  121237. - if (atomic_inc_return(&chip->wq_processing) == 1)
  121238. - cancel_delayed_work_sync(&chip->work);
  121239. + chip->init = 1;
  121240. + mb();
  121241. + flush_delayed_work(&chip->work);
  121242. ak4114_init_regs(chip);
  121243. /* bring up statistics / event queing */
  121244. - if (atomic_dec_and_test(&chip->wq_processing))
  121245. + chip->init = 0;
  121246. + if (chip->kctls[0])
  121247. schedule_delayed_work(&chip->work, HZ / 10);
  121248. }
  121249. @@ -610,10 +612,10 @@
  121250. {
  121251. struct ak4114 *chip = container_of(work, struct ak4114, work.work);
  121252. - if (atomic_inc_return(&chip->wq_processing) == 1)
  121253. + if (!chip->init)
  121254. snd_ak4114_check_rate_and_errors(chip, chip->check_flags);
  121255. - if (atomic_dec_and_test(&chip->wq_processing))
  121256. - schedule_delayed_work(&chip->work, HZ / 10);
  121257. +
  121258. + schedule_delayed_work(&chip->work, HZ / 10);
  121259. }
  121260. EXPORT_SYMBOL(snd_ak4114_create);
  121261. diff -Nur linux-3.12.38/sound/pci/hda/hda_codec.c linux-rpi/sound/pci/hda/hda_codec.c
  121262. --- linux-3.12.38/sound/pci/hda/hda_codec.c 2015-02-16 16:15:42.000000000 +0100
  121263. +++ linux-rpi/sound/pci/hda/hda_codec.c 2015-03-10 17:26:51.906216684 +0100
  121264. @@ -329,10 +329,8 @@
  121265. unsigned int parm;
  121266. parm = snd_hda_param_read(codec, nid, AC_PAR_NODE_COUNT);
  121267. - if (parm == -1) {
  121268. - *start_id = 0;
  121269. + if (parm == -1)
  121270. return 0;
  121271. - }
  121272. *start_id = (parm >> 16) & 0x7fff;
  121273. return (int)(parm & 0x7fff);
  121274. }
  121275. diff -Nur linux-3.12.38/sound/pci/hda/patch_sigmatel.c linux-rpi/sound/pci/hda/patch_sigmatel.c
  121276. --- linux-3.12.38/sound/pci/hda/patch_sigmatel.c 2015-02-16 16:15:42.000000000 +0100
  121277. +++ linux-rpi/sound/pci/hda/patch_sigmatel.c 2015-03-10 17:26:51.914216684 +0100
  121278. @@ -582,9 +582,9 @@
  121279. spec->gpio_mask;
  121280. }
  121281. if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
  121282. - spec->gpio_dir &= spec->gpio_mask;
  121283. + spec->gpio_mask &= spec->gpio_mask;
  121284. if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
  121285. - spec->gpio_data &= spec->gpio_mask;
  121286. + spec->gpio_dir &= spec->gpio_mask;
  121287. if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
  121288. spec->eapd_mask &= spec->gpio_mask;
  121289. if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
  121290. diff -Nur linux-3.12.38/sound/soc/atmel/atmel_ssc_dai.c linux-rpi/sound/soc/atmel/atmel_ssc_dai.c
  121291. --- linux-3.12.38/sound/soc/atmel/atmel_ssc_dai.c 2015-02-16 16:15:42.000000000 +0100
  121292. +++ linux-rpi/sound/soc/atmel/atmel_ssc_dai.c 2015-03-10 17:26:51.926216684 +0100
  121293. @@ -344,6 +344,7 @@
  121294. struct atmel_pcm_dma_params *dma_params;
  121295. int dir, channels, bits;
  121296. u32 tfmr, rfmr, tcmr, rcmr;
  121297. + int start_event;
  121298. int ret;
  121299. /*
  121300. @@ -450,10 +451,19 @@
  121301. * The SSC transmit clock is obtained from the BCLK signal on
  121302. * on the TK line, and the SSC receive clock is
  121303. * generated from the transmit clock.
  121304. + *
  121305. + * For single channel data, one sample is transferred
  121306. + * on the falling edge of the LRC clock.
  121307. + * For two channel data, one sample is
  121308. + * transferred on both edges of the LRC clock.
  121309. */
  121310. + start_event = ((channels == 1)
  121311. + ? SSC_START_FALLING_RF
  121312. + : SSC_START_EDGE_RF);
  121313. +
  121314. rcmr = SSC_BF(RCMR_PERIOD, 0)
  121315. | SSC_BF(RCMR_STTDLY, START_DELAY)
  121316. - | SSC_BF(RCMR_START, SSC_START_FALLING_RF)
  121317. + | SSC_BF(RCMR_START, start_event)
  121318. | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
  121319. | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
  121320. | SSC_BF(RCMR_CKS, SSC_CKS_CLOCK);
  121321. @@ -461,14 +471,14 @@
  121322. rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
  121323. | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE)
  121324. | SSC_BF(RFMR_FSLEN, 0)
  121325. - | SSC_BF(RFMR_DATNB, (channels - 1))
  121326. + | SSC_BF(RFMR_DATNB, 0)
  121327. | SSC_BIT(RFMR_MSBF)
  121328. | SSC_BF(RFMR_LOOP, 0)
  121329. | SSC_BF(RFMR_DATLEN, (bits - 1));
  121330. tcmr = SSC_BF(TCMR_PERIOD, 0)
  121331. | SSC_BF(TCMR_STTDLY, START_DELAY)
  121332. - | SSC_BF(TCMR_START, SSC_START_FALLING_RF)
  121333. + | SSC_BF(TCMR_START, start_event)
  121334. | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
  121335. | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
  121336. | SSC_BF(TCMR_CKS, SSC_CKS_PIN);
  121337. @@ -477,7 +487,7 @@
  121338. | SSC_BF(TFMR_FSDEN, 0)
  121339. | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE)
  121340. | SSC_BF(TFMR_FSLEN, 0)
  121341. - | SSC_BF(TFMR_DATNB, (channels - 1))
  121342. + | SSC_BF(TFMR_DATNB, 0)
  121343. | SSC_BIT(TFMR_MSBF)
  121344. | SSC_BF(TFMR_DATDEF, 0)
  121345. | SSC_BF(TFMR_DATLEN, (bits - 1));
  121346. diff -Nur linux-3.12.38/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  121347. --- linux-3.12.38/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  121348. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2015-03-10 17:26:51.926216684 +0100
  121349. @@ -0,0 +1,998 @@
  121350. +/*
  121351. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  121352. + *
  121353. + * Author: Florian Meier <florian.meier@koalo.de>
  121354. + * Copyright 2013
  121355. + *
  121356. + * Based on
  121357. + * Raspberry Pi PCM I2S ALSA Driver
  121358. + * Copyright (c) by Phil Poole 2013
  121359. + *
  121360. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  121361. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  121362. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  121363. + *
  121364. + * OMAP ALSA SoC DAI driver using McBSP port
  121365. + * Copyright (C) 2008 Nokia Corporation
  121366. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  121367. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  121368. + *
  121369. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  121370. + * Author: Timur Tabi <timur@freescale.com>
  121371. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  121372. + *
  121373. + * This program is free software; you can redistribute it and/or
  121374. + * modify it under the terms of the GNU General Public License
  121375. + * version 2 as published by the Free Software Foundation.
  121376. + *
  121377. + * This program is distributed in the hope that it will be useful, but
  121378. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  121379. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  121380. + * General Public License for more details.
  121381. + */
  121382. +
  121383. +#include "bcm2708-i2s.h"
  121384. +
  121385. +#include <linux/init.h>
  121386. +#include <linux/module.h>
  121387. +#include <linux/device.h>
  121388. +#include <linux/slab.h>
  121389. +#include <linux/delay.h>
  121390. +#include <linux/io.h>
  121391. +#include <linux/clk.h>
  121392. +#include <mach/gpio.h>
  121393. +
  121394. +#include <sound/core.h>
  121395. +#include <sound/pcm.h>
  121396. +#include <sound/pcm_params.h>
  121397. +#include <sound/initval.h>
  121398. +#include <sound/soc.h>
  121399. +#include <sound/dmaengine_pcm.h>
  121400. +
  121401. +#include <asm/system_info.h>
  121402. +
  121403. +/* Clock registers */
  121404. +#define BCM2708_CLK_PCMCTL_REG 0x00
  121405. +#define BCM2708_CLK_PCMDIV_REG 0x04
  121406. +
  121407. +/* Clock register settings */
  121408. +#define BCM2708_CLK_PASSWD (0x5a000000)
  121409. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  121410. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  121411. +#define BCM2708_CLK_FLIP BIT(8)
  121412. +#define BCM2708_CLK_BUSY BIT(7)
  121413. +#define BCM2708_CLK_KILL BIT(5)
  121414. +#define BCM2708_CLK_ENAB BIT(4)
  121415. +#define BCM2708_CLK_SRC(v) (v)
  121416. +
  121417. +#define BCM2708_CLK_SHIFT (12)
  121418. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  121419. +#define BCM2708_CLK_DIVF(v) (v)
  121420. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  121421. +
  121422. +enum {
  121423. + BCM2708_CLK_MASH_0 = 0,
  121424. + BCM2708_CLK_MASH_1,
  121425. + BCM2708_CLK_MASH_2,
  121426. + BCM2708_CLK_MASH_3,
  121427. +};
  121428. +
  121429. +enum {
  121430. + BCM2708_CLK_SRC_GND = 0,
  121431. + BCM2708_CLK_SRC_OSC,
  121432. + BCM2708_CLK_SRC_DBG0,
  121433. + BCM2708_CLK_SRC_DBG1,
  121434. + BCM2708_CLK_SRC_PLLA,
  121435. + BCM2708_CLK_SRC_PLLC,
  121436. + BCM2708_CLK_SRC_PLLD,
  121437. + BCM2708_CLK_SRC_HDMI,
  121438. +};
  121439. +
  121440. +/* Most clocks are not useable (freq = 0) */
  121441. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  121442. + [BCM2708_CLK_SRC_GND] = 0,
  121443. + [BCM2708_CLK_SRC_OSC] = 19200000,
  121444. + [BCM2708_CLK_SRC_DBG0] = 0,
  121445. + [BCM2708_CLK_SRC_DBG1] = 0,
  121446. + [BCM2708_CLK_SRC_PLLA] = 0,
  121447. + [BCM2708_CLK_SRC_PLLC] = 0,
  121448. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  121449. + [BCM2708_CLK_SRC_HDMI] = 0,
  121450. +};
  121451. +
  121452. +/* I2S registers */
  121453. +#define BCM2708_I2S_CS_A_REG 0x00
  121454. +#define BCM2708_I2S_FIFO_A_REG 0x04
  121455. +#define BCM2708_I2S_MODE_A_REG 0x08
  121456. +#define BCM2708_I2S_RXC_A_REG 0x0c
  121457. +#define BCM2708_I2S_TXC_A_REG 0x10
  121458. +#define BCM2708_I2S_DREQ_A_REG 0x14
  121459. +#define BCM2708_I2S_INTEN_A_REG 0x18
  121460. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  121461. +#define BCM2708_I2S_GRAY_REG 0x20
  121462. +
  121463. +/* I2S register settings */
  121464. +#define BCM2708_I2S_STBY BIT(25)
  121465. +#define BCM2708_I2S_SYNC BIT(24)
  121466. +#define BCM2708_I2S_RXSEX BIT(23)
  121467. +#define BCM2708_I2S_RXF BIT(22)
  121468. +#define BCM2708_I2S_TXE BIT(21)
  121469. +#define BCM2708_I2S_RXD BIT(20)
  121470. +#define BCM2708_I2S_TXD BIT(19)
  121471. +#define BCM2708_I2S_RXR BIT(18)
  121472. +#define BCM2708_I2S_TXW BIT(17)
  121473. +#define BCM2708_I2S_CS_RXERR BIT(16)
  121474. +#define BCM2708_I2S_CS_TXERR BIT(15)
  121475. +#define BCM2708_I2S_RXSYNC BIT(14)
  121476. +#define BCM2708_I2S_TXSYNC BIT(13)
  121477. +#define BCM2708_I2S_DMAEN BIT(9)
  121478. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  121479. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  121480. +#define BCM2708_I2S_RXCLR BIT(4)
  121481. +#define BCM2708_I2S_TXCLR BIT(3)
  121482. +#define BCM2708_I2S_TXON BIT(2)
  121483. +#define BCM2708_I2S_RXON BIT(1)
  121484. +#define BCM2708_I2S_EN (1)
  121485. +
  121486. +#define BCM2708_I2S_CLKDIS BIT(28)
  121487. +#define BCM2708_I2S_PDMN BIT(27)
  121488. +#define BCM2708_I2S_PDME BIT(26)
  121489. +#define BCM2708_I2S_FRXP BIT(25)
  121490. +#define BCM2708_I2S_FTXP BIT(24)
  121491. +#define BCM2708_I2S_CLKM BIT(23)
  121492. +#define BCM2708_I2S_CLKI BIT(22)
  121493. +#define BCM2708_I2S_FSM BIT(21)
  121494. +#define BCM2708_I2S_FSI BIT(20)
  121495. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  121496. +#define BCM2708_I2S_FSLEN(v) (v)
  121497. +
  121498. +#define BCM2708_I2S_CHWEX BIT(15)
  121499. +#define BCM2708_I2S_CHEN BIT(14)
  121500. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  121501. +#define BCM2708_I2S_CHWID(v) (v)
  121502. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  121503. +#define BCM2708_I2S_CH2(v) (v)
  121504. +
  121505. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  121506. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  121507. +#define BCM2708_I2S_TX(v) ((v) << 8)
  121508. +#define BCM2708_I2S_RX(v) (v)
  121509. +
  121510. +#define BCM2708_I2S_INT_RXERR BIT(3)
  121511. +#define BCM2708_I2S_INT_TXERR BIT(2)
  121512. +#define BCM2708_I2S_INT_RXR BIT(1)
  121513. +#define BCM2708_I2S_INT_TXW BIT(0)
  121514. +
  121515. +/* I2S DMA interface */
  121516. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  121517. +#define BCM2708_DMA_DREQ_PCM_TX 2
  121518. +#define BCM2708_DMA_DREQ_PCM_RX 3
  121519. +
  121520. +/* I2S pin configuration */
  121521. +static int bcm2708_i2s_gpio=BCM2708_I2S_GPIO_AUTO;
  121522. +
  121523. +/* General device struct */
  121524. +struct bcm2708_i2s_dev {
  121525. + struct device *dev;
  121526. + struct snd_dmaengine_dai_dma_data dma_data[2];
  121527. + unsigned int fmt;
  121528. + unsigned int bclk_ratio;
  121529. +
  121530. + struct regmap *i2s_regmap;
  121531. + struct regmap *clk_regmap;
  121532. +};
  121533. +
  121534. +void bcm2708_i2s_set_gpio(int gpio) {
  121535. + bcm2708_i2s_gpio=gpio;
  121536. +}
  121537. +EXPORT_SYMBOL(bcm2708_i2s_set_gpio);
  121538. +
  121539. +
  121540. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  121541. +{
  121542. + /* Start the clock if in master mode */
  121543. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  121544. +
  121545. + switch (master) {
  121546. + case SND_SOC_DAIFMT_CBS_CFS:
  121547. + case SND_SOC_DAIFMT_CBS_CFM:
  121548. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121549. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121550. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  121551. + break;
  121552. + default:
  121553. + break;
  121554. + }
  121555. +}
  121556. +
  121557. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  121558. +{
  121559. + uint32_t clkreg;
  121560. + int timeout = 1000;
  121561. +
  121562. + /* Stop clock */
  121563. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121564. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121565. + BCM2708_CLK_PASSWD);
  121566. +
  121567. + /* Wait for the BUSY flag going down */
  121568. + while (--timeout) {
  121569. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  121570. + if (!(clkreg & BCM2708_CLK_BUSY))
  121571. + break;
  121572. + }
  121573. +
  121574. + if (!timeout) {
  121575. + /* KILL the clock */
  121576. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  121577. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121578. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  121579. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  121580. + }
  121581. +}
  121582. +
  121583. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  121584. + bool tx, bool rx)
  121585. +{
  121586. + int timeout = 1000;
  121587. + uint32_t syncval;
  121588. + uint32_t csreg;
  121589. + uint32_t i2s_active_state;
  121590. + uint32_t clkreg;
  121591. + uint32_t clk_active_state;
  121592. + uint32_t off;
  121593. + uint32_t clr;
  121594. +
  121595. + off = tx ? BCM2708_I2S_TXON : 0;
  121596. + off |= rx ? BCM2708_I2S_RXON : 0;
  121597. +
  121598. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  121599. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  121600. +
  121601. + /* Backup the current state */
  121602. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  121603. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  121604. +
  121605. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  121606. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  121607. +
  121608. + /* Start clock if not running */
  121609. + if (!clk_active_state) {
  121610. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  121611. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  121612. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  121613. + }
  121614. +
  121615. + /* Stop I2S module */
  121616. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  121617. +
  121618. + /*
  121619. + * Clear the FIFOs
  121620. + * Requires at least 2 PCM clock cycles to take effect
  121621. + */
  121622. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  121623. +
  121624. + /* Wait for 2 PCM clock cycles */
  121625. +
  121626. + /*
  121627. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  121628. + * FIXME: This does not seem to work for slave mode!
  121629. + */
  121630. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  121631. + syncval &= BCM2708_I2S_SYNC;
  121632. +
  121633. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  121634. + BCM2708_I2S_SYNC, ~syncval);
  121635. +
  121636. + /* Wait for the SYNC flag changing it's state */
  121637. + while (--timeout) {
  121638. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  121639. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  121640. + break;
  121641. + }
  121642. +
  121643. + if (!timeout)
  121644. + dev_err(dev->dev, "I2S SYNC error!\n");
  121645. +
  121646. + /* Stop clock if it was not running before */
  121647. + if (!clk_active_state)
  121648. + bcm2708_i2s_stop_clock(dev);
  121649. +
  121650. + /* Restore I2S state */
  121651. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  121652. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  121653. +}
  121654. +
  121655. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  121656. + unsigned int fmt)
  121657. +{
  121658. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  121659. + dev->fmt = fmt;
  121660. + return 0;
  121661. +}
  121662. +
  121663. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  121664. + unsigned int ratio)
  121665. +{
  121666. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  121667. + dev->bclk_ratio = ratio;
  121668. + return 0;
  121669. +}
  121670. +
  121671. +
  121672. +static int bcm2708_i2s_set_function(unsigned offset, int function)
  121673. +{
  121674. + #define GPIOFSEL(x) (0x00+(x)*4)
  121675. + void __iomem *gpio = __io_address(GPIO_BASE);
  121676. + unsigned alt = function <= 3 ? function + 4: function == 4 ? 3 : 2;
  121677. + unsigned gpiodir;
  121678. + unsigned gpio_bank = offset / 10;
  121679. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  121680. +
  121681. + if (offset >= BCM2708_NR_GPIOS)
  121682. + return -EINVAL;
  121683. +
  121684. + gpiodir = readl(gpio + GPIOFSEL(gpio_bank));
  121685. + gpiodir &= ~(7 << gpio_field_offset);
  121686. + gpiodir |= alt << gpio_field_offset;
  121687. + writel(gpiodir, gpio + GPIOFSEL(gpio_bank));
  121688. + return 0;
  121689. +}
  121690. +
  121691. +static void bcm2708_i2s_setup_gpio(void)
  121692. +{
  121693. + /*
  121694. + * This is the common way to handle the GPIO pins for
  121695. + * the Raspberry Pi.
  121696. + * TODO Better way would be to handle
  121697. + * this in the device tree!
  121698. + */
  121699. + int pin,pinconfig,startpin,alt;
  121700. +
  121701. + /* SPI is on different GPIOs on different boards */
  121702. + /* for Raspberry Pi B+, this is pin GPIO18-21, for original on 28-31 */
  121703. + if (bcm2708_i2s_gpio==BCM2708_I2S_GPIO_AUTO) {
  121704. + if ((system_rev & 0xffffff) >= 0x10) {
  121705. + /* Model B+ */
  121706. + pinconfig=BCM2708_I2S_GPIO_PIN18;
  121707. + } else {
  121708. + /* original */
  121709. + pinconfig=BCM2708_I2S_GPIO_PIN28;
  121710. + }
  121711. + } else {
  121712. + pinconfig=bcm2708_i2s_gpio;
  121713. + }
  121714. +
  121715. + if (pinconfig==BCM2708_I2S_GPIO_PIN18) {
  121716. + startpin=18;
  121717. + alt=BCM2708_I2S_GPIO_PIN18_ALT;
  121718. + } else if (pinconfig==BCM2708_I2S_GPIO_PIN28) {
  121719. + startpin=28;
  121720. + alt=BCM2708_I2S_GPIO_PIN28_ALT;
  121721. + } else {
  121722. + printk(KERN_INFO "Can't configure I2S GPIOs, unknown pin mode for I2S: %i\n",pinconfig);
  121723. + return;
  121724. + }
  121725. +
  121726. + /* configure I2S pins to correct ALT mode */
  121727. + for (pin = startpin; pin <= startpin+3; pin++) {
  121728. + bcm2708_i2s_set_function(pin, alt);
  121729. + }
  121730. +}
  121731. +
  121732. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  121733. + struct snd_pcm_hw_params *params,
  121734. + struct snd_soc_dai *dai)
  121735. +{
  121736. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  121737. +
  121738. + unsigned int sampling_rate = params_rate(params);
  121739. + unsigned int data_length, data_delay, bclk_ratio;
  121740. + unsigned int ch1pos, ch2pos, mode, format;
  121741. + unsigned int mash = BCM2708_CLK_MASH_1;
  121742. + unsigned int divi, divf, target_frequency;
  121743. + int clk_src = -1;
  121744. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  121745. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  121746. + || master == SND_SOC_DAIFMT_CBS_CFM);
  121747. +
  121748. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  121749. + || master == SND_SOC_DAIFMT_CBM_CFS);
  121750. + uint32_t csreg;
  121751. +
  121752. + /*
  121753. + * If a stream is already enabled,
  121754. + * the registers are already set properly.
  121755. + */
  121756. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  121757. +
  121758. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  121759. + return 0;
  121760. +
  121761. +
  121762. + bcm2708_i2s_setup_gpio();
  121763. +
  121764. + /*
  121765. + * Adjust the data length according to the format.
  121766. + * We prefill the half frame length with an integer
  121767. + * divider of 2400 as explained at the clock settings.
  121768. + * Maybe it is overwritten there, if the Integer mode
  121769. + * does not apply.
  121770. + */
  121771. + switch (params_format(params)) {
  121772. + case SNDRV_PCM_FORMAT_S16_LE:
  121773. + data_length = 16;
  121774. + bclk_ratio = 50;
  121775. + break;
  121776. + case SNDRV_PCM_FORMAT_S24_LE:
  121777. + data_length = 24;
  121778. + bclk_ratio = 50;
  121779. + break;
  121780. + case SNDRV_PCM_FORMAT_S32_LE:
  121781. + data_length = 32;
  121782. + bclk_ratio = 100;
  121783. + break;
  121784. + default:
  121785. + return -EINVAL;
  121786. + }
  121787. +
  121788. + /* If bclk_ratio already set, use that one. */
  121789. + if (dev->bclk_ratio)
  121790. + bclk_ratio = dev->bclk_ratio;
  121791. +
  121792. + /*
  121793. + * Clock Settings
  121794. + *
  121795. + * The target frequency of the bit clock is
  121796. + * sampling rate * frame length
  121797. + *
  121798. + * Integer mode:
  121799. + * Sampling rates that are multiples of 8000 kHz
  121800. + * can be driven by the oscillator of 19.2 MHz
  121801. + * with an integer divider as long as the frame length
  121802. + * is an integer divider of 19200000/8000=2400 as set up above.
  121803. + * This is no longer possible if the sampling rate
  121804. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  121805. + *
  121806. + * MASH mode:
  121807. + * For all other sampling rates, it is not possible to
  121808. + * have an integer divider. Approximate the clock
  121809. + * with the MASH module that induces a slight frequency
  121810. + * variance. To minimize that it is best to have the fastest
  121811. + * clock here. That is PLLD with 500 MHz.
  121812. + */
  121813. + target_frequency = sampling_rate * bclk_ratio;
  121814. + clk_src = BCM2708_CLK_SRC_OSC;
  121815. + mash = BCM2708_CLK_MASH_0;
  121816. +
  121817. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  121818. + && bit_master && frame_master) {
  121819. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  121820. + divf = 0;
  121821. + } else {
  121822. + uint64_t dividend;
  121823. +
  121824. + if (!dev->bclk_ratio) {
  121825. + /*
  121826. + * Overwrite bclk_ratio, because the
  121827. + * above trick is not needed or can
  121828. + * not be used.
  121829. + */
  121830. + bclk_ratio = 2 * data_length;
  121831. + }
  121832. +
  121833. + target_frequency = sampling_rate * bclk_ratio;
  121834. +
  121835. + clk_src = BCM2708_CLK_SRC_PLLD;
  121836. + mash = BCM2708_CLK_MASH_1;
  121837. +
  121838. + dividend = bcm2708_clk_freq[clk_src];
  121839. + dividend <<= BCM2708_CLK_SHIFT;
  121840. + do_div(dividend, target_frequency);
  121841. + divi = dividend >> BCM2708_CLK_SHIFT;
  121842. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  121843. + }
  121844. +
  121845. + /* Set clock divider */
  121846. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  121847. + | BCM2708_CLK_DIVI(divi)
  121848. + | BCM2708_CLK_DIVF(divf));
  121849. +
  121850. + /* Setup clock, but don't start it yet */
  121851. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  121852. + | BCM2708_CLK_MASH(mash)
  121853. + | BCM2708_CLK_SRC(clk_src));
  121854. +
  121855. + /* Setup the frame format */
  121856. + format = BCM2708_I2S_CHEN;
  121857. +
  121858. + if (data_length >= 24)
  121859. + format |= BCM2708_I2S_CHWEX;
  121860. +
  121861. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  121862. +
  121863. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  121864. + case SND_SOC_DAIFMT_I2S:
  121865. + data_delay = 1;
  121866. + break;
  121867. + default:
  121868. + /*
  121869. + * TODO
  121870. + * Others are possible but are not implemented at the moment.
  121871. + */
  121872. + dev_err(dev->dev, "%s:bad format\n", __func__);
  121873. + return -EINVAL;
  121874. + }
  121875. +
  121876. + ch1pos = data_delay;
  121877. + ch2pos = bclk_ratio / 2 + data_delay;
  121878. +
  121879. + switch (params_channels(params)) {
  121880. + case 2:
  121881. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  121882. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  121883. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  121884. + break;
  121885. + default:
  121886. + return -EINVAL;
  121887. + }
  121888. +
  121889. + /*
  121890. + * Set format for both streams.
  121891. + * We cannot set another frame length
  121892. + * (and therefore word length) anyway,
  121893. + * so the format will be the same.
  121894. + */
  121895. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  121896. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  121897. +
  121898. + /* Setup the I2S mode */
  121899. + mode = 0;
  121900. +
  121901. + if (data_length <= 16) {
  121902. + /*
  121903. + * Use frame packed mode (2 channels per 32 bit word)
  121904. + * We cannot set another frame length in the second stream
  121905. + * (and therefore word length) anyway,
  121906. + * so the format will be the same.
  121907. + */
  121908. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  121909. + }
  121910. +
  121911. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  121912. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  121913. +
  121914. + /* Master or slave? */
  121915. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  121916. + case SND_SOC_DAIFMT_CBS_CFS:
  121917. + /* CPU is master */
  121918. + break;
  121919. + case SND_SOC_DAIFMT_CBM_CFS:
  121920. + /*
  121921. + * CODEC is bit clock master
  121922. + * CPU is frame master
  121923. + */
  121924. + mode |= BCM2708_I2S_CLKM;
  121925. + break;
  121926. + case SND_SOC_DAIFMT_CBS_CFM:
  121927. + /*
  121928. + * CODEC is frame master
  121929. + * CPU is bit clock master
  121930. + */
  121931. + mode |= BCM2708_I2S_FSM;
  121932. + break;
  121933. + case SND_SOC_DAIFMT_CBM_CFM:
  121934. + /* CODEC is master */
  121935. + mode |= BCM2708_I2S_CLKM;
  121936. + mode |= BCM2708_I2S_FSM;
  121937. + break;
  121938. + default:
  121939. + dev_err(dev->dev, "%s:bad master\n", __func__);
  121940. + return -EINVAL;
  121941. + }
  121942. +
  121943. + /*
  121944. + * Invert clocks?
  121945. + *
  121946. + * The BCM approach seems to be inverted to the classical I2S approach.
  121947. + */
  121948. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  121949. + case SND_SOC_DAIFMT_NB_NF:
  121950. + /* None. Therefore, both for BCM */
  121951. + mode |= BCM2708_I2S_CLKI;
  121952. + mode |= BCM2708_I2S_FSI;
  121953. + break;
  121954. + case SND_SOC_DAIFMT_IB_IF:
  121955. + /* Both. Therefore, none for BCM */
  121956. + break;
  121957. + case SND_SOC_DAIFMT_NB_IF:
  121958. + /*
  121959. + * Invert only frame sync. Therefore,
  121960. + * invert only bit clock for BCM
  121961. + */
  121962. + mode |= BCM2708_I2S_CLKI;
  121963. + break;
  121964. + case SND_SOC_DAIFMT_IB_NF:
  121965. + /*
  121966. + * Invert only bit clock. Therefore,
  121967. + * invert only frame sync for BCM
  121968. + */
  121969. + mode |= BCM2708_I2S_FSI;
  121970. + break;
  121971. + default:
  121972. + return -EINVAL;
  121973. + }
  121974. +
  121975. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  121976. +
  121977. + /* Setup the DMA parameters */
  121978. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  121979. + BCM2708_I2S_RXTHR(1)
  121980. + | BCM2708_I2S_TXTHR(1)
  121981. + | BCM2708_I2S_DMAEN, 0xffffffff);
  121982. +
  121983. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  121984. + BCM2708_I2S_TX_PANIC(0x10)
  121985. + | BCM2708_I2S_RX_PANIC(0x30)
  121986. + | BCM2708_I2S_TX(0x30)
  121987. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  121988. +
  121989. + /* Clear FIFOs */
  121990. + bcm2708_i2s_clear_fifos(dev, true, true);
  121991. +
  121992. + return 0;
  121993. +}
  121994. +
  121995. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  121996. + struct snd_soc_dai *dai)
  121997. +{
  121998. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  121999. + uint32_t cs_reg;
  122000. +
  122001. + bcm2708_i2s_start_clock(dev);
  122002. +
  122003. + /*
  122004. + * Clear both FIFOs if the one that should be started
  122005. + * is not empty at the moment. This should only happen
  122006. + * after overrun. Otherwise, hw_params would have cleared
  122007. + * the FIFO.
  122008. + */
  122009. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  122010. +
  122011. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  122012. + && !(cs_reg & BCM2708_I2S_TXE))
  122013. + bcm2708_i2s_clear_fifos(dev, true, false);
  122014. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  122015. + && (cs_reg & BCM2708_I2S_RXD))
  122016. + bcm2708_i2s_clear_fifos(dev, false, true);
  122017. +
  122018. + return 0;
  122019. +}
  122020. +
  122021. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  122022. + struct snd_pcm_substream *substream,
  122023. + struct snd_soc_dai *dai)
  122024. +{
  122025. + uint32_t mask;
  122026. +
  122027. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  122028. + mask = BCM2708_I2S_RXON;
  122029. + else
  122030. + mask = BCM2708_I2S_TXON;
  122031. +
  122032. + regmap_update_bits(dev->i2s_regmap,
  122033. + BCM2708_I2S_CS_A_REG, mask, 0);
  122034. +
  122035. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  122036. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  122037. + bcm2708_i2s_stop_clock(dev);
  122038. +}
  122039. +
  122040. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  122041. + struct snd_soc_dai *dai)
  122042. +{
  122043. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122044. + uint32_t mask;
  122045. +
  122046. + switch (cmd) {
  122047. + case SNDRV_PCM_TRIGGER_START:
  122048. + case SNDRV_PCM_TRIGGER_RESUME:
  122049. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  122050. + bcm2708_i2s_start_clock(dev);
  122051. +
  122052. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  122053. + mask = BCM2708_I2S_RXON;
  122054. + else
  122055. + mask = BCM2708_I2S_TXON;
  122056. +
  122057. + regmap_update_bits(dev->i2s_regmap,
  122058. + BCM2708_I2S_CS_A_REG, mask, mask);
  122059. + break;
  122060. +
  122061. + case SNDRV_PCM_TRIGGER_STOP:
  122062. + case SNDRV_PCM_TRIGGER_SUSPEND:
  122063. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  122064. + bcm2708_i2s_stop(dev, substream, dai);
  122065. + break;
  122066. + default:
  122067. + return -EINVAL;
  122068. + }
  122069. +
  122070. + return 0;
  122071. +}
  122072. +
  122073. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  122074. + struct snd_soc_dai *dai)
  122075. +{
  122076. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122077. +
  122078. + if (dai->active)
  122079. + return 0;
  122080. +
  122081. + /* Should this still be running stop it */
  122082. + bcm2708_i2s_stop_clock(dev);
  122083. +
  122084. + /* Enable PCM block */
  122085. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122086. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  122087. +
  122088. + /*
  122089. + * Disable STBY.
  122090. + * Requires at least 4 PCM clock cycles to take effect.
  122091. + */
  122092. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122093. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  122094. +
  122095. + return 0;
  122096. +}
  122097. +
  122098. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  122099. + struct snd_soc_dai *dai)
  122100. +{
  122101. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122102. +
  122103. + bcm2708_i2s_stop(dev, substream, dai);
  122104. +
  122105. + /* If both streams are stopped, disable module and clock */
  122106. + if (dai->active)
  122107. + return;
  122108. +
  122109. + /* Disable the module */
  122110. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  122111. + BCM2708_I2S_EN, 0);
  122112. +
  122113. + /*
  122114. + * Stopping clock is necessary, because stop does
  122115. + * not stop the clock when SND_SOC_DAIFMT_CONT
  122116. + */
  122117. + bcm2708_i2s_stop_clock(dev);
  122118. +}
  122119. +
  122120. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  122121. + .startup = bcm2708_i2s_startup,
  122122. + .shutdown = bcm2708_i2s_shutdown,
  122123. + .prepare = bcm2708_i2s_prepare,
  122124. + .trigger = bcm2708_i2s_trigger,
  122125. + .hw_params = bcm2708_i2s_hw_params,
  122126. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  122127. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  122128. +};
  122129. +
  122130. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  122131. +{
  122132. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  122133. +
  122134. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  122135. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  122136. +
  122137. + return 0;
  122138. +}
  122139. +
  122140. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  122141. + .name = "bcm2708-i2s",
  122142. + .probe = bcm2708_i2s_dai_probe,
  122143. + .playback = {
  122144. + .channels_min = 2,
  122145. + .channels_max = 2,
  122146. + .rates = SNDRV_PCM_RATE_8000_192000,
  122147. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  122148. + | SNDRV_PCM_FMTBIT_S24_LE
  122149. + | SNDRV_PCM_FMTBIT_S32_LE
  122150. + },
  122151. + .capture = {
  122152. + .channels_min = 2,
  122153. + .channels_max = 2,
  122154. + .rates = SNDRV_PCM_RATE_8000_192000,
  122155. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  122156. + | SNDRV_PCM_FMTBIT_S24_LE
  122157. + | SNDRV_PCM_FMTBIT_S32_LE
  122158. + },
  122159. + .ops = &bcm2708_i2s_dai_ops,
  122160. + .symmetric_rates = 1
  122161. +};
  122162. +
  122163. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  122164. +{
  122165. + switch (reg) {
  122166. + case BCM2708_I2S_CS_A_REG:
  122167. + case BCM2708_I2S_FIFO_A_REG:
  122168. + case BCM2708_I2S_INTSTC_A_REG:
  122169. + case BCM2708_I2S_GRAY_REG:
  122170. + return true;
  122171. + default:
  122172. + return false;
  122173. + };
  122174. +}
  122175. +
  122176. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  122177. +{
  122178. + switch (reg) {
  122179. + case BCM2708_I2S_FIFO_A_REG:
  122180. + return true;
  122181. + default:
  122182. + return false;
  122183. + };
  122184. +}
  122185. +
  122186. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  122187. +{
  122188. + switch (reg) {
  122189. + case BCM2708_CLK_PCMCTL_REG:
  122190. + return true;
  122191. + default:
  122192. + return false;
  122193. + };
  122194. +}
  122195. +
  122196. +static const struct regmap_config bcm2708_regmap_config[] = {
  122197. + {
  122198. + .reg_bits = 32,
  122199. + .reg_stride = 4,
  122200. + .val_bits = 32,
  122201. + .max_register = BCM2708_I2S_GRAY_REG,
  122202. + .precious_reg = bcm2708_i2s_precious_reg,
  122203. + .volatile_reg = bcm2708_i2s_volatile_reg,
  122204. + .cache_type = REGCACHE_RBTREE,
  122205. + .name = "i2s",
  122206. + },
  122207. + {
  122208. + .reg_bits = 32,
  122209. + .reg_stride = 4,
  122210. + .val_bits = 32,
  122211. + .max_register = BCM2708_CLK_PCMDIV_REG,
  122212. + .volatile_reg = bcm2708_clk_volatile_reg,
  122213. + .cache_type = REGCACHE_RBTREE,
  122214. + .name = "clk",
  122215. + },
  122216. +};
  122217. +
  122218. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  122219. + .name = "bcm2708-i2s-comp",
  122220. +};
  122221. +
  122222. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  122223. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  122224. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  122225. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  122226. + SNDRV_PCM_FMTBIT_S24_LE |
  122227. + SNDRV_PCM_FMTBIT_S32_LE,
  122228. + .period_bytes_min = 32,
  122229. + .period_bytes_max = 64 * PAGE_SIZE,
  122230. + .periods_min = 2,
  122231. + .periods_max = 255,
  122232. + .buffer_bytes_max = 128 * PAGE_SIZE,
  122233. +};
  122234. +
  122235. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  122236. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  122237. + .pcm_hardware = &bcm2708_pcm_hardware,
  122238. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  122239. +};
  122240. +
  122241. +
  122242. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  122243. +{
  122244. + struct bcm2708_i2s_dev *dev;
  122245. + int i;
  122246. + int ret;
  122247. + struct regmap *regmap[2];
  122248. + struct resource *mem[2];
  122249. +
  122250. + /* Request both ioareas */
  122251. + for (i = 0; i <= 1; i++) {
  122252. + void __iomem *base;
  122253. +
  122254. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  122255. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  122256. + if (IS_ERR(base))
  122257. + return PTR_ERR(base);
  122258. +
  122259. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  122260. + &bcm2708_regmap_config[i]);
  122261. + if (IS_ERR(regmap[i])) {
  122262. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  122263. + return PTR_ERR(regmap[i]);
  122264. + }
  122265. + }
  122266. +
  122267. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  122268. + GFP_KERNEL);
  122269. + if (IS_ERR(dev))
  122270. + return PTR_ERR(dev);
  122271. +
  122272. + dev->i2s_regmap = regmap[0];
  122273. + dev->clk_regmap = regmap[1];
  122274. +
  122275. + /* Set the DMA address */
  122276. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  122277. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  122278. +
  122279. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  122280. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  122281. +
  122282. + /* Set the DREQ */
  122283. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  122284. + BCM2708_DMA_DREQ_PCM_TX;
  122285. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  122286. + BCM2708_DMA_DREQ_PCM_RX;
  122287. +
  122288. + /* Set the bus width */
  122289. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  122290. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  122291. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  122292. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  122293. +
  122294. + /* Set burst */
  122295. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  122296. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  122297. +
  122298. + /* BCLK ratio - use default */
  122299. + dev->bclk_ratio = 0;
  122300. +
  122301. + /* Store the pdev */
  122302. + dev->dev = &pdev->dev;
  122303. + dev_set_drvdata(&pdev->dev, dev);
  122304. +
  122305. + ret = snd_soc_register_component(&pdev->dev,
  122306. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  122307. +
  122308. + if (ret) {
  122309. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  122310. + ret = -ENOMEM;
  122311. + return ret;
  122312. + }
  122313. +
  122314. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  122315. + &bcm2708_dmaengine_pcm_config,
  122316. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  122317. + if (ret) {
  122318. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  122319. + snd_soc_unregister_component(&pdev->dev);
  122320. + return ret;
  122321. + }
  122322. +
  122323. + return 0;
  122324. +}
  122325. +
  122326. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  122327. +{
  122328. + snd_dmaengine_pcm_unregister(&pdev->dev);
  122329. + snd_soc_unregister_component(&pdev->dev);
  122330. + return 0;
  122331. +}
  122332. +
  122333. +static struct platform_driver bcm2708_i2s_driver = {
  122334. + .probe = bcm2708_i2s_probe,
  122335. + .remove = bcm2708_i2s_remove,
  122336. + .driver = {
  122337. + .name = "bcm2708-i2s",
  122338. + .owner = THIS_MODULE,
  122339. + },
  122340. +};
  122341. +
  122342. +module_platform_driver(bcm2708_i2s_driver);
  122343. +
  122344. +MODULE_ALIAS("platform:bcm2708-i2s");
  122345. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  122346. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  122347. +MODULE_LICENSE("GPL v2");
  122348. diff -Nur linux-3.12.38/sound/soc/bcm/bcm2708-i2s.h linux-rpi/sound/soc/bcm/bcm2708-i2s.h
  122349. --- linux-3.12.38/sound/soc/bcm/bcm2708-i2s.h 1970-01-01 01:00:00.000000000 +0100
  122350. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.h 2015-03-09 10:39:38.554893685 +0100
  122351. @@ -0,0 +1,35 @@
  122352. +/*
  122353. + * I2S configuration for sound cards.
  122354. + *
  122355. + * Copyright (c) 2014 Daniel Matuschek <daniel@hifiberry.com>
  122356. + *
  122357. + * This program is free software; you can redistribute it and/or modify
  122358. + * it under the terms of the GNU General Public License as published by
  122359. + * the Free Software Foundation; either version 2 of the License, or
  122360. + * (at your option) any later version.
  122361. + *
  122362. + * This program is distributed in the hope that it will be useful,
  122363. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  122364. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  122365. + * GNU General Public License for more details.
  122366. + *
  122367. + * You should have received a copy of the GNU General Public License
  122368. + * along with this program; if not, write to the Free Software
  122369. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  122370. + */
  122371. +
  122372. +#ifndef BCM2708_I2S_H
  122373. +#define BCM2708_I2S_H
  122374. +
  122375. +/* I2S pin assignment */
  122376. +#define BCM2708_I2S_GPIO_AUTO 0
  122377. +#define BCM2708_I2S_GPIO_PIN18 1
  122378. +#define BCM2708_I2S_GPIO_PIN28 2
  122379. +
  122380. +/* Alt mode to enable I2S */
  122381. +#define BCM2708_I2S_GPIO_PIN18_ALT 0
  122382. +#define BCM2708_I2S_GPIO_PIN28_ALT 2
  122383. +
  122384. +extern void bcm2708_i2s_set_gpio(int gpio);
  122385. +
  122386. +#endif
  122387. diff -Nur linux-3.12.38/sound/soc/bcm/hifiberry_amp.c linux-rpi/sound/soc/bcm/hifiberry_amp.c
  122388. --- linux-3.12.38/sound/soc/bcm/hifiberry_amp.c 1970-01-01 01:00:00.000000000 +0100
  122389. +++ linux-rpi/sound/soc/bcm/hifiberry_amp.c 2015-03-10 17:26:51.930216684 +0100
  122390. @@ -0,0 +1,106 @@
  122391. +/*
  122392. + * ASoC Driver for HifiBerry AMP
  122393. + *
  122394. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  122395. + * Copyright 2014
  122396. + *
  122397. + * This program is free software; you can redistribute it and/or
  122398. + * modify it under the terms of the GNU General Public License
  122399. + * version 2 as published by the Free Software Foundation.
  122400. + *
  122401. + * This program is distributed in the hope that it will be useful, but
  122402. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122403. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122404. + * General Public License for more details.
  122405. + */
  122406. +
  122407. +#include <linux/module.h>
  122408. +#include <linux/platform_device.h>
  122409. +
  122410. +#include <sound/core.h>
  122411. +#include <sound/pcm.h>
  122412. +#include <sound/pcm_params.h>
  122413. +#include <sound/soc.h>
  122414. +#include <sound/jack.h>
  122415. +
  122416. +static int snd_rpi_hifiberry_amp_init(struct snd_soc_pcm_runtime *rtd)
  122417. +{
  122418. + // ToDo: init of the dsp-registers.
  122419. + return 0;
  122420. +}
  122421. +
  122422. +static int snd_rpi_hifiberry_amp_hw_params( struct snd_pcm_substream *substream,
  122423. + struct snd_pcm_hw_params *params )
  122424. +{
  122425. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122426. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122427. +
  122428. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  122429. +}
  122430. +
  122431. +static struct snd_soc_ops snd_rpi_hifiberry_amp_ops = {
  122432. + .hw_params = snd_rpi_hifiberry_amp_hw_params,
  122433. +};
  122434. +
  122435. +static struct snd_soc_dai_link snd_rpi_hifiberry_amp_dai[] = {
  122436. + {
  122437. + .name = "HifiBerry AMP",
  122438. + .stream_name = "HifiBerry AMP HiFi",
  122439. + .cpu_dai_name = "bcm2708-i2s.0",
  122440. + .codec_dai_name = "tas5713-hifi",
  122441. + .platform_name = "bcm2708-i2s.0",
  122442. + .codec_name = "tas5713.1-001b",
  122443. + .dai_fmt = SND_SOC_DAIFMT_I2S |
  122444. + SND_SOC_DAIFMT_NB_NF |
  122445. + SND_SOC_DAIFMT_CBS_CFS,
  122446. + .ops = &snd_rpi_hifiberry_amp_ops,
  122447. + .init = snd_rpi_hifiberry_amp_init,
  122448. + },
  122449. +};
  122450. +
  122451. +
  122452. +static struct snd_soc_card snd_rpi_hifiberry_amp = {
  122453. + .name = "snd_rpi_hifiberry_amp",
  122454. + .dai_link = snd_rpi_hifiberry_amp_dai,
  122455. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_amp_dai),
  122456. +};
  122457. +
  122458. +
  122459. +static int snd_rpi_hifiberry_amp_probe(struct platform_device *pdev)
  122460. +{
  122461. + int ret = 0;
  122462. +
  122463. + snd_rpi_hifiberry_amp.dev = &pdev->dev;
  122464. +
  122465. + ret = snd_soc_register_card(&snd_rpi_hifiberry_amp);
  122466. +
  122467. + if (ret != 0) {
  122468. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  122469. + }
  122470. +
  122471. + return ret;
  122472. +}
  122473. +
  122474. +
  122475. +static int snd_rpi_hifiberry_amp_remove(struct platform_device *pdev)
  122476. +{
  122477. + return snd_soc_unregister_card(&snd_rpi_hifiberry_amp);
  122478. +}
  122479. +
  122480. +
  122481. +static struct platform_driver snd_rpi_hifiberry_amp_driver = {
  122482. + .driver = {
  122483. + .name = "snd-hifiberry-amp",
  122484. + .owner = THIS_MODULE,
  122485. + },
  122486. + .probe = snd_rpi_hifiberry_amp_probe,
  122487. + .remove = snd_rpi_hifiberry_amp_remove,
  122488. +};
  122489. +
  122490. +
  122491. +module_platform_driver(snd_rpi_hifiberry_amp_driver);
  122492. +
  122493. +
  122494. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  122495. +MODULE_DESCRIPTION("ASoC driver for HiFiBerry-AMP");
  122496. +MODULE_LICENSE("GPL v2");
  122497. diff -Nur linux-3.12.38/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  122498. --- linux-3.12.38/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  122499. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2015-03-10 17:26:51.930216684 +0100
  122500. @@ -0,0 +1,100 @@
  122501. +/*
  122502. + * ASoC Driver for HifiBerry DAC
  122503. + *
  122504. + * Author: Florian Meier <florian.meier@koalo.de>
  122505. + * Copyright 2013
  122506. + *
  122507. + * This program is free software; you can redistribute it and/or
  122508. + * modify it under the terms of the GNU General Public License
  122509. + * version 2 as published by the Free Software Foundation.
  122510. + *
  122511. + * This program is distributed in the hope that it will be useful, but
  122512. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122513. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122514. + * General Public License for more details.
  122515. + */
  122516. +
  122517. +#include <linux/module.h>
  122518. +#include <linux/platform_device.h>
  122519. +
  122520. +#include <sound/core.h>
  122521. +#include <sound/pcm.h>
  122522. +#include <sound/pcm_params.h>
  122523. +#include <sound/soc.h>
  122524. +#include <sound/jack.h>
  122525. +
  122526. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  122527. +{
  122528. + return 0;
  122529. +}
  122530. +
  122531. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  122532. + struct snd_pcm_hw_params *params)
  122533. +{
  122534. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122535. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122536. +
  122537. + unsigned int sample_bits =
  122538. + snd_pcm_format_physical_width(params_format(params));
  122539. +
  122540. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  122541. +}
  122542. +
  122543. +/* machine stream operations */
  122544. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  122545. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  122546. +};
  122547. +
  122548. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  122549. +{
  122550. + .name = "HifiBerry DAC",
  122551. + .stream_name = "HifiBerry DAC HiFi",
  122552. + .cpu_dai_name = "bcm2708-i2s.0",
  122553. + .codec_dai_name = "pcm5102a-hifi",
  122554. + .platform_name = "bcm2708-i2s.0",
  122555. + .codec_name = "pcm5102a-codec",
  122556. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  122557. + SND_SOC_DAIFMT_CBS_CFS,
  122558. + .ops = &snd_rpi_hifiberry_dac_ops,
  122559. + .init = snd_rpi_hifiberry_dac_init,
  122560. +},
  122561. +};
  122562. +
  122563. +/* audio machine driver */
  122564. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  122565. + .name = "snd_rpi_hifiberry_dac",
  122566. + .dai_link = snd_rpi_hifiberry_dac_dai,
  122567. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  122568. +};
  122569. +
  122570. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  122571. +{
  122572. + int ret = 0;
  122573. +
  122574. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  122575. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  122576. + if (ret)
  122577. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  122578. +
  122579. + return ret;
  122580. +}
  122581. +
  122582. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  122583. +{
  122584. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  122585. +}
  122586. +
  122587. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  122588. + .driver = {
  122589. + .name = "snd-hifiberry-dac",
  122590. + .owner = THIS_MODULE,
  122591. + },
  122592. + .probe = snd_rpi_hifiberry_dac_probe,
  122593. + .remove = snd_rpi_hifiberry_dac_remove,
  122594. +};
  122595. +
  122596. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  122597. +
  122598. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  122599. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  122600. +MODULE_LICENSE("GPL v2");
  122601. diff -Nur linux-3.12.38/sound/soc/bcm/hifiberry_dacplus.c linux-rpi/sound/soc/bcm/hifiberry_dacplus.c
  122602. --- linux-3.12.38/sound/soc/bcm/hifiberry_dacplus.c 1970-01-01 01:00:00.000000000 +0100
  122603. +++ linux-rpi/sound/soc/bcm/hifiberry_dacplus.c 2015-03-10 17:26:51.930216684 +0100
  122604. @@ -0,0 +1,119 @@
  122605. +/*
  122606. + * ASoC Driver for HiFiBerry DAC+
  122607. + *
  122608. + * Author: Daniel Matuschek
  122609. + * Copyright 2014
  122610. + * based on code by Florian Meier <florian.meier@koalo.de>
  122611. + *
  122612. + * This program is free software; you can redistribute it and/or
  122613. + * modify it under the terms of the GNU General Public License
  122614. + * version 2 as published by the Free Software Foundation.
  122615. + *
  122616. + * This program is distributed in the hope that it will be useful, but
  122617. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122618. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122619. + * General Public License for more details.
  122620. + */
  122621. +
  122622. +#include <linux/module.h>
  122623. +#include <linux/platform_device.h>
  122624. +
  122625. +#include <sound/core.h>
  122626. +#include <sound/pcm.h>
  122627. +#include <sound/pcm_params.h>
  122628. +#include <sound/soc.h>
  122629. +#include <sound/jack.h>
  122630. +
  122631. +#include "../codecs/pcm512x.h"
  122632. +
  122633. +static int snd_rpi_hifiberry_dacplus_init(struct snd_soc_pcm_runtime *rtd)
  122634. +{
  122635. + struct snd_soc_codec *codec = rtd->codec;
  122636. + snd_soc_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08);
  122637. + snd_soc_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0xf, 0x02);
  122638. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  122639. + return 0;
  122640. +}
  122641. +
  122642. +static int snd_rpi_hifiberry_dacplus_hw_params(struct snd_pcm_substream *substream,
  122643. + struct snd_pcm_hw_params *params)
  122644. +{
  122645. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122646. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122647. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 64);
  122648. +}
  122649. +
  122650. +static int snd_rpi_hifiberry_dacplus_startup(struct snd_pcm_substream *substream) {
  122651. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122652. + struct snd_soc_codec *codec = rtd->codec;
  122653. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x08);
  122654. + return 0;
  122655. +}
  122656. +
  122657. +static void snd_rpi_hifiberry_dacplus_shutdown(struct snd_pcm_substream *substream) {
  122658. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122659. + struct snd_soc_codec *codec = rtd->codec;
  122660. + snd_soc_update_bits(codec, PCM512x_GPIO_CONTROL_1, 0x08,0x00);
  122661. +}
  122662. +
  122663. +/* machine stream operations */
  122664. +static struct snd_soc_ops snd_rpi_hifiberry_dacplus_ops = {
  122665. + .hw_params = snd_rpi_hifiberry_dacplus_hw_params,
  122666. + .startup = snd_rpi_hifiberry_dacplus_startup,
  122667. + .shutdown = snd_rpi_hifiberry_dacplus_shutdown,
  122668. +};
  122669. +
  122670. +static struct snd_soc_dai_link snd_rpi_hifiberry_dacplus_dai[] = {
  122671. +{
  122672. + .name = "HiFiBerry DAC+",
  122673. + .stream_name = "HiFiBerry DAC+ HiFi",
  122674. + .cpu_dai_name = "bcm2708-i2s.0",
  122675. + .codec_dai_name = "pcm512x-hifi",
  122676. + .platform_name = "bcm2708-i2s.0",
  122677. + .codec_name = "pcm512x.1-004d",
  122678. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  122679. + SND_SOC_DAIFMT_CBS_CFS,
  122680. + .ops = &snd_rpi_hifiberry_dacplus_ops,
  122681. + .init = snd_rpi_hifiberry_dacplus_init,
  122682. +},
  122683. +};
  122684. +
  122685. +/* audio machine driver */
  122686. +static struct snd_soc_card snd_rpi_hifiberry_dacplus = {
  122687. + .name = "snd_rpi_hifiberry_dacplus",
  122688. + .dai_link = snd_rpi_hifiberry_dacplus_dai,
  122689. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dacplus_dai),
  122690. +};
  122691. +
  122692. +static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
  122693. +{
  122694. + int ret = 0;
  122695. +
  122696. + snd_rpi_hifiberry_dacplus.dev = &pdev->dev;
  122697. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dacplus);
  122698. + if (ret)
  122699. + dev_err(&pdev->dev,
  122700. + "snd_soc_register_card() failed: %d\n", ret);
  122701. +
  122702. + return ret;
  122703. +}
  122704. +
  122705. +static int snd_rpi_hifiberry_dacplus_remove(struct platform_device *pdev)
  122706. +{
  122707. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dacplus);
  122708. +}
  122709. +
  122710. +static struct platform_driver snd_rpi_hifiberry_dacplus_driver = {
  122711. + .driver = {
  122712. + .name = "snd-rpi-hifiberry-dacplus",
  122713. + .owner = THIS_MODULE,
  122714. + },
  122715. + .probe = snd_rpi_hifiberry_dacplus_probe,
  122716. + .remove = snd_rpi_hifiberry_dacplus_remove,
  122717. +};
  122718. +
  122719. +module_platform_driver(snd_rpi_hifiberry_dacplus_driver);
  122720. +
  122721. +MODULE_AUTHOR("Daniel Matuschek <daniel@hifiberry.com>");
  122722. +MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+");
  122723. +MODULE_LICENSE("GPL v2");
  122724. diff -Nur linux-3.12.38/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  122725. --- linux-3.12.38/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  122726. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2015-03-10 17:26:51.930216684 +0100
  122727. @@ -0,0 +1,153 @@
  122728. +/*
  122729. + * ASoC Driver for HifiBerry Digi
  122730. + *
  122731. + * Author: Daniel Matuschek <info@crazy-audio.com>
  122732. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  122733. + * Copyright 2013
  122734. + *
  122735. + * This program is free software; you can redistribute it and/or
  122736. + * modify it under the terms of the GNU General Public License
  122737. + * version 2 as published by the Free Software Foundation.
  122738. + *
  122739. + * This program is distributed in the hope that it will be useful, but
  122740. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122741. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122742. + * General Public License for more details.
  122743. + */
  122744. +
  122745. +#include <linux/module.h>
  122746. +#include <linux/platform_device.h>
  122747. +
  122748. +#include <sound/core.h>
  122749. +#include <sound/pcm.h>
  122750. +#include <sound/pcm_params.h>
  122751. +#include <sound/soc.h>
  122752. +#include <sound/jack.h>
  122753. +
  122754. +#include "../codecs/wm8804.h"
  122755. +
  122756. +static int samplerate=44100;
  122757. +
  122758. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  122759. +{
  122760. + struct snd_soc_codec *codec = rtd->codec;
  122761. +
  122762. + /* enable TX output */
  122763. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  122764. +
  122765. + return 0;
  122766. +}
  122767. +
  122768. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  122769. + struct snd_pcm_hw_params *params)
  122770. +{
  122771. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122772. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  122773. + struct snd_soc_codec *codec = rtd->codec;
  122774. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122775. +
  122776. + int sysclk = 27000000; /* This is fixed on this board */
  122777. +
  122778. + long mclk_freq=0;
  122779. + int mclk_div=1;
  122780. +
  122781. + int ret;
  122782. +
  122783. + samplerate = params_rate(params);
  122784. +
  122785. + switch (samplerate) {
  122786. + case 44100:
  122787. + case 48000:
  122788. + case 88200:
  122789. + case 96000:
  122790. + mclk_freq=samplerate*256;
  122791. + mclk_div=WM8804_MCLKDIV_256FS;
  122792. + break;
  122793. + case 176400:
  122794. + case 192000:
  122795. + mclk_freq=samplerate*128;
  122796. + mclk_div=WM8804_MCLKDIV_128FS;
  122797. + break;
  122798. + default:
  122799. + dev_err(substream->pcm->dev,
  122800. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  122801. + }
  122802. +
  122803. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  122804. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  122805. +
  122806. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  122807. + sysclk, SND_SOC_CLOCK_OUT);
  122808. + if (ret < 0) {
  122809. + dev_err(substream->pcm->dev,
  122810. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  122811. + return ret;
  122812. + }
  122813. +
  122814. + /* Enable TX output */
  122815. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  122816. +
  122817. + /* Power on */
  122818. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  122819. +
  122820. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  122821. +}
  122822. +
  122823. +/* machine stream operations */
  122824. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  122825. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  122826. +};
  122827. +
  122828. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  122829. +{
  122830. + .name = "HifiBerry Digi",
  122831. + .stream_name = "HifiBerry Digi HiFi",
  122832. + .cpu_dai_name = "bcm2708-i2s.0",
  122833. + .codec_dai_name = "wm8804-spdif",
  122834. + .platform_name = "bcm2708-i2s.0",
  122835. + .codec_name = "wm8804.1-003b",
  122836. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  122837. + SND_SOC_DAIFMT_CBM_CFM,
  122838. + .ops = &snd_rpi_hifiberry_digi_ops,
  122839. + .init = snd_rpi_hifiberry_digi_init,
  122840. +},
  122841. +};
  122842. +
  122843. +/* audio machine driver */
  122844. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  122845. + .name = "snd_rpi_hifiberry_digi",
  122846. + .dai_link = snd_rpi_hifiberry_digi_dai,
  122847. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  122848. +};
  122849. +
  122850. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  122851. +{
  122852. + int ret = 0;
  122853. +
  122854. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  122855. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  122856. + if (ret)
  122857. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  122858. +
  122859. + return ret;
  122860. +}
  122861. +
  122862. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  122863. +{
  122864. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  122865. +}
  122866. +
  122867. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  122868. + .driver = {
  122869. + .name = "snd-hifiberry-digi",
  122870. + .owner = THIS_MODULE,
  122871. + },
  122872. + .probe = snd_rpi_hifiberry_digi_probe,
  122873. + .remove = snd_rpi_hifiberry_digi_remove,
  122874. +};
  122875. +
  122876. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  122877. +
  122878. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  122879. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  122880. +MODULE_LICENSE("GPL v2");
  122881. diff -Nur linux-3.12.38/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  122882. --- linux-3.12.38/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  122883. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2015-03-10 17:26:51.930216684 +0100
  122884. @@ -0,0 +1,111 @@
  122885. +/*
  122886. + * ASoC Driver for IQaudIO DAC
  122887. + *
  122888. + * Author: Florian Meier <florian.meier@koalo.de>
  122889. + * Copyright 2013
  122890. + *
  122891. + * This program is free software; you can redistribute it and/or
  122892. + * modify it under the terms of the GNU General Public License
  122893. + * version 2 as published by the Free Software Foundation.
  122894. + *
  122895. + * This program is distributed in the hope that it will be useful, but
  122896. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  122897. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  122898. + * General Public License for more details.
  122899. + */
  122900. +
  122901. +#include <linux/module.h>
  122902. +#include <linux/platform_device.h>
  122903. +
  122904. +#include <sound/core.h>
  122905. +#include <sound/pcm.h>
  122906. +#include <sound/pcm_params.h>
  122907. +#include <sound/soc.h>
  122908. +#include <sound/jack.h>
  122909. +
  122910. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  122911. +{
  122912. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  122913. +
  122914. + return 0;
  122915. +}
  122916. +
  122917. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  122918. + struct snd_pcm_hw_params *params)
  122919. +{
  122920. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  122921. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  122922. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  122923. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  122924. +
  122925. + unsigned int sample_bits =
  122926. + snd_pcm_format_physical_width(params_format(params));
  122927. +
  122928. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  122929. +}
  122930. +
  122931. +/* machine stream operations */
  122932. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  122933. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  122934. +};
  122935. +
  122936. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  122937. +{
  122938. + .name = "IQaudIO DAC",
  122939. + .stream_name = "IQaudIO DAC HiFi",
  122940. + .cpu_dai_name = "bcm2708-i2s.0",
  122941. + .codec_dai_name = "pcm512x-hifi",
  122942. + .platform_name = "bcm2708-i2s.0",
  122943. + .codec_name = "pcm512x.1-004c",
  122944. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  122945. + SND_SOC_DAIFMT_CBS_CFS,
  122946. + .ops = &snd_rpi_iqaudio_dac_ops,
  122947. + .init = snd_rpi_iqaudio_dac_init,
  122948. +},
  122949. +};
  122950. +
  122951. +/* audio machine driver */
  122952. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  122953. + .name = "snd_rpi_iqaudio_dac",
  122954. + .dai_link = snd_rpi_iqaudio_dac_dai,
  122955. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  122956. +};
  122957. +
  122958. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  122959. +{
  122960. + int ret = 0;
  122961. +
  122962. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  122963. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  122964. + if (ret)
  122965. + dev_err(&pdev->dev,
  122966. + "snd_soc_register_card() failed: %d\n", ret);
  122967. +
  122968. + return ret;
  122969. +}
  122970. +
  122971. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  122972. +{
  122973. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  122974. +}
  122975. +
  122976. +static const struct of_device_id iqaudio_of_match[] = {
  122977. + { .compatible = "iqaudio,iqaudio-dac", },
  122978. + {},
  122979. +};
  122980. +
  122981. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  122982. + .driver = {
  122983. + .name = "snd-rpi-iqaudio-dac",
  122984. + .owner = THIS_MODULE,
  122985. + .of_match_table = iqaudio_of_match,
  122986. + },
  122987. + .probe = snd_rpi_iqaudio_dac_probe,
  122988. + .remove = snd_rpi_iqaudio_dac_remove,
  122989. +};
  122990. +
  122991. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  122992. +
  122993. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  122994. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  122995. +MODULE_LICENSE("GPL v2");
  122996. diff -Nur linux-3.12.38/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  122997. --- linux-3.12.38/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  122998. +++ linux-rpi/sound/soc/bcm/Kconfig 2015-03-10 17:26:51.926216684 +0100
  122999. @@ -0,0 +1,52 @@
  123000. +config SND_BCM2708_SOC_I2S
  123001. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  123002. + depends on MACH_BCM2708
  123003. + select REGMAP_MMIO
  123004. + select SND_SOC_DMAENGINE_PCM
  123005. + select SND_SOC_GENERIC_DMAENGINE_PCM
  123006. + help
  123007. + Say Y or M if you want to add support for codecs attached to
  123008. + the BCM2708 I2S interface. You will also need
  123009. + to select the audio interfaces to support below.
  123010. +
  123011. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  123012. + tristate "Support for HifiBerry DAC"
  123013. + depends on SND_BCM2708_SOC_I2S
  123014. + select SND_SOC_PCM5102A
  123015. + help
  123016. + Say Y or M if you want to add support for HifiBerry DAC.
  123017. +
  123018. +config SND_BCM2708_SOC_HIFIBERRY_DACPLUS
  123019. + tristate "Support for HifiBerry DAC+"
  123020. + depends on SND_BCM2708_SOC_I2S
  123021. + select SND_SOC_PCM512x
  123022. + help
  123023. + Say Y or M if you want to add support for HifiBerry DAC+.
  123024. +
  123025. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  123026. + tristate "Support for HifiBerry Digi"
  123027. + depends on SND_BCM2708_SOC_I2S
  123028. + select SND_SOC_WM8804
  123029. + help
  123030. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  123031. +
  123032. +config SND_BCM2708_SOC_HIFIBERRY_AMP
  123033. + tristate "Support for the HifiBerry Amp"
  123034. + depends on SND_BCM2708_SOC_I2S
  123035. + select SND_SOC_TAS5713
  123036. + help
  123037. + Say Y or M if you want to add support for the HifiBerry Amp amplifier board.
  123038. +
  123039. +config SND_BCM2708_SOC_RPI_DAC
  123040. + tristate "Support for RPi-DAC"
  123041. + depends on SND_BCM2708_SOC_I2S
  123042. + select SND_SOC_PCM1794A
  123043. + help
  123044. + Say Y or M if you want to add support for RPi-DAC.
  123045. +
  123046. +config SND_BCM2708_SOC_IQAUDIO_DAC
  123047. + tristate "Support for IQaudIO-DAC"
  123048. + depends on SND_BCM2708_SOC_I2S
  123049. + select SND_SOC_PCM512x
  123050. + help
  123051. + Say Y or M if you want to add support for IQaudIO-DAC.
  123052. diff -Nur linux-3.12.38/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  123053. --- linux-3.12.38/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  123054. +++ linux-rpi/sound/soc/bcm/Makefile 2015-03-10 17:26:51.926216684 +0100
  123055. @@ -0,0 +1,19 @@
  123056. +# BCM2708 Platform Support
  123057. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  123058. +
  123059. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  123060. +
  123061. +# BCM2708 Machine Support
  123062. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  123063. +snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
  123064. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  123065. +snd-soc-hifiberry-amp-objs := hifiberry_amp.o
  123066. +snd-soc-rpi-dac-objs := rpi-dac.o
  123067. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  123068. +
  123069. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  123070. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
  123071. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  123072. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) += snd-soc-hifiberry-amp.o
  123073. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  123074. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  123075. diff -Nur linux-3.12.38/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  123076. --- linux-3.12.38/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  123077. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2015-03-09 10:39:38.554893685 +0100
  123078. @@ -0,0 +1,97 @@
  123079. +/*
  123080. + * ASoC Driver for RPi-DAC.
  123081. + *
  123082. + * Author: Florian Meier <florian.meier@koalo.de>
  123083. + * Copyright 2013
  123084. + *
  123085. + * This program is free software; you can redistribute it and/or
  123086. + * modify it under the terms of the GNU General Public License
  123087. + * version 2 as published by the Free Software Foundation.
  123088. + *
  123089. + * This program is distributed in the hope that it will be useful, but
  123090. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123091. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123092. + * General Public License for more details.
  123093. + */
  123094. +
  123095. +#include <linux/module.h>
  123096. +#include <linux/platform_device.h>
  123097. +
  123098. +#include <sound/core.h>
  123099. +#include <sound/pcm.h>
  123100. +#include <sound/pcm_params.h>
  123101. +#include <sound/soc.h>
  123102. +#include <sound/jack.h>
  123103. +
  123104. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  123105. +{
  123106. + return 0;
  123107. +}
  123108. +
  123109. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  123110. + struct snd_pcm_hw_params *params)
  123111. +{
  123112. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  123113. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  123114. +
  123115. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  123116. +}
  123117. +
  123118. +/* machine stream operations */
  123119. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  123120. + .hw_params = snd_rpi_rpi_dac_hw_params,
  123121. +};
  123122. +
  123123. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  123124. +{
  123125. + .name = "RPi-DAC",
  123126. + .stream_name = "RPi-DAC HiFi",
  123127. + .cpu_dai_name = "bcm2708-i2s.0",
  123128. + .codec_dai_name = "pcm1794a-hifi",
  123129. + .platform_name = "bcm2708-i2s.0",
  123130. + .codec_name = "pcm1794a-codec",
  123131. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  123132. + SND_SOC_DAIFMT_CBS_CFS,
  123133. + .ops = &snd_rpi_rpi_dac_ops,
  123134. + .init = snd_rpi_rpi_dac_init,
  123135. +},
  123136. +};
  123137. +
  123138. +/* audio machine driver */
  123139. +static struct snd_soc_card snd_rpi_rpi_dac = {
  123140. + .name = "snd_rpi_rpi_dac",
  123141. + .dai_link = snd_rpi_rpi_dac_dai,
  123142. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  123143. +};
  123144. +
  123145. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  123146. +{
  123147. + int ret = 0;
  123148. +
  123149. + snd_rpi_rpi_dac.dev = &pdev->dev;
  123150. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  123151. + if (ret)
  123152. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  123153. +
  123154. + return ret;
  123155. +}
  123156. +
  123157. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  123158. +{
  123159. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  123160. +}
  123161. +
  123162. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  123163. + .driver = {
  123164. + .name = "snd-rpi-dac",
  123165. + .owner = THIS_MODULE,
  123166. + },
  123167. + .probe = snd_rpi_rpi_dac_probe,
  123168. + .remove = snd_rpi_rpi_dac_remove,
  123169. +};
  123170. +
  123171. +module_platform_driver(snd_rpi_rpi_dac_driver);
  123172. +
  123173. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123174. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  123175. +MODULE_LICENSE("GPL v2");
  123176. diff -Nur linux-3.12.38/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  123177. --- linux-3.12.38/sound/soc/codecs/Kconfig 2015-02-16 16:15:42.000000000 +0100
  123178. +++ linux-rpi/sound/soc/codecs/Kconfig 2015-03-10 17:26:51.930216684 +0100
  123179. @@ -59,6 +59,9 @@
  123180. select SND_SOC_PCM1681 if I2C
  123181. select SND_SOC_PCM1792A if SPI_MASTER
  123182. select SND_SOC_PCM3008
  123183. + select SND_SOC_PCM1794A
  123184. + select SND_SOC_PCM5102A
  123185. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  123186. select SND_SOC_RT5631 if I2C
  123187. select SND_SOC_RT5640 if I2C
  123188. select SND_SOC_SGTL5000 if I2C
  123189. @@ -71,6 +74,7 @@
  123190. select SND_SOC_STA529 if I2C
  123191. select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
  123192. select SND_SOC_TAS5086 if I2C
  123193. + select SND_SOC_TAS5713 if I2C
  123194. select SND_SOC_TLV320AIC23 if I2C
  123195. select SND_SOC_TLV320AIC26 if SPI_MASTER
  123196. select SND_SOC_TLV320AIC32X4 if I2C
  123197. @@ -311,6 +315,15 @@
  123198. config SND_SOC_PCM3008
  123199. tristate
  123200. +config SND_SOC_PCM1794A
  123201. + tristate
  123202. +
  123203. +config SND_SOC_PCM5102A
  123204. + tristate
  123205. +
  123206. +config SND_SOC_PCM512x
  123207. + tristate
  123208. +
  123209. config SND_SOC_RT5631
  123210. tristate
  123211. @@ -352,6 +365,9 @@
  123212. config SND_SOC_TAS5086
  123213. tristate
  123214. +config SND_SOC_TAS5713
  123215. + tristate
  123216. +
  123217. config SND_SOC_TLV320AIC23
  123218. tristate
  123219. diff -Nur linux-3.12.38/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  123220. --- linux-3.12.38/sound/soc/codecs/Makefile 2015-02-16 16:15:42.000000000 +0100
  123221. +++ linux-rpi/sound/soc/codecs/Makefile 2015-03-10 17:26:51.930216684 +0100
  123222. @@ -46,6 +46,9 @@
  123223. snd-soc-pcm1681-objs := pcm1681.o
  123224. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  123225. snd-soc-pcm3008-objs := pcm3008.o
  123226. +snd-soc-pcm1794a-objs := pcm1794a.o
  123227. +snd-soc-pcm5102a-objs := pcm5102a.o
  123228. +snd-soc-pcm512x-objs := pcm512x.o
  123229. snd-soc-rt5631-objs := rt5631.o
  123230. snd-soc-rt5640-objs := rt5640.o
  123231. snd-soc-sgtl5000-objs := sgtl5000.o
  123232. @@ -62,6 +65,7 @@
  123233. snd-soc-sta529-objs := sta529.o
  123234. snd-soc-stac9766-objs := stac9766.o
  123235. snd-soc-tas5086-objs := tas5086.o
  123236. +snd-soc-tas5713-objs := tas5713.o
  123237. snd-soc-tlv320aic23-objs := tlv320aic23.o
  123238. snd-soc-tlv320aic26-objs := tlv320aic26.o
  123239. snd-soc-tlv320aic3x-objs := tlv320aic3x.o
  123240. @@ -179,6 +183,9 @@
  123241. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  123242. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  123243. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  123244. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  123245. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  123246. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  123247. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  123248. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  123249. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  123250. @@ -192,6 +199,7 @@
  123251. obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o
  123252. obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
  123253. obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
  123254. +obj-$(CONFIG_SND_SOC_TAS5713) += snd-soc-tas5713.o
  123255. obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
  123256. obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
  123257. obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
  123258. diff -Nur linux-3.12.38/sound/soc/codecs/max98090.c linux-rpi/sound/soc/codecs/max98090.c
  123259. --- linux-3.12.38/sound/soc/codecs/max98090.c 2015-02-16 16:15:42.000000000 +0100
  123260. +++ linux-rpi/sound/soc/codecs/max98090.c 2015-03-10 17:26:51.934216684 +0100
  123261. @@ -1378,8 +1378,8 @@
  123262. {"STENL Mux", "Sidetone Left", "DMICL"},
  123263. {"STENR Mux", "Sidetone Right", "ADCR"},
  123264. {"STENR Mux", "Sidetone Right", "DMICR"},
  123265. - {"DACL", NULL, "STENL Mux"},
  123266. - {"DACR", NULL, "STENL Mux"},
  123267. + {"DACL", "NULL", "STENL Mux"},
  123268. + {"DACR", "NULL", "STENL Mux"},
  123269. {"AIFINL", NULL, "SHDN"},
  123270. {"AIFINR", NULL, "SHDN"},
  123271. diff -Nur linux-3.12.38/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  123272. --- linux-3.12.38/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  123273. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2015-03-09 10:39:38.566893685 +0100
  123274. @@ -0,0 +1,62 @@
  123275. +/*
  123276. + * Driver for the PCM1794A codec
  123277. + *
  123278. + * Author: Florian Meier <florian.meier@koalo.de>
  123279. + * Copyright 2013
  123280. + *
  123281. + * This program is free software; you can redistribute it and/or
  123282. + * modify it under the terms of the GNU General Public License
  123283. + * version 2 as published by the Free Software Foundation.
  123284. + *
  123285. + * This program is distributed in the hope that it will be useful, but
  123286. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123287. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123288. + * General Public License for more details.
  123289. + */
  123290. +
  123291. +
  123292. +#include <linux/init.h>
  123293. +#include <linux/module.h>
  123294. +#include <linux/platform_device.h>
  123295. +
  123296. +#include <sound/soc.h>
  123297. +
  123298. +static struct snd_soc_dai_driver pcm1794a_dai = {
  123299. + .name = "pcm1794a-hifi",
  123300. + .playback = {
  123301. + .channels_min = 2,
  123302. + .channels_max = 2,
  123303. + .rates = SNDRV_PCM_RATE_8000_192000,
  123304. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  123305. + SNDRV_PCM_FMTBIT_S24_LE
  123306. + },
  123307. +};
  123308. +
  123309. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  123310. +
  123311. +static int pcm1794a_probe(struct platform_device *pdev)
  123312. +{
  123313. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  123314. + &pcm1794a_dai, 1);
  123315. +}
  123316. +
  123317. +static int pcm1794a_remove(struct platform_device *pdev)
  123318. +{
  123319. + snd_soc_unregister_codec(&pdev->dev);
  123320. + return 0;
  123321. +}
  123322. +
  123323. +static struct platform_driver pcm1794a_codec_driver = {
  123324. + .probe = pcm1794a_probe,
  123325. + .remove = pcm1794a_remove,
  123326. + .driver = {
  123327. + .name = "pcm1794a-codec",
  123328. + .owner = THIS_MODULE,
  123329. + },
  123330. +};
  123331. +
  123332. +module_platform_driver(pcm1794a_codec_driver);
  123333. +
  123334. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  123335. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123336. +MODULE_LICENSE("GPL v2");
  123337. diff -Nur linux-3.12.38/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  123338. --- linux-3.12.38/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  123339. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2015-03-10 17:26:51.938216684 +0100
  123340. @@ -0,0 +1,63 @@
  123341. +/*
  123342. + * Driver for the PCM5102A codec
  123343. + *
  123344. + * Author: Florian Meier <florian.meier@koalo.de>
  123345. + * Copyright 2013
  123346. + *
  123347. + * This program is free software; you can redistribute it and/or
  123348. + * modify it under the terms of the GNU General Public License
  123349. + * version 2 as published by the Free Software Foundation.
  123350. + *
  123351. + * This program is distributed in the hope that it will be useful, but
  123352. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123353. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123354. + * General Public License for more details.
  123355. + */
  123356. +
  123357. +
  123358. +#include <linux/init.h>
  123359. +#include <linux/module.h>
  123360. +#include <linux/platform_device.h>
  123361. +
  123362. +#include <sound/soc.h>
  123363. +
  123364. +static struct snd_soc_dai_driver pcm5102a_dai = {
  123365. + .name = "pcm5102a-hifi",
  123366. + .playback = {
  123367. + .channels_min = 2,
  123368. + .channels_max = 2,
  123369. + .rates = SNDRV_PCM_RATE_8000_192000,
  123370. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  123371. + SNDRV_PCM_FMTBIT_S24_LE |
  123372. + SNDRV_PCM_FMTBIT_S32_LE
  123373. + },
  123374. +};
  123375. +
  123376. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  123377. +
  123378. +static int pcm5102a_probe(struct platform_device *pdev)
  123379. +{
  123380. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  123381. + &pcm5102a_dai, 1);
  123382. +}
  123383. +
  123384. +static int pcm5102a_remove(struct platform_device *pdev)
  123385. +{
  123386. + snd_soc_unregister_codec(&pdev->dev);
  123387. + return 0;
  123388. +}
  123389. +
  123390. +static struct platform_driver pcm5102a_codec_driver = {
  123391. + .probe = pcm5102a_probe,
  123392. + .remove = pcm5102a_remove,
  123393. + .driver = {
  123394. + .name = "pcm5102a-codec",
  123395. + .owner = THIS_MODULE,
  123396. + },
  123397. +};
  123398. +
  123399. +module_platform_driver(pcm5102a_codec_driver);
  123400. +
  123401. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  123402. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  123403. +MODULE_LICENSE("GPL v2");
  123404. diff -Nur linux-3.12.38/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  123405. --- linux-3.12.38/sound/soc/codecs/pcm512x.c 1970-01-01 01:00:00.000000000 +0100
  123406. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2015-03-10 17:26:51.938216684 +0100
  123407. @@ -0,0 +1,678 @@
  123408. +/*
  123409. + * Driver for the PCM512x CODECs
  123410. + *
  123411. + * Author: Mark Brown <broonie@linaro.org>
  123412. + * Copyright 2014 Linaro Ltd
  123413. + *
  123414. + * This program is free software; you can redistribute it and/or
  123415. + * modify it under the terms of the GNU General Public License
  123416. + * version 2 as published by the Free Software Foundation.
  123417. + *
  123418. + * This program is distributed in the hope that it will be useful, but
  123419. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  123420. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  123421. + * General Public License for more details.
  123422. + */
  123423. +
  123424. +
  123425. +#include <linux/init.h>
  123426. +#include <linux/module.h>
  123427. +#include <linux/clk.h>
  123428. +#include <linux/i2c.h>
  123429. +#include <linux/pm_runtime.h>
  123430. +#include <linux/regmap.h>
  123431. +#include <linux/regulator/consumer.h>
  123432. +#include <linux/spi/spi.h>
  123433. +#include <sound/soc.h>
  123434. +#include <sound/soc-dapm.h>
  123435. +#include <sound/tlv.h>
  123436. +
  123437. +#include "pcm512x.h"
  123438. +
  123439. +#define PCM512x_NUM_SUPPLIES 3
  123440. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  123441. + "AVDD",
  123442. + "DVDD",
  123443. + "CPVDD",
  123444. +};
  123445. +
  123446. +struct pcm512x_priv {
  123447. + struct regmap *regmap;
  123448. + struct clk *sclk;
  123449. + struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
  123450. + struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
  123451. +};
  123452. +
  123453. +/*
  123454. + * We can't use the same notifier block for more than one supply and
  123455. + * there's no way I can see to get from a callback to the caller
  123456. + * except container_of().
  123457. + */
  123458. +#define PCM512x_REGULATOR_EVENT(n) \
  123459. +static int pcm512x_regulator_event_##n(struct notifier_block *nb, \
  123460. + unsigned long event, void *data) \
  123461. +{ \
  123462. + struct pcm512x_priv *pcm512x = container_of(nb, struct pcm512x_priv, \
  123463. + supply_nb[n]); \
  123464. + if (event & REGULATOR_EVENT_DISABLE) { \
  123465. + regcache_mark_dirty(pcm512x->regmap); \
  123466. + regcache_cache_only(pcm512x->regmap, true); \
  123467. + } \
  123468. + return 0; \
  123469. +}
  123470. +
  123471. +PCM512x_REGULATOR_EVENT(0)
  123472. +PCM512x_REGULATOR_EVENT(1)
  123473. +PCM512x_REGULATOR_EVENT(2)
  123474. +
  123475. +static const struct reg_default pcm512x_reg_defaults[] = {
  123476. + { PCM512x_RESET, 0x00 },
  123477. + { PCM512x_POWER, 0x00 },
  123478. + { PCM512x_MUTE, 0x00 },
  123479. + { PCM512x_DSP, 0x00 },
  123480. + { PCM512x_PLL_REF, 0x00 },
  123481. + { PCM512x_DAC_ROUTING, 0x11 },
  123482. + { PCM512x_DSP_PROGRAM, 0x01 },
  123483. + { PCM512x_CLKDET, 0x00 },
  123484. + { PCM512x_AUTO_MUTE, 0x00 },
  123485. + { PCM512x_ERROR_DETECT, 0x00 },
  123486. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  123487. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  123488. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  123489. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  123490. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  123491. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  123492. +};
  123493. +
  123494. +static bool pcm512x_readable(struct device *dev, unsigned int reg)
  123495. +{
  123496. + switch (reg) {
  123497. + case PCM512x_RESET:
  123498. + case PCM512x_POWER:
  123499. + case PCM512x_MUTE:
  123500. + case PCM512x_PLL_EN:
  123501. + case PCM512x_SPI_MISO_FUNCTION:
  123502. + case PCM512x_DSP:
  123503. + case PCM512x_GPIO_EN:
  123504. + case PCM512x_BCLK_LRCLK_CFG:
  123505. + case PCM512x_DSP_GPIO_INPUT:
  123506. + case PCM512x_MASTER_MODE:
  123507. + case PCM512x_PLL_REF:
  123508. + case PCM512x_PLL_COEFF_0:
  123509. + case PCM512x_PLL_COEFF_1:
  123510. + case PCM512x_PLL_COEFF_2:
  123511. + case PCM512x_PLL_COEFF_3:
  123512. + case PCM512x_PLL_COEFF_4:
  123513. + case PCM512x_DSP_CLKDIV:
  123514. + case PCM512x_DAC_CLKDIV:
  123515. + case PCM512x_NCP_CLKDIV:
  123516. + case PCM512x_OSR_CLKDIV:
  123517. + case PCM512x_MASTER_CLKDIV_1:
  123518. + case PCM512x_MASTER_CLKDIV_2:
  123519. + case PCM512x_FS_SPEED_MODE:
  123520. + case PCM512x_IDAC_1:
  123521. + case PCM512x_IDAC_2:
  123522. + case PCM512x_ERROR_DETECT:
  123523. + case PCM512x_I2S_1:
  123524. + case PCM512x_I2S_2:
  123525. + case PCM512x_DAC_ROUTING:
  123526. + case PCM512x_DSP_PROGRAM:
  123527. + case PCM512x_CLKDET:
  123528. + case PCM512x_AUTO_MUTE:
  123529. + case PCM512x_DIGITAL_VOLUME_1:
  123530. + case PCM512x_DIGITAL_VOLUME_2:
  123531. + case PCM512x_DIGITAL_VOLUME_3:
  123532. + case PCM512x_DIGITAL_MUTE_1:
  123533. + case PCM512x_DIGITAL_MUTE_2:
  123534. + case PCM512x_DIGITAL_MUTE_3:
  123535. + case PCM512x_GPIO_OUTPUT_1:
  123536. + case PCM512x_GPIO_OUTPUT_2:
  123537. + case PCM512x_GPIO_OUTPUT_3:
  123538. + case PCM512x_GPIO_OUTPUT_4:
  123539. + case PCM512x_GPIO_OUTPUT_5:
  123540. + case PCM512x_GPIO_OUTPUT_6:
  123541. + case PCM512x_GPIO_CONTROL_1:
  123542. + case PCM512x_GPIO_CONTROL_2:
  123543. + case PCM512x_OVERFLOW:
  123544. + case PCM512x_RATE_DET_1:
  123545. + case PCM512x_RATE_DET_2:
  123546. + case PCM512x_RATE_DET_3:
  123547. + case PCM512x_RATE_DET_4:
  123548. + case PCM512x_ANALOG_MUTE_DET:
  123549. + case PCM512x_GPIN:
  123550. + case PCM512x_DIGITAL_MUTE_DET:
  123551. + return true;
  123552. + default:
  123553. + return false;
  123554. + }
  123555. +}
  123556. +
  123557. +static bool pcm512x_volatile(struct device *dev, unsigned int reg)
  123558. +{
  123559. + switch (reg) {
  123560. + case PCM512x_PLL_EN:
  123561. + case PCM512x_OVERFLOW:
  123562. + case PCM512x_RATE_DET_1:
  123563. + case PCM512x_RATE_DET_2:
  123564. + case PCM512x_RATE_DET_3:
  123565. + case PCM512x_RATE_DET_4:
  123566. + case PCM512x_ANALOG_MUTE_DET:
  123567. + case PCM512x_GPIN:
  123568. + case PCM512x_DIGITAL_MUTE_DET:
  123569. + return true;
  123570. + default:
  123571. + return false;
  123572. + }
  123573. +}
  123574. +
  123575. +static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  123576. +
  123577. +static const char *pcm512x_dsp_program_texts[] = {
  123578. + "FIR interpolation with de-emphasis",
  123579. + "Low latency IIR with de-emphasis",
  123580. + "High attenuation with de-emphasis",
  123581. + "Ringing-less low latency FIR",
  123582. +};
  123583. +
  123584. +static const unsigned int pcm512x_dsp_program_values[] = {
  123585. + 1,
  123586. + 2,
  123587. + 3,
  123588. + 5,
  123589. + 7,
  123590. +};
  123591. +
  123592. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  123593. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  123594. + pcm512x_dsp_program_texts,
  123595. + pcm512x_dsp_program_values);
  123596. +
  123597. +static const char *pcm512x_clk_missing_text[] = {
  123598. + "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  123599. +};
  123600. +
  123601. +static const struct soc_enum pcm512x_clk_missing =
  123602. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  123603. +
  123604. +static const char *pcm512x_autom_text[] = {
  123605. + "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  123606. +};
  123607. +
  123608. +static const struct soc_enum pcm512x_autom_l =
  123609. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  123610. + pcm512x_autom_text);
  123611. +
  123612. +static const struct soc_enum pcm512x_autom_r =
  123613. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  123614. + pcm512x_autom_text);
  123615. +
  123616. +static const char *pcm512x_ramp_rate_text[] = {
  123617. + "1 sample/update", "2 samples/update", "4 samples/update",
  123618. + "Immediate"
  123619. +};
  123620. +
  123621. +static const struct soc_enum pcm512x_vndf =
  123622. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDF_SHIFT, 4,
  123623. + pcm512x_ramp_rate_text);
  123624. +
  123625. +static const struct soc_enum pcm512x_vnuf =
  123626. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUF_SHIFT, 4,
  123627. + pcm512x_ramp_rate_text);
  123628. +
  123629. +static const struct soc_enum pcm512x_vedf =
  123630. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  123631. + pcm512x_ramp_rate_text);
  123632. +
  123633. +static const char *pcm512x_ramp_step_text[] = {
  123634. + "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  123635. +};
  123636. +
  123637. +static const struct soc_enum pcm512x_vnds =
  123638. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDS_SHIFT, 4,
  123639. + pcm512x_ramp_step_text);
  123640. +
  123641. +static const struct soc_enum pcm512x_vnus =
  123642. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUS_SHIFT, 4,
  123643. + pcm512x_ramp_step_text);
  123644. +
  123645. +static const struct soc_enum pcm512x_veds =
  123646. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  123647. + pcm512x_ramp_step_text);
  123648. +
  123649. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  123650. +static const struct snd_kcontrol_new pcm512x_controls[] = {
  123651. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  123652. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  123653. +SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  123654. + PCM512x_RQMR_SHIFT, 1, 1),
  123655. +
  123656. +SOC_SINGLE("Deemphasis Switch", PCM512x_DSP, PCM512x_DEMP_SHIFT, 1, 1),
  123657. +SOC_VALUE_ENUM("DSP Program", pcm512x_dsp_program),
  123658. +
  123659. +SOC_ENUM("Clock Missing Period", pcm512x_clk_missing),
  123660. +SOC_ENUM("Auto Mute Time Left", pcm512x_autom_l),
  123661. +SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
  123662. +SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
  123663. + PCM512x_ACTL_SHIFT, 1, 0),
  123664. +SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
  123665. + PCM512x_AMLR_SHIFT, 1, 0),
  123666. +
  123667. +SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
  123668. +SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
  123669. +SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
  123670. +SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
  123671. +SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
  123672. +SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
  123673. +};
  123674. +
  123675. +static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
  123676. +SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
  123677. +SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
  123678. +
  123679. +SND_SOC_DAPM_OUTPUT("OUTL"),
  123680. +SND_SOC_DAPM_OUTPUT("OUTR"),
  123681. +};
  123682. +
  123683. +static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
  123684. + { "DACL", NULL, "Playback" },
  123685. + { "DACR", NULL, "Playback" },
  123686. +
  123687. + { "OUTL", NULL, "DACL" },
  123688. + { "OUTR", NULL, "DACR" },
  123689. +};
  123690. +
  123691. +static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
  123692. + enum snd_soc_bias_level level)
  123693. +{
  123694. + struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev);
  123695. + int ret;
  123696. +
  123697. + switch (level) {
  123698. + case SND_SOC_BIAS_ON:
  123699. + case SND_SOC_BIAS_PREPARE:
  123700. + break;
  123701. +
  123702. + case SND_SOC_BIAS_STANDBY:
  123703. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  123704. + PCM512x_RQST, 0);
  123705. + if (ret != 0) {
  123706. + dev_err(codec->dev, "Failed to remove standby: %d\n",
  123707. + ret);
  123708. + return ret;
  123709. + }
  123710. + break;
  123711. +
  123712. + case SND_SOC_BIAS_OFF:
  123713. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  123714. + PCM512x_RQST, PCM512x_RQST);
  123715. + if (ret != 0) {
  123716. + dev_err(codec->dev, "Failed to request standby: %d\n",
  123717. + ret);
  123718. + return ret;
  123719. + }
  123720. + break;
  123721. + }
  123722. +
  123723. + codec->dapm.bias_level = level;
  123724. +
  123725. + return 0;
  123726. +}
  123727. +
  123728. +static struct snd_soc_dai_driver pcm512x_dai = {
  123729. + .name = "pcm512x-hifi",
  123730. + .playback = {
  123731. + .stream_name = "Playback",
  123732. + .channels_min = 2,
  123733. + .channels_max = 2,
  123734. + .rates = SNDRV_PCM_RATE_8000_192000,
  123735. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  123736. + SNDRV_PCM_FMTBIT_S24_LE |
  123737. + SNDRV_PCM_FMTBIT_S32_LE
  123738. + },
  123739. +};
  123740. +
  123741. +static struct snd_soc_codec_driver pcm512x_codec_driver = {
  123742. + .set_bias_level = pcm512x_set_bias_level,
  123743. + .idle_bias_off = true,
  123744. +
  123745. + .controls = pcm512x_controls,
  123746. + .num_controls = ARRAY_SIZE(pcm512x_controls),
  123747. + .dapm_widgets = pcm512x_dapm_widgets,
  123748. + .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
  123749. + .dapm_routes = pcm512x_dapm_routes,
  123750. + .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  123751. +};
  123752. +
  123753. +static const struct regmap_config pcm512x_regmap = {
  123754. + .reg_bits = 8,
  123755. + .val_bits = 8,
  123756. +
  123757. + .readable_reg = pcm512x_readable,
  123758. + .volatile_reg = pcm512x_volatile,
  123759. +
  123760. + .max_register = PCM512x_MAX_REGISTER,
  123761. + .reg_defaults = pcm512x_reg_defaults,
  123762. + .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  123763. + .cache_type = REGCACHE_RBTREE,
  123764. +};
  123765. +
  123766. +static const struct of_device_id pcm512x_of_match[] = {
  123767. + { .compatible = "ti,pcm5121", },
  123768. + { .compatible = "ti,pcm5122", },
  123769. + { }
  123770. +};
  123771. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  123772. +
  123773. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  123774. +{
  123775. + struct pcm512x_priv *pcm512x;
  123776. + int i, ret;
  123777. +
  123778. + pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL);
  123779. + if (!pcm512x)
  123780. + return -ENOMEM;
  123781. +
  123782. + dev_set_drvdata(dev, pcm512x);
  123783. + pcm512x->regmap = regmap;
  123784. +
  123785. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++)
  123786. + pcm512x->supplies[i].supply = pcm512x_supply_names[i];
  123787. +
  123788. + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies),
  123789. + pcm512x->supplies);
  123790. + if (ret != 0) {
  123791. + dev_err(dev, "Failed to get supplies: %d\n", ret);
  123792. + return ret;
  123793. + }
  123794. +
  123795. + pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0;
  123796. + pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1;
  123797. + pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2;
  123798. +
  123799. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) {
  123800. + ret = regulator_register_notifier(pcm512x->supplies[i].consumer,
  123801. + &pcm512x->supply_nb[i]);
  123802. + if (ret != 0) {
  123803. + dev_err(dev,
  123804. + "Failed to register regulator notifier: %d\n",
  123805. + ret);
  123806. + }
  123807. + }
  123808. +
  123809. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  123810. + pcm512x->supplies);
  123811. + if (ret != 0) {
  123812. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  123813. + return ret;
  123814. + }
  123815. +
  123816. + /* Reset the device, verifying I/O in the process for I2C */
  123817. + ret = regmap_write(regmap, PCM512x_RESET,
  123818. + PCM512x_RSTM | PCM512x_RSTR);
  123819. + if (ret != 0) {
  123820. + dev_err(dev, "Failed to reset device: %d\n", ret);
  123821. + goto err;
  123822. + }
  123823. +
  123824. + ret = regmap_write(regmap, PCM512x_RESET, 0);
  123825. + if (ret != 0) {
  123826. + dev_err(dev, "Failed to reset device: %d\n", ret);
  123827. + goto err;
  123828. + }
  123829. +
  123830. + pcm512x->sclk = devm_clk_get(dev, NULL);
  123831. + if (IS_ERR(pcm512x->sclk)) {
  123832. + if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
  123833. + return -EPROBE_DEFER;
  123834. +
  123835. + dev_info(dev, "No SCLK, using BCLK: %ld\n",
  123836. + PTR_ERR(pcm512x->sclk));
  123837. +
  123838. + /* Disable reporting of missing SCLK as an error */
  123839. + regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
  123840. + PCM512x_IDCH, PCM512x_IDCH);
  123841. +
  123842. + /* Switch PLL input to BCLK */
  123843. + regmap_update_bits(regmap, PCM512x_PLL_REF,
  123844. + PCM512x_SREF, PCM512x_SREF);
  123845. + } else {
  123846. + ret = clk_prepare_enable(pcm512x->sclk);
  123847. + if (ret != 0) {
  123848. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  123849. + return ret;
  123850. + }
  123851. + }
  123852. +
  123853. + /* Default to standby mode */
  123854. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  123855. + PCM512x_RQST, PCM512x_RQST);
  123856. + if (ret != 0) {
  123857. + dev_err(dev, "Failed to request standby: %d\n",
  123858. + ret);
  123859. + goto err_clk;
  123860. + }
  123861. +
  123862. + pm_runtime_set_active(dev);
  123863. + pm_runtime_enable(dev);
  123864. + pm_runtime_idle(dev);
  123865. +
  123866. + ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
  123867. + &pcm512x_dai, 1);
  123868. + if (ret != 0) {
  123869. + dev_err(dev, "Failed to register CODEC: %d\n", ret);
  123870. + goto err_pm;
  123871. + }
  123872. +
  123873. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  123874. +
  123875. + return 0;
  123876. +
  123877. +err_pm:
  123878. + pm_runtime_disable(dev);
  123879. +err_clk:
  123880. + if (!IS_ERR(pcm512x->sclk))
  123881. + clk_disable_unprepare(pcm512x->sclk);
  123882. +err:
  123883. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  123884. + pcm512x->supplies);
  123885. + return ret;
  123886. +}
  123887. +
  123888. +static void pcm512x_remove(struct device *dev)
  123889. +{
  123890. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  123891. +
  123892. + snd_soc_unregister_codec(dev);
  123893. + pm_runtime_disable(dev);
  123894. + if (!IS_ERR(pcm512x->sclk))
  123895. + clk_disable_unprepare(pcm512x->sclk);
  123896. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  123897. + pcm512x->supplies);
  123898. +}
  123899. +
  123900. +/* TODO
  123901. +static int pcm512x_suspend(struct device *dev)
  123902. +{
  123903. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  123904. + int ret;
  123905. +
  123906. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  123907. + PCM512x_RQPD, PCM512x_RQPD);
  123908. + if (ret != 0) {
  123909. + dev_err(dev, "Failed to request power down: %d\n", ret);
  123910. + return ret;
  123911. + }
  123912. +
  123913. + ret = regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  123914. + pcm512x->supplies);
  123915. + if (ret != 0) {
  123916. + dev_err(dev, "Failed to disable supplies: %d\n", ret);
  123917. + return ret;
  123918. + }
  123919. +
  123920. + if (!IS_ERR(pcm512x->sclk))
  123921. + clk_disable_unprepare(pcm512x->sclk);
  123922. +
  123923. + return 0;
  123924. +}
  123925. +
  123926. +static int pcm512x_resume(struct device *dev)
  123927. +{
  123928. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  123929. + int ret;
  123930. +
  123931. + if (!IS_ERR(pcm512x->sclk)) {
  123932. + ret = clk_prepare_enable(pcm512x->sclk);
  123933. + if (ret != 0) {
  123934. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  123935. + return ret;
  123936. + }
  123937. + }
  123938. +
  123939. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  123940. + pcm512x->supplies);
  123941. + if (ret != 0) {
  123942. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  123943. + return ret;
  123944. + }
  123945. +
  123946. + regcache_cache_only(pcm512x->regmap, false);
  123947. + ret = regcache_sync(pcm512x->regmap);
  123948. + if (ret != 0) {
  123949. + dev_err(dev, "Failed to sync cache: %d\n", ret);
  123950. + return ret;
  123951. + }
  123952. +
  123953. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  123954. + PCM512x_RQPD, 0);
  123955. + if (ret != 0) {
  123956. + dev_err(dev, "Failed to remove power down: %d\n", ret);
  123957. + return ret;
  123958. + }
  123959. +
  123960. + return 0;
  123961. +}
  123962. +
  123963. +// END OF PCM512x_suspend and resume calls TODO
  123964. +*/
  123965. +
  123966. +static const struct dev_pm_ops pcm512x_pm_ops = {
  123967. + SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  123968. +};
  123969. +
  123970. +#if IS_ENABLED(CONFIG_I2C)
  123971. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  123972. + const struct i2c_device_id *id)
  123973. +{
  123974. + struct regmap *regmap;
  123975. +
  123976. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  123977. + if (IS_ERR(regmap))
  123978. + return PTR_ERR(regmap);
  123979. +
  123980. + return pcm512x_probe(&i2c->dev, regmap);
  123981. +}
  123982. +
  123983. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  123984. +{
  123985. + pcm512x_remove(&i2c->dev);
  123986. + return 0;
  123987. +}
  123988. +
  123989. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  123990. + { "pcm5121", },
  123991. + { "pcm5122", },
  123992. + { }
  123993. +};
  123994. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  123995. +
  123996. +static struct i2c_driver pcm512x_i2c_driver = {
  123997. + .probe = pcm512x_i2c_probe,
  123998. + .remove = pcm512x_i2c_remove,
  123999. + .id_table = pcm512x_i2c_id,
  124000. + .driver = {
  124001. + .name = "pcm512x",
  124002. + .owner = THIS_MODULE,
  124003. + .of_match_table = pcm512x_of_match,
  124004. + .pm = &pcm512x_pm_ops,
  124005. + },
  124006. +};
  124007. +#endif
  124008. +
  124009. +#if defined(CONFIG_SPI_MASTER)
  124010. +static int pcm512x_spi_probe(struct spi_device *spi)
  124011. +{
  124012. + struct regmap *regmap;
  124013. + int ret;
  124014. +
  124015. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  124016. + if (IS_ERR(regmap)) {
  124017. + ret = PTR_ERR(regmap);
  124018. + return ret;
  124019. + }
  124020. +
  124021. + return pcm512x_probe(&spi->dev, regmap);
  124022. +}
  124023. +
  124024. +static int pcm512x_spi_remove(struct spi_device *spi)
  124025. +{
  124026. + pcm512x_remove(&spi->dev);
  124027. + return 0;
  124028. +}
  124029. +
  124030. +static const struct spi_device_id pcm512x_spi_id[] = {
  124031. + { "pcm5121", },
  124032. + { "pcm5122", },
  124033. + { },
  124034. +};
  124035. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  124036. +
  124037. +static struct spi_driver pcm512x_spi_driver = {
  124038. + .probe = pcm512x_spi_probe,
  124039. + .remove = pcm512x_spi_remove,
  124040. + .id_table = pcm512x_spi_id,
  124041. + .driver = {
  124042. + .name = "pcm512x",
  124043. + .owner = THIS_MODULE,
  124044. + .of_match_table = pcm512x_of_match,
  124045. + .pm = &pcm512x_pm_ops,
  124046. + },
  124047. +};
  124048. +#endif
  124049. +
  124050. +static int __init pcm512x_modinit(void)
  124051. +{
  124052. + int ret = 0;
  124053. +
  124054. +#if IS_ENABLED(CONFIG_I2C)
  124055. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  124056. + if (ret) {
  124057. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  124058. + ret);
  124059. + }
  124060. +#endif
  124061. +#if defined(CONFIG_SPI_MASTER)
  124062. + ret = spi_register_driver(&pcm512x_spi_driver);
  124063. + if (ret != 0) {
  124064. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  124065. + ret);
  124066. + }
  124067. +#endif
  124068. + return ret;
  124069. +}
  124070. +module_init(pcm512x_modinit);
  124071. +
  124072. +static void __exit pcm512x_exit(void)
  124073. +{
  124074. +#if IS_ENABLED(CONFIG_I2C)
  124075. + i2c_del_driver(&pcm512x_i2c_driver);
  124076. +#endif
  124077. +#if defined(CONFIG_SPI_MASTER)
  124078. + spi_unregister_driver(&pcm512x_spi_driver);
  124079. +#endif
  124080. +}
  124081. +module_exit(pcm512x_exit);
  124082. +
  124083. +MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  124084. +MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  124085. +MODULE_LICENSE("GPL v2");
  124086. diff -Nur linux-3.12.38/sound/soc/codecs/pcm512x.h linux-rpi/sound/soc/codecs/pcm512x.h
  124087. --- linux-3.12.38/sound/soc/codecs/pcm512x.h 1970-01-01 01:00:00.000000000 +0100
  124088. +++ linux-rpi/sound/soc/codecs/pcm512x.h 2015-03-10 17:26:51.938216684 +0100
  124089. @@ -0,0 +1,142 @@
  124090. +/*
  124091. + * Driver for the PCM512x CODECs
  124092. + *
  124093. + * Author: Mark Brown <broonie@linaro.org>
  124094. + * Copyright 2014 Linaro Ltd
  124095. + *
  124096. + * This program is free software; you can redistribute it and/or
  124097. + * modify it under the terms of the GNU General Public License
  124098. + * version 2 as published by the Free Software Foundation.
  124099. + *
  124100. + * This program is distributed in the hope that it will be useful, but
  124101. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  124102. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  124103. + * General Public License for more details.
  124104. + */
  124105. +
  124106. +#ifndef _SND_SOC_PCM512X
  124107. +#define _SND_SOC_PCM512X
  124108. +
  124109. +#define PCM512x_PAGE_0_BASE 0
  124110. +
  124111. +#define PCM512x_PAGE 0
  124112. +
  124113. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  124114. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  124115. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  124116. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  124117. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  124118. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  124119. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  124120. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  124121. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  124122. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  124123. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  124124. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  124125. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  124126. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  124127. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  124128. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  124129. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  124130. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  124131. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  124132. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  124133. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  124134. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  124135. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  124136. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  124137. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  124138. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  124139. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  124140. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  124141. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  124142. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  124143. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  124144. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  124145. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  124146. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  124147. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  124148. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  124149. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  124150. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  124151. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  124152. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  124153. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  124154. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  124155. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  124156. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  124157. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  124158. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  124159. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  124160. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  124161. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  124162. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  124163. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  124164. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  124165. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  124166. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  124167. +
  124168. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  124169. +
  124170. +/* Page 0, Register 1 - reset */
  124171. +#define PCM512x_RSTR (1 << 0)
  124172. +#define PCM512x_RSTM (1 << 4)
  124173. +
  124174. +/* Page 0, Register 2 - power */
  124175. +#define PCM512x_RQPD (1 << 0)
  124176. +#define PCM512x_RQPD_SHIFT 0
  124177. +#define PCM512x_RQST (1 << 4)
  124178. +#define PCM512x_RQST_SHIFT 4
  124179. +
  124180. +/* Page 0, Register 3 - mute */
  124181. +#define PCM512x_RQMR_SHIFT 0
  124182. +#define PCM512x_RQML_SHIFT 4
  124183. +
  124184. +/* Page 0, Register 4 - PLL */
  124185. +#define PCM512x_PLCE (1 << 0)
  124186. +#define PCM512x_RLCE_SHIFT 0
  124187. +#define PCM512x_PLCK (1 << 4)
  124188. +#define PCM512x_PLCK_SHIFT 4
  124189. +
  124190. +/* Page 0, Register 7 - DSP */
  124191. +#define PCM512x_SDSL (1 << 0)
  124192. +#define PCM512x_SDSL_SHIFT 0
  124193. +#define PCM512x_DEMP (1 << 4)
  124194. +#define PCM512x_DEMP_SHIFT 4
  124195. +
  124196. +/* Page 0, Register 13 - PLL reference */
  124197. +#define PCM512x_SREF (1 << 4)
  124198. +
  124199. +/* Page 0, Register 37 - Error detection */
  124200. +#define PCM512x_IPLK (1 << 0)
  124201. +#define PCM512x_DCAS (1 << 1)
  124202. +#define PCM512x_IDCM (1 << 2)
  124203. +#define PCM512x_IDCH (1 << 3)
  124204. +#define PCM512x_IDSK (1 << 4)
  124205. +#define PCM512x_IDBK (1 << 5)
  124206. +#define PCM512x_IDFS (1 << 6)
  124207. +
  124208. +/* Page 0, Register 42 - DAC routing */
  124209. +#define PCM512x_AUPR_SHIFT 0
  124210. +#define PCM512x_AUPL_SHIFT 4
  124211. +
  124212. +/* Page 0, Register 59 - auto mute */
  124213. +#define PCM512x_ATMR_SHIFT 0
  124214. +#define PCM512x_ATML_SHIFT 4
  124215. +
  124216. +/* Page 0, Register 63 - ramp rates */
  124217. +#define PCM512x_VNDF_SHIFT 6
  124218. +#define PCM512x_VNDS_SHIFT 4
  124219. +#define PCM512x_VNUF_SHIFT 2
  124220. +#define PCM512x_VNUS_SHIFT 0
  124221. +
  124222. +/* Page 0, Register 64 - emergency ramp rates */
  124223. +#define PCM512x_VEDF_SHIFT 6
  124224. +#define PCM512x_VEDS_SHIFT 4
  124225. +
  124226. +/* Page 0, Register 65 - Digital mute enables */
  124227. +#define PCM512x_ACTL_SHIFT 2
  124228. +#define PCM512x_AMLE_SHIFT 1
  124229. +#define PCM512x_AMLR_SHIFT 0
  124230. +
  124231. +#endif
  124232. diff -Nur linux-3.12.38/sound/soc/codecs/sgtl5000.c linux-rpi/sound/soc/codecs/sgtl5000.c
  124233. --- linux-3.12.38/sound/soc/codecs/sgtl5000.c 2015-02-16 16:15:42.000000000 +0100
  124234. +++ linux-rpi/sound/soc/codecs/sgtl5000.c 2015-03-10 17:26:51.938216684 +0100
  124235. @@ -1550,9 +1550,6 @@
  124236. if (ret)
  124237. return ret;
  124238. - /* Need 8 clocks before I2C accesses */
  124239. - udelay(1);
  124240. -
  124241. /* read chip information */
  124242. ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, &reg);
  124243. if (ret)
  124244. diff -Nur linux-3.12.38/sound/soc/codecs/sigmadsp.c linux-rpi/sound/soc/codecs/sigmadsp.c
  124245. --- linux-3.12.38/sound/soc/codecs/sigmadsp.c 2015-02-16 16:15:42.000000000 +0100
  124246. +++ linux-rpi/sound/soc/codecs/sigmadsp.c 2015-03-10 17:26:51.938216684 +0100
  124247. @@ -176,13 +176,6 @@
  124248. goto done;
  124249. }
  124250. - if (ssfw_head->version != 1) {
  124251. - dev_err(dev,
  124252. - "Failed to load firmware: Invalid version %d. Supported firmware versions: 1\n",
  124253. - ssfw_head->version);
  124254. - goto done;
  124255. - }
  124256. -
  124257. crc = crc32(0, fw->data + sizeof(*ssfw_head),
  124258. fw->size - sizeof(*ssfw_head));
  124259. pr_debug("%s: crc=%x\n", __func__, crc);
  124260. diff -Nur linux-3.12.38/sound/soc/codecs/tas5713.c linux-rpi/sound/soc/codecs/tas5713.c
  124261. --- linux-3.12.38/sound/soc/codecs/tas5713.c 1970-01-01 01:00:00.000000000 +0100
  124262. +++ linux-rpi/sound/soc/codecs/tas5713.c 2015-03-10 17:26:51.938216684 +0100
  124263. @@ -0,0 +1,370 @@
  124264. +/*
  124265. + * ASoC Driver for TAS5713
  124266. + *
  124267. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  124268. + * Copyright 2014
  124269. + *
  124270. + * This program is free software; you can redistribute it and/or
  124271. + * modify it under the terms of the GNU General Public License
  124272. + * version 2 as published by the Free Software Foundation.
  124273. + *
  124274. + * This program is distributed in the hope that it will be useful, but
  124275. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  124276. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  124277. + * General Public License for more details.
  124278. + */
  124279. +
  124280. +#include <linux/module.h>
  124281. +#include <linux/moduleparam.h>
  124282. +#include <linux/init.h>
  124283. +#include <linux/delay.h>
  124284. +#include <linux/pm.h>
  124285. +#include <linux/i2c.h>
  124286. +#include <linux/of_device.h>
  124287. +#include <linux/spi/spi.h>
  124288. +#include <linux/regmap.h>
  124289. +#include <linux/regulator/consumer.h>
  124290. +#include <linux/slab.h>
  124291. +#include <sound/core.h>
  124292. +#include <sound/pcm.h>
  124293. +#include <sound/pcm_params.h>
  124294. +#include <sound/soc.h>
  124295. +#include <sound/initval.h>
  124296. +#include <sound/tlv.h>
  124297. +
  124298. +#include <linux/kernel.h>
  124299. +#include <linux/string.h>
  124300. +#include <linux/fs.h>
  124301. +#include <asm/uaccess.h>
  124302. +
  124303. +#include "tas5713.h"
  124304. +
  124305. +
  124306. +static struct i2c_client *i2c;
  124307. +
  124308. +struct tas5713_priv {
  124309. + struct regmap *regmap;
  124310. + int mclk_div;
  124311. + struct snd_soc_codec *codec;
  124312. +};
  124313. +
  124314. +static struct tas5713_priv *priv_data;
  124315. +
  124316. +
  124317. +
  124318. +
  124319. +/*
  124320. + * _ _ ___ _ ___ _ _
  124321. + * /_\ | | / __| /_\ / __|___ _ _| |_ _ _ ___| |___
  124322. + * / _ \| |__\__ \/ _ \ | (__/ _ \ ' \ _| '_/ _ \ (_-<
  124323. + * /_/ \_\____|___/_/ \_\ \___\___/_||_\__|_| \___/_/__/
  124324. + *
  124325. + */
  124326. +
  124327. +static const DECLARE_TLV_DB_SCALE(tas5713_vol_tlv, -10000, 50, 1);
  124328. +
  124329. +
  124330. +static const struct snd_kcontrol_new tas5713_snd_controls[] = {
  124331. + SOC_SINGLE_TLV ("Master" , TAS5713_VOL_MASTER, 0, 248, 1, tas5713_vol_tlv),
  124332. + SOC_DOUBLE_R_TLV("Channels" , TAS5713_VOL_CH1, TAS5713_VOL_CH2, 0, 248, 1, tas5713_vol_tlv)
  124333. +};
  124334. +
  124335. +
  124336. +
  124337. +
  124338. +/*
  124339. + * __ __ _ _ ___ _
  124340. + * | \/ |__ _ __| |_ (_)_ _ ___ | \ _ _(_)_ _____ _ _
  124341. + * | |\/| / _` / _| ' \| | ' \/ -_) | |) | '_| \ V / -_) '_|
  124342. + * |_| |_\__,_\__|_||_|_|_||_\___| |___/|_| |_|\_/\___|_|
  124343. + *
  124344. + */
  124345. +
  124346. +static int tas5713_hw_params(struct snd_pcm_substream *substream,
  124347. + struct snd_pcm_hw_params *params,
  124348. + struct snd_soc_dai *dai)
  124349. +{
  124350. + u16 blen = 0x00;
  124351. +
  124352. + struct snd_soc_codec *codec;
  124353. + codec = dai->codec;
  124354. + priv_data->codec = dai->codec;
  124355. +
  124356. + switch (params_format(params)) {
  124357. + case SNDRV_PCM_FORMAT_S16_LE:
  124358. + blen = 0x03;
  124359. + break;
  124360. + case SNDRV_PCM_FORMAT_S20_3LE:
  124361. + blen = 0x1;
  124362. + break;
  124363. + case SNDRV_PCM_FORMAT_S24_LE:
  124364. + blen = 0x04;
  124365. + break;
  124366. + case SNDRV_PCM_FORMAT_S32_LE:
  124367. + blen = 0x05;
  124368. + break;
  124369. + default:
  124370. + dev_err(dai->dev, "Unsupported word length: %u\n",
  124371. + params_format(params));
  124372. + return -EINVAL;
  124373. + }
  124374. +
  124375. + // set word length
  124376. + snd_soc_update_bits(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x7, blen);
  124377. +
  124378. + return 0;
  124379. +}
  124380. +
  124381. +
  124382. +static int tas5713_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
  124383. +{
  124384. + unsigned int val = 0;
  124385. +
  124386. + struct tas5713_priv *tas5713;
  124387. + struct snd_soc_codec *codec = dai->codec;
  124388. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124389. +
  124390. + if (mute) {
  124391. + val = TAS5713_SOFT_MUTE_ALL;
  124392. + }
  124393. +
  124394. + return regmap_write(tas5713->regmap, TAS5713_SOFT_MUTE, val);
  124395. +}
  124396. +
  124397. +
  124398. +static const struct snd_soc_dai_ops tas5713_dai_ops = {
  124399. + .hw_params = tas5713_hw_params,
  124400. + .mute_stream = tas5713_mute_stream,
  124401. +};
  124402. +
  124403. +
  124404. +static struct snd_soc_dai_driver tas5713_dai = {
  124405. + .name = "tas5713-hifi",
  124406. + .playback = {
  124407. + .stream_name = "Playback",
  124408. + .channels_min = 2,
  124409. + .channels_max = 2,
  124410. + .rates = SNDRV_PCM_RATE_8000_48000,
  124411. + .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE ),
  124412. + },
  124413. + .ops = &tas5713_dai_ops,
  124414. +};
  124415. +
  124416. +
  124417. +
  124418. +
  124419. +/*
  124420. + * ___ _ ___ _
  124421. + * / __|___ __| |___ __ | \ _ _(_)_ _____ _ _
  124422. + * | (__/ _ \/ _` / -_) _| | |) | '_| \ V / -_) '_|
  124423. + * \___\___/\__,_\___\__| |___/|_| |_|\_/\___|_|
  124424. + *
  124425. + */
  124426. +
  124427. +static int tas5713_remove(struct snd_soc_codec *codec)
  124428. +{
  124429. + struct tas5713_priv *tas5713;
  124430. +
  124431. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124432. +
  124433. + return 0;
  124434. +}
  124435. +
  124436. +
  124437. +static int tas5713_probe(struct snd_soc_codec *codec)
  124438. +{
  124439. + struct tas5713_priv *tas5713;
  124440. + int i, ret;
  124441. +
  124442. + i2c = container_of(codec->dev, struct i2c_client, dev);
  124443. +
  124444. + tas5713 = snd_soc_codec_get_drvdata(codec);
  124445. +
  124446. + codec->control_data = tas5713->regmap;
  124447. +
  124448. + ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
  124449. + if (ret < 0) {
  124450. + dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
  124451. + return ret;
  124452. + }
  124453. +
  124454. + // Reset error
  124455. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  124456. +
  124457. + // Trim oscillator
  124458. + ret = snd_soc_write(codec, TAS5713_OSC_TRIM, 0x00);
  124459. + msleep(1000);
  124460. +
  124461. + // Reset error
  124462. + ret = snd_soc_write(codec, TAS5713_ERROR_STATUS, 0x00);
  124463. +
  124464. + // Clock mode: 44/48kHz, MCLK=64xfs
  124465. + ret = snd_soc_write(codec, TAS5713_CLOCK_CTRL, 0x60);
  124466. +
  124467. + // I2S 24bit
  124468. + ret = snd_soc_write(codec, TAS5713_SERIAL_DATA_INTERFACE, 0x05);
  124469. +
  124470. + // Unmute
  124471. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  124472. + ret = snd_soc_write(codec, TAS5713_SOFT_MUTE, 0x00);
  124473. +
  124474. + // Set volume to 0db
  124475. + ret = snd_soc_write(codec, TAS5713_VOL_MASTER, 0x00);
  124476. +
  124477. + // Now start programming the default initialization sequence
  124478. + for (i = 0; i < ARRAY_SIZE(tas5713_init_sequence); ++i) {
  124479. + ret = i2c_master_send(i2c,
  124480. + tas5713_init_sequence[i].data,
  124481. + tas5713_init_sequence[i].size);
  124482. +
  124483. + if (ret < 0) {
  124484. + printk(KERN_INFO "TAS5713 CODEC PROBE: InitSeq returns: %d\n", ret);
  124485. + }
  124486. + }
  124487. +
  124488. + // Unmute
  124489. + ret = snd_soc_write(codec, TAS5713_SYSTEM_CTRL2, 0x00);
  124490. +
  124491. +
  124492. + return 0;
  124493. +}
  124494. +
  124495. +
  124496. +static struct snd_soc_codec_driver soc_codec_dev_tas5713 = {
  124497. + .probe = tas5713_probe,
  124498. + .remove = tas5713_remove,
  124499. + .controls = tas5713_snd_controls,
  124500. + .num_controls = ARRAY_SIZE(tas5713_snd_controls),
  124501. +};
  124502. +
  124503. +
  124504. +
  124505. +
  124506. +/*
  124507. + * ___ ___ ___ ___ _
  124508. + * |_ _|_ ) __| | \ _ _(_)_ _____ _ _
  124509. + * | | / / (__ | |) | '_| \ V / -_) '_|
  124510. + * |___/___\___| |___/|_| |_|\_/\___|_|
  124511. + *
  124512. + */
  124513. +
  124514. +static const struct reg_default tas5713_reg_defaults[] = {
  124515. + { 0x07 ,0x80 }, // R7 - VOL_MASTER - -40dB
  124516. + { 0x08 , 30 }, // R8 - VOL_CH1 - 0dB
  124517. + { 0x09 , 30 }, // R9 - VOL_CH2 - 0dB
  124518. + { 0x0A ,0x80 }, // R10 - VOL_HEADPHONE - -40dB
  124519. +};
  124520. +
  124521. +
  124522. +static bool tas5713_reg_volatile(struct device *dev, unsigned int reg)
  124523. +{
  124524. + switch (reg) {
  124525. + case TAS5713_DEVICE_ID:
  124526. + case TAS5713_ERROR_STATUS:
  124527. + return true;
  124528. + default:
  124529. + return false;
  124530. + }
  124531. +}
  124532. +
  124533. +
  124534. +static const struct of_device_id tas5713_of_match[] = {
  124535. + { .compatible = "ti,tas5713", },
  124536. + { }
  124537. +};
  124538. +MODULE_DEVICE_TABLE(of, tas5713_of_match);
  124539. +
  124540. +
  124541. +static struct regmap_config tas5713_regmap_config = {
  124542. + .reg_bits = 8,
  124543. + .val_bits = 8,
  124544. +
  124545. + .max_register = TAS5713_MAX_REGISTER,
  124546. + .volatile_reg = tas5713_reg_volatile,
  124547. +
  124548. + .cache_type = REGCACHE_RBTREE,
  124549. + .reg_defaults = tas5713_reg_defaults,
  124550. + .num_reg_defaults = ARRAY_SIZE(tas5713_reg_defaults),
  124551. +};
  124552. +
  124553. +
  124554. +static int tas5713_i2c_probe(struct i2c_client *i2c,
  124555. + const struct i2c_device_id *id)
  124556. +{
  124557. + int ret;
  124558. +
  124559. + priv_data = devm_kzalloc(&i2c->dev, sizeof *priv_data, GFP_KERNEL);
  124560. + if (!priv_data)
  124561. + return -ENOMEM;
  124562. +
  124563. + priv_data->regmap = devm_regmap_init_i2c(i2c, &tas5713_regmap_config);
  124564. + if (IS_ERR(priv_data->regmap)) {
  124565. + ret = PTR_ERR(priv_data->regmap);
  124566. + return ret;
  124567. + }
  124568. +
  124569. + i2c_set_clientdata(i2c, priv_data);
  124570. +
  124571. + ret = snd_soc_register_codec(&i2c->dev,
  124572. + &soc_codec_dev_tas5713, &tas5713_dai, 1);
  124573. +
  124574. + return ret;
  124575. +}
  124576. +
  124577. +
  124578. +static int tas5713_i2c_remove(struct i2c_client *i2c)
  124579. +{
  124580. + snd_soc_unregister_codec(&i2c->dev);
  124581. + i2c_set_clientdata(i2c, NULL);
  124582. +
  124583. + kfree(priv_data);
  124584. +
  124585. + return 0;
  124586. +}
  124587. +
  124588. +
  124589. +static const struct i2c_device_id tas5713_i2c_id[] = {
  124590. + { "tas5713", 0 },
  124591. + { }
  124592. +};
  124593. +
  124594. +MODULE_DEVICE_TABLE(i2c, tas5713_i2c_id);
  124595. +
  124596. +
  124597. +static struct i2c_driver tas5713_i2c_driver = {
  124598. + .driver = {
  124599. + .name = "tas5713",
  124600. + .owner = THIS_MODULE,
  124601. + .of_match_table = tas5713_of_match,
  124602. + },
  124603. + .probe = tas5713_i2c_probe,
  124604. + .remove = tas5713_i2c_remove,
  124605. + .id_table = tas5713_i2c_id
  124606. +};
  124607. +
  124608. +
  124609. +static int __init tas5713_modinit(void)
  124610. +{
  124611. + int ret = 0;
  124612. +
  124613. + ret = i2c_add_driver(&tas5713_i2c_driver);
  124614. + if (ret) {
  124615. + printk(KERN_ERR "Failed to register tas5713 I2C driver: %d\n",
  124616. + ret);
  124617. + }
  124618. +
  124619. + return ret;
  124620. +}
  124621. +module_init(tas5713_modinit);
  124622. +
  124623. +
  124624. +static void __exit tas5713_exit(void)
  124625. +{
  124626. + i2c_del_driver(&tas5713_i2c_driver);
  124627. +}
  124628. +module_exit(tas5713_exit);
  124629. +
  124630. +
  124631. +MODULE_AUTHOR("Sebastian Eickhoff <basti.eickhoff@googlemail.com>");
  124632. +MODULE_DESCRIPTION("ASoC driver for TAS5713");
  124633. +MODULE_LICENSE("GPL v2");
  124634. diff -Nur linux-3.12.38/sound/soc/codecs/tas5713.h linux-rpi/sound/soc/codecs/tas5713.h
  124635. --- linux-3.12.38/sound/soc/codecs/tas5713.h 1970-01-01 01:00:00.000000000 +0100
  124636. +++ linux-rpi/sound/soc/codecs/tas5713.h 2015-03-10 17:26:51.938216684 +0100
  124637. @@ -0,0 +1,210 @@
  124638. +/*
  124639. + * ASoC Driver for TAS5713
  124640. + *
  124641. + * Author: Sebastian Eickhoff <basti.eickhoff@googlemail.com>
  124642. + * Copyright 2014
  124643. + *
  124644. + * This program is free software; you can redistribute it and/or
  124645. + * modify it under the terms of the GNU General Public License
  124646. + * version 2 as published by the Free Software Foundation.
  124647. + *
  124648. + * This program is distributed in the hope that it will be useful, but
  124649. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  124650. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  124651. + * General Public License for more details.
  124652. + */
  124653. +
  124654. +#ifndef _TAS5713_H
  124655. +#define _TAS5713_H
  124656. +
  124657. +
  124658. +// TAS5713 I2C-bus register addresses
  124659. +
  124660. +#define TAS5713_CLOCK_CTRL 0x00
  124661. +#define TAS5713_DEVICE_ID 0x01
  124662. +#define TAS5713_ERROR_STATUS 0x02
  124663. +#define TAS5713_SYSTEM_CTRL1 0x03
  124664. +#define TAS5713_SERIAL_DATA_INTERFACE 0x04
  124665. +#define TAS5713_SYSTEM_CTRL2 0x05
  124666. +#define TAS5713_SOFT_MUTE 0x06
  124667. +#define TAS5713_VOL_MASTER 0x07
  124668. +#define TAS5713_VOL_CH1 0x08
  124669. +#define TAS5713_VOL_CH2 0x09
  124670. +#define TAS5713_VOL_HEADPHONE 0x0A
  124671. +#define TAS5713_VOL_CONFIG 0x0E
  124672. +#define TAS5713_MODULATION_LIMIT 0x10
  124673. +#define TAS5713_IC_DLY_CH1 0x11
  124674. +#define TAS5713_IC_DLY_CH2 0x12
  124675. +#define TAS5713_IC_DLY_CH3 0x13
  124676. +#define TAS5713_IC_DLY_CH4 0x14
  124677. +
  124678. +#define TAS5713_START_STOP_PERIOD 0x1A
  124679. +#define TAS5713_OSC_TRIM 0x1B
  124680. +#define TAS5713_BKND_ERR 0x1C
  124681. +
  124682. +#define TAS5713_INPUT_MUX 0x20
  124683. +#define TAS5713_SRC_SELECT_CH4 0x21
  124684. +#define TAS5713_PWM_MUX 0x25
  124685. +
  124686. +#define TAS5713_CH1_BQ0 0x29
  124687. +#define TAS5713_CH1_BQ1 0x2A
  124688. +#define TAS5713_CH1_BQ2 0x2B
  124689. +#define TAS5713_CH1_BQ3 0x2C
  124690. +#define TAS5713_CH1_BQ4 0x2D
  124691. +#define TAS5713_CH1_BQ5 0x2E
  124692. +#define TAS5713_CH1_BQ6 0x2F
  124693. +#define TAS5713_CH1_BQ7 0x58
  124694. +#define TAS5713_CH1_BQ8 0x59
  124695. +
  124696. +#define TAS5713_CH2_BQ0 0x30
  124697. +#define TAS5713_CH2_BQ1 0x31
  124698. +#define TAS5713_CH2_BQ2 0x32
  124699. +#define TAS5713_CH2_BQ3 0x33
  124700. +#define TAS5713_CH2_BQ4 0x34
  124701. +#define TAS5713_CH2_BQ5 0x35
  124702. +#define TAS5713_CH2_BQ6 0x36
  124703. +#define TAS5713_CH2_BQ7 0x5C
  124704. +#define TAS5713_CH2_BQ8 0x5D
  124705. +
  124706. +#define TAS5713_CH4_BQ0 0x5A
  124707. +#define TAS5713_CH4_BQ1 0x5B
  124708. +#define TAS5713_CH3_BQ0 0x5E
  124709. +#define TAS5713_CH3_BQ1 0x5F
  124710. +
  124711. +#define TAS5713_DRC1_SOFTENING_FILTER_ALPHA_OMEGA 0x3B
  124712. +#define TAS5713_DRC1_ATTACK_RELEASE_RATE 0x3C
  124713. +#define TAS5713_DRC2_SOFTENING_FILTER_ALPHA_OMEGA 0x3E
  124714. +#define TAS5713_DRC2_ATTACK_RELEASE_RATE 0x3F
  124715. +#define TAS5713_DRC1_ATTACK_RELEASE_THRES 0x40
  124716. +#define TAS5713_DRC2_ATTACK_RELEASE_THRES 0x43
  124717. +#define TAS5713_DRC_CTRL 0x46
  124718. +
  124719. +#define TAS5713_BANK_SW_CTRL 0x50
  124720. +#define TAS5713_CH1_OUTPUT_MIXER 0x51
  124721. +#define TAS5713_CH2_OUTPUT_MIXER 0x52
  124722. +#define TAS5713_CH1_INPUT_MIXER 0x53
  124723. +#define TAS5713_CH2_INPUT_MIXER 0x54
  124724. +#define TAS5713_OUTPUT_POST_SCALE 0x56
  124725. +#define TAS5713_OUTPUT_PRESCALE 0x57
  124726. +
  124727. +#define TAS5713_IDF_POST_SCALE 0x62
  124728. +
  124729. +#define TAS5713_CH1_INLINE_MIXER 0x70
  124730. +#define TAS5713_CH1_INLINE_DRC_EN_MIXER 0x71
  124731. +#define TAS5713_CH1_R_CHANNEL_MIXER 0x72
  124732. +#define TAS5713_CH1_L_CHANNEL_MIXER 0x73
  124733. +#define TAS5713_CH2_INLINE_MIXER 0x74
  124734. +#define TAS5713_CH2_INLINE_DRC_EN_MIXER 0x75
  124735. +#define TAS5713_CH2_L_CHANNEL_MIXER 0x76
  124736. +#define TAS5713_CH2_R_CHANNEL_MIXER 0x77
  124737. +
  124738. +#define TAS5713_UPDATE_DEV_ADDR_KEY 0xF8
  124739. +#define TAS5713_UPDATE_DEV_ADDR_REG 0xF9
  124740. +
  124741. +#define TAS5713_REGISTER_COUNT 0x46
  124742. +#define TAS5713_MAX_REGISTER 0xF9
  124743. +
  124744. +
  124745. +// Bitmasks for registers
  124746. +#define TAS5713_SOFT_MUTE_ALL 0x07
  124747. +
  124748. +
  124749. +
  124750. +struct tas5713_init_command {
  124751. + const int size;
  124752. + const char *const data;
  124753. +};
  124754. +
  124755. +static const struct tas5713_init_command tas5713_init_sequence[] = {
  124756. +
  124757. + // Trim oscillator
  124758. + { .size = 2, .data = "\x1B\x00" },
  124759. + // System control register 1 (0x03): block DC
  124760. + { .size = 2, .data = "\x03\x80" },
  124761. + // Mute everything
  124762. + { .size = 2, .data = "\x05\x40" },
  124763. + // Modulation limit register (0x10): 97.7%
  124764. + { .size = 2, .data = "\x10\x02" },
  124765. + // Interchannel delay registers
  124766. + // (0x11, 0x12, 0x13, and 0x14): BD mode
  124767. + { .size = 2, .data = "\x11\xB8" },
  124768. + { .size = 2, .data = "\x12\x60" },
  124769. + { .size = 2, .data = "\x13\xA0" },
  124770. + { .size = 2, .data = "\x14\x48" },
  124771. + // PWM shutdown group register (0x19): no shutdown
  124772. + { .size = 2, .data = "\x19\x00" },
  124773. + // Input multiplexer register (0x20): BD mode
  124774. + { .size = 2, .data = "\x20\x00\x89\x77\x72" },
  124775. + // PWM output mux register (0x25)
  124776. + // Channel 1 --> OUTA, channel 1 neg --> OUTB
  124777. + // Channel 2 --> OUTC, channel 2 neg --> OUTD
  124778. + { .size = 5, .data = "\x25\x01\x02\x13\x45" },
  124779. + // DRC control (0x46): DRC off
  124780. + { .size = 5, .data = "\x46\x00\x00\x00\x00" },
  124781. + // BKND_ERR register (0x1C): 299ms reset period
  124782. + { .size = 2, .data = "\x1C\x07" },
  124783. + // Mute channel 3
  124784. + { .size = 2, .data = "\x0A\xFF" },
  124785. + // Volume configuration register (0x0E): volume slew 512 steps
  124786. + { .size = 2, .data = "\x0E\x90" },
  124787. + // Clock control register (0x00): 44/48kHz, MCLK=64xfs
  124788. + { .size = 2, .data = "\x00\x60" },
  124789. + // Bank switch and eq control (0x50): no bank switching
  124790. + { .size = 5, .data = "\x50\x00\x00\x00\x00" },
  124791. + // Volume registers (0x07, 0x08, 0x09, 0x0A)
  124792. + { .size = 2, .data = "\x07\x20" },
  124793. + { .size = 2, .data = "\x08\x30" },
  124794. + { .size = 2, .data = "\x09\x30" },
  124795. + { .size = 2, .data = "\x0A\xFF" },
  124796. + // 0x72, 0x73, 0x76, 0x77 input mixer:
  124797. + // no intermix between channels
  124798. + { .size = 5, .data = "\x72\x00\x00\x00\x00" },
  124799. + { .size = 5, .data = "\x73\x00\x80\x00\x00" },
  124800. + { .size = 5, .data = "\x76\x00\x00\x00\x00" },
  124801. + { .size = 5, .data = "\x77\x00\x80\x00\x00" },
  124802. + // 0x70, 0x71, 0x74, 0x75 inline DRC mixer:
  124803. + // no inline DRC inmix
  124804. + { .size = 5, .data = "\x70\x00\x80\x00\x00" },
  124805. + { .size = 5, .data = "\x71\x00\x00\x00\x00" },
  124806. + { .size = 5, .data = "\x74\x00\x80\x00\x00" },
  124807. + { .size = 5, .data = "\x75\x00\x00\x00\x00" },
  124808. + // 0x56, 0x57 Output scale
  124809. + { .size = 5, .data = "\x56\x00\x80\x00\x00" },
  124810. + { .size = 5, .data = "\x57\x00\x02\x00\x00" },
  124811. + // 0x3B, 0x3c
  124812. + { .size = 9, .data = "\x3B\x00\x08\x00\x00\x00\x78\x00\x00" },
  124813. + { .size = 9, .data = "\x3C\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124814. + { .size = 9, .data = "\x3E\x00\x08\x00\x00\x00\x78\x00\x00" },
  124815. + { .size = 9, .data = "\x3F\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124816. + { .size = 9, .data = "\x40\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124817. + { .size = 9, .data = "\x43\x00\x00\x01\x00\xFF\xFF\xFF\x00" },
  124818. + // 0x51, 0x52: output mixer
  124819. + { .size = 9, .data = "\x51\x00\x80\x00\x00\x00\x00\x00\x00" },
  124820. + { .size = 9, .data = "\x52\x00\x80\x00\x00\x00\x00\x00\x00" },
  124821. + // PEQ defaults
  124822. + { .size = 21, .data = "\x29\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124823. + { .size = 21, .data = "\x2A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124824. + { .size = 21, .data = "\x2B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124825. + { .size = 21, .data = "\x2C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124826. + { .size = 21, .data = "\x2D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124827. + { .size = 21, .data = "\x2E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124828. + { .size = 21, .data = "\x2F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124829. + { .size = 21, .data = "\x30\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124830. + { .size = 21, .data = "\x31\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124831. + { .size = 21, .data = "\x32\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124832. + { .size = 21, .data = "\x33\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124833. + { .size = 21, .data = "\x34\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124834. + { .size = 21, .data = "\x35\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124835. + { .size = 21, .data = "\x36\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124836. + { .size = 21, .data = "\x58\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124837. + { .size = 21, .data = "\x59\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124838. + { .size = 21, .data = "\x5C\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124839. + { .size = 21, .data = "\x5D\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124840. + { .size = 21, .data = "\x5E\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124841. + { .size = 21, .data = "\x5F\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124842. + { .size = 21, .data = "\x5A\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124843. + { .size = 21, .data = "\x5B\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
  124844. +};
  124845. +
  124846. +
  124847. +#endif /* _TAS5713_H */
  124848. diff -Nur linux-3.12.38/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  124849. --- linux-3.12.38/sound/soc/codecs/wm8804.c 2015-02-16 16:15:42.000000000 +0100
  124850. +++ linux-rpi/sound/soc/codecs/wm8804.c 2015-03-10 17:26:51.946216683 +0100
  124851. @@ -63,6 +63,7 @@
  124852. struct regmap *regmap;
  124853. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  124854. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  124855. + int mclk_div;
  124856. };
  124857. static int txsrc_get(struct snd_kcontrol *kcontrol,
  124858. @@ -277,6 +278,7 @@
  124859. blen = 0x1;
  124860. break;
  124861. case SNDRV_PCM_FORMAT_S24_LE:
  124862. + case SNDRV_PCM_FORMAT_S32_LE:
  124863. blen = 0x2;
  124864. break;
  124865. default:
  124866. @@ -318,7 +320,7 @@
  124867. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  124868. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  124869. - unsigned int source)
  124870. + unsigned int source, unsigned int mclk_div)
  124871. {
  124872. u64 Kpart;
  124873. unsigned long int K, Ndiv, Nmod, tmp;
  124874. @@ -330,7 +332,8 @@
  124875. */
  124876. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  124877. tmp = target * post_table[i].div;
  124878. - if (tmp >= 90000000 && tmp <= 100000000) {
  124879. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  124880. + (mclk_div == post_table[i].mclkdiv)) {
  124881. pll_div->freqmode = post_table[i].freqmode;
  124882. pll_div->mclkdiv = post_table[i].mclkdiv;
  124883. target *= post_table[i].div;
  124884. @@ -387,8 +390,11 @@
  124885. } else {
  124886. int ret;
  124887. struct pll_div pll_div;
  124888. + struct wm8804_priv *wm8804;
  124889. - ret = pll_factors(&pll_div, freq_out, freq_in);
  124890. + wm8804 = snd_soc_codec_get_drvdata(codec);
  124891. +
  124892. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  124893. if (ret)
  124894. return ret;
  124895. @@ -452,6 +458,7 @@
  124896. int div_id, int div)
  124897. {
  124898. struct snd_soc_codec *codec;
  124899. + struct wm8804_priv *wm8804;
  124900. codec = dai->codec;
  124901. switch (div_id) {
  124902. @@ -459,6 +466,10 @@
  124903. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  124904. (div & 0x3) << 4);
  124905. break;
  124906. + case WM8804_MCLK_DIV:
  124907. + wm8804 = snd_soc_codec_get_drvdata(codec);
  124908. + wm8804->mclk_div = div;
  124909. + break;
  124910. default:
  124911. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  124912. return -EINVAL;
  124913. @@ -641,7 +652,7 @@
  124914. };
  124915. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  124916. - SNDRV_PCM_FMTBIT_S24_LE)
  124917. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  124918. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  124919. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  124920. @@ -674,7 +685,7 @@
  124921. .suspend = wm8804_suspend,
  124922. .resume = wm8804_resume,
  124923. .set_bias_level = wm8804_set_bias_level,
  124924. - .idle_bias_off = true,
  124925. + .idle_bias_off = false,
  124926. .controls = wm8804_snd_controls,
  124927. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  124928. diff -Nur linux-3.12.38/sound/soc/codecs/wm8804.h linux-rpi/sound/soc/codecs/wm8804.h
  124929. --- linux-3.12.38/sound/soc/codecs/wm8804.h 2015-02-16 16:15:42.000000000 +0100
  124930. +++ linux-rpi/sound/soc/codecs/wm8804.h 2015-03-09 10:39:38.578893685 +0100
  124931. @@ -57,5 +57,9 @@
  124932. #define WM8804_CLKOUT_SRC_OSCCLK 4
  124933. #define WM8804_CLKOUT_DIV 1
  124934. +#define WM8804_MCLK_DIV 2
  124935. +
  124936. +#define WM8804_MCLKDIV_256FS 0
  124937. +#define WM8804_MCLKDIV_128FS 1
  124938. #endif /* _WM8804_H */
  124939. diff -Nur linux-3.12.38/sound/soc/codecs/wm8960.c linux-rpi/sound/soc/codecs/wm8960.c
  124940. --- linux-3.12.38/sound/soc/codecs/wm8960.c 2015-02-16 16:15:42.000000000 +0100
  124941. +++ linux-rpi/sound/soc/codecs/wm8960.c 2015-03-10 17:26:51.946216683 +0100
  124942. @@ -555,7 +555,7 @@
  124943. { 22050, 2 },
  124944. { 24000, 2 },
  124945. { 16000, 3 },
  124946. - { 11025, 4 },
  124947. + { 11250, 4 },
  124948. { 12000, 4 },
  124949. { 8000, 5 },
  124950. };
  124951. diff -Nur linux-3.12.38/sound/soc/dwc/designware_i2s.c linux-rpi/sound/soc/dwc/designware_i2s.c
  124952. --- linux-3.12.38/sound/soc/dwc/designware_i2s.c 2015-02-16 16:15:42.000000000 +0100
  124953. +++ linux-rpi/sound/soc/dwc/designware_i2s.c 2015-03-10 17:26:51.954216683 +0100
  124954. @@ -263,19 +263,6 @@
  124955. snd_soc_dai_set_dma_data(dai, substream, NULL);
  124956. }
  124957. -static int dw_i2s_prepare(struct snd_pcm_substream *substream,
  124958. - struct snd_soc_dai *dai)
  124959. -{
  124960. - struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  124961. -
  124962. - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  124963. - i2s_write_reg(dev->i2s_base, TXFFR, 1);
  124964. - else
  124965. - i2s_write_reg(dev->i2s_base, RXFFR, 1);
  124966. -
  124967. - return 0;
  124968. -}
  124969. -
  124970. static int dw_i2s_trigger(struct snd_pcm_substream *substream,
  124971. int cmd, struct snd_soc_dai *dai)
  124972. {
  124973. @@ -307,7 +294,6 @@
  124974. .startup = dw_i2s_startup,
  124975. .shutdown = dw_i2s_shutdown,
  124976. .hw_params = dw_i2s_hw_params,
  124977. - .prepare = dw_i2s_prepare,
  124978. .trigger = dw_i2s_trigger,
  124979. };
  124980. diff -Nur linux-3.12.38/sound/soc/generic/simple-card.c linux-rpi/sound/soc/generic/simple-card.c
  124981. --- linux-3.12.38/sound/soc/generic/simple-card.c 2015-02-16 16:15:42.000000000 +0100
  124982. +++ linux-rpi/sound/soc/generic/simple-card.c 2015-03-10 17:26:51.954216683 +0100
  124983. @@ -27,6 +27,11 @@
  124984. if (!ret && daifmt)
  124985. ret = snd_soc_dai_set_fmt(dai, daifmt);
  124986. + if (ret == -ENOTSUPP) {
  124987. + dev_dbg(dai->dev, "ASoC: set_fmt is not supported\n");
  124988. + ret = 0;
  124989. + }
  124990. +
  124991. if (!ret && set->sysclk)
  124992. ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
  124993. diff -Nur linux-3.12.38/sound/soc/Kconfig linux-rpi/sound/soc/Kconfig
  124994. --- linux-3.12.38/sound/soc/Kconfig 2015-02-16 16:15:42.000000000 +0100
  124995. +++ linux-rpi/sound/soc/Kconfig 2015-03-10 17:26:51.926216684 +0100
  124996. @@ -33,6 +33,7 @@
  124997. # All the supported SoCs
  124998. source "sound/soc/atmel/Kconfig"
  124999. source "sound/soc/au1x/Kconfig"
  125000. +source "sound/soc/bcm/Kconfig"
  125001. source "sound/soc/blackfin/Kconfig"
  125002. source "sound/soc/cirrus/Kconfig"
  125003. source "sound/soc/davinci/Kconfig"
  125004. diff -Nur linux-3.12.38/sound/soc/Makefile linux-rpi/sound/soc/Makefile
  125005. --- linux-3.12.38/sound/soc/Makefile 2015-02-16 16:15:42.000000000 +0100
  125006. +++ linux-rpi/sound/soc/Makefile 2015-03-10 17:26:51.926216684 +0100
  125007. @@ -10,6 +10,7 @@
  125008. obj-$(CONFIG_SND_SOC) += generic/
  125009. obj-$(CONFIG_SND_SOC) += atmel/
  125010. obj-$(CONFIG_SND_SOC) += au1x/
  125011. +obj-$(CONFIG_SND_SOC) += bcm/
  125012. obj-$(CONFIG_SND_SOC) += blackfin/
  125013. obj-$(CONFIG_SND_SOC) += cirrus/
  125014. obj-$(CONFIG_SND_SOC) += davinci/
  125015. diff -Nur linux-3.12.38/sound/soc/omap/omap-mcbsp.c linux-rpi/sound/soc/omap/omap-mcbsp.c
  125016. --- linux-3.12.38/sound/soc/omap/omap-mcbsp.c 2015-02-16 16:15:42.000000000 +0100
  125017. +++ linux-rpi/sound/soc/omap/omap-mcbsp.c 2015-03-10 17:26:51.958216683 +0100
  125018. @@ -436,7 +436,7 @@
  125019. case SND_SOC_DAIFMT_CBM_CFS:
  125020. /* McBSP slave. FS clock as output */
  125021. regs->srgr2 |= FSGM;
  125022. - regs->pcr0 |= FSXM | FSRM;
  125023. + regs->pcr0 |= FSXM;
  125024. break;
  125025. case SND_SOC_DAIFMT_CBM_CFM:
  125026. /* McBSP slave */
  125027. diff -Nur linux-3.12.38/sound/soc/soc-core.c linux-rpi/sound/soc/soc-core.c
  125028. --- linux-3.12.38/sound/soc/soc-core.c 2015-02-16 16:15:42.000000000 +0100
  125029. +++ linux-rpi/sound/soc/soc-core.c 2015-03-10 17:26:51.962216683 +0100
  125030. @@ -3038,8 +3038,8 @@
  125031. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  125032. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  125033. - uinfo->value.integer.min = 0;
  125034. - uinfo->value.integer.max = platform_max - min;
  125035. + uinfo->value.integer.min = min;
  125036. + uinfo->value.integer.max = platform_max;
  125037. return 0;
  125038. }
  125039. @@ -3070,9 +3070,10 @@
  125040. unsigned int val, val_mask;
  125041. int ret;
  125042. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  125043. if (invert)
  125044. - val = max - val;
  125045. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  125046. + else
  125047. + val = (ucontrol->value.integer.value[0] & mask);
  125048. val_mask = mask << shift;
  125049. val = val << shift;
  125050. @@ -3081,9 +3082,10 @@
  125051. return ret;
  125052. if (snd_soc_volsw_is_stereo(mc)) {
  125053. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  125054. if (invert)
  125055. - val = max - val;
  125056. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  125057. + else
  125058. + val = (ucontrol->value.integer.value[1] & mask);
  125059. val_mask = mask << shift;
  125060. val = val << shift;
  125061. @@ -3121,18 +3123,14 @@
  125062. (snd_soc_read(codec, reg) >> shift) & mask;
  125063. if (invert)
  125064. ucontrol->value.integer.value[0] =
  125065. - max - ucontrol->value.integer.value[0];
  125066. - ucontrol->value.integer.value[0] =
  125067. - ucontrol->value.integer.value[0] - min;
  125068. + max - ucontrol->value.integer.value[0] + min;
  125069. if (snd_soc_volsw_is_stereo(mc)) {
  125070. ucontrol->value.integer.value[1] =
  125071. (snd_soc_read(codec, rreg) >> shift) & mask;
  125072. if (invert)
  125073. ucontrol->value.integer.value[1] =
  125074. - max - ucontrol->value.integer.value[1];
  125075. - ucontrol->value.integer.value[1] =
  125076. - ucontrol->value.integer.value[1] - min;
  125077. + max - ucontrol->value.integer.value[1] + min;
  125078. }
  125079. return 0;
  125080. @@ -3576,6 +3574,22 @@
  125081. EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
  125082. /**
  125083. + * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  125084. + * @dai: DAI
  125085. + * @ratio Ratio of BCLK to Sample rate.
  125086. + *
  125087. + * Configures the DAI for a preset BCLK to sample rate ratio.
  125088. + */
  125089. +int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  125090. +{
  125091. + if (dai->driver && dai->driver->ops->set_bclk_ratio)
  125092. + return dai->driver->ops->set_bclk_ratio(dai, ratio);
  125093. + else
  125094. + return -EINVAL;
  125095. +}
  125096. +EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  125097. +
  125098. +/**
  125099. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  125100. * @dai: DAI
  125101. * @fmt: SND_SOC_DAIFMT_ format value.
  125102. diff -Nur linux-3.12.38/sound/usb/mixer.c linux-rpi/sound/usb/mixer.c
  125103. --- linux-3.12.38/sound/usb/mixer.c 2015-02-16 16:15:42.000000000 +0100
  125104. +++ linux-rpi/sound/usb/mixer.c 2015-03-10 17:26:51.970216683 +0100
  125105. @@ -886,7 +886,6 @@
  125106. case USB_ID(0x046d, 0x0807): /* Logitech Webcam C500 */
  125107. case USB_ID(0x046d, 0x0808):
  125108. case USB_ID(0x046d, 0x0809):
  125109. - case USB_ID(0x046d, 0x0819): /* Logitech Webcam C210 */
  125110. case USB_ID(0x046d, 0x081b): /* HD Webcam c310 */
  125111. case USB_ID(0x046d, 0x081d): /* HD Webcam c510 */
  125112. case USB_ID(0x046d, 0x0825): /* HD Webcam c270 */
  125113. diff -Nur linux-3.12.38/sound/usb/mixer_maps.c linux-rpi/sound/usb/mixer_maps.c
  125114. --- linux-3.12.38/sound/usb/mixer_maps.c 2015-02-16 16:15:42.000000000 +0100
  125115. +++ linux-rpi/sound/usb/mixer_maps.c 2015-03-10 17:26:51.970216683 +0100
  125116. @@ -322,11 +322,8 @@
  125117. { 0 } /* terminator */
  125118. };
  125119. -/* some (all?) SCMS USB3318 devices are affected by a firmware lock up
  125120. - * when anything attempts to access FU 10 (control)
  125121. - */
  125122. -static const struct usbmix_name_map scms_usb3318_map[] = {
  125123. - { 10, NULL },
  125124. +static const struct usbmix_name_map kef_x300a_map[] = {
  125125. + { 10, NULL }, /* firmware locks up (?) when we try to access this FU */
  125126. { 0 }
  125127. };
  125128. @@ -418,14 +415,8 @@
  125129. .map = ebox44_map,
  125130. },
  125131. {
  125132. - /* KEF X300A */
  125133. .id = USB_ID(0x27ac, 0x1000),
  125134. - .map = scms_usb3318_map,
  125135. - },
  125136. - {
  125137. - /* Arcam rPAC */
  125138. - .id = USB_ID(0x25c4, 0x0003),
  125139. - .map = scms_usb3318_map,
  125140. + .map = kef_x300a_map,
  125141. },
  125142. { 0 } /* terminator */
  125143. };
  125144. diff -Nur linux-3.12.38/sound/usb/quirks.c linux-rpi/sound/usb/quirks.c
  125145. --- linux-3.12.38/sound/usb/quirks.c 2015-02-16 16:15:42.000000000 +0100
  125146. +++ linux-rpi/sound/usb/quirks.c 2015-03-10 17:26:51.970216683 +0100
  125147. @@ -662,9 +662,8 @@
  125148. /*
  125149. * Novation Twitch DJ controller
  125150. - * Focusrite Novation Saffire 6 USB audio card
  125151. */
  125152. -static int snd_usb_novation_boot_quirk(struct usb_device *dev)
  125153. +static int snd_usb_twitch_boot_quirk(struct usb_device *dev)
  125154. {
  125155. /* preemptively set up the device because otherwise the
  125156. * raw MIDI endpoints are not active */
  125157. @@ -973,9 +972,9 @@
  125158. /* Digidesign Mbox 2 */
  125159. return snd_usb_mbox2_boot_quirk(dev);
  125160. - case USB_ID(0x1235, 0x0010): /* Focusrite Novation Saffire 6 USB */
  125161. - case USB_ID(0x1235, 0x0018): /* Focusrite Novation Twitch */
  125162. - return snd_usb_novation_boot_quirk(dev);
  125163. + case USB_ID(0x1235, 0x0018):
  125164. + /* Focusrite Novation Twitch */
  125165. + return snd_usb_twitch_boot_quirk(dev);
  125166. case USB_ID(0x133e, 0x0815):
  125167. /* Access Music VirusTI Desktop */
  125168. diff -Nur linux-3.12.38/sound/usb/quirks-table.h linux-rpi/sound/usb/quirks-table.h
  125169. --- linux-3.12.38/sound/usb/quirks-table.h 2015-02-16 16:15:42.000000000 +0100
  125170. +++ linux-rpi/sound/usb/quirks-table.h 2015-03-10 17:26:51.970216683 +0100
  125171. @@ -72,21 +72,22 @@
  125172. }
  125173. },
  125174. -/* Creative/E-Mu devices */
  125175. +/* Creative/Toshiba Multimedia Center SB-0500 */
  125176. {
  125177. - USB_DEVICE(0x041e, 0x3010),
  125178. + USB_DEVICE(0x041e, 0x3048),
  125179. .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
  125180. - .vendor_name = "Creative Labs",
  125181. - .product_name = "Sound Blaster MP3+",
  125182. + .vendor_name = "Toshiba",
  125183. + .product_name = "SB-0500",
  125184. .ifnum = QUIRK_NO_INTERFACE
  125185. }
  125186. },
  125187. -/* Creative/Toshiba Multimedia Center SB-0500 */
  125188. +
  125189. +/* Creative/E-Mu devices */
  125190. {
  125191. - USB_DEVICE(0x041e, 0x3048),
  125192. + USB_DEVICE(0x041e, 0x3010),
  125193. .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
  125194. - .vendor_name = "Toshiba",
  125195. - .product_name = "SB-0500",
  125196. + .vendor_name = "Creative Labs",
  125197. + .product_name = "Sound Blaster MP3+",
  125198. .ifnum = QUIRK_NO_INTERFACE
  125199. }
  125200. },
  125201. @@ -2579,46 +2580,6 @@
  125202. }
  125203. },
  125204. {
  125205. - USB_DEVICE(0x1235, 0x0010),
  125206. - .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125207. - .vendor_name = "Focusrite",
  125208. - .product_name = "Saffire 6 USB",
  125209. - .ifnum = QUIRK_ANY_INTERFACE,
  125210. - .type = QUIRK_COMPOSITE,
  125211. - .data = (const struct snd_usb_audio_quirk[]) {
  125212. - {
  125213. - .ifnum = 0,
  125214. - .type = QUIRK_AUDIO_FIXED_ENDPOINT,
  125215. - .data = &(const struct audioformat) {
  125216. - .formats = SNDRV_PCM_FMTBIT_S24_3LE,
  125217. - .channels = 4,
  125218. - .iface = 0,
  125219. - .altsetting = 1,
  125220. - .altset_idx = 1,
  125221. - .attributes = UAC_EP_CS_ATTR_SAMPLE_RATE,
  125222. - .endpoint = 0x01,
  125223. - .ep_attr = USB_ENDPOINT_XFER_ISOC,
  125224. - .rates = SNDRV_PCM_RATE_44100 |
  125225. - SNDRV_PCM_RATE_48000,
  125226. - .rate_min = 44100,
  125227. - .rate_max = 48000,
  125228. - .nr_rates = 2,
  125229. - .rate_table = (unsigned int[]) {
  125230. - 44100, 48000
  125231. - }
  125232. - }
  125233. - },
  125234. - {
  125235. - .ifnum = 1,
  125236. - .type = QUIRK_MIDI_RAW_BYTES
  125237. - },
  125238. - {
  125239. - .ifnum = -1
  125240. - }
  125241. - }
  125242. - }
  125243. -},
  125244. -{
  125245. USB_DEVICE(0x1235, 0x0018),
  125246. .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
  125247. .vendor_name = "Novation",
  125248. @@ -2667,57 +2628,6 @@
  125249. .type = QUIRK_MIDI_NOVATION
  125250. }
  125251. },
  125252. -{
  125253. - /*
  125254. - * Focusrite Scarlett 18i6
  125255. - *
  125256. - * Avoid mixer creation, which otherwise fails because some of
  125257. - * the interface descriptor subtypes for interface 0 are
  125258. - * unknown. That should be fixed or worked-around but this at
  125259. - * least allows the device to be used successfully with a DAW
  125260. - * and an external mixer. See comments below about other
  125261. - * ignored interfaces.
  125262. - */
  125263. - USB_DEVICE(0x1235, 0x8004),
  125264. - .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
  125265. - .vendor_name = "Focusrite",
  125266. - .product_name = "Scarlett 18i6",
  125267. - .ifnum = QUIRK_ANY_INTERFACE,
  125268. - .type = QUIRK_COMPOSITE,
  125269. - .data = & (const struct snd_usb_audio_quirk[]) {
  125270. - {
  125271. - /* InterfaceSubClass 1 (Control Device) */
  125272. - .ifnum = 0,
  125273. - .type = QUIRK_IGNORE_INTERFACE
  125274. - },
  125275. - {
  125276. - .ifnum = 1,
  125277. - .type = QUIRK_AUDIO_STANDARD_INTERFACE
  125278. - },
  125279. - {
  125280. - .ifnum = 2,
  125281. - .type = QUIRK_AUDIO_STANDARD_INTERFACE
  125282. - },
  125283. - {
  125284. - /* InterfaceSubClass 1 (Control Device) */
  125285. - .ifnum = 3,
  125286. - .type = QUIRK_IGNORE_INTERFACE
  125287. - },
  125288. - {
  125289. - .ifnum = 4,
  125290. - .type = QUIRK_MIDI_STANDARD_INTERFACE
  125291. - },
  125292. - {
  125293. - /* InterfaceSubClass 1 (Device Firmware Update) */
  125294. - .ifnum = 5,
  125295. - .type = QUIRK_IGNORE_INTERFACE
  125296. - },
  125297. - {
  125298. - .ifnum = -1
  125299. - }
  125300. - }
  125301. - }
  125302. -},
  125303. /* Access Music devices */
  125304. {
  125305. @@ -2804,45 +2714,133 @@
  125306. }
  125307. },
  125308. -/*
  125309. - * Auvitek au0828 devices with audio interface.
  125310. - * This should be kept in sync with drivers/media/usb/au0828/au0828-cards.c
  125311. - * Please notice that some drivers are DVB only, and don't need to be
  125312. - * here. That's the case, for example, of DVICO_FUSIONHDTV7.
  125313. - */
  125314. -
  125315. -#define AU0828_DEVICE(vid, pid, vname, pname) { \
  125316. - USB_DEVICE_VENDOR_SPEC(vid, pid), \
  125317. - .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
  125318. - USB_DEVICE_ID_MATCH_INT_CLASS | \
  125319. - USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
  125320. - .bInterfaceClass = USB_CLASS_AUDIO, \
  125321. - .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, \
  125322. - .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { \
  125323. - .vendor_name = vname, \
  125324. - .product_name = pname, \
  125325. - .ifnum = QUIRK_ANY_INTERFACE, \
  125326. - .type = QUIRK_AUDIO_ALIGN_TRANSFER, \
  125327. - } \
  125328. -}
  125329. -
  125330. -AU0828_DEVICE(0x2040, 0x7200, "Hauppauge", "HVR-950Q"),
  125331. -AU0828_DEVICE(0x2040, 0x7240, "Hauppauge", "HVR-850"),
  125332. -AU0828_DEVICE(0x2040, 0x7210, "Hauppauge", "HVR-950Q"),
  125333. -AU0828_DEVICE(0x2040, 0x7217, "Hauppauge", "HVR-950Q"),
  125334. -AU0828_DEVICE(0x2040, 0x721b, "Hauppauge", "HVR-950Q"),
  125335. -AU0828_DEVICE(0x2040, 0x721e, "Hauppauge", "HVR-950Q"),
  125336. -AU0828_DEVICE(0x2040, 0x721f, "Hauppauge", "HVR-950Q"),
  125337. -AU0828_DEVICE(0x2040, 0x7280, "Hauppauge", "HVR-950Q"),
  125338. -AU0828_DEVICE(0x0fd9, 0x0008, "Hauppauge", "HVR-950Q"),
  125339. -AU0828_DEVICE(0x2040, 0x7201, "Hauppauge", "HVR-950Q-MXL"),
  125340. -AU0828_DEVICE(0x2040, 0x7211, "Hauppauge", "HVR-950Q-MXL"),
  125341. -AU0828_DEVICE(0x2040, 0x7281, "Hauppauge", "HVR-950Q-MXL"),
  125342. -AU0828_DEVICE(0x05e1, 0x0480, "Hauppauge", "Woodbury"),
  125343. -AU0828_DEVICE(0x2040, 0x8200, "Hauppauge", "Woodbury"),
  125344. -AU0828_DEVICE(0x2040, 0x7260, "Hauppauge", "HVR-950Q"),
  125345. -AU0828_DEVICE(0x2040, 0x7213, "Hauppauge", "HVR-950Q"),
  125346. -AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
  125347. +/* Hauppauge HVR-950Q and HVR-850 */
  125348. +{
  125349. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x7200),
  125350. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125351. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125352. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125353. + .bInterfaceClass = USB_CLASS_AUDIO,
  125354. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125355. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125356. + .vendor_name = "Hauppauge",
  125357. + .product_name = "HVR-950Q",
  125358. + .ifnum = QUIRK_ANY_INTERFACE,
  125359. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125360. + }
  125361. +},
  125362. +{
  125363. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x7240),
  125364. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125365. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125366. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125367. + .bInterfaceClass = USB_CLASS_AUDIO,
  125368. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125369. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125370. + .vendor_name = "Hauppauge",
  125371. + .product_name = "HVR-850",
  125372. + .ifnum = QUIRK_ANY_INTERFACE,
  125373. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125374. + }
  125375. +},
  125376. +{
  125377. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x7210),
  125378. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125379. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125380. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125381. + .bInterfaceClass = USB_CLASS_AUDIO,
  125382. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125383. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125384. + .vendor_name = "Hauppauge",
  125385. + .product_name = "HVR-950Q",
  125386. + .ifnum = QUIRK_ANY_INTERFACE,
  125387. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125388. + }
  125389. +},
  125390. +{
  125391. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x7217),
  125392. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125393. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125394. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125395. + .bInterfaceClass = USB_CLASS_AUDIO,
  125396. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125397. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125398. + .vendor_name = "Hauppauge",
  125399. + .product_name = "HVR-950Q",
  125400. + .ifnum = QUIRK_ANY_INTERFACE,
  125401. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125402. + }
  125403. +},
  125404. +{
  125405. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x721b),
  125406. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125407. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125408. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125409. + .bInterfaceClass = USB_CLASS_AUDIO,
  125410. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125411. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125412. + .vendor_name = "Hauppauge",
  125413. + .product_name = "HVR-950Q",
  125414. + .ifnum = QUIRK_ANY_INTERFACE,
  125415. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125416. + }
  125417. +},
  125418. +{
  125419. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x721e),
  125420. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125421. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125422. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125423. + .bInterfaceClass = USB_CLASS_AUDIO,
  125424. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125425. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125426. + .vendor_name = "Hauppauge",
  125427. + .product_name = "HVR-950Q",
  125428. + .ifnum = QUIRK_ANY_INTERFACE,
  125429. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125430. + }
  125431. +},
  125432. +{
  125433. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x721f),
  125434. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125435. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125436. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125437. + .bInterfaceClass = USB_CLASS_AUDIO,
  125438. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125439. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125440. + .vendor_name = "Hauppauge",
  125441. + .product_name = "HVR-950Q",
  125442. + .ifnum = QUIRK_ANY_INTERFACE,
  125443. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125444. + }
  125445. +},
  125446. +{
  125447. + USB_DEVICE_VENDOR_SPEC(0x2040, 0x7280),
  125448. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125449. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125450. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125451. + .bInterfaceClass = USB_CLASS_AUDIO,
  125452. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125453. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125454. + .vendor_name = "Hauppauge",
  125455. + .product_name = "HVR-950Q",
  125456. + .ifnum = QUIRK_ANY_INTERFACE,
  125457. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125458. + }
  125459. +},
  125460. +{
  125461. + USB_DEVICE_VENDOR_SPEC(0x0fd9, 0x0008),
  125462. + .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
  125463. + USB_DEVICE_ID_MATCH_INT_CLASS |
  125464. + USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  125465. + .bInterfaceClass = USB_CLASS_AUDIO,
  125466. + .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
  125467. + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
  125468. + .vendor_name = "Hauppauge",
  125469. + .product_name = "HVR-950Q",
  125470. + .ifnum = QUIRK_ANY_INTERFACE,
  125471. + .type = QUIRK_AUDIO_ALIGN_TRANSFER,
  125472. + }
  125473. +},
  125474. /* Digidesign Mbox */
  125475. {
  125476. @@ -3108,6 +3106,58 @@
  125477. },
  125478. {
  125479. .ifnum = -1
  125480. + }
  125481. + }
  125482. + }
  125483. +},
  125484. +
  125485. +{
  125486. + /*
  125487. + * Focusrite Scarlett 18i6
  125488. + *
  125489. + * Avoid mixer creation, which otherwise fails because some of
  125490. + * the interface descriptor subtypes for interface 0 are
  125491. + * unknown. That should be fixed or worked-around but this at
  125492. + * least allows the device to be used successfully with a DAW
  125493. + * and an external mixer. See comments below about other
  125494. + * ignored interfaces.
  125495. + */
  125496. + USB_DEVICE(0x1235, 0x8004),
  125497. + .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
  125498. + .vendor_name = "Focusrite",
  125499. + .product_name = "Scarlett 18i6",
  125500. + .ifnum = QUIRK_ANY_INTERFACE,
  125501. + .type = QUIRK_COMPOSITE,
  125502. + .data = & (const struct snd_usb_audio_quirk[]) {
  125503. + {
  125504. + /* InterfaceSubClass 1 (Control Device) */
  125505. + .ifnum = 0,
  125506. + .type = QUIRK_IGNORE_INTERFACE
  125507. + },
  125508. + {
  125509. + .ifnum = 1,
  125510. + .type = QUIRK_AUDIO_STANDARD_INTERFACE
  125511. + },
  125512. + {
  125513. + .ifnum = 2,
  125514. + .type = QUIRK_AUDIO_STANDARD_INTERFACE
  125515. + },
  125516. + {
  125517. + /* InterfaceSubClass 1 (Control Device) */
  125518. + .ifnum = 3,
  125519. + .type = QUIRK_IGNORE_INTERFACE
  125520. + },
  125521. + {
  125522. + .ifnum = 4,
  125523. + .type = QUIRK_MIDI_STANDARD_INTERFACE
  125524. + },
  125525. + {
  125526. + /* InterfaceSubClass 1 (Device Firmware Update) */
  125527. + .ifnum = 5,
  125528. + .type = QUIRK_IGNORE_INTERFACE
  125529. + },
  125530. + {
  125531. + .ifnum = -1
  125532. }
  125533. }
  125534. }
  125535. diff -Nur linux-3.12.38/tools/perf/util/hist.h linux-rpi/tools/perf/util/hist.h
  125536. --- linux-3.12.38/tools/perf/util/hist.h 2015-02-16 16:15:42.000000000 +0100
  125537. +++ linux-rpi/tools/perf/util/hist.h 2015-03-10 17:26:51.986216683 +0100
  125538. @@ -35,7 +35,6 @@
  125539. u32 nr_invalid_chains;
  125540. u32 nr_unknown_id;
  125541. u32 nr_unprocessable_samples;
  125542. - u32 nr_unordered_events;
  125543. };
  125544. enum hist_column {
  125545. diff -Nur linux-3.12.38/tools/perf/util/session.c linux-rpi/tools/perf/util/session.c
  125546. --- linux-3.12.38/tools/perf/util/session.c 2015-02-16 16:15:42.000000000 +0100
  125547. +++ linux-rpi/tools/perf/util/session.c 2015-03-10 17:26:51.990216683 +0100
  125548. @@ -681,7 +681,8 @@
  125549. return -ETIME;
  125550. if (timestamp < s->ordered_samples.last_flush) {
  125551. - s->stats.nr_unordered_events++;
  125552. + printf("Warning: Timestamp below last timeslice flush\n");
  125553. + return -EINVAL;
  125554. }
  125555. if (!list_empty(sc)) {
  125556. @@ -1167,8 +1168,6 @@
  125557. "Do you have a KVM guest running and not using 'perf kvm'?\n",
  125558. session->stats.nr_unprocessable_samples);
  125559. }
  125560. - if (session->stats.nr_unordered_events != 0)
  125561. - ui__warning("%u out of order events recorded.\n", session->stats.nr_unordered_events);
  125562. }
  125563. volatile int session_done;